Updates for more code coverage
[dmaap/dbcapi.git] / src / test / java / org / onap / dmaap / dbcapi / service / TopicServiceTest.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  org.onap.dmaap.dbcapi.model.*;
23 import org.onap.dmaap.dbcapi.testframework.DmaapObjectFactory;
24 import org.onap.dmaap.dbcapi.testframework.ReflectionHarness;
25
26 import static org.junit.Assert.*;
27
28 import org.junit.After;
29 import org.junit.Before;
30 import org.junit.Test;
31 import java.util.List;
32 import java.util.ArrayList;
33
34 public class TopicServiceTest {
35
36         private static final String  fmt = "%24s: %s%n";
37         private static DmaapObjectFactory factory = new DmaapObjectFactory();
38         ReflectionHarness rh = new ReflectionHarness();
39
40         private TopicService ts;
41         private MR_ClusterService mcs;
42         private MR_ClientService cls;
43         private DcaeLocationService dls;
44
45         DmaapService ds;
46         String locname;
47
48         @Before
49         public void setUp() throws Exception {
50                 ts = new TopicService();
51                 assert( ts != null );
52                 mcs = new MR_ClusterService();
53                 assert( mcs != null );
54                 Dmaap nd = factory.genDmaap();
55                 ds = new DmaapService();
56                 ds.addDmaap( nd );
57                 ts = new TopicService();
58                 mcs = new MR_ClusterService();
59                 cls = new MR_ClientService();
60
61                 dls = new DcaeLocationService();
62                 DcaeLocation loc = factory.genDcaeLocation( "central" );
63                 locname = loc.getDcaeLocationName();
64                 dls.addDcaeLocation( loc );
65                 loc = factory.genDcaeLocation( "edge");
66
67                 ApiError err = new ApiError();
68                 
69                 MR_Cluster node = factory.genMR_Cluster( "central" );
70                 mcs.addMr_Cluster( node, err);
71                 node = factory.genMR_Cluster("edge" );
72                 mcs.addMr_Cluster(node,  err);
73         }
74
75         @After
76         public void tearDown() throws Exception {
77         }
78
79
80         @Test
81         public void test1() {
82
83
84                 rh.reflect( "org.onap.dmaap.dbcapi.service.TopicService", "get", null );        
85         
86         }
87
88         @Test
89         public void test2() {
90                 String v = "Validate";
91                 rh.reflect( "org.onap.dmaap.dbcapi.service.TopicService", "set", v );
92
93         }
94
95         @Test
96         public void test3() {
97                 String t = "test3";
98                 Topic topic = factory.genSimpleTopic( t );
99                 ApiError err = new ApiError();
100                 
101                 Topic nTopic = ts.addTopic( topic, err, false );
102                 if ( nTopic != null ) {
103                         assertTrue( nTopic.getTopicName().equals( t ));
104                 }
105
106         }
107
108         @Test
109         public void test3a() {
110
111
112                 ApiError err = new ApiError();
113
114                 String t = "org.onap.dmaap.interestingTopic";
115                 Topic topic = factory.genSimpleTopic(t);
116                 String f = "mrc.onap.org:3904/events/org.onap.dmaap.interestingTopic";
117                 String c = "publisher";
118                 String[] a = { "sub", "view" };
119                 MR_Client sub = factory.genMR_Client("central",  f, c, a );
120                 String[] b = { "pub", "view" };
121                 MR_Client pub = factory.genMR_Client( "edge", f, c, b );
122                 ArrayList<MR_Client> clients = new ArrayList<MR_Client>();
123
124                 clients.add( sub );
125                 clients.add( pub );
126
127                 topic.setClients( clients );
128
129                 ts.reviewTopic( topic );
130                 ts.checkForBridge( topic, err );
131                 
132                 Topic nTopic = ts.addTopic( topic, err, false );
133                 if ( nTopic != null ) {
134                         assertTrue( nTopic.getTopicName().equals( t ));
135                 }
136                 
137
138                 ts.removeTopic( "test3", err );
139         }
140
141         @Test
142         public void test4() {
143                 List<Topic> l = ts.getAllTopics();
144
145         }
146
147         @Test
148         public void test5() {
149                 ApiError err = new ApiError();
150
151                 Topic topic = factory.genSimpleTopic("test5");
152                 Topic nTopic = ts.updateTopic( topic, err );
153
154                 assertTrue( err.getCode() == 200 );
155         }
156         
157         @Test
158         public void bridgeTest6() {
159                 ApiError err = new ApiError();
160
161                 String t = "org.onap.dmaap.bridgingTopic";
162                 Topic topic = factory.genSimpleTopic(t);
163                 topic.setReplicationCase( ReplicationType.REPLICATION_EDGE_TO_CENTRAL );
164
165                 String c = "publisher";
166                 String[] a = { "sub", "view" };
167                 MR_Client sub = factory.genMR_Client("central",  topic.getFqtn(), c, a );
168                 String[] b = { "pub", "view" };
169                 MR_Client pub = factory.genMR_Client( "edge", topic.getFqtn(), c, b );
170                 ArrayList<MR_Client> clients = new ArrayList<MR_Client>();
171
172                 clients.add( sub );
173                 clients.add( pub );
174
175                 topic.setClients( clients );
176
177                 Topic nTopic = ts.updateTopic( topic, err );
178
179                 assertTrue( err.getCode() == 200 );
180         }
181         @Test
182         public void bridgeTest7() {
183                 ApiError err = new ApiError();
184
185                 String t = "org.onap.dmaap.bridgingTopic7";
186                 Topic topic = factory.genSimpleTopic(t);
187                 topic.setReplicationCase( ReplicationType.REPLICATION_CENTRAL_TO_EDGE );
188
189                 String c = "publisher";
190                 String[] a = { "sub", "view" };
191                 MR_Client sub = factory.genMR_Client("edge",  topic.getFqtn(), c, a );
192                 String[] b = { "pub", "view" };
193                 MR_Client pub = factory.genMR_Client( "central", topic.getFqtn(), c, b );
194                 ArrayList<MR_Client> clients = new ArrayList<MR_Client>();
195
196                 clients.add( sub );
197                 clients.add( pub );
198
199                 topic.setClients( clients );
200
201                 Topic nTopic = ts.updateTopic( topic, err );
202
203                 assertTrue( err.getCode() == 200 );
204         }
205
206 }