e80697a3b2c4c8fe11398281e925e5451e8edc97
[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
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;
36
37 public class MR_ClientServiceTest {
38
39         private static final String  fmt = "%24s: %s%n";
40         
41         private static DmaapObjectFactory factory = new DmaapObjectFactory();
42
43         ReflectionHarness rh = new ReflectionHarness();
44
45         private TopicService ts;
46         private MR_ClusterService mcs;
47         private MR_ClientService cls;
48         private DcaeLocationService dls;
49
50         private String f;
51         private String locname;
52
53         @Before
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";
60
61                 dls = new DcaeLocationService();
62                 DcaeLocation loc = factory.genDcaeLocation( "central" );
63                 dls.addDcaeLocation( loc );
64
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 ); 
69         }
70
71         @After
72         public void tearDown() throws Exception {
73         }
74
75
76         @Test
77         public void test1() {
78
79
80                 rh.reflect( "org.onap.dmaap.dbcapi.service.MR_ClientService", "get", null );    
81         
82         }
83
84         @Test
85         public void test2() {
86                 String v = "Validate";
87                 rh.reflect( "org.onap.dmaap.dbcapi.service.MR_ClientService", "set", v );
88
89         }
90
91         @Test
92         public void test3() {
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() ));
98                 }
99
100                 MR_Client c = factory.genPublisher( "edge",  topic.getFqtn() );
101
102                 c = cls.addMr_Client( c, topic, err );
103
104         }
105
106         @Test
107         public void test4() {
108                 List<MR_Client> l = cls.getAllMr_Clients();
109
110                 List<MR_Client> al = cls.getAllMrClients( "foo" );
111
112                 List<MR_Client> al2 = cls.getClientsByLocation( "central" );
113         }
114
115         @Test
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() ));
122                 }
123                 MR_Client c = factory.genPublisher( "central", topic.getFqtn() );
124
125                 c = cls.addMr_Client( c, topic, err );
126                 assertTrue( c != null );
127
128                 c = factory.genSubscriber( "central", topic.getFqtn() );
129                 c = cls.addMr_Client( c, topic, err );
130                 assertTrue( err.getCode() == 200 );
131
132                 
133         }
134         
135 }