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.PowerMockIgnore;
38 import org.powermock.core.classloader.annotations.PrepareForTest;
39 import org.powermock.modules.junit4.PowerMockRunner;
41 import org.onap.dmaap.dmf.mr.CambriaApiException;
42 import org.apache.kafka.clients.admin.AdminClient;
44 import org.onap.dmaap.dmf.mr.beans.DMaaPKafkaMetaBroker;
45 import org.onap.dmaap.dmf.mr.beans.DMaaPKafkaMetaBroker.KafkaTopic;
46 import org.onap.dmaap.dmf.mr.constants.CambriaConstants;
47 import org.onap.dmaap.dmf.mr.metabroker.Topic;
48 import org.onap.dmaap.dmf.mr.metabroker.Broker1.TopicExistsException;
49 import com.att.nsa.configs.ConfigDb;
50 import com.att.nsa.configs.ConfigDbException;
51 import com.att.nsa.configs.ConfigPath;
53 @PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"})
54 @RunWith(PowerMockRunner.class)
55 @PrepareForTest({ AdminClient.class })
56 public class DMaaPKafkaMetaBrokerTest {
59 private DMaaPKafkaMetaBroker dMaaPKafkaMetaBroker;
63 private AdminClient fKafkaAdminClient;
65 private AdminClient client;
67 private ConfigDb configDb;
69 ConfigPath fBaseTopicData;
71 private ZkClient zkClient;
77 MockitoAnnotations.initMocks(this);
78 PowerMockito.mockStatic(AdminClient.class);
79 // PowerMockito.when(AdminClient.create (any(Properties.class)
80 // )).thenReturn(fKafkaAdminClient);
82 // PowerMockito.mockStatic(AdminUtils.class);
83 PowerMockito.when(configDb.parse("/topics")).thenReturn(fBaseTopicData);
88 public void testBrokercreate() {
89 DMaaPKafkaMetaBroker broker = new DMaaPKafkaMetaBroker();
94 public void testcreateTopicEntry() {
96 KafkaTopic kafkaTopic = new KafkaTopic("topics", configDb, fBaseTopicData);
97 dMaaPKafkaMetaBroker.createTopicEntry("name", "desc", "owner", true);
98 } catch (Exception e) {
105 public void testGetAlltopics() {
107 dMaaPKafkaMetaBroker.getAllTopics();
108 } catch (ConfigDbException e) {
109 // TODO Auto-generated catch block
116 public void testcreateTopic() {
118 dMaaPKafkaMetaBroker.createTopic("testtopic", "testtopic", "admin", 1, 1, true);
119 } catch (CambriaApiException e) {
120 // TODO Auto-generated catch block
122 } catch (TopicExistsException e) {
123 // TODO Auto-generated catch block
125 } catch (Exception e) {
126 // TODO Auto-generatee.printStackTrace();
132 public void testcreateTopic_wrongPartition() {
135 dMaaPKafkaMetaBroker.createTopic("testtopic", "testtopic", "admin", 0, 1, true);
136 } catch (CambriaApiException e) {
138 } catch (TopicExistsException e) {
139 // TODO Auto-generated catch block
141 } catch (Exception e) {
142 // TODO Auto-generatee.printStackTrace();
148 public void testcreateTopic_wrongReplica() {
151 dMaaPKafkaMetaBroker.createTopic("testtopic", "testtopic", "admin", 1, 0, true);
152 } catch (CambriaApiException e) {
154 } catch (TopicExistsException e) {
155 // TODO Auto-generated catch block
157 } catch (Exception e) {
158 // TODO Auto-generatee.printStackTrace();
164 public void testcreateTopic_error1() {
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) {
179 public void testcreateTopic_error2() {
181 dMaaPKafkaMetaBroker.createTopic("testtopic", "testtopic", "admin", 1, 1, true);
182 } catch (CambriaApiException e) {
184 } catch (TopicExistsException e) {
185 // TODO Auto-generated catch block
187 } catch (Exception e) {
193 public void testcreateTopic_error3() {
195 dMaaPKafkaMetaBroker.createTopic("testtopic", "testtopic", "admin", 1, 1, true);
196 } catch (CambriaApiException e) {
197 // TODO Auto-generated catch block
199 } catch (TopicExistsException e) {
202 } catch (Exception e) {
209 public void testDeleteTopic() {
211 dMaaPKafkaMetaBroker.deleteTopic("testtopic");
212 } catch (CambriaApiException e) {
213 // TODO Auto-generated catch block
215 } catch (TopicExistsException e) {
216 // TODO Auto-generated catch block
218 } catch (Exception e) {
226 public void testDeleteTopic_error1() {
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_error2() {
243 dMaaPKafkaMetaBroker.deleteTopic("testtopic");
244 } catch (CambriaApiException e) {
246 } catch (TopicExistsException e) {
247 // TODO Auto-generated catch block
249 } catch (Exception e) {
256 public void testDeleteTopic_error3() {
258 dMaaPKafkaMetaBroker.deleteTopic("testtopic");
259 } catch (CambriaApiException e) {
260 // TODO Auto-generated catch block
262 } catch (TopicExistsException e) {
264 } catch (Exception e) {