More unit tests to pass 50%
[dmaap/dbcapi.git] / 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.ArrayList;
25 import java.util.List;
26
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;
37
38 public class MR_ClientServiceTest {
39
40         private static final String  fmt = "%24s: %s%n";
41         
42         private static DmaapObjectFactory factory = new DmaapObjectFactory();
43
44         ReflectionHarness rh = new ReflectionHarness();
45
46         private TopicService ts;
47         private MR_ClusterService mcs;
48         private MR_ClientService cls;
49         private DcaeLocationService dls;
50
51         private String f;
52         private String locname;
53
54         @Before
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";
61
62                 dls = new DcaeLocationService();
63                 DcaeLocation loc = factory.genDcaeLocation( "central" );
64                 dls.addDcaeLocation( loc );
65
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 ); 
70         }
71
72         @After
73         public void tearDown() throws Exception {
74         }
75
76
77         @Test
78         public void test1() {
79
80
81                 rh.reflect( "org.onap.dmaap.dbcapi.service.MR_ClientService", "get", null );    
82         
83         }
84
85         @Test
86         public void test2() {
87                 String v = "Validate";
88                 rh.reflect( "org.onap.dmaap.dbcapi.service.MR_ClientService", "set", v );
89
90         }
91
92         @Test
93         public void test3() {
94                 Topic topic = factory.genSimpleTopic( "test3" );
95                 ApiError err = new ApiError();
96                 Topic nTopic = ts.addTopic( topic, err );
97                 if ( nTopic != null ) {
98                         assertTrue( nTopic.getTopicName().equals( topic.getTopicName() ));
99                 }
100                 String[] actions = { "pub", "view" };
101                 MR_Client c = factory.genPublisher( "edge",  topic.getFqtn() );
102
103                 c = cls.addMr_Client( c, topic, err );
104
105         }
106
107         @Test
108         public void test4() {
109                 List<MR_Client> l = cls.getAllMr_Clients();
110
111                 ArrayList<MR_Client> al = cls.getAllMrClients( "foo" );
112
113                 ArrayList<MR_Client> al2 = cls.getClientsByLocation( "central" );
114         }
115
116         @Test
117         public void test5() {
118                 Topic topic = factory.genSimpleTopic( "test5" );
119                 ApiError err = new ApiError();
120                 Topic nTopic = ts.addTopic( topic, err );
121                 if ( nTopic != null ) {
122                         assertTrue( nTopic.getTopicName().equals( topic.getTopicName() ));
123                 }
124                 MR_Client c = factory.genPublisher( "central", topic.getFqtn() );
125
126                 c = cls.addMr_Client( c, topic, err );
127                 if ( c != null ) {
128                                 c = factory.genSubscriber( "central", topic.getFqtn() );
129                                 c = cls.updateMr_Client( c, err );
130                                 assertTrue( err.getCode() == 200 );
131                 }
132         }
133
134 }