f7b14d448132e70b51cce5234715121e29423dfc
[dmaap/messagerouter/mirroragent.git] / src / test / java / org / onap / dmaap / mr / dmaapMMAgent / TestMirrorMakerAgent.java
1 /*******************************************************************************
2  *  ============LICENSE_START=======================================================
3  *  org.onap.dmaap
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
11  *  
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=========================================================
18  *
19  *  ECOMP is a trademark and service mark of AT&T Intellectual Property.
20  *  
21  *******************************************************************************/
22
23 package org.onap.dmaap.mr.dmaapMMAgent;
24
25 import static org.junit.Assert.*;
26 import static org.mockito.Mockito.spy;
27
28 import java.util.ArrayList;
29
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;
38
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;
43
44 @RunWith(PowerMockRunner.class)
45 public class TestMirrorMakerAgent {
46
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>();
52         Gson g = new Gson();
53         @InjectMocks
54         private MirrorMakerAgent agent;
55         @Mock
56         private TopicUtil topicUtil;
57
58         @Before
59         public void setUp() {
60                 MockitoAnnotations.initMocks(this);
61         }
62
63         @Test
64         public void testcheckStartup() {
65                 String currentDirectory = System.getProperty("user.dir");
66                 String MMAGENTHOME = currentDirectory + "/src/test/resources/";
67                 String parameters[] = { "-encrypt", "test" };
68                 String args[] = null;
69
70                 System.setProperty("MMAGENTHOME", MMAGENTHOME);
71                 mirrorMakerAgent.main(args);
72
73         }
74
75         @Test
76         public void testReadAgentTopics() {
77
78                 agent.exitLoop = true;
79                 agent.readAgentTopic();
80         }
81
82         @Test
83         public void testReadCreateMirrorMaker() throws Exception {
84
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);
89
90         }
91
92         @Test
93         public void testReadUpdateMirrorMaker() throws Exception {
94
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);
99
100         }
101
102         @Test
103         public void testReadDeleteMirrorMaker() throws Exception {
104
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);
109
110         }
111
112         @Test
113         public void testReadListMirrorMaker() throws Exception {
114
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);
119
120         }
121
122         @Test
123         public void testReadWhitelistMirrorMaker() throws Exception {
124
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);
129
130         }
131
132         @Test
133         public void testCreateMirrorMaker() {
134                 mirrorMaker.setConsumer("consumer");
135                 mirrorMaker.setName("MirrorMaker1");
136                 mirrorMaker.setProducer("producer");
137                 mirrorMaker.setStatus("200");
138                 mirrorMaker.setWhitelist("whitelist");
139
140                 mirrorMaker2.setConsumer("consumer");
141                 mirrorMaker2.setName("MirrorMaker2");
142                 mirrorMaker2.setProducer("producer");
143                 mirrorMaker2.setStatus("200");
144                 mirrorMaker2.setWhitelist("whitelist");
145
146                 listsMirrorMaker.add(mirrorMaker2);
147                 listMirrorMaker.setListMirrorMaker(listsMirrorMaker);
148
149                 mirrorMakerAgent.mirrorMakers = listMirrorMaker;
150
151                 mirrorMakerAgent.createMirrorMaker(mirrorMaker);
152
153                 assertEquals(2, mirrorMakerAgent.mirrorMakers.getListMirrorMaker().size());
154         }
155
156         @Test
157         public void testPublish() {
158                 TopicUtil util = new TopicUtil();
159                 util.publishTopic("topicURL", "topicname", "mechid", "password", "message");
160
161         }
162
163         @Test
164         public void testSubscribe() {
165                 TopicUtil util = new TopicUtil();
166                 util.subscribeTopic("topicURL", "topicname", "1", "mechid", "password");
167
168         }
169 }