2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.dmaap.mmagent;
23 import static org.junit.Assert.*;
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;
37 @RunWith(PowerMockRunner.class)
38 @PowerMockIgnore("jdk.internal.reflect.*")
39 public class UpdateMirrorMakerTest {
42 public ExpectedException exceptionRule = ExpectedException.none();
44 MirrorMaker mirrorMaker;
45 UpdateMirrorMaker updateMirrorMaker;
46 JSONObject jsonObject;
49 public void setUp() throws Exception {
50 mirrorMaker = new MirrorMaker();
51 updateMirrorMaker = new UpdateMirrorMaker();
52 jsonObject = PowerMockito.mock(JSONObject.class);
54 mirrorMaker.setConsumer("test");
55 PowerMockito.when(jsonObject.has("consumer")).thenReturn(true);
57 mirrorMaker.setProducer("test");
58 PowerMockito.when(jsonObject.has("producer")).thenReturn(true);
60 mirrorMaker.setNumStreams(1);
61 PowerMockito.when(jsonObject.has("numStreams")).thenReturn(true);
63 PowerMockito.when(jsonObject.has("whitelist")).thenReturn(true);
67 public void tearDown() throws Exception {
71 public void testGetUpdateMirrorMaker() {
73 UpdateMirrorMaker mMaker = new UpdateMirrorMaker();
74 mMaker.getUpdateMirrorMaker();
81 public void testSetUpdateMirrorMaker() {
83 UpdateMirrorMaker mMaker = new UpdateMirrorMaker();
84 mMaker.setUpdateMirrorMaker(new MirrorMaker());
91 public void testGetMessageID() {
93 UpdateMirrorMaker mMaker = new UpdateMirrorMaker();
94 mMaker.getMessageID();
101 public void testSetMessageID() {
103 UpdateMirrorMaker mMaker = new UpdateMirrorMaker();
104 mMaker.setMessageID("messageID");
111 @Test(expected = CambriaApiException.class)
112 public void testValidateJSONNullConsumer() throws CambriaApiException {
113 mirrorMaker.setConsumer(null);
114 updateMirrorMaker.setUpdateMirrorMaker(mirrorMaker);
115 updateMirrorMaker.validateJSON(jsonObject);
118 @Test(expected = CambriaApiException.class)
119 public void testValidateJSONNullProducer() throws CambriaApiException {
120 mirrorMaker.setProducer(null);
121 updateMirrorMaker.setUpdateMirrorMaker(mirrorMaker);
122 updateMirrorMaker.validateJSON(jsonObject);
125 @Test(expected = CambriaApiException.class)
126 public void testValidateJSONNoNumStreams() throws CambriaApiException {
127 mirrorMaker.setNumStreams(0);
128 updateMirrorMaker.setUpdateMirrorMaker(mirrorMaker);
129 updateMirrorMaker.validateJSON(jsonObject);
132 @Test(expected = CambriaApiException.class)
133 public void testValidateJSONWhitelist() throws CambriaApiException {
134 PowerMockito.when(jsonObject.has("whitelist")).thenReturn(true);
136 updateMirrorMaker.setUpdateMirrorMaker(mirrorMaker);
137 updateMirrorMaker.validateJSON(jsonObject);