2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 package org.onap.dmaap.mr.cambria.beans;
22 import static org.junit.Assert.assertTrue;
24 import com.att.nsa.configs.ConfigDb;
25 import com.att.nsa.configs.ConfigDbException;
26 import com.att.nsa.configs.ConfigPath;
27 import java.util.Properties;
28 import org.mockito.ArgumentMatchers;
29 import org.I0Itec.zkclient.ZkClient;
30 import org.apache.kafka.clients.admin.AdminClient;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.mockito.InjectMocks;
35 import org.mockito.Mock;
36 import org.mockito.MockitoAnnotations;
37 import org.onap.dmaap.dmf.mr.CambriaApiException;
38 import org.onap.dmaap.dmf.mr.beans.DMaaPKafkaMetaBroker;
39 import org.onap.dmaap.dmf.mr.beans.DMaaPKafkaMetaBroker.KafkaTopic;
40 import org.onap.dmaap.dmf.mr.metabroker.Broker1.TopicExistsException;
41 import org.onap.dmaap.dmf.mr.metabroker.Topic;
42 import org.powermock.api.mockito.PowerMockito;
43 import org.powermock.core.classloader.annotations.PowerMockIgnore;
44 import org.powermock.core.classloader.annotations.PrepareForTest;
45 import org.powermock.modules.junit4.PowerMockRunner;
47 @PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"})
48 @RunWith(PowerMockRunner.class)
49 @PrepareForTest({ AdminClient.class })
50 public class DMaaPKafkaMetaBrokerTest {
53 private DMaaPKafkaMetaBroker dMaaPKafkaMetaBroker;
57 private AdminClient fKafkaAdminClient;
59 private ConfigDb configDb;
61 ConfigPath fBaseTopicData;
63 private ZkClient zkClient;
69 MockitoAnnotations.initMocks(this);
70 PowerMockito.mockStatic(AdminClient.class);
71 PowerMockito.when(AdminClient.create(ArgumentMatchers.any(Properties.class))).thenReturn(fKafkaAdminClient);
72 PowerMockito.when(configDb.parse("/topics")).thenReturn(fBaseTopicData);
76 public void testBrokercreate() {
77 DMaaPKafkaMetaBroker broker = new DMaaPKafkaMetaBroker();
81 public void testcreateTopicEntry() {
83 KafkaTopic kafkaTopic = new KafkaTopic("topics", configDb, fBaseTopicData);
84 dMaaPKafkaMetaBroker.createTopicEntry("name", "desc", "owner", true);
85 } catch (Exception e) {
91 public void testGetAlltopics() {
93 dMaaPKafkaMetaBroker.getAllTopics();
94 } catch (ConfigDbException e) {
95 // TODO Auto-generated catch block
101 public void testcreateTopic() {
103 dMaaPKafkaMetaBroker.createTopic("testtopic", "testtopic", "admin", 1, 1, true);
104 } catch (CambriaApiException e) {
105 // TODO Auto-generated catch block
107 } catch (TopicExistsException e) {
108 // TODO Auto-generated catch block
110 } catch (Exception e) {
111 // TODO Auto-generatee.printStackTrace();
117 public void testcreateTopic_wrongPartition() {
120 dMaaPKafkaMetaBroker.createTopic("testtopic", "testtopic", "admin", 0, 1, true);
121 } catch (CambriaApiException e) {
123 } catch (TopicExistsException e) {
124 // TODO Auto-generated catch block
126 } catch (Exception e) {
127 // TODO Auto-generatee.printStackTrace();
133 public void testcreateTopic_wrongReplica() {
136 dMaaPKafkaMetaBroker.createTopic("testtopic", "testtopic", "admin", 1, 0, true);
137 } catch (CambriaApiException e) {
139 } catch (TopicExistsException e) {
140 // TODO Auto-generated catch block
142 } catch (Exception e) {
143 // TODO Auto-generatee.printStackTrace();
149 public void testcreateTopic_error1() {
151 dMaaPKafkaMetaBroker.createTopic("testtopic", "testtopic", "admin", 1, 1, true);
152 } catch (CambriaApiException e) {
154 } catch (TopicExistsException e) {
155 // TODO Auto-generated catch block
157 } catch (Exception e) {
164 public void testcreateTopic_error2() {
166 dMaaPKafkaMetaBroker.createTopic("testtopic", "testtopic", "admin", 1, 1, true);
167 } catch (CambriaApiException e) {
169 } catch (TopicExistsException e) {
170 // TODO Auto-generated catch block
172 } catch (Exception e) {
178 public void testcreateTopic_error3() {
180 dMaaPKafkaMetaBroker.createTopic("testtopic", "testtopic", "admin", 1, 1, true);
181 } catch (CambriaApiException e) {
182 // TODO Auto-generated catch block
184 } catch (TopicExistsException e) {
187 } catch (Exception e) {
194 public void testDeleteTopic() {
196 dMaaPKafkaMetaBroker.deleteTopic("testtopic");
197 } catch (CambriaApiException e) {
198 // TODO Auto-generated catch block
200 } catch (TopicExistsException e) {
201 // TODO Auto-generated catch block
203 } catch (Exception e) {
211 public void testDeleteTopic_error1() {
213 dMaaPKafkaMetaBroker.deleteTopic("testtopic");
214 } catch (CambriaApiException e) {
216 } catch (TopicExistsException e) {
217 // TODO Auto-generated catch block
219 } catch (Exception e) {
226 public void testDeleteTopic_error2() {
228 dMaaPKafkaMetaBroker.deleteTopic("testtopic");
229 } catch (CambriaApiException e) {
231 } catch (TopicExistsException e) {
232 // TODO Auto-generated catch block
234 } catch (Exception e) {
241 public void testDeleteTopic_error3() {
243 dMaaPKafkaMetaBroker.deleteTopic("testtopic");
244 } catch (CambriaApiException e) {
245 // TODO Auto-generated catch block
247 } catch (TopicExistsException e) {
249 } catch (Exception e) {