Merge "Updated the testcases"
[dmaap/messagerouter/mirroragent.git] / src / test / java / com / att / nsa / 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 com.att.nsa.dmaapMMAgent;
24
25 import static org.junit.Assert.*;
26 import static org.mockito.Mockito.spy;
27 import static org.mockito.Mockito.when;
28
29 import java.util.ArrayList;
30
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.mockito.MockitoAnnotations;
35 import org.powermock.modules.junit4.PowerMockRunner;
36
37 import com.att.nsa.dmaapMMAgent.dao.ListMirrorMaker;
38 import com.att.nsa.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         MirrorMakerAgent agent = spy(new MirrorMakerAgent());
52
53         @Before
54         public void setUp() {
55                 MockitoAnnotations.initMocks(this);
56         }
57
58         @Test
59         public void testcheckStartup() {
60                 String currentDirectory = System.getProperty("user.dir");
61                 String MMAGENTHOME = currentDirectory + "/src/test/resources/";
62                 String parameters[] = { "-encrypt", "test" };
63                 String args[] = null;
64
65                 System.setProperty("MMAGENTHOME", MMAGENTHOME);
66                 mirrorMakerAgent.main(args);
67
68         }
69
70         @Test
71         public void testReadAgentTopics() {
72                 when(agent.subscribeTopic("60000")).thenReturn(null);
73                 agent.exitLoop = true;
74                 agent.readAgentTopic();
75         }
76
77         @Test
78         public void testReadCreateMirrorMaker() {
79                 when(agent.publishTopic(
80                                 "{\"messageID\":\"test\",\"listMirrorMaker\":[{\"name\":\"test\",\"consumer\":\"test\",\"producer\":\"test\",\"status\":\"STOPPED\"}]}"))
81                                                 .thenReturn(null);
82                 String topicMessage = "{ messageID:\"test\", createMirrorMaker: {   name:\"test\",   consumer:\"test\",  producer:\"test\"}}";
83                 LinkedTreeMap<?, ?> object = g.fromJson(topicMessage, LinkedTreeMap.class);
84                 agent.readAgent(object, topicMessage);
85
86         }
87
88         @Test
89         public void testReadUpdateMirrorMaker() {
90                 when(agent.publishTopic(
91                                 "{\"messageID\":\"test\",\"listMirrorMaker\":[{\"name\":\"test\",\"consumer\":\"test\",\"producer\":\"test\",\"status\":\"STOPPED\"}]}"))
92                                                 .thenReturn(null);
93                 String topicMessage = "{ messageID:\"test\", updateMirrorMaker: {   name:\"test\",   consumer:\"test\",  producer:\"test\"}}";
94                 LinkedTreeMap<?, ?> object = g.fromJson(topicMessage, LinkedTreeMap.class);
95                 testReadCreateMirrorMaker();
96                 agent.readAgent(object, topicMessage);
97
98         }
99
100         @Test
101         public void testReadDeleteMirrorMaker() {
102                 when(agent.publishTopic(
103                                 "{\"messageID\":\"test\",\"listMirrorMaker\":[{\"name\":\"test\",\"consumer\":\"test\",\"producer\":\"test\",\"status\":\"STOPPED\"}]}"))
104                                                 .thenReturn(null);
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() {
114                 when(agent.publishTopic(
115                                 "{\"messageID\":\"test\",\"listMirrorMaker\":[{\"name\":\"test\",\"consumer\":\"test\",\"producer\":\"test\",\"status\":\"STOPPED\"}]}"))
116                                                 .thenReturn(null);
117                 String topicMessage = "{ messageID:\"test\", listAllMirrorMaker: {   name:\"test\",   consumer:\"test\",  producer:\"test\",  whitelist:\"test\",status:\"test\" }}";
118                 LinkedTreeMap<?, ?> object = g.fromJson(topicMessage, LinkedTreeMap.class);
119                 testReadCreateMirrorMaker();
120                 agent.readAgent(object, topicMessage);
121
122         }
123
124         @Test
125         public void testReadWhitelistMirrorMaker() {
126                 when(agent.publishTopic(
127                                 "{\"messageID\":\"test\",\"listMirrorMaker\":[{\"name\":\"test\",\"consumer\":\"test\",\"producer\":\"test\",\"status\":\"STOPPED\"}]}"))
128                                                 .thenReturn(null);
129                 String topicMessage = "{ messageID:\"test\", updateWhiteList: {   name:\"test\",   consumer:\"test\",  producer:\"test\",  whitelist:\"test\",status:\"test\" }}";
130                 LinkedTreeMap<?, ?> object = g.fromJson(topicMessage, LinkedTreeMap.class);
131                 testReadCreateMirrorMaker();
132                 agent.readAgent(object, topicMessage);
133
134         }
135
136         @Test
137         public void testCreateMirrorMaker() {
138                 mirrorMaker.setConsumer("consumer");
139                 mirrorMaker.setName("MirrorMaker1");
140                 mirrorMaker.setProducer("producer");
141                 mirrorMaker.setStatus("200");
142                 mirrorMaker.setWhitelist("whitelist");
143
144                 mirrorMaker2.setConsumer("consumer");
145                 mirrorMaker2.setName("MirrorMaker2");
146                 mirrorMaker2.setProducer("producer");
147                 mirrorMaker2.setStatus("200");
148                 mirrorMaker2.setWhitelist("whitelist");
149
150                 listsMirrorMaker.add(mirrorMaker2);
151                 listMirrorMaker.setListMirrorMaker(listsMirrorMaker);
152
153                 mirrorMakerAgent.mirrorMakers = listMirrorMaker;
154
155                 mirrorMakerAgent.createMirrorMaker(mirrorMaker);
156
157                 assertEquals(2, mirrorMakerAgent.mirrorMakers.getListMirrorMaker().size());
158         }
159
160 }

© 2017 ONAP. Copyright © The Linux Foundation ®. All Rights Reserved.
The Linux Foundation has registered trademarks and uses trademarks.
For a list of trademarks of The Linux Foundation, please see our Trademark Usage page.
Linux is a registered trademark of Linus Torvalds.
Privacy Policy and Terms of Use