ONAP Policy Engine - Common Modules
================================================================================
Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved.
+ Modifications Copyright (C) 2023 Nordix Foundation.
================================================================================
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.powermock</groupId>
- <artifactId>powermock-api-mockito2</artifactId>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
* ================================================================================
* 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.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
-import org.powermock.reflect.Whitebox;
import org.slf4j.MDC;
+import org.springframework.test.util.ReflectionTestUtils;
public class PolicyLoggerTest {
@Test
public void testInfoMessageCodesStringStringArray() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.info(MessageCodes.ERROR_DATA_ISSUE, "str1", "str2");
Mockito.verify(mockLogger).info(MessageCodes.ERROR_DATA_ISSUE, "str2");
}
@Test
public void testInfoStringString() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.info("str1", "str2");
Mockito.verify(mockLogger, never()).info(Mockito.anyString(), Mockito.anyString());
Mockito.when(mockLogger.isInfoEnabled()).thenReturn(true);
@Test
public void testInfoObject() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.info("str1");
Mockito.verify(mockLogger).info(MessageCodes.GENERAL_INFO, "str1");
}
@Test
public void testInfoMessageCodesThrowableStringArray() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.info(MessageCodes.ERROR_DATA_ISSUE, new NullPointerException(), "str1", "str2");
Mockito.verify(mockLogger).info((MessageCodes) Mockito.any(),
Mockito.startsWith("str1:str2:java.lang.NullPointerException"));
@Test
public void testInfoMessageCodesStringThrowableStringArray() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.info(MessageCodes.ERROR_DATA_ISSUE, "PolicyLoggerTest", new NullPointerException(), "str1",
"str2");
Mockito.verify(mockLogger).info((MessageCodes) Mockito.any(),
@Test
public void testWarnMessageCodesStringStringArray() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.warn(MessageCodes.ERROR_DATA_ISSUE, "str1");
Mockito.verify(mockLogger).warn(MessageCodes.ERROR_DATA_ISSUE);
}
@Test
public void testWarnStringString() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.warn("str1", "str2");
Mockito.verify(mockLogger, never()).info(Mockito.anyString(), Mockito.anyString());
Mockito.when(mockLogger.isWarnEnabled()).thenReturn(true);
@Test
public void testWarnObject() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.warn(1);
Mockito.verify(mockLogger).warn(MessageCodes.GENERAL_WARNING, "1");
}
@Test
public void testWarnMessageCodesThrowableStringArray() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.warn(MessageCodes.ERROR_DATA_ISSUE, new NullPointerException(), "str1", "str2");
Mockito.verify(mockLogger).warn((MessageCodes) Mockito.any(),
Mockito.startsWith("str1:str2:java.lang.NullPointerException"));
@Test
public void testWarnMessageCodesStringThrowableStringArray() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.warn(MessageCodes.ERROR_DATA_ISSUE, "PolicyLoggerTest", new NullPointerException(), "str1",
"str2");
Mockito.verify(mockLogger).warn((MessageCodes) Mockito.any(),
@Test
public void testWarnString() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.warn("str1");
Mockito.verify(mockLogger).warn(MessageCodes.GENERAL_WARNING, "str1");
}
@Test
public void testErrorStringString() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "errorLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "errorLogger", mockLogger);
PolicyLogger.error("str1", "str2");
Mockito.verify(mockLogger, never()).info(Mockito.anyString(), Mockito.anyString());
Mockito.when(mockLogger.isErrorEnabled()).thenReturn(true);
@Test
public void testErrorString() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "errorLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "errorLogger", mockLogger);
PolicyLogger.error("str1");
Mockito.verify(mockLogger).error(MessageCodes.GENERAL_ERROR, "str1");
assertEquals("ERROR", MDC.get("ErrorCategory"));
@Test
public void testErrorObject() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "errorLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "errorLogger", mockLogger);
PolicyLogger.error(1);
Mockito.verify(mockLogger).error(MessageCodes.GENERAL_ERROR, "1");
assertEquals("ERROR", MDC.get("ErrorCategory"));
@Test
public void testErrorMessageCodesThrowableStringArray() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "errorLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "errorLogger", mockLogger);
PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, new NullPointerException(), "str1", "str2");
Mockito.verify(mockLogger).error((MessageCodes) Mockito.any(),
Mockito.startsWith("str1:str2:java.lang.NullPointerException"));
@Test
public void testErrorMessageCodesStringThrowableStringArray() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "errorLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "errorLogger", mockLogger);
PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "PolicyLoggerTest", new NullPointerException(), "str1",
"str2");
Mockito.verify(mockLogger).error((MessageCodes) Mockito.any(),
@Test
public void testErrorMessageCodesStringArray() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "errorLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "errorLogger", mockLogger);
PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "str1", "str2");
Mockito.verify(mockLogger).error(MessageCodes.ERROR_DATA_ISSUE, "str1", "str2");
}
@Test
public void testDebugMessageCodesStringArray() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.debug(MessageCodes.ERROR_DATA_ISSUE, "str1", "str2");
Mockito.verify(mockLogger).debug(MessageCodes.ERROR_DATA_ISSUE, "str1", "str2");
}
@Test
public void testDebugStringString() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.debug("str1", "str2");
Mockito.verify(mockLogger, never()).info(Mockito.anyString(), Mockito.anyString());
Mockito.when(mockLogger.isDebugEnabled()).thenReturn(true);
@Test
public void testDebugString() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.debug("str1");
Mockito.verify(mockLogger).debug("str1");
}
@Test
public void testDebugObject() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.debug(1);
Mockito.verify(mockLogger).debug("{}", 1);
}
@Test
public void testAuditStringObject() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "auditLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "auditLogger", mockLogger);
PolicyLogger.audit("PolicyLoggerTest", 1);
Mockito.verify(mockLogger, never()).info(Mockito.anyString(), Mockito.anyString());
Mockito.when(mockLogger.isInfoEnabled()).thenReturn(true);
@Test
public void testAuditObject() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "auditLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "auditLogger", mockLogger);
PolicyLogger.audit(1);
assertEquals("", MDC.get("ClassName"));
assertEquals("COMPLETE", MDC.get("StatusCode"));
@Test
public void testDebugMessageCodesThrowableStringArray() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.debug(MessageCodes.ERROR_DATA_ISSUE, new NullPointerException(), "str1", "str2");
Mockito.verify(mockLogger).debug((MessageCodes) Mockito.any(),
Mockito.startsWith("str1:str2:java.lang.NullPointerException"));
@Test
public void testDebugMessageCodesStringThrowableStringArray() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.debug(MessageCodes.ERROR_DATA_ISSUE, "PolicyLoggerTest", new NullPointerException(), "str1",
"str2");
Mockito.verify(mockLogger).debug((MessageCodes) Mockito.any(),
@Test
public void testIsDebugEnabled() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
Mockito.when(mockLogger.isDebugEnabled()).thenReturn(false).thenReturn(true);
assertFalse(PolicyLogger.isDebugEnabled());
assertTrue(PolicyLogger.isDebugEnabled());
@Test
public void testIsErrorEnabled() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "errorLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "errorLogger", mockLogger);
Mockito.when(mockLogger.isErrorEnabled()).thenReturn(false).thenReturn(true);
assertFalse(PolicyLogger.isErrorEnabled());
assertTrue(PolicyLogger.isErrorEnabled());
@Test
public void testIsWarnEnabled() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
Mockito.when(mockLogger.isWarnEnabled()).thenReturn(false).thenReturn(true);
assertFalse(PolicyLogger.isWarnEnabled());
assertTrue(PolicyLogger.isWarnEnabled());
@Test
public void testIsInfoEnabled1() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
Mockito.when(mockLogger.isInfoEnabled()).thenReturn(false).thenReturn(true);
assertFalse(PolicyLogger.isInfoEnabled1());
assertTrue(PolicyLogger.isInfoEnabled1());
@Test
public void testIsAuditEnabled() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
Mockito.when(mockLogger.isInfoEnabled()).thenReturn(false).thenReturn(true);
assertFalse(PolicyLogger.isAuditEnabled());
assertTrue(PolicyLogger.isAuditEnabled());
@Test
public void testIsInfoEnabled() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
Mockito.when(mockLogger.isInfoEnabled()).thenReturn(false).thenReturn(true);
assertFalse(PolicyLogger.isInfoEnabled());
assertTrue(PolicyLogger.isInfoEnabled());
@Test
public void testTraceStringString() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.trace("str1", "str2");
Mockito.verify(mockLogger).trace(MessageCodes.GENERAL_INFO, "str2");
}
@Test
public void testTraceObject() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.trace(1);
Mockito.verify(mockLogger).trace("{}", 1);
}
@Test
public void testRecordMetricEventString() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "metricsLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "metricsLogger", mockLogger);
PolicyLogger.recordMetricEvent("eventId");
Mockito.verify(mockLogger).info(Mockito.eq(MessageCodes.RULE_METRICS_INFO), Mockito.anyString(),
Mockito.eq("eventId"));
@Test
public void testMetricsString() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "metricsLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "metricsLogger", mockLogger);
PolicyLogger.metrics("str1");
Mockito.verify(mockLogger).info(Mockito.eq(MessageCodes.RULE_METRICS_INFO), Mockito.anyString(),
Mockito.eq("str1"));
@Test
public void testMetricsStringObject() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "metricsLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "metricsLogger", mockLogger);
PolicyLogger.metrics("PolicyLoggerTest", 1);
Mockito.verify(mockLogger, never()).info(Mockito.anyString(), Mockito.anyString());
Mockito.when(mockLogger.isInfoEnabled()).thenReturn(true);
@Test
public void testMetricsObject() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "metricsLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "metricsLogger", mockLogger);
PolicyLogger.metrics(1);
Mockito.verify(mockLogger).info(Mockito.eq(MessageCodes.RULE_METRICS_INFO), Mockito.anyString(),
Mockito.eq("1"));
@Test
public void testMetricsPrintln() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "metricsLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "metricsLogger", mockLogger);
PolicyLogger.metricsPrintln("str1");
Mockito.verify(mockLogger).info("str1");
}
* ================================================================================
* 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.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import org.mockito.Mockito;
import org.onap.policy.common.logging.eelf.MessageCodes;
import org.onap.policy.common.logging.eelf.PolicyLogger;
-import org.powermock.reflect.Whitebox;
import org.slf4j.MDC;
+import org.springframework.test.util.ReflectionTestUtils;
public class EelfLoggerTest {
@Test
public void testDebugObject() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
eelfLogger.debug("message");
Mockito.verify(mockLogger, never()).info(Mockito.anyString(), Mockito.anyString());
Mockito.when(mockLogger.isDebugEnabled()).thenReturn(true);
@Test
public void testErrorObject() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "errorLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "errorLogger", mockLogger);
eelfLogger.error("message");
Mockito.verify(mockLogger, never()).info(Mockito.anyString(), Mockito.anyString());
Mockito.when(mockLogger.isErrorEnabled()).thenReturn(true);
@Test
public void testInfoObject() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
eelfLogger.info("message");
Mockito.verify(mockLogger, never()).info(Mockito.anyString(), Mockito.anyString());
Mockito.when(mockLogger.isInfoEnabled()).thenReturn(true);
@Test
public void testWarnObject() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
eelfLogger.warn("message");
Mockito.verify(mockLogger, never()).info(Mockito.anyString(), Mockito.anyString());
Mockito.when(mockLogger.isWarnEnabled()).thenReturn(true);
@Test
public void testTraceObject() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
eelfLogger.trace("message");
Mockito.verify(mockLogger).trace(MessageCodes.GENERAL_INFO, "message");
}
@Test
public void testIsDebugEnabled() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
Mockito.when(mockLogger.isDebugEnabled()).thenReturn(false).thenReturn(true);
assertFalse(eelfLogger.isDebugEnabled());
assertTrue(eelfLogger.isDebugEnabled());
@Test
public void testIsInfoEnabled() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
Mockito.when(mockLogger.isInfoEnabled()).thenReturn(false).thenReturn(true);
assertFalse(eelfLogger.isInfoEnabled());
assertTrue(eelfLogger.isInfoEnabled());
@Test
public void testIsWarnEnabled() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
Mockito.when(mockLogger.isWarnEnabled()).thenReturn(false).thenReturn(true);
assertFalse(eelfLogger.isWarnEnabled());
assertTrue(eelfLogger.isWarnEnabled());
@Test
public void testIsErrorEnabled() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "errorLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "errorLogger", mockLogger);
Mockito.when(mockLogger.isErrorEnabled()).thenReturn(false).thenReturn(true);
assertFalse(eelfLogger.isErrorEnabled());
assertTrue(eelfLogger.isErrorEnabled());
@Test
public void testIsTraceEnabled() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
Mockito.when(mockLogger.isDebugEnabled()).thenReturn(false).thenReturn(true);
assertFalse(eelfLogger.isTraceEnabled());
assertTrue(eelfLogger.isTraceEnabled());
@Test
public void testDebugObjectThrowable() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
eelfLogger.debug("message", new NullPointerException());
Mockito.verify(mockLogger).debug((MessageCodes) Mockito.any(),
Mockito.startsWith("message:java.lang.NullPointerException"));
@Test
public void testErrorObjectThrowable() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "errorLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "errorLogger", mockLogger);
eelfLogger.error("message", new NullPointerException());
Mockito.verify(mockLogger).error((MessageCodes) Mockito.any(),
Mockito.startsWith("message:java.lang.NullPointerException"));
@Test
public void testInfoObjectThrowable() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
eelfLogger.info("message", new NullPointerException());
Mockito.verify(mockLogger, never()).info(Mockito.anyString(), Mockito.anyString());
Mockito.when(mockLogger.isInfoEnabled()).thenReturn(true);
@Test
public void testWarnObjectThrowable() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
eelfLogger.warn("message", new NullPointerException());
Mockito.verify(mockLogger).warn((MessageCodes) Mockito.any(),
Mockito.startsWith("message:java.lang.NullPointerException"));
@Test
public void testTraceObjectThrowable() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
eelfLogger.trace("message", new NullPointerException());
Mockito.verify(mockLogger).trace("{}", "message");
}
@Test
public void testAuditObjectThrowable() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "auditLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "auditLogger", mockLogger);
eelfLogger.audit("message", new NullPointerException());
Mockito.verify(mockLogger).info("{}", "message");
}
@Test
public void testMetrics() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "metricsLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "metricsLogger", mockLogger);
eelfLogger.metrics(1);
Mockito.verify(mockLogger, never()).info(Mockito.anyString(), Mockito.anyString());
Mockito.when(mockLogger.isInfoEnabled()).thenReturn(true);
@Test
public void testErrorMessageCodesThrowableStringArray() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "errorLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "errorLogger", mockLogger);
eelfLogger.error(MessageCodes.GENERAL_ERROR, new NullPointerException(), "str1", "str2");
Mockito.verify(mockLogger).error((MessageCodes) Mockito.any(),
Mockito.startsWith("str1:str2:java.lang.NullPointerException"));
@Test
public void testErrorMessageCodesStringArray() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "errorLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "errorLogger", mockLogger);
eelfLogger.error(MessageCodes.GENERAL_ERROR, "str1", "str2");
Mockito.verify(mockLogger).error(MessageCodes.GENERAL_ERROR, "str1", "str2");
@Test
public void testWarnMessageCodesStringArray() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
eelfLogger.warn(MessageCodes.GENERAL_ERROR, "str1", "str2");
Mockito.verify(mockLogger).warn(MessageCodes.GENERAL_ERROR, "str1", "str2");
}
@Test
public void testWarnMessageCodesThrowableStringArray() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
+ ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
eelfLogger.warn(MessageCodes.GENERAL_ERROR, new NullPointerException(), "str1", "str2");
Mockito.verify(mockLogger).warn((MessageCodes) Mockito.any(),
Mockito.startsWith("str1:str2:java.lang.NullPointerException"));
* ================================================================================
* 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.
* ================================================================================
* 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.Set;
import org.junit.Test;
import org.onap.policy.common.logging.flexlogger.FlexLogger.PropertiesCallBack;
-import org.powermock.reflect.Whitebox;
+import org.springframework.test.util.ReflectionTestUtils;
public class FlexLoggerTest {
@Test
public void testGetLoggerClassOfQEelf() {
- Whitebox.setInternalState(FlexLogger.class, "loggerType", LoggerType.EELF);
+ ReflectionTestUtils.setField(FlexLogger.class, "loggerType", LoggerType.EELF);
Logger logger = FlexLogger.getLogger((Class<?>) null);
assertSame(logger, FlexLogger.getLogger((Class<?>) null));
assertNotEquals(logger, FlexLogger.getLogger(String.class));
@Test
public void testGetLoggerClassOfQSystemOut() {
- Whitebox.setInternalState(FlexLogger.class, "loggerType", LoggerType.SYSTEMOUT);
+ ReflectionTestUtils.setField(FlexLogger.class, "loggerType", LoggerType.SYSTEMOUT);
Logger logger = FlexLogger.getLogger(this.getClass());
assertSame(logger, FlexLogger.getLogger(this.getClass()));
}
@Test
public void testGetLoggerStringEelf() {
- Whitebox.setInternalState(FlexLogger.class, "loggerType", LoggerType.EELF);
+ ReflectionTestUtils.setField(FlexLogger.class, "loggerType", LoggerType.EELF);
Logger logger = FlexLogger.getLogger();
assertSame(logger, FlexLogger.getLogger());
}
@Test
public void testGetLoggerStringSystemOut() {
- Whitebox.setInternalState(FlexLogger.class, "loggerType", LoggerType.SYSTEMOUT);
+ ReflectionTestUtils.setField(FlexLogger.class, "loggerType", LoggerType.SYSTEMOUT);
Logger logger = FlexLogger.getLogger();
assertSame(logger, FlexLogger.getLogger());
}
@Test
public void testGetLoggerClassOfQBooleanEelf() {
- Whitebox.setInternalState(FlexLogger.class, "loggerType", LoggerType.EELF);
+ 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() {
- Whitebox.setInternalState(FlexLogger.class, "loggerType", LoggerType.SYSTEMOUT);
+ 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() {
- Whitebox.setInternalState(FlexLogger.class, "loggerType", LoggerType.EELF);
+ ReflectionTestUtils.setField(FlexLogger.class, "loggerType", LoggerType.EELF);
Logger logger = FlexLogger.getLogger(true);
assertSame(logger, FlexLogger.getLogger(true));
}
@Test
public void testGetLoggerStringBooleanSystemOut() {
- Whitebox.setInternalState(FlexLogger.class, "loggerType", LoggerType.SYSTEMOUT);
+ ReflectionTestUtils.setField(FlexLogger.class, "loggerType", LoggerType.SYSTEMOUT);
Logger logger = FlexLogger.getLogger(true);
assertSame(logger, FlexLogger.getLogger(true));
}
* ONAP-Logging
* ================================================================================
* Copyright (C) 2018-2020 Ericsson, AT&T. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
import org.junit.BeforeClass;
import org.junit.Test;
import org.onap.policy.common.logging.flexlogger.PropertyUtil.Listener;
-import org.powermock.reflect.Whitebox;
+import org.springframework.test.util.ReflectionTestUtils;
public class PropertyUtilTest {
private static final String TIMER_FIELD = "timer";
private static final File FILE = new File("target/test.properties");
private static Timer saveTimer;
-
+
private TimerTask task;
private Timer timer;
private TestListener testListener;
-
+
@BeforeClass
public static void setUpBeforeClass() {
- saveTimer = Whitebox.getInternalState(PropertyUtil.LazyHolder.class, TIMER_FIELD);
-
+ saveTimer = (Timer) ReflectionTestUtils.getField(PropertyUtil.LazyHolder.class, TIMER_FIELD);
+
}
-
+
@AfterClass
public static void tearDownAfterClass() {
- Whitebox.setInternalState(PropertyUtil.LazyHolder.class, TIMER_FIELD, saveTimer);
-
+ ReflectionTestUtils.setField(PropertyUtil.LazyHolder.class, TIMER_FIELD, saveTimer);
+
}
/**
public void setUp() throws IOException {
task = null;
timer = mock(Timer.class);
- Whitebox.setInternalState(PropertyUtil.LazyHolder.class, TIMER_FIELD, timer);
-
+ ReflectionTestUtils.setField(PropertyUtil.LazyHolder.class, TIMER_FIELD, timer);
+
doAnswer(args -> {
task = args.getArgument(0, TimerTask.class);
return null;
}).when(timer).schedule(any(TimerTask.class), anyLong(), anyLong());
-
+
testListener = new TestListener();
-
+
FileOutputStream fileOutputStream = new FileOutputStream(FILE);
Properties properties = new Properties();
properties.put("testProperty", "testValue");
PropertyUtil.stopListening(FILE, testListener);
FILE.delete();
}
-
+
@Test
public void testTimer() {
assertNotNull(saveTimer);
* ONAP
* ================================================================================
* Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
assertThat(result.getResult()).doesNotContain("blank").contains("annotatedValueMap", "\" \"", "-10");
}
+ @SuppressWarnings("deprecation")
@Test
public void testValidateField_testGetValue() {
// unannotated
ONAP Policy Engine - Common Modules
================================================================================
Copyright (C) 2018-2021 AT&T Intellectual Property. All rights reserved.
- Modifications Copyright (C) 2019 Nordix Foundation.
+ Modifications Copyright (C) 2019,2023 Nordix Foundation.
================================================================================
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.powermock</groupId>
- <artifactId>powermock-api-mockito2</artifactId>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
* ONAP
* ================================================================================
* Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
+ * Modificaitons Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
/**
* Used to verify that JsonElements are not managed.
*/
+ @SuppressWarnings("deprecation")
public static class MyJson extends JsonElement {
@Override
public JsonElement deepCopy() {
* ONAP
* ================================================================================
* Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import org.onap.policy.common.gson.internal.Adapter.Factory;
import org.onap.policy.common.gson.internal.DataAdapterFactory.Data;
import org.onap.policy.common.gson.internal.DataAdapterFactory.DerivedData;
-import org.powermock.reflect.Whitebox;
+import org.springframework.test.util.ReflectionTestUtils;
public class AdapterTest {
private static final String GET_INVALID_NAME = "get$InvalidName";
@BeforeClass
public static void setUpBeforeClass() {
- saveFactory = Whitebox.getInternalState(Adapter.class, FACTORY_FIELD);
+ saveFactory = (Factory) ReflectionTestUtils.getField(Adapter.class, FACTORY_FIELD);
}
@After
public void tearDown() {
- Whitebox.setInternalState(Adapter.class, FACTORY_FIELD, saveFactory);
+ ReflectionTestUtils.setField(Adapter.class, FACTORY_FIELD, saveFactory);
}
@Test
// return an invalid field name
Factory factory = mock(Factory.class);
when(factory.getName(any(Field.class))).thenReturn("$invalidFieldName");
- Whitebox.setInternalState(Adapter.class, FACTORY_FIELD, factory);
+ ReflectionTestUtils.setField(Adapter.class, FACTORY_FIELD, factory);
assertFalse(Adapter.isManaged(field(VALUE_NAME)));
}
// return an invalid method name
Factory factory = mock(Factory.class);
- Whitebox.setInternalState(Adapter.class, FACTORY_FIELD, factory);
+ ReflectionTestUtils.setField(Adapter.class, FACTORY_FIELD, factory);
when(factory.getName(any(Method.class))).thenReturn(GET_INVALID_NAME);
assertFalse(Adapter.isManaged(mget(GET_VALUE_NAME)));
// return an invalid field name
Factory factory = mock(Factory.class);
when(factory.getName(any(Field.class))).thenReturn("$invalidFieldName");
- Whitebox.setInternalState(Adapter.class, FACTORY_FIELD, factory);
+ ReflectionTestUtils.setField(Adapter.class, FACTORY_FIELD, factory);
assertEquals(null, Adapter.detmPropName(field(VALUE_NAME)));
}
// return an invalid method name
Factory factory = mock(Factory.class);
- Whitebox.setInternalState(Adapter.class, FACTORY_FIELD, factory);
+ ReflectionTestUtils.setField(Adapter.class, FACTORY_FIELD, factory);
when(factory.getName(any(Method.class))).thenReturn(GET_INVALID_NAME);
assertEquals(null, Adapter.detmGetterPropName(mget(GET_VALUE_NAME)));
// return an invalid method name
Factory factory = mock(Factory.class);
- Whitebox.setInternalState(Adapter.class, FACTORY_FIELD, factory);
+ ReflectionTestUtils.setField(Adapter.class, FACTORY_FIELD, factory);
when(factory.getName(any(Method.class))).thenReturn(SET_INVALID_NAME);
assertEquals(null, Adapter.detmSetterPropName(mset(SET_VALUE_NAME)));
ONAP Policy Engine - Common Modules
================================================================================
Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved.
+ Modifications Copyright (C) 2023 Nordix Foundation.
================================================================================
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.powermock</groupId>
- <artifactId>powermock-api-mockito2</artifactId>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
* Integrity Audit
* ================================================================================
* Copyright (C) 2017-2019, 2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import org.onap.policy.common.utils.test.log.logback.ExtractAppender;
import org.onap.policy.common.utils.time.CurrentTime;
import org.onap.policy.common.utils.time.TestTime;
-import org.powermock.reflect.Whitebox;
import org.slf4j.LoggerFactory;
+import org.springframework.test.util.ReflectionTestUtils;
/**
* All JUnits are designed to run in the local development environment where they have write
* @param dbUrl the URL to the DB
* @throws IOException if an IO error occurs
*/
+ @SuppressWarnings("unchecked")
protected static void setUpBeforeClass(String dbUrl) throws IOException {
// truncate the logs
IntegrityAuditTestBase.dbUrl = dbUrl;
// save data that we have to restore at the end of the test
- savedTime = Whitebox.getInternalState(AuditorTime.class, TIME_SUPPLY_FIELD);
+ savedTime = (Supplier<CurrentTime>) ReflectionTestUtils.getField(AuditorTime.class, TIME_SUPPLY_FIELD);
savedDebugLevel = debugLogger.getLevel();
savedErrorLevel = errorLogger.getLevel();
// done
em = emf.createEntityManager();
- Whitebox.setInternalState(AuditorTime.class, TIME_SUPPLY_FIELD, timeSupplier);
+ ReflectionTestUtils.setField(AuditorTime.class, TIME_SUPPLY_FIELD, timeSupplier);
debugLogger.setLevel(Level.DEBUG);
errorLogger.setLevel(Level.ERROR);
}
IntegrityAudit.setUnitTesting(false);
- Whitebox.setInternalState(AuditorTime.class, TIME_SUPPLY_FIELD, savedTime);
+ ReflectionTestUtils.setField(AuditorTime.class, TIME_SUPPLY_FIELD, savedTime);
debugLogger.setLevel(savedDebugLevel);
errorLogger.setLevel(savedErrorLevel);
ONAP Policy Engine - Common Modules
================================================================================
Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved.
+ Modifications Copyright (C) 2023 Nordix Foundation.
================================================================================
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
<dependencies>
<dependency>
- <groupId>org.powermock</groupId>
- <artifactId>powermock-api-mockito2</artifactId>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
* Integrity Monitor
* ================================================================================
* Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
+ * Modificaitons Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.powermock.reflect.Whitebox;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.test.util.ReflectionTestUtils;
public class AllSeemsWellTest extends IntegrityMonitorTestBase {
private static final String ALL_SEEMS_WELL_MSG = "'AllSeemsWellTest - ALLSEEMSWELL'";
}
};
- Whitebox.setInternalState(IntegrityMonitor.class, IM_INSTANCE_FIELD, im);
+ ReflectionTestUtils.setField(IntegrityMonitor.class, IM_INSTANCE_FIELD, im);
}
@After
* Integrity Monitor
* ================================================================================
* Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
+ * Modificaitons Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import org.onap.policy.common.im.jpa.ForwardProgressEntity;
import org.onap.policy.common.im.jpa.ResourceRegistrationEntity;
import org.onap.policy.common.im.jpa.StateManagementEntity;
-import org.powermock.reflect.Whitebox;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.test.util.ReflectionTestUtils;
/*
* All JUnits are designed to run in the local development environment
}
};
- Whitebox.setInternalState(IntegrityMonitor.class, IM_INSTANCE_FIELD, im);
+ ReflectionTestUtils.setField(IntegrityMonitor.class, IM_INSTANCE_FIELD, im);
// wait for the monitor thread to start
waitCycles(1);
* Integrity Audit
* ================================================================================
* Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
+ * Modificaitons Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import org.onap.policy.common.utils.test.log.logback.ExtractAppender;
import org.onap.policy.common.utils.time.CurrentTime;
import org.onap.policy.common.utils.time.TestTime;
-import org.powermock.reflect.Whitebox;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.test.util.ReflectionTestUtils;
/**
* All JUnits are designed to run in the local development environment where they have write
IntegrityMonitor.setUnitTesting(true);
testTime = new TestTime();
- Whitebox.setInternalState(MonitorTime.class, TIME_INSTANCE_FIELD, testTime);
+ ReflectionTestUtils.setField(MonitorTime.class, TIME_INSTANCE_FIELD, testTime);
properties = new Properties();
properties.put(IntegrityMonitorProperties.DB_DRIVER, DB_DRIVER);
systemProps.put(JMX_PORT_PROP, savedJmxPort);
}
- Whitebox.setInternalState(MonitorTime.class, TIME_INSTANCE_FIELD, savedTime);
+ ReflectionTestUtils.setField(MonitorTime.class, TIME_INSTANCE_FIELD, savedTime);
IntegrityMonitor.setUnitTesting(false);
============LICENSE_START=======================================================
Copyright (C) 2022 Ericsson. All rights reserved.
Modifications Copyright (C) 2018-2022 AT&T Intellectual Property. All rights reserved.
- Modifications Copyright (C) 2019-2022 Nordix Foundation.
+ Modifications Copyright (C) 2019-2023 Nordix Foundation.
Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
================================================================================
Licensed under the Apache License, Version 2.0 (the "License");
</dependency>
<dependency>
- <groupId>org.powermock</groupId>
- <artifactId>powermock-api-mockito2</artifactId>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
* Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2018 Samsung Electronics Co., Ltd.
* Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
- * Copyright (C) 2022 Nordix Foundation.
+ * Modifications Copyright (C) 2022-2023 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.UUID;
import java.util.concurrent.TimeUnit;
import org.apache.commons.lang3.StringUtils;
-import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerConfig;
* ONAP
* ================================================================================
* Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
- * Copyright (C) 2022 Nordix Foundation.
+ * Modifications Copyright (C) 2022-2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import com.google.re2j.Pattern;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
-import org.apache.commons.lang3.StringUtils;
import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams.TopicParamsBuilder;
import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
* ONAP Policy Engine - Common Modules
* ================================================================================
* Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
package org.onap.policy.common.endpoints.event.comm.bus;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.onap.policy.common.endpoints.properties.PolicyEndPointProperties.PROPERTY_KAFKA_SOURCE_TOPICS;
-import static org.onap.policy.common.endpoints.properties.PolicyEndPointProperties.PROPERTY_TOPIC_EFFECTIVE_TOPIC_SUFFIX;
import java.util.Arrays;
import java.util.Deque;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import org.onap.policy.common.endpoints.event.comm.Topic;
import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
-import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
public class KafkaTopicSourceFactoryTest extends KafkaTopicFactoryTestBase<KafkaTopicSource> {
* policy-endpoints
* ================================================================================
* Copyright (C) 2018-2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import org.onap.policy.common.endpoints.event.comm.bus.internal.BusConsumer.FetchingBusConsumer;
import org.onap.policy.common.endpoints.event.comm.bus.internal.BusConsumer.KafkaConsumerWrapper;
import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
-import org.powermock.reflect.Whitebox;
+import org.springframework.test.util.ReflectionTestUtils;
public class BusConsumerTest extends TopicTestBase {
when(inner.fetch()).thenReturn(lst);
CambriaConsumerWrapper cons = new CambriaConsumerWrapper(builder.build());
- Whitebox.setInternalState(cons, "consumer", inner);
+ ReflectionTestUtils.setField(cons, "consumer", inner);
assertEquals(lst, IteratorUtils.toList(cons.fetch().iterator()));
* ============LICENSE_START=======================================================
* policy-endpoints
* ================================================================================
- * Copyright (C) 2022 Nordix Foundation.
+ * Copyright (C) 2022-2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import org.junit.Test;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.endpoints.event.comm.bus.TopicTestBase;
-import org.onap.policy.common.utils.gson.GsonTestUtils;
public class InlineKafkaTopicSinkTest extends TopicTestBase {
private InlineKafkaTopicSink sink;
* ================================================================================
* Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import org.onap.policy.common.gson.GsonMessageBodyHandler;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.network.NetworkUtil;
-import org.powermock.reflect.Whitebox;
+import org.springframework.test.util.ReflectionTestUtils;
public class RestServerTest {
private static final String METRICS_URI = "/metrics";
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception {
- saveFactory = Whitebox.getInternalState(RestServer.class, FACTORY_FIELD);
+ saveFactory = (Factory) ReflectionTestUtils.getField(RestServer.class, FACTORY_FIELD);
realPort = NetworkUtil.allocPort();
*/
@AfterClass
public static void tearDownAfterClass() {
- Whitebox.setInternalState(RestServer.class, FACTORY_FIELD, saveFactory);
+ ReflectionTestUtils.setField(RestServer.class, FACTORY_FIELD, saveFactory);
realRest.stop();
}
when(server1.getName()).thenReturn(SERVER1);
when(server2.getName()).thenReturn(SERVER2);
- Whitebox.setInternalState(RestServer.class, FACTORY_FIELD, factory);
+ ReflectionTestUtils.setField(RestServer.class, FACTORY_FIELD, factory);
}
@Test
ONAP Policy Engine - Common Modules
================================================================================
Copyright (C) 2018-2021 AT&T Intellectual Property. All rights reserved.
+ Modificaitons Copyright (C) 2023 Nordix Foundation.
================================================================================
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
<version>${project.version}</version>
</dependency>
<dependency>
- <groupId>org.powermock</groupId>
- <artifactId>powermock-api-mockito2</artifactId>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
* ONAP Policy Engine - Common Modules
* ================================================================================
* Copyright (C) 2018-2020 AT&T Intellectual Property. All rights reserved.
+ * Modificaitons Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import org.junit.BeforeClass;
import org.junit.Test;
import org.onap.policy.common.utils.io.Serializer.Factory;
-import org.powermock.reflect.Whitebox;
+import org.springframework.test.util.ReflectionTestUtils;
public class SerializerTest {
private static final String FACTORY = "factory";
@BeforeClass
public static void setUpBeforeClass() {
- saveFactory = Whitebox.getInternalState(Serializer.class, FACTORY);
+ saveFactory = (Factory) ReflectionTestUtils.getField(Serializer.class, FACTORY);
}
@AfterClass
public static void tearDownAfterClass() {
- Whitebox.setInternalState(Serializer.class, FACTORY, saveFactory);
+ ReflectionTestUtils.setField(Serializer.class, FACTORY, saveFactory);
}
@Before
* @param factory new factory to be set
*/
private void setFactory(Factory factory) {
- Whitebox.setInternalState(Serializer.class, FACTORY, factory);
+ ReflectionTestUtils.setField(Serializer.class, FACTORY, factory);
}
/**
ONAP Policy Engine - Common Modules
================================================================================
Copyright (C) 2018-2021 AT&T Intellectual Property. All rights reserved.
- Modifications Copyright (C) 2021 Nordix Foundation.
+ Modifications Copyright (C) 2021,2023 Nordix Foundation.
================================================================================
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>org.powermock</groupId>
- <artifactId>powermock-api-mockito2</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.powermock</groupId>
- <artifactId>powermock-module-junit4</artifactId>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>