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