[DMAAP MM] Update info.yaml
[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
27 import java.util.ArrayList;
28
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;
36
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;
41
42 @RunWith(PowerMockRunner.class)
43 public class TestMirrorMakerAgent {
44
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>();
50         Gson g = new Gson();
51         @InjectMocks
52         private MirrorMakerAgent agent;
53         @Mock
54         private TopicUtil topicUtil;
55
56         @Before
57         public void setUp() {
58                 MockitoAnnotations.initMocks(this);
59         }
60
61         @Test
62         public void testcheckStartup() {
63                 String currentDirectory = System.getProperty("user.dir");
64                 String MMAGENTHOME = currentDirectory + "/src/test/resources/";
65                 String parameters[] = { "-encrypt", "test" };
66                 String args[] = null;
67
68                 System.setProperty("MMAGENTHOME", MMAGENTHOME);
69                 mirrorMakerAgent.main(args);
70
71         }
72         
73         @Test
74         public void testcheckStartupWtOneParam() {
75                 String parameters[] = { "test" };
76                 mirrorMakerAgent.main(parameters);
77
78         }
79         
80
81         @Test
82         public void testReadAgentTopics() {
83
84                 agent.exitLoop = true;
85                 agent.readAgentTopic();
86         }
87
88         @Test
89         public void testReadCreateMirrorMaker() throws Exception {
90
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);
95
96         }
97
98         @Test
99         public void testReadUpdateMirrorMaker() throws Exception {
100
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);
105
106         }
107
108         @Test
109         public void testReadDeleteMirrorMaker() throws Exception {
110
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);
115
116         }
117
118         @Test
119         public void testReadListMirrorMaker() throws Exception {
120
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);
125
126         }
127
128         @Test
129         public void testReadWhitelistMirrorMaker() throws Exception {
130
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);
135
136         }
137
138         @Test
139         public void testCreateMirrorMaker() {
140                 mirrorMaker.setConsumer("consumer");
141                 mirrorMaker.setName("MirrorMaker1");
142                 mirrorMaker.setProducer("producer");
143                 mirrorMaker.setStatus("200");
144                 mirrorMaker.setWhitelist("whitelist");
145
146                 mirrorMaker2.setConsumer("consumer");
147                 mirrorMaker2.setName("MirrorMaker2");
148                 mirrorMaker2.setProducer("producer");
149                 mirrorMaker2.setStatus("200");
150                 mirrorMaker2.setWhitelist("whitelist");
151
152                 listsMirrorMaker.add(mirrorMaker2);
153                 listMirrorMaker.setListMirrorMaker(listsMirrorMaker);
154
155                 mirrorMakerAgent.mirrorMakers = listMirrorMaker;
156
157                 mirrorMakerAgent.createMirrorMaker(mirrorMaker);
158
159                 assertEquals(2, mirrorMakerAgent.mirrorMakers.getListMirrorMaker().size());
160         }
161
162         @Test
163         public void testPublish() {
164                 TopicUtil util = new TopicUtil();
165                 util.publishTopic("http://localhost:3904/events/testtopic", "topicname", "mechid", "password", "message");
166
167         }
168
169         @Test
170         public void testSubscribe() {
171                 TopicUtil util = new TopicUtil();
172                 util.subscribeTopic("http://localhost:3904/events/testtopic/cg/c", "topicname", "1", "mechid", "password");
173
174         }
175 }