* ONAP-Logging
* ================================================================================
* Copyright (C) 2017-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.
if (obj == null) {
return false;
}
- if (obj instanceof String) {
- String otherRequestId = (String) obj;
+ if (obj instanceof String otherRequestId) {
return requestId != null && requestId.equals(otherRequestId);
}
if (getClass() != obj.getClass()) {
* ONAP-Logging
* ================================================================================
* Copyright (C) 2017-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.
/**
* FlexLogger acts as factory to generate instances of Logger based on logger type.
*/
-public class FlexLogger extends SecurityManager {
+public class FlexLogger {
private static final String GET_LOGGER_PREFIX = "FlexLogger:getLogger : loggerType = ";
private static LoggerType loggerType = LoggerType.EELF;
* Returns the calling class name.
*/
public String getClassName() {
- displayMessage("getClassContext()[3].getName() " + getClassContext()[3].getName());
- return getClassContext()[3].getName();
+ StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
+ if (stackTrace.length > 3) {
+ return stackTrace[3].getClassName();
+ }
+ return "UnknownClass";
}
/**
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertSame;
-import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import org.junit.jupiter.api.Test;
* ONAP
* ================================================================================
* Copyright (C) 2020-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.
return true;
}
- BeanValidationResult result2 = (value instanceof ParameterGroup ? ((ParameterGroup) value).validate()
+ BeanValidationResult result2 = (value instanceof ParameterGroup parameterGroup ? parameterGroup.validate()
: validateTop(fieldName, value));
if (result2.isClean()) {
private List<Data> listField;
@Test
- public void testAddToTree() throws Exception {
+ void testAddToTree() throws Exception {
ser = new FieldSerializer(gson, FieldSerializerTest.class.getDeclaredField(TEXT_FIELD_NAME));
// serialize null value first
* Integrity Monitor
* ================================================================================
* Copyright (C) 2017-2018, 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.
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
-import jakarta.persistence.NamedQueries;
import jakarta.persistence.NamedQuery;
import jakarta.persistence.Table;
import java.io.Serial;
@SuppressWarnings("rawtypes")
List resourceList = query.getResultList();
if (resourceList.isEmpty()) {
- logger.debug("Record not found, resourceName: " + resourceName);
+ logger.debug("Record not found, resourceName: {}", resourceName);
fail("missing record");
}
assertEquals(StateManagement.HOT_STANDBY, sme1.getStandbyStatus());
logger.debug("--");
} else {
- logger.debug("Record not found, resourceName: " + resourceName);
+ logger.debug("Record not found, resourceName: {}", resourceName);
fail("record not found");
}
}
@Test
- void testJpa() throws Exception {
+ void testJpa() {
logger.debug("\n??? logger.infor StateManagementEntityTest: Entering\n\n");
// Define the resourceName for the StateManagement constructor
logger.info("\n\nStateManagementTest: Exit\n\n");
}
- private void test_1(final StateManagement sm) throws StateManagementException, IntegrityMonitorException {
+ private void test_1(final StateManagement sm) throws IntegrityMonitorException {
logger.info("\n??? initial state");
assertEquals(UNLOCKED_ENABLED_NULL_NULL, makeString(sm));
assertEquals(UNLOCKED_ENABLED_NULL_HOTSTANDBY, makeString(sm2));
}
- private void test_2(final StateManagement sm) throws StateManagementException, IntegrityMonitorException {
+ private void test_2(final StateManagement sm) throws IntegrityMonitorException {
// D3 If demote() is called while standbyStatus is null and
// adminState is locked or opState is disabled,
// the state shall transition to coldstandby
@Test
@SuppressWarnings("unchecked")
- void test_StateManagementInitialization_ThrowException_ifEntityManagerCreateQuerythrowsAnyException()
- throws Exception {
+ void test_StateManagementInitialization_ThrowException_ifEntityManagerCreateQuerythrowsAnyException() {
assertThatThrownBy(() -> {
final EntityManager mockedEm = getMockedEntityManager();
final EntityManagerFactory mockedEmf = getMockedEntityManagerFactory(mockedEm);
@Test
@SuppressWarnings("unchecked")
- void test_StateManagementInitialization_ThrowStateManagementException_ifEntityManagerThrowsAnyException()
- throws Exception {
+ void test_StateManagementInitialization_ThrowStateManagementException_ifEntityManagerThrowsAnyException() {
assertThatThrownBy(() -> {
final EntityManager mockedEm = getMockedEntityManager();
final EntityManagerFactory mockedEmf = getMockedEntityManagerFactory(mockedEm);
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-core</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-junit-jupiter</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file
* ONAP
* ================================================================================
* 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.
import java.util.Arrays;
import java.util.Date;
import java.util.concurrent.TimeUnit;
-import java.util.stream.Collectors;
import lombok.Getter;
import org.bouncycastle.asn1.x500.X500Name;
import org.bouncycastle.asn1.x509.Extension;
* @throws IOException if an I/O error occurs
* @throws InterruptedException if an interrupt occurs
*/
- public SelfSignedKeyStore() throws IOException, InterruptedException {
+ public SelfSignedKeyStore() throws IOException {
this(RELATIVE_PATH);
}
* @throws IOException if an I/O error occurs
* @throws InterruptedException if an interrupt occurs
*/
- public SelfSignedKeyStore(String relativePath) throws IOException, InterruptedException {
+ public SelfSignedKeyStore(String relativePath) throws IOException {
keystoreName = System.getProperty("user.dir") + "/" + relativePath;
// use existing file if it isn't too old
@Test
void testRoundTrip() throws Exception {
- MyObject obj1 = new MyObject(3);
+ MyObject obj1 = new MyObject(4);
MyObject obj2 = Serializer.roundTrip(obj1);
assertEquals(obj1.value, obj2.value);
}
@Test
- public void testSelfSignedKeyStore() throws Exception {
+ void testSelfSignedKeyStore() throws Exception {
SelfSignedKeyStore ks = new SelfSignedKeyStore();
assertThat(ks.getKeystoreName()).isEqualTo(defaultName);
}
@Test
- public void testSelfSignedKeyStoreString() throws IOException, InterruptedException {
+ void testSelfSignedKeyStoreString() throws IOException, InterruptedException {
String relName = "target/my-keystore";
String altName = saveUserDir + "/" + relName;
File altFile = new File(altName);
* Tests the constructor, when the keystore already exists.
*/
@Test
- public void testSelfSignedKeyStoreStringExists() throws Exception {
+ void testSelfSignedKeyStoreStringExists() throws Exception {
new SelfSignedKeyStore();
assertThat(defaultKeystore).exists();
* Tests the constructor, when the SAN file is not found.
*/
@Test
- public void testSelfSignedKeyStoreStringNoSanFile() {
+ void testSelfSignedKeyStoreStringNoSanFile() {
assertThatThrownBy(() -> new SelfSignedKeyStore() {
@Override
protected String getKeystoreSanName() {
* Tests the constructor, when write fails.
*/
@Test
- public void testSelfSignedKeyStoreStringWriteFailure() {
+ void testSelfSignedKeyStoreStringWriteFailure() {
assertThatThrownBy(() -> new SelfSignedKeyStore("target/unknown/path/to/keystore"))
.isInstanceOf(IOException.class);
}
@Test
- public void testGetKeystoreName() throws Exception {
+ void testGetKeystoreName() throws Exception {
String relpath = SelfSignedKeyStore.RELATIVE_PATH;
// append the first part of the relative path to user.dir
}
@Test
- void testDestroy() throws InterruptedException {
+ void testDestroy() {
// this won't interrupt
multi.enqueue(new WorkItem(multi, DELAY_MS));
}
@Test
- void testWaitUntilCallable() throws InterruptedException {
+ void testWaitUntilCallable() {
multi.enqueue(new WorkItem(multi, DELAY_MS));
multi.enqueue(new WorkItem(multi, DELAY_MS * 2));
multi.enqueue(new WorkItem(multi, DELAY_MS * 3));
}
@Test
- void testWaitUntilCallable_ConditionThrowsEx() throws InterruptedException {
+ void testWaitUntilCallable_ConditionThrowsEx() {
multi = new TestTimeMulti();
Callable<Boolean> callable = () -> {
}
@Test
- void testWaitUntilCallable_NeverSatisfied() throws InterruptedException {
+ void testWaitUntilCallable_NeverSatisfied() {
multi = new TestTimeMulti(SHORT_WAIT_MS);
final long realBegin = System.currentTimeMillis();
}
@Test
- void testWaitUntilLongTimeUnitCallable() throws InterruptedException {
+ void testWaitUntilLongTimeUnitCallable() {
multi.enqueue(new WorkItem(multi, DELAY_MS));
multi.enqueue(new WorkItem(multi, DELAY_MS * 2));
multi.enqueue(new WorkItem(multi, DELAY_MS * 3));
}
@Test
- void testWaitUntilLongTimeUnitCallable_PseudoTimeExpires() throws InterruptedException {
+ void testWaitUntilLongTimeUnitCallable_PseudoTimeExpires() {
multi.enqueue(new WorkItem(multi, DELAY_MS));
multi.enqueue(new WorkItem(multi, DELAY_MS * 2));
multi.enqueue(new WorkItem(multi, DELAY_MS * 3));
import org.junit.jupiter.api.Test;
-public class TestTimeTest {
+class TestTimeTest {
@Test
- public void test() throws Exception {
+ void test() throws Exception {
TestTime tm = new TestTime();
TestTime tm2 = new TestTime();
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-public class WorkItemTest {
+class WorkItemTest {
private TestTime currentTime;
private WorkItem item;
}
@Test
- public void testWorkItem() {
+ void testWorkItem() {
assertThatIllegalArgumentException().isThrownBy(() -> new WorkItem(currentTime, -1));
// should not throw an exception
}
@Test
- public void testGetDelay() {
+ void testGetDelay() {
assertEquals(1, item.getDelay());
}
@Test
- public void testWasCancelled() {
+ void testWasCancelled() {
assertFalse(item.wasCancelled());
}
@Test
- public void testBumpNextTime() {
+ void testBumpNextTime() {
assertFalse(item.bumpNextTime());
}
@Test
- public void testBumpNextTimeLong() {
+ void testBumpNextTimeLong() {
assertThatIllegalArgumentException().isThrownBy(() -> item.bumpNextTime(-1));
long cur = currentTime.getMillis();
}
@Test
- public void testInterrupt() {
+ void testInterrupt() {
item.interrupt();
assertFalse(Thread.interrupted());
}
@Test
- public void testIsAssociatedWith() {
+ void testIsAssociatedWith() {
assertFalse(item.isAssociatedWith(this));
}
@Test
- public void testFire() {
+ void testFire() {
// ensure no exception is thrown
assertThatCode(() -> item.fire()).doesNotThrowAnyException();
}
@Test
- public void testGetNextMs() {
+ void testGetNextMs() {
assertEquals(currentTime.getMillis() + 1, item.getNextMs());
assertEquals(currentTime.getMillis() + 10, new WorkItem(currentTime, 10).getNextMs());
}
* 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.
* @return a gson element corresponding to the node
*/
protected JsonElement makeJson(Node node) {
- if (node instanceof MappingNode) {
- return makeJsonObject((MappingNode) node);
+ if (node instanceof MappingNode mappingNode) {
+ return makeJsonObject(mappingNode);
- } else if (node instanceof SequenceNode) {
- return makeJsonArray((SequenceNode) node);
+ } else if (node instanceof SequenceNode sequenceNode) {
+ return makeJsonArray(sequenceNode);
} else {
return makeJsonPrim((ScalarNode) node);
}
@Test
- void testToJsonTree_testFromJsonJsonElementClassT() throws Exception {
+ void testToJsonTree_testFromJsonJsonElementClassT() {
MyMap map = new MyMap();
map.props = new LinkedHashMap<>();
map.props.put("jel keyA", "jel valueA");
}
@Test
- void testStandardTypeAdapter() throws Exception {
+ void testStandardTypeAdapter() {
String json = "{'abc':'def'}".replace('\'', '"');
StandardCoderObject sco = coder.fromJson(json, StandardCoderObject.class);
assertNotNull(sco.getData());
}
@Test
- void testStandardTypeAdapter() throws Exception {
+ void testStandardTypeAdapter() {
String yaml = "abc: def\n";
StandardCoderObject sco = coder.fromJson(yaml, StandardCoderObject.class);
assertNotNull(sco.getData());
@Test
@SuppressWarnings("unchecked")
- void testCompressLists() throws IOException, CoderException {
+ void testCompressLists() throws CoderException {
assertEquals("plain-string", PropertyObjectUtils.compressLists("plain-string").toString());
// @formatter:off
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import java.security.GeneralSecurityException;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static final String ENCRYPTED_MSG = "original value : {} encrypted value: {}";
@Test
- void testEncrypt() throws GeneralSecurityException {
+ void testEncrypt() {
logger.info("testEncrypt:");
CryptoCoder cryptoUtils = new CryptoUtils(SECRET_KEY);
String encryptedValue = cryptoUtils.encrypt(PASS);
}
@Test
- void testDecrypt() throws GeneralSecurityException {
+ void testDecrypt() {
logger.info("testDecrypt:");
CryptoCoder cryptoUtils = new CryptoUtils(SECRET_KEY);
String decryptedValue = cryptoUtils.decrypt(ENCRYPTED_PASS);