SPDX-License-Identifier: Apache-2.0
============LICENSE_END=========================================================
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onap.policy.common</groupId>
<artifactId>common-parameters</artifactId>
<name>${project.artifactId}</name>
- <description>[${project.parent.artifactId}] module provides common property and parameter handling the ONAP Policy Framework</description>
+ <description>[${project.parent.artifactId}] module provides common property and parameter handling the ONAP Policy
+ Framework
+ </description>
<dependencies>
<dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- <scope>provided</scope>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
</dependency>
<dependency>
- <groupId>org.projectlombok</groupId>
- <artifactId>lombok</artifactId>
+ <groupId>com.google.re2j</groupId>
+ <artifactId>re2j</artifactId>
</dependency>
<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
- <groupId>com.google.re2j</groupId>
- <artifactId>re2j</artifactId>
+ <groupId>org.projectlombok</groupId>
+ <artifactId>lombok</artifactId>
</dependency>
<dependency>
- <groupId>com.google.code.gson</groupId>
- <artifactId>gson</artifactId>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
- <groupId>org.assertj</groupId>
- <artifactId>assertj-core</artifactId>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <scope>test</scope>
</dependency>
</dependencies>
</project>
/*-
- * ============LICENSE_START=======================================================
+ * ============LICENSE_START=========================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2021 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
*
* @return the group name
*/
- public String getName();
+ String getName();
/**
* Set the group name.
*
* @param name the group name
*/
- public void setName(final String name);
+ void setName(final String name);
/**
* Validate parameters.
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. 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.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
*
* @return the name
*/
- public String getName();
+ String getName();
/**
* Gets the status of validation.
*
* @return the status
*/
- public ValidationStatus getStatus();
+ ValidationStatus getStatus();
/**
* Checks if the result is valid.
* @return true, if is valid
*/
default boolean isValid() {
- return getStatus().isValid();
+ return getStatus().isValid();
}
/**
* @return true, if is clean
*/
default boolean isClean() {
- return getStatus().isClean();
+ return getStatus().isClean();
}
/**
*/
default String getResult() {
return getResult(
- ParameterConstants.DEFAULT_INITIAL_RESULT_INDENTATION,
- ParameterConstants.DEFAULT_RESULT_INDENTATION,
- ParameterConstants.DO_NOT_SHOW_CLEAN_RESULTS);
+ ParameterConstants.DEFAULT_INITIAL_RESULT_INDENTATION,
+ ParameterConstants.DEFAULT_RESULT_INDENTATION,
+ ParameterConstants.DO_NOT_SHOW_CLEAN_RESULTS);
}
/**
* Gets the validation result.
*
* @param initialIndentation the indentation to use on the main result output
- * @param subIndentation the indentation to use on sub parts of the result output
- * @param showClean output information on clean fields
+ * @param subIndentation the indentation to use on sub parts of the result output
+ * @param showClean output information on clean fields
* @return the result
*/
- public String getResult(final String initialIndentation, final String subIndentation, final boolean showClean);
-
+ String getResult(final String initialIndentation, final String subIndentation, final boolean showClean);
+
/**
- * Set a validation result.
- * @param status The validation status the field is receiving
+ * Set a validation result.
+ *
+ * @param status The validation status the field is receiving
* @param message The validation message explaining the validation status
*/
- public void setResult(final ValidationStatus status, final String message);
+ void setResult(final ValidationStatus status, final String message);
}
\ No newline at end of file
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
+ * Copyright (C) 2021, 2024 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.parameters;
+package org.onap.policy.common.parameters.rest;
-import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.common.parameters.ParameterGroup;
import org.onap.policy.common.parameters.ValidationStatus;
+import org.onap.policy.common.parameters.topic.BusTopicParams;
public class RestClientParameters extends BusTopicParams implements ParameterGroup {
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019,2023 Nordix Foundation.
+ * Copyright (C) 2019, 2023-2024 Nordix Foundation.
* Modifications Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
* ================================================================================
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.parameters;
+package org.onap.policy.common.parameters.rest;
import lombok.Getter;
import org.onap.policy.common.parameters.ParameterGroupImpl;
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.bus.internal;
+package org.onap.policy.common.parameters.topic;
import java.util.List;
import java.util.Map;
return StringUtils.isBlank(longitude);
}
- boolean isConsumerInstanceInvalid() {
+ public boolean isConsumerInstanceInvalid() {
return StringUtils.isBlank(consumerInstance);
}
- boolean isConsumerGroupInvalid() {
+ public boolean isConsumerGroupInvalid() {
return StringUtils.isBlank(consumerGroup);
}
boolean isServersInvalid() {
return (servers == null || servers.isEmpty()
- || (servers.size() == 1 && ("".equals(servers.get(0)))));
+ || (servers.size() == 1 && ("".equals(servers.get(0)))));
}
- boolean isTopicInvalid() {
+ public boolean isTopicInvalid() {
return StringUtils.isBlank(topic);
}
- boolean isPartitionIdInvalid() {
+ public boolean isPartitionIdInvalid() {
return StringUtils.isBlank(partitionId);
}
}
public boolean isPortInvalid() {
- return (getPort() <= 0 || getPort() >= 65535);
+ return (getPort() <= 0 || getPort() >= 65535);
}
/**
return StringUtils.isNotBlank(password);
}
- boolean isAdditionalPropsValid() {
+ public boolean isAdditionalPropsValid() {
return additionalProps != null;
}
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.parameters;
+package org.onap.policy.common.parameters.topic;
import java.util.List;
import lombok.Getter;
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019, 2024 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.parameters;
+package org.onap.policy.common.parameters.topic;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
-import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
import org.onap.policy.common.parameters.annotations.NotBlank;
import org.onap.policy.common.parameters.annotations.NotNull;
@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());
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());
data.strValue = STRING_VALUE;
assertTrue(validator.validateTop(TOP, data).isValid());
- /**
- * Repeat with a subclass.
- */
@Getter
class Derived extends Data {
@Min(10)
@Test
void testVerNotNull() {
+ @Getter
class NotNullCheck {
- @Getter
@Min(1)
@NotNull
Integer intValue;
@Test
void testVerNotBlank() {
+ @Getter
class NotBlankCheck {
- @Getter
@NotBlank
String strValue;
}
/*
* Class with "blank" annotation on an integer.
*/
+ @Getter
class NotBlankInt {
- @Getter
@NotBlank
int intValue;
}
*/
@Test
void testVerSizeCollection() {
+ @Getter
class CollectionSizeCheck {
- @Getter
@Size(min = 3)
Collection<Integer> items;
}
*/
@Test
void testVerSizeMap() {
+ @Getter
class MapSizeCheck {
- @Getter
@Size(min = 3)
Map<Integer, Integer> items;
}
*/
@Test
void testVerSizeOther() {
+ @Getter
class OtherSizeCheck {
- @Getter
@Size(min = 3)
Integer items;
}
@Test
void testVerRegex() {
+ @Getter
class RegexCheck {
- @Getter
@Pattern(regexp = "[a-f]*")
String strValue;
}
assertTrue(validator.validateTop(TOP, regexCheck).isValid());
// invalid regex
+ @Getter
class InvalidRegexCheck {
- @Getter
@Pattern(regexp = "[a-f")
String strValue;
}
/*
* Class with "regex" annotation on an integer.
*/
+ @Getter
class RegexInt {
- @Getter
@Pattern(regexp = "[a-f]*")
int intValue;
}
/*
* Field is not a number.
*/
+ @Getter
class NonNumeric {
- @Getter
@Max(100)
String strValue;
}
/*
* 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;
}
/*
* Field is not a number.
*/
+ @Getter
class NonNumeric {
- @Getter
@Min(10)
String strValue;
}
/*
* 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;
}
@Test
void testVerClassName() {
+ @Getter
class ClassNameCheck {
- @Getter
@ClassName
String strValue;
}
@Test
void testVerCascade() {
+ @Getter
class Item {
- @Getter
@NotNull
Integer intValue;
}
@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
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;
}
public int getParameterizedMethod(boolean flag) {
- return 0;
+ return flag ? 0 : 1;
}
public int getExMethod() {
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.parameters;
+package org.onap.policy.common.parameters.rest;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
--- /dev/null
+/*
+ * ============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);
+ }
+}
<packaging>jar</packaging>
<dependencies>
+ <dependency>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.google.re2j</groupId>
+ <artifactId>re2j</artifactId>
+ </dependency>
<dependency>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
- <dependency>
- <groupId>com.google.code.gson</groupId>
- <artifactId>gson</artifactId>
- </dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
- <dependency>
- <groupId>com.google.re2j</groupId>
- <artifactId>re2j</artifactId>
- </dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
import java.util.Map;
import java.util.TreeMap;
import java.util.TreeSet;
-import java.util.stream.Collectors;
+import lombok.Getter;
+import lombok.Setter;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.onap.policy.common.gson.annotation.GsonJsonAnyGetter;
void testExamineClassOfQ_testExamineField_testExamineInField_testExamineOutField() {
walker.walkClassHierarchy(DerivedFromBottom.class);
- assertEquals("[Intfc1, Intfc2, Intfc1, Intfc3, Bottom, DerivedFromBottom]", walker.classes.toString());
+ assertEquals("[InterfaceOne, InterfaceTwo, InterfaceOne, InterfaceThree, Bottom, DerivedFromBottom]",
+ walker.classes.toString());
- List<String> inFields = walker.getInProps(Field.class).stream().map(Field::getName)
- .collect(Collectors.toList());
- Collections.sort(inFields);
+ List<String> inFields = walker.getInProps(Field.class).stream().map(Field::getName).sorted().toList();
assertEquals("[exposedField, overriddenValue, transField]", inFields.toString());
- List<String> outFields = walker.getInProps(Field.class).stream().map(Field::getName)
- .collect(Collectors.toList());
- Collections.sort(outFields);
+ List<String> outFields = walker.getInProps(Field.class).stream().map(Field::getName).sorted().toList();
assertEquals("[exposedField, overriddenValue, transField]", outFields.toString());
// should work with interfaces without throwing an NPE
- walker.walkClassHierarchy(Intfc1.class);
+ walker.walkClassHierarchy(InterfaceOne.class);
}
@Test
assertNotNull(walker.getAnyGetter());
assertEquals("getTheMap", walker.getAnyGetter().getName());
- List<String> getters = walker.getOutProps(Method.class).stream().map(Method::getName)
- .collect(Collectors.toList());
- Collections.sort(getters);
+ List<String> getters = walker.getOutProps(Method.class).stream().map(Method::getName).sorted().toList();
assertEquals("[getId, getOnlyOut, getValue]", getters.toString());
assertNotNull(walker.getAnySetter());
assertEquals("setMapValue", walker.getAnySetter().getName());
- List<String> setters = walker.getInProps(Method.class).stream().map(Method::getName)
- .collect(Collectors.toList());
- Collections.sort(setters);
+ List<String> setters = walker.getInProps(Method.class).stream().map(Method::getName).sorted().toList();
assertEquals("[setId, setOnlyIn, setValue]", setters.toString());
// getter with invalid parameter count
* Walker subclass that records items that are examined.
*/
private static class MyWalker extends ClassWalker {
- private List<String> classes = new ArrayList<>();
- private List<String> methods = new ArrayList<>();
+ private final List<String> classes = new ArrayList<>();
+ private final List<String> methods = new ArrayList<>();
@Override
protected void examine(Class<?> clazz) {
}
}
- protected static interface Intfc1 {
- int id = 1000;
+ protected interface InterfaceOne {
+ int id = 1000; // NOSONAR I think this is meant to be accessible as fields, not constants
}
- protected static interface Intfc2 {
- String text = "intfc2-text";
+ protected interface InterfaceTwo {
+ String text = "intfc2-text"; // NOSONAR I think this is meant to be accessible as fields, not constants
}
- private static interface Intfc3 {
+ private interface InterfaceThree {
}
- protected static class Bottom implements Intfc1, Intfc3 {
+ protected static class Bottom implements InterfaceOne, InterfaceThree {
private int id;
public String value;
}
}
- protected static class DerivedFromBottom extends Bottom implements Intfc1, Intfc2 {
+ protected static class DerivedFromBottom extends Bottom implements InterfaceOne, InterfaceTwo {
private String text;
protected String anotherValue;
}
}
+ @Setter
protected static class Data {
+ @Getter
private int id;
+ // this will be ignored, because there's already a field by this name
private String text;
- public int getId() {
- return id;
- }
-
- public void setId(int id) {
- this.id = id;
- }
-
// not public, but property provided
@GsonJsonProperty("text")
protected String getText() {
return text;
}
- // this will be ignored, because there's already a field by this name
- public void setText(String text) {
- this.text = text;
- }
-
// should only show up in the output list
public int getOnlyOut() {
return 1100;
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ============LICENSE_START=======================================================
+ ONAP Policy Engine - Common Modules
+ ================================================================================
+ 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=========================================================
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.onap.policy.common</groupId>
+ <artifactId>common-modules</artifactId>
+ <version>3.0.1-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>message-bus</artifactId>
+
+ <properties>
+ <maven.compiler.source>17</maven.compiler.source>
+ <maven.compiler.target>17</maven.compiler.target>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.onap.policy.common</groupId>
+ <artifactId>capabilities</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.policy.common</groupId>
+ <artifactId>common-parameters</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.policy.common</groupId>
+ <artifactId>gson</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.policy.common</groupId>
+ <artifactId>utils</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-core</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.google.re2j</groupId>
+ <artifactId>re2j</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>io.opentelemetry</groupId>
+ <artifactId>opentelemetry-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.opentelemetry</groupId>
+ <artifactId>opentelemetry-context</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.opentelemetry.instrumentation</groupId>
+ <artifactId>opentelemetry-kafka-clients-2.6</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-collections4</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.kafka</groupId>
+ <artifactId>kafka-clients</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.projectlombok</groupId>
+ <artifactId>lombok</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-junit-jupiter</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.policy.common</groupId>
+ <artifactId>utils-test</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm;
+package org.onap.policy.common.message.bus.event;
import java.util.List;
import org.onap.policy.common.capabilities.Lockable;
/**
* Get the more recent events in this topic entity.
*
- * @return list of most recent events
+ * @return array of most recent events
*/
String[] getRecentEvents();
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm;
+package org.onap.policy.common.message.bus.event;
import java.util.List;
import java.util.Properties;
import org.onap.policy.common.capabilities.Lockable;
import org.onap.policy.common.capabilities.Startable;
-import org.onap.policy.common.endpoints.event.comm.bus.KafkaTopicSink;
-import org.onap.policy.common.endpoints.event.comm.bus.KafkaTopicSource;
-import org.onap.policy.common.endpoints.event.comm.bus.NoopTopicSink;
-import org.onap.policy.common.endpoints.event.comm.bus.NoopTopicSource;
-import org.onap.policy.common.endpoints.parameters.TopicParameterGroup;
-import org.onap.policy.common.endpoints.parameters.TopicParameters;
+import org.onap.policy.common.message.bus.event.kafka.KafkaTopicSink;
+import org.onap.policy.common.message.bus.event.kafka.KafkaTopicSource;
+import org.onap.policy.common.message.bus.event.noop.NoopTopicSink;
+import org.onap.policy.common.message.bus.event.noop.NoopTopicSource;
+import org.onap.policy.common.parameters.topic.TopicParameterGroup;
+import org.onap.policy.common.parameters.topic.TopicParameters;
/**
* Abstraction to manage the system's Networked Topic Endpoints, sources of all events input into
* ONAP
* ================================================================================
* Copyright (C) 2019, 2021 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.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm;
+package org.onap.policy.common.message.bus.event;
import lombok.AccessLevel;
import lombok.Getter;
* Topic endpoint manager.
*/
@Getter
- private static TopicEndpoint manager = new TopicEndpointProxy();
+ static TopicEndpoint manager = new TopicEndpointProxy();
}
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm;
+package org.onap.policy.common.message.bus.event;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Properties;
import lombok.Getter;
import org.onap.policy.common.capabilities.Startable;
-import org.onap.policy.common.endpoints.event.comm.bus.KafkaTopicFactories;
-import org.onap.policy.common.endpoints.event.comm.bus.KafkaTopicSink;
-import org.onap.policy.common.endpoints.event.comm.bus.KafkaTopicSource;
-import org.onap.policy.common.endpoints.event.comm.bus.NoopTopicFactories;
-import org.onap.policy.common.endpoints.event.comm.bus.NoopTopicSink;
-import org.onap.policy.common.endpoints.event.comm.bus.NoopTopicSource;
-import org.onap.policy.common.endpoints.parameters.TopicParameterGroup;
-import org.onap.policy.common.endpoints.parameters.TopicParameters;
import org.onap.policy.common.gson.annotation.GsonJsonIgnore;
+import org.onap.policy.common.message.bus.event.kafka.KafkaTopicFactories;
+import org.onap.policy.common.message.bus.event.kafka.KafkaTopicSink;
+import org.onap.policy.common.message.bus.event.kafka.KafkaTopicSource;
+import org.onap.policy.common.message.bus.event.noop.NoopTopicFactories;
+import org.onap.policy.common.message.bus.event.noop.NoopTopicSink;
+import org.onap.policy.common.message.bus.event.noop.NoopTopicSource;
+import org.onap.policy.common.parameters.topic.TopicParameterGroup;
+import org.onap.policy.common.parameters.topic.TopicParameters;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/*-
* ============LICENSE_START=======================================================
- * policy-endpoints
- * ================================================================================
* Copyright (C) 2017 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.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm;
+package org.onap.policy.common.message.bus.event;
/**
* Listener for event messages entering the Policy Engine.
/**
* Notification of a new Event over a given Topic.
- *
+ *
* @param commType communication infrastructure type
- * @param topic topic name
- * @param event event message as a string
+ * @param topic topic name
+ * @param event event message as a string
*/
- public void onTopicEvent(Topic.CommInfrastructure commType, String topic, String event);
+ void onTopicEvent(Topic.CommInfrastructure commType, String topic, String event);
}
/*-
* ============LICENSE_START=======================================================
- * policy-endpoints
- * ================================================================================
* Copyright (C) 2017 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.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm;
+package org.onap.policy.common.message.bus.event;
/**
* Marks a Topic entity as registerable.
/**
* Register for notification of events with this Topic Entity.
- *
+ *
* @param topicListener the listener of events
*/
- public void register(TopicListener topicListener);
+ void register(TopicListener topicListener);
/**
* Unregisters for notification of events with this Topic Entity.
- *
+ *
* @param topicListener the listener of events
*/
- public void unregister(TopicListener topicListener);
+ void unregister(TopicListener topicListener);
}
/*
* ============LICENSE_START=======================================================
- * policy-endpoints
- * ================================================================================
* Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2023 Nordix Foundation.
+ * Modifications Copyright (C) 2023-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.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm;
+package org.onap.policy.common.message.bus.event;
/**
* Marks a given Topic Endpoint as able to send messages over a topic.
/**
* Sends a string message over this Topic Endpoint.
- *
+ *
* @param message message to send
- *
* @return true if the send operation succeeded, false otherwise
* @throws IllegalArgumentException an invalid message has been provided
- * @throws IllegalStateException the entity is in a state that prevents
+ * @throws IllegalStateException the entity is in a state that prevents
* it from sending messages, for example, locked or stopped.
*/
boolean send(String message);
/*-
* ============LICENSE_START=======================================================
- * policy-endpoints
- * ================================================================================
* Copyright (C) 2017 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.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm;
+package org.onap.policy.common.message.bus.event;
/**
* Marker for a Topic Entity, indicating that the entity is able to read
public interface TopicSource extends Topic {
/**
- * Pushes an event into the source programatically.
- *
+ * Pushes an event into the source programmatically.
+ *
* @param event the event in json format
* @return true if it can be processed correctly, false otherwise
*/
- public boolean offer(String event);
+ boolean offer(String event);
}
\ No newline at end of file
/*-
* ============LICENSE_START=======================================================
- * policy-endpoints
- * ================================================================================
* Copyright (C) 2017 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.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.bus;
+package org.onap.policy.common.message.bus.event.base;
/**
* API.
public interface ApiKeyEnabled {
/**
* Get API key.
- *
+ *
* @return api key
*/
- public String getApiKey();
+ String getApiKey();
/**
* Get API secret.
- *
+ *
* @return api secret
*/
- public String getApiSecret();
+ String getApiSecret();
}
/*
* ============LICENSE_START=======================================================
- * policy-endpoints
- * ================================================================================
* Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2018 Samsung Electronics Co., Ltd.
* Modifications Copyright (C) 2020,2023 Bell Canada. All rights reserved.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.bus.internal;
+package org.onap.policy.common.message.bus.event.base;
+
+import static org.onap.policy.common.message.bus.properties.MessageBusProperties.DEFAULT_TIMEOUT_MS_FETCH;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.SpanContext;
import org.apache.kafka.clients.consumer.OffsetAndMetadata;
import org.apache.kafka.common.TopicPartition;
import org.apache.kafka.common.header.Headers;
-import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
+import org.onap.policy.common.parameters.topic.BusTopicParams;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* @return list of messages
* @throws IOException when error encountered by underlying libraries
*/
- public Iterable<String> fetch() throws IOException;
+ Iterable<String> fetch() throws IOException;
/**
* close underlying library consumer.
*/
- public void close();
+ void close();
/**
* Consumer that handles fetch() failures by sleeping.
this.fetchTimeout = busTopicParams.getFetchTimeout();
if (this.fetchTimeout <= 0) {
- this.sleepTime = PolicyEndPointProperties.DEFAULT_TIMEOUT_MS_FETCH;
+ this.sleepTime = DEFAULT_TIMEOUT_MS_FETCH;
} else {
// don't sleep too long, even if fetch timeout is large
- this.sleepTime = Math.min(this.fetchTimeout, PolicyEndPointProperties.DEFAULT_TIMEOUT_MS_FETCH);
+ this.sleepTime = Math.min(this.fetchTimeout, DEFAULT_TIMEOUT_MS_FETCH);
}
}
if (busTopicParams.isAllowTracing()) {
this.allowTracing = true;
kafkaProps.setProperty(ConsumerConfig.INTERCEPTOR_CLASSES_CONFIG,
- TracingConsumerInterceptor.class.getName());
+ TracingConsumerInterceptor.class.getName());
}
consumer = new KafkaConsumer<>(kafkaProps);
}
SpanContext spanContext = SpanContext.createFromRemoteParent(
- traceParentInfo.getTraceId(), traceParentInfo.getSpanId(),
- TraceFlags.getSampled(), TraceState.builder().build());
+ traceParentInfo.getTraceId(), traceParentInfo.getSpanId(),
+ TraceFlags.getSampled(), TraceState.builder().build());
Context.current().with(Span.wrap(spanContext)).makeCurrent();
}
TraceParentInfo traceParentInfo = new TraceParentInfo();
if (headers.lastHeader("traceparent") != null) {
traceParentInfo.setParentTraceId(new String(headers.lastHeader(
- "traceparent").value(), StandardCharsets.UTF_8));
+ "traceparent").value(), StandardCharsets.UTF_8));
String[] parts = traceParentInfo.getParentTraceId().split("-");
traceParentInfo.setTraceId(parts[1]);
--- /dev/null
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2018 Samsung Electronics Co., Ltd.
+ * Modifications Copyright (C) 2020,2023 Bell Canada. All rights reserved.
+ * Modifications Copyright (C) 2022-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.message.bus.event.base;
+
+public interface BusPublisher {
+
+ String NO_MESSAGE_PROVIDED = "No message provided";
+ String LOG_CLOSE = "{}: CLOSE";
+
+ /**
+ * sends a message.
+ *
+ * @param partitionId id
+ * @param message the message
+ * @return true if success, false otherwise
+ * @throws IllegalArgumentException if no message provided
+ */
+ boolean send(String partitionId, String message);
+
+ /**
+ * closes the publisher.
+ */
+ void close();
+}
* ================================================================================
* Copyright (C) 2017-2019, 2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2020 Bell Canada. 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.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.bus.internal;
+package org.onap.policy.common.message.bus.event.base;
import lombok.Getter;
-import org.onap.policy.common.endpoints.event.comm.bus.ApiKeyEnabled;
+import org.onap.policy.common.parameters.topic.BusTopicParams;
/**
* Bus Topic Base.
protected boolean allowTracing;
/**
- * allow self signed certificates.
+ * allow self-signed certificates.
*/
protected boolean allowSelfSignedCerts;
* Instantiates a new Bus Topic Base.
*
* <p>servers list of servers
- * topic topic name
- * apiKey API Key
- * apiSecret API Secret
- * useHttps does connection use HTTPS?
- * allowTracing Is tracing allowed?
- * allowSelfSignedCerts are self-signed certificates allow
+ * topic: the topic name
+ * apiKey: API Key
+ * apiSecret: API Secret
+ * useHttps: does connection use HTTPS?
+ * allowTracing: Is tracing allowed?
+ * allowSelfSignedCerts: are self-signed certificates allow
+ *
* @param busTopicParams holds all our parameters
* @throws IllegalArgumentException if invalid parameters are present
*/
@Override
public String toString() {
return "BusTopicBase [apiKey=" + apiKey + ", apiSecret=" + apiSecret + ", useHttps=" + useHttps
- + ", allowSelfSignedCerts=" + allowSelfSignedCerts + ", toString()=" + super.toString() + "]";
+ + ", allowSelfSignedCerts=" + allowSelfSignedCerts + ", toString()=" + super.toString() + "]";
}
}
/*-
* ============LICENSE_START=======================================================
- * policy-endpoints
- * ================================================================================
* Copyright (C) 2017, 2019 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2023-2024 Nordix Foundation.
* ================================================================================
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.bus;
+package org.onap.policy.common.message.bus.event.base;
-import org.onap.policy.common.endpoints.event.comm.TopicSink;
+import org.onap.policy.common.message.bus.event.TopicSink;
/**
* Topic Sink over Bus Infrastructure (KAFKA).
/*-
* ============LICENSE_START=======================================================
- * policy-endpoints
- * ================================================================================
* Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2024 Nordix Foundation.
* ================================================================================
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.bus;
+package org.onap.policy.common.message.bus.event.base;
-import org.onap.policy.common.endpoints.event.comm.TopicSource;
+import org.onap.policy.common.message.bus.event.TopicSource;
/**
* Generic Topic Source for Bus Communication Infrastructure.
/*
* ============LICENSE_START=======================================================
- * policy-endpoints
- * ================================================================================
* Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2018-2019 Samsung Electronics Co., Ltd.
* Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.bus.internal;
+package org.onap.policy.common.message.bus.event.base;
import java.util.UUID;
import lombok.Getter;
import lombok.Setter;
-import org.onap.policy.common.endpoints.event.comm.bus.BusTopicSink;
-import org.onap.policy.common.endpoints.utils.NetLoggerUtil;
-import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
+import org.onap.policy.common.message.bus.utils.NetLoggerUtil;
+import org.onap.policy.common.message.bus.utils.NetLoggerUtil.EventType;
+import org.onap.policy.common.parameters.topic.BusTopicParams;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Loggers.
*/
- private static Logger logger = LoggerFactory.getLogger(InlineBusTopicSink.class);
+ private static final Logger logger = LoggerFactory.getLogger(InlineBusTopicSink.class);
/**
* The partition key to publish to.
/**
* Constructor for abstract sink.
* @param busTopicParams contains below listed attributes
- * servers servers
- * topic topic
- * apiKey api secret
- * apiSecret api secret
- * partitionId partition id
- * useHttps does connection use HTTPS?
- * allowTracing is tracing allowed?
- * allowSelfSignedCerts are self-signed certificates allow *
+ * servers: servers
+ * topic: topic
+ * apiKey: api secret
+ * apiSecret: api secret
+ * partitionId: partition id
+ * useHttps: does connection use HTTPS?
+ * allowTracing: is tracing allowed?
+ * allowSelfSignedCerts: are self-signed certificates allow *
* @throws IllegalArgumentException if invalid parameters are passed in
*/
protected InlineBusTopicSink(BusTopicParams busTopicParams) {
/*-
* ============LICENSE_START=======================================================
- * policy-endpoints
- * ================================================================================
* Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2018-2019 Samsung Electronics Co., Ltd.
* Modifications Copyright (C) 2020 Bell Canada. 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.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.bus.internal;
+package org.onap.policy.common.message.bus.event.base;
+
+import static org.onap.policy.common.message.bus.properties.MessageBusProperties.NO_LIMIT_FETCH;
+import static org.onap.policy.common.message.bus.properties.MessageBusProperties.NO_TIMEOUT_MS_FETCH;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.UUID;
import lombok.Getter;
-import org.onap.policy.common.endpoints.event.comm.TopicListener;
-import org.onap.policy.common.endpoints.event.comm.bus.BusTopicSource;
-import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
-import org.onap.policy.common.endpoints.utils.NetLoggerUtil;
-import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
+import org.onap.policy.common.message.bus.event.TopicListener;
+import org.onap.policy.common.message.bus.utils.NetLoggerUtil;
+import org.onap.policy.common.message.bus.utils.NetLoggerUtil.EventType;
+import org.onap.policy.common.parameters.topic.BusTopicParams;
import org.onap.policy.common.utils.network.NetworkUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
implements Runnable, BusTopicSource {
/**
- * Not to be converted to PolicyLogger. This will contain all instract /out traffic and only
+ * Not to be converted to PolicyLogger. This will contain all in/out traffic and only
* that in a single file in a concise format.
*/
- private static Logger logger = LoggerFactory.getLogger(SingleThreadedBusTopicSource.class);
+ private static final Logger logger = LoggerFactory.getLogger(SingleThreadedBusTopicSource.class);
/**
* Bus consumer group.
}
if (busTopicParams.getFetchTimeout() <= 0) {
- this.fetchTimeout = PolicyEndPointProperties.NO_TIMEOUT_MS_FETCH;
+ this.fetchTimeout = NO_TIMEOUT_MS_FETCH;
} else {
this.fetchTimeout = busTopicParams.getFetchTimeout();
}
if (busTopicParams.getFetchLimit() <= 0) {
- this.fetchLimit = PolicyEndPointProperties.NO_LIMIT_FETCH;
+ this.fetchLimit = NO_LIMIT_FETCH;
} else {
this.fetchLimit = busTopicParams.getFetchLimit();
}
* ================================================================================
* Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
- * Modifications Copyright (C) 2023 Nordix Foundation.
+ * Modifications Copyright (C) 2023-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.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.bus.internal;
+package org.onap.policy.common.message.bus.event.base;
import java.util.ArrayList;
import java.util.List;
import lombok.AccessLevel;
import lombok.Getter;
import org.apache.commons.collections4.queue.CircularFifoQueue;
-import org.onap.policy.common.endpoints.event.comm.Topic;
-import org.onap.policy.common.endpoints.event.comm.TopicListener;
+import org.onap.policy.common.message.bus.event.Topic;
+import org.onap.policy.common.message.bus.event.TopicListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* ONAP
* ================================================================================
* Copyright (C) 2019 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.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.bus;
+package org.onap.policy.common.message.bus.event.base;
import java.util.List;
import java.util.Properties;
-import org.onap.policy.common.endpoints.event.comm.Topic;
-import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
+import org.onap.policy.common.message.bus.event.Topic;
+import org.onap.policy.common.parameters.topic.BusTopicParams;
/**
* Topic Base Factory.
* ONAP
* ================================================================================
* Copyright (C) 2019, 2021 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.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.bus;
+package org.onap.policy.common.message.bus.event.base;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Properties;
-import org.onap.policy.common.endpoints.event.comm.Topic;
-import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
+import org.onap.policy.common.message.bus.event.Topic;
+import org.onap.policy.common.parameters.topic.BusTopicParams;
/**
* Topic Factory implementation that indexes T instances in a hash table.
* @param topic topic.
* @return an instance of T.
*/
- protected abstract T build(List<String> servers, String topic);
+ public abstract T build(List<String> servers, String topic);
/**
* {@inheritDoc}.
* ONAP
* ================================================================================
* Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2023 Nordix Foundation.
+ * Modifications Copyright (C) 2023-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.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.client;
+package org.onap.policy.common.message.bus.event.client;
-import jakarta.validation.constraints.NotNull;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.TimeUnit;
import lombok.Getter;
-import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
-import org.onap.policy.common.endpoints.event.comm.TopicEndpoint;
-import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
-import org.onap.policy.common.endpoints.event.comm.TopicListener;
-import org.onap.policy.common.endpoints.event.comm.TopicSink;
-import org.onap.policy.common.endpoints.event.comm.TopicSource;
+import org.onap.policy.common.message.bus.event.Topic.CommInfrastructure;
+import org.onap.policy.common.message.bus.event.TopicEndpoint;
+import org.onap.policy.common.message.bus.event.TopicEndpointManager;
+import org.onap.policy.common.message.bus.event.TopicListener;
+import org.onap.policy.common.message.bus.event.TopicSink;
+import org.onap.policy.common.message.bus.event.TopicSource;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
return checkerQueue.peek();
}
- @NotNull
private <T> TopicListener getTopicListener(T message) {
@SuppressWarnings("unchecked")
final Class<? extends T> clazz = (Class<? extends T>) message.getClass();
}
/**
- * Stops any listeners that are currently stuck in {@link #awaitReady(Object)} by
+ * Stops any listeners that are currently stuck in {@link #awaitReady(Object, long)} by
* adding {@code false} to the queue.
*/
public void stopWaiting() {
* ONAP
* ================================================================================
* Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2023 Nordix Foundation.
+ * Modifications Copyright (C) 2023-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.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.client;
+package org.onap.policy.common.message.bus.event.client;
import java.io.Serial;
/*-
* ============LICENSE_START=======================================================
- * ONAP PAP
+ * ONAP
* ================================================================================
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019, 2024 Nordix Foundation.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.client;
+package org.onap.policy.common.message.bus.event.client;
import java.util.List;
import lombok.Getter;
import lombok.NonNull;
-import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
-import org.onap.policy.common.endpoints.event.comm.TopicSink;
+import org.onap.policy.common.message.bus.event.TopicEndpointManager;
+import org.onap.policy.common.message.bus.event.TopicSink;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
/*-
* ============LICENSE_START=======================================================
- * ONAP PAP
+ * ONAP
* ================================================================================
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019, 2023 Nordix Foundation.
+ * Modifications Copyright (C) 2019, 2023-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.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.client;
+package org.onap.policy.common.message.bus.event.client;
import java.io.Serial;
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2022-2023 Nordix Foundation.
+ * Copyright (C) 2022-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.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.bus;
+package org.onap.policy.common.message.bus.event.kafka;
+
+import static org.onap.policy.common.message.bus.properties.MessageBusProperties.PROPERTY_KAFKA_SINK_TOPICS;
+import static org.onap.policy.common.message.bus.properties.MessageBusProperties.PROPERTY_TOPIC_SERVERS_SUFFIX;
+import static org.onap.policy.common.message.bus.properties.MessageBusProperties.PROPERTY_TOPIC_SINK_PARTITION_KEY_SUFFIX;
import com.google.re2j.Pattern;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import org.apache.commons.lang3.StringUtils;
-import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
-import org.onap.policy.common.endpoints.event.comm.bus.internal.InlineKafkaTopicSink;
-import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
-import org.onap.policy.common.endpoints.utils.KafkaPropertyUtils;
-import org.onap.policy.common.endpoints.utils.PropertyUtils;
+import org.onap.policy.common.message.bus.utils.KafkaPropertyUtils;
+import org.onap.policy.common.parameters.topic.BusTopicParams;
+import org.onap.policy.common.utils.properties.PropertyUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Override
public List<KafkaTopicSink> build(Properties properties) {
- String writeTopics = properties.getProperty(PolicyEndPointProperties.PROPERTY_KAFKA_SINK_TOPICS);
+ String writeTopics = properties.getProperty(PROPERTY_KAFKA_SINK_TOPICS);
if (StringUtils.isBlank(writeTopics)) {
logger.info("{}: no topic for KAFKA Sink", this);
return new ArrayList<>();
return;
}
- String topicPrefix = PolicyEndPointProperties.PROPERTY_KAFKA_SINK_TOPICS + "." + topic;
+ String topicPrefix = PROPERTY_KAFKA_SINK_TOPICS + "." + topic;
var props = new PropertyUtils(properties, topicPrefix,
(name, value, ex) -> logger.warn("{}: {} {} is in invalid format for topic sink {} ",
this, name, value, topic));
- String servers = properties.getProperty(topicPrefix + PolicyEndPointProperties.PROPERTY_TOPIC_SERVERS_SUFFIX);
+ String servers = properties.getProperty(topicPrefix + PROPERTY_TOPIC_SERVERS_SUFFIX);
if (StringUtils.isBlank(servers)) {
logger.error("{}: no KAFKA servers configured for sink {}", this, topic);
return;
}
KafkaTopicSink kafkaTopicWriter = this.build(KafkaPropertyUtils.makeBuilder(props, topic, servers)
- .partitionId(props.getString(PolicyEndPointProperties.PROPERTY_TOPIC_SINK_PARTITION_KEY_SUFFIX, null))
+ .partitionId(props.getString(PROPERTY_TOPIC_SINK_PARTITION_KEY_SUFFIX, null))
.build());
newKafkaTopicSinks.add(kafkaTopicWriter);
}
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2022-2023 Nordix Foundation.
+ * Copyright (C) 2022-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.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.bus;
+package org.onap.policy.common.message.bus.event.kafka;
+
+import static org.onap.policy.common.message.bus.properties.MessageBusProperties.DEFAULT_LIMIT_FETCH;
+import static org.onap.policy.common.message.bus.properties.MessageBusProperties.DEFAULT_TIMEOUT_MS_FETCH;
+import static org.onap.policy.common.message.bus.properties.MessageBusProperties.PROPERTY_KAFKA_SOURCE_TOPICS;
+import static org.onap.policy.common.message.bus.properties.MessageBusProperties.PROPERTY_TOPIC_SERVERS_SUFFIX;
+import static org.onap.policy.common.message.bus.properties.MessageBusProperties.PROPERTY_TOPIC_SOURCE_CONSUMER_GROUP_SUFFIX;
+import static org.onap.policy.common.message.bus.properties.MessageBusProperties.PROPERTY_TOPIC_SOURCE_CONSUMER_INSTANCE_SUFFIX;
+import static org.onap.policy.common.message.bus.properties.MessageBusProperties.PROPERTY_TOPIC_SOURCE_FETCH_LIMIT_SUFFIX;
+import static org.onap.policy.common.message.bus.properties.MessageBusProperties.PROPERTY_TOPIC_SOURCE_FETCH_TIMEOUT_SUFFIX;
import com.google.re2j.Pattern;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import org.apache.commons.lang3.StringUtils;
-import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
-import org.onap.policy.common.endpoints.event.comm.bus.internal.SingleThreadedKafkaTopicSource;
-import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
-import org.onap.policy.common.endpoints.utils.KafkaPropertyUtils;
-import org.onap.policy.common.endpoints.utils.PropertyUtils;
+import org.onap.policy.common.message.bus.utils.KafkaPropertyUtils;
+import org.onap.policy.common.parameters.topic.BusTopicParams;
+import org.onap.policy.common.utils.properties.PropertyUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Override
public List<KafkaTopicSource> build(Properties properties) {
- String readTopics = properties.getProperty(PolicyEndPointProperties.PROPERTY_KAFKA_SOURCE_TOPICS);
+ String readTopics = properties.getProperty(PROPERTY_KAFKA_SOURCE_TOPICS);
if (StringUtils.isBlank(readTopics)) {
logger.info("{}: no topic for KAFKA Source", this);
return new ArrayList<>();
.servers(servers)
.topic(topic)
.managed(true)
- .fetchTimeout(PolicyEndPointProperties.DEFAULT_TIMEOUT_MS_FETCH)
- .fetchLimit(PolicyEndPointProperties.DEFAULT_LIMIT_FETCH)
+ .fetchTimeout(DEFAULT_TIMEOUT_MS_FETCH)
+ .fetchLimit(DEFAULT_LIMIT_FETCH)
.useHttps(false).build());
}
return;
}
- String topicPrefix = PolicyEndPointProperties.PROPERTY_KAFKA_SOURCE_TOPICS + "." + topic;
+ String topicPrefix = PROPERTY_KAFKA_SOURCE_TOPICS + "." + topic;
var props = new PropertyUtils(properties, topicPrefix,
(name, value, ex) -> logger.warn("{}: {} {} is in invalid format for topic source {} ",
this, name, value, topic));
- String servers = properties.getProperty(topicPrefix + PolicyEndPointProperties.PROPERTY_TOPIC_SERVERS_SUFFIX);
+ String servers = properties.getProperty(topicPrefix + PROPERTY_TOPIC_SERVERS_SUFFIX);
if (StringUtils.isBlank(servers)) {
logger.error("{}: no KAFKA servers configured for source {}", this, topic);
return;
var kafkaTopicSource = this.build(KafkaPropertyUtils.makeBuilder(props, topic, servers)
.consumerGroup(props.getString(
- PolicyEndPointProperties.PROPERTY_TOPIC_SOURCE_CONSUMER_GROUP_SUFFIX, null))
+ PROPERTY_TOPIC_SOURCE_CONSUMER_GROUP_SUFFIX, null))
.consumerInstance(props.getString(
- PolicyEndPointProperties.PROPERTY_TOPIC_SOURCE_CONSUMER_INSTANCE_SUFFIX, null))
+ PROPERTY_TOPIC_SOURCE_CONSUMER_INSTANCE_SUFFIX, null))
.fetchTimeout(props.getInteger(
- PolicyEndPointProperties.PROPERTY_TOPIC_SOURCE_FETCH_TIMEOUT_SUFFIX,
- PolicyEndPointProperties.DEFAULT_TIMEOUT_MS_FETCH))
- .fetchLimit(props.getInteger(PolicyEndPointProperties.PROPERTY_TOPIC_SOURCE_FETCH_LIMIT_SUFFIX,
- PolicyEndPointProperties.DEFAULT_LIMIT_FETCH))
+ PROPERTY_TOPIC_SOURCE_FETCH_TIMEOUT_SUFFIX,
+ DEFAULT_TIMEOUT_MS_FETCH))
+ .fetchLimit(props.getInteger(PROPERTY_TOPIC_SOURCE_FETCH_LIMIT_SUFFIX,
+ DEFAULT_LIMIT_FETCH))
.build());
newKafkaTopicSources.add(kafkaTopicSource);
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2022-2023 Nordix Foundation.
+ * Copyright (C) 2022-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.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.bus.internal;
+package org.onap.policy.common.message.bus.event.kafka;
import java.util.Map;
-import org.onap.policy.common.endpoints.event.comm.Topic;
-import org.onap.policy.common.endpoints.event.comm.bus.KafkaTopicSink;
+import org.onap.policy.common.message.bus.event.Topic;
+import org.onap.policy.common.message.bus.event.base.InlineBusTopicSink;
+import org.onap.policy.common.parameters.topic.BusTopicParams;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Override
public void init() {
- this.publisher = new BusPublisher.KafkaPublisherWrapper(BusTopicParams.builder()
+ this.publisher = new KafkaPublisherWrapper(BusTopicParams.builder()
.servers(this.servers)
.topic(this.effectiveTopic)
.useHttps(this.useHttps)
--- /dev/null
+/*
+ * ============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.message.bus.event.kafka;
+
+import io.opentelemetry.instrumentation.kafkaclients.v2_6.TracingProducerInterceptor;
+import java.util.Properties;
+import java.util.UUID;
+import org.apache.kafka.clients.producer.KafkaProducer;
+import org.apache.kafka.clients.producer.Producer;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.onap.policy.common.message.bus.event.base.BusPublisher;
+import org.onap.policy.common.parameters.topic.BusTopicParams;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Kafka based library publisher.
+ */
+public class KafkaPublisherWrapper implements BusPublisher {
+
+ private static final Logger logger = LoggerFactory.getLogger(KafkaPublisherWrapper.class);
+ private static final String KEY_SERIALIZER = "org.apache.kafka.common.serialization.StringSerializer";
+
+ private final String topic;
+
+ /**
+ * Kafka publisher.
+ */
+ private final Producer<String, String> producer;
+ protected Properties kafkaProps;
+
+ /**
+ * Kafka Publisher Wrapper.
+ *
+ * @param busTopicParams topic parameters
+ */
+ public KafkaPublisherWrapper(BusTopicParams busTopicParams) {
+
+ if (busTopicParams.isTopicInvalid()) {
+ throw new IllegalArgumentException("No topic for Kafka");
+ }
+
+ this.topic = busTopicParams.getTopic();
+
+ // Setup Properties for consumer
+ kafkaProps = new Properties();
+ kafkaProps.setProperty(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, busTopicParams.getServers().get(0));
+ if (busTopicParams.isAdditionalPropsValid()) {
+ kafkaProps.putAll(busTopicParams.getAdditionalProps());
+ }
+
+ if (kafkaProps.get(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG) == null) {
+ kafkaProps.setProperty(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, KEY_SERIALIZER);
+ }
+
+ if (kafkaProps.get(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG) == null) {
+ kafkaProps.setProperty(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, KEY_SERIALIZER);
+ }
+
+ if (busTopicParams.isAllowTracing()) {
+ kafkaProps.setProperty(ProducerConfig.INTERCEPTOR_CLASSES_CONFIG,
+ TracingProducerInterceptor.class.getName());
+ }
+
+ producer = new KafkaProducer<>(kafkaProps);
+ }
+
+ @Override
+ public boolean send(String partitionId, String message) {
+ if (message == null) {
+ throw new IllegalArgumentException(NO_MESSAGE_PROVIDED);
+ }
+
+ try {
+ // Create the record
+ ProducerRecord<String, String> producerRecord =
+ new ProducerRecord<>(topic, UUID.randomUUID().toString(), message);
+
+ this.producer.send(producerRecord);
+ producer.flush();
+ } catch (Exception e) {
+ logger.warn("{}: SEND of {} cannot be performed because of {}", this, message, e.getMessage(), e);
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public void close() {
+ logger.info(LOG_CLOSE, this);
+
+ try {
+ this.producer.close();
+ } catch (Exception e) {
+ logger.warn("{}: CLOSE FAILED because of {}", this, e.getMessage(), e);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "KafkaPublisherWrapper []";
+ }
+
+}
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2022 Nordix Foundation.
+ * Copyright (C) 2022, 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.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.bus;
+package org.onap.policy.common.message.bus.event.kafka;
import lombok.AccessLevel;
import lombok.Getter;
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2022 Nordix Foundation.
+ * Copyright (C) 2022, 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.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.bus;
+package org.onap.policy.common.message.bus.event.kafka;
+
+import org.onap.policy.common.message.bus.event.base.BusTopicSink;
/**
* Topic Writer over KAFKA Infrastructure.
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2022 Nordix Foundation.
+ * Copyright (C) 2022, 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.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.bus;
+package org.onap.policy.common.message.bus.event.kafka;
import java.util.List;
import java.util.Properties;
-import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
+import org.onap.policy.common.parameters.topic.BusTopicParams;
/**
* KAFKA Topic Sink Factory.
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2022 Nordix Foundation.
+ * Copyright (C) 2022, 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.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.bus;
+package org.onap.policy.common.message.bus.event.kafka;
+
+import org.onap.policy.common.message.bus.event.base.BusTopicSource;
/**
* Kafka Topic Source.
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2022-2023 Nordix Foundation.
+ * Copyright (C) 2022-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.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.bus;
+package org.onap.policy.common.message.bus.event.kafka;
import java.util.List;
import java.util.Properties;
-import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
+import org.onap.policy.common.parameters.topic.BusTopicParams;
/**
* Kafka Topic Source Factory.
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2022-2023 Nordix Foundation.
+ * Copyright (C) 2022-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.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.bus.internal;
+package org.onap.policy.common.message.bus.event.kafka;
-import java.net.MalformedURLException;
import java.util.Map;
-import org.onap.policy.common.endpoints.event.comm.Topic;
-import org.onap.policy.common.endpoints.event.comm.bus.KafkaTopicSource;
+import org.onap.policy.common.message.bus.event.Topic;
+import org.onap.policy.common.message.bus.event.base.BusConsumer;
+import org.onap.policy.common.message.bus.event.base.SingleThreadedBusTopicSource;
+import org.onap.policy.common.parameters.topic.BusTopicParams;
/**
* This topic source implementation specializes in reading messages over a Kafka Bus topic source and
}
/**
- * Initialize the Cambria client.
+ * Initialize the client.
*/
@Override
- public void init() throws MalformedURLException {
+ public void init() {
BusTopicParams.TopicParamsBuilder builder = BusTopicParams.builder()
.servers(this.servers)
.topic(this.effectiveTopic)
* Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019 Samsung Electronics Co., Ltd.
* Modifications Copyright (C) 2020 Bell Canada. 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.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.bus;
+package org.onap.policy.common.message.bus.event.noop;
import java.util.List;
-import org.onap.policy.common.endpoints.event.comm.bus.internal.TopicBase;
-import org.onap.policy.common.endpoints.utils.NetLoggerUtil;
-import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
+import org.onap.policy.common.message.bus.event.base.TopicBase;
+import org.onap.policy.common.message.bus.utils.NetLoggerUtil;
+import org.onap.policy.common.message.bus.utils.NetLoggerUtil.EventType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Logger.
*/
- private static Logger logger = LoggerFactory.getLogger(NoopTopicEndpoint.class);
+ private static final Logger logger = LoggerFactory.getLogger(NoopTopicEndpoint.class);
/**
* Constructs the object.
* ONAP
* ================================================================================
* Copyright (C) 2019, 2021 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.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.bus;
+package org.onap.policy.common.message.bus.event.noop;
import lombok.AccessLevel;
import lombok.Getter;
* ONAP
* ================================================================================
* Copyright (C) 2019, 2021 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.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.bus;
+package org.onap.policy.common.message.bus.event.noop;
+
+import static org.onap.policy.common.message.bus.properties.MessageBusProperties.PROPERTY_MANAGED_SUFFIX;
+import static org.onap.policy.common.message.bus.properties.MessageBusProperties.PROPERTY_TOPIC_SERVERS_SUFFIX;
import com.google.re2j.Pattern;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
-import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
-import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
+import org.onap.policy.common.message.bus.event.Topic.CommInfrastructure;
+import org.onap.policy.common.message.bus.event.base.TopicBaseHashedFactory;
/**
* Noop Topic Factory.
protected List<String> getServers(String topicName, Properties properties) {
String servers =
properties.getProperty(getTopicsPropertyName() + "." + topicName
- + PolicyEndPointProperties.PROPERTY_TOPIC_SERVERS_SUFFIX);
+ + PROPERTY_TOPIC_SERVERS_SUFFIX);
if (servers == null || servers.isEmpty()) {
servers = CommInfrastructure.NOOP.toString();
@Override
protected boolean isManaged(String topicName, Properties properties) {
var managedString =
- properties.getProperty(getTopicsPropertyName()
- + "." + topicName + PolicyEndPointProperties.PROPERTY_MANAGED_SUFFIX);
+ properties.getProperty(getTopicsPropertyName() + "." + topicName + PROPERTY_MANAGED_SUFFIX);
var managed = true;
if (managedString != null && !managedString.isEmpty()) {
* ONAP
* ================================================================================
* Copyright (C) 2017-2019 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.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.bus;
+package org.onap.policy.common.message.bus.event.noop;
import java.util.List;
-import org.onap.policy.common.endpoints.event.comm.TopicSink;
-import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
+import org.onap.policy.common.message.bus.event.TopicSink;
+import org.onap.policy.common.message.bus.utils.NetLoggerUtil.EventType;
/**
* No Operation Topic Sink.
* ONAP
* ================================================================================
* Copyright (C) 2017-2019 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.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.bus;
+package org.onap.policy.common.message.bus.event.noop;
+
+import static org.onap.policy.common.message.bus.properties.MessageBusProperties.PROPERTY_NOOP_SINK_TOPICS;
import java.util.List;
-import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
/**
* Noop Topic Sink Factory.
*/
@Override
protected String getTopicsPropertyName() {
- return PolicyEndPointProperties.PROPERTY_NOOP_SINK_TOPICS;
+ return PROPERTY_NOOP_SINK_TOPICS;
}
/**
* {@inheritDoc}.
*/
@Override
- protected NoopTopicSink build(List<String> servers, String topic) {
+ public NoopTopicSink build(List<String> servers, String topic) {
return new NoopTopicSink(servers, topic);
}
* ONAP
* ================================================================================
* Copyright (C) 2019 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.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.bus;
+package org.onap.policy.common.message.bus.event.noop;
import java.util.List;
-import org.onap.policy.common.endpoints.event.comm.TopicSource;
-import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
+import org.onap.policy.common.message.bus.event.TopicSource;
+import org.onap.policy.common.message.bus.utils.NetLoggerUtil.EventType;
/**
* No Operation Topic Source.
* ONAP
* ================================================================================
* Copyright (C) 2019 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.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.bus;
+package org.onap.policy.common.message.bus.event.noop;
+
+import static org.onap.policy.common.message.bus.properties.MessageBusProperties.PROPERTY_NOOP_SOURCE_TOPICS;
import java.util.List;
-import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
/**
* No Operation Topic Source Factory.
*/
@Override
protected String getTopicsPropertyName() {
- return PolicyEndPointProperties.PROPERTY_NOOP_SOURCE_TOPICS;
+ return PROPERTY_NOOP_SOURCE_TOPICS;
}
/**
* {@inheritDoc}.
*/
@Override
- protected NoopTopicSource build(List<String> servers, String topic) {
+ public NoopTopicSource build(List<String> servers, String topic) {
return new NoopTopicSource(servers, topic);
}
/*
* ============LICENSE_START=======================================================
- * policy-endpoints
- * ================================================================================
* Copyright (C) 2019 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.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.features;
+package org.onap.policy.common.message.bus.features;
-import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
-import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
+import org.onap.policy.common.message.bus.event.Topic.CommInfrastructure;
+import org.onap.policy.common.message.bus.utils.NetLoggerUtil.EventType;
import org.onap.policy.common.utils.services.OrderedService;
import org.slf4j.Logger;
* ONAP
* ================================================================================
* Copyright (C) 2019, 2021 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.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.features;
+package org.onap.policy.common.message.bus.features;
import lombok.AccessLevel;
import lombok.Getter;
--- /dev/null
+/*-
+ * ============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.message.bus.properties;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class MessageBusProperties {
+
+ /* Generic property suffixes */
+
+ public static final String PROPERTY_TOPIC_SERVERS_SUFFIX = ".servers";
+ public static final String PROPERTY_TOPIC_EFFECTIVE_TOPIC_SUFFIX = ".effectiveTopic";
+
+ public static final String PROPERTY_TOPIC_SOURCE_CONSUMER_GROUP_SUFFIX = ".consumerGroup";
+ public static final String PROPERTY_TOPIC_SOURCE_CONSUMER_INSTANCE_SUFFIX = ".consumerInstance";
+ public static final String PROPERTY_TOPIC_SOURCE_FETCH_TIMEOUT_SUFFIX = ".fetchTimeout";
+ public static final String PROPERTY_TOPIC_SOURCE_FETCH_LIMIT_SUFFIX = ".fetchLimit";
+ public static final String PROPERTY_MANAGED_SUFFIX = ".managed";
+ public static final String PROPERTY_ADDITIONAL_PROPS_SUFFIX = ".additionalProps";
+
+ public static final String PROPERTY_TOPIC_SINK_PARTITION_KEY_SUFFIX = ".partitionKey";
+
+ public static final String PROPERTY_ALLOW_SELF_SIGNED_CERTIFICATES_SUFFIX = ".selfSignedCertificates";
+
+ public static final String PROPERTY_NOOP_SOURCE_TOPICS = "noop.source.topics";
+ public static final String PROPERTY_NOOP_SINK_TOPICS = "noop.sink.topics";
+
+ /* KAFKA Properties */
+
+ public static final String PROPERTY_KAFKA_SOURCE_TOPICS = "kafka.source.topics";
+ public static final String PROPERTY_KAFKA_SINK_TOPICS = "kafka.sink.topics";
+
+ /* HTTP Server Properties */
+
+ public static final String PROPERTY_HTTP_HTTPS_SUFFIX = ".https";
+
+ /* Topic Sink Values */
+
+ /* Topic Source values */
+
+ /**
+ * Default Timeout fetching in milliseconds.
+ */
+ public static final int DEFAULT_TIMEOUT_MS_FETCH = 15000;
+
+ /**
+ * Default maximum number of messages fetch at the time.
+ */
+ public static final int DEFAULT_LIMIT_FETCH = 100;
+
+ /**
+ * Definition of No Timeout fetching.
+ */
+ public static final int NO_TIMEOUT_MS_FETCH = -1;
+
+ /**
+ * Definition of No limit fetching.
+ */
+ public static final int NO_LIMIT_FETCH = -1;
+}
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2022-2024 Nordix Foundation.
+ * Copyright (C) 2022-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.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.utils;
+package org.onap.policy.common.message.bus.utils;
-import static org.onap.policy.common.endpoints.properties.PolicyEndPointProperties.PROPERTY_ADDITIONAL_PROPS_SUFFIX;
-import static org.onap.policy.common.endpoints.properties.PolicyEndPointProperties.PROPERTY_MANAGED_SUFFIX;
-import static org.onap.policy.common.endpoints.properties.PolicyEndPointProperties.PROPERTY_TOPIC_EFFECTIVE_TOPIC_SUFFIX;
+import static org.onap.policy.common.message.bus.properties.MessageBusProperties.PROPERTY_ADDITIONAL_PROPS_SUFFIX;
+import static org.onap.policy.common.message.bus.properties.MessageBusProperties.PROPERTY_MANAGED_SUFFIX;
+import static org.onap.policy.common.message.bus.properties.MessageBusProperties.PROPERTY_TOPIC_EFFECTIVE_TOPIC_SUFFIX;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.re2j.Pattern;
import java.util.Map;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
-import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
-import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams.TopicParamsBuilder;
+import org.onap.policy.common.parameters.topic.BusTopicParams;
+import org.onap.policy.common.parameters.topic.BusTopicParams.TopicParamsBuilder;
+import org.onap.policy.common.utils.properties.PropertyUtils;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class KafkaPropertyUtils {
/*
* ============LICENSE_START=======================================================
- * policy-endpoints
- * ================================================================================
* Copyright (C) 2019, 2021 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.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.utils;
+package org.onap.policy.common.message.bus.utils;
import lombok.Getter;
-import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
-import org.onap.policy.common.endpoints.features.NetLoggerFeatureProviders;
+import org.onap.policy.common.message.bus.event.Topic.CommInfrastructure;
+import org.onap.policy.common.message.bus.features.NetLoggerFeatureProviders;
import org.onap.policy.common.utils.services.FeatureApiUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* ============LICENSE_START=======================================================
* Copyright (C) 2019, 2024 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
-
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.parameters;
+package org.onap.policy.common.message.bus.event;
import java.io.File;
import java.io.IOException;
-import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
-import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import org.onap.policy.common.parameters.ParameterGroup;
+import org.onap.policy.common.parameters.topic.TopicParameters;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
*/
public class CommonTestData {
- public static final String REST_SERVER_PASS = "zb!XztG34";
- public static final String REST_SERVER_USER = "healthcheck";
- public static final int REST_SERVER_PORT = 6969;
- public static final String REST_SERVER_HOST = "0.0.0.0";
- public static final boolean REST_SERVER_HTTPS = true;
- public static final boolean REST_SERVER_AAF = false;
-
public static final String TOPIC_NAME = "policy-pdp-pap";
public static final String TOPIC_INFRA = "kafka";
public static final String TOPIC_SERVER = "kafka:9092";
public static final List<TopicParameters> TOPIC_PARAMS =
- Arrays.asList(getTopicParameters(TOPIC_NAME, TOPIC_INFRA, TOPIC_SERVER));
+ List.of(getTopicParameters(TOPIC_NAME, TOPIC_INFRA, TOPIC_SERVER));
protected static final Coder coder = new StandardCoder();
/**
* Create topic parameters for test cases.
*
- * @param topicName name of topic
- * @param topicInfra topicCommInfrastructure
+ * @param topicName name of topic
+ * @param topicInfra topicCommInfrastructure
* @param topicServer topic server
- *
* @return topic parameters
*/
public static TopicParameters getTopicParameters(String topicName, String topicInfra, String topicServer) {
final TopicParameters topicParams = new TopicParameters();
topicParams.setTopic(topicName);
topicParams.setTopicCommInfrastructure(topicInfra);
- topicParams.setServers(Arrays.asList(topicServer));
+ topicParams.setServers(List.of(topicServer));
return topicParams;
}
* Converts the contents of a map to a parameter class.
*
* @param source property map
- * @param clazz class of object to be created from the map
+ * @param clazz class of object to be created from the map
* @return a new object represented by the map
*/
public <T extends ParameterGroup> T toObject(final Map<String, Object> source, final Class<T> clazz) {
}
}
- /**
- * Returns a property map for a RestServerParameters map for test cases.
- *
- * @param isEmpty boolean value to represent that object created should be empty or not
- * @return a property map suitable for constructing an object
- */
- public Map<String, Object> getRestServerParametersMap(final boolean isEmpty) {
- final Map<String, Object> map = new TreeMap<>();
- map.put("https", REST_SERVER_HTTPS);
- map.put("aaf", REST_SERVER_AAF);
-
- if (!isEmpty) {
- map.put("host", REST_SERVER_HOST);
- map.put("port", REST_SERVER_PORT);
- map.put("userName", REST_SERVER_USER);
- map.put("password", REST_SERVER_PASS);
- }
-
- return map;
- }
-
/**
* Returns a property map for a TopicParameters map for test cases.
*
*/
public String getParameterGroupAsString(String filePath) throws IOException {
File file = new File(filePath);
- return new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8);
+ return Files.readString(file.toPath());
}
}
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm;
+package org.onap.policy.common.message.bus.event;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import java.util.Properties;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
-import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
-import org.onap.policy.common.endpoints.event.comm.bus.KafkaTopicFactories;
-import org.onap.policy.common.endpoints.event.comm.bus.KafkaTopicPropertyBuilder;
-import org.onap.policy.common.endpoints.event.comm.bus.NoopTopicFactories;
-import org.onap.policy.common.endpoints.event.comm.bus.NoopTopicPropertyBuilder;
-import org.onap.policy.common.endpoints.parameters.TopicParameterGroup;
-import org.onap.policy.common.endpoints.parameters.TopicParameters;
-import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
+import org.onap.policy.common.message.bus.event.Topic.CommInfrastructure;
+import org.onap.policy.common.message.bus.event.kafka.KafkaTopicFactories;
+import org.onap.policy.common.message.bus.event.kafka.KafkaTopicPropertyBuilder;
+import org.onap.policy.common.message.bus.event.noop.NoopTopicFactories;
+import org.onap.policy.common.message.bus.event.noop.NoopTopicPropertyBuilder;
+import org.onap.policy.common.message.bus.properties.MessageBusProperties;
+import org.onap.policy.common.parameters.topic.TopicParameterGroup;
+import org.onap.policy.common.parameters.topic.TopicParameters;
import org.onap.policy.common.utils.gson.GsonTestUtils;
class TopicEndpointProxyTest {
group.setTopicSources(new LinkedList<>());
NoopTopicPropertyBuilder noopSourceBuilder =
- new NoopTopicPropertyBuilder(PolicyEndPointProperties.PROPERTY_NOOP_SOURCE_TOPICS)
+ new NoopTopicPropertyBuilder(MessageBusProperties.PROPERTY_NOOP_SOURCE_TOPICS)
.makeTopic(NOOP_SOURCE_TOPIC);
configuration.putAll(noopSourceBuilder.build());
group.getTopicSources().add(noopSourceBuilder.getParams());
NoopTopicPropertyBuilder noopSinkBuilder =
- new NoopTopicPropertyBuilder(PolicyEndPointProperties.PROPERTY_NOOP_SINK_TOPICS)
+ new NoopTopicPropertyBuilder(MessageBusProperties.PROPERTY_NOOP_SINK_TOPICS)
.makeTopic(NOOP_SINK_TOPIC);
configuration.putAll(noopSinkBuilder.build());
group.getTopicSinks().add(noopSinkBuilder.getParams());
TopicParameters invalidCommInfraParams =
- new NoopTopicPropertyBuilder(PolicyEndPointProperties.PROPERTY_NOOP_SOURCE_TOPICS)
+ new NoopTopicPropertyBuilder(MessageBusProperties.PROPERTY_NOOP_SOURCE_TOPICS)
.makeTopic(NOOP_SOURCE_TOPIC).getParams();
invalidCommInfraParams.setTopicCommInfrastructure(Topic.CommInfrastructure.REST.name());
group.getTopicSources().add(invalidCommInfraParams);
TopicEndpoint manager = new TopicEndpointProxy();
KafkaTopicPropertyBuilder kafkaTopicPropertyBuilder =
- new KafkaTopicPropertyBuilder(PolicyEndPointProperties.PROPERTY_KAFKA_SOURCE_TOPICS)
+ new KafkaTopicPropertyBuilder(MessageBusProperties.PROPERTY_KAFKA_SOURCE_TOPICS)
.makeTopic(KAFKA_SOURCE_TOPIC);
configuration.putAll(kafkaTopicPropertyBuilder.build());
assertSame(1, sinks.size());
KafkaTopicPropertyBuilder kafkaTopicPropertyBuilder =
- new KafkaTopicPropertyBuilder(PolicyEndPointProperties.PROPERTY_KAFKA_SINK_TOPICS)
+ new KafkaTopicPropertyBuilder(MessageBusProperties.PROPERTY_KAFKA_SINK_TOPICS)
.makeTopic(KAFKA_SINK_TOPIC);
configuration.putAll(kafkaTopicPropertyBuilder.build());
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.parameters;
+package org.onap.policy.common.message.bus.event;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Test;
-import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
import org.onap.policy.common.parameters.ValidationResult;
+import org.onap.policy.common.parameters.topic.BusTopicParams;
+import org.onap.policy.common.parameters.topic.TopicParameterGroup;
+import org.onap.policy.common.parameters.topic.TopicParameters;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
* @author Ajith Sreekumar (ajith.sreekumar@est.tech)
*/
class TopicParameterGroupTest {
- private static CommonTestData testData = new CommonTestData();
+ private static final CommonTestData testData = new CommonTestData();
private static final Coder coder = new StandardCoder();
+ private final String packageDir = "src/test/resources/org/onap/policy/common/message/bus/parameters/";
@Test
void test() throws CoderException {
@Test
void test_valid() throws Exception {
String json = testData.getParameterGroupAsString(
- "src/test/resources/org/onap/policy/common/endpoints/parameters/TopicParameters_valid.json");
+ packageDir + "TopicParameters_valid.json");
TopicParameterGroup topicParameterGroup = coder.decode(json, TopicParameterGroup.class);
final ValidationResult result = topicParameterGroup.validate();
assertNull(result.getResult());
@Test
void test_invalid() throws Exception {
String json = testData.getParameterGroupAsString(
- "src/test/resources/org/onap/policy/common/endpoints/parameters/TopicParameters_invalid.json");
+ packageDir + "TopicParameters_invalid.json");
TopicParameterGroup topicParameterGroup = coder.decode(json, TopicParameterGroup.class);
final ValidationResult result = topicParameterGroup.validate();
assertFalse(result.isValid());
@Test
void test_missing_mandatory_params() throws Exception {
String json = testData.getParameterGroupAsString(
- "src/test/resources/org/onap/policy/common/endpoints/parameters/TopicParameters_missing_mandatory.json");
+ packageDir + "TopicParameters_missing_mandatory.json");
TopicParameterGroup topicParameterGroup = coder.decode(json, TopicParameterGroup.class);
final ValidationResult result = topicParameterGroup.validate();
assertTrue(result.getResult().contains("Mandatory parameters are missing"));
}
@Test
- void test_allparams() throws Exception {
+ void test_allParams() throws Exception {
String json = testData.getParameterGroupAsString(
- "src/test/resources/org/onap/policy/common/endpoints/parameters/TopicParameters_all_params.json");
+ packageDir + "TopicParameters_all_params.json");
TopicParameterGroup topicParameterGroup = coder.decode(json, TopicParameterGroup.class);
final ValidationResult result = topicParameterGroup.validate();
assertNull(result.getResult());
/*
* ============LICENSE_START=======================================================
- * policy-endpoints
- * ================================================================================
* Copyright (C) 2018-2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2023-2024 Nordix Foundation.
* ================================================================================
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.bus.internal;
+package org.onap.policy.common.message.bus.event.base;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
-import org.onap.policy.common.endpoints.event.comm.bus.TopicTestBase;
-import org.onap.policy.common.endpoints.event.comm.bus.internal.BusConsumer.FetchingBusConsumer;
-import org.onap.policy.common.endpoints.event.comm.bus.internal.BusConsumer.KafkaConsumerWrapper;
-import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
+import org.onap.policy.common.message.bus.event.base.BusConsumer.FetchingBusConsumer;
+import org.onap.policy.common.message.bus.event.base.BusConsumer.KafkaConsumerWrapper;
+import org.onap.policy.common.message.bus.properties.MessageBusProperties;
+import org.onap.policy.common.parameters.topic.BusTopicParams;
class BusConsumerTest extends TopicTestBase {
void testFetchingBusConsumer() {
// should not be negative
var cons = new FetchingBusConsumerImpl(makeBuilder().fetchTimeout(-1).build());
- assertThat(cons.getSleepTime()).isEqualTo(PolicyEndPointProperties.DEFAULT_TIMEOUT_MS_FETCH);
+ assertThat(cons.getSleepTime()).isEqualTo(MessageBusProperties.DEFAULT_TIMEOUT_MS_FETCH);
// should not be zero
cons = new FetchingBusConsumerImpl(makeBuilder().fetchTimeout(0).build());
- assertThat(cons.getSleepTime()).isEqualTo(PolicyEndPointProperties.DEFAULT_TIMEOUT_MS_FETCH);
+ assertThat(cons.getSleepTime()).isEqualTo(MessageBusProperties.DEFAULT_TIMEOUT_MS_FETCH);
// should not be too large
cons = new FetchingBusConsumerImpl(
- makeBuilder().fetchTimeout(PolicyEndPointProperties.DEFAULT_TIMEOUT_MS_FETCH + 100).build());
- assertThat(cons.getSleepTime()).isEqualTo(PolicyEndPointProperties.DEFAULT_TIMEOUT_MS_FETCH);
+ makeBuilder().fetchTimeout(MessageBusProperties.DEFAULT_TIMEOUT_MS_FETCH + 100).build());
+ assertThat(cons.getSleepTime()).isEqualTo(MessageBusProperties.DEFAULT_TIMEOUT_MS_FETCH);
// should not be what was specified
cons = new FetchingBusConsumerImpl(makeBuilder().fetchTimeout(100).build());
}
@Test
- void testFetchWithMessagesAndTraceparent() {
+ void testFetchWithMessagesAndTraceParent() {
// Setup
KafkaConsumerWrapper kafkaConsumerWrapper = new KafkaConsumerWrapper(makeKafkaBuilder().build());
kafkaConsumerWrapper.consumer = mockedKafkaConsumer;
/*
* ============LICENSE_START=======================================================
- * policy-endpoints
- * ================================================================================
* Copyright (C) 2018-2020 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2024 Nordix Foundation
* ================================================================================
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.bus.internal;
+package org.onap.policy.common.message.bus.event.base;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import org.onap.policy.common.endpoints.event.comm.bus.TopicTestBase;
+import org.onap.policy.common.parameters.topic.BusTopicParams;
import org.onap.policy.common.utils.gson.GsonTestUtils;
class BusTopicBaseTest extends TopicTestBase {
/*
* ============LICENSE_START=======================================================
- * policy-endpoints
- * ================================================================================
* Copyright (C) 2018-2020 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2024 Nordix Foundation
* ================================================================================
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.bus;
+package org.onap.policy.common.message.bus.event.base;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.onap.policy.common.endpoints.properties.PolicyEndPointProperties.PROPERTY_ALLOW_SELF_SIGNED_CERTIFICATES_SUFFIX;
-import static org.onap.policy.common.endpoints.properties.PolicyEndPointProperties.PROPERTY_HTTP_HTTPS_SUFFIX;
-import static org.onap.policy.common.endpoints.properties.PolicyEndPointProperties.PROPERTY_MANAGED_SUFFIX;
-import static org.onap.policy.common.endpoints.properties.PolicyEndPointProperties.PROPERTY_TOPIC_EFFECTIVE_TOPIC_SUFFIX;
+import static org.onap.policy.common.message.bus.properties.MessageBusProperties.PROPERTY_ALLOW_SELF_SIGNED_CERTIFICATES_SUFFIX;
+import static org.onap.policy.common.message.bus.properties.MessageBusProperties.PROPERTY_HTTP_HTTPS_SUFFIX;
+import static org.onap.policy.common.message.bus.properties.MessageBusProperties.PROPERTY_MANAGED_SUFFIX;
+import static org.onap.policy.common.message.bus.properties.MessageBusProperties.PROPERTY_TOPIC_EFFECTIVE_TOPIC_SUFFIX;
-import java.util.Arrays;
import java.util.List;
import java.util.Properties;
import java.util.function.Predicate;
-import org.onap.policy.common.endpoints.event.comm.Topic;
-import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
+import org.onap.policy.common.message.bus.event.Topic;
+import org.onap.policy.common.parameters.topic.BusTopicParams;
/**
* Base class for Topic Factory tests that use BusTopicParams.
/**
* Tests building a topic using BusTopicParams.
*/
- void testBuildBusTopicParams() {
+ public void testBuildBusTopicParams() {
initFactory();
// two unmanaged topics
/**
* Tests exception cases when building a topic using BusTopicParams.
*/
- void testBuildBusTopicParams_Ex() {
+ public void testBuildBusTopicParams_Ex() {
// null topic
assertThatIllegalArgumentException().isThrownBy(() -> buildTopic(makeBuilder().topic(null).build()));
/**
* Tests building a topic using a list of servers and a topic.
*/
- void testBuildListOfStringString() {
+ public void testBuildListOfStringString() {
initFactory();
T item1 = buildTopic(servers, MY_TOPIC);
BusTopicParams params = getLastParams();
assertEquals(servers, params.getServers());
assertEquals(MY_TOPIC, params.getTopic());
- assertEquals(true, params.isManaged());
- assertEquals(false, params.isUseHttps());
+ assertTrue(params.isManaged());
+ assertFalse(params.isUseHttps());
T item2 = buildTopic(servers, TOPIC2);
assertNotNull(item2);
* Tests building a topic using Properties. Verifies parameters specific to Bus
* topics.
*/
- void testBuildProperties() {
+ public void testBuildProperties() {
initFactory();
List<T> topics = buildTopics(makePropBuilder().makeTopic(MY_TOPIC).build());
assertEquals(MY_EFFECTIVE_TOPIC, topics.get(0).getEffectiveTopic());
BusTopicParams params = getLastParams();
- assertEquals(true, params.isManaged());
- assertEquals(true, params.isUseHttps());
- assertEquals(true, params.isAllowSelfSignedCerts());
+ assertTrue(params.isManaged());
+ assertTrue(params.isUseHttps());
+ assertTrue(params.isAllowSelfSignedCerts());
assertEquals(MY_API_KEY, params.getApiKey());
assertEquals(MY_API_SECRET, params.getApiSecret());
- assertEquals(Arrays.asList(SERVER), params.getServers());
+ assertEquals(List.of(SERVER), params.getServers());
assertEquals(MY_TOPIC, params.getTopic());
assertEquals(MY_EFFECTIVE_TOPIC, params.getEffectiveTopic());
* @param builderName name of the builder property
* @param addName name of the "additional" property
*/
- protected void expectNullAddProp(String builderName, String addName) {
+ public void expectNullAddProp(String builderName, String addName) {
// remove the property
initFactory();
/*
* ============LICENSE_START=======================================================
- * policy-endpoints
- * ================================================================================
* Copyright (C) 2018-2020 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2024 Nordix Foundation.
* ================================================================================
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.bus.internal;
+package org.onap.policy.common.message.bus.event.base;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
-import org.onap.policy.common.endpoints.event.comm.TopicListener;
-import org.onap.policy.common.endpoints.event.comm.bus.TopicTestBase;
+import org.onap.policy.common.message.bus.event.Topic.CommInfrastructure;
+import org.onap.policy.common.message.bus.event.TopicListener;
+import org.onap.policy.common.parameters.topic.BusTopicParams;
import org.onap.policy.common.utils.gson.GsonTestUtils;
class InlineBusTopicSinkTest extends TopicTestBase {
/*
* ============LICENSE_START=======================================================
- * policy-endpoints
- * ================================================================================
* Copyright (C) 2018-2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2024 Nordix Foundation
* ================================================================================
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.bus.internal;
+package org.onap.policy.common.message.bus.event.base;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import org.junit.jupiter.api.Test;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
-import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
-import org.onap.policy.common.endpoints.event.comm.TopicListener;
-import org.onap.policy.common.endpoints.event.comm.bus.TopicTestBase;
+import org.onap.policy.common.message.bus.event.Topic.CommInfrastructure;
+import org.onap.policy.common.message.bus.event.TopicListener;
+import org.onap.policy.common.parameters.topic.BusTopicParams;
import org.onap.policy.common.utils.gson.GsonTestUtils;
import org.onap.policy.common.utils.network.NetworkUtil;
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.bus.internal;
+package org.onap.policy.common.message.bus.event.base;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
-import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
-import org.onap.policy.common.endpoints.event.comm.TopicListener;
-import org.onap.policy.common.endpoints.event.comm.bus.TopicTestBase;
+import org.onap.policy.common.message.bus.event.Topic.CommInfrastructure;
+import org.onap.policy.common.message.bus.event.TopicListener;
import org.onap.policy.common.utils.gson.GsonTestUtils;
class TopicBaseTest extends TopicTestBase {
void testRegister() {
TopicListener listener = mock(TopicListener.class);
base.register(listener);
- assertEquals(Arrays.asList(listener), base.snapshotTopicListeners());
+ assertEquals(List.of(listener), base.snapshotTopicListeners());
// re-register - list should be unchanged
base.register(listener);
- assertEquals(Arrays.asList(listener), base.snapshotTopicListeners());
+ assertEquals(List.of(listener), base.snapshotTopicListeners());
// register a new listener
TopicListener listener2 = mock(TopicListener.class);
base.register(listener2);
- assertEquals(Arrays.asList(listener, listener2), base.snapshotTopicListeners());
+ assertEquals(List.of(listener, listener2), base.snapshotTopicListeners());
}
@Test
// unregister one
base.unregister(listener);
- assertEquals(Arrays.asList(listener2), base.snapshotTopicListeners());
+ assertEquals(List.of(listener2), base.snapshotTopicListeners());
// unregister the other
base.unregister(listener2);
/*
* ============LICENSE_START=======================================================
- * policy-endpoints
- * ================================================================================
* Copyright (C) 2018-2020 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2024 Nordix Foundation
* ================================================================================
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.bus;
+package org.onap.policy.common.message.bus.event.base;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.onap.policy.common.endpoints.properties.PolicyEndPointProperties.PROPERTY_TOPIC_SERVERS_SUFFIX;
+import static org.onap.policy.common.message.bus.properties.MessageBusProperties.PROPERTY_TOPIC_SERVERS_SUFFIX;
import java.util.List;
import java.util.Properties;
-import org.onap.policy.common.endpoints.event.comm.Topic;
+import org.onap.policy.common.message.bus.event.Topic;
/**
* Base class for XxxTopicFactory tests.
// null servers
assertTrue(buildTopics(makePropBuilder().makeTopic(MY_TOPIC).removeTopicProperty(PROPERTY_TOPIC_SERVERS_SUFFIX)
- .build()).isEmpty());
+ .build()).isEmpty());
// empty servers
assertTrue(buildTopics(makePropBuilder().makeTopic(MY_TOPIC).setTopicProperty(PROPERTY_TOPIC_SERVERS_SUFFIX, "")
- .build()).isEmpty());
+ .build()).isEmpty());
}
/**
* Tests building multiple topics using Properties.
*/
- void testBuildProperties_Multiple() {
+ public void testBuildProperties_Multiple() {
initFactory();
// make two fully-defined topics, and add two duplicate topic names to the list
TopicPropertyBuilder builder =
- makePropBuilder().makeTopic(MY_TOPIC).makeTopic(TOPIC2).addTopic(MY_TOPIC).addTopic(MY_TOPIC);
+ makePropBuilder().makeTopic(MY_TOPIC).makeTopic(TOPIC2).addTopic(MY_TOPIC).addTopic(MY_TOPIC);
List<T> lst = buildTopics(builder.build());
assertEquals(4, lst.size());
/**
* Tests destroy(topic), get(topic), and inventory() methods.
*/
- void testDestroyString_testGet_testInventory() {
+ public void testDestroyString_testGet_testInventory() {
initFactory();
List<T> lst = buildTopics(makePropBuilder().makeTopic(MY_TOPIC).makeTopic(TOPIC2).build());
/**
* Tests exception cases with destroy(topic).
*/
- void testDestroyString_Ex() {
+ public void testDestroyString_Ex() {
// null topic
assertThatIllegalArgumentException().as("null topic").isThrownBy(() -> destroyTopic(null));
/**
* Tests the destroy() method.
*/
- void testDestroy() {
+ public void testDestroy() {
initFactory();
List<T> lst = buildTopics(makePropBuilder().makeTopic(MY_TOPIC).makeTopic(TOPIC2).build());
/**
* Tests exception cases with get(topic).
*/
- void testGet_Ex() {
+ public void testGet_Ex() {
// null topic
assertThatIllegalArgumentException().as("null topic").isThrownBy(() -> getTopic(null));
* ONAP Policy Engine - Common Modules
* ================================================================================
* Copyright (C) 2018 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.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.bus;
+package org.onap.policy.common.message.bus.event.base;
import java.util.Properties;
/*
* ============LICENSE_START=======================================================
- * policy-endpoints
- * ================================================================================
* Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2024 Nordix Foundation.
* ================================================================================
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.bus;
+package org.onap.policy.common.message.bus.event.base;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
-import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
-import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams.TopicParamsBuilder;
+import org.onap.policy.common.parameters.topic.BusTopicParams;
+import org.onap.policy.common.parameters.topic.BusTopicParams.TopicParamsBuilder;
/**
* Base class for Topic Test classes.
public static final String MY_MESSAGE = "my-message";
public static final String MY_PARTITION = "my-partition";
public static final String MY_MESSAGE2 = "my-message-2";
- public static final String MY_PARTITION2 = "my-partition-2";
- public static final String ROUTE_PROP = "routeOffer";
- public static final String MY_ROUTE = "my-route";
public static final String MY_SERIALIZER = "org.apache.kafka.common.serialization.StringSerializer";
public static final int KAFKA_PORT = 9092;
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.client;
+package org.onap.policy.common.message.bus.event.client;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
-import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
-import org.onap.policy.common.endpoints.event.comm.TopicEndpoint;
-import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
-import org.onap.policy.common.endpoints.event.comm.TopicListener;
-import org.onap.policy.common.endpoints.event.comm.TopicSink;
-import org.onap.policy.common.endpoints.event.comm.TopicSource;
+import org.onap.policy.common.message.bus.event.Topic.CommInfrastructure;
+import org.onap.policy.common.message.bus.event.TopicEndpoint;
+import org.onap.policy.common.message.bus.event.TopicEndpointManager;
+import org.onap.policy.common.message.bus.event.TopicListener;
+import org.onap.policy.common.message.bus.event.TopicSink;
+import org.onap.policy.common.message.bus.event.TopicSource;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
@Test
void testBidirectionalTopicClientExceptions() {
assertThatThrownBy(() -> new BidirectionalTopicClient2("unknown-sink", SOURCE_TOPIC))
- .isInstanceOf(BidirectionalTopicClientException.class)
- .hasMessage("no sinks for topic: unknown-sink");
+ .isInstanceOf(BidirectionalTopicClientException.class)
+ .hasMessage("no sinks for topic: unknown-sink");
assertThatThrownBy(() -> new BidirectionalTopicClient2(SINK_TOPIC, "unknown-source"))
- .isInstanceOf(BidirectionalTopicClientException.class)
- .hasMessage("no sources for topic: unknown-source");
+ .isInstanceOf(BidirectionalTopicClientException.class)
+ .hasMessage("no sources for topic: unknown-source");
// too many sources
when(endpoint.getTopicSources(Arrays.asList(SOURCE_TOPIC))).thenReturn(Arrays.asList(source, source));
assertThatThrownBy(() -> new BidirectionalTopicClient2(SINK_TOPIC, SOURCE_TOPIC))
- .isInstanceOf(BidirectionalTopicClientException.class)
- .hasMessage("too many sources for topic: my-source-topic");
+ .isInstanceOf(BidirectionalTopicClientException.class)
+ .hasMessage("too many sources for topic: my-source-topic");
}
/**
* Verifies that awaitReceipt() returns {@code true}.
*
* @throws InterruptedException if interrupted while waiting for the thread to
- * terminate
+ * terminate
*/
private void verifyReceipt() throws InterruptedException {
assertThat(context.join()).isTrue();
* Verifies that awaitReceipt() returns {@code false}.
*
* @throws InterruptedException if interrupted while waiting for the thread to
- * terminate
+ * terminate
*/
private void verifyNoReceipt() throws InterruptedException {
assertThat(context.join()).isTrue();
private class BidirectionalTopicClient2 extends BidirectionalTopicClient {
public BidirectionalTopicClient2(String sinkTopic, String sourceTopic)
- throws BidirectionalTopicClientException {
+ throws BidirectionalTopicClientException {
super(sinkTopic, sourceTopic);
}
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.client;
+package org.onap.policy.common.message.bus.event.client;
import static org.junit.jupiter.api.Assertions.assertEquals;
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.client;
+package org.onap.policy.common.message.bus.event.client;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
-import org.onap.policy.common.endpoints.event.comm.TopicSink;
+import org.onap.policy.common.message.bus.event.TopicEndpointManager;
+import org.onap.policy.common.message.bus.event.TopicSink;
class TopicSinkClientTest {
private static final String TOPIC = "my-topic";
// unknown topic -> should throw exception
sinks = new LinkedList<>();
assertThatThrownBy(() -> new TopicSinkClient2(TOPIC)).isInstanceOf(TopicSinkClientException.class)
- .hasMessage("no sinks for topic: my-topic");
+ .hasMessage("no sinks for topic: my-topic");
}
@Test
assertEquals(TOPIC, new TopicSinkClient(TopicEndpointManager.getManager().getNoopTopicSink(TOPIC)).getTopic());
assertEquals(TOPIC, new TopicSinkClient(TOPIC).getTopic());
- assertThatThrownBy(() -> new TopicSinkClient((TopicSink) null)).isInstanceOf(IllegalArgumentException.class);
+ assertThatThrownBy(() -> new TopicSinkClient((TopicSink) null))
+ .hasMessageContaining("sink is marked non-null but is null");
assertThatThrownBy(() -> new TopicSinkClient("blah")).isInstanceOf(TopicSinkClientException.class)
- .hasMessage("no sinks for topic: blah");
+ .hasMessage("no sinks for topic: blah");
}
@Test
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.bus;
+package org.onap.policy.common.message.bus.event.kafka;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import java.util.List;
-import org.apache.kafka.clients.ClientUtils;
import org.junit.jupiter.api.Test;
-import org.mockito.Mock;
-import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
+import org.onap.policy.common.parameters.topic.BusTopicParams;
class IndexedKafkaTopicSourceFactoryTest {
private IndexedKafkaTopicSourceFactory factory;
- @Mock
- ClientUtils mockClientUtils;
-
@Test
void testBuild() {
factory = new IndexedKafkaTopicSourceFactory();
assertThatThrownBy(() -> factory.build(params))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("A topic must be provided");
-
- params.setTopic("topic01");
-
- assertThatThrownBy(() -> factory.build(servers, "topic1"))
- .isInstanceOf(IllegalArgumentException.class)
- .hasMessageContaining("cannot create topic");
}
}
/*
* ============LICENSE_START=======================================================
- * policy-endpoints
- * ================================================================================
* Copyright (C) 2022-2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.bus.internal;
+package org.onap.policy.common.message.bus.event.kafka;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
-import org.onap.policy.common.endpoints.event.comm.bus.TopicTestBase;
+import org.onap.policy.common.message.bus.event.Topic.CommInfrastructure;
+import org.onap.policy.common.message.bus.event.base.TopicTestBase;
class InlineKafkaTopicSinkTest extends TopicTestBase {
private InlineKafkaTopicSink sink;
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.bus.internal;
+package org.onap.policy.common.message.bus.event.kafka;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentMatchers;
+import org.onap.policy.common.parameters.topic.BusTopicParams;
class KafkaPublisherWrapperTest {
- private BusPublisher.KafkaPublisherWrapper kafkaPublisherWrapper;
+ private KafkaPublisherWrapper kafkaPublisherWrapper;
private Producer<String, String> mockProducer;
private BusTopicParams mockBusTopicParams;
when(mockBusTopicParams.isAdditionalPropsValid()).thenReturn(false);
when(mockBusTopicParams.isAllowTracing()).thenReturn(false);
- kafkaPublisherWrapper = new BusPublisher.KafkaPublisherWrapper(mockBusTopicParams) {
- protected Producer<String, String> createProducer(Properties props) { // NOSONAR instance creation
+ kafkaPublisherWrapper = new KafkaPublisherWrapper(mockBusTopicParams) {
+ private Producer<String, String> createProducer(Properties props) { // NOSONAR instance creation
return mockProducer;
}
};
/*
* ============LICENSE_START=======================================================
- * policy-endpoints
- * ================================================================================
* Copyright (C) 2022-2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.bus;
+package org.onap.policy.common.message.bus.event.kafka;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import java.util.Collections;
-import org.onap.policy.common.endpoints.event.comm.Topic;
+import org.onap.policy.common.message.bus.event.Topic;
+import org.onap.policy.common.message.bus.event.base.BusTopicFactoryTestBase;
/**
* Base class for KafkaTopicXxxFactory tests.
public abstract class KafkaTopicFactoryTestBase<T extends Topic> extends BusTopicFactoryTestBase<T> {
@Override
- void testBuildBusTopicParams_Ex() {
+ public void testBuildBusTopicParams_Ex() {
super.testBuildBusTopicParams_Ex();
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.bus;
+package org.onap.policy.common.message.bus.event.kafka;
-import static org.onap.policy.common.endpoints.event.comm.bus.TopicTestBase.MY_EFFECTIVE_TOPIC;
-import static org.onap.policy.common.endpoints.event.comm.bus.TopicTestBase.MY_PARTITION;
-import static org.onap.policy.common.endpoints.properties.PolicyEndPointProperties.PROPERTY_HTTP_HTTPS_SUFFIX;
-import static org.onap.policy.common.endpoints.properties.PolicyEndPointProperties.PROPERTY_MANAGED_SUFFIX;
-import static org.onap.policy.common.endpoints.properties.PolicyEndPointProperties.PROPERTY_TOPIC_EFFECTIVE_TOPIC_SUFFIX;
-import static org.onap.policy.common.endpoints.properties.PolicyEndPointProperties.PROPERTY_TOPIC_SERVERS_SUFFIX;
-import static org.onap.policy.common.endpoints.properties.PolicyEndPointProperties.PROPERTY_TOPIC_SINK_PARTITION_KEY_SUFFIX;
+import static org.onap.policy.common.message.bus.event.base.TopicTestBase.MY_EFFECTIVE_TOPIC;
+import static org.onap.policy.common.message.bus.event.base.TopicTestBase.MY_PARTITION;
+import static org.onap.policy.common.message.bus.properties.MessageBusProperties.PROPERTY_HTTP_HTTPS_SUFFIX;
+import static org.onap.policy.common.message.bus.properties.MessageBusProperties.PROPERTY_MANAGED_SUFFIX;
+import static org.onap.policy.common.message.bus.properties.MessageBusProperties.PROPERTY_TOPIC_EFFECTIVE_TOPIC_SUFFIX;
+import static org.onap.policy.common.message.bus.properties.MessageBusProperties.PROPERTY_TOPIC_SERVERS_SUFFIX;
+import static org.onap.policy.common.message.bus.properties.MessageBusProperties.PROPERTY_TOPIC_SINK_PARTITION_KEY_SUFFIX;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.List;
import java.util.Map;
import lombok.Getter;
-import org.onap.policy.common.endpoints.parameters.TopicParameters;
+import org.onap.policy.common.message.bus.event.base.TopicPropertyBuilder;
+import org.onap.policy.common.parameters.topic.TopicParameters;
@Getter
public class KafkaTopicPropertyBuilder extends TopicPropertyBuilder {
/*
* ============LICENSE_START=======================================================
- * policy-endpoints
- * ================================================================================
* Copyright (C) 2022, 2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.bus;
+package org.onap.policy.common.message.bus.event.kafka;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.onap.policy.common.endpoints.properties.PolicyEndPointProperties.PROPERTY_KAFKA_SINK_TOPICS;
-import static org.onap.policy.common.endpoints.properties.PolicyEndPointProperties.PROPERTY_TOPIC_EFFECTIVE_TOPIC_SUFFIX;
+import static org.onap.policy.common.message.bus.properties.MessageBusProperties.PROPERTY_KAFKA_SINK_TOPICS;
+import static org.onap.policy.common.message.bus.properties.MessageBusProperties.PROPERTY_TOPIC_EFFECTIVE_TOPIC_SUFFIX;
import java.util.Deque;
import java.util.LinkedList;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
+import org.onap.policy.common.message.bus.event.base.TopicPropertyBuilder;
+import org.onap.policy.common.parameters.topic.BusTopicParams;
class KafkaTopicSinkFactoryTest extends KafkaTopicFactoryTestBase<KafkaTopicSink> {
@Test
@Override
- void testBuildBusTopicParams() {
+ public void testBuildBusTopicParams() {
super.testBuildBusTopicParams();
super.testBuildBusTopicParams_Ex();
}
@Test
@Override
- void testBuildListOfStringString() {
+ public void testBuildListOfStringString() {
super.testBuildListOfStringString();
// check parameters that were used
@Test
@Override
- void testBuildProperties() {
+ public void testBuildProperties() {
List<KafkaTopicSink> topics = buildTopics(makePropBuilder().makeTopic(MY_TOPIC).build());
assertEquals(1, topics.size());
assertEquals(MY_TOPIC, topics.get(0).getTopic());
@Test
@Override
- void testDestroyString_testGet_testInventory() {
+ public void testDestroyString_testGet_testInventory() {
super.testDestroyString_testGet_testInventory();
super.testDestroyString_Ex();
}
@Test
@Override
- void testDestroy() {
+ public void testDestroy() {
super.testDestroy();
}
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.bus;
+package org.onap.policy.common.message.bus.event.kafka;
import static org.junit.jupiter.api.Assertions.assertNotNull;
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.bus;
+package org.onap.policy.common.message.bus.event.kafka;
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 static org.onap.policy.common.endpoints.properties.PolicyEndPointProperties.PROPERTY_KAFKA_SOURCE_TOPICS;
+import static org.onap.policy.common.message.bus.properties.MessageBusProperties.PROPERTY_KAFKA_SOURCE_TOPICS;
import java.util.Deque;
import java.util.LinkedList;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
+import org.onap.policy.common.message.bus.event.base.TopicPropertyBuilder;
+import org.onap.policy.common.parameters.topic.BusTopicParams;
class KafkaTopicSourceFactoryTest extends KafkaTopicFactoryTestBase<KafkaTopicSource> {
@Test
@Override
- void testBuildProperties() {
+ public void testBuildProperties() {
initFactory();
@Test
@Override
- void testDestroyString_testGet_testInventory() {
+ public void testDestroyString_testGet_testInventory() {
super.testDestroyString_testGet_testInventory();
super.testDestroyString_Ex();
}
@Test
@Override
- void testDestroy() {
+ public void testDestroy() {
super.testDestroy();
}
* Factory that records the parameters of all the sources it creates.
*/
private static class SourceFactory extends IndexedKafkaTopicSourceFactory {
- private Deque<BusTopicParams> params = new LinkedList<>();
+ private final Deque<BusTopicParams> params = new LinkedList<>();
@Override
protected KafkaTopicSource makeSource(BusTopicParams busTopicParams) {
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.bus;
+package org.onap.policy.common.message.bus.event.kafka;
import static org.junit.jupiter.api.Assertions.assertNotNull;
/*
* ============LICENSE_START=======================================================
- * policy-endpoints
- * ================================================================================
* Copyright (C) 2018-2020 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2024 Nordix Foundation
* ================================================================================
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.bus.internal;
+package org.onap.policy.common.message.bus.event.kafka;
-import static org.assertj.core.api.Assertions.assertThatCode;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
-import org.onap.policy.common.endpoints.event.comm.bus.TopicTestBase;
-import org.onap.policy.common.utils.gson.GsonTestUtils;
+import org.onap.policy.common.message.bus.event.Topic.CommInfrastructure;
+import org.onap.policy.common.message.bus.event.base.TopicTestBase;
class SingleThreadedKafkaTopicSourceTest extends TopicTestBase {
private SingleThreadedKafkaTopicSource source;
source.shutdown();
}
- void testSerialize() {
- assertThatCode(() -> new GsonTestUtils().compareGson(source, SingleThreadedKafkaTopicSourceTest.class))
- .doesNotThrowAnyException();
- }
-
@Test
void testToString() {
assertTrue(source.toString().startsWith("SingleThreadedKafkaTopicSource ["));
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.bus;
+package org.onap.policy.common.message.bus.event.noop;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Collections;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
-import org.onap.policy.common.endpoints.event.comm.TopicListener;
+import org.onap.policy.common.message.bus.event.Topic.CommInfrastructure;
+import org.onap.policy.common.message.bus.event.TopicListener;
+import org.onap.policy.common.message.bus.event.base.TopicTestBase;
public abstract class NoopTopicEndpointTest<F extends NoopTopicFactory<T>, T extends NoopTopicEndpoint>
extends TopicTestBase {
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.bus;
+package org.onap.policy.common.message.bus.event.noop;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.onap.policy.common.endpoints.properties.PolicyEndPointProperties.PROPERTY_MANAGED_SUFFIX;
-import static org.onap.policy.common.endpoints.properties.PolicyEndPointProperties.PROPERTY_TOPIC_SERVERS_SUFFIX;
+import static org.onap.policy.common.message.bus.properties.MessageBusProperties.PROPERTY_MANAGED_SUFFIX;
+import static org.onap.policy.common.message.bus.properties.MessageBusProperties.PROPERTY_TOPIC_SERVERS_SUFFIX;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
-import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
+import org.onap.policy.common.message.bus.event.Topic.CommInfrastructure;
+import org.onap.policy.common.message.bus.event.base.TopicFactoryTestBase;
+import org.onap.policy.common.message.bus.event.base.TopicPropertyBuilder;
+import org.onap.policy.common.message.bus.event.base.TopicTestBase;
+import org.onap.policy.common.parameters.topic.BusTopicParams;
public abstract class NoopTopicFactoryTest<F extends NoopTopicFactory<T>, T extends NoopTopicEndpoint>
extends TopicFactoryTestBase<T> {
- private static final List<String> NOOP_SERVERS = Arrays.asList(CommInfrastructure.NOOP.toString());
+ private static final List<String> NOOP_SERVERS = List.of(CommInfrastructure.NOOP.toString());
private F factory = null;
protected abstract F buildFactory();
void testBuildBusTopicParams() {
initFactory();
- T item1 = buildTopic(makeParams(servers, MY_TOPIC, true));
+ T item1 = buildTopic(makeParams(servers));
assertNotNull(item1);
assertEquals(servers, item1.getServers());
@Test
@Override
- void testDestroyString_testGet_testInventory() {
+ public void testDestroyString_testGet_testInventory() {
super.testDestroyString_testGet_testInventory();
super.testDestroyString_Ex();
}
@Test
@Override
- void testDestroy() {
+ public void testDestroy() {
super.testDestroy();
}
return new NoopTopicPropertyBuilder(factory.getTopicsPropertyName());
}
- private BusTopicParams makeParams(List<String> servers, String topic, boolean managed) {
+ private BusTopicParams makeParams(List<String> servers) {
BusTopicParams params = new BusTopicParams();
params.setServers(servers);
- params.setTopic(topic);
- params.setManaged(managed);
+ params.setTopic(TopicTestBase.MY_TOPIC);
+ params.setManaged(true);
return params;
}
* ONAP
* ================================================================================
* Copyright (C) 2018-2019 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.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.bus;
+package org.onap.policy.common.message.bus.event.noop;
-import static org.onap.policy.common.endpoints.event.comm.bus.TopicTestBase.MY_EFFECTIVE_TOPIC;
-import static org.onap.policy.common.endpoints.properties.PolicyEndPointProperties.PROPERTY_ALLOW_SELF_SIGNED_CERTIFICATES_SUFFIX;
-import static org.onap.policy.common.endpoints.properties.PolicyEndPointProperties.PROPERTY_HTTP_HTTPS_SUFFIX;
-import static org.onap.policy.common.endpoints.properties.PolicyEndPointProperties.PROPERTY_MANAGED_SUFFIX;
-import static org.onap.policy.common.endpoints.properties.PolicyEndPointProperties.PROPERTY_TOPIC_EFFECTIVE_TOPIC_SUFFIX;
-import static org.onap.policy.common.endpoints.properties.PolicyEndPointProperties.PROPERTY_TOPIC_SERVERS_SUFFIX;
+import static org.onap.policy.common.message.bus.event.base.TopicTestBase.MY_EFFECTIVE_TOPIC;
+import static org.onap.policy.common.message.bus.properties.MessageBusProperties.PROPERTY_ALLOW_SELF_SIGNED_CERTIFICATES_SUFFIX;
+import static org.onap.policy.common.message.bus.properties.MessageBusProperties.PROPERTY_HTTP_HTTPS_SUFFIX;
+import static org.onap.policy.common.message.bus.properties.MessageBusProperties.PROPERTY_MANAGED_SUFFIX;
+import static org.onap.policy.common.message.bus.properties.MessageBusProperties.PROPERTY_TOPIC_EFFECTIVE_TOPIC_SUFFIX;
+import static org.onap.policy.common.message.bus.properties.MessageBusProperties.PROPERTY_TOPIC_SERVERS_SUFFIX;
-import java.util.Arrays;
+import java.util.List;
import lombok.Getter;
-import org.onap.policy.common.endpoints.parameters.TopicParameters;
+import org.onap.policy.common.message.bus.event.base.TopicPropertyBuilder;
+import org.onap.policy.common.parameters.topic.TopicParameters;
+@Getter
public class NoopTopicPropertyBuilder extends TopicPropertyBuilder {
public static final String SERVER = "my-server";
- public static final String TOPIC2 = "my-topic-2";
- @Getter
- private TopicParameters params = new TopicParameters();
+ private final TopicParameters params = new TopicParameters();
/**
* Constructs the object.
params.setManaged(true);
params.setUseHttps(true);
params.setAllowSelfSignedCerts(true);
- params.setServers(Arrays.asList(SERVER));
+ params.setServers(List.of(SERVER));
return this;
}
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.bus;
+package org.onap.policy.common.message.bus.event.noop;
import static org.junit.jupiter.api.Assertions.assertTrue;
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.bus;
+package org.onap.policy.common.message.bus.event.noop;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertFalse;
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.bus;
+package org.onap.policy.common.message.bus.event.noop;
import static org.junit.jupiter.api.Assertions.assertTrue;
/*
* ============LICENSE_START=======================================================
- * policy-endpoints
- * ================================================================================
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2024 Nordix Foundation
* ================================================================================
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.event.comm.bus;
+package org.onap.policy.common.message.bus.event.noop;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.features;
+package org.onap.policy.common.message.bus.features;
import static org.junit.jupiter.api.Assertions.assertFalse;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
-import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
-import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
+import org.onap.policy.common.message.bus.event.Topic.CommInfrastructure;
+import org.onap.policy.common.message.bus.utils.NetLoggerUtil.EventType;
import org.slf4j.Logger;
@ExtendWith(MockitoExtension.class)
/*-
* ============LICENSE_START=======================================================
- * policy-endpoints
- * ================================================================================
* Copyright (C) 2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.utils;
+package org.onap.policy.common.message.bus.utils;
-import static org.onap.policy.common.endpoints.properties.PolicyEndPointProperties.PROPERTY_ADDITIONAL_PROPS_SUFFIX;
+import static org.onap.policy.common.message.bus.properties.MessageBusProperties.PROPERTY_ADDITIONAL_PROPS_SUFFIX;
import java.util.Properties;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
+import org.onap.policy.common.utils.properties.PropertyUtils;
class KafkaPropertyUtilsTest {
/*-
* ============LICENSE_START=======================================================
- * policy-endpoints
- * ================================================================================
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2024 Nordix Foundation
* ================================================================================
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.utils;
+package org.onap.policy.common.message.bus.utils;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
-import org.onap.policy.common.endpoints.features.NetLoggerFeatureApi;
-import org.onap.policy.common.endpoints.features.NetLoggerFeatureProviders;
-import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
+import org.onap.policy.common.message.bus.event.Topic.CommInfrastructure;
+import org.onap.policy.common.message.bus.features.NetLoggerFeatureApi;
+import org.onap.policy.common.message.bus.features.NetLoggerFeatureProviders;
+import org.onap.policy.common.message.bus.utils.NetLoggerUtil.EventType;
import org.slf4j.Logger;
/**
* Sets the return value for the before/after hooks.
*
* @param beforeVal beforeLog() return value
- * @param afterVal afterLog() return value
+ * @param afterVal afterLog() return value
*/
public void setReturnValue(boolean beforeVal, boolean afterVal) {
this.beforeReturn = beforeVal;
*/
@Override
public boolean beforeLog(Logger eventLogger, EventType type, CommInfrastructure protocol, String topic,
- String message) {
+ String message) {
if (beforeException) {
throw new RuntimeException("beforeLog exception");
*/
@Override
public boolean afterLog(Logger eventLogger, EventType type, CommInfrastructure protocol, String topic,
- String message) {
+ String message) {
if (afterException) {
throw new RuntimeException("afterLog exception");
--- /dev/null
+org.onap.policy.common.message.bus.utils.NetLoggerUtilTest$NetLoggerFeature
\ No newline at end of file
--- /dev/null
+<!--
+ ============LICENSE_START=======================================================
+ ONAP
+ ================================================================================
+ 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=========================================================
+ -->
+<configuration>
+
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
+ <Pattern>
+ %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36}.%M\(%line\) - %msg%n
+ </Pattern>
+ </encoder>
+ </appender>
+
+ <appender name="testAppender" class="org.onap.policy.common.message.bus.utils.NetLoggerUtilTest$TestAppender"/>
+
+ <logger name="org.onap.policy.drools.http.server.test" level="INFO"/>
+
+ <logger name="network" level="INFO">
+ <appender-ref ref="testAppender"/>
+ </logger>
+
+ <root level="WARN">
+ <appender-ref ref="STDOUT"/>
+ </root>
+
+</configuration>
\ No newline at end of file
<groupId>org.onap.policy.common</groupId>
<artifactId>capabilities</artifactId>
<version>${project.version}</version>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>org.onap.policy.common</groupId>
- <artifactId>gson</artifactId>
+ <artifactId>common-parameters</artifactId>
<version>${project.version}</version>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>org.onap.policy.common</groupId>
- <artifactId>utils</artifactId>
+ <artifactId>gson</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.onap.policy.common</groupId>
- <artifactId>common-parameters</artifactId>
+ <artifactId>message-bus</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.onap.policy.common</groupId>
- <artifactId>utils-test</artifactId>
+ <artifactId>utils</artifactId>
<version>${project.version}</version>
- <scope>test</scope>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>org.glassfish.jaxb</groupId>
- <artifactId>jaxb-runtime</artifactId>
+ <groupId>com.google.re2j</groupId>
+ <artifactId>re2j</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>org.glassfish.jersey.containers</groupId>
- <artifactId>jersey-container-servlet-core</artifactId>
+ <groupId>io.prometheus</groupId>
+ <artifactId>simpleclient_hotspot</artifactId>
</dependency>
<dependency>
- <groupId>org.glassfish.jersey.core</groupId>
- <artifactId>jersey-server</artifactId>
- <version>${version.jersey}</version>
+ <groupId>io.prometheus</groupId>
+ <artifactId>simpleclient_servlet_jakarta</artifactId>
</dependency>
<dependency>
- <groupId>org.glassfish.jersey.inject</groupId>
- <artifactId>jersey-hk2</artifactId>
- <version>${version.jersey}</version>
+ <groupId>jakarta.ws.rs</groupId>
+ <artifactId>jakarta.ws.rs-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>org.eclipse.jetty</groupId>
- <artifactId>jetty-servlet</artifactId>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
</dependency>
<dependency>
- <groupId>org.apache.kafka</groupId>
- <artifactId>kafka-clients</artifactId>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-servlet</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-util</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty.toolchain</groupId>
+ <artifactId>jetty-jakarta-servlet-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.core</groupId>
+ <artifactId>jersey-client</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.core</groupId>
+ <artifactId>jersey-server</artifactId>
+ <version>${version.jersey}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.projectlombok</groupId>
+ <artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-collections4</artifactId>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <scope>provided</scope>
</dependency>
<dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-jexl3</artifactId>
+ <groupId>org.yaml</groupId>
+ <artifactId>snakeyaml</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>io.swagger.core.v3</groupId>
- <artifactId>swagger-annotations</artifactId>
- <scope>test</scope>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <scope>provided</scope>
</dependency>
<dependency>
- <groupId>io.opentelemetry.instrumentation</groupId>
- <artifactId>opentelemetry-kafka-clients-2.6</artifactId>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-core</artifactId>
+ <scope>provided</scope>
</dependency>
<dependency>
- <groupId>io.swagger.core.v3</groupId>
- <artifactId>swagger-jaxrs2-jakarta</artifactId>
+ <groupId>org.glassfish.jaxb</groupId>
+ <artifactId>jaxb-runtime</artifactId>
+ <scope>runtime</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.inject</groupId>
+ <artifactId>jersey-hk2</artifactId>
+ <version>${version.jersey}</version>
+ <scope>runtime</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.swagger.core.v3</groupId>
- <artifactId>swagger-jaxrs2-servlet-initializer-v2-jakarta</artifactId>
+ <artifactId>swagger-annotations</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>io.prometheus</groupId>
- <artifactId>simpleclient_hotspot</artifactId>
+ <groupId>io.swagger.core.v3</groupId>
+ <artifactId>swagger-jaxrs2-jakarta</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>io.prometheus</groupId>
- <artifactId>simpleclient_servlet_jakarta</artifactId>
- <scope>provided</scope>
+ <groupId>org.onap.policy.common</groupId>
+ <artifactId>utils-test</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
- <artifactId>mockito-junit-jupiter</artifactId>
+ <artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
+++ /dev/null
-/*
- * ============LICENSE_START=======================================================
- * policy-endpoints
- * ================================================================================
- * Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2018 Samsung Electronics Co., Ltd.
- * Modifications Copyright (C) 2020,2023 Bell Canada. All rights reserved.
- * Modifications Copyright (C) 2022-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.endpoints.event.comm.bus.internal;
-
-import io.opentelemetry.instrumentation.kafkaclients.v2_6.TracingProducerInterceptor;
-import java.util.Properties;
-import java.util.UUID;
-import org.apache.kafka.clients.producer.KafkaProducer;
-import org.apache.kafka.clients.producer.Producer;
-import org.apache.kafka.clients.producer.ProducerConfig;
-import org.apache.kafka.clients.producer.ProducerRecord;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public interface BusPublisher {
-
- String NO_MESSAGE_PROVIDED = "No message provided";
- String LOG_CLOSE = "{}: CLOSE";
- String LOG_CLOSE_FAILED = "{}: CLOSE FAILED";
-
- /**
- * sends a message.
- *
- * @param partitionId id
- * @param message the message
- * @return true if success, false otherwise
- * @throws IllegalArgumentException if no message provided
- */
- boolean send(String partitionId, String message);
-
- /**
- * closes the publisher.
- */
- void close();
-
- /**
- * Kafka based library publisher.
- */
- class KafkaPublisherWrapper implements BusPublisher {
-
- private static final Logger logger = LoggerFactory.getLogger(KafkaPublisherWrapper.class);
- private static final String KEY_SERIALIZER = "org.apache.kafka.common.serialization.StringSerializer";
-
- private final String topic;
-
- /**
- * Kafka publisher.
- */
- private final Producer<String, String> producer;
- protected Properties kafkaProps;
-
- /**
- * Kafka Publisher Wrapper.
- *
- * @param busTopicParams topic parameters
- */
- protected KafkaPublisherWrapper(BusTopicParams busTopicParams) {
-
- if (busTopicParams.isTopicInvalid()) {
- throw new IllegalArgumentException("No topic for Kafka");
- }
-
- this.topic = busTopicParams.getTopic();
-
- // Setup Properties for consumer
- kafkaProps = new Properties();
- kafkaProps.setProperty(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, busTopicParams.getServers().get(0));
- if (busTopicParams.isAdditionalPropsValid()) {
- kafkaProps.putAll(busTopicParams.getAdditionalProps());
- }
- if (kafkaProps.get(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG) == null) {
- kafkaProps.setProperty(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, KEY_SERIALIZER);
- }
- if (kafkaProps.get(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG) == null) {
- kafkaProps.setProperty(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, KEY_SERIALIZER);
- }
-
- if (busTopicParams.isAllowTracing()) {
- kafkaProps.setProperty(ProducerConfig.INTERCEPTOR_CLASSES_CONFIG,
- TracingProducerInterceptor.class.getName());
- }
-
- producer = new KafkaProducer<>(kafkaProps);
- }
-
- @Override
- public boolean send(String partitionId, String message) {
- if (message == null) {
- throw new IllegalArgumentException(NO_MESSAGE_PROVIDED);
- }
-
- try {
- // Create the record
- ProducerRecord<String, String> producerRecord =
- new ProducerRecord<>(topic, UUID.randomUUID().toString(), message);
-
- this.producer.send(producerRecord);
- producer.flush();
- } catch (Exception e) {
- logger.warn("{}: SEND of {} cannot be performed because of {}", this, message, e.getMessage(), e);
- return false;
- }
- return true;
- }
-
- @Override
- public void close() {
- logger.info(LOG_CLOSE, this);
-
- try {
- this.producer.close();
- } catch (Exception e) {
- logger.warn("{}: CLOSE FAILED because of {}", this, e.getMessage(), e);
- }
- }
-
- @Override
- public String toString() {
- return "KafkaPublisherWrapper []";
- }
-
- }
-}
* ================================================================================
* Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2018 Samsung Electronics Co., Ltd.
+ * 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.
import java.util.List;
import java.util.Properties;
-import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
+import org.onap.policy.common.parameters.topic.BusTopicParams;
/**
* Http Client Factory.
* ONAP
* ================================================================================
* Copyright (C) 2017-2019, 2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2023 Nordix Foundation.
+ * Modifications Copyright (C) 2023-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.
import java.util.List;
import java.util.Properties;
import org.apache.commons.lang3.StringUtils;
-import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
import org.onap.policy.common.endpoints.http.client.internal.JerseyClient;
import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
-import org.onap.policy.common.endpoints.utils.PropertyUtils;
+import org.onap.policy.common.parameters.topic.BusTopicParams;
+import org.onap.policy.common.utils.properties.PropertyUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* ================================================================================
* Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2018 Samsung Electronics Co., Ltd.
- * Modifications Copyright (C) 2019, 2023 Nordix Foundation.
+ * Modifications Copyright (C) 2019, 2023-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.
import org.apache.commons.lang3.StringUtils;
import org.glassfish.jersey.client.ClientProperties;
import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
-import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
import org.onap.policy.common.endpoints.http.client.HttpClient;
+import org.onap.policy.common.parameters.topic.BusTopicParams;
import org.onap.policy.common.utils.network.NetworkUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.onap.policy.common.endpoints.http.server.internal.JettyJerseyServer;
import org.onap.policy.common.endpoints.http.server.internal.JettyStaticResourceServer;
import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
-import org.onap.policy.common.endpoints.utils.PropertyUtils;
+import org.onap.policy.common.utils.properties.PropertyUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Properties;
import java.util.stream.Collectors;
import lombok.ToString;
-import org.onap.policy.common.endpoints.parameters.RestServerParameters;
import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
import org.onap.policy.common.gson.GsonMessageBodyHandler;
+import org.onap.policy.common.parameters.rest.RestServerParameters;
import org.onap.policy.common.utils.services.ServiceManagerContainer;
/**
* ================================================================================
* Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2020 Bell Canada. 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.
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
-import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
-import org.onap.policy.common.endpoints.event.comm.TopicListener;
+import org.onap.policy.common.message.bus.event.Topic.CommInfrastructure;
+import org.onap.policy.common.message.bus.event.TopicListener;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
* ONAP
* ================================================================================
* Copyright (C) 2019, 2021 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.
package org.onap.policy.common.endpoints.listeners;
import java.util.concurrent.ConcurrentHashMap;
-import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
+import org.onap.policy.common.message.bus.event.Topic.CommInfrastructure;
import org.onap.policy.common.utils.coder.StandardCoderObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* ONAP
* ================================================================================
* Copyright (C) 2019, 2021 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.
import com.google.common.base.Strings;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
-import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
+import org.onap.policy.common.message.bus.event.Topic.CommInfrastructure;
import org.onap.policy.common.utils.coder.StandardCoderObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* ================================================================================
* Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2020 Bell Canada. 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.
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
-import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
+import org.onap.policy.common.message.bus.event.Topic.CommInfrastructure;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
* ONAP
* ================================================================================
* Copyright (C) 2019 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.
package org.onap.policy.common.endpoints.listeners;
-import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
+import org.onap.policy.common.message.bus.event.Topic.CommInfrastructure;
/**
* Listener for messages of a certain type.
/* Generic property suffixes */
- public static final String PROPERTY_TOPIC_SERVERS_SUFFIX = ".servers";
- public static final String PROPERTY_TOPIC_TOPICS_SUFFIX = ".topics";
- public static final String PROPERTY_TOPIC_API_KEY_SUFFIX = ".apiKey";
- public static final String PROPERTY_TOPIC_API_SECRET_SUFFIX = ".apiSecret";
- public static final String PROPERTY_TOPIC_EFFECTIVE_TOPIC_SUFFIX = ".effectiveTopic";
- public static final String PROPERTY_TOPIC_EVENTS_SUFFIX = ".events";
- public static final String PROPERTY_TOPIC_EVENTS_FILTER_SUFFIX = ".filter";
- public static final String PROPERTY_TOPIC_EVENTS_CUSTOM_MODEL_CODER_GSON_SUFFIX = ".events.custom.gson";
-
- public static final String PROPERTY_TOPIC_SOURCE_CONSUMER_GROUP_SUFFIX = ".consumerGroup";
- public static final String PROPERTY_TOPIC_SOURCE_CONSUMER_INSTANCE_SUFFIX = ".consumerInstance";
- public static final String PROPERTY_TOPIC_SOURCE_FETCH_TIMEOUT_SUFFIX = ".fetchTimeout";
- public static final String PROPERTY_TOPIC_SOURCE_FETCH_LIMIT_SUFFIX = ".fetchLimit";
public static final String PROPERTY_MANAGED_SUFFIX = ".managed";
- public static final String PROPERTY_ADDITIONAL_PROPS_SUFFIX = ".additionalProps";
-
- public static final String PROPERTY_TOPIC_SINK_PARTITION_KEY_SUFFIX = ".partitionKey";
-
public static final String PROPERTY_ALLOW_SELF_SIGNED_CERTIFICATES_SUFFIX = ".selfSignedCertificates";
- public static final String PROPERTY_NOOP_SOURCE_TOPICS = "noop.source.topics";
- public static final String PROPERTY_NOOP_SINK_TOPICS = "noop.sink.topics";
-
- /* KAFKA Properties */
-
- public static final String PROPERTY_KAFKA_SOURCE_TOPICS = "kafka.source.topics";
- public static final String PROPERTY_KAFKA_SINK_TOPICS = "kafka.sink.topics";
-
/* HTTP Server Properties */
public static final String PROPERTY_HTTP_SERVER_SERVICES = "http.server.services";
public static final String PROPERTY_HTTP_URL_SUFFIX = PROPERTY_HTTP_CONTEXT_URIPATH_SUFFIX;
- /* Topic Sink Values */
-
- /**
- * Log Failures after X number of retries.
- */
- public static final int DEFAULT_LOG_SEND_FAILURES_AFTER = 1;
-
-
- /* Topic Source values */
-
- /**
- * Default Timeout fetching in milliseconds.
- */
- public static final int DEFAULT_TIMEOUT_MS_FETCH = 15000;
-
- /**
- * Default maximum number of messages fetch at the time.
- */
- public static final int DEFAULT_LIMIT_FETCH = 100;
-
- /**
- * Definition of No Timeout fetching.
- */
- public static final int NO_TIMEOUT_MS_FETCH = -1;
-
- /**
- * Definition of No limit fetching.
- */
- public static final int NO_LIMIT_FETCH = -1;
}
+++ /dev/null
-/*
- * ============LICENSE_START=======================================================
- * policy-endpoints
- * ================================================================================
- * 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.endpoints.event.comm.bus.internal;
-
-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.function.BiConsumer;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.onap.policy.common.endpoints.event.comm.bus.TopicTestBase;
-import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams.TopicParamsBuilder;
-
-class BusTopicParamsTest extends TopicTestBase {
-
- @BeforeEach
- @Override
- public void setUp() {
- super.setUp();
- }
-
- @Test
- void testGetters() {
- BusTopicParams params = makeBuilder().build();
-
- assertEquals(addProps, params.getAdditionalProps());
- assertEquals(MY_AFT_ENV, params.getAftEnvironment());
- assertTrue(params.isAllowSelfSignedCerts());
- assertEquals(MY_API_KEY, params.getApiKey());
- assertEquals(MY_API_SECRET, params.getApiSecret());
- assertEquals(MY_BASE_PATH, params.getBasePath());
- assertEquals(MY_CLIENT_NAME, params.getClientName());
- assertEquals(MY_CONS_GROUP, params.getConsumerGroup());
- assertEquals(MY_CONS_INST, params.getConsumerInstance());
- assertEquals(MY_ENV, params.getEnvironment());
- assertEquals(MY_FETCH_LIMIT, params.getFetchLimit());
- assertEquals(MY_FETCH_TIMEOUT, params.getFetchTimeout());
- assertEquals(MY_HOST, params.getHostname());
- assertEquals(MY_LAT, params.getLatitude());
- assertEquals(MY_LONG, params.getLongitude());
- assertTrue(params.isManaged());
- assertEquals(MY_PARTITION, params.getPartitionId());
- assertEquals(MY_PARTNER, params.getPartner());
- assertEquals(MY_PASS, params.getPassword());
- assertEquals(MY_PORT, params.getPort());
- assertEquals(servers, params.getServers());
- assertEquals(MY_TOPIC, params.getTopic());
- assertEquals(MY_EFFECTIVE_TOPIC, params.getEffectiveTopic());
- assertTrue(params.isUseHttps());
- 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() {
- assertFalse(makeBuilder().additionalProps(null).build().isAdditionalPropsValid());
- assertTrue(makeBuilder().aftEnvironment("").build().isAftEnvironmentInvalid());
- assertFalse(makeBuilder().apiKey("").build().isApiKeyValid());
- assertFalse(makeBuilder().apiSecret("").build().isApiSecretValid());
- assertTrue(makeBuilder().clientName("").build().isClientNameInvalid());
- assertTrue(makeBuilder().consumerGroup("").build().isConsumerGroupInvalid());
- assertTrue(makeBuilder().consumerInstance("").build().isConsumerInstanceInvalid());
- assertTrue(makeBuilder().environment("").build().isEnvironmentInvalid());
- assertTrue(makeBuilder().hostname("").build().isHostnameInvalid());
- assertTrue(makeBuilder().latitude("").build().isLatitudeInvalid());
- assertTrue(makeBuilder().longitude("").build().isLongitudeInvalid());
- assertTrue(makeBuilder().partitionId("").build().isPartitionIdInvalid());
- assertTrue(makeBuilder().partner("").build().isPartnerInvalid());
- assertFalse(makeBuilder().password("").build().isPasswordValid());
- assertTrue(makeBuilder().port(-1).build().isPortInvalid());
- assertTrue(makeBuilder().port(65536).build().isPortInvalid());
- assertTrue(makeBuilder().servers(null).build().isServersInvalid());
- assertTrue(makeBuilder().servers(new LinkedList<>()).build().isServersInvalid());
- assertTrue(makeBuilder().servers(List.of("")).build().isServersInvalid());
- assertFalse(makeBuilder().servers(List.of("one-server")).build().isServersInvalid());
- assertTrue(makeBuilder().topic("").build().isTopicInvalid());
- 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 builder = BusTopicParams.builder();
-
- // first try the "false" case
- function.accept(builder, false);
-
- BusTopicParams params = builder.build();
- assertEquals("false:false:false",
- params.isAllowSelfSignedCerts() + ":" + params.isManaged() + ":" + params.isUseHttps());
-
-
- // now try the "true" case
- function.accept(builder, true);
-
- params = builder.build();
- assertEquals(expectedTrue,
- params.isAllowSelfSignedCerts() + ":" + params.isManaged() + ":" + params.isUseHttps());
- }
-}
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import lombok.Getter;
+import lombok.Setter;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
import org.onap.policy.common.endpoints.http.client.HttpClient;
import org.onap.policy.common.endpoints.http.client.HttpClientConfigException;
import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
import org.onap.policy.common.endpoints.http.server.internal.JettyJerseyServer;
import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
+import org.onap.policy.common.parameters.topic.BusTopicParams;
import org.onap.policy.common.utils.network.NetworkUtil;
class HttpClientTest {
}
+ @Setter
+ @Getter
static class MyEntity {
private String myParameter;
this.myParameter = myParameter;
}
- public void setMyParameter(final String myParameter) {
- this.myParameter = myParameter;
- }
-
- public String getMyParameter() {
- return myParameter;
- }
-
}
static class MyCallback implements InvocationCallback<Response> {
@Getter
private Throwable throwable;
- private CountDownLatch latch = new CountDownLatch(1);
+ private final CountDownLatch latch = new CountDownLatch(1);
@Override
public void completed(Response response) {
*/
@Test
void testExplicitPrometheusServer() throws Exception {
- logger.info("-- testPrometheusServer() --");
+ logger.info("-- testExplicitPrometheusServer() --");
HttpServletServer server = HttpServletServerFactoryInstance.getServerFactory()
.build(PROMETHEUS, LOCALHOST, port, "/", false, true);
*/
@Test
void testPrometheusJaxRsFilterSwaggerServer() throws Exception {
- logger.info("-- testPrometheusServer() --");
+ logger.info("-- testPrometheusJaxRsFilterSwaggerServer() --");
HttpServletServer server = HttpServletServerFactoryInstance.getServerFactory()
.build(PROMETHEUS, LOCALHOST, port, "/", true, true);
import org.onap.policy.common.endpoints.http.server.RestServer.Factory;
import org.onap.policy.common.endpoints.http.server.YamlExceptionMapper;
import org.onap.policy.common.endpoints.http.server.YamlMessageBodyHandler;
-import org.onap.policy.common.endpoints.parameters.RestServerParameters;
import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
import org.onap.policy.common.gson.GsonMessageBodyHandler;
+import org.onap.policy.common.parameters.rest.RestServerParameters;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.network.NetworkUtil;
import org.springframework.test.util.ReflectionTestUtils;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
+import org.onap.policy.common.message.bus.event.Topic.CommInfrastructure;
import org.onap.policy.common.utils.coder.StandardCoderObject;
import org.onap.policy.common.utils.test.log.logback.ExtractAppender;
import org.slf4j.LoggerFactory;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
+import org.onap.policy.common.message.bus.event.Topic.CommInfrastructure;
import org.onap.policy.common.utils.coder.StandardCoderObject;
import org.onap.policy.common.utils.test.log.logback.ExtractAppender;
import org.slf4j.LoggerFactory;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
+import org.onap.policy.common.message.bus.event.Topic.CommInfrastructure;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
+import org.onap.policy.common.message.bus.event.Topic.CommInfrastructure;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
private static final Coder coder = new StandardCoder();
private ScoListener<MyMessage> primary;
- private MyMessage status;
- private StandardCoderObject sco;
/**
* Initializes statics.
void testOnTopicEvent() {
primary = spy(primary);
- status = new MyMessage(NAME);
- sco = makeSco(status);
+ MyMessage status = new MyMessage(NAME);
+ StandardCoderObject sco = makeSco(status);
primary.onTopicEvent(INFRA, TOPIC, sco);
verify(primary).onTopicEvent(INFRA, TOPIC, sco, status);
// undecodable message
logger.addAppender(appender);
- primary.onTopicEvent(INFRA, TOPIC, makeSco("[]"));
+ primary.onTopicEvent(INFRA, TOPIC, makeSco());
verify(primary, times(1)).onTopicEvent(INFRA, TOPIC, sco, status);
assertTrue(appender.getExtracted().toString().contains("unable to decode"));
}
/**
* Makes a standard object from a JSON string.
*
- * @param source message to be converted
* @return a standard object representing the message
*/
- private StandardCoderObject makeSco(String source) {
+ private StandardCoderObject makeSco() {
try {
- return coder.decode(source, StandardCoderObject.class);
+ return coder.decode("[]", StandardCoderObject.class);
} catch (CoderException e) {
throw new RuntimeException(e);
}
MyMessage other = (MyMessage) obj;
if (name == null) {
- if (other.name != null) {
- return false;
- }
- } else if (!name.equals(other.name)) {
- return false;
+ return other.name == null;
+ } else {
+ return name.equals(other.name);
}
- return true;
}
}
}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019, 2024 Nordix Foundation.
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.common.endpoints.rest;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.util.Map;
+import java.util.TreeMap;
+import org.onap.policy.common.parameters.ParameterGroup;
+import org.onap.policy.common.utils.coder.Coder;
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.common.utils.coder.StandardCoder;
+
+/**
+ * Class to hold/create all parameters for test cases.
+ *
+ * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
+ */
+public class CommonTestData {
+
+ public static final String REST_SERVER_PASS = "zb!XztG34";
+ public static final String REST_SERVER_USER = "healthcheck";
+ public static final int REST_SERVER_PORT = 6969;
+ public static final String REST_SERVER_HOST = "0.0.0.0";
+ public static final boolean REST_SERVER_HTTPS = true;
+ public static final boolean REST_SERVER_AAF = false;
+
+ protected static final Coder coder = new StandardCoder();
+
+ /**
+ * Converts the contents of a map to a parameter class.
+ *
+ * @param source property map
+ * @param clazz class of object to be created from the map
+ * @return a new object represented by the map
+ */
+ public <T extends ParameterGroup> T toObject(final Map<String, Object> source, final Class<T> clazz) {
+ try {
+ return coder.decode(coder.encode(source), clazz);
+
+ } catch (final CoderException e) {
+ throw new RuntimeException("cannot create " + clazz.getName() + " from map", e);
+ }
+ }
+
+ /**
+ * Returns a property map for a RestServerParameters map for test cases.
+ *
+ * @param isEmpty boolean value to represent that object created should be empty or not
+ * @return a property map suitable for constructing an object
+ */
+ public Map<String, Object> getRestServerParametersMap(final boolean isEmpty) {
+ final Map<String, Object> map = new TreeMap<>();
+ map.put("https", REST_SERVER_HTTPS);
+ map.put("aaf", REST_SERVER_AAF);
+
+ if (!isEmpty) {
+ map.put("host", REST_SERVER_HOST);
+ map.put("port", REST_SERVER_PORT);
+ map.put("userName", REST_SERVER_USER);
+ map.put("password", REST_SERVER_PASS);
+ }
+
+ return map;
+ }
+
+ /**
+ * Gets the standard parameter group as a String.
+ *
+ * @param filePath path of the file
+ * @return the standard parameters
+ * @throws IOException when file read operation fails
+ */
+ public String getParameterGroupAsString(String filePath) throws IOException {
+ File file = new File(filePath);
+ return Files.readString(file.toPath());
+ }
+}
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.parameters;
+package org.onap.policy.common.endpoints.rest;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
import org.onap.policy.common.parameters.ValidationResult;
+import org.onap.policy.common.parameters.rest.RestServerParameters;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.StandardCoder;
*/
class RestServerParametersTest {
- private static CommonTestData testData = new CommonTestData();
+ private static final CommonTestData testData = new CommonTestData();
private static final Coder coder = new StandardCoder();
@Test
@Test
void test_valid() throws Exception {
String json = testData.getParameterGroupAsString(
- "src/test/resources/org/onap/policy/common/endpoints/parameters/RestServerParameters_valid.json");
+ "src/test/resources/org/onap/policy/common/endpoints/rest/RestServerParameters_valid.json");
RestServerParameters restServerParameters = coder.decode(json, RestServerParameters.class);
final ValidationResult result = restServerParameters.validate();
assertNull(result.getResult());
@Test
void test_invalid() throws Exception {
String json = testData.getParameterGroupAsString(
- "src/test/resources/org/onap/policy/common/endpoints/parameters/RestServerParameters_invalid.json");
+ "src/test/resources/org/onap/policy/common/endpoints/rest/RestServerParameters_invalid.json");
RestServerParameters restServerParameters = coder.decode(json, RestServerParameters.class);
final ValidationResult result = restServerParameters.validate();
assertFalse(result.isValid());
+++ /dev/null
-org.onap.policy.common.endpoints.utils.NetLoggerUtilTest$NetLoggerFeature
+++ /dev/null
-{
- "servers": [
- "svra",
- "svrb"
- ],
- "topic": "my-topic",
- "effectiveTopic": "my-effective-topic",
- "recentEvents": [],
- "alive": false,
- "locked": false,
- "useHttps": false,
- "allowTracing": false,
- "topicCommInfrastructure": "KAFKA",
- "partitionKey": "my-partition",
- "additionalProps": {
- "security.protocol": "SASL_PLAINTEXT",
- "sasl.mechanism": "SCRAM-SHA-512",
- "sasl.jaas.config": "org.apache.kafka.common.security.plain.PlainLoginModule required username=abc password=abc serviceName=kafka;"
- }
-}
+++ /dev/null
-{
- "servers": [
- "localhost:9092",
- "10.1.2.3:9092"
- ],
- "topic": "my-topic",
- "effectiveTopic": "my-effective-topic",
- "recentEvents": [],
- "alive": false,
- "locked": false,
- "useHttps": false,
- "allowTracing": false,
- "topicCommInfrastructure": "KAFKA",
- "additionalProps": {
- "security.protocol": "SASL_PLAINTEXT",
- "sasl.mechanism": "SCRAM-SHA-512",
- "sasl.jaas.config": "org.apache.kafka.common.security.plain.PlainLoginModule required username=abc password=abc serviceName=kafka;"
- }
-}
--- /dev/null
+{
+ "topicSources" : [ {
+ "topic" : "policy-pdp-pap1",
+ "servers" : [ "kafka2, kafka3" ],
+ "topicCommInfrastructure" : "kafka",
+ "effectiveTopic" : "my-effective-topic",
+ "apiKey" : "my-api-key",
+ "apiSecret" : "my-api-secret",
+ "port": 123,
+ "useHttps" : true,
+ "allowTracing": true,
+ "allowSelfSignedCerts" : true,
+ "consumerGroup" : "consumer group",
+ "consumerInstance" : "consumer instance",
+ "fetchTimeout" : 15000,
+ "fetchLimit" : 100,
+ "userName": "username",
+ "password": "password",
+ "managed": true,
+ "environment": "environment1",
+ "aftEnvironment": "aftEnvironment1",
+ "partner": "partner1",
+ "latitude": "1234",
+ "longitude": "1234",
+ "partitionId": "partition_id",
+ "additionalProps": {"xyz":"xyz"},
+ "clientName": "clientName1",
+ "hostname": "hostname1",
+ "basePath": "basePath1",
+ "serializationProvider": "serializationProvider1"
+ }],
+ "topicSinks" : [ {
+ "topic" : "policy-pdp-pap1",
+ "servers" : [ "kafka2, kafka3" ],
+ "topicCommInfrastructure" : "kafka",
+ "effectiveTopic" : "my-effective-topic",
+ "apiKey" : "my-api-key",
+ "apiSecret" : "my-api-secret",
+ "port": 123,
+ "useHttps" : true,
+ "allowTracing": true,
+ "allowSelfSignedCerts" : true,
+ "consumerGroup" : "consumer group",
+ "consumerInstance" : "consumer instance",
+ "fetchTimeout" : 15000,
+ "fetchLimit" : 100,
+ "userName": "username",
+ "password": "password",
+ "managed": true,
+ "environment": "environment1",
+ "aftEnvironment": "aftEnvironment1",
+ "partner": "partner1",
+ "latitude": "1234",
+ "longitude": "1234",
+ "partitionId": "partition_id",
+ "additionalProps": {"xyz":"xyz"},
+ "clientName": "clientName1",
+ "hostname": "hostname1",
+ "basePath": "basePath1",
+ "serializationProvider": "serializationProvider1"
+ }]
+}
\ No newline at end of file
--- /dev/null
+{
+ "topicSources" : [{
+ "topic" : "ueb-source",
+ "servers" : ["my-server"]
+ }]
+}
\ No newline at end of file
--- /dev/null
+{
+ "topicSources" : [ {
+ "topic" : "policy-pdp-pap1",
+ "servers" : [],
+ "topicCommInfrastructure" : "kafka"
+ }],
+ "topicSinks" : [ {
+ "topic" : "policy-pdp-pap2",
+ "servers" : [ "kafka1, kafka2" ],
+ "topicCommInfrastructure" : "kafka"
+ }]
+}
\ No newline at end of file
--- /dev/null
+{
+ "topicSources" : [ {
+ "topic" : "ueb-source",
+ "servers" : [ "my-server" ],
+ "topicCommInfrastructure" : "ueb"
+ },{
+ "topic" : "policy-pdp-pap1",
+ "servers" : [ "kafka1, kafka2" ],
+ "topicCommInfrastructure" : "kafka"
+ },{
+ "topic" : "policy-pdp-pap2",
+ "servers" : [ "kafka2, kafka3" ],
+ "topicCommInfrastructure" : "kafka"
+ }],
+ "topicSinks" : [ {
+ "topic" : "ueb-sink",
+ "servers" : [ "my-server" ],
+ "topicCommInfrastructure" : "ueb"
+ },{
+ "topic" : "policy-pdp-pap2",
+ "servers" : [ "kafka1, kafka2" ],
+ "topicCommInfrastructure" : "kafka"
+ },{
+ "topic" : "policy-pdp-pap3",
+ "servers" : [ "kafka2, kafka3" ],
+ "topicCommInfrastructure" : "kafka",
+ "effectiveTopic":"effectiveTopic1",
+ "allowSelfSignedCerts":true
+ }]
+}
\ No newline at end of file
<modules>
<module>capabilities</module>
- <module>utils-test</module>
- <module>utils</module>
- <module>gson</module>
<module>common-parameters</module>
- <module>policy-endpoints</module>
+ <module>gson</module>
+ <module>utils</module>
+ <module>utils-test</module>
<module>spring-utils</module>
+ <module>message-bus</module>
+ <module>policy-endpoints</module>
</modules>
<build>
<artifactId>utils</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-core</artifactId>
+ </dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
- <artifactId>mockito-junit-jupiter</artifactId>
+ <artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.assertj</groupId>
- <artifactId>assertj-core</artifactId>
- </dependency>
</dependencies>
</project>
\ No newline at end of file
ONAP Policy Engine - Common Modules
================================================================================
Copyright (C) 2018-2021 AT&T Intellectual Property. All rights reserved.
- Modificaitons Copyright (C) 2023-2024 Nordix Foundation.
+ Modifications Copyright (C) 2023-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.
============LICENSE_END=========================================================
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<dependencies>
<dependency>
- <groupId>org.bouncycastle</groupId>
- <artifactId>bcpkix-fips</artifactId>
+ <groupId>org.onap.policy.common</groupId>
+ <artifactId>utils</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.policy.common</groupId>
+ <artifactId>gson</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-jexl3</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.bouncycastle</groupId>
+ <artifactId>bcpkix-fips</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>org.onap.policy.common</groupId>
- <artifactId>utils</artifactId>
- <version>${project.version}</version>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-core</artifactId>
<scope>provided</scope>
</dependency>
-
- <!-- from parent -->
- <dependency>
- <groupId>org.awaitility</groupId>
- <artifactId>awaitility</artifactId>
- <scope>test</scope>
+ <dependency>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.google.re2j</groupId>
+ <artifactId>re2j</artifactId>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>com.openpojo</groupId>
<artifactId>openpojo</artifactId>
<scope>compile</scope>
</dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest</artifactId>
+ <scope>compile</scope>
+ </dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>compile</scope>
</dependency>
+ <dependency>
+ <groupId>org.projectlombok</groupId>
+ <artifactId>lombok</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.awaitility</groupId>
+ <artifactId>awaitility</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.hamcrest</groupId>
- <artifactId>hamcrest-core</artifactId>
- <version>2.2</version>
- <scope>compile</scope>
- </dependency>
</dependencies>
</project>
<version>${project.version}</version>
</dependency>
<dependency>
- <groupId>commons-net</groupId>
- <artifactId>commons-net</artifactId>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
</dependency>
<dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.google.re2j</groupId>
+ <artifactId>re2j</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
- <groupId>jakarta.persistence</groupId>
- <artifactId>jakarta.persistence-api</artifactId>
+ <groupId>commons-net</groupId>
+ <artifactId>commons-net</artifactId>
</dependency>
<dependency>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-classic</artifactId>
+ <groupId>jakarta.persistence</groupId>
+ <artifactId>jakarta.persistence-api</artifactId>
</dependency>
<dependency>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-core</artifactId>
+ <groupId>jakarta.xml.bind</groupId>
+ <artifactId>jakarta.xml.bind-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
- <groupId>com.google.re2j</groupId>
- <artifactId>re2j</artifactId>
+ <groupId>org.projectlombok</groupId>
+ <artifactId>lombok</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
</dependency>
+ <dependency>
+ <groupId>com.openpojo</groupId>
+ <artifactId>openpojo</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.mockito</groupId>
- <artifactId>mockito-junit-jupiter</artifactId>
+ <artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
- <groupId>jakarta.xml.bind</groupId>
- <artifactId>jakarta.xml.bind-api</artifactId>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-junit-jupiter</artifactId>
+ <scope>test</scope>
</dependency>
</dependencies>
</project>
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.utils;
+package org.onap.policy.common.utils.properties;
import java.util.Properties;
import lombok.AllArgsConstructor;
/*-
- * ============LICENSE_START=======================================================
+ * ============LICENSE_START===============================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2018, 2021 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
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.report;
+package org.onap.policy.common.utils.report;
import lombok.Getter;
import lombok.Setter;
* utils
* ================================================================================
* Copyright (C) 2019-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.
*/
public class OrderedServiceImpl<T extends OrderedService> {
// logger
- private static Logger logger = LoggerFactory.getLogger(OrderedServiceImpl.class);
+ private static final Logger logger = LoggerFactory.getLogger(OrderedServiceImpl.class);
// sorted list of instances implementing the service
private List<T> implementers = null;
// 'ServiceLoader' that is used to discover and create the services
- private ServiceLoader<T> serviceLoader = null;
+ private final ServiceLoader<T> serviceLoader;
// use this to ensure that we only use one unique instance of each class
- private static Map<Class<?>, OrderedService> classToSingleton = new HashMap<>();
+ private static final Map<Class<?>, OrderedService> classToSingleton = new HashMap<>();
/**
* Constructor - create the 'ServiceLoader' instance.
*
* @param clazz the class object associated with 'T' (I supposed it could
- * be a subclass, but I'm not sure this is useful)
+ * be a subclass, but I'm not sure if this is useful)
*/
public OrderedServiceImpl(Class<T> clazz) {
// This constructor wouldn't be needed if 'T.class' was legal
/**
* Get List of implementers.
*
- * @return the sorted list of services implementing interface 'T' discovered
- * by 'ServiceLoader'.
+ * @return the sorted list of services implementing interface 'T' discovered by 'ServiceLoader'.
*/
public synchronized List<T> getList() {
if (implementers == null) {
* expensive operation in terms of CPU and elapsed time, so it is best if it
* isn't invoked too frequently.
*
- * @return the sorted list of services implementing interface 'T' discovered
- * by 'ServiceLoader'.
+ * @return the sorted list of services implementing interface 'T' discovered by 'ServiceLoader'.
*/
@SuppressWarnings("unchecked")
public synchronized List<T> rebuildList() {
- // build a list of all of the current implementors
+ // build a list of all the current implementors
List<T> tmp = new LinkedList<>();
for (T service : serviceLoader) {
tmp.add((T) getSingleton(service));
// Sort the list according to sequence number, and then alphabetically
// according to full class name.
- Collections.sort(tmp, (o1, o2) -> {
+ tmp.sort((o1, o2) -> {
int s1 = o1.getSequenceNumber();
int s2 = o2.getSequenceNumber();
if (s1 < s2) {
/**
* If a service implements multiple APIs managed by 'ServiceLoader', a
* separate instance is created for each API. This method ensures that
- * the first instance is used in all of the lists.
+ * the first instance is used in all the lists.
*
* @param service this is the object created by ServiceLoader
* @return the object to use in place of 'service'. If 'service' is the first
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.utils;
+package org.onap.policy.common.utils.properties;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.common.endpoints.report;
+package org.onap.policy.common.utils.report;
+import static org.hamcrest.CoreMatchers.anyOf;
+import static org.hamcrest.CoreMatchers.anything;
+
+import com.openpojo.reflection.PojoClass;
import com.openpojo.reflection.filters.FilterClassName;
import com.openpojo.validation.Validator;
import com.openpojo.validation.ValidatorBuilder;
+import com.openpojo.validation.affirm.Affirm;
import com.openpojo.validation.rule.impl.GetterMustExistRule;
import com.openpojo.validation.rule.impl.SetterMustExistRule;
+import com.openpojo.validation.test.Tester;
import com.openpojo.validation.test.impl.GetterTester;
import com.openpojo.validation.test.impl.SetterTester;
+import com.openpojo.validation.utils.ValidationHelper;
+import org.hamcrest.Matcher;
import org.junit.jupiter.api.Test;
-import org.onap.policy.common.utils.test.ToStringTester;
/**
* Class to perform unit test of HealthCheckReport.
validator.validate(HealthCheckReport.class.getPackage().getName(),
new FilterClassName(HealthCheckReport.class.getName()));
}
+
+ static class ToStringTester implements Tester {
+
+ private final Matcher<?> matcher;
+
+ public ToStringTester() {
+ matcher = anything();
+ }
+
+ @Override
+ public void run(final PojoClass pojoClass) {
+ final Class<?> clazz = pojoClass.getClazz();
+ if (anyOf(matcher).matches(clazz)) {
+ final Object classInstance = ValidationHelper.getBasicInstance(pojoClass);
+
+ Affirm.affirmFalse("Found default toString output",
+ classInstance.toString().matches(Object.class.getName() + "@" + "\\w+"));
+ }
+
+ }
+ }
}
normalizePath(resultD2.iterator().next()));
Set<String> resultJ0 = ResourceUtils.getDirectoryContents("com");
- assertTrue(resultJ0.contains("com/google/gson/"));
+ assertTrue(resultJ0.contains("com/google/"));
assertEquals("com/google/", normalizePath(resultJ0.iterator().next()));
Set<String> resultJ1 = ResourceUtils.getDirectoryContents("com/google/gson");