Junit for UpdateMirrorMaker.java
[dmaap/messagerouter/messageservice.git] / src / test / java / org / onap / dmaap / mmagent / UpdateMirrorMakerTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP Policy Engine
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21  package org.onap.dmaap.mmagent;
22
23 import static org.junit.Assert.*;
24
25 import org.json.JSONObject;
26 import org.junit.After;
27 import org.junit.Before;
28 import org.junit.Rule;
29 import org.junit.Test;
30 import org.junit.rules.ExpectedException;
31 import org.junit.runner.RunWith;
32 import org.onap.dmaap.dmf.mr.CambriaApiException;
33 import org.powermock.api.mockito.PowerMockito;
34 import org.powermock.modules.junit4.PowerMockRunner;
35
36 @RunWith(PowerMockRunner.class)
37 public class UpdateMirrorMakerTest {
38
39         @Rule
40         public ExpectedException exceptionRule = ExpectedException.none();
41
42         MirrorMaker mirrorMaker;
43         UpdateMirrorMaker updateMirrorMaker;
44         JSONObject jsonObject;
45
46         @Before
47         public void setUp() throws Exception {
48                 mirrorMaker = new MirrorMaker();
49                 updateMirrorMaker = new UpdateMirrorMaker();
50                 jsonObject = PowerMockito.mock(JSONObject.class);
51
52                 mirrorMaker.setConsumer("test");
53                 PowerMockito.when(jsonObject.has("consumer")).thenReturn(true);
54
55                 mirrorMaker.setProducer("test");
56                 PowerMockito.when(jsonObject.has("producer")).thenReturn(true);
57
58                 mirrorMaker.setNumStreams(1);
59                 PowerMockito.when(jsonObject.has("numStreams")).thenReturn(true);
60
61                 PowerMockito.when(jsonObject.has("whitelist")).thenReturn(true);
62         }
63
64         @After
65         public void tearDown() throws Exception {
66         }
67
68         @Test
69         public void testGetUpdateMirrorMaker() {
70
71                 UpdateMirrorMaker mMaker = new UpdateMirrorMaker();
72                 mMaker.getUpdateMirrorMaker();
73
74                 assertTrue(true);
75
76         }
77         
78         @Test
79         public void testSetUpdateMirrorMaker() {
80
81                 UpdateMirrorMaker mMaker = new UpdateMirrorMaker();
82                 mMaker.setUpdateMirrorMaker(new MirrorMaker());
83
84                 assertTrue(true);
85
86         }
87         
88         @Test
89         public void testGetMessageID() {
90
91                 UpdateMirrorMaker mMaker = new UpdateMirrorMaker();
92                 mMaker.getMessageID();
93
94                 assertTrue(true);
95
96         }
97         
98         @Test
99         public void testSetMessageID() {
100
101                 UpdateMirrorMaker mMaker = new UpdateMirrorMaker();
102                 mMaker.setMessageID("messageID");
103
104                 assertTrue(true);
105
106         }
107
108
109         @Test(expected = CambriaApiException.class)
110         public void testValidateJSONNullConsumer() throws CambriaApiException {
111                 mirrorMaker.setConsumer(null);
112                 updateMirrorMaker.setUpdateMirrorMaker(mirrorMaker);
113                 updateMirrorMaker.validateJSON(jsonObject);
114         }
115
116         @Test(expected = CambriaApiException.class)
117         public void testValidateJSONNullProducer() throws CambriaApiException {
118                 mirrorMaker.setProducer(null);
119                 updateMirrorMaker.setUpdateMirrorMaker(mirrorMaker);
120                 updateMirrorMaker.validateJSON(jsonObject);
121         }
122
123         @Test(expected = CambriaApiException.class)
124         public void testValidateJSONNoNumStreams() throws CambriaApiException {
125                 mirrorMaker.setNumStreams(0);
126                 updateMirrorMaker.setUpdateMirrorMaker(mirrorMaker);
127                 updateMirrorMaker.validateJSON(jsonObject);
128         }
129
130         @Test(expected = CambriaApiException.class)
131         public void testValidateJSONWhitelist() throws CambriaApiException {
132                 PowerMockito.when(jsonObject.has("whitelist")).thenReturn(true);
133
134                 updateMirrorMaker.setUpdateMirrorMaker(mirrorMaker);
135                 updateMirrorMaker.validateJSON(jsonObject);
136         }
137 }