[DMAAP-BC] Consolidate bus controller repos
[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  org.onap.dmaap.dbcapi.model.*;
23 import org.onap.dmaap.dbcapi.testframework.DmaapObjectFactory;
24 import org.onap.dmaap.dbcapi.testframework.ReflectionHarness;
25
26 import static org.junit.Assert.*;
27
28 import org.junit.After;
29 import org.junit.Before;
30 import org.junit.Test;
31 import java.util.List;
32 import java.util.ArrayList;
33
34 public class MirrorMakerServiceTest {
35
36         private static final String  fmt = "%24s: %s%n";
37         private static DmaapObjectFactory factory = new DmaapObjectFactory();
38         ReflectionHarness rh = new ReflectionHarness();
39
40         private MirrorMakerService mms;
41         private TopicService ts;
42         private MR_ClusterService mcs;
43         private MR_ClientService cls;
44         private DcaeLocationService dls;
45         
46         private Topic replicationTopic;
47
48
49         DmaapService ds;
50         String locname;
51
52         @Before
53         public void setUp() throws Exception {
54                 mms = new MirrorMakerService();
55                 ts = new TopicService();
56                 assert( ts != null );
57                 mcs = new MR_ClusterService();
58                 assert( mcs != null );
59                 Dmaap nd = factory.genDmaap();
60                 ds = new DmaapService();
61                 ds.addDmaap( nd );
62                 ts = new TopicService();
63                 mcs = new MR_ClusterService();
64                 cls = new MR_ClientService();
65
66                 dls = new DcaeLocationService();
67                 DcaeLocation loc = factory.genDcaeLocation( "central" );
68                 locname = loc.getDcaeLocationName();
69                 dls.addDcaeLocation( loc );
70                 loc = factory.genDcaeLocation( "edge");
71                 dls.addDcaeLocation( loc );
72
73                 ApiError err = new ApiError();
74                 
75                 MR_Cluster node = factory.genMR_Cluster( "central" );
76                 mcs.addMr_Cluster( node, err);
77                 node = factory.genMR_Cluster("edge" );
78                 mcs.addMr_Cluster(node,  err);
79
80
81                 String t = "org.onap.dmaap.bridgingTopic";
82                 replicationTopic = factory.genSimpleTopic(t);
83                 replicationTopic.setReplicationCase( ReplicationType.REPLICATION_EDGE_TO_CENTRAL );
84
85                 String c = "publisher";
86                 String[] a = { "sub", "view" };
87                 MR_Client sub = factory.genMR_Client("central",  replicationTopic.getFqtn(), c, a );
88                 String[] b = { "pub", "view" };
89                 MR_Client pub = factory.genMR_Client( "edge", replicationTopic.getFqtn(), c, b );
90                 ArrayList<MR_Client> clients = new ArrayList<MR_Client>();
91
92                 clients.add( sub );
93                 clients.add( pub );
94
95                 replicationTopic.setClients( clients );
96
97         }
98
99         @After
100         public void tearDown() throws Exception {
101         }
102
103
104 //      @Test
105 //      public void test_getters() {
106 //
107 //
108 //              rh.reflect( "org.onap.dmaap.dbcapi.service.MirrorMakerService", "get", null );  
109 //      
110 //      }
111
112         @Test
113         public void test_setters() {
114                 String v = "Validate";
115                 rh.reflect( "org.onap.dmaap.dbcapi.service.MirrorMakerService", "set", v );
116
117         }
118
119         
120         
121         @Test
122         public void CreateMirrorMakerWithSingleTopic() {
123                 ApiError err = new ApiError();
124
125
126                 Topic nTopic = ts.addTopic(replicationTopic, err, true );
127
128                 assertTrue( err.getCode() == 200 );
129                 
130                 List<String> mma = mms.getAllMirrorMakers();
131         }
132         
133         @Test
134         public void DeleteMirrorMakerWithSingleTopic() {
135
136                 ApiError err = new ApiError();
137                 Topic nTopic = ts.addTopic(replicationTopic, err, true );
138                 replicationTopic.setTopicDescription("modified topic");
139                 nTopic = ts.updateTopic( replicationTopic, err );
140
141                 assertTrue( err.getCode() == 200 );
142
143                 
144                 List<String> mma = mms.getAllMirrorMakers();
145                 
146                 int nMM = mma.size();
147                 assertTrue( nMM >= 1);
148                 
149                 String name = mma.get(0);
150                 
151                 MirrorMaker mm = mms.getMirrorMaker(name);
152                 
153                 mms.delMirrorMaker(mm);
154                 
155                 mma = mms.getAllMirrorMakers();
156                 
157                 assertTrue( mma.size() == (nMM-1) );
158         }
159         
160         @Test
161         public void SplitMirrorMakerWithSingleTopic() {
162
163                 ApiError err = new ApiError();
164
165
166                 Topic nTopic = ts.addTopic( replicationTopic, err, true );
167                 replicationTopic.setTopicDescription("modified topic");
168                 nTopic = ts.updateTopic( replicationTopic, err );
169
170
171                 assertTrue( err.getCode() == 200 );
172                 List<String> mma = mms.getAllMirrorMakers();
173                 
174                 int nMM = mma.size();
175                 assertTrue( nMM >= 1);
176                 
177                 String name = mma.get(0);
178                 
179                 MirrorMaker mm = mms.getMirrorMaker(name);
180                 
181                 MirrorMaker mm2 = mms.splitMM(mm);      
182
183         }
184
185 }