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 TopicServiceTest {
36 private static final String fmt = "%24s: %s%n";
37 private static DmaapObjectFactory factory = new DmaapObjectFactory();
38 ReflectionHarness rh = new ReflectionHarness();
40 private TopicService ts;
41 private MR_ClusterService mcs;
42 private MR_ClientService cls;
43 private DcaeLocationService dls;
49 public void setUp() throws Exception {
50 ts = new TopicService();
52 mcs = new MR_ClusterService();
53 assert( mcs != null );
54 Dmaap nd = factory.genDmaap();
55 ds = new DmaapService();
57 ts = new TopicService();
58 mcs = new MR_ClusterService();
59 cls = new MR_ClientService();
61 dls = new DcaeLocationService();
62 DcaeLocation loc = factory.genDcaeLocation( "central" );
63 locname = loc.getDcaeLocationName();
64 dls.addDcaeLocation( loc );
65 loc = factory.genDcaeLocation( "edge");
67 ApiError err = new ApiError();
69 MR_Cluster node = factory.genMR_Cluster( "central" );
70 mcs.addMr_Cluster( node, err);
71 node = factory.genMR_Cluster("edge" );
72 mcs.addMr_Cluster(node, err);
76 public void tearDown() throws Exception {
84 rh.reflect( "org.onap.dmaap.dbcapi.service.TopicService", "get", null );
90 String v = "Validate";
91 rh.reflect( "org.onap.dmaap.dbcapi.service.TopicService", "set", v );
98 Topic topic = factory.genSimpleTopic( t );
99 ApiError err = new ApiError();
101 Topic nTopic = ts.addTopic( topic, err, false );
102 if ( nTopic != null ) {
103 assertTrue( nTopic.getTopicName().equals( t ));
109 public void test3a() {
112 ApiError err = new ApiError();
114 String t = "org.onap.dmaap.interestingTopic";
115 Topic topic = factory.genSimpleTopic(t);
116 String f = "mrc.onap.org:3904/events/org.onap.dmaap.interestingTopic";
117 String c = "publisher";
118 String[] a = { "sub", "view" };
119 MR_Client sub = factory.genMR_Client("central", f, c, a );
120 String[] b = { "pub", "view" };
121 MR_Client pub = factory.genMR_Client( "edge", f, c, b );
122 ArrayList<MR_Client> clients = new ArrayList<MR_Client>();
127 topic.setClients( clients );
129 ts.reviewTopic( topic );
130 ts.checkForBridge( topic, err );
132 Topic nTopic = ts.addTopic( topic, err, false );
133 if ( nTopic != null ) {
134 assertTrue( nTopic.getTopicName().equals( t ));
138 ts.removeTopic( "test3", err );
142 public void test4() {
143 List<Topic> l = ts.getAllTopics();
148 public void test5() {
149 ApiError err = new ApiError();
151 Topic topic = factory.genSimpleTopic("test5");
152 Topic nTopic = ts.updateTopic( topic, err );
154 assertTrue( err.getCode() == 200 );
158 public void bridgeTest6() {
159 ApiError err = new ApiError();
161 String t = "org.onap.dmaap.bridgingTopic";
162 Topic topic = factory.genSimpleTopic(t);
163 topic.setReplicationCase( ReplicationType.REPLICATION_EDGE_TO_CENTRAL );
165 String c = "publisher";
166 String[] a = { "sub", "view" };
167 MR_Client sub = factory.genMR_Client("central", topic.getFqtn(), c, a );
168 String[] b = { "pub", "view" };
169 MR_Client pub = factory.genMR_Client( "edge", topic.getFqtn(), c, b );
170 ArrayList<MR_Client> clients = new ArrayList<MR_Client>();
175 topic.setClients( clients );
177 Topic nTopic = ts.updateTopic( topic, err );
179 assertTrue( err.getCode() == 200 );
182 public void bridgeTest7() {
183 ApiError err = new ApiError();
185 String t = "org.onap.dmaap.bridgingTopic7";
186 Topic topic = factory.genSimpleTopic(t);
187 topic.setReplicationCase( ReplicationType.REPLICATION_CENTRAL_TO_EDGE );
189 String c = "publisher";
190 String[] a = { "sub", "view" };
191 MR_Client sub = factory.genMR_Client("edge", topic.getFqtn(), c, a );
192 String[] b = { "pub", "view" };
193 MR_Client pub = factory.genMR_Client( "central", topic.getFqtn(), c, b );
194 ArrayList<MR_Client> clients = new ArrayList<MR_Client>();
199 topic.setClients( clients );
201 Topic nTopic = ts.updateTopic( topic, err );
203 assertTrue( err.getCode() == 200 );