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;
27 import org.junit.After;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.onap.dmaap.dbcapi.model.ApiError;
31 import org.onap.dmaap.dbcapi.model.DcaeLocation;
32 import org.onap.dmaap.dbcapi.model.MR_Client;
33 import org.onap.dmaap.dbcapi.model.MR_Cluster;
34 import org.onap.dmaap.dbcapi.model.Topic;
35 import org.onap.dmaap.dbcapi.testframework.DmaapObjectFactory;
36 import org.onap.dmaap.dbcapi.testframework.ReflectionHarness;
38 public class MR_ClientServiceTest {
40 private static final String fmt = "%24s: %s%n";
42 private static DmaapObjectFactory factory = new DmaapObjectFactory();
44 ReflectionHarness rh = new ReflectionHarness();
46 private TopicService ts;
47 private MR_ClusterService mcs;
48 private MR_ClientService cls;
49 private DcaeLocationService dls;
52 private String locname;
55 public void setUp() throws Exception {
56 ts = new TopicService();
57 mcs = new MR_ClusterService();
58 cls = new MR_ClientService();
59 f = "mrsn01.onap.org";
60 locname = "central-demo";
62 dls = new DcaeLocationService();
63 DcaeLocation loc = factory.genDcaeLocation( "central" );
64 dls.addDcaeLocation( loc );
66 ApiError err = new ApiError();
67 String[] h = { "zplvm009.onap.org", "zplvm007.onap.org", "zplvm008.onap.org" };
68 MR_Cluster node = factory.genMR_Cluster( "central" );
69 MR_Cluster n2 = mcs.addMr_Cluster( node, err );
73 public void tearDown() throws Exception {
81 rh.reflect( "org.onap.dmaap.dbcapi.service.MR_ClientService", "get", null );
87 String v = "Validate";
88 rh.reflect( "org.onap.dmaap.dbcapi.service.MR_ClientService", "set", v );
94 Topic topic = factory.genSimpleTopic( "test3" );
95 ApiError err = new ApiError();
96 Topic nTopic = ts.addTopic( topic, err, false );
97 if ( nTopic != null ) {
98 assertTrue( nTopic.getTopicName().equals( topic.getTopicName() ));
100 String[] actions = { "pub", "view" };
101 MR_Client c = factory.genPublisher( "edge", topic.getFqtn() );
103 c = cls.addMr_Client( c, topic, err );
108 public void test4() {
109 List<MR_Client> l = cls.getAllMr_Clients();
111 ArrayList<MR_Client> al = cls.getAllMrClients( "foo" );
113 ArrayList<MR_Client> al2 = cls.getClientsByLocation( "central" );
117 public void test5() {
118 Topic topic = factory.genSimpleTopic( "test5" );
119 ApiError err = new ApiError();
120 Topic nTopic = ts.addTopic( topic, err, false );
121 if ( nTopic != null ) {
122 assertTrue( nTopic.getTopicName().equals( topic.getTopicName() ));
124 MR_Client c = factory.genPublisher( "central", topic.getFqtn() );
126 c = cls.addMr_Client( c, topic, err );
128 c = factory.genSubscriber( "central", topic.getFqtn() );
129 c = cls.updateMr_Client( c, err );
130 assertTrue( err.getCode() == 200 );