update link to upper-constraints.txt
[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.core.classloader.annotations.PowerMockIgnore;
35 import org.powermock.modules.junit4.PowerMockRunner;
36
37 @RunWith(PowerMockRunner.class)
38 @PowerMockIgnore("jdk.internal.reflect.*")
39 public class UpdateMirrorMakerTest {
40
41         @Rule
42         public ExpectedException exceptionRule = ExpectedException.none();
43
44         MirrorMaker mirrorMaker;
45         UpdateMirrorMaker updateMirrorMaker;
46         JSONObject jsonObject;
47
48         @Before
49         public void setUp() throws Exception {
50                 mirrorMaker = new MirrorMaker();
51                 updateMirrorMaker = new UpdateMirrorMaker();
52                 jsonObject = PowerMockito.mock(JSONObject.class);
53
54                 mirrorMaker.setConsumer("test");
55                 PowerMockito.when(jsonObject.has("consumer")).thenReturn(true);
56
57                 mirrorMaker.setProducer("test");
58                 PowerMockito.when(jsonObject.has("producer")).thenReturn(true);
59
60                 mirrorMaker.setNumStreams(1);
61                 PowerMockito.when(jsonObject.has("numStreams")).thenReturn(true);
62
63                 PowerMockito.when(jsonObject.has("whitelist")).thenReturn(true);
64         }
65
66         @After
67         public void tearDown() throws Exception {
68         }
69
70         @Test
71         public void testGetUpdateMirrorMaker() {
72
73                 UpdateMirrorMaker mMaker = new UpdateMirrorMaker();
74                 mMaker.getUpdateMirrorMaker();
75
76                 assertTrue(true);
77
78         }
79         
80         @Test
81         public void testSetUpdateMirrorMaker() {
82
83                 UpdateMirrorMaker mMaker = new UpdateMirrorMaker();
84                 mMaker.setUpdateMirrorMaker(new MirrorMaker());
85
86                 assertTrue(true);
87
88         }
89         
90         @Test
91         public void testGetMessageID() {
92
93                 UpdateMirrorMaker mMaker = new UpdateMirrorMaker();
94                 mMaker.getMessageID();
95
96                 assertTrue(true);
97
98         }
99         
100         @Test
101         public void testSetMessageID() {
102
103                 UpdateMirrorMaker mMaker = new UpdateMirrorMaker();
104                 mMaker.setMessageID("messageID");
105
106                 assertTrue(true);
107
108         }
109
110
111         @Test(expected = CambriaApiException.class)
112         public void testValidateJSONNullConsumer() throws CambriaApiException {
113                 mirrorMaker.setConsumer(null);
114                 updateMirrorMaker.setUpdateMirrorMaker(mirrorMaker);
115                 updateMirrorMaker.validateJSON(jsonObject);
116         }
117
118         @Test(expected = CambriaApiException.class)
119         public void testValidateJSONNullProducer() throws CambriaApiException {
120                 mirrorMaker.setProducer(null);
121                 updateMirrorMaker.setUpdateMirrorMaker(mirrorMaker);
122                 updateMirrorMaker.validateJSON(jsonObject);
123         }
124
125         @Test(expected = CambriaApiException.class)
126         public void testValidateJSONNoNumStreams() throws CambriaApiException {
127                 mirrorMaker.setNumStreams(0);
128                 updateMirrorMaker.setUpdateMirrorMaker(mirrorMaker);
129                 updateMirrorMaker.validateJSON(jsonObject);
130         }
131
132         @Test(expected = CambriaApiException.class)
133         public void testValidateJSONWhitelist() throws CambriaApiException {
134                 PowerMockito.when(jsonObject.has("whitelist")).thenReturn(true);
135
136                 updateMirrorMaker.setUpdateMirrorMaker(mirrorMaker);
137                 updateMirrorMaker.validateJSON(jsonObject);
138         }
139 }