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.List;
26 import org.junit.After;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.onap.dmaap.dbcapi.model.ApiError;
30 import org.onap.dmaap.dbcapi.model.DcaeLocation;
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.Topic;
34 import org.onap.dmaap.dbcapi.testframework.DmaapObjectFactory;
35 import org.onap.dmaap.dbcapi.testframework.ReflectionHarness;
37 public class MR_ClientServiceTest {
39 private static final String fmt = "%24s: %s%n";
41 private static DmaapObjectFactory factory = new DmaapObjectFactory();
43 ReflectionHarness rh = new ReflectionHarness();
45 private TopicService ts;
46 private MR_ClusterService mcs;
47 private MR_ClientService cls;
48 private DcaeLocationService dls;
51 private String locname;
54 public void setUp() throws Exception {
55 ts = new TopicService();
56 mcs = new MR_ClusterService();
57 cls = new MR_ClientService();
58 f = "mrsn01.onap.org";
59 locname = "central-demo";
61 dls = new DcaeLocationService();
62 DcaeLocation loc = factory.genDcaeLocation( "central" );
63 dls.addDcaeLocation( loc );
65 ApiError err = new ApiError();
66 String[] h = { "zplvm009.onap.org", "zplvm007.onap.org", "zplvm008.onap.org" };
67 MR_Cluster node = factory.genMR_Cluster( "central" );
68 MR_Cluster n2 = mcs.addMr_Cluster( node, err );
72 public void tearDown() throws Exception {
80 rh.reflect( "org.onap.dmaap.dbcapi.service.MR_ClientService", "get", null );
86 String v = "Validate";
87 rh.reflect( "org.onap.dmaap.dbcapi.service.MR_ClientService", "set", v );
93 Topic topic = factory.genSimpleTopic( "test3" );
94 ApiError err = new ApiError();
95 Topic nTopic = ts.addTopic( topic, err, false );
96 if ( nTopic != null ) {
97 assertTrue( nTopic.getTopicName().equals( topic.getTopicName() ));
100 MR_Client c = factory.genPublisher( "edge", topic.getFqtn() );
102 c = cls.addMr_Client( c, topic, err );
107 public void test4() {
108 List<MR_Client> l = cls.getAllMr_Clients();
110 List<MR_Client> al = cls.getAllMrClients( "foo" );
112 List<MR_Client> al2 = cls.getClientsByLocation( "central" );
116 public void AddSubscriberToTopic() {
117 Topic topic = factory.genSimpleTopic( "test5" );
118 ApiError err = new ApiError();
119 Topic nTopic = ts.addTopic( topic, err, false );
120 if ( nTopic != null ) {
121 assertTrue( nTopic.getTopicName().equals( topic.getTopicName() ));
123 MR_Client c = factory.genPublisher( "central", topic.getFqtn() );
125 c = cls.addMr_Client( c, topic, err );
126 assertTrue( c != null );
128 c = factory.genSubscriber( "central", topic.getFqtn() );
129 c = cls.addMr_Client( c, topic, err );
130 assertTrue( err.getCode() == 200 );