575752230de5c0c30021fd94928502aa5686e6a7
[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 import  org.onap.dmaap.dbcapi.model.*;
22
23 import static org.junit.Assert.*;
24
25 import org.junit.After;
26 import org.junit.Before;
27 import org.junit.Test;
28 import java.util.List;
29 import java.util.ArrayList;
30
31 public class TopicServiceTest {
32
33         private static final String  fmt = "%24s: %s%n";
34
35         ReflectionHarness rh = new ReflectionHarness();
36
37         TopicService ts;
38         MR_ClusterService mcs;
39         String locname = "central-onap";
40
41         @Before
42         public void setUp() throws Exception {
43                 ts = new TopicService();
44                 mcs = new MR_ClusterService();
45         }
46
47         @After
48         public void tearDown() throws Exception {
49         }
50
51
52         @Test
53         public void test1() {
54
55
56                 rh.reflect( "org.onap.dmaap.dbcapi.service.TopicService", "get", null );        
57         
58         }
59
60         @Test
61         public void test2() {
62                 String v = "Validate";
63                 rh.reflect( "org.onap.dmaap.dbcapi.service.TopicService", "set", v );
64
65         }
66
67         @Test
68         public void test3() {
69                 Topic topic = new Topic();
70                 ApiError err = new ApiError();
71                 topic.setTopicName( "test3" );
72                 topic.setFqtnStyle( FqtnType.Validator("none") );
73                 topic.getFqtn();
74                 Topic nTopic = ts.addTopic( topic, err );
75                 if ( nTopic != null ) {
76                         assertTrue( nTopic.getTopicName().equals( topic.getTopicName() ));
77                 }
78
79         }
80
81         @Test
82         public void test3a() {
83                 Topic topic = new Topic();
84                 ApiError err = new ApiError();
85                 topic.setTopicName( "test3" );
86                 topic.setFqtnStyle( FqtnType.Validator("none") );
87                 topic.getFqtn();
88                 String t = "org.onap.dmaap.interestingTopic";
89                 String f = "mrc.onap.org:3904/events/org.onap.dmaap.interestingTopic";
90                 String c = "publisher";
91                 String[] a = { "sub", "view" };
92                 MR_Client sub = new MR_Client( locname, f, c, a );
93                 String[] b = { "pub", "view" };
94                 MR_Client pub = new MR_Client( "edge", f, c, b );
95                 ArrayList<MR_Client> clients = new ArrayList<MR_Client>();
96
97                 clients.add( sub );
98                 clients.add( pub );
99
100                 topic.setClients( clients );
101
102                 ts.reviewTopic( topic );
103                 ts.checkForBridge( topic, err );
104                 
105                 Topic nTopic = ts.addTopic( topic, err );
106                 if ( nTopic != null ) {
107                         assertTrue( nTopic.getTopicName().equals( topic.getTopicName() ));
108                 }
109                 
110
111                 ts.removeTopic( "test3", err );
112         }
113
114         @Test
115         public void test4() {
116                 List<Topic> l = ts.getAllTopics();
117
118         }
119
120         @Test
121         public void test5() {
122                 ApiError err = new ApiError();
123 /*
124
125 TODO: find a null pointer in here...
126                 String[] hl = { "host1", "host2", "host3" };
127                 String loc = "central-onap";
128                 MR_Cluster cluster = new MR_Cluster( loc, "localhost", "", hl );
129                 mcs.addMr_Cluster( cluster, err );
130                 Topic topic = new Topic();
131                 topic.setTopicName( "test5" );
132                 topic.setFqtnStyle( FqtnType.Validator("none") );
133                 topic.setReplicationCase( ReplicationType.Validator("none") );
134                 String f = topic.getFqtn();
135                 Topic nTopic = ts.updateTopic( topic, err );
136 */
137                 assertTrue( err.getCode() == 0 );
138         }
139
140 }