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 static org.junit.Assert.assertTrue;
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;
39 public class MirrorMakerServiceTest {
41 private static DmaapObjectFactory factory = new DmaapObjectFactory();
42 ReflectionHarness rh = new ReflectionHarness();
44 private MirrorMakerService mms;
45 private TopicService ts;
46 private MR_ClusterService mcs;
47 private MR_ClientService cls;
48 private DcaeLocationService dls;
50 private Topic replicationTopic;
56 public void setUp() throws Exception {
57 System.setProperty("ConfigFile", "src/test/resources/dmaapbc.properties");
58 mms = new MirrorMakerService();
59 ts = new TopicService();
61 mcs = new MR_ClusterService();
62 assert( mcs != null );
63 Dmaap nd = factory.genDmaap();
64 ds = new DmaapService();
66 ts = new TopicService();
67 mcs = new MR_ClusterService();
68 cls = new MR_ClientService();
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 );
77 ApiError err = new ApiError();
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);
85 String t = "org.onap.dmaap.bridgingTopic";
86 replicationTopic = factory.genSimpleTopic(t);
87 replicationTopic.setReplicationCase( ReplicationType.REPLICATION_EDGE_TO_CENTRAL );
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>();
99 replicationTopic.setClients( clients );
103 public void test_setters() {
104 String v = "Validate";
105 rh.reflect( "org.onap.dmaap.dbcapi.service.MirrorMakerService", "set", v );
109 public void CreateMirrorMakerWithSingleTopic() {
110 ApiError err = new ApiError();
111 Topic nTopic = ts.addTopic(replicationTopic, err, true );
113 assertTrue( err.getCode() == 200 );
115 List<String> mma = mms.getAllMirrorMakers();
119 public void DeleteMirrorMakerWithSingleTopic() {
121 ApiError err = new ApiError();
122 Topic nTopic = ts.addTopic(replicationTopic, err, true );
123 replicationTopic.setTopicDescription("modified topic");
124 nTopic = ts.updateTopic( replicationTopic, err );
126 assertTrue( err.getCode() == 200 );
129 List<String> mma = mms.getAllMirrorMakers();
131 int nMM = mma.size();
132 assertTrue( nMM >= 1);
134 String name = mma.get(0);
136 MirrorMaker mm = mms.getMirrorMaker(name);
138 mms.delMirrorMaker(mm);
140 mma = mms.getAllMirrorMakers();
142 assertTrue( mma.size() == (nMM-1) );
146 public void SplitMirrorMakerWithSingleTopic() {
148 ApiError err = new ApiError();
151 Topic nTopic = ts.addTopic( replicationTopic, err, true );
152 replicationTopic.setTopicDescription("modified topic");
153 nTopic = ts.updateTopic( replicationTopic, err );
156 assertTrue( err.getCode() == 200 );
157 List<String> mma = mms.getAllMirrorMakers();
159 int nMM = mma.size();
160 assertTrue( nMM >= 1);
162 String name = mma.get(0);
164 MirrorMaker mm = mms.getMirrorMaker(name);
166 MirrorMaker mm2 = mms.splitMM(mm);