* ONAP Policy Engine - Common Modules
* ================================================================================
* 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.
package org.onap.policy.common.logging.eelf;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import com.att.eelf.configuration.Configuration;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class DroolsPdpMdcInfoTest {
+class DroolsPdpMdcInfoTest {
/**
* Test method for {@link org.onap.policy.common.logging.eelf.DroolsPdpMdcInfo#getMdcInfo()}.
*/
@Test
- public void testGetMdcInfo() {
+ void testGetMdcInfo() {
DroolsPdpMdcInfo di = new DroolsPdpMdcInfo();
assertNotNull(di.getMdcInfo());
* ================================================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2020 AT&T.
+ * 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.logging.eelf;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.logging.eelf.ErrorCodeMap.ErrorCodeInfo;
-public class ErrorCodeMapTest {
+class ErrorCodeMapTest {
@Test
- public void testGetErrorCodeInfo() {
+ void testGetErrorCodeInfo() {
assertNotNull(ErrorCodeMap.getErrorCodeInfo(MessageCodes.EXCEPTION_ERROR));
assertNotNull(ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR));
assertNotNull(ErrorCodeMap.getErrorCodeInfo(MessageCodes.MISS_PROPERTY_ERROR));
}
@Test
- public void testErrorCodeInfoGetErrorCode() {
+ void testErrorCodeInfoGetErrorCode() {
ErrorCodeInfo errorCodeInfo = ErrorCodeMap.getErrorCodeInfo(MessageCodes.EXCEPTION_ERROR);
assertEquals("500", errorCodeInfo.getErrorCode());
}
@Test
- public void testErrorCodeInfoGetErrorDesc() {
+ void testErrorCodeInfoGetErrorDesc() {
ErrorCodeInfo errorCodeInfo = ErrorCodeMap.getErrorCodeInfo(MessageCodes.EXCEPTION_ERROR);
assertEquals("This is an exception error message during the process. Please check the error message for detail "
+ "information", errorCodeInfo.getErrorDesc());
* ONAP Policy Engine - Common Modules
* ================================================================================
* 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.
package org.onap.policy.common.logging.eelf;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
import java.time.Instant;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class EventDataTest {
+class EventDataTest {
private static final Instant istart = Instant.ofEpochMilli(100000L);
private static final Instant iend = Instant.ofEpochMilli(200000L);
* Test method for {@link EventData#EventData()}.
*/
@Test
- public void testEventData() {
+ void testEventData() {
EventData eventData = new EventData();
assertNull(eventData.getEndTime());
* Test method for {@link EventData#EventData(String, Instant, Instant)}.
*/
@Test
- public void testEventDataStringInstantInstant() {
+ void testEventDataStringInstantInstant() {
EventData eventData = new EventData("myreq", istart, iend);
assertEquals("myreq", eventData.getRequestId());
* Test method for {@link EventData#getRequestId()} and {@link EventData#setRequestId(String)}.
*/
@Test
- public void testGetSetRequestId() {
+ void testGetSetRequestId() {
EventData eventData = new EventData();
assertNull(eventData.getRequestId());
* Test method for {@link EventData#getStartTime()} and {@link EventData#setStartTime(Instant)}.
*/
@Test
- public void testGetSetStartTime() {
+ void testGetSetStartTime() {
EventData eventData = new EventData();
assertNull(eventData.getStartTime());
* Test method for {@link EventData#getEndTime()} and {@link EventData#setEndTime(Instant)}.
*/
@Test
- public void testGetSetEndTime() {
+ void testGetSetEndTime() {
EventData eventData = new EventData();
assertNull(eventData.getEndTime());
* Test method for {@link EventData#toString()}.
*/
@Test
- public void testToString() {
+ void testToString() {
EventData eventData = new EventData("myreq", istart, iend);
assertEquals("myreq Starting Time : 1970-01-01T00:01:40Z Ending Time : 1970-01-01T00:03:20Z",
eventData.toString());
* Test method for {@link EventData#hashCode()}.
*/
@Test
- public void testHashCode() {
+ void testHashCode() {
int hc1 = new EventData("abc", istart, iend).hashCode();
assertNotEquals(hc1, new EventData("abd", istart, iend).hashCode());
* Test method for {@link EventData#equals(Object)}.
*/
@Test
- public void testEqualsObject() {
+ void testEqualsObject() {
final EventData d1 = new EventData("abc", istart, iend);
final EventData d2 = new EventData("abd", istart, iend);
final EventData d3 = new EventData("abc", iend, istart);
assertEquals(d1, d1);
// compare with null
- assertNotEquals(d1, null);
+ assertNotEquals(null, d1);
// compare with request id
// note: ignoring sonar because we want to test d1.equals(), not "abc".equals()
assertEquals(d1, "abc"); // NOSONAR
- assertNotEquals(d1, "abd");
+ assertNotEquals("abd", d1);
// compare with int - different class type
- assertNotEquals(d1, 10);
+ assertNotEquals(10, d1);
// "this" has null request id
assertNotEquals(new EventData(), d1);
* ONAP Policy Engine - Common Modules
* ================================================================================
* 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.
package org.onap.policy.common.logging.eelf;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.time.Instant;
import java.util.concurrent.ConcurrentMap;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
-public class EventTrackInfoHandlerTest {
+class EventTrackInfoHandlerTest {
private static final Instant inow = Instant.now();
private static final Instant iexpired = Instant.ofEpochMilli(10000L);
private EventTrackInfoHandler hdlr;
- @BeforeClass
+ @BeforeAll
public static void setUpBeforeClass() {
tracker = PolicyLogger.getEventTracker();
info = tracker.getEventInfo();
/**
* Perform set up for test cases.
*/
- @Before
- public void setUp() {
+ @BeforeEach
+ void setUp() {
info.clear();
hdlr = new EventTrackInfoHandler();
}
@Test
- public void testNoEvents() {
+ void testNoEvents() {
hdlr.run();
assertEquals(0, info.size());
}
@Test
- public void testNothingExpired() {
+ void testNothingExpired() {
tracker.storeEventData(data1);
tracker.storeEventData(data2);
}
@Test
- public void testSomeExpired() {
+ void testSomeExpired() {
// not expired
tracker.storeEventData(data1);
tracker.storeEventData(data2);
}
@Test
- public void testMultipleRuns() {
+ void testMultipleRuns() {
hdlr.run();
assertEquals(0, info.size());
* ONAP Policy Engine - Common Modules
* ================================================================================
* 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.
package org.onap.policy.common.logging.eelf;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.time.Instant;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
-public class EventTrackInfoTest {
+class EventTrackInfoTest {
private static final Instant istart = Instant.ofEpochMilli(100000L);
private static final Instant iend = Instant.ofEpochMilli(200000L);
private EventTrackInfo info;
- @Before
- public void setUp() {
+ @BeforeEach
+ void setUp() {
info = new EventTrackInfo();
}
* Test method for {@link EventTrackInfo#EventTrackInfo()}.
*/
@Test
- public void testEventTrackInfo() {
+ void testEventTrackInfo() {
assertNotNull(info.getEventInfo());
}
* Test method for {@link EventTrackInfo#getEventDataByRequestId(String)}.
*/
@Test
- public void testGetEventDataByRequestId() {
+ void testGetEventDataByRequestId() {
info.storeEventData(data1);
info.storeEventData(data2);
* Test method for {@link EventTrackInfo#storeEventData(EventData)}.
*/
@Test
- public void testStoreEventData() {
+ void testStoreEventData() {
// should ignore null
info.storeEventData(null);
assertTrue(info.getEventInfo().isEmpty());
* Test method for {@link EventTrackInfo#remove(String)}.
*/
@Test
- public void testRemove() {
+ void testRemove() {
info.storeEventData(data1);
info.storeEventData(data2);
* Test method for {@link EventTrackInfo#getEventInfo()}.
*/
@Test
- public void testGetEventInfo() {
+ void testGetEventInfo() {
info.storeEventData(data1);
info.storeEventData(data2);
* ================================================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2019-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.
import static com.att.eelf.configuration.Configuration.MDC_SERVICE_INSTANCE_ID;
import static com.att.eelf.configuration.Configuration.MDC_SERVICE_NAME;
import static org.assertj.core.api.Assertions.assertThatCode;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+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.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.never;
import static org.onap.policy.common.logging.eelf.OnapConfigProperties.PARTNER_NAME;
import static org.onap.policy.common.logging.eelf.OnapConfigProperties.RESPONSE_CODE;
import java.time.Instant;
import java.util.Properties;
import java.util.UUID;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.slf4j.MDC;
import org.springframework.test.util.ReflectionTestUtils;
-public class PolicyLoggerTest {
+class PolicyLoggerTest {
/**
* Perform set up for test cases.
*/
- @Before
- public void setUp() {
+ @BeforeEach
+ void setUp() {
Properties properties = new Properties();
properties.setProperty("policy.component", "XACML");
PolicyLogger.init(properties);
}
@Test
- public void testSetAndGetDebugLevelLevel() {
+ void testSetAndGetDebugLevelLevel() {
PolicyLogger.setDebugLevel(Level.INFO);
assertEquals(Level.INFO, PolicyLogger.getDebugLevel());
PolicyLogger.setDebugLevel(Level.DEBUG);
}
@Test
- public void testSetAndGetAuditLevelLevel() {
+ void testSetAndGetAuditLevelLevel() {
PolicyLogger.setAuditLevel(Level.INFO);
assertEquals(Level.INFO, PolicyLogger.getAuditLevel());
PolicyLogger.setAuditLevel(Level.DEBUG);
}
@Test
- public void testSetAndGetMetricsLevelLevel() {
+ void testSetAndGetMetricsLevelLevel() {
PolicyLogger.setMetricsLevel(Level.INFO);
assertEquals(Level.INFO, PolicyLogger.getMetricsLevel());
PolicyLogger.setMetricsLevel(Level.DEBUG);
}
@Test
- public void testSetAndGetErrorLevelLevel() {
+ void testSetAndGetErrorLevelLevel() {
PolicyLogger.setErrorLevel(Level.INFO);
assertEquals(Level.INFO, PolicyLogger.getErrorLevel());
PolicyLogger.setErrorLevel(Level.DEBUG);
}
@Test
- public void testSetAndGetClassname() {
+ void testSetAndGetClassname() {
assertEquals("ClassName", PolicyLogger.getClassname());
PolicyLogger.setClassname("PolicyLoggerTest");
assertEquals("PolicyLoggerTest", PolicyLogger.getClassname());
}
@Test
- public void testPostMdcInfoForEventString() {
+ void testPostMdcInfoForEventString() {
PolicyLogger.postMdcInfoForEvent("transactionId");
assertEquals("", MDC.get(MDC_REMOTE_HOST));
}
@Test
- public void testPostMdcInfoForEventStringDrools() {
+ void testPostMdcInfoForEventStringDrools() {
Properties properties = new Properties();
properties.setProperty("policy.component", "DROOLS");
PolicyLogger.init(properties);
}
@Test
- public void testSetAndGetTransId() {
+ void testSetAndGetTransId() {
PolicyLogger.setTransId("123456");
assertEquals("123456", PolicyLogger.getTransId());
}
@Test
- public void testPostMdcInfoForEventObject() {
+ void testPostMdcInfoForEventObject() {
PolicyLogger.postMdcInfoForEvent(1);
assertEquals("", MDC.get(MDC_REMOTE_HOST));
}
@Test
- public void testPostMdcInfoForTriggeredRule() {
+ void testPostMdcInfoForTriggeredRule() {
PolicyLogger.postMdcInfoForTriggeredRule("transactionId");
assertEquals("", MDC.get(MDC_REMOTE_HOST));
}
@Test
- public void testPostMdcUuidForTriggeredRule() {
+ void testPostMdcUuidForTriggeredRule() {
PolicyLogger.postMdcUuidForTriggeredRule(1);
assertEquals("", MDC.get(MDC_REMOTE_HOST));
}
@Test
- public void testInfoMessageCodesStringStringArray() {
+ void testInfoMessageCodesStringStringArray() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.info(MessageCodes.ERROR_DATA_ISSUE, "str1", "str2");
}
@Test
- public void testInfoStringString() {
+ void testInfoStringString() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.info("str1", "str2");
}
@Test
- public void testInfoObject() {
+ void testInfoObject() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.info("str1");
}
@Test
- public void testInfoMessageCodesThrowableStringArray() {
+ void testInfoMessageCodesThrowableStringArray() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.info(MessageCodes.ERROR_DATA_ISSUE, new NullPointerException(), "str1", "str2");
}
@Test
- public void testInfoMessageCodesStringThrowableStringArray() {
+ void testInfoMessageCodesStringThrowableStringArray() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.info(MessageCodes.ERROR_DATA_ISSUE, "PolicyLoggerTest", new NullPointerException(), "str1",
}
@Test
- public void testWarnMessageCodesStringStringArray() {
+ void testWarnMessageCodesStringStringArray() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.warn(MessageCodes.ERROR_DATA_ISSUE, "str1");
}
@Test
- public void testWarnStringString() {
+ void testWarnStringString() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.warn("str1", "str2");
}
@Test
- public void testWarnObject() {
+ void testWarnObject() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.warn(1);
}
@Test
- public void testWarnMessageCodesThrowableStringArray() {
+ void testWarnMessageCodesThrowableStringArray() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.warn(MessageCodes.ERROR_DATA_ISSUE, new NullPointerException(), "str1", "str2");
}
@Test
- public void testWarnMessageCodesStringThrowableStringArray() {
+ void testWarnMessageCodesStringThrowableStringArray() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.warn(MessageCodes.ERROR_DATA_ISSUE, "PolicyLoggerTest", new NullPointerException(), "str1",
}
@Test
- public void testWarnString() {
+ void testWarnString() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.warn("str1");
}
@Test
- public void testErrorStringString() {
+ void testErrorStringString() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "errorLogger", mockLogger);
PolicyLogger.error("str1", "str2");
}
@Test
- public void testErrorString() {
+ void testErrorString() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "errorLogger", mockLogger);
PolicyLogger.error("str1");
}
@Test
- public void testErrorObject() {
+ void testErrorObject() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "errorLogger", mockLogger);
PolicyLogger.error(1);
}
@Test
- public void testErrorMessageCodesThrowableStringArray() {
+ void testErrorMessageCodesThrowableStringArray() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "errorLogger", mockLogger);
PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, new NullPointerException(), "str1", "str2");
}
@Test
- public void testErrorMessageCodesStringThrowableStringArray() {
+ void testErrorMessageCodesStringThrowableStringArray() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "errorLogger", mockLogger);
PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "PolicyLoggerTest", new NullPointerException(), "str1",
}
@Test
- public void testErrorMessageCodesStringArray() {
+ void testErrorMessageCodesStringArray() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "errorLogger", mockLogger);
PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "str1", "str2");
}
@Test
- public void testDebugMessageCodesStringArray() {
+ void testDebugMessageCodesStringArray() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.debug(MessageCodes.ERROR_DATA_ISSUE, "str1", "str2");
}
@Test
- public void testDebugStringString() {
+ void testDebugStringString() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.debug("str1", "str2");
}
@Test
- public void testDebugString() {
+ void testDebugString() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.debug("str1");
}
@Test
- public void testDebugObject() {
+ void testDebugObject() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.debug(1);
}
@Test
- public void testAuditStringObject() {
+ void testAuditStringObject() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "auditLogger", mockLogger);
PolicyLogger.audit("PolicyLoggerTest", 1);
}
@Test
- public void testAuditObject() {
+ void testAuditObject() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "auditLogger", mockLogger);
PolicyLogger.audit(1);
}
@Test
- public void testDebugMessageCodesThrowableStringArray() {
+ void testDebugMessageCodesThrowableStringArray() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.debug(MessageCodes.ERROR_DATA_ISSUE, new NullPointerException(), "str1", "str2");
}
@Test
- public void testDebugMessageCodesStringThrowableStringArray() {
+ void testDebugMessageCodesStringThrowableStringArray() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.debug(MessageCodes.ERROR_DATA_ISSUE, "PolicyLoggerTest", new NullPointerException(), "str1",
}
@Test
- public void testIsDebugEnabled() {
+ void testIsDebugEnabled() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
Mockito.when(mockLogger.isDebugEnabled()).thenReturn(false).thenReturn(true);
}
@Test
- public void testIsErrorEnabled() {
+ void testIsErrorEnabled() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "errorLogger", mockLogger);
Mockito.when(mockLogger.isErrorEnabled()).thenReturn(false).thenReturn(true);
}
@Test
- public void testIsWarnEnabled() {
+ void testIsWarnEnabled() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
Mockito.when(mockLogger.isWarnEnabled()).thenReturn(false).thenReturn(true);
}
@Test
- public void testIsInfoEnabled1() {
+ void testIsInfoEnabled1() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
Mockito.when(mockLogger.isInfoEnabled()).thenReturn(false).thenReturn(true);
}
@Test
- public void testIsAuditEnabled() {
+ void testIsAuditEnabled() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
Mockito.when(mockLogger.isInfoEnabled()).thenReturn(false).thenReturn(true);
}
@Test
- public void testIsInfoEnabled() {
+ void testIsInfoEnabled() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
Mockito.when(mockLogger.isInfoEnabled()).thenReturn(false).thenReturn(true);
}
@Test
- public void testTraceStringString() {
+ void testTraceStringString() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.trace("str1", "str2");
}
@Test
- public void testTraceObject() {
+ void testTraceObject() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.trace(1);
}
@Test
- public void testRecordAuditEventStartAndEnd() {
+ void testRecordAuditEventStartAndEnd() {
PolicyLogger.recordAuditEventStart("eventId");
assertNotNull(PolicyLogger.getEventTracker().getEventInfo().get("eventId"));
}
@Test
- public void testRecordAuditEventStartAndEndUuid() {
+ void testRecordAuditEventStartAndEndUuid() {
UUID uuid = UUID.randomUUID();
PolicyLogger.recordAuditEventStart(uuid);;
assertNotNull(PolicyLogger.getEventTracker().getEventInfo().get(uuid.toString()));
@Test
- public void testRecordAuditEventEndStringStringString() {
+ void testRecordAuditEventEndStringStringString() {
PolicyLogger.recordAuditEventStart("eventId");
assertNotNull(PolicyLogger.getEventTracker().getEventInfo().get("eventId"));
}
@Test
- public void testRecordAuditEventEndUuidStringString() {
+ void testRecordAuditEventEndUuidStringString() {
UUID uuid = UUID.randomUUID();
PolicyLogger.recordAuditEventStart(uuid);;
assertNotNull(PolicyLogger.getEventTracker().getEventInfo().get(uuid.toString()));
@Test
- public void testCreatAuditEventTrackingRecordStringStringString() {
+ void testCreatAuditEventTrackingRecordStringStringString() {
PolicyLogger.recordAuditEventStart("eventId");
assertNotNull(PolicyLogger.getEventTracker().getEventInfo().get("eventId"));
}
@Test
- public void testCreatAuditEventTrackingRecordUuidString() {
+ void testCreatAuditEventTrackingRecordUuidString() {
UUID uuid = UUID.randomUUID();
PolicyLogger.recordAuditEventStart(uuid);;
assertNotNull(PolicyLogger.getEventTracker().getEventInfo().get(uuid.toString()));
}
@Test
- public void testRecordAuditEventStartToEnd() {
+ void testRecordAuditEventStartToEnd() {
PolicyLogger.recordAuditEventStartToEnd("eventId", "rule", Instant.now(), Instant.now(), "policyVersion");
assertEquals("eventId", MDC.get(MDC_KEY_REQUEST_ID));
}
@Test
- public void testRecordMetricEventStringString() {
+ void testRecordMetricEventStringString() {
PolicyLogger.recordMetricEvent("eventId", "str1");
assertEquals("eventId", MDC.get(MDC_KEY_REQUEST_ID));
}
@Test
- public void testRecordMetricEventStringStringString() {
+ void testRecordMetricEventStringStringString() {
PolicyLogger.recordMetricEvent("eventId", "PolicyLoggerTest", "str1");
assertEquals("eventId", MDC.get(MDC_KEY_REQUEST_ID));
}
@Test
- public void testRecordMetricEventUuidString() {
+ void testRecordMetricEventUuidString() {
UUID uuid = UUID.randomUUID();
PolicyLogger.recordMetricEvent(uuid, "str1");
assertEquals(uuid.toString(), MDC.get(MDC_KEY_REQUEST_ID));
}
@Test
- public void testRecordMetricEventString() {
+ void testRecordMetricEventString() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "metricsLogger", mockLogger);
PolicyLogger.recordMetricEvent("eventId");
}
@Test
- public void testMetricsString() {
+ void testMetricsString() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "metricsLogger", mockLogger);
PolicyLogger.metrics("str1");
}
@Test
- public void testMetricsStringObject() {
+ void testMetricsStringObject() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "metricsLogger", mockLogger);
PolicyLogger.metrics("PolicyLoggerTest", 1);
}
@Test
- public void testMetricsObject() {
+ void testMetricsObject() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "metricsLogger", mockLogger);
PolicyLogger.metrics(1);
}
@Test
- public void testMetricsPrintln() {
+ void testMetricsPrintln() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "metricsLogger", mockLogger);
PolicyLogger.metricsPrintln("str1");
}
@Test
- public void testInitNullProperties() {
+ void testInitNullProperties() {
assertThatCode(() -> PolicyLogger.init(null)).doesNotThrowAnyException();
}
@Test
- public void testInit() {
+ void testInit() {
Properties properties = new Properties();
properties.setProperty("override.logback.level.setup", "true");
properties.setProperty("metricsLogger.level", "OFF");
}
@Test
- public void testSetDebugLevelString() {
+ void testSetDebugLevelString() {
PolicyLogger.setOverrideLogbackLevel(true);
PolicyLogger.setDebugLevel("TRACE");
assertEquals(Level.TRACE, PolicyLogger.getDebugLevel());
}
@Test
- public void testSetErrorLevelStringOff() {
+ void testSetErrorLevelStringOff() {
PolicyLogger.setOverrideLogbackLevel(true);
PolicyLogger.setErrorLevel("OFF");
assertEquals(Level.OFF, PolicyLogger.getErrorLevel());
}
@Test
- public void testSetErrorLevelStringOther() {
+ void testSetErrorLevelStringOther() {
PolicyLogger.setOverrideLogbackLevel(true);
PolicyLogger.setErrorLevel("INFO");
assertEquals(Level.ERROR, PolicyLogger.getErrorLevel());
}
@Test
- public void testSetMetricsLevelStringOff() {
+ void testSetMetricsLevelStringOff() {
PolicyLogger.setOverrideLogbackLevel(true);
PolicyLogger.setMetricsLevel("OFF");
assertEquals(Level.OFF, PolicyLogger.getMetricsLevel());
}
@Test
- public void testSetMetricsLevelStringOther() {
+ void testSetMetricsLevelStringOther() {
PolicyLogger.setOverrideLogbackLevel(true);
PolicyLogger.setMetricsLevel("ERROR");
assertEquals(Level.INFO, PolicyLogger.getMetricsLevel());
}
@Test
- public void testSetAuditLevelStringOff() {
+ void testSetAuditLevelStringOff() {
PolicyLogger.setOverrideLogbackLevel(true);
PolicyLogger.setAuditLevel("OFF");
assertEquals(Level.OFF, PolicyLogger.getAuditLevel());
}
@Test
- public void testSetAuditLevelStringOther() {
+ void testSetAuditLevelStringOther() {
PolicyLogger.setOverrideLogbackLevel(true);
PolicyLogger.setAuditLevel("ERROR");
assertEquals(Level.INFO, PolicyLogger.getAuditLevel());
}
@Test
- public void testSetAndIsOverrideLogbackLevel() {
+ void testSetAndIsOverrideLogbackLevel() {
PolicyLogger.setOverrideLogbackLevel(false);
assertFalse(PolicyLogger.isOverrideLogbackLevel());
PolicyLogger.setOverrideLogbackLevel(true);
}
@Test
- public void testSetServerInfo() {
+ void testSetServerInfo() {
PolicyLogger.setServerInfo("serverHost", "serverPort");
assertEquals("serverHost:serverPort", MDC.get(SERVER_NAME));
}
* ================================================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2019-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.
package org.onap.policy.common.logging.flexlogger;
import static com.att.eelf.configuration.Configuration.MDC_KEY_REQUEST_ID;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+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.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.never;
import com.att.eelf.configuration.EELFLogger;
import java.util.UUID;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.onap.policy.common.logging.eelf.MessageCodes;
import org.onap.policy.common.logging.eelf.PolicyLogger;
import org.slf4j.MDC;
import org.springframework.test.util.ReflectionTestUtils;
-public class EelfLoggerTest {
+class EelfLoggerTest {
EelfLogger eelfLogger = new EelfLogger("EelfLoggerTest", "transactionId");
@Test
- public void testEelfLoggerClassOfQ() {
+ void testEelfLoggerClassOfQ() {
new EelfLogger(this.getClass());
assertNotNull(PolicyLogger.getTransId());
assertFalse(PolicyLogger.getTransId().isEmpty());
}
@Test
- public void testEelfLoggerString() {
+ void testEelfLoggerString() {
new EelfLogger("EelfLoggerTest");
assertNotNull(PolicyLogger.getTransId());
assertFalse(PolicyLogger.getTransId().isEmpty());
}
@Test
- public void testEelfLoggerClassOfQBoolean() {
+ void testEelfLoggerClassOfQBoolean() {
new EelfLogger(this.getClass(), true);
assertNotNull(PolicyLogger.getTransId());
assertFalse(PolicyLogger.getTransId().isEmpty());
}
@Test
- public void testEelfLoggerStringBoolean() {
+ void testEelfLoggerStringBoolean() {
new EelfLogger("EelfLoggerTest", true);
assertNotNull(PolicyLogger.getTransId());
assertFalse(PolicyLogger.getTransId().isEmpty());
}
@Test
- public void testEelfLoggerClassOfQString() {
+ void testEelfLoggerClassOfQString() {
new EelfLogger(this.getClass(), "transactionId");
assertEquals("transactionId", PolicyLogger.getTransId());
}
@Test
- public void testEelfLoggerStringString() {
+ void testEelfLoggerStringString() {
new EelfLogger("EelfLoggerTest", "transactionId");
assertEquals("transactionId", PolicyLogger.getTransId());
}
@Test
- public void testSetAndGetTransId() {
+ void testSetAndGetTransId() {
assertEquals("transactionId", eelfLogger.getTransId());
eelfLogger.setTransId("transactionId2");
assertEquals("transactionId2", eelfLogger.getTransId());
}
@Test
- public void testDebugObject() {
+ void testDebugObject() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
eelfLogger.debug("message");
}
@Test
- public void testErrorObject() {
+ void testErrorObject() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "errorLogger", mockLogger);
eelfLogger.error("message");
}
@Test
- public void testInfoObject() {
+ void testInfoObject() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
eelfLogger.info("message");
}
@Test
- public void testWarnObject() {
+ void testWarnObject() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
eelfLogger.warn("message");
}
@Test
- public void testTraceObject() {
+ void testTraceObject() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
eelfLogger.trace("message");
}
@Test
- public void testIsDebugEnabled() {
+ void testIsDebugEnabled() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
Mockito.when(mockLogger.isDebugEnabled()).thenReturn(false).thenReturn(true);
}
@Test
- public void testIsInfoEnabled() {
+ void testIsInfoEnabled() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
Mockito.when(mockLogger.isInfoEnabled()).thenReturn(false).thenReturn(true);
}
@Test
- public void testIsWarnEnabled() {
+ void testIsWarnEnabled() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
Mockito.when(mockLogger.isWarnEnabled()).thenReturn(false).thenReturn(true);
}
@Test
- public void testIsErrorEnabled() {
+ void testIsErrorEnabled() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "errorLogger", mockLogger);
Mockito.when(mockLogger.isErrorEnabled()).thenReturn(false).thenReturn(true);
}
@Test
- public void testIsAuditEnabled() {
- PolicyLogger.setOverrideLogbackLevel(true);
- PolicyLogger.setAuditLevel("ERROR");
- assertTrue(eelfLogger.isAuditEnabled());
- }
-
- @Test
- public void testIsMetricsEnabled() {
+ void testIsMetricsEnabled() {
PolicyLogger.setOverrideLogbackLevel(true);
PolicyLogger.setMetricsLevel("ERROR");
assertTrue(eelfLogger.isMetricsEnabled());
}
@Test
- public void testIsTraceEnabled() {
+ void testIsTraceEnabled() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
Mockito.when(mockLogger.isDebugEnabled()).thenReturn(false).thenReturn(true);
}
@Test
- public void testAuditObject() {
+ void testAuditObject() {
PolicyLogger.setOverrideLogbackLevel(true);
PolicyLogger.setAuditLevel("ERROR");
assertTrue(eelfLogger.isAuditEnabled());
}
@Test
- public void testDebugObjectThrowable() {
+ void testDebugObjectThrowable() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
eelfLogger.debug("message", new NullPointerException());
}
@Test
- public void testErrorObjectThrowable() {
+ void testErrorObjectThrowable() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "errorLogger", mockLogger);
eelfLogger.error("message", new NullPointerException());
}
@Test
- public void testInfoObjectThrowable() {
+ void testInfoObjectThrowable() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
eelfLogger.info("message", new NullPointerException());
}
@Test
- public void testWarnObjectThrowable() {
+ void testWarnObjectThrowable() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
eelfLogger.warn("message", new NullPointerException());
}
@Test
- public void testTraceObjectThrowable() {
+ void testTraceObjectThrowable() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
eelfLogger.trace("message", new NullPointerException());
}
@Test
- public void testAuditObjectThrowable() {
+ void testAuditObjectThrowable() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "auditLogger", mockLogger);
eelfLogger.audit("message", new NullPointerException());
}
@Test
- public void testRecordAuditEventStartString() {
+ void testRecordAuditEventStartString() {
eelfLogger.recordAuditEventStart("eventId");
assertNotNull(PolicyLogger.getEventTracker().getEventInfo().get("eventId"));
}
@Test
- public void testRecordAuditEventStartUuid() {
+ void testRecordAuditEventStartUuid() {
UUID uuid = UUID.randomUUID();
eelfLogger.recordAuditEventStart(uuid);
assertNotNull(PolicyLogger.getEventTracker().getEventInfo().get(uuid.toString()));
}
@Test
- public void testRecordAuditEventEndStringStringString() {
+ void testRecordAuditEventEndStringStringString() {
eelfLogger.recordAuditEventStart("eventId");
assertNotNull(PolicyLogger.getEventTracker().getEventInfo().get("eventId"));
}
@Test
- public void testRecordAuditEventEndUuidStringString() {
+ void testRecordAuditEventEndUuidStringString() {
UUID uuid = UUID.randomUUID();
eelfLogger.recordAuditEventStart(uuid);;
assertNotNull(PolicyLogger.getEventTracker().getEventInfo().get(uuid.toString()));
}
@Test
- public void testRecordAuditEventEndStringString() {
+ void testRecordAuditEventEndStringString() {
eelfLogger.recordAuditEventStart("eventId");
assertNotNull(PolicyLogger.getEventTracker().getEventInfo().get("eventId"));
}
@Test
- public void testRecordAuditEventEndUuidString() {
+ void testRecordAuditEventEndUuidString() {
UUID uuid = UUID.randomUUID();
eelfLogger.recordAuditEventStart(uuid);;
assertNotNull(PolicyLogger.getEventTracker().getEventInfo().get(uuid.toString()));
}
@Test
- public void testRecordMetricEventStringString() {
+ void testRecordMetricEventStringString() {
eelfLogger.recordMetricEvent("eventId", "str1");
assertEquals("eventId", MDC.get(MDC_KEY_REQUEST_ID));
}
@Test
- public void testRecordMetricEventUuidString() {
+ void testRecordMetricEventUuidString() {
UUID uuid = UUID.randomUUID();
eelfLogger.recordMetricEvent(uuid, "str2");
assertEquals(uuid.toString(), MDC.get(MDC_KEY_REQUEST_ID));
}
@Test
- public void testMetrics() {
+ void testMetrics() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "metricsLogger", mockLogger);
eelfLogger.metrics(1);
}
@Test
- public void testErrorMessageCodesThrowableStringArray() {
+ void testErrorMessageCodesThrowableStringArray() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "errorLogger", mockLogger);
eelfLogger.error(MessageCodes.GENERAL_ERROR, new NullPointerException(), "str1", "str2");
}
@Test
- public void testErrorMessageCodesStringArray() {
+ void testErrorMessageCodesStringArray() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "errorLogger", mockLogger);
eelfLogger.error(MessageCodes.GENERAL_ERROR, "str1", "str2");
}
@Test
- public void testPostMdcInfoForEventString() {
+ void testPostMdcInfoForEventString() {
eelfLogger.postMdcInfoForEvent("transactionId");
assertEquals("transactionId", MDC.get(MDC_KEY_REQUEST_ID));
}
@Test
- public void testWarnMessageCodesStringArray() {
+ void testWarnMessageCodesStringArray() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
eelfLogger.warn(MessageCodes.GENERAL_ERROR, "str1", "str2");
}
@Test
- public void testWarnMessageCodesThrowableStringArray() {
+ void testWarnMessageCodesThrowableStringArray() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
eelfLogger.warn(MessageCodes.GENERAL_ERROR, new NullPointerException(), "str1", "str2");
}
@Test
- public void testPostMdcInfoForTriggeredRule() {
+ void testPostMdcInfoForTriggeredRule() {
eelfLogger.postMdcInfoForTriggeredRule("transactionId");
assertEquals("transactionId", MDC.get(MDC_KEY_REQUEST_ID));
}
@Test
- public void testPostMDdcInfoForEventObject() {
+ void testPostMDdcInfoForEventObject() {
eelfLogger.postMdcInfoForEvent(1);
assertEquals("1", MDC.get(MDC_KEY_REQUEST_ID));
}
* ================================================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2019-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.
package org.onap.policy.common.logging.flexlogger;
import static org.assertj.core.api.Assertions.assertThatCode;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertSame;
+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.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.logging.flexlogger.FlexLogger.PropertiesCallBack;
import org.springframework.test.util.ReflectionTestUtils;
-public class FlexLoggerTest {
+class FlexLoggerTest {
@Test
- public void testGetLoggerClassOfQEelf() {
+ void testGetLoggerClassOfQEelf() {
ReflectionTestUtils.setField(FlexLogger.class, "loggerType", LoggerType.EELF);
Logger logger = FlexLogger.getLogger((Class<?>) null);
assertSame(logger, FlexLogger.getLogger((Class<?>) null));
}
@Test
- public void testGetLoggerClassOfQSystemOut() {
+ void testGetLoggerClassOfQSystemOut() {
ReflectionTestUtils.setField(FlexLogger.class, "loggerType", LoggerType.SYSTEMOUT);
Logger logger = FlexLogger.getLogger(this.getClass());
assertSame(logger, FlexLogger.getLogger(this.getClass()));
}
@Test
- public void testGetLoggerStringEelf() {
+ void testGetLoggerStringEelf() {
ReflectionTestUtils.setField(FlexLogger.class, "loggerType", LoggerType.EELF);
Logger logger = FlexLogger.getLogger();
assertSame(logger, FlexLogger.getLogger());
}
@Test
- public void testGetLoggerStringSystemOut() {
+ void testGetLoggerStringSystemOut() {
ReflectionTestUtils.setField(FlexLogger.class, "loggerType", LoggerType.SYSTEMOUT);
Logger logger = FlexLogger.getLogger();
assertSame(logger, FlexLogger.getLogger());
}
@Test
- public void testGetLoggerClassOfQBooleanEelf() {
+ void testGetLoggerClassOfQBooleanEelf() {
ReflectionTestUtils.setField(FlexLogger.class, "loggerType", LoggerType.EELF);
Logger logger = FlexLogger.getLogger(this.getClass(), true);
assertSame(logger, FlexLogger.getLogger(this.getClass(), true));
}
@Test
- public void testGetLoggerClassOfQBooleanSystemOut() {
+ void testGetLoggerClassOfQBooleanSystemOut() {
ReflectionTestUtils.setField(FlexLogger.class, "loggerType", LoggerType.SYSTEMOUT);
Logger logger = FlexLogger.getLogger(this.getClass(), true);
assertSame(logger, FlexLogger.getLogger(this.getClass(), true));
}
@Test
- public void testGetLoggerStringBooleanEelf() {
+ void testGetLoggerStringBooleanEelf() {
ReflectionTestUtils.setField(FlexLogger.class, "loggerType", LoggerType.EELF);
Logger logger = FlexLogger.getLogger(true);
assertSame(logger, FlexLogger.getLogger(true));
}
@Test
- public void testGetLoggerStringBooleanSystemOut() {
+ void testGetLoggerStringBooleanSystemOut() {
ReflectionTestUtils.setField(FlexLogger.class, "loggerType", LoggerType.SYSTEMOUT);
Logger logger = FlexLogger.getLogger(true);
assertSame(logger, FlexLogger.getLogger(true));
}
@Test
- public void testGetClassName() {
+ void testGetClassName() {
assertNotEquals("FlexLogger", new FlexLogger().getClassName());
}
@Test
- public void testPropertiesCallBack() throws IOException {
+ void testPropertiesCallBack() {
Set<String> changedKeys = new HashSet<>();
changedKeys.add("debugLogger.level");
changedKeys.add("metricsLogger.level");
* ONAP-Logging
* ================================================================================
* Copyright (C) 2018-2020 Ericsson, AT&T. 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.
package org.onap.policy.common.logging.flexlogger;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Mockito.doAnswer;
import java.util.TimerTask;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.logging.flexlogger.PropertyUtil.Listener;
import org.springframework.test.util.ReflectionTestUtils;
-public class PropertyUtilTest {
+class PropertyUtilTest {
private static final String TIMER_FIELD = "timer";
private static final File FILE = new File("target/test.properties");
private Timer timer;
private TestListener testListener;
- @BeforeClass
+ @BeforeAll
public static void setUpBeforeClass() {
saveTimer = (Timer) ReflectionTestUtils.getField(PropertyUtil.LazyHolder.class, TIMER_FIELD);
}
- @AfterClass
+ @AfterAll
public static void tearDownAfterClass() {
ReflectionTestUtils.setField(PropertyUtil.LazyHolder.class, TIMER_FIELD, saveTimer);
/**
* Perform test case set up.
*/
- @Before
- public void setUp() throws IOException {
+ @BeforeEach
+ void setUp() throws IOException {
task = null;
timer = mock(Timer.class);
ReflectionTestUtils.setField(PropertyUtil.LazyHolder.class, TIMER_FIELD, timer);
fileOutputStream.close();
}
- @After
- public void tearDown() throws IOException {
+ @AfterEach
+ void tearDown() throws IOException {
PropertyUtil.stopListening(FILE, testListener);
FILE.delete();
}
@Test
- public void testTimer() {
+ void testTimer() {
assertNotNull(saveTimer);
}
@Test
- public void testGetProperties() throws IOException {
+ void testGetProperties() throws IOException {
FileOutputStream fileOutputStream = new FileOutputStream(FILE);
Properties properties = new Properties();
properties.put("testProperty", "testValue");
}
@Test
- public void testPropertiesChanged() throws IOException, InterruptedException {
+ void testPropertiesChanged() throws IOException, InterruptedException {
PropertyUtil.getProperties(FILE, testListener);
FileOutputStream fileOutputStream = new FileOutputStream(FILE);
}
@Test
- public void testStopListening() throws IOException {
+ void testStopListening() throws IOException {
FileOutputStream fileOutputStream = new FileOutputStream(FILE);
Properties properties = new Properties();
properties.put("testProperty", "testValue");
* ================================================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
* Modifications 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.
package org.onap.policy.common.logging.flexlogger;
import static org.assertj.core.api.Assertions.assertThatCode;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+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 com.att.eelf.configuration.EELFLogger.Level;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.UUID;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.logging.eelf.MessageCodes;
import org.onap.policy.common.logging.eelf.PolicyLogger;
-public class SystemOutLoggerTest {
+class SystemOutLoggerTest {
SystemOutLogger systemOutLogger = new SystemOutLogger("SystemOutLoggerTest");
@Test
- public void testSystemOutLoggerClassOfQ() {
+ void testSystemOutLoggerClassOfQ() {
assertThatCode(() -> new SystemOutLogger(SystemOutLoggerTest.class)).doesNotThrowAnyException();
}
@Test
- public void testSetAndGetTransId() {
+ void testSetAndGetTransId() {
systemOutLogger.setTransId("transactionId");
assertEquals("transactionId", systemOutLogger.getTransId());
}
@Test
- public void testDebugObject() {
+ void testDebugObject() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
}
@Test
- public void testErrorObject() {
+ void testErrorObject() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
}
@Test
- public void testInfoObject() {
+ void testInfoObject() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
}
@Test
- public void testWarnObject() {
+ void testWarnObject() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
}
@Test
- public void testTraceObject() {
+ void testTraceObject() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
}
@Test
- public void testIsDebugEnabled() {
+ void testIsDebugEnabled() {
PolicyLogger.setDebugLevel(Level.DEBUG);
systemOutLogger = new SystemOutLogger("SystemOutLoggerTest");
assertTrue(systemOutLogger.isDebugEnabled());
}
@Test
- public void testIsWarnEnabled() {
+ void testIsWarnEnabled() {
PolicyLogger.setDebugLevel(Level.WARN);
systemOutLogger = new SystemOutLogger("SystemOutLoggerTest");
assertTrue(systemOutLogger.isWarnEnabled());
}
@Test
- public void testIsInfoEnabled() {
+ void testIsInfoEnabled() {
PolicyLogger.setDebugLevel(Level.INFO);
systemOutLogger = new SystemOutLogger("SystemOutLoggerTest");
assertTrue(systemOutLogger.isInfoEnabled());
}
@Test
- public void testIsErrorEnabled() {
+ void testIsErrorEnabled() {
PolicyLogger.setErrorLevel(Level.ERROR);
systemOutLogger = new SystemOutLogger("SystemOutLoggerTest");
assertTrue(systemOutLogger.isErrorEnabled());
}
@Test
- public void testIsAuditEnabled() {
+ void testIsAuditEnabled() {
PolicyLogger.setAuditLevel(Level.INFO);
systemOutLogger = new SystemOutLogger("SystemOutLoggerTest");
assertTrue(systemOutLogger.isAuditEnabled());
}
@Test
- public void testIsMetricsEnabled() {
+ void testIsMetricsEnabled() {
PolicyLogger.setMetricsLevel(Level.INFO);
systemOutLogger = new SystemOutLogger("SystemOutLoggerTest");
assertTrue(systemOutLogger.isMetricsEnabled());
}
@Test
- public void testAuditObject() {
+ void testAuditObject() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
}
@Test
- public void testRecordAuditEventStartString() {
+ void testRecordAuditEventStartString() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
}
@Test
- public void testRecordAuditEventStartUuid() {
+ void testRecordAuditEventStartUuid() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
}
@Test
- public void testRecordAuditEventEndStringStringString() {
+ void testRecordAuditEventEndStringStringString() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
}
@Test
- public void testRecordAuditEventEndUuidStringString() {
+ void testRecordAuditEventEndUuidStringString() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
}
@Test
- public void testRecordAuditEventEndStringString() {
+ void testRecordAuditEventEndStringString() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
}
@Test
- public void testRecordAuditEventEndUuidString() {
+ void testRecordAuditEventEndUuidString() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
}
@Test
- public void testRecordMetricEventStringString() {
+ void testRecordMetricEventStringString() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
try {
System.setOut(ps);
systemOutLogger.recordMetricEvent("eventId", "rule");
- assertTrue(baos.toString(), baos.toString().contains("SystemOutLoggerTest : eventId:eventIdmessage:rule"));
+ assertTrue(baos.toString().contains("SystemOutLoggerTest : eventId:eventIdmessage:rule"), baos.toString());
} finally {
System.out.flush();
System.setOut(old);
}
@Test
- public void testRecordMetricEventUuidString() {
+ void testRecordMetricEventUuidString() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
}
@Test
- public void testMetrics() {
+ void testMetrics() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
}
@Test
- public void testErrorMessageCodesThrowableStringArray() {
+ void testErrorMessageCodesThrowableStringArray() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
}
@Test
- public void testErrorMessageCodesStringArray() {
+ void testErrorMessageCodesStringArray() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
}
@Test
- public void testPostMdcInfoForEventString() {
+ void testPostMdcInfoForEventString() {
assertEquals("transactionId", systemOutLogger.postMdcInfoForEvent("transactionId"));
}
@Test
- public void testWarnMessageCodesStringArray() {
+ void testWarnMessageCodesStringArray() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
}
@Test
- public void testWarnMessageCodesThrowableStringArray() {
+ void testWarnMessageCodesThrowableStringArray() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
}
@Test
- public void testDebugObjectThrowable() {
+ void testDebugObjectThrowable() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
System.setOut(ps);
systemOutLogger.setTransId("transactionId");
systemOutLogger.debug("1", new NullPointerException());
- assertTrue(baos.toString(),
- baos.toString().contains("transactionId|SystemOutLoggerTest : 1:java.lang.NullPointerException"));
+ assertTrue(baos.toString().contains("transactionId|SystemOutLoggerTest : 1:java.lang.NullPointerException"),
+ baos.toString());
} finally {
System.out.flush();
System.setOut(old);
}
@Test
- public void testErrorObjectThrowable() {
+ void testErrorObjectThrowable() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
System.setOut(ps);
systemOutLogger.setTransId("transactionId");
systemOutLogger.error("1", new NullPointerException());
- assertTrue(baos.toString(),
- baos.toString().contains("transactionId|SystemOutLoggerTest : 1:java.lang.NullPointerException"));
+ assertTrue(baos.toString().contains("transactionId|SystemOutLoggerTest : 1:java.lang.NullPointerException"),
+ baos.toString());
} finally {
System.out.flush();
System.setOut(old);
}
@Test
- public void testInfoObjectThrowable() {
+ void testInfoObjectThrowable() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
System.setOut(ps);
systemOutLogger.setTransId("transactionId");
systemOutLogger.info("1", new NullPointerException());
- assertTrue(baos.toString(),
- baos.toString().contains("transactionId|SystemOutLoggerTest : 1:java.lang.NullPointerException"));
+ assertTrue(baos.toString().contains("transactionId|SystemOutLoggerTest : 1:java.lang.NullPointerException"),
+ baos.toString());
} finally {
System.out.flush();
System.setOut(old);
}
@Test
- public void testWarnObjectThrowable() {
+ void testWarnObjectThrowable() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
System.setOut(ps);
systemOutLogger.setTransId("transactionId");
systemOutLogger.warn("1", new NullPointerException());
- assertTrue(baos.toString(),
- baos.toString().contains("transactionId|SystemOutLoggerTest : 1:java.lang.NullPointerException"));
+ assertTrue(baos.toString().contains("transactionId|SystemOutLoggerTest : 1:java.lang.NullPointerException"),
+ baos.toString());
} finally {
System.out.flush();
System.setOut(old);
}
@Test
- public void testTraceObjectThrowable() {
+ void testTraceObjectThrowable() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
System.setOut(ps);
systemOutLogger.setTransId("transactionId");
systemOutLogger.trace(1, new NullPointerException());
- assertTrue(baos.toString(),
- baos.toString().contains("transactionId|SystemOutLoggerTest : 1:java.lang.NullPointerException"));
+ assertTrue(baos.toString().contains("transactionId|SystemOutLoggerTest : 1:java.lang.NullPointerException"),
+ baos.toString());
} finally {
System.out.flush();
System.setOut(old);
}
@Test
- public void testAuditObjectThrowable() {
+ void testAuditObjectThrowable() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
System.setOut(ps);
systemOutLogger.setTransId("transactionId");
systemOutLogger.audit("1", new NullPointerException());
- assertTrue(baos.toString(),
- baos.toString().contains("transactionId|SystemOutLoggerTest : 1:java.lang.NullPointerException"));
+ assertTrue(baos.toString().contains("transactionId|SystemOutLoggerTest : 1:java.lang.NullPointerException"),
+ baos.toString());
} finally {
System.out.flush();
System.setOut(old);
}
@Test
- public void testIsTraceEnabled() {
+ void testIsTraceEnabled() {
assertFalse(systemOutLogger.isTraceEnabled());
}
@Test
- public void testPostMdcInfoForTriggeredRule() {
+ void testPostMdcInfoForTriggeredRule() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
try {
System.setOut(ps);
systemOutLogger.postMdcInfoForTriggeredRule("transactionId");
- assertTrue(baos.toString(), baos.toString().contains("transactionId"));
+ assertTrue(baos.toString().contains("transactionId"), baos.toString());
} finally {
System.out.flush();
System.setOut(old);
}
@Test
- public void testPostMdcInfoForEventObject() {
+ void testPostMdcInfoForEventObject() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
try {
System.setOut(ps);
systemOutLogger.postMdcInfoForEvent(1);
- assertTrue(baos.toString(), baos.toString().contains("1"));
+ assertTrue(baos.toString().contains("1"), baos.toString());
} finally {
System.out.flush();
System.setOut(old);
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
* Modifications 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.
package org.onap.policy.common.parameters;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class ExceptionTest {
+class ExceptionTest {
private static final String PARAMETER_EXCEPTION = "Parameter Exception";
private static final String EXCEPTION_OBJECT = "Exception Object";
@Test
- public void testParameterException() {
+ void testParameterException() {
assertEquals(PARAMETER_EXCEPTION, new ParameterException(PARAMETER_EXCEPTION).getMessage());
assertEquals(EXCEPTION_OBJECT,
}
@Test
- public void testParameterRuntimeException() {
+ void testParameterRuntimeException() {
assertEquals(PARAMETER_EXCEPTION, new ParameterRuntimeException(PARAMETER_EXCEPTION).getMessage());
assertEquals(EXCEPTION_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.
package org.onap.policy.common.parameters;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Arrays;
import java.util.List;
import java.util.Map.Entry;
import java.util.TreeMap;
import java.util.function.BiConsumer;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
-public class TestBeanValidationResult {
+class TestBeanValidationResult {
private static final String TEXT1 = "abc";
private static final String TEXT2 = "def";
private static final String MY_LIST = "my-list";
/**
* Sets up.
*/
- @Before
- public void setUp() {
+ @BeforeEach
+ void setUp() {
clean = new ObjectValidationResult(TEXT1, 10);
cleanMsg = clean.getResult("", "", true);
}
@Test
- public void testBeanValidationResult() {
+ void testBeanValidationResult() {
assertTrue(bean.isValid());
assertNull(bean.getResult());
}
@Test
- public void testAddResult_testGetResult() {
+ void testAddResult_testGetResult() {
// null should be ok
assertTrue(bean.addResult(null));
}
@Test
- public void testValidateNotNull() {
+ void testValidateNotNull() {
assertTrue(bean.validateNotNull("sub-name", "sub-object"));
assertTrue(bean.isValid());
assertNull(bean.getResult());
}
@Test
- public void testValidateNotNullList() {
+ void testValidateNotNullList() {
List<ValidationResult> list = Arrays.asList(clean);
assertTrue(bean.validateNotNullList(MY_LIST, list, item -> item));
assertTrue(bean.isValid());
}
@Test
- public void testValidateNotNullList_NullList() {
+ void testValidateNotNullList_NullList() {
List<ValidationResult> list = null;
assertFalse(bean.validateNotNullList(MY_LIST, list, item -> item));
assertFalse(bean.isValid());
}
@Test
- public void testValidateList() {
+ void testValidateList() {
List<ValidationResult> list = null;
bean = new BeanValidationResult(NAME, OBJECT);
assertTrue(bean.validateList(MY_LIST, list, item -> item));
}
@Test
- public void testValidateMap() {
+ void testValidateMap() {
Map<String, ValidationResult> map = null;
bean = new BeanValidationResult(NAME, OBJECT);
assertTrue(bean.validateMap(MY_MAP, map, validMapEntry()));
* 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.
package org.onap.policy.common.parameters;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Collection;
import java.util.HashMap;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
import lombok.Getter;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.parameters.annotations.ClassName;
import org.onap.policy.common.parameters.annotations.Max;
import org.onap.policy.common.parameters.annotations.Min;
import org.onap.policy.common.parameters.annotations.Size;
import org.onap.policy.common.parameters.annotations.Valid;
-public class TestBeanValidator {
+class TestBeanValidator {
private static final String TOP = "top";
private static final String STR_FIELD = "strValue";
private static final String INT_FIELD = "intValue";
private BeanValidator validator;
- @Before
- public void setUp() {
+ @BeforeEach
+ void setUp() {
validator = new BeanValidator();
}
@Test
- public void testValidateTop_testValidateFields() {
+ void testValidateTop_testValidateFields() {
// validate null
assertTrue(validator.validateTop(TOP, null).isValid());
}
@Test
- public void testVerNotNull() {
+ void testVerNotNull() {
class NotNullCheck {
@Getter
@Min(1)
}
@Test
- public void testVerNotBlank() {
+ void testVerNotBlank() {
class NotBlankCheck {
@Getter
@NotBlank
* Tests verSize with a collection.
*/
@Test
- public void testVerSizeCollection() {
+ void testVerSizeCollection() {
class CollectionSizeCheck {
@Getter
@Size(min = 3)
* Tests verSize with a map.
*/
@Test
- public void testVerSizeMap() {
+ void testVerSizeMap() {
class MapSizeCheck {
@Getter
@Size(min = 3)
* Tests verSize with an object for which it doesn't apply.
*/
@Test
- public void testVerSizeOther() {
+ void testVerSizeOther() {
class OtherSizeCheck {
@Getter
@Size(min = 3)
}
@Test
- public void testVerRegex() {
+ void testVerRegex() {
class RegexCheck {
@Getter
@Pattern(regexp = "[a-f]*")
}
@Test
- public void testVerMax() {
+ void testVerMax() {
/*
* Field is not a number.
*/
}
@Test
- public void testVerMin() {
+ void testVerMin() {
/*
* Field is not a number.
*/
}
@Test
- public void testVerClassName() {
+ void testVerClassName() {
class ClassNameCheck {
@Getter
@ClassName
}
@Test
- public void testVerCascade() {
+ void testVerCascade() {
class Item {
@Getter
@NotNull
}
@Test
- public void testVerCollection() {
+ void testVerCollection() {
@Getter
class Container {
List<@Min(5) Integer> items;
}
@Test
- public void testVerMap() {
+ void testVerMap() {
@Getter
class Container {
Map<String, @Min(5) Integer> items;
}
@Test
- public void testGetEntryName() {
+ 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);
* ONAP
* ================================================================================
* Copyright (C) 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.Map;
import lombok.Getter;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.parameters.annotations.Min;
import org.onap.policy.common.parameters.annotations.NotBlank;
import org.onap.policy.common.parameters.annotations.NotNull;
-public class TestFieldValidator extends ValidatorUtil {
+class TestFieldValidator extends ValidatorUtil {
private static final String INT_LIST_FIELD = "intList";
private static final String INT_MAP_FIELD = "intMap";
private static final String UNANNOTATED_FIELD = "unannotated";
private int exMethod;
- @Before
- public void setUp() {
+ @BeforeEach
+ void setUp() {
bean = new BeanValidator();
}
@Test
- public void testGetAnnotation() {
+ void testGetAnnotation() {
// field-level annotation
assertThat(new FieldValidator(bean, TestFieldValidator.class, getField(INT_FIELD)).isEmpty()).isFalse();
}
@Test
- public void testFieldValidator() throws NoSuchFieldException, SecurityException {
+ void testFieldValidator() throws NoSuchFieldException, SecurityException {
/*
* Note: nested classes contain fields like "$this", thus the check for "$" in the
* variable name is already covered by the other tests.
}
@Test
- public void testFieldValidator_SetNullAllowed() {
+ void testFieldValidator_SetNullAllowed() {
// default - null is allowed
assertThat(new FieldValidator(bean, TestFieldValidator.class, getField(INT_FIELD)).isNullAllowed()).isTrue();
}
@Test
- public void testAddListValidator() {
+ void testAddListValidator() {
// unannotated
assertThat(new FieldValidator(bean, TestFieldValidator.class, getField("unannotatedList")).isEmpty()).isTrue();
}
@Test
- public void testAddMapValidator() {
+ void testAddMapValidator() {
// unannotated
assertThat(new FieldValidator(bean, TestFieldValidator.class, getField("unannotatedMap")).isEmpty()).isTrue();
@SuppressWarnings("deprecation")
@Test
- public void testValidateField_testGetValue() {
+ void testValidateField_testGetValue() {
// unannotated
BeanValidationResult result = new BeanValidationResult(MY_NAME, this);
new FieldValidator(bean, getClass(), getField(UNANNOTATED_FIELD)).validateField(result, this);
}
@Test
- public void testValidateField_testGetValue_ListField() {
+ void testValidateField_testGetValue_ListField() {
// valid
BeanValidationResult result = new BeanValidationResult(MY_NAME, this);
intList = List.of(10, 20, 30, 40);
}
@Test
- public void testValidateField_testGetValue_MapField() {
+ void testValidateField_testGetValue_MapField() {
// valid
BeanValidationResult result = new BeanValidationResult(MY_NAME, this);
intMap = Map.of("ten", 10, "twenty", 20, "thirty", 30, "forty", 40);
}
@Test
- public void testClassOnly() {
+ void testClassOnly() {
// class-level annotation has no bearing on a static field
assertThat(new FieldValidator(bean, ClassAnnot.class, getField(ClassAnnot.class, "staticValue")).isEmpty())
.isTrue();
}
@Test
- public void testGetAccessor() {
+ void testGetAccessor() {
// uses "getXxx"
assertThat(new FieldValidator(bean, TestFieldValidator.class, getField(INT_FIELD)).isEmpty()).isFalse();
}
@Test
- public void testGetMethod() {
+ void testGetMethod() {
assertThat(new FieldValidator(bean, TestFieldValidator.class, getField(INT_FIELD)).isEmpty()).isFalse();
// these are invalid for various reasons
}
@Test
- public void testValidMethod() {
+ void testValidMethod() {
assertThat(new FieldValidator(bean, TestFieldValidator.class, getField(INT_FIELD)).isEmpty()).isFalse();
// these are invalid for various reasons
}
@Test
- public void testIsFieldAnnotated_testSetFieldAnnotated() {
+ void testIsFieldAnnotated_testSetFieldAnnotated() {
// annotated at the field level
assertThat(new FieldValidator(bean, getClass(), getField(INT_FIELD)).isFieldAnnotated()).isTrue();
return -1000;
}
- public void getVoidMethod() {
+ void getVoidMethod() {
// do nothing
}
* 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.lang.annotation.Retention;
import java.lang.annotation.Target;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.parameters.annotations.Min;
import org.onap.policy.common.parameters.annotations.NotBlank;
import org.onap.policy.common.parameters.annotations.NotNull;
-public class TestItemValidator extends ValidatorUtil {
+class TestItemValidator extends ValidatorUtil {
// annotated fields - each field must have exactly one annotation
private String multiMatch;
- @Before
- public void setUp() {
+ @BeforeEach
+ void setUp() {
bean = new BeanValidator();
}
@Test
- public void testGetAnnotation() {
+ void testGetAnnotation() {
// no matches
assertThat(new ItemValidator(bean, getAnnotType("noAnnotations"), true).isEmpty()).isTrue();
}
@Test
- public void testItemValidatorBeanValidatorAnnotation() {
+ void testItemValidatorBeanValidatorAnnotation() {
assertThat(new ItemValidator(bean, getAnnotType("match")).isEmpty()).isFalse();
}
@Test
- public void testItemValidatorBeanValidatorAnnotationBoolean() {
+ void testItemValidatorBeanValidatorAnnotationBoolean() {
assertThat(new ItemValidator(bean, getAnnotType("match"), true).isEmpty()).isFalse();
assertThat(new ItemValidator(bean, getAnnotType("match"), false).isEmpty()).isTrue();
* 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.parameters;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class TestObjectValidationResult {
+class TestObjectValidationResult {
private static final String NAME = "my-name";
private static final Object OBJECT = "my-object";
private ObjectValidationResult result;
@Test
- public void testValidationResultImplStringObjectValidationStatusString() {
+ void testValidationResultImplStringObjectValidationStatusString() {
result = new ObjectValidationResult(NAME, OBJECT, ValidationStatus.INVALID, "invalid data");
assertEquals(NAME, result.getName());
assertEquals(OBJECT, result.getObject());
}
@Test
- public void testGetResult() {
+ void testGetResult() {
result = new ObjectValidationResult(NAME, OBJECT);
assertEquals(ValidationStatus.CLEAN, result.getStatus());
assertNull(result.getResult());
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
* Modifications 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.parameters;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.parameters.annotations.Max;
import org.onap.policy.common.parameters.annotations.Min;
import org.onap.policy.common.parameters.annotations.NotBlank;
import org.onap.policy.common.parameters.annotations.NotNull;
import org.onap.policy.common.parameters.annotations.Valid;
-public class TestValidation {
+class TestValidation {
private static final String NOT_BLANK_STRING_MESSAGE =
"field 'notBlankString' type 'java.lang.String' value '' INVALID, must be a non-blank string\n"
.replace('\'', '"');
private long maxLong;
@Test
- public void testGetValidationResult() {
+ void testGetValidationResult() {
Contained item = new Contained();
item.setName("item");
}
@Test
- public void testParameterValidationResult_NotNull() throws Exception {
+ void testParameterValidationResult_NotNull() throws Exception {
ParameterValidationResult result = new ParameterValidationResult(
TestValidation.class.getDeclaredField(NOT_NULL_STRING_NAME), null);
assertEquals(ValidationStatus.INVALID, result.getStatus());
}
@Test
- public void testParameterValidationResult_NotBlank() throws Exception {
+ void testParameterValidationResult_NotBlank() throws Exception {
ParameterValidationResult result =
new ParameterValidationResult(TestValidation.class.getDeclaredField(NOT_BLANK_STRING_NAME), "");
assertEquals(ValidationStatus.INVALID, result.getStatus());
}
@Test
- public void testParameterValidationResult_Min() throws Exception {
+ void testParameterValidationResult_Min() throws Exception {
ParameterValidationResult result =
new ParameterValidationResult(TestValidation.class.getDeclaredField(MIN_LONG_NAME), 9L);
assertEquals(ValidationStatus.INVALID, result.getStatus());
}
@Test
- public void testParameterValidationResult_Max() throws Exception {
+ void testParameterValidationResult_Max() throws Exception {
ParameterValidationResult result =
new ParameterValidationResult(TestValidation.class.getDeclaredField(MAX_LONG_NAME), 11L);
assertEquals(ValidationStatus.INVALID, result.getStatus());
* 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.parameters;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
-public class TestValidationResultImpl {
+class TestValidationResultImpl {
private static final String NAME = "my-name";
private static final Object OBJECT = "my-object";
private MyResult result;
- @Before
- public void setUp() {
+ @BeforeEach
+ void setUp() {
result = new MyResult(NAME, OBJECT);
}
@Test
- public void testValidationResultImplStringObjectValidationStatusString() {
+ void testValidationResultImplStringObjectValidationStatusString() {
result = new MyResult(NAME, OBJECT, ValidationStatus.INVALID, "invalid data");
assertEquals(NAME, result.getName());
assertEquals(OBJECT, result.getObject());
}
@Test
- public void testValidateNotNull() {
+ void testValidateNotNull() {
assertTrue(result.validateNotNull());
assertTrue(result.isValid());
assertNull(result.getResult());
}
@Test
- public void testSetResultValidationStatus() {
+ void testSetResultValidationStatus() {
result.setResult(ValidationStatus.WARNING);
assertEquals(ValidationStatus.WARNING, result.getStatus());
}
@Test
- public void testSetResult_testGetResult_testGetStatus() {
+ void testSetResult_testGetResult_testGetStatus() {
assertEquals(ValidationStatus.CLEAN, result.getStatus());
assertEquals("CLEAN item has status CLEAN", result.getResult("xxx ", "yyy", true));
}
@Test
- public void testGetName() {
+ void testGetName() {
assertEquals(NAME, result.getName());
}
* 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.lang.annotation.Annotation;
import java.util.concurrent.atomic.AtomicBoolean;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.parameters.annotations.Min;
import org.onap.policy.common.parameters.annotations.NotBlank;
import org.onap.policy.common.parameters.annotations.NotNull;
-public class TestValueValidator extends ValidatorUtil {
+class TestValueValidator extends ValidatorUtil {
private ValueValidator validator;
private final int annotField = 1;
- @Before
- public void setUp() {
+ @BeforeEach
+ void setUp() {
validator = new MyValueValidator();
}
@Test
- public void testIsEmpty() {
+ void testIsEmpty() {
assertThat(validator.isEmpty()).isTrue();
validator.addAnnotation(NotNull.class, (result2, fieldName, value) -> true);
}
@Test
- public void testValidateValue_NullValue() {
+ void testValidateValue_NullValue() {
BeanValidationResult result = new BeanValidationResult(MY_NAME, this);
validator.validateValue(result, MY_FIELD, null);
}
@Test
- public void testValidateValue_NotNullValue() {
+ void testValidateValue_NotNullValue() {
BeanValidationResult result = new BeanValidationResult(MY_NAME, this);
validator.validateValue(result, MY_FIELD, HELLO);
}
@Test
- public void testAddAnnotationClassOfTChecker() {
+ void testAddAnnotationClassOfTChecker() {
// the field does not have this annotation
validator.addAnnotation(Min.class, (result2, fieldName, value) -> true);
assertThat(validator.isEmpty()).isTrue();
}
@Test
- public void testAddAnnotationClassOfTCheckerWithAnnotOfT() {
+ void testAddAnnotationClassOfTCheckerWithAnnotOfT() {
// the field does not have this annotation
validator.addAnnotation(Min.class, (result2, fieldName, annot, value) -> true);
assertThat(validator.isEmpty()).isTrue();
}
@Test
- public void testGetAnnotation() {
+ void testGetAnnotation() {
assertThat(new ValueValidator().getAnnotation(NotNull.class)).isNull();
}
<groupId>com.google.re2j</groupId>
<artifactId>re2j</artifactId>
</dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
* 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.gson;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class DoubleConverterTest {
+class DoubleConverterTest {
@Test
- @SuppressWarnings("unchecked")
- public void testConvertFromDoubleObject() {
+ void testConvertFromDoubleObject() {
// these should be unchanged
assertNull(DoubleConverter.convertFromDouble((Object) null));
assertEquals("hello", DoubleConverter.convertFromDouble("hello"));
}
@Test
- public void testConvertFromDoubleList() {
+ void testConvertFromDoubleList() {
// null is ok
DoubleConverter.convertFromDouble((List<Object>) null);
}
@Test
- public void testConvertFromDoubleMap() {
+ void testConvertFromDoubleMap() {
// null is ok
DoubleConverter.convertFromDouble((Map<String, Object>) null);
* ONAP
* ================================================================================
* Copyright (C) 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.
package org.onap.policy.common.gson;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+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 jakarta.ws.rs.core.MediaType;
import java.io.ByteArrayInputStream;
import java.util.Map;
import java.util.UUID;
import lombok.ToString;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
-public class GsonMessageBodyHandlerTest {
+class GsonMessageBodyHandlerTest {
private static final String GEN_TYPE = "some-type";
private static final String[] subtypes = {"json", "jSoN", "hello+json", "javascript", "x-javascript", "x-json"};
private GsonMessageBodyHandler hdlr;
- @Before
- public void setUp() {
+ @BeforeEach
+ void setUp() {
hdlr = new GsonMessageBodyHandler();
}
@Test
- public void testIsWriteable() {
+ void testIsWriteable() {
// null media type
assertTrue(hdlr.isWriteable(null, null, null, null));
for (String subtype : subtypes) {
- assertTrue("writeable " + subtype, hdlr.isWriteable(null, null, null, new MediaType(GEN_TYPE, subtype)));
+ assertTrue(hdlr.isWriteable(null, null, null, new MediaType(GEN_TYPE, subtype)), "writeable " + subtype);
}
}
@Test
- public void testGetSize() {
+ void testGetSize() {
assertEquals(-1, hdlr.getSize(null, null, null, null, null));
}
@Test
- public void testWriteTo_testReadFrom() throws Exception {
+ void testWriteTo_testReadFrom() throws Exception {
ByteArrayOutputStream outstr = new ByteArrayOutputStream();
MyObject obj1 = new MyObject(10);
hdlr.writeTo(obj1, obj1.getClass(), CLASS_OBJ, null, null, null, outstr);
}
@Test
- public void testWriteTo_DifferentTypes() throws Exception {
+ void testWriteTo_DifferentTypes() throws Exception {
ByteArrayOutputStream outstr = new ByteArrayOutputStream();
// use a derived type, but specify the base type when writing
}
@Test
- public void testIsReadable() {
+ void testIsReadable() {
// null media type
assertTrue(hdlr.isReadable(null, null, null, null));
assertFalse(hdlr.isReadable(null, null, null, new MediaType(GEN_TYPE, null)));
for (String subtype : subtypes) {
- assertTrue("readable " + subtype, hdlr.isReadable(null, null, null, new MediaType(GEN_TYPE, subtype)));
+ assertTrue(hdlr.isReadable(null, null, null, new MediaType(GEN_TYPE, subtype)), "readable " + subtype);
}
}
@Test
- public void testReadFrom_DifferentTypes() throws Exception {
+ void testReadFrom_DifferentTypes() throws Exception {
ByteArrayOutputStream outstr = new ByteArrayOutputStream();
MyObject obj1 = new MyObject(10);
hdlr.writeTo(obj1, obj1.getClass(), CLASS_OBJ, null, null, null, outstr);
}
@Test
- public void testMapDouble() throws Exception {
+ void testMapDouble() throws Exception {
MyMap map = new MyMap();
map.props = new HashMap<>();
map.props.put("plainString", "def");
}
@Test
- public void testInterestingFields() throws IOException {
+ void testInterestingFields() throws IOException {
InterestingFields data = new InterestingFields();
data.instant = Instant.ofEpochMilli(1583249713500L);
data.uuid = UUID.fromString("a850cb9f-3c5e-417c-abfd-0679cdcd1ab0");
* ONAP
* ================================================================================
* Copyright (C) 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.
package org.onap.policy.common.gson;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.time.Instant;
import lombok.ToString;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class InstantAsMillisTypeAdapterTest {
+class InstantAsMillisTypeAdapterTest {
private static Gson gson =
new GsonBuilder().registerTypeAdapter(Instant.class, new InstantAsMillisTypeAdapter()).create();
@Test
- public void test() {
+ void test() {
InterestingFields data = new InterestingFields();
data.instant = Instant.ofEpochMilli(1583249713500L);
* 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.
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonParseException;
import java.time.Instant;
import lombok.ToString;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class InstantTypeAdapterTest {
+class InstantTypeAdapterTest {
private static Gson gson =
new GsonBuilder().registerTypeAdapter(Instant.class, new InstantTypeAdapter()).create();
@Test
- public void test() {
+ void test() {
InterestingFields data = new InterestingFields();
data.instant = Instant.ofEpochMilli(1583249713500L);
* ONAP
* ================================================================================
* Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
- * Modificaitons Copyright (C) 2023 Nordix Foundation.
+ * Modificaitons 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.
package org.onap.policy.common.gson;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+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 com.google.gson.FieldAttributes;
import com.google.gson.Gson;
import java.util.LinkedList;
import java.util.TreeMap;
import lombok.ToString;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
-public class JacksonExclusionStrategyTest {
+class JacksonExclusionStrategyTest {
private static JacksonExclusionStrategy strategy;
private static Gson gson;
- @BeforeClass
+ @BeforeAll
public static void setUpBeforeClass() {
strategy = new JacksonExclusionStrategy();
gson = new GsonBuilder().setExclusionStrategies(strategy).create();
}
@Test
- public void testWithGson() {
+ void testWithGson() {
Derived data = new Derived();
data.setId(10);
data.setText("some text");
}
@Test
- public void testShouldSkipField() throws Exception {
+ void testShouldSkipField() throws Exception {
// should skip every field of Data
assertTrue(strategy.shouldSkipField(new FieldAttributes(Data.class.getDeclaredField("id"))));
assertTrue(strategy.shouldSkipField(new FieldAttributes(Data.class.getDeclaredField("text"))));
}
@Test
- public void testShouldSkipClass() {
+ void testShouldSkipClass() {
assertFalse(strategy.shouldSkipClass(null));
assertFalse(strategy.shouldSkipClass(Object.class));
}
@Test
- public void testIsManaged() {
+ void testIsManaged() {
// these classes SHOULD be managed
Class<?>[] managed = {Data.class, Intfc.class, com.google.gson.TypeAdapter.class};
for (Class<?> clazz : managed) {
- assertTrue(clazz.getName(), JacksonExclusionStrategy.isManaged(clazz));
+ assertTrue(JacksonExclusionStrategy.isManaged(clazz), clazz.getName());
}
// generic classes should NOT be managed
MyMap.class, MyList.class, MyJson.class, GenericArrayType.class};
for (Class<?> clazz : unmanaged) {
- assertFalse(clazz.getName(), JacksonExclusionStrategy.isManaged(clazz));
+ assertFalse(JacksonExclusionStrategy.isManaged(clazz), clazz.getName());
}
}
return id;
}
- public void setId(int id) {
+ void setId(int id) {
this.id = id;
}
return text;
}
- public void setText(String text) {
+ void setText(String text) {
this.text = text;
}
}
return value;
}
- public void setValue(String value) {
+ void setValue(String value) {
this.value = value;
}
}
* 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.gson;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
+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.assertNull;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.util.ArrayList;
import java.util.List;
import lombok.ToString;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.gson.annotation.GsonJsonIgnore;
import org.onap.policy.common.gson.annotation.GsonJsonProperty;
-public class JacksonFieldAdapterFactoryTest {
+class JacksonFieldAdapterFactoryTest {
private static JacksonFieldAdapterFactory factory = new JacksonFieldAdapterFactory();
.registerTypeAdapterFactory(factory).create();
@Test
- public void testCreate() {
+ void testCreate() {
// unhandled types
assertNull(factory.create(gson, TypeToken.get(JsonElement.class)));
assertNull(factory.create(gson, TypeToken.get(NothingToSerialize.class)));
}
@Test
- public void testCreate_Lists() {
+ void testCreate_Lists() {
DataList lst = new DataList();
lst.theList = new ArrayList<>();
lst.theList.add(new Data(200, "text 20"));
}
@Test
- public void testCreate_OnlyOutProps() {
+ void testCreate_OnlyOutProps() {
InFieldIgnored data = new InFieldIgnored();
data.value = "out only";
}
@Test
- public void testCreate_OnlyInProps() {
+ void testCreate_OnlyInProps() {
OutFieldIgnored data = new OutFieldIgnored();
data.value = "in only";
this.text = text;
}
- public void setId(int id) {
+ void setId(int id) {
this.id = id;
}
}
* ONAP
* ================================================================================
* Copyright (C) 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.
package org.onap.policy.common.gson;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+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 com.google.gson.Gson;
import com.google.gson.JsonObject;
import java.util.Map;
import java.util.TreeMap;
import lombok.ToString;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.gson.annotation.GsonJsonAnyGetter;
import org.onap.policy.common.gson.annotation.GsonJsonAnySetter;
-public class JacksonHandlerTest {
+class JacksonHandlerTest {
@Test
- public void test() throws Exception {
+ void test() throws Exception {
JacksonHandler hdlr = new JacksonHandler();
assertTrue(hdlr.isReadable(null, null, null, MediaType.APPLICATION_JSON_TYPE));
}
@Test
- public void testMapDouble() throws Exception {
+ void testMapDouble() throws Exception {
MyMap map = new MyMap();
map.props = new HashMap<>();
map.props.put("plainString", "def");
* 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.gson;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+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.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.util.Map;
import java.util.TreeMap;
import lombok.ToString;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.gson.annotation.GsonJsonAnyGetter;
import org.onap.policy.common.gson.annotation.GsonJsonAnySetter;
import org.onap.policy.common.gson.annotation.GsonJsonIgnore;
import org.onap.policy.common.gson.annotation.GsonJsonProperty;
-public class JacksonMethodAdapterFactoryTest {
+class JacksonMethodAdapterFactoryTest {
private static JacksonMethodAdapterFactory factory = new JacksonMethodAdapterFactory();
.registerTypeAdapterFactory(factory).create();
@Test
- public void testCreate() {
+ void testCreate() {
// unhandled types
assertNull(factory.create(gson, TypeToken.get(JsonElement.class)));
assertNull(factory.create(gson, TypeToken.get(NothingToSerialize.class)));
dblget.overMap.put("getB", 110);
String result2 = gson.toJson(dblget);
- dblget.overMap.keySet().forEach(key -> assertTrue("over contains " + key, result2.contains(key)));
- der.map.keySet().forEach(key -> assertFalse("sub contains " + key, result2.contains(key)));
+ dblget.overMap.keySet().forEach(key -> assertTrue(result2.contains(key), "over contains " + key));
+ der.map.keySet().forEach(key -> assertFalse(result2.contains(key), "sub contains " + key));
// override of AnySetter
Map<String, Integer> map = new TreeMap<>();
* ONAP
* ================================================================================
* Copyright (C) 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.
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonParseException;
import java.time.LocalDateTime;
import lombok.ToString;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class LocalDateTimeTypeAdapterTest {
+class LocalDateTimeTypeAdapterTest {
private static Gson gson =
new GsonBuilder().registerTypeAdapter(LocalDateTime.class, new LocalDateTimeTypeAdapter()).create();
@Test
- public void test() {
+ void test() {
InterestingFields data = new InterestingFields();
data.date = LocalDateTime.of(2020, 2, 3, 4, 5, 6, 789000000);
* 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 static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonParseException;
import java.time.LocalDate;
import lombok.ToString;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class LocalDateTypeAdapterTest {
+class LocalDateTypeAdapterTest {
private static Gson gson =
new GsonBuilder().registerTypeAdapter(LocalDate.class, new LocalDateTypeAdapter()).create();
private static final String TEST_DATE = "2020-01-01";
@Test
- public void test() {
+ void test() {
InterestingFields data = new InterestingFields();
data.date = LocalDate.parse(TEST_DATE);
* ONAP
* ================================================================================
* 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.
package org.onap.policy.common.gson;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class MapDoubleAdapterFactoryTest {
+class MapDoubleAdapterFactoryTest {
private static Gson gson = new GsonBuilder().registerTypeAdapterFactory(new MapDoubleAdapterFactory()).create();
@Test
@SuppressWarnings("unchecked")
- public void testMap() {
+ void testMap() {
MyMap map = new MyMap();
map.data = new HashMap<>();
map.data.put("plainString", "def");
}
@Test
- public void testList() {
+ void testList() {
MyList list = new MyList();
list.data = new ArrayList<>();
list.data.add("ghi");
}
@Test
- public void test_ValueIsNotObject() {
+ void test_ValueIsNotObject() {
MyDoubleMap map = new MyDoubleMap();
map.data = new LinkedHashMap<>();
map.data.put("plainDouble", 13.5);
}
@Test
- public void test_KeyIsNotString() {
+ void test_KeyIsNotString() {
MyObjectMap map = new MyObjectMap();
map.data = new LinkedHashMap<>();
}
@Test
- public void test_ListValueIsNotObject() {
+ void test_ListValueIsNotObject() {
MyDoubleList list = new MyDoubleList();
list.data = new ArrayList<>();
list.data.add(13.5);
* 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 static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonParseException;
import java.time.OffsetDateTime;
import lombok.ToString;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class OffsetDateTimeAdapterTest {
+class OffsetDateTimeAdapterTest {
private static Gson gson =
new GsonBuilder().registerTypeAdapter(OffsetDateTime.class, new OffsetDateTimeTypeAdapter()).create();
private static final String TEST_DATE = "2020-01-01T12:00:00.999+05:00";
@Test
- public void test() {
+ void test() {
InterestingFields data = new InterestingFields();
data.date = OffsetDateTime.parse(TEST_DATE);
* 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 static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonParseException;
import java.time.OffsetTime;
import lombok.ToString;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class OffsetTimeTypeAdapterTest {
+class OffsetTimeTypeAdapterTest {
private static Gson gson =
new GsonBuilder().registerTypeAdapter(OffsetTime.class, new OffsetTimeTypeAdapter()).create();
private static final String TEST_TIME = "12:00:00.999+05:00";
@Test
- public void test() {
+ void test() {
InterestingFields data = new InterestingFields();
data.time = OffsetTime.parse(TEST_TIME);
* 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 static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class StringTypeAdapterTest {
+class StringTypeAdapterTest {
private static Gson gson = new GsonBuilder().registerTypeAdapter(MyData.class, new MyAdapter()).create();
private static final int TEST_NUM1 = 10;
private static final int TEST_NUM3 = 30;
@Test
- public void test() {
+ void test() {
InterestingFields data = new InterestingFields();
data.data1 = new MyData(TEST_NUM1);
data.data2 = null;
* 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 static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonParseException;
import java.time.ZoneOffset;
import lombok.ToString;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class ZoneOffsetTypeAdapterTest {
+class ZoneOffsetTypeAdapterTest {
private static Gson gson =
new GsonBuilder().registerTypeAdapter(ZoneOffset.class, new ZoneOffsetTypeAdapter()).create();
private static final String TEST_ZONE = "+05:00";
@Test
- public void test() {
+ void test() {
InterestingFields data = new InterestingFields();
data.zone = ZoneOffset.of(TEST_ZONE);
* 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.
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import lombok.ToString;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class ZonedDateTimeTypeAdapterTest {
+class ZonedDateTimeTypeAdapterTest {
private static Gson gson =
new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeTypeAdapter()).create();
@Test
- public void test() {
+ void test() {
InterestingFields data = new InterestingFields();
data.date = ZonedDateTime.of(2020, 2, 3, 4, 5, 6, 789000000, ZoneId.of("US/Eastern"));
* ONAP
* ================================================================================
* Copyright (C) 2019-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.
package org.onap.policy.common.gson.internal;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+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.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.List;
-import org.junit.After;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.gson.JacksonExclusionStrategy;
import org.onap.policy.common.gson.annotation.GsonJsonProperty;
import org.onap.policy.common.gson.internal.Adapter.Factory;
import org.onap.policy.common.gson.internal.DataAdapterFactory.DerivedData;
import org.springframework.test.util.ReflectionTestUtils;
-public class AdapterTest {
+class AdapterTest {
private static final String GET_INVALID_NAME = "get$InvalidName";
private static final String SET_INVALID_NAME = "set$InvalidName";
private static final String EMPTY_ALIAS = "emptyAlias";
private Data dataField;
- @BeforeClass
+ @BeforeAll
public static void setUpBeforeClass() {
saveFactory = (Factory) ReflectionTestUtils.getField(Adapter.class, FACTORY_FIELD);
}
- @After
- public void tearDown() {
+ @AfterEach
+ void tearDown() {
ReflectionTestUtils.setField(Adapter.class, FACTORY_FIELD, saveFactory);
}
@Test
- public void testIsManagedField() {
+ void testIsManagedField() {
assertTrue(Adapter.isManaged(field(VALUE_NAME)));
// return an invalid field name
}
@Test
- public void testIsManagedMethod() {
+ void testIsManagedMethod() {
assertTrue(Adapter.isManaged(mget(GET_VALUE_NAME)));
// return an invalid method name
}
@Test
- public void testAdapterField_Converter() {
+ void testAdapterField_Converter() {
Adapter adapter = new Adapter(gson, field("dataField"));
// first, write something of type Data
@Test
@SuppressWarnings("unchecked")
- public void testAdapterField_Converter_List() {
+ void testAdapterField_Converter_List() {
listField = DataAdapterFactory.makeList();
Adapter adapter = new Adapter(gson, field("listField"));
}
@Test
- public void testAdapterMethod_Converter() throws Exception {
+ void testAdapterMethod_Converter() throws Exception {
listField = DataAdapterFactory.makeList();
Method getter = mget("getMyList");
}
@Test
- public void testGetPropName_testGetFullName_testMakeError() {
+ void testGetPropName_testGetFullName_testMakeError() {
// test field
Adapter adapter = new Adapter(gson, field(VALUE_NAME));
}
@Test
- public void testToJsonTree() {
+ void testToJsonTree() {
Adapter adapter = new Adapter(gson, field(VALUE_NAME));
JsonElement tree = adapter.toJsonTree("hello");
}
@Test
- public void testFromJsonTree() {
+ void testFromJsonTree() {
Adapter adapter = new Adapter(gson, field(VALUE_NAME));
assertEquals("world", adapter.fromJsonTree(new JsonPrimitive("world")));
}
@Test
- public void testDetmPropName() {
+ void testDetmPropName() {
assertEquals(EMPTY_ALIAS, Adapter.detmPropName(field(EMPTY_ALIAS)));
assertEquals("name-with-alias", Adapter.detmPropName(field("nameWithAlias")));
assertEquals("unaliased", Adapter.detmPropName(field("unaliased")));
}
@Test
- public void testDetmGetterPropName() {
+ void testDetmGetterPropName() {
assertEquals(EMPTY_ALIAS, Adapter.detmGetterPropName(mget("getEmptyAlias")));
assertEquals("get-with-alias", Adapter.detmGetterPropName(mget("getWithAlias")));
assertEquals("plain", Adapter.detmGetterPropName(mget("getPlain")));
}
@Test
- public void testDetmSetterPropName() {
+ void testDetmSetterPropName() {
assertEquals(EMPTY_ALIAS, Adapter.detmSetterPropName(mset("setEmptyAlias")));
assertEquals("set-with-alias", Adapter.detmSetterPropName(mset("setWithAlias")));
assertEquals("plain", Adapter.detmSetterPropName(mset("setPlain")));
}
@Test
- public void testGetQualifiedNameField() throws Exception {
+ void testGetQualifiedNameField() throws Exception {
assertEquals(MY_NAME + ".value", Adapter.getQualifiedName(AdapterTest.class.getDeclaredField(VALUE_NAME)));
}
@Test
- public void testGetQualifiedNameMethod() {
+ void testGetQualifiedNameMethod() {
assertEquals(MY_NAME + GET_VALUE, Adapter.getQualifiedName(mget(GET_VALUE_NAME)));
}
* 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.gson.internal;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.gson.JacksonExclusionStrategy;
import org.onap.policy.common.gson.internal.DataAdapterFactory.Data;
-public class AnyGetterSerializerTest {
+class AnyGetterSerializerTest {
private static DataAdapterFactory dataAdapter = new DataAdapterFactory();
*
* @throws Exception if an error occurs
*/
- @Before
- public void setUp() throws Exception {
+ @BeforeEach
+ void setUp() throws Exception {
set = new HashSet<>(Arrays.asList("id", "value"));
ser = new AnyGetterSerializer(gson, set, MapData.class.getDeclaredMethod("getTheMap"));
}
@Test
- public void testAddToTree_testCopyLiftedItems() {
+ void testAddToTree_testCopyLiftedItems() {
JsonObject tree = new JsonObject();
tree.addProperty("hello", "world");
}
@Test
- public void testAddToTree_NullMap() {
+ void testAddToTree_NullMap() {
JsonObject tree = new JsonObject();
tree.addProperty("hello", "world");
}
@Test
- public void testAddToTree_NotAnObject() throws Exception {
+ void testAddToTree_NotAnObject() throws Exception {
ser = new AnyGetterSerializer(gson, set, NotAnObject.class.getDeclaredMethod("getNonMap"));
JsonObject tree = new JsonObject();
* 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.gson.internal;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.gson.JacksonExclusionStrategy;
import org.onap.policy.common.gson.internal.DataAdapterFactory.Data;
-public class AnySetterDeserializerTest {
+class AnySetterDeserializerTest {
private static DataAdapterFactory dataAdapter = new DataAdapterFactory();
*
* @throws Exception if an error occurs
*/
- @Before
- public void setUp() throws Exception {
+ @BeforeEach
+ void setUp() throws Exception {
set = new HashSet<>(Arrays.asList("id", "value"));
deser = new AnySetterDeserializer(gson, set,
MapData.class.getDeclaredMethod("setItem", String.class, List.class));
}
@Test
- public void testAnySetterDeserializer() {
+ void testAnySetterDeserializer() {
JsonObject json = new JsonObject();
// these should not be copied
* 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.gson.internal;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
import com.google.gson.JsonParseException;
import java.lang.reflect.Field;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.stream.Collectors;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.gson.annotation.GsonJsonAnyGetter;
import org.onap.policy.common.gson.annotation.GsonJsonAnySetter;
import org.onap.policy.common.gson.annotation.GsonJsonIgnore;
import org.onap.policy.common.gson.annotation.GsonJsonProperty;
-public class ClassWalkerTest {
+class ClassWalkerTest {
private static final String SET_OVERRIDE = ".setOverride";
private static final String INVALID_FIELD_NAME = "invalidFieldName";
/**
* Set up.
*/
- @Before
- public void setUp() {
+ @BeforeEach
+ void setUp() {
walker = new MyWalker();
}
@Test
- public void testExamineClassOfQ_testExamineField_testExamineInField_testExamineOutField() {
+ void testExamineClassOfQ_testExamineField_testExamineInField_testExamineOutField() {
walker.walkClassHierarchy(DerivedFromBottom.class);
assertEquals("[Intfc1, Intfc2, Intfc1, Intfc3, Bottom, DerivedFromBottom]", walker.classes.toString());
}
@Test
- public void testHasAnyGetter() {
+ void testHasAnyGetter() {
walker.walkClassHierarchy(Object.class);
assertNull(walker.getAnyGetter());
assertNull(walker.getAnySetter());
}
@Test
- public void testHasAnySetter() {
+ void testHasAnySetter() {
walker.walkClassHierarchy(Object.class);
assertNull(walker.getAnySetter());
assertNull(walker.getAnyGetter());
}
@Test
- public void testExamineMethod() {
+ void testExamineMethod() {
walker.walkClassHierarchy(DerivedFromData.class);
assertEquals("[Data, DerivedFromData]", walker.classes.toString());
}
@Test
- public void testExamineMethod_AnyGetter() {
+ void testExamineMethod_AnyGetter() {
walker.walkClassHierarchy(AnyGetterOverride.class);
assertNotNull(walker.getAnyGetter());
}
@Test
- public void testExamineMethod_AnySetter() {
+ void testExamineMethod_AnySetter() {
walker.walkClassHierarchy(AnySetterOverride.class);
assertNotNull(walker.getAnySetter());
}
@Test
- public void testGetInNotIgnored_testGetOutNotIgnored() {
+ void testGetInNotIgnored_testGetOutNotIgnored() {
walker.walkClassHierarchy(DerivedFromData.class);
assertEquals("[id, onlyIn, text, value]", new TreeSet<>(walker.getInNotIgnored()).toString());
* ONAP
* ================================================================================
* 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.
package org.onap.policy.common.gson.internal;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import java.util.List;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.gson.JacksonExclusionStrategy;
import org.onap.policy.common.gson.internal.DataAdapterFactory.Data;
-public class FieldDeserializerTest {
+class FieldDeserializerTest {
private static final String TEXT_FIELD_NAME = "text";
private static final String LIST_FIELD_NAME = "listField";
private static final String INITIAL_VALUE = "initial value";
private List<Data> listField;
@Test
- public void testGetFromTree() throws Exception {
+ void testGetFromTree() throws Exception {
deser = new FieldDeserializer(gson, FieldDeserializerTest.class.getDeclaredField(TEXT_FIELD_NAME));
JsonObject json = new JsonObject();
}
@Test
- public void testGetFromTree_SetEx() throws Exception {
+ void testGetFromTree_SetEx() throws Exception {
deser = new FieldDeserializer(gson, FieldDeserializerTest.class.getDeclaredField(TEXT_FIELD_NAME)) {
@Override
public Object fromJsonTree(JsonElement tree) {
* ONAP
* ================================================================================
* 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.
package org.onap.policy.common.gson.internal;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import java.util.List;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.gson.JacksonExclusionStrategy;
import org.onap.policy.common.gson.internal.DataAdapterFactory.Data;
-public class FieldSerializerTest {
+class FieldSerializerTest {
private static final String TEXT_FIELD_NAME = "text";
private static final String LIST_FIELD_NAME = "listField";
}
@Test
- public void testAddToTree_GetEx() throws Exception {
+ void testAddToTree_GetEx() throws Exception {
ser = new FieldSerializer(gson, FieldSerializerTest.class.getDeclaredField(TEXT_FIELD_NAME)) {
@Override
protected Object getFromObject(Object source) throws IllegalAccessException {
* 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.gson.internal;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.util.ArrayList;
import java.util.List;
import lombok.ToString;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
-public class JacksonTypeAdapterTest {
+class JacksonTypeAdapterTest {
private static final String HELLO = "hello";
private static final String WORLD = "world";
/**
* Initializes the previously defined fields.
*/
- @Before
- public void setUp() {
+ @BeforeEach
+ void setUp() {
// create list of serializers, one for "id" and one for "value"
sers = new ArrayList<>(2);
sers.add(new NamedSer(HELLO) {
}
@Test
- public void testWriteJsonWriterT() throws Exception {
+ void testWriteJsonWriterT() throws Exception {
Data data = new Data("abc", "def");
StringWriter wtr = new StringWriter();
* @throws Exception if an error occurs
*/
@Test
- public void testWriteJsonWriterT_NotAnObject() throws Exception {
+ void testWriteJsonWriterT_NotAnObject() throws Exception {
TypeAdapter<String> delegate = gson.getAdapter(String.class);
JacksonTypeAdapter<String> stringAdapter = new JacksonTypeAdapter<>(gson, delegate, sers, desers);
}
@Test
- public void testReadJsonReader() throws Exception {
+ void testReadJsonReader() throws Exception {
Data data = adapter
.read(new JsonReader(new StringReader("{'hello':'four','world':'score'}".replace('\'', '"'))));
* @throws Exception if an error occurs
*/
@Test
- public void testReadJsonReader_NotAnObject() throws Exception {
+ void testReadJsonReader_NotAnObject() throws Exception {
TypeAdapter<String> delegate = gson.getAdapter(String.class);
JacksonTypeAdapter<String> stringAdapter = new JacksonTypeAdapter<>(gson, delegate, sers, desers);
* 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.gson.internal;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import com.google.gson.Gson;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class LifterTest {
+class LifterTest {
private static Gson gson = new Gson();
@Test
- public void testLifter_testShouldLift() throws Exception {
+ void testLifter_testShouldLift() throws Exception {
Set<String> set = new HashSet<>(Arrays.asList("abc", "def"));
Lifter lifter = new Lifter(gson, set, LifterTest.class.getDeclaredMethod("getValue"), String.class);
* ONAP
* ================================================================================
* 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.
package org.onap.policy.common.gson.internal;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import com.google.gson.Gson;
import com.google.gson.JsonParseException;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class MethodAdapterTest {
+class MethodAdapterTest {
private static final Gson gson = new Gson();
private String saved;
@Test
- public void testMethodAdapter_testInvoke() throws Exception {
+ void testMethodAdapter_testInvoke() throws Exception {
MethodAdapter adapter =
new MethodAdapter(gson, MethodAdapterTest.class.getDeclaredMethod("getValue"), String.class);
assertEquals("hello", adapter.invoke(this));
return "hello";
}
- public void setValue(String val) {
+ void setValue(String val) {
saved = val;
}
}
* ONAP
* ================================================================================
* 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.
package org.onap.policy.common.gson.internal;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonNull;
import com.google.gson.JsonObject;
import java.util.List;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.gson.JacksonExclusionStrategy;
import org.onap.policy.common.gson.internal.DataAdapterFactory.Data;
-public class MethodDeserializerTest {
+class MethodDeserializerTest {
private static final String PROP_NAME = "text";
private static final String METHOD_NAME = "setText";
private static final String INITIAL_VALUE = "initial value";
private List<Data> listField;
@Test
- public void testGetFromTree() throws Exception {
+ void testGetFromTree() throws Exception {
deser = new MethodDeserializer(gson, MethodDeserializerTest.class.getDeclaredMethod(METHOD_NAME, String.class));
// non-existent value - should not overwrite
* ONAP
* ================================================================================
* 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.
package org.onap.policy.common.gson.internal;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import java.util.List;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.gson.JacksonExclusionStrategy;
import org.onap.policy.common.gson.internal.DataAdapterFactory.Data;
-public class MethodSerializerTest {
+class MethodSerializerTest {
private static final String PROP_NAME = "text";
private static final String METHOD_NAME = "getText";
private List<Data> listField;
@Test
- public void testAddToTree() throws Exception {
+ void testAddToTree() throws Exception {
ser = new MethodSerializer(gson, MethodSerializerTest.class.getDeclaredMethod(METHOD_NAME));
// serialize null value first
JsonElement tree = ser.toJsonTree(listField);
assertTrue(dataAdapter.isDataWritten());
- assertEquals(DataAdapterFactory.ENCODED_LIST, tree.toString());
+ assertEquals(DataAdapterFactory.ENCODED_LIST, tree.toString());
}
protected String getText() {
</plugin>
</plugins>
</reporting>
+ <dependencies>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-api</artifactId>
+ </dependency>
+ </dependencies>
</project>