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.*;
27 import java.util.ArrayList;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.mockito.InjectMocks;
33 import org.mockito.Mock;
34 import org.mockito.MockitoAnnotations;
35 import org.powermock.modules.junit4.PowerMockRunner;
37 import org.onap.dmaap.mr.dmaapMMAgent.dao.ListMirrorMaker;
38 import org.onap.dmaap.mr.dmaapMMAgent.dao.MirrorMaker;
39 import com.google.gson.Gson;
40 import com.google.gson.internal.LinkedTreeMap;
42 @RunWith(PowerMockRunner.class)
43 public class TestMirrorMakerAgent {
45 MirrorMakerAgent mirrorMakerAgent = new MirrorMakerAgent();
46 ListMirrorMaker listMirrorMaker = new ListMirrorMaker();
47 MirrorMaker mirrorMaker = new MirrorMaker();
48 MirrorMaker mirrorMaker2 = new MirrorMaker();
49 ArrayList<MirrorMaker> listsMirrorMaker = new ArrayList<MirrorMaker>();
52 private MirrorMakerAgent agent;
54 private TopicUtil topicUtil;
58 MockitoAnnotations.initMocks(this);
62 public void testcheckStartup() {
63 String currentDirectory = System.getProperty("user.dir");
64 String MMAGENTHOME = currentDirectory + "/src/test/resources/";
65 String parameters[] = { "-encrypt", "test" };
68 System.setProperty("MMAGENTHOME", MMAGENTHOME);
69 mirrorMakerAgent.main(args);
74 public void testcheckStartupWtOneParam() {
75 String parameters[] = { "test" };
76 mirrorMakerAgent.main(parameters);
82 public void testReadAgentTopics() {
84 agent.exitLoop = true;
85 agent.readAgentTopic();
89 public void testReadCreateMirrorMaker() throws Exception {
91 String topicMessage = "{ messageID:\"test\", createMirrorMaker: { name:\"test\", consumer:\"test\", producer:\"test\"}}";
92 LinkedTreeMap<?, ?> object = g.fromJson(topicMessage, LinkedTreeMap.class);
93 agent.exitLoop = true;
94 agent.readAgent(object, topicMessage);
99 public void testReadUpdateMirrorMaker() throws Exception {
101 String topicMessage = "{ messageID:\"test\", updateMirrorMaker: { name:\"test\", consumer:\"test\", producer:\"test\"}}";
102 LinkedTreeMap<?, ?> object = g.fromJson(topicMessage, LinkedTreeMap.class);
103 testReadCreateMirrorMaker();
104 agent.readAgent(object, topicMessage);
109 public void testReadDeleteMirrorMaker() throws Exception {
111 String topicMessage = "{ messageID:\"test\", deleteMirrorMaker: { name:\"test\", consumer:\"test\", producer:\"test\", whitelist:\"test\",status:\"test\" }}";
112 LinkedTreeMap<?, ?> object = g.fromJson(topicMessage, LinkedTreeMap.class);
113 testReadCreateMirrorMaker();
114 agent.readAgent(object, topicMessage);
119 public void testReadListMirrorMaker() throws Exception {
121 String topicMessage = "{ messageID:\"test\", listAllMirrorMaker: { name:\"test\", consumer:\"test\", producer:\"test\", whitelist:\"test\",status:\"test\" }}";
122 LinkedTreeMap<?, ?> object = g.fromJson(topicMessage, LinkedTreeMap.class);
123 testReadCreateMirrorMaker();
124 agent.readAgent(object, topicMessage);
129 public void testReadWhitelistMirrorMaker() throws Exception {
131 String topicMessage = "{ messageID:\"test\", updateWhiteList: { name:\"test\", consumer:\"test\", producer:\"test\", whitelist:\"test\",status:\"test\" }}";
132 LinkedTreeMap<?, ?> object = g.fromJson(topicMessage, LinkedTreeMap.class);
133 testReadCreateMirrorMaker();
134 agent.readAgent(object, topicMessage);
139 public void testCreateMirrorMaker() {
140 mirrorMaker.setConsumer("consumer");
141 mirrorMaker.setName("MirrorMaker1");
142 mirrorMaker.setProducer("producer");
143 mirrorMaker.setStatus("200");
144 mirrorMaker.setWhitelist("whitelist");
146 mirrorMaker2.setConsumer("consumer");
147 mirrorMaker2.setName("MirrorMaker2");
148 mirrorMaker2.setProducer("producer");
149 mirrorMaker2.setStatus("200");
150 mirrorMaker2.setWhitelist("whitelist");
152 listsMirrorMaker.add(mirrorMaker2);
153 listMirrorMaker.setListMirrorMaker(listsMirrorMaker);
155 mirrorMakerAgent.mirrorMakers = listMirrorMaker;
157 mirrorMakerAgent.createMirrorMaker(mirrorMaker);
159 assertEquals(2, mirrorMakerAgent.mirrorMakers.getListMirrorMaker().size());
163 public void testPublish() {
164 TopicUtil util = new TopicUtil();
165 util.publishTopic("http://localhost:3904/events/testtopic", "topicname", "mechid", "password", "message");
170 public void testSubscribe() {
171 TopicUtil util = new TopicUtil();
172 util.subscribeTopic("http://localhost:3904/events/testtopic/cg/c", "topicname", "1", "mechid", "password");