summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/test/java
diff options
context:
space:
mode:
authorvempo <vitaliy.emporopulo@amdocs.com>2018-04-04 15:59:32 +0300
committerOren Kleks <orenkle@amdocs.com>2018-04-08 04:51:30 +0000
commit14345a8e2cb17d002bcea294130ac9fb64b6b83e (patch)
tree9d87800ab351d53259367c13404f74b07f3ddc13 /openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/test/java
parent6040ee42d045f4dfaaf29a4cdd9ed93c6f20cff9 (diff)
Fixed proxy instead of resource type in audit
Change-Id: I1b3c22105f27e9d3dee0947815d32eb453a56831 Issue-ID: SDC-1190 Signed-off-by: vempo <vitaliy.emporopulo@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/test/java')
-rw-r--r--openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/test/java/org/openecomp/sdc/logging/servlet/jaxrs/LoggingRequestFilterTest.java90
1 files changed, 77 insertions, 13 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/test/java/org/openecomp/sdc/logging/servlet/jaxrs/LoggingRequestFilterTest.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/test/java/org/openecomp/sdc/logging/servlet/jaxrs/LoggingRequestFilterTest.java
index 0e0be017df..579f41c3e6 100644
--- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/test/java/org/openecomp/sdc/logging/servlet/jaxrs/LoggingRequestFilterTest.java
+++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/test/java/org/openecomp/sdc/logging/servlet/jaxrs/LoggingRequestFilterTest.java
@@ -21,6 +21,7 @@ import static org.easymock.EasyMock.anyString;
import static org.openecomp.sdc.logging.servlet.jaxrs.LoggingRequestFilter.START_TIME_KEY;
import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
import java.util.UUID;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ResourceInfo;
@@ -44,13 +45,19 @@ import org.testng.annotations.Test;
@PrepareForTest({LoggingContext.class, ContextData.class})
public class LoggingRequestFilterTest extends PowerMockTestCase {
- private static final Class RESOURCE_CLASS = MockResource.class;
- private static final Method RESOURCE_METHOD = MockResource.class.getDeclaredMethods()[0];
- private static final String RESOURCE_NAME = RESOURCE_CLASS.getName() + "." + RESOURCE_METHOD.getName();
+ private static final Class DEFAULT_RESOURCE_CLASS = MockResource.class;
+ private static final Method DEFAULT_RESOURCE_METHOD = MockResource.class.getDeclaredMethods()[0];
+ private static final String DEFAULT_SERVICE_NAME =
+ formatServiceName(DEFAULT_RESOURCE_CLASS, DEFAULT_RESOURCE_METHOD);
private static final String RANDOM_REQUEST_ID = UUID.randomUUID().toString();
+
private static final String RANDOM_PARTNER_NAME = UUID.randomUUID().toString();
+ private static String formatServiceName(Class resourceClass, Method resourceMethod) {
+ return resourceClass.getName() + "#" + resourceMethod.getName();
+ }
+
/**
* Verify all mocks after each test.
*/
@@ -74,9 +81,9 @@ public class LoggingRequestFilterTest extends PowerMockTestCase {
}
@Test
- public void serviceNamePopulatedWhenThereIsMatchingResource() {
+ public void serviceNamePopulatedWhenThereIsMatchingResourceAndConcreteType() {
- mockContextDataBuilder(null, RESOURCE_NAME, null);
+ mockContextDataBuilder(null, DEFAULT_SERVICE_NAME, null);
mockLoggingContext();
LoggingRequestFilter filter = new LoggingRequestFilter();
@@ -88,9 +95,54 @@ public class LoggingRequestFilterTest extends PowerMockTestCase {
}
@Test
+ public void serviceNamePopulatedWhenThereIsMatchingResourceAndJavaProxyType() throws NoSuchMethodException {
+
+ Object proxyResource = Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
+ new Class<?>[] {MockResource.class}, (proxy, method, arguments) -> null);
+
+ final String serviceName = formatServiceName(MockResource.class, DEFAULT_RESOURCE_METHOD);
+
+ mockContextDataBuilder(null, serviceName, null);
+ mockLoggingContext();
+
+ LoggingRequestFilter filter = new LoggingRequestFilter();
+
+ Class<?> proxyClass = proxyResource.getClass();
+ Method proxyMethod =
+ proxyClass.getMethod(DEFAULT_RESOURCE_METHOD.getName(), DEFAULT_RESOURCE_METHOD.getParameterTypes());
+
+ filter.setResource(mockResource(proxyClass, proxyMethod));
+
+ filter.filter(mockContainerRequestContext(
+ new RequestIdHeader(null),
+ new PartnerHeader(null)));
+ }
+
+ @Test
+ public void serviceNameIncludesProxyClassnameWhenJavaProxyTypeAndNoMatchingInterface() {
+
+ Object proxyResource = Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
+ new Class<?>[] {Comparable.class}, (proxy, method, arguments) -> null);
+
+ final String serviceName = formatServiceName(proxyResource.getClass(), DEFAULT_RESOURCE_METHOD);
+
+ mockContextDataBuilder(null, serviceName, null);
+ mockLoggingContext();
+
+ LoggingRequestFilter filter = new LoggingRequestFilter();
+
+ Class<?> proxyClass = proxyResource.getClass();
+ filter.setResource(mockResource(proxyClass, DEFAULT_RESOURCE_METHOD));
+
+ filter.filter(mockContainerRequestContext(
+ new RequestIdHeader(null),
+ new PartnerHeader(null)));
+ }
+
+ @Test
public void partnerNamePopulatedWhenPresentInDefaultHeader() {
- mockContextDataBuilder(null, RESOURCE_NAME, RANDOM_PARTNER_NAME);
+ mockContextDataBuilder(null, DEFAULT_SERVICE_NAME, RANDOM_PARTNER_NAME);
mockLoggingContext();
LoggingRequestFilter filter = new LoggingRequestFilter();
@@ -105,7 +157,7 @@ public class LoggingRequestFilterTest extends PowerMockTestCase {
public void partnerNamePopulatedWhenPresentInCustomHeader() {
final String partnerHeader = "x-partner-header";
- mockContextDataBuilder(null, RESOURCE_NAME, RANDOM_PARTNER_NAME);
+ mockContextDataBuilder(null, DEFAULT_SERVICE_NAME, RANDOM_PARTNER_NAME);
mockLoggingContext();
LoggingRequestFilter filter = new LoggingRequestFilter();
@@ -120,7 +172,7 @@ public class LoggingRequestFilterTest extends PowerMockTestCase {
@Test
public void requestIdPopulatedWhenPresentInDefaultHeader() {
- mockContextDataBuilder(RANDOM_REQUEST_ID, RESOURCE_NAME, null);
+ mockContextDataBuilder(RANDOM_REQUEST_ID, DEFAULT_SERVICE_NAME, null);
mockLoggingContext();
LoggingRequestFilter filter = new LoggingRequestFilter();
@@ -135,7 +187,7 @@ public class LoggingRequestFilterTest extends PowerMockTestCase {
public void requestIdPopulatedWhenPresentInCustomHeader() {
final String requestIdHeader = "x-request-id";
- mockContextDataBuilder(RANDOM_REQUEST_ID, RESOURCE_NAME, null);
+ mockContextDataBuilder(RANDOM_REQUEST_ID, DEFAULT_SERVICE_NAME, null);
mockLoggingContext();
LoggingRequestFilter filter = new LoggingRequestFilter();
@@ -148,10 +200,14 @@ public class LoggingRequestFilterTest extends PowerMockTestCase {
}
private ResourceInfo mockResource() {
+ return mockResource(DEFAULT_RESOURCE_CLASS, DEFAULT_RESOURCE_METHOD);
+ }
+
+ private ResourceInfo mockResource(Class resourceType, Method resourceMethod) {
ResourceInfo resource = EasyMock.mock(ResourceInfo.class);
//noinspection unchecked
- EasyMock.expect(resource.getResourceClass()).andReturn(RESOURCE_CLASS);
- EasyMock.expect(resource.getResourceMethod()).andReturn(RESOURCE_METHOD);
+ EasyMock.expect(resource.getResourceClass()).andReturn(resourceType);
+ EasyMock.expect(resource.getResourceMethod()).andReturn(resourceMethod);
EasyMock.replay(resource);
return resource;
}
@@ -252,11 +308,19 @@ public class LoggingRequestFilterTest extends PowerMockTestCase {
}
}
- private static class MockResource {
+ private interface MockResource {
@SuppressWarnings("EmptyMethod")
- void process() {
+ void process();
+ }
+
+ private static class MockResourceImpl implements MockResource {
+
+ @Override
+ public void process() {
// no-op
}
}
+
+
} \ No newline at end of file