View Javadoc
1   /**
2    * Copyright 2011-2013 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10   * software distributed under the License is distributed on an "AS IS"
11   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing
13   * permissions and limitations under the License.
14   */
15  package org.kuali.mobility.push.controller;
16  
17  import org.junit.Before;
18  import org.junit.Test;
19  import org.junit.runner.RunWith;
20  import org.kuali.mobility.push.controllers.PushConfigController;
21  import org.kuali.mobility.push.entity.Device;
22  import org.kuali.mobility.push.service.send.config.BlackberryPushConfig;
23  import org.mockito.Mock;
24  import org.springframework.ui.ExtendedModelMap;
25  import org.springframework.ui.Model;
26  
27  import java.util.Properties;
28  
29  import static org.junit.Assert.assertTrue;
30  import static org.mockito.Matchers.any;
31  import static org.mockito.Mockito.when;
32  
33  /**
34   * @author Kuali Mobility Team (mobility.collab@kuali.org)
35   */
36  @RunWith(org.mockito.runners.MockitoJUnitRunner.class)
37  public class PushConfigControllerTest {
38  
39  	private Model uiModel;
40  	private PushConfigController controller;
41  
42  	@Mock
43  	private Properties kmeProperties;
44  	@Mock
45  	private BlackberryPushConfig bbPushConfig;
46  
47  	private static final String[] PLATFORMS = {
48  		Device.TYPE_IOS,
49  		Device.TYPE_ANDROID,
50  		Device.TYPE_BLACKBERRY,
51  		Device.TYPE_WINDOWS};
52  	private static final String VALUE = "value";
53  
54  	@Before
55  	public void preTest() {
56  		this.setController(new PushConfigController());
57  		getController().setBbPushConfig(getBbPushConfig());
58  		getController().setKmeProperties(getKmeProperties());
59  		this.setUiModel(new ExtendedModelMap());
60  	}
61  
62  	@Test
63  	public void testGetPushConfigDefault() {
64  		getController().getPushConfig(null, getUiModel());
65  		assertTrue("Model was modified and should not have been.", getUiModel().asMap().isEmpty());
66  	}
67  
68  	@Test
69  	public void testGetPushConfigiOS() {
70  		getController().getPushConfig(PLATFORMS[0],getUiModel());
71  		assertTrue("Model was modified and should not have been.", getUiModel().asMap().isEmpty());
72  	}
73  
74  	@Test
75  	public void testGetPushConfigAndroid() {
76  		when(getKmeProperties().getProperty(any(String.class),any(String.class))).thenReturn(VALUE);
77  		getController().getPushConfig(PLATFORMS[1],getUiModel());
78  		assertTrue("Model wasn't modified for Android and should have been.", getUiModel().asMap().containsKey("applicationId"));
79  	}
80  
81  	@Test
82  	public void testGetPushConfigBlackberry() {
83  		when(getKmeProperties().getProperty(any(String.class))).thenReturn(VALUE);
84  		when(getBbPushConfig().getApplicationId()).thenReturn(VALUE);
85  		when(getBbPushConfig().getPushUrl()).thenReturn(VALUE);
86  		getController().getPushConfig(PLATFORMS[2], getUiModel());
87  		assertTrue("Model wasn't modified for Blackberry and should have been.",
88  			getUiModel().asMap().containsKey("applicationId")
89  			&& getUiModel().asMap().containsKey("registrationUrl")
90  			&& getUiModel().asMap().containsKey("port")
91  		);
92  	}
93  
94  	public Model getUiModel() {
95  		return uiModel;
96  	}
97  
98  	public void setUiModel(Model uiModel) {
99  		this.uiModel = uiModel;
100 	}
101 
102 	public PushConfigController getController() {
103 		return controller;
104 	}
105 
106 	public void setController(PushConfigController controller) {
107 		this.controller = controller;
108 	}
109 
110 	public Properties getKmeProperties() {
111 		return kmeProperties;
112 	}
113 
114 	public void setKmeProperties(Properties kmeProperties) {
115 		this.kmeProperties = kmeProperties;
116 	}
117 
118 	public BlackberryPushConfig getBbPushConfig() {
119 		return bbPushConfig;
120 	}
121 
122 	public void setBbPushConfig(BlackberryPushConfig bbPushConfig) {
123 		this.bbPushConfig = bbPushConfig;
124 	}
125 }