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 org.I0Itec.zkclient.ZkClient;
25 import org.I0Itec.zkclient.exception.ZkNoNodeException;
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.junit.runner.RunWith;
29 import static org.mockito.Matchers.any;
31 import java.util.Properties;
33 import org.mockito.InjectMocks;
34 import org.mockito.Mock;
35 import org.mockito.MockitoAnnotations;
36 import org.powermock.api.mockito.PowerMockito;
37 import org.powermock.core.classloader.annotations.PrepareForTest;
38 import org.powermock.modules.junit4.PowerMockRunner;
40 import org.onap.dmaap.dmf.mr.CambriaApiException;
41 import org.apache.kafka.clients.admin.AdminClient;
43 import org.onap.dmaap.dmf.mr.beans.DMaaPKafkaMetaBroker;
44 import org.onap.dmaap.dmf.mr.beans.DMaaPKafkaMetaBroker.KafkaTopic;
45 import org.onap.dmaap.dmf.mr.constants.CambriaConstants;
46 import org.onap.dmaap.dmf.mr.metabroker.Topic;
47 import org.onap.dmaap.dmf.mr.metabroker.Broker1.TopicExistsException;
48 import com.att.nsa.configs.ConfigDb;
49 import com.att.nsa.configs.ConfigDbException;
50 import com.att.nsa.configs.ConfigPath;
52 @RunWith(PowerMockRunner.class)
53 @PrepareForTest({ AdminClient.class })
54 public class DMaaPKafkaMetaBrokerTest {
57 private DMaaPKafkaMetaBroker dMaaPKafkaMetaBroker;
61 private AdminClient fKafkaAdminClient;
63 private AdminClient client;
65 private ConfigDb configDb;
67 ConfigPath fBaseTopicData;
69 private ZkClient zkClient;
75 MockitoAnnotations.initMocks(this);
76 PowerMockito.mockStatic(AdminClient.class);
77 // PowerMockito.when(AdminClient.create (any(Properties.class)
78 // )).thenReturn(fKafkaAdminClient);
80 // PowerMockito.mockStatic(AdminUtils.class);
81 PowerMockito.when(configDb.parse("/topics")).thenReturn(fBaseTopicData);
86 public void testBrokercreate() {
87 DMaaPKafkaMetaBroker broker = new DMaaPKafkaMetaBroker();
92 public void testcreateTopicEntry() {
94 KafkaTopic kafkaTopic = new KafkaTopic("topics", configDb, fBaseTopicData);
95 dMaaPKafkaMetaBroker.createTopicEntry("name", "desc", "owner", true);
96 } catch (Exception e) {
103 public void testGetAlltopics() {
105 dMaaPKafkaMetaBroker.getAllTopics();
106 } catch (ConfigDbException e) {
107 // TODO Auto-generated catch block
114 public void testcreateTopic() {
116 dMaaPKafkaMetaBroker.createTopic("testtopic", "testtopic", "admin", 1, 1, true);
117 } catch (CambriaApiException e) {
118 // TODO Auto-generated catch block
120 } catch (TopicExistsException e) {
121 // TODO Auto-generated catch block
123 } catch (Exception e) {
124 // TODO Auto-generatee.printStackTrace();
130 public void testcreateTopic_wrongPartition() {
133 dMaaPKafkaMetaBroker.createTopic("testtopic", "testtopic", "admin", 0, 1, true);
134 } catch (CambriaApiException e) {
136 } catch (TopicExistsException e) {
137 // TODO Auto-generated catch block
139 } catch (Exception e) {
140 // TODO Auto-generatee.printStackTrace();
146 public void testcreateTopic_wrongReplica() {
149 dMaaPKafkaMetaBroker.createTopic("testtopic", "testtopic", "admin", 1, 0, true);
150 } catch (CambriaApiException e) {
152 } catch (TopicExistsException e) {
153 // TODO Auto-generated catch block
155 } catch (Exception e) {
156 // TODO Auto-generatee.printStackTrace();
162 public void testcreateTopic_error1() {
164 dMaaPKafkaMetaBroker.createTopic("testtopic", "testtopic", "admin", 1, 1, true);
165 } catch (CambriaApiException e) {
167 } catch (TopicExistsException e) {
168 // TODO Auto-generated catch block
170 } catch (Exception e) {
177 public void testcreateTopic_error2() {
179 dMaaPKafkaMetaBroker.createTopic("testtopic", "testtopic", "admin", 1, 1, true);
180 } catch (CambriaApiException e) {
182 } catch (TopicExistsException e) {
183 // TODO Auto-generated catch block
185 } catch (Exception e) {
191 public void testcreateTopic_error3() {
193 dMaaPKafkaMetaBroker.createTopic("testtopic", "testtopic", "admin", 1, 1, true);
194 } catch (CambriaApiException e) {
195 // TODO Auto-generated catch block
197 } catch (TopicExistsException e) {
200 } catch (Exception e) {
207 public void testDeleteTopic() {
209 dMaaPKafkaMetaBroker.deleteTopic("testtopic");
210 } catch (CambriaApiException e) {
211 // TODO Auto-generated catch block
213 } catch (TopicExistsException e) {
214 // TODO Auto-generated catch block
216 } catch (Exception e) {
224 public void testDeleteTopic_error1() {
226 dMaaPKafkaMetaBroker.deleteTopic("testtopic");
227 } catch (CambriaApiException e) {
229 } catch (TopicExistsException e) {
230 // TODO Auto-generated catch block
232 } catch (Exception e) {
239 public void testDeleteTopic_error2() {
241 dMaaPKafkaMetaBroker.deleteTopic("testtopic");
242 } catch (CambriaApiException e) {
244 } catch (TopicExistsException e) {
245 // TODO Auto-generated catch block
247 } catch (Exception e) {
254 public void testDeleteTopic_error3() {
256 dMaaPKafkaMetaBroker.deleteTopic("testtopic");
257 } catch (CambriaApiException e) {
258 // TODO Auto-generated catch block
260 } catch (TopicExistsException e) {
262 } catch (Exception e) {