Add unit test cases
[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
27 import java.io.DataOutputStream;
28 import java.io.FileInputStream;
29 import java.io.FileNotFoundException;
30 import java.net.HttpURLConnection;
31 import java.util.ArrayList;
32
33 import org.junit.Test;
34 import org.junit.runner.RunWith;
35 import org.powermock.api.mockito.PowerMockito;
36 import org.powermock.core.classloader.annotations.Mock;
37 import org.powermock.modules.junit4.PowerMockRunner;
38
39 import com.att.nsa.dmaapMMAgent.dao.ListMirrorMaker;
40 import com.att.nsa.dmaapMMAgent.dao.MirrorMaker;
41
42 @RunWith(PowerMockRunner.class)
43 public class TestMirrorMakerAgent {
44         MirrorMakerAgent mirrorMakerAgent = new MirrorMakerAgent();
45         ListMirrorMaker listMirrorMaker = new ListMirrorMaker();
46         MirrorMaker mirrorMaker = new MirrorMaker();
47         MirrorMaker mirrorMaker2 = new MirrorMaker();
48         ArrayList<MirrorMaker> listsMirrorMaker = new ArrayList<MirrorMaker>();
49
50         @Test
51         public void testcheckStartup() {
52                 String currentDirectory = System.getProperty("user.dir");
53                 String MMAGENTHOME = currentDirectory + "/src/test/resources/";
54                 String parameters[] = {"-encrypt", "test"};
55                 String args[] = null;
56                 
57                 System.setProperty("MMAGENTHOME", MMAGENTHOME);
58                 
59                 mirrorMakerAgent.main(args);
60                 
61         }
62         
63         @Test
64         public void testCreateMirrorMaker() {
65                 mirrorMaker.setConsumer("consumer");
66                 mirrorMaker.setName("MirrorMaker1");
67                 mirrorMaker.setProducer("producer");
68                 mirrorMaker.setStatus("200");
69                 mirrorMaker.setWhitelist("whitelist");
70                 
71                 mirrorMaker2.setConsumer("consumer");
72                 mirrorMaker2.setName("MirrorMaker2");
73                 mirrorMaker2.setProducer("producer");
74                 mirrorMaker2.setStatus("200");
75                 mirrorMaker2.setWhitelist("whitelist");
76                 
77                 listsMirrorMaker.add(mirrorMaker2);
78                 listMirrorMaker.setListMirrorMaker(listsMirrorMaker);
79                 
80                 mirrorMakerAgent.mirrorMakers = listMirrorMaker;
81                 
82                 mirrorMakerAgent.createMirrorMaker(mirrorMaker);
83                 
84                 assertEquals(2, mirrorMakerAgent.mirrorMakers.getListMirrorMaker().size());
85         }
86
87 }