2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 package org.onap.dmaap.dbcapi.service;
22 import org.onap.dmaap.dbcapi.model.*;
23 import org.onap.dmaap.dbcapi.testframework.DmaapObjectFactory;
24 import org.onap.dmaap.dbcapi.testframework.ReflectionHarness;
26 import static org.junit.Assert.*;
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;
34 public class MirrorMakerServiceTest {
36 private static final String fmt = "%24s: %s%n";
37 private static DmaapObjectFactory factory = new DmaapObjectFactory();
38 ReflectionHarness rh = new ReflectionHarness();
40 private MirrorMakerService mms;
41 private TopicService ts;
42 private MR_ClusterService mcs;
43 private MR_ClientService cls;
44 private DcaeLocationService dls;
50 public void setUp() throws Exception {
51 mms = new MirrorMakerService();
52 ts = new TopicService();
54 mcs = new MR_ClusterService();
55 assert( mcs != null );
56 Dmaap nd = factory.genDmaap();
57 ds = new DmaapService();
59 ts = new TopicService();
60 mcs = new MR_ClusterService();
61 cls = new MR_ClientService();
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 );
70 ApiError err = new ApiError();
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);
79 public void tearDown() throws Exception {
84 // public void test_getters() {
87 // rh.reflect( "org.onap.dmaap.dbcapi.service.MirrorMakerService", "get", null );
92 public void test_setters() {
93 String v = "Validate";
94 rh.reflect( "org.onap.dmaap.dbcapi.service.MirrorMakerService", "set", v );
101 public void CreateMirrorMakerWithSingleTopic() {
102 ApiError err = new ApiError();
104 String t = "org.onap.dmaap.bridgingTopic";
105 Topic topic = factory.genSimpleTopic(t);
106 topic.setReplicationCase( ReplicationType.REPLICATION_EDGE_TO_CENTRAL );
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>();
118 topic.setClients( clients );
120 Topic nTopic = ts.updateTopic( topic, err );
122 assertTrue( err.getCode() == 200 );
124 List<String> mma = mms.getAllMirrorMakers();
128 public void DeleteMirrorMakerWithSingleTopic() {
131 List<String> mma = mms.getAllMirrorMakers();
133 int nMM = mma.size();
134 assertTrue( nMM >= 1);
136 String name = mma.get(0);
138 MirrorMaker mm = mms.getMirrorMaker(name);
140 mms.delMirrorMaker(mm);
142 mma = mms.getAllMirrorMakers();
144 assertTrue( mma.size() == (nMM-1) );
148 public void SplitMirrorMakerWithSingleTopic() {
150 ApiError err = new ApiError();
152 String t = "org.onap.dmaap.bridgingTopic";
153 Topic topic = factory.genSimpleTopic(t);
154 topic.setReplicationCase( ReplicationType.REPLICATION_EDGE_TO_CENTRAL );
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>();
166 topic.setClients( clients );
168 Topic nTopic = ts.updateTopic( topic, err );
170 assertTrue( err.getCode() == 200 );
171 List<String> mma = mms.getAllMirrorMakers();
173 int nMM = mma.size();
174 assertTrue( nMM >= 1);
176 String name = mma.get(0);
178 MirrorMaker mm = mms.getMirrorMaker(name);
180 MirrorMaker mm2 = mms.splitMM(mm);