* ONAP
* ================================================================================
* Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2024 Nordix Foundation
+ * Modifications Copyright (C) 2024-2025 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
validator.validateValue(result, MY_FIELD, null);
assertThat(result.getResult()).isNull();
- validator.addAnnotation(NotNull.class,
- (result2, fieldName, value) -> result2.validateNotNull(fieldName, value));
+ validator.addAnnotation(NotNull.class, BeanValidationResult::validateNotNull);
validator.validateValue(result, MY_FIELD, null);
assertThat(result.getResult()).contains(MY_FIELD, "null");
}
validator.validateValue(result, MY_FIELD, HELLO);
assertThat(result.getResult()).isNull();
- validator.addAnnotation(NotNull.class,
- (result2, fieldName, value) -> result2.validateNotNull(fieldName, value));
+ validator.addAnnotation(NotNull.class, BeanValidationResult::validateNotNull);
validator.validateValue(result, MY_FIELD, HELLO);
assertThat(result.getResult()).isNull();
}
assertThat(validator.isNullAllowed()).isTrue();
// "null" flag should become false with this annotation
- assertThat(validator.isNullAllowed()).isTrue();
validator.addAnnotation(NotNull.class, (result2, fieldName, value) -> true);
assertThat(validator.isNullAllowed()).isFalse();
}
// the field DOES have this annotation
validator.addAnnotation(NotNull.class, (result2, fieldName, annot, value) -> {
- wasNull.set(annot instanceof NotNull);
+ wasNull.set(annot != null);
return result2.validateNotNull(fieldName, value);
});
assertThat(validator.isEmpty()).isFalse();
* ONAP
* ================================================================================
* Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2023-2024 Nordix Foundation.
+ * Modifications Copyright (C) 2023-2025 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
// use a derived type, but specify the base type when reading
@SuppressWarnings("rawtypes")
- Class clazz = new MyObject() {}.getClass();
+ Class clazz = MyObject.class;
@SuppressWarnings("unchecked")
Class<Object> objclazz = clazz;
* ONAP
* ================================================================================
* Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
- * Modificaitons Copyright (C) 2023-2024 Nordix Foundation.
+ * Modificaitons Copyright (C) 2023-2025 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.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
+import java.io.Serial;
import java.lang.reflect.GenericArrayType;
import java.util.LinkedList;
import java.util.TreeMap;
+import lombok.Getter;
+import lombok.Setter;
import lombok.ToString;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
// generic classes should NOT be managed
Class<?>[] unmanaged = {
- new Data[0].getClass(), Enum.class, boolean.class, byte.class, short.class, int.class,
+ Data[].class, Enum.class, boolean.class, byte.class, short.class, int.class,
long.class, float.class, double.class, char.class, Boolean.class, Byte.class, Short.class,
Integer.class, Long.class, Float.class, Double.class, Character.class, String.class,
MyMap.class, MyList.class, MyJson.class, GenericArrayType.class};
/**
* Used to verify that no fields are exposed.
*/
+ @Getter
+ @Setter
@ToString
public static class Data {
private int id;
public String text;
- public int getId() {
- return id;
- }
-
void setId(int id) {
this.id = id;
}
- public String getText() {
- return text;
- }
-
void setText(String text) {
this.text = text;
}
}
+ @Getter
@ToString(callSuper = true)
public static class Derived extends Data {
protected String value;
- public String getValue() {
- return value;
- }
-
void setValue(String value) {
this.value = value;
}
/**
* Used to verify that enums are not managed.
*/
- public static enum Enum {
+ public enum Enum {
UP, DOWN,
}
/**
* Used to verify that interfaces <i>are</i> managed.
*/
- public static interface Intfc {
+ public interface Intfc {
int getId();
}
/**
* Used to verify that Maps are not managed.
*/
+ @Getter
public static class MyMap extends TreeMap<String, Data> {
+ @Serial
private static final long serialVersionUID = 1L;
private int mapId;
- public int getMapId() {
- return mapId;
- }
}
/**
* Used to verify that Collections are not managed.
*/
public static class MyList extends LinkedList<Data> {
+ @Serial
private static final long serialVersionUID = 1L;
}
* ONAP
* ================================================================================
* Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2024 Nordix Foundation.
+ * Modifications Copyright (C) 2024-2025 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 static org.mockito.Mockito.when;
import java.util.Arrays;
+import java.util.List;
import java.util.Properties;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
lenient().when(source.offer(anyString())).thenReturn(true);
lenient().when(source.getTopicCommInfrastructure()).thenReturn(SOURCE_INFRA);
- lenient().when(endpoint.getTopicSinks(anyString())).thenReturn(Arrays.asList());
- lenient().when(endpoint.getTopicSinks(SINK_TOPIC)).thenReturn(Arrays.asList(sink));
+ lenient().when(endpoint.getTopicSinks(anyString())).thenReturn(List.of());
+ lenient().when(endpoint.getTopicSinks(SINK_TOPIC)).thenReturn(List.of(sink));
- lenient().when(endpoint.getTopicSources(any())).thenReturn(Arrays.asList());
- lenient().when(endpoint.getTopicSources(Arrays.asList(SOURCE_TOPIC))).thenReturn(Arrays.asList(source));
+ lenient().when(endpoint.getTopicSources(any())).thenReturn(List.of());
+ lenient().when(endpoint.getTopicSources(List.of(SOURCE_TOPIC))).thenReturn(List.of(source));
theMessage = new MyMessage(MY_TEXT);
.hasMessage("no sources for topic: unknown-source");
// too many sources
- when(endpoint.getTopicSources(Arrays.asList(SOURCE_TOPIC))).thenReturn(Arrays.asList(source, source));
+ when(endpoint.getTopicSources(List.of(SOURCE_TOPIC))).thenReturn(Arrays.asList(source, source));
assertThatThrownBy(() -> new BidirectionalTopicClient2(SINK_TOPIC, SOURCE_TOPIC))
.isInstanceOf(BidirectionalTopicClientException.class)
@Override
public boolean send(String messageText) {
- boolean result = super.send(messageText);
+ boolean messageSent = super.send(messageText);
sendSem.release();
- return result;
+ return messageSent;
}
@Override
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019, 2024 Nordix Foundation.
+ * Copyright (C) 2019, 2024-2025 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
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;
* ONAP
* ================================================================================
* Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2024 Nordix Foundation
+ * Modifications Copyright (C) 2024-2025 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* For "pass", the encrypted value was generated via:
* java org.onap.policy.common.utils.security.CryptoUtils enc hello abcdefghijklmnopqrstuvwxyzabcdef
*/
- private static final String json =
+ private static final String JSON =
("{'aes_encryption_key':'abcdefghijklmnopqrstuvwxyzabcdef'"
+ ",'xacml.pdp.rest.password':'enc:FSfOhDygtmnX3gkMSfTFMoBFW+AG5k6goNj2KZgQmeF0DqgcMg=='"
+ ",'xacml.pdp.rest.user':'testpdp'"
@Test
void testPropertyCoder() {
- MyClass data = propertyCoder.decode(json, AES_ENCRYPTION_KEY, MyClass.class);
+ MyClass data = propertyCoder.decode(JSON, AES_ENCRYPTION_KEY, MyClass.class);
assertEquals("alpha", data.getPdpRestPass());
assertEquals("hello", data.servers.get(0).pass);
assertEquals("server1", data.servers.get(0).name);
@Test
void testPropertyCoderReader() {
- Reader reader = new StringReader(json);
+ Reader reader = new StringReader(JSON);
MyClass data = propertyCoder.decode(reader, AES_ENCRYPTION_KEY, MyClass.class);
assertEquals("alpha", data.getPdpRestPass());
assertEquals("hello", data.servers.get(0).pass);
* ONAP
* ================================================================================
* Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2024 Nordix Foundation
+ * Modifications Copyright (C) 2024-2025 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
private static final String PROP1 = "abc";
private static final String PROP2 = "ghi";
private static final Integer PROP2_INDEX = 1;
- private static final String PROP2b = "jkl";
+ private static final String PROP_2_B = "jkl";
private static final String VAL1 = "def";
private static final String VAL2 = "mno";
private static final String JSON = "{'abc':'def','ghi':[{},{'jkl':'mno'}]}".replace('\'', '"');
assertEquals(VAL1, sco.getString(PROP1));
// multiple fields
- assertEquals(VAL2, sco.getString(PROP2, PROP2_INDEX, PROP2b));
+ assertEquals(VAL2, sco.getString(PROP2, PROP2_INDEX, PROP_2_B));
// not found
assertNull(sco.getString("xyz"));
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2024 Nordix Foundation
+ * Modifications Copyright (C) 2024-2025 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@Test
void testValidateIntParameter() {
assertTrue(ParameterValidationUtils.validateIntParameter(5555));
- assertTrue(ParameterValidationUtils.validateIntParameter(Integer.valueOf(7777)));
assertFalse(ParameterValidationUtils.validateIntParameter(0));
assertFalse(ParameterValidationUtils.validateIntParameter(-1));
}
@Test
void testValidateLongParameter() {
assertTrue(ParameterValidationUtils.validateLongParameter(5555L));
- assertTrue(ParameterValidationUtils.validateLongParameter(Long.valueOf(7777L)));
assertFalse(ParameterValidationUtils.validateLongParameter(0L));
assertFalse(ParameterValidationUtils.validateLongParameter(-1L));
}