1 /*******************************************************************************
2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2022 Huawei Canada Limited.
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 *******************************************************************************/
22 package org.onap.slice.analysis.ms.dmaap;
24 import com.openpojo.reflection.PojoClass;
25 import com.openpojo.reflection.impl.PojoClassFactory;
26 import com.openpojo.validation.Validator;
27 import com.openpojo.validation.ValidatorBuilder;
28 import com.openpojo.validation.rule.impl.GetterMustExistRule;
29 import com.openpojo.validation.rule.impl.SetterMustExistRule;
30 import com.openpojo.validation.test.impl.GetterTester;
31 import com.openpojo.validation.test.impl.SetterTester;
32 import org.junit.Test;
33 import static org.junit.Assert.assertEquals;
35 public class MRTopicParamsTest {
36 private static final String TEST_TOPIC = "test-topic";
37 private static final String TEST_HOST = "test-host";
38 private static final String MY_CLIENT = "my-client";
39 private static final String MY_CG = "my-cg";
40 private static final String MY_CI = "my-ci";
41 private static final String MY_API_SEC = "my-api-sec";
42 private static final String MY_API_KEY = "my-api-key";
43 private static final int MY_FETCH_LIMIT = 100;
44 private static final int MY_FETCH_TIMEOUT = 1000;
45 private static final String MY_PASS = "my-pass";
46 private static final String MY_USERNAME = "my-username";
47 private static final int MY_PORT = 5555;
50 public void builderTest() {
51 MRTopicParams params = MRTopicParams.builder()
54 .clientName(MY_CLIENT)
56 .consumerInstance(MY_CI)
57 .apiSecret(MY_API_SEC)
59 .fetchLimit(MY_FETCH_LIMIT)
60 .fetchTimeout(MY_FETCH_TIMEOUT)
62 .userName(MY_USERNAME)
66 assertEquals(TEST_TOPIC, params.getTopic());
67 assertEquals(TEST_HOST, params.getHostname());
68 assertEquals(MY_CLIENT, params.getClientName());
69 assertEquals(MY_CG, params.getConsumerGroup());
70 assertEquals(MY_CI, params.getConsumerInstance());
71 assertEquals(MY_API_SEC, params.getApiSecret());
72 assertEquals(MY_API_KEY, params.getApiKey());
73 assertEquals(MY_FETCH_LIMIT, params.getFetchLimit());
74 assertEquals(MY_FETCH_TIMEOUT, params.getFetchTimeout());
75 assertEquals(MY_PASS, params.getPassword());
76 assertEquals(MY_USERNAME, params.getUserName());
77 assertEquals(MY_PORT, params.getPort());
81 public void testGetterSetterMRTopicParams() {
82 PojoClass pojoclass = PojoClassFactory.getPojoClass(MRTopicParams.class);
83 validateMd(pojoclass);
86 public void validateMd(PojoClass pojoclass) {
87 Validator validator = ValidatorBuilder
89 .with(new SetterMustExistRule())
90 .with(new GetterMustExistRule())
91 .with(new SetterTester())
92 .with(new GetterTester())
94 validator.validate(pojoclass);