[DMAAP-BC] Fix failing jenkins
[dmaap/buscontroller.git] / dmaap-bc / src / test / java / org / onap / dmaap / dbcapi / service / MR_ClientServiceTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * org.onap.dmaap
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20 package org.onap.dmaap.dbcapi.service;
21
22 import static org.junit.Assert.assertTrue;
23
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;
34
35 public class MR_ClientServiceTest {
36
37         private static DmaapObjectFactory factory = new DmaapObjectFactory();
38
39         ReflectionHarness rh = new ReflectionHarness();
40
41         private TopicService ts;
42         private MR_ClusterService mcs;
43         private MR_ClientService cls;
44         private DcaeLocationService dls;
45
46         private String f;
47         private String locname;
48
49         @Before
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";
57
58                 dls = new DcaeLocationService();
59                 DcaeLocation loc = factory.genDcaeLocation( "central" );
60                 dls.addDcaeLocation( loc );
61
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 ); 
66         }
67
68         @Test
69         public void test1() {
70                 rh.reflect( "org.onap.dmaap.dbcapi.service.MR_ClientService", "get", null );
71         }
72
73         @Test
74         public void test2() {
75                 String v = "Validate";
76                 rh.reflect( "org.onap.dmaap.dbcapi.service.MR_ClientService", "set", v );
77         }
78
79         @Test
80         public void test3() {
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() ));
86                 }
87
88                 MR_Client c = factory.genPublisher( "edge",  topic.getFqtn() );
89
90                 c = cls.addMr_Client( c, topic, err );
91
92         }
93
94         @Test
95         public void test4() {
96                 List<MR_Client> l = cls.getAllMr_Clients();
97
98                 List<MR_Client> al = cls.getAllMrClients( "foo" );
99
100                 List<MR_Client> al2 = cls.getClientsByLocation( "central" );
101         }
102
103         @Test
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() ));
110                 }
111                 MR_Client c = factory.genPublisher( "central", topic.getFqtn() );
112
113                 c = cls.addMr_Client( c, topic, err );
114                 assertTrue( c != null );
115
116                 c = factory.genSubscriber( "central", topic.getFqtn() );
117                 c = cls.addMr_Client( c, topic, err );
118                 assertTrue( err.getCode() == 200 );
119
120         }
121 }