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;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.onap.dmaap.dbcapi.model.ApiError;
28 import org.onap.dmaap.dbcapi.model.DcaeLocation;
29 import org.onap.dmaap.dbcapi.model.MR_Client;
30 import org.onap.dmaap.dbcapi.model.MR_Cluster;
31 import org.onap.dmaap.dbcapi.model.Topic;
32 import org.onap.dmaap.dbcapi.testframework.DmaapObjectFactory;
33 import org.onap.dmaap.dbcapi.testframework.ReflectionHarness;
35 public class MR_ClientServiceTest {
37 private static DmaapObjectFactory factory = new DmaapObjectFactory();
39 ReflectionHarness rh = new ReflectionHarness();
41 private TopicService ts;
42 private MR_ClusterService mcs;
43 private MR_ClientService cls;
44 private DcaeLocationService dls;
47 private String locname;
50 public void setUp() throws Exception {
51 System.setProperty("ConfigFile", "src/test/resources/dmaapbc.properties");
52 ts = new TopicService();
53 mcs = new MR_ClusterService();
54 cls = new MR_ClientService();
55 f = "mrsn01.onap.org";
56 locname = "central-demo";
58 dls = new DcaeLocationService();
59 DcaeLocation loc = factory.genDcaeLocation( "central" );
60 dls.addDcaeLocation( loc );
62 ApiError err = new ApiError();
63 String[] h = { "zplvm009.onap.org", "zplvm007.onap.org", "zplvm008.onap.org" };
64 MR_Cluster node = factory.genMR_Cluster( "central" );
65 MR_Cluster n2 = mcs.addMr_Cluster( node, err );
70 rh.reflect( "org.onap.dmaap.dbcapi.service.MR_ClientService", "get", null );
75 String v = "Validate";
76 rh.reflect( "org.onap.dmaap.dbcapi.service.MR_ClientService", "set", v );
81 Topic topic = factory.genSimpleTopic( "test3" );
82 ApiError err = new ApiError();
83 Topic nTopic = ts.addTopic( topic, err, false );
84 if ( nTopic != null ) {
85 assertTrue( nTopic.getTopicName().equals( topic.getTopicName() ));
88 MR_Client c = factory.genPublisher( "edge", topic.getFqtn() );
90 c = cls.addMr_Client( c, topic, err );
96 List<MR_Client> l = cls.getAllMr_Clients();
98 List<MR_Client> al = cls.getAllMrClients( "foo" );
100 List<MR_Client> al2 = cls.getClientsByLocation( "central" );
104 public void AddSubscriberToTopic() {
105 Topic topic = factory.genSimpleTopic( "test5" );
106 ApiError err = new ApiError();
107 Topic nTopic = ts.addTopic( topic, err, false );
108 if ( nTopic != null ) {
109 assertTrue( nTopic.getTopicName().equals( topic.getTopicName() ));
111 MR_Client c = factory.genPublisher( "central", topic.getFqtn() );
113 c = cls.addMr_Client( c, topic, err );
114 assertTrue( c != null );
116 c = factory.genSubscriber( "central", topic.getFqtn() );
117 c = cls.addMr_Client( c, topic, err );
118 assertTrue( err.getCode() == 200 );