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;
46 private Topic replicationTopic;
53 public void setUp() throws Exception {
54 mms = new MirrorMakerService();
55 ts = new TopicService();
57 mcs = new MR_ClusterService();
58 assert( mcs != null );
59 Dmaap nd = factory.genDmaap();
60 ds = new DmaapService();
62 ts = new TopicService();
63 mcs = new MR_ClusterService();
64 cls = new MR_ClientService();
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 );
73 ApiError err = new ApiError();
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);
81 String t = "org.onap.dmaap.bridgingTopic";
82 replicationTopic = factory.genSimpleTopic(t);
83 replicationTopic.setReplicationCase( ReplicationType.REPLICATION_EDGE_TO_CENTRAL );
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>();
95 replicationTopic.setClients( clients );
100 public void tearDown() throws Exception {
105 // public void test_getters() {
108 // rh.reflect( "org.onap.dmaap.dbcapi.service.MirrorMakerService", "get", null );
113 public void test_setters() {
114 String v = "Validate";
115 rh.reflect( "org.onap.dmaap.dbcapi.service.MirrorMakerService", "set", v );
122 public void CreateMirrorMakerWithSingleTopic() {
123 ApiError err = new ApiError();
126 Topic nTopic = ts.addTopic(replicationTopic, err, true );
128 assertTrue( err.getCode() == 200 );
130 List<String> mma = mms.getAllMirrorMakers();
134 public void DeleteMirrorMakerWithSingleTopic() {
136 ApiError err = new ApiError();
137 Topic nTopic = ts.addTopic(replicationTopic, err, true );
138 replicationTopic.setTopicDescription("modified topic");
139 nTopic = ts.updateTopic( replicationTopic, err );
141 assertTrue( err.getCode() == 200 );
144 List<String> mma = mms.getAllMirrorMakers();
146 int nMM = mma.size();
147 assertTrue( nMM >= 1);
149 String name = mma.get(0);
151 MirrorMaker mm = mms.getMirrorMaker(name);
153 mms.delMirrorMaker(mm);
155 mma = mms.getAllMirrorMakers();
157 assertTrue( mma.size() == (nMM-1) );
161 public void SplitMirrorMakerWithSingleTopic() {
163 ApiError err = new ApiError();
166 Topic nTopic = ts.addTopic( replicationTopic, err, true );
167 replicationTopic.setTopicDescription("modified topic");
168 nTopic = ts.updateTopic( replicationTopic, err );
171 assertTrue( err.getCode() == 200 );
172 List<String> mma = mms.getAllMirrorMakers();
174 int nMM = mma.size();
175 assertTrue( nMM >= 1);
177 String name = mma.get(0);
179 MirrorMaker mm = mms.getMirrorMaker(name);
181 MirrorMaker mm2 = mms.splitMM(mm);