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
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.modules.junit4.PowerMockRunner;
37
38 import com.att.nsa.dmaapMMAgent.dao.ListMirrorMaker;
39 import com.att.nsa.dmaapMMAgent.dao.MirrorMaker;
40 import com.google.gson.Gson;
41 import com.google.gson.internal.LinkedTreeMap;
42
43 @RunWith(PowerMockRunner.class)
44 public class TestMirrorMakerAgent {
45
46         MirrorMakerAgent mirrorMakerAgent = new MirrorMakerAgent();
47         ListMirrorMaker listMirrorMaker = new ListMirrorMaker();
48         MirrorMaker mirrorMaker = new MirrorMaker();
49         MirrorMaker mirrorMaker2 = new MirrorMaker();
50         ArrayList<MirrorMaker> listsMirrorMaker = new ArrayList<MirrorMaker>();
51         Gson g = new Gson();
52         @InjectMocks
53         private MirrorMakerAgent agent;
54         @Mock
55         private TopicUtil topicUtil;
56
57         @Before
58         public void setUp() {
59                 MockitoAnnotations.initMocks(this);
60         }
61
62         @Test
63         public void testcheckStartup() {
64                 String currentDirectory = System.getProperty("user.dir");
65                 String MMAGENTHOME = currentDirectory + "/src/test/resources/";
66                 String parameters[] = { "-encrypt", "test" };
67                 String args[] = null;
68
69                 System.setProperty("MMAGENTHOME", MMAGENTHOME);
70                 mirrorMakerAgent.main(args);
71
72         }
73
74         @Test
75         public void testReadAgentTopics() {
76                 
77                 agent.exitLoop = true;
78                 agent.readAgentTopic();
79         }
80
81         @Test
82         public void testReadCreateMirrorMaker() {
83                 
84                 String topicMessage = "{ messageID:\"test\", createMirrorMaker: {   name:\"test\",   consumer:\"test\",  producer:\"test\"}}";
85                 LinkedTreeMap<?, ?> object = g.fromJson(topicMessage, LinkedTreeMap.class);
86                 agent.readAgent(object, topicMessage);
87
88         }
89
90         @Test
91         public void testReadUpdateMirrorMaker() {
92                 
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                 
103                 String topicMessage = "{ messageID:\"test\", deleteMirrorMaker: {   name:\"test\",   consumer:\"test\",  producer:\"test\",  whitelist:\"test\",status:\"test\" }}";
104                 LinkedTreeMap<?, ?> object = g.fromJson(topicMessage, LinkedTreeMap.class);
105                 testReadCreateMirrorMaker();
106                 agent.readAgent(object, topicMessage);
107
108         }
109
110         @Test
111         public void testReadListMirrorMaker() {
112                 
113                 String topicMessage = "{ messageID:\"test\", listAllMirrorMaker: {   name:\"test\",   consumer:\"test\",  producer:\"test\",  whitelist:\"test\",status:\"test\" }}";
114                 LinkedTreeMap<?, ?> object = g.fromJson(topicMessage, LinkedTreeMap.class);
115                 testReadCreateMirrorMaker();
116                 agent.readAgent(object, topicMessage);
117
118         }
119
120         @Test
121         public void testReadWhitelistMirrorMaker() {
122                 
123                 String topicMessage = "{ messageID:\"test\", updateWhiteList: {   name:\"test\",   consumer:\"test\",  producer:\"test\",  whitelist:\"test\",status:\"test\" }}";
124                 LinkedTreeMap<?, ?> object = g.fromJson(topicMessage, LinkedTreeMap.class);
125                 testReadCreateMirrorMaker();
126                 agent.readAgent(object, topicMessage);
127
128         }
129
130         @Test
131         public void testCreateMirrorMaker() {
132                 mirrorMaker.setConsumer("consumer");
133                 mirrorMaker.setName("MirrorMaker1");
134                 mirrorMaker.setProducer("producer");
135                 mirrorMaker.setStatus("200");
136                 mirrorMaker.setWhitelist("whitelist");
137
138                 mirrorMaker2.setConsumer("consumer");
139                 mirrorMaker2.setName("MirrorMaker2");
140                 mirrorMaker2.setProducer("producer");
141                 mirrorMaker2.setStatus("200");
142                 mirrorMaker2.setWhitelist("whitelist");
143
144                 listsMirrorMaker.add(mirrorMaker2);
145                 listMirrorMaker.setListMirrorMaker(listsMirrorMaker);
146
147                 mirrorMakerAgent.mirrorMakers = listMirrorMaker;
148
149                 mirrorMakerAgent.createMirrorMaker(mirrorMaker);
150
151                 assertEquals(2, mirrorMakerAgent.mirrorMakers.getListMirrorMaker().size());
152         }
153
154 }

© 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