[DMAAP-BC] Fix failing jenkins
[dmaap/buscontroller.git] / dmaap-bc / src / test / java / org / onap / dmaap / dbcapi / service / MirrorMakerServiceTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * org.onap.dmaap
4  * ================================================================================
5  * Copyright (C) 2018 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  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.dmaap.dbcapi.service;
21
22 import static org.junit.Assert.assertTrue;
23
24 import java.util.ArrayList;
25 import java.util.List;
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.onap.dmaap.dbcapi.model.ApiError;
29 import org.onap.dmaap.dbcapi.model.DcaeLocation;
30 import org.onap.dmaap.dbcapi.model.Dmaap;
31 import org.onap.dmaap.dbcapi.model.MR_Client;
32 import org.onap.dmaap.dbcapi.model.MR_Cluster;
33 import org.onap.dmaap.dbcapi.model.MirrorMaker;
34 import org.onap.dmaap.dbcapi.model.ReplicationType;
35 import org.onap.dmaap.dbcapi.model.Topic;
36 import org.onap.dmaap.dbcapi.testframework.DmaapObjectFactory;
37 import org.onap.dmaap.dbcapi.testframework.ReflectionHarness;
38
39 public class MirrorMakerServiceTest {
40
41         private static DmaapObjectFactory factory = new DmaapObjectFactory();
42         ReflectionHarness rh = new ReflectionHarness();
43
44         private MirrorMakerService mms;
45         private TopicService ts;
46         private MR_ClusterService mcs;
47         private MR_ClientService cls;
48         private DcaeLocationService dls;
49         
50         private Topic replicationTopic;
51
52         DmaapService ds;
53         String locname;
54
55         @Before
56         public void setUp() throws Exception {
57                 System.setProperty("ConfigFile", "src/test/resources/dmaapbc.properties");
58                 mms = new MirrorMakerService();
59                 ts = new TopicService();
60                 assert( ts != null );
61                 mcs = new MR_ClusterService();
62                 assert( mcs != null );
63                 Dmaap nd = factory.genDmaap();
64                 ds = new DmaapService();
65                 ds.addDmaap( nd );
66                 ts = new TopicService();
67                 mcs = new MR_ClusterService();
68                 cls = new MR_ClientService();
69
70                 dls = new DcaeLocationService();
71                 DcaeLocation loc = factory.genDcaeLocation( "central" );
72                 locname = loc.getDcaeLocationName();
73                 dls.addDcaeLocation( loc );
74                 loc = factory.genDcaeLocation( "edge");
75                 dls.addDcaeLocation( loc );
76
77                 ApiError err = new ApiError();
78                 
79                 MR_Cluster node = factory.genMR_Cluster( "central" );
80                 mcs.addMr_Cluster( node, err);
81                 node = factory.genMR_Cluster("edge" );
82                 mcs.addMr_Cluster(node,  err);
83
84
85                 String t = "org.onap.dmaap.bridgingTopic";
86                 replicationTopic = factory.genSimpleTopic(t);
87                 replicationTopic.setReplicationCase( ReplicationType.REPLICATION_EDGE_TO_CENTRAL );
88
89                 String c = "publisher";
90                 String[] a = { "sub", "view" };
91                 MR_Client sub = factory.genMR_Client("central",  replicationTopic.getFqtn(), c, a );
92                 String[] b = { "pub", "view" };
93                 MR_Client pub = factory.genMR_Client( "edge", replicationTopic.getFqtn(), c, b );
94                 ArrayList<MR_Client> clients = new ArrayList<MR_Client>();
95
96                 clients.add( sub );
97                 clients.add( pub );
98
99                 replicationTopic.setClients( clients );
100         }
101
102         @Test
103         public void test_setters() {
104                 String v = "Validate";
105                 rh.reflect( "org.onap.dmaap.dbcapi.service.MirrorMakerService", "set", v );
106         }
107         
108         @Test
109         public void CreateMirrorMakerWithSingleTopic() {
110                 ApiError err = new ApiError();
111                 Topic nTopic = ts.addTopic(replicationTopic, err, true );
112
113                 assertTrue( err.getCode() == 200 );
114                 
115                 List<String> mma = mms.getAllMirrorMakers();
116         }
117         
118         @Test
119         public void DeleteMirrorMakerWithSingleTopic() {
120
121                 ApiError err = new ApiError();
122                 Topic nTopic = ts.addTopic(replicationTopic, err, true );
123                 replicationTopic.setTopicDescription("modified topic");
124                 nTopic = ts.updateTopic( replicationTopic, err );
125
126                 assertTrue( err.getCode() == 200 );
127
128                 
129                 List<String> mma = mms.getAllMirrorMakers();
130                 
131                 int nMM = mma.size();
132                 assertTrue( nMM >= 1);
133                 
134                 String name = mma.get(0);
135                 
136                 MirrorMaker mm = mms.getMirrorMaker(name);
137                 
138                 mms.delMirrorMaker(mm);
139                 
140                 mma = mms.getAllMirrorMakers();
141                 
142                 assertTrue( mma.size() == (nMM-1) );
143         }
144         
145         @Test
146         public void SplitMirrorMakerWithSingleTopic() {
147
148                 ApiError err = new ApiError();
149
150
151                 Topic nTopic = ts.addTopic( replicationTopic, err, true );
152                 replicationTopic.setTopicDescription("modified topic");
153                 nTopic = ts.updateTopic( replicationTopic, err );
154
155
156                 assertTrue( err.getCode() == 200 );
157                 List<String> mma = mms.getAllMirrorMakers();
158                 
159                 int nMM = mma.size();
160                 assertTrue( nMM >= 1);
161                 
162                 String name = mma.get(0);
163                 
164                 MirrorMaker mm = mms.getMirrorMaker(name);
165                 
166                 MirrorMaker mm2 = mms.splitMM(mm);
167         }
168
169 }