aboutsummaryrefslogtreecommitdiffstats
path: root/common-parameters/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'common-parameters/src/test/java')
-rw-r--r--common-parameters/src/test/java/org/onap/policy/common/parameters/TestBeanValidationResult.java4
-rw-r--r--common-parameters/src/test/java/org/onap/policy/common/parameters/TestBeanValidator.java98
-rw-r--r--common-parameters/src/test/java/org/onap/policy/common/parameters/TestFieldValidator.java4
-rw-r--r--common-parameters/src/test/java/org/onap/policy/common/parameters/rest/RestClientParametersTest.java116
-rw-r--r--common-parameters/src/test/java/org/onap/policy/common/parameters/topic/BusTopicParamsTest.java201
5 files changed, 368 insertions, 55 deletions
diff --git a/common-parameters/src/test/java/org/onap/policy/common/parameters/TestBeanValidationResult.java b/common-parameters/src/test/java/org/onap/policy/common/parameters/TestBeanValidationResult.java
index 2fc09949..ab733aed 100644
--- a/common-parameters/src/test/java/org/onap/policy/common/parameters/TestBeanValidationResult.java
+++ b/common-parameters/src/test/java/org/onap/policy/common/parameters/TestBeanValidationResult.java
@@ -112,7 +112,7 @@ class TestBeanValidationResult {
@Test
void testValidateNotNullList() {
- List<ValidationResult> list = Arrays.asList(clean);
+ List<ValidationResult> list = List.of(clean);
assertTrue(bean.validateNotNullList(MY_LIST, list, item -> item));
assertTrue(bean.isValid());
assertNull(bean.getResult());
@@ -141,7 +141,7 @@ class TestBeanValidationResult {
assertTrue(bean.isValid());
assertNull(bean.getResult());
- list = Arrays.asList(clean);
+ list = List.of(clean);
bean = new BeanValidationResult(NAME, OBJECT);
assertTrue(bean.validateList(MY_LIST, list, item -> item));
assertTrue(bean.isValid());
diff --git a/common-parameters/src/test/java/org/onap/policy/common/parameters/TestBeanValidator.java b/common-parameters/src/test/java/org/onap/policy/common/parameters/TestBeanValidator.java
index 31c34209..c4211136 100644
--- a/common-parameters/src/test/java/org/onap/policy/common/parameters/TestBeanValidator.java
+++ b/common-parameters/src/test/java/org/onap/policy/common/parameters/TestBeanValidator.java
@@ -82,9 +82,6 @@ class TestBeanValidator {
data.strValue = STRING_VALUE;
assertTrue(validator.validateTop(TOP, data).isValid());
- /**
- * Repeat with a subclass.
- */
@Getter
class Derived extends Data {
@Min(10)
@@ -119,8 +116,8 @@ class TestBeanValidator {
@Test
void testVerNotNull() {
+ @Getter
class NotNullCheck {
- @Getter
@Min(1)
@NotNull
Integer intValue;
@@ -138,8 +135,8 @@ class TestBeanValidator {
@Test
void testVerNotBlank() {
+ @Getter
class NotBlankCheck {
- @Getter
@NotBlank
String strValue;
}
@@ -164,8 +161,8 @@ class TestBeanValidator {
/*
* Class with "blank" annotation on an integer.
*/
+ @Getter
class NotBlankInt {
- @Getter
@NotBlank
int intValue;
}
@@ -180,8 +177,8 @@ class TestBeanValidator {
*/
@Test
void testVerSizeCollection() {
+ @Getter
class CollectionSizeCheck {
- @Getter
@Size(min = 3)
Collection<Integer> items;
}
@@ -210,8 +207,8 @@ class TestBeanValidator {
*/
@Test
void testVerSizeMap() {
+ @Getter
class MapSizeCheck {
- @Getter
@Size(min = 3)
Map<Integer, Integer> items;
}
@@ -240,8 +237,8 @@ class TestBeanValidator {
*/
@Test
void testVerSizeOther() {
+ @Getter
class OtherSizeCheck {
- @Getter
@Size(min = 3)
Integer items;
}
@@ -254,8 +251,8 @@ class TestBeanValidator {
@Test
void testVerRegex() {
+ @Getter
class RegexCheck {
- @Getter
@Pattern(regexp = "[a-f]*")
String strValue;
}
@@ -272,8 +269,8 @@ class TestBeanValidator {
assertTrue(validator.validateTop(TOP, regexCheck).isValid());
// invalid regex
+ @Getter
class InvalidRegexCheck {
- @Getter
@Pattern(regexp = "[a-f")
String strValue;
}
@@ -292,8 +289,8 @@ class TestBeanValidator {
/*
* Class with "regex" annotation on an integer.
*/
+ @Getter
class RegexInt {
- @Getter
@Pattern(regexp = "[a-f]*")
int intValue;
}
@@ -309,8 +306,8 @@ class TestBeanValidator {
/*
* Field is not a number.
*/
+ @Getter
class NonNumeric {
- @Getter
@Max(100)
String strValue;
}
@@ -322,68 +319,68 @@ class TestBeanValidator {
/*
* Integer field.
*/
+ @Getter
class IntField {
- @Getter
@Max(100)
Integer intValue;
}
// ok value
IntField intField = new IntField();
- assertNumeric("testVerMax-integer", intField, value -> {
+ assertNumeric(intField, value -> {
intField.intValue = value;
- }, INT_FIELD, "maximum", INT_VALUE, 100, 101);
+ }, INT_FIELD, "maximum", 100, 101);
/*
* Long field.
*/
+ @Getter
class LongField {
- @Getter
@Max(100)
Long numValue;
}
// ok value
LongField longField = new LongField();
- assertNumeric("testVerMax-long", longField, value -> {
+ assertNumeric(longField, value -> {
longField.numValue = (long) value;
- }, NUM_FIELD, "maximum", INT_VALUE, 100, 101);
+ }, NUM_FIELD, "maximum", 100, 101);
/*
* Float field.
*/
+ @Getter
class FloatField {
- @Getter
@Max(100)
Float numValue;
}
// ok value
FloatField floatField = new FloatField();
- assertNumeric("testVerMax-float", floatField, value -> {
+ assertNumeric(floatField, value -> {
floatField.numValue = (float) value;
- }, NUM_FIELD, "maximum", INT_VALUE, 100, 101);
+ }, NUM_FIELD, "maximum", 100, 101);
/*
* Double field.
*/
+ @Getter
class DoubleField {
- @Getter
@Max(100)
Double numValue;
}
// ok value
DoubleField doubleField = new DoubleField();
- assertNumeric("testVerMax-double", doubleField, value -> {
+ assertNumeric(doubleField, value -> {
doubleField.numValue = (double) value;
- }, NUM_FIELD, "maximum", INT_VALUE, 100, 101);
+ }, NUM_FIELD, "maximum", 100, 101);
/*
* Atomic Integer field (which is a subclass of Number).
*/
+ @Getter
class AtomIntValue {
- @Getter
@Max(100)
AtomicInteger numValue;
}
@@ -403,8 +400,8 @@ class TestBeanValidator {
/*
* Field is not a number.
*/
+ @Getter
class NonNumeric {
- @Getter
@Min(10)
String strValue;
}
@@ -416,68 +413,68 @@ class TestBeanValidator {
/*
* Integer field.
*/
+ @Getter
class IntField {
- @Getter
@Min(10)
Integer intValue;
}
// ok value
IntField intField = new IntField();
- assertNumeric("testVerMin-integer", intField, value -> {
+ assertNumeric(intField, value -> {
intField.intValue = value;
- }, INT_FIELD, "minimum", INT_VALUE, 10, 1);
+ }, INT_FIELD, "minimum", 10, 1);
/*
* Long field.
*/
+ @Getter
class LongField {
- @Getter
@Min(10)
Long numValue;
}
// ok value
LongField longField = new LongField();
- assertNumeric("testVerMin-long", longField, value -> {
+ assertNumeric(longField, value -> {
longField.numValue = (long) value;
- }, NUM_FIELD, "minimum", INT_VALUE, 10, 1);
+ }, NUM_FIELD, "minimum", 10, 1);
/*
* Float field.
*/
+ @Getter
class FloatField {
- @Getter
@Min(10)
Float numValue;
}
// ok value
FloatField floatField = new FloatField();
- assertNumeric("testVerMin-float", floatField, value -> {
+ assertNumeric(floatField, value -> {
floatField.numValue = (float) value;
- }, NUM_FIELD, "minimum", INT_VALUE, 10, 1);
+ }, NUM_FIELD, "minimum", 10, 1);
/*
* Double field.
*/
+ @Getter
class DoubleField {
- @Getter
@Min(10)
Double numValue;
}
// ok value
DoubleField doubleField = new DoubleField();
- assertNumeric("testVerMin-double", doubleField, value -> {
+ assertNumeric(doubleField, value -> {
doubleField.numValue = (double) value;
- }, NUM_FIELD, "minimum", INT_VALUE, 10, 1);
+ }, NUM_FIELD, "minimum", 10, 1);
/*
* Atomic Integer field (which is a subclass of Number).
*/
+ @Getter
class AtomIntValue {
- @Getter
@Min(10)
AtomicInteger numValue;
}
@@ -494,8 +491,8 @@ class TestBeanValidator {
@Test
void testVerClassName() {
+ @Getter
class ClassNameCheck {
- @Getter
@ClassName
String strValue;
}
@@ -518,8 +515,8 @@ class TestBeanValidator {
@Test
void testVerCascade() {
+ @Getter
class Item {
- @Getter
@NotNull
Integer intValue;
}
@@ -626,27 +623,26 @@ class TestBeanValidator {
@Test
void testGetEntryName() {
- assertThat(validator.getEntryName(makeEntry(null, 0))).isEmpty();
- assertThat(validator.getEntryName(makeEntry("", 0))).isEmpty();
- assertThat(validator.getEntryName(makeEntry(STRING_VALUE, 0))).isEqualTo(STRING_VALUE);
+ assertThat(validator.getEntryName(makeEntry(null))).isEmpty();
+ assertThat(validator.getEntryName(makeEntry(""))).isEmpty();
+ assertThat(validator.getEntryName(makeEntry(STRING_VALUE))).isEqualTo(STRING_VALUE);
}
/**
* Makes a Map entry with the given key and value.
*
* @param key desired key
- * @param value desired value
* @return a new Map entry
*/
- private Map.Entry<String, Integer> makeEntry(String key, int value) {
+ private Map.Entry<String, Integer> makeEntry(String key) {
HashMap<String, Integer> map = new HashMap<>();
- map.put(key, value);
+ map.put(key, 0);
return map.entrySet().iterator().next();
}
- private <T> void assertNumeric(String testName, T object, Consumer<Integer> setter, String fieldName,
- String expectedText, int inside, int edge, int outside) {
- setter.accept(inside);
+ private <T> void assertNumeric(T object, Consumer<Integer> setter, String fieldName,
+ String expectedText, int edge, int outside) {
+ setter.accept(TestBeanValidator.INT_VALUE);
assertTrue(validator.validateTop(TOP, object).isValid());
// on the edge
diff --git a/common-parameters/src/test/java/org/onap/policy/common/parameters/TestFieldValidator.java b/common-parameters/src/test/java/org/onap/policy/common/parameters/TestFieldValidator.java
index 0fb39b0f..0659ad81 100644
--- a/common-parameters/src/test/java/org/onap/policy/common/parameters/TestFieldValidator.java
+++ b/common-parameters/src/test/java/org/onap/policy/common/parameters/TestFieldValidator.java
@@ -101,7 +101,7 @@ class TestFieldValidator extends ValidatorUtil {
private int voidMethod;
/**
- * Accessor is {@link #getParameterizedMethod()}, which requires a parameter.
+ * Accessor is {@link #getParameterizedMethod(boolean)}, which requires a parameter.
*/
@Min(0)
private int parameterizedMethod;
@@ -357,7 +357,7 @@ class TestFieldValidator extends ValidatorUtil {
}
public int getParameterizedMethod(boolean flag) {
- return 0;
+ return flag ? 0 : 1;
}
public int getExMethod() {
diff --git a/common-parameters/src/test/java/org/onap/policy/common/parameters/rest/RestClientParametersTest.java b/common-parameters/src/test/java/org/onap/policy/common/parameters/rest/RestClientParametersTest.java
new file mode 100644
index 00000000..0e5df570
--- /dev/null
+++ b/common-parameters/src/test/java/org/onap/policy/common/parameters/rest/RestClientParametersTest.java
@@ -0,0 +1,116 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2024 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.common.parameters.rest;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.onap.policy.common.parameters.BeanValidationResult;
+import org.onap.policy.common.parameters.ValidationStatus;
+
+class RestClientParametersTest {
+
+ private RestClientParameters params;
+
+ @BeforeEach
+ void setUp() {
+ params = new RestClientParameters();
+ }
+
+ @Test
+ void testValidate_ValidParameters() {
+ params.setHostname("localhost");
+ params.setClientName("testClient");
+ params.setPort(8080);
+
+ BeanValidationResult result = params.validate();
+
+ assertEquals(ValidationStatus.CLEAN, result.getStatus(), "Expected the parameters to be valid");
+ assertNull(result.getResult(), "Expected no validation errors");
+ }
+
+ @Test
+ void testValidate_InvalidHostname() {
+ params.setHostname("");
+ params.setClientName("testClient");
+ params.setPort(8080);
+
+ BeanValidationResult result = params.validate();
+
+ assertEquals(ValidationStatus.INVALID, result.getStatus(), "Expected the parameters to be invalid");
+ assertTrue(result.getResult().contains("hostname") && result.getResult().contains("is blank"),
+ "Expected invalid hostname error message");
+ }
+
+ @Test
+ void testValidate_InvalidClientName() {
+ params.setHostname("localhost");
+ params.setClientName("");
+ params.setPort(8080);
+
+ BeanValidationResult result = params.validate();
+
+ assertEquals(ValidationStatus.INVALID, result.getStatus(), "Expected the parameters to be invalid");
+ assertTrue(result.getResult().contains("clientName") && result.getResult().contains("is blank"),
+ "Expected invalid clientName error message");
+ }
+
+ @Test
+ void testValidate_InvalidPort() {
+ params.setHostname("localhost");
+ params.setClientName("testClient");
+ params.setPort(-1);
+
+ BeanValidationResult result = params.validate();
+
+ assertEquals(ValidationStatus.INVALID, result.getStatus(), "Expected the parameters to be invalid");
+ assertTrue(result.getResult().contains("port") && result.getResult().contains("is not valid"),
+ "Expected invalid port error message");
+ }
+
+ @Test
+ void testValidate_MultipleInvalidParameters() {
+ params.setHostname("");
+ params.setClientName("");
+ params.setPort(-1);
+
+ BeanValidationResult result = params.validate();
+
+ assertEquals(ValidationStatus.INVALID, result.getStatus(), "Expected the parameters to be invalid");
+
+ assertTrue(result.getResult().contains("hostname") && result.getResult().contains("is blank"),
+ "Expected invalid hostname error message");
+
+ assertTrue(result.getResult().contains("clientName") && result.getResult().contains("is blank"),
+ "Expected invalid clientName error message");
+
+ assertTrue(result.getResult().contains("port") && result.getResult().contains("is not valid"),
+ "Expected invalid port error message");
+ }
+
+ @Test
+ void testGetAndSetName() {
+ String name = "testClient";
+ params.setName(name);
+ assertEquals(name, params.getName(), "Expected the client name to be set and retrieved correctly");
+ }
+}
diff --git a/common-parameters/src/test/java/org/onap/policy/common/parameters/topic/BusTopicParamsTest.java b/common-parameters/src/test/java/org/onap/policy/common/parameters/topic/BusTopicParamsTest.java
new file mode 100644
index 00000000..c474e5fc
--- /dev/null
+++ b/common-parameters/src/test/java/org/onap/policy/common/parameters/topic/BusTopicParamsTest.java
@@ -0,0 +1,201 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018-2020 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2024 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.common.parameters.topic;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.function.BiConsumer;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.onap.policy.common.parameters.topic.BusTopicParams.TopicParamsBuilder;
+
+class BusTopicParamsTest {
+
+ public static final String MY_AFT_ENV = "my-aft-env";
+ public static final String MY_API_KEY = "my-api-key";
+ public static final String MY_API_SECRET = "my-api-secret";
+ public static final String MY_BASE_PATH = "my-base";
+ public static final String MY_CLIENT_NAME = "my-client";
+ public static final String MY_CONS_GROUP = "my-cons-group";
+ public static final String MY_CONS_INST = "my-cons-inst";
+ public static final String MY_ENV = "my-env";
+ public static final int MY_FETCH_LIMIT = 100;
+ public static final int MY_FETCH_TIMEOUT = 101;
+ public static final String MY_HOST = "my-host";
+ public static final String MY_LAT = "my-lat";
+ public static final String MY_LONG = "my-long";
+ public static final String MY_PARTNER = "my-partner";
+ public static final String MY_PASS = "my-pass";
+ public static final int MY_PORT = 102;
+ public static final String MY_TOPIC = "my-topic";
+ public static final String MY_EFFECTIVE_TOPIC = "my-effective-topic";
+ public static final String MY_USERNAME = "my-user";
+ public static final String MY_PARTITION = "my-partition";
+ public static final String MY_SERIALIZER = "org.apache.kafka.common.serialization.StringSerializer";
+
+ protected Map<String, String> addProps;
+ protected TopicParamsBuilder builder;
+
+ @BeforeEach
+ public void setUp() {
+ addProps = new TreeMap<>();
+ addProps.put("my-key-A", "my-value-A");
+ addProps.put("my-key-B", "my-value-B");
+
+ builder = makeBuilder();
+ }
+
+ @Test
+ void testGetters() {
+ BusTopicParams params = makeBuilder().build();
+
+ Assertions.assertEquals(addProps, params.getAdditionalProps());
+ Assertions.assertEquals(MY_AFT_ENV, params.getAftEnvironment());
+ assertTrue(params.isAllowSelfSignedCerts());
+ Assertions.assertEquals(MY_API_KEY, params.getApiKey());
+ Assertions.assertEquals(MY_API_SECRET, params.getApiSecret());
+ Assertions.assertEquals(MY_BASE_PATH, params.getBasePath());
+ Assertions.assertEquals(MY_CLIENT_NAME, params.getClientName());
+ Assertions.assertEquals(MY_CONS_GROUP, params.getConsumerGroup());
+ Assertions.assertEquals(MY_CONS_INST, params.getConsumerInstance());
+ Assertions.assertEquals(MY_ENV, params.getEnvironment());
+ Assertions.assertEquals(MY_FETCH_LIMIT, params.getFetchLimit());
+ Assertions.assertEquals(MY_FETCH_TIMEOUT, params.getFetchTimeout());
+ Assertions.assertEquals(MY_HOST, params.getHostname());
+ Assertions.assertEquals(MY_LAT, params.getLatitude());
+ Assertions.assertEquals(MY_LONG, params.getLongitude());
+ assertTrue(params.isManaged());
+ Assertions.assertEquals(MY_PARTITION, params.getPartitionId());
+ Assertions.assertEquals(MY_PARTNER, params.getPartner());
+ Assertions.assertEquals(MY_PASS, params.getPassword());
+ Assertions.assertEquals(MY_PORT, params.getPort());
+ Assertions.assertEquals(List.of("localhost"), params.getServers());
+ Assertions.assertEquals(MY_TOPIC, params.getTopic());
+ Assertions.assertEquals(MY_EFFECTIVE_TOPIC, params.getEffectiveTopic());
+ assertTrue(params.isUseHttps());
+ Assertions.assertEquals(MY_USERNAME, params.getUserName());
+ }
+
+ @Test
+ void testBooleanGetters() {
+ // ensure that booleans are independent of each other
+ testBoolean("true:false:false", TopicParamsBuilder::allowSelfSignedCerts);
+ testBoolean("false:true:false", TopicParamsBuilder::managed);
+ testBoolean("false:false:true", TopicParamsBuilder::useHttps);
+ }
+
+ @Test
+ void testValidators() {
+ BusTopicParams params = makeBuilder().build();
+
+ // test validity methods
+ assertTrue(params.isAdditionalPropsValid());
+ assertFalse(params.isAftEnvironmentInvalid());
+ assertTrue(params.isApiKeyValid());
+ assertTrue(params.isApiSecretValid());
+ assertFalse(params.isClientNameInvalid());
+ assertFalse(params.isConsumerGroupInvalid());
+ assertFalse(params.isConsumerInstanceInvalid());
+ assertFalse(params.isEnvironmentInvalid());
+ assertFalse(params.isHostnameInvalid());
+ assertFalse(params.isLatitudeInvalid());
+ assertFalse(params.isLongitudeInvalid());
+ assertFalse(params.isPartitionIdInvalid());
+ assertFalse(params.isPartnerInvalid());
+ assertTrue(params.isPasswordValid());
+ assertFalse(params.isPortInvalid());
+ assertFalse(params.isServersInvalid());
+ assertFalse(params.isTopicInvalid());
+ assertTrue(params.isUserNameValid());
+ }
+
+ @Test
+ void testInvertedValidators() {
+ Assertions.assertFalse(makeBuilder().additionalProps(null).build().isAdditionalPropsValid());
+ Assertions.assertTrue(makeBuilder().aftEnvironment("").build().isAftEnvironmentInvalid());
+ Assertions.assertFalse(makeBuilder().apiKey("").build().isApiKeyValid());
+ Assertions.assertFalse(makeBuilder().apiSecret("").build().isApiSecretValid());
+ Assertions.assertTrue(makeBuilder().clientName("").build().isClientNameInvalid());
+ Assertions.assertTrue(makeBuilder().consumerGroup("").build().isConsumerGroupInvalid());
+ Assertions.assertTrue(makeBuilder().consumerInstance("").build().isConsumerInstanceInvalid());
+ Assertions.assertTrue(makeBuilder().environment("").build().isEnvironmentInvalid());
+ Assertions.assertTrue(makeBuilder().hostname("").build().isHostnameInvalid());
+ Assertions.assertTrue(makeBuilder().latitude("").build().isLatitudeInvalid());
+ Assertions.assertTrue(makeBuilder().longitude("").build().isLongitudeInvalid());
+ Assertions.assertTrue(makeBuilder().partitionId("").build().isPartitionIdInvalid());
+ Assertions.assertTrue(makeBuilder().partner("").build().isPartnerInvalid());
+ Assertions.assertFalse(makeBuilder().password("").build().isPasswordValid());
+ Assertions.assertTrue(makeBuilder().port(-1).build().isPortInvalid());
+ Assertions.assertTrue(makeBuilder().port(65536).build().isPortInvalid());
+ Assertions.assertTrue(makeBuilder().servers(null).build().isServersInvalid());
+ Assertions.assertTrue(makeBuilder().servers(new LinkedList<>()).build().isServersInvalid());
+ Assertions.assertTrue(makeBuilder().servers(List.of("")).build().isServersInvalid());
+ Assertions.assertFalse(makeBuilder().servers(List.of("one-server")).build().isServersInvalid());
+ Assertions.assertTrue(makeBuilder().topic("").build().isTopicInvalid());
+ Assertions.assertFalse(makeBuilder().userName("").build().isUserNameValid());
+ }
+
+ /**
+ * Tests the boolean methods by applying a function, once with {@code false} and once
+ * with {@code true}. Verifies that all the boolean methods return the correct
+ * value by concatenating them.
+ *
+ * @param expectedTrue the string that is expected when {@code true} is passed to the
+ * method
+ * @param function function to be applied to the builder
+ */
+ private void testBoolean(String expectedTrue, BiConsumer<TopicParamsBuilder, Boolean> function) {
+ TopicParamsBuilder topicParamsBuilder = BusTopicParams.builder();
+
+ // first try the "false" case
+ function.accept(topicParamsBuilder, false);
+
+ BusTopicParams params = topicParamsBuilder.build();
+ assertEquals("false:false:false",
+ params.isAllowSelfSignedCerts() + ":" + params.isManaged() + ":" + params.isUseHttps());
+
+
+ // now try the "true" case
+ function.accept(topicParamsBuilder, true);
+
+ params = topicParamsBuilder.build();
+ assertEquals(expectedTrue,
+ params.isAllowSelfSignedCerts() + ":" + params.isManaged() + ":" + params.isUseHttps());
+ }
+
+ public TopicParamsBuilder makeBuilder() {
+
+ return BusTopicParams.builder().additionalProps(addProps).aftEnvironment(MY_AFT_ENV).allowSelfSignedCerts(true)
+ .apiKey(MY_API_KEY).apiSecret(MY_API_SECRET).basePath(MY_BASE_PATH).clientName(MY_CLIENT_NAME)
+ .consumerGroup(MY_CONS_GROUP).consumerInstance(MY_CONS_INST).environment(MY_ENV)
+ .fetchLimit(MY_FETCH_LIMIT).fetchTimeout(MY_FETCH_TIMEOUT).hostname(MY_HOST).latitude(MY_LAT)
+ .longitude(MY_LONG).managed(true).partitionId(MY_PARTITION).partner(MY_PARTNER)
+ .password(MY_PASS).port(MY_PORT).servers(List.of("localhost")).topic(MY_TOPIC)
+ .effectiveTopic(MY_EFFECTIVE_TOPIC).useHttps(true).allowTracing(true).userName(MY_USERNAME)
+ .serializationProvider(MY_SERIALIZER);
+ }
+}