1 /*******************************************************************************
2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 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 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ============LICENSE_END=========================================================
19 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21 *******************************************************************************/
23 package org.onap.dmaap.mr.dmaapMMAgent;
25 import static org.junit.Assert.*;
26 import static org.mockito.Mockito.spy;
28 import java.util.ArrayList;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.mockito.InjectMocks;
34 import org.mockito.Mock;
35 import org.mockito.MockitoAnnotations;
36 import org.powermock.core.classloader.annotations.PowerMockIgnore;
37 import org.powermock.modules.junit4.PowerMockRunner;
39 import org.onap.dmaap.mr.dmaapMMAgent.dao.ListMirrorMaker;
40 import org.onap.dmaap.mr.dmaapMMAgent.dao.MirrorMaker;
41 import com.google.gson.Gson;
42 import com.google.gson.internal.LinkedTreeMap;
44 @RunWith(PowerMockRunner.class)
45 public class TestMirrorMakerAgent {
47 MirrorMakerAgent mirrorMakerAgent = new MirrorMakerAgent();
48 ListMirrorMaker listMirrorMaker = new ListMirrorMaker();
49 MirrorMaker mirrorMaker = new MirrorMaker();
50 MirrorMaker mirrorMaker2 = new MirrorMaker();
51 ArrayList<MirrorMaker> listsMirrorMaker = new ArrayList<MirrorMaker>();
54 private MirrorMakerAgent agent;
56 private TopicUtil topicUtil;
60 MockitoAnnotations.initMocks(this);
64 public void testcheckStartup() {
65 String currentDirectory = System.getProperty("user.dir");
66 String MMAGENTHOME = currentDirectory + "/src/test/resources/";
67 String parameters[] = { "-encrypt", "test" };
70 System.setProperty("MMAGENTHOME", MMAGENTHOME);
71 mirrorMakerAgent.main(args);
76 public void testReadAgentTopics() {
78 agent.exitLoop = true;
79 agent.readAgentTopic();
83 public void testReadCreateMirrorMaker() throws Exception {
85 String topicMessage = "{ messageID:\"test\", createMirrorMaker: { name:\"test\", consumer:\"test\", producer:\"test\"}}";
86 LinkedTreeMap<?, ?> object = g.fromJson(topicMessage, LinkedTreeMap.class);
87 agent.exitLoop = true;
88 agent.readAgent(object, topicMessage);
93 public void testReadUpdateMirrorMaker() throws Exception {
95 String topicMessage = "{ messageID:\"test\", updateMirrorMaker: { name:\"test\", consumer:\"test\", producer:\"test\"}}";
96 LinkedTreeMap<?, ?> object = g.fromJson(topicMessage, LinkedTreeMap.class);
97 testReadCreateMirrorMaker();
98 agent.readAgent(object, topicMessage);
103 public void testReadDeleteMirrorMaker() throws Exception {
105 String topicMessage = "{ messageID:\"test\", deleteMirrorMaker: { name:\"test\", consumer:\"test\", producer:\"test\", whitelist:\"test\",status:\"test\" }}";
106 LinkedTreeMap<?, ?> object = g.fromJson(topicMessage, LinkedTreeMap.class);
107 testReadCreateMirrorMaker();
108 agent.readAgent(object, topicMessage);
113 public void testReadListMirrorMaker() throws Exception {
115 String topicMessage = "{ messageID:\"test\", listAllMirrorMaker: { name:\"test\", consumer:\"test\", producer:\"test\", whitelist:\"test\",status:\"test\" }}";
116 LinkedTreeMap<?, ?> object = g.fromJson(topicMessage, LinkedTreeMap.class);
117 testReadCreateMirrorMaker();
118 agent.readAgent(object, topicMessage);
123 public void testReadWhitelistMirrorMaker() throws Exception {
125 String topicMessage = "{ messageID:\"test\", updateWhiteList: { name:\"test\", consumer:\"test\", producer:\"test\", whitelist:\"test\",status:\"test\" }}";
126 LinkedTreeMap<?, ?> object = g.fromJson(topicMessage, LinkedTreeMap.class);
127 testReadCreateMirrorMaker();
128 agent.readAgent(object, topicMessage);
133 public void testCreateMirrorMaker() {
134 mirrorMaker.setConsumer("consumer");
135 mirrorMaker.setName("MirrorMaker1");
136 mirrorMaker.setProducer("producer");
137 mirrorMaker.setStatus("200");
138 mirrorMaker.setWhitelist("whitelist");
140 mirrorMaker2.setConsumer("consumer");
141 mirrorMaker2.setName("MirrorMaker2");
142 mirrorMaker2.setProducer("producer");
143 mirrorMaker2.setStatus("200");
144 mirrorMaker2.setWhitelist("whitelist");
146 listsMirrorMaker.add(mirrorMaker2);
147 listMirrorMaker.setListMirrorMaker(listsMirrorMaker);
149 mirrorMakerAgent.mirrorMakers = listMirrorMaker;
151 mirrorMakerAgent.createMirrorMaker(mirrorMaker);
153 assertEquals(2, mirrorMakerAgent.mirrorMakers.getListMirrorMaker().size());
157 public void testPublish() {
158 TopicUtil util = new TopicUtil();
159 util.publishTopic("topicURL", "topicname", "mechid", "password", "message");
164 public void testSubscribe() {
165 TopicUtil util = new TopicUtil();
166 util.subscribeTopic("topicURL", "topicname", "1", "mechid", "password");