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.modules.junit4.PowerMockRunner;
36 @RunWith(PowerMockRunner.class)
37 public class UpdateMirrorMakerTest {
40 public ExpectedException exceptionRule = ExpectedException.none();
42 MirrorMaker mirrorMaker;
43 UpdateMirrorMaker updateMirrorMaker;
44 JSONObject jsonObject;
47 public void setUp() throws Exception {
48 mirrorMaker = new MirrorMaker();
49 updateMirrorMaker = new UpdateMirrorMaker();
50 jsonObject = PowerMockito.mock(JSONObject.class);
52 mirrorMaker.setConsumer("test");
53 PowerMockito.when(jsonObject.has("consumer")).thenReturn(true);
55 mirrorMaker.setProducer("test");
56 PowerMockito.when(jsonObject.has("producer")).thenReturn(true);
58 mirrorMaker.setNumStreams(1);
59 PowerMockito.when(jsonObject.has("numStreams")).thenReturn(true);
61 PowerMockito.when(jsonObject.has("whitelist")).thenReturn(true);
65 public void tearDown() throws Exception {
69 public void testGetUpdateMirrorMaker() {
71 UpdateMirrorMaker mMaker = new UpdateMirrorMaker();
72 mMaker.getUpdateMirrorMaker();
79 public void testSetUpdateMirrorMaker() {
81 UpdateMirrorMaker mMaker = new UpdateMirrorMaker();
82 mMaker.setUpdateMirrorMaker(new MirrorMaker());
89 public void testGetMessageID() {
91 UpdateMirrorMaker mMaker = new UpdateMirrorMaker();
92 mMaker.getMessageID();
99 public void testSetMessageID() {
101 UpdateMirrorMaker mMaker = new UpdateMirrorMaker();
102 mMaker.setMessageID("messageID");
109 @Test(expected = CambriaApiException.class)
110 public void testValidateJSONNullConsumer() throws CambriaApiException {
111 mirrorMaker.setConsumer(null);
112 updateMirrorMaker.setUpdateMirrorMaker(mirrorMaker);
113 updateMirrorMaker.validateJSON(jsonObject);
116 @Test(expected = CambriaApiException.class)
117 public void testValidateJSONNullProducer() throws CambriaApiException {
118 mirrorMaker.setProducer(null);
119 updateMirrorMaker.setUpdateMirrorMaker(mirrorMaker);
120 updateMirrorMaker.validateJSON(jsonObject);
123 @Test(expected = CambriaApiException.class)
124 public void testValidateJSONNoNumStreams() throws CambriaApiException {
125 mirrorMaker.setNumStreams(0);
126 updateMirrorMaker.setUpdateMirrorMaker(mirrorMaker);
127 updateMirrorMaker.validateJSON(jsonObject);
130 @Test(expected = CambriaApiException.class)
131 public void testValidateJSONWhitelist() throws CambriaApiException {
132 PowerMockito.when(jsonObject.has("whitelist")).thenReturn(true);
134 updateMirrorMaker.setUpdateMirrorMaker(mirrorMaker);
135 updateMirrorMaker.validateJSON(jsonObject);