diff options
-rw-r--r-- | vid-app-common/src/main/java/org/onap/vid/controller/WebConfig.java | 10 | ||||
-rw-r--r-- | vid-automation/pom.xml | 4 | ||||
-rw-r--r-- | vid-automation/src/test/java/org/onap/vid/more/AuditLoggerTest.java | 65 |
3 files changed, 76 insertions, 3 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/WebConfig.java b/vid-app-common/src/main/java/org/onap/vid/controller/WebConfig.java index 6936d0a71..6c5595ca3 100644 --- a/vid-app-common/src/main/java/org/onap/vid/controller/WebConfig.java +++ b/vid-app-common/src/main/java/org/onap/vid/controller/WebConfig.java @@ -29,6 +29,7 @@ import java.io.File; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import javax.servlet.ServletContext; +import org.onap.logging.filter.spring.LoggingInterceptor; import org.onap.portalsdk.core.util.SystemProperties; import org.onap.vid.aai.AaiClient; import org.onap.vid.aai.AaiClientInterface; @@ -68,6 +69,8 @@ import org.onap.vid.utils.Logging; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.togglz.core.manager.FeatureManager; import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; @@ -77,7 +80,7 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2; @EnableSwagger2 @Configuration -public class WebConfig { +public class WebConfig implements WebMvcConfigurer { /** * Gets the object mapper. @@ -216,4 +219,9 @@ public class WebConfig { int threadsCount = defaultIfNull(Integer.parseInt(SystemProperties.getProperty(VidProperties.VID_THREAD_COUNT)), 1); return Executors.newFixedThreadPool(threadsCount); } + + @Override + public void addInterceptors(InterceptorRegistry registry) { + registry.addInterceptor(new LoggingInterceptor()); + } } diff --git a/vid-automation/pom.xml b/vid-automation/pom.xml index 6f2ae22c2..e2ef865f4 100644 --- a/vid-automation/pom.xml +++ b/vid-automation/pom.xml @@ -191,8 +191,8 @@ </dependency> <dependency> <groupId>org.hamcrest</groupId> - <artifactId>hamcrest-all</artifactId> - <version>1.3</version> + <artifactId>java-hamcrest</artifactId> + <version>2.0.0.0</version> </dependency> <dependency> <groupId>org.apache.commons</groupId> diff --git a/vid-automation/src/test/java/org/onap/vid/more/AuditLoggerTest.java b/vid-automation/src/test/java/org/onap/vid/more/AuditLoggerTest.java new file mode 100644 index 000000000..b27d6a8af --- /dev/null +++ b/vid-automation/src/test/java/org/onap/vid/more/AuditLoggerTest.java @@ -0,0 +1,65 @@ +package org.onap.vid.more; + +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.allOf; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.equalToIgnoringCase; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.collection.IsMapContaining.hasKey; +import static vid.automation.test.services.SimulatorApi.RegistrationStrategy.APPEND; +import static vid.automation.test.services.SimulatorApi.RegistrationStrategy.CLEAR_THEN_SET; +import static vid.automation.test.services.SimulatorApi.registerExpectationFromPreset; + +import java.util.List; +import java.util.function.Supplier; +import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetVpnsByType; +import org.onap.vid.api.BaseApiTest; +import org.onap.vid.more.LoggerFormatTest.LogName; +import org.springframework.http.ResponseEntity; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; +import vid.automation.test.services.SimulatorApi; + +public class AuditLoggerTest extends BaseApiTest { + + private final String ECOMP_REQUEST_ID_ECHO = "x-ecomp-requestid-echo"; + + @BeforeClass + public void login() { + super.login(); + } + + @BeforeMethod + public void resetPreset() { + SimulatorApi.registerExpectation("create_new_instance/aai_get_full_subscribers.json", CLEAR_THEN_SET); + } + + @Test + public void aaiController2$GetVpnList_requestIdIsAuditedInEntryAndInExit() { + registerExpectationFromPreset(new PresetAAIGetVpnsByType(), APPEND); + String requestId = getRequestId(() -> restTemplate.getForEntity(buildUri("aai_get_vpn_list"), String.class)); + + assertThat("request id must be found in exactly two rows", getRequestLogLines(requestId), + contains( + allOf(containsString(requestId), containsString("Entering")), + allOf(containsString(requestId), containsString("Exiting")) + )); + } + + private List<String> getRequestLogLines(String requestId) { + return LoggerFormatTest.getRequestLogLines(requestId, LogName.audit2019, restTemplate, uri); + } + + private String getRequestId(Supplier<ResponseEntity<?>> request) { + ResponseEntity<?> response = request.get(); + + assertThat(response.getHeaders(), hasKey(equalToIgnoringCase(ECOMP_REQUEST_ID_ECHO))); + List<String> requestIds = response.getHeaders().get(ECOMP_REQUEST_ID_ECHO); + + assertThat(requestIds, hasSize(1)); + return requestIds.get(0); + } + +} |