package org.onap.vid.more;
-import com.google.common.collect.ImmutableList;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.hasItem;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalToIgnoringCase;
+import static org.onap.vid.api.CategoryParametersApiTest.MAINTENANCE_CATEGORY_PARAMETER;
+import static org.onap.vid.api.pProbeMsoApiTest.MSO_CREATE_CONFIGURATION;
+import static org.springframework.http.HttpHeaders.AUTHORIZATION;
+import static vid.automation.test.services.SimulatorApi.RegistrationStrategy.APPEND;
+
import com.google.common.collect.ImmutableMap;
+import java.util.List;
+import java.util.UUID;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.junit.Assert;
import org.onap.vid.api.BaseApiTest;
import org.onap.vid.api.OperationalEnvironmentControllerApiTest;
import org.onap.vid.api.ServiceInstanceMsoApiTest;
-import org.springframework.http.*;
+import org.onap.vid.more.LoggerFormatTest.LogName;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import vid.automation.test.services.SimulatorApi;
-import java.util.List;
-import java.util.UUID;
-
-import static org.hamcrest.CoreMatchers.*;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.onap.vid.api.CategoryParametersApiTest.GET_CATEGORY_PARAMETER_PROPERTIES;
-import static org.onap.vid.api.pProbeMsoApiTest.MSO_CREATE_CONFIGURATION;
-import static org.springframework.http.HttpHeaders.AUTHORIZATION;
-import static vid.automation.test.services.SimulatorApi.RegistrationStrategy.APPEND;
-
public class RequestIdFilterInstalled extends BaseApiTest {
/*
Clients unit-tests.
*/
- private static final String ECOMP_REQUEST_ID = "x-ecomp-requestid";
- private final String ECOMP_REQUEST_ID_ECHO = ECOMP_REQUEST_ID + "-echo";
+ private static final String REQUEST_ID_HEADER = "x-onap-requestid";
+ private final String ECOMP_REQUEST_ID_ECHO = "x-ecomp-requestid-echo";
@BeforeClass
public void login() {
}
@Test
- public void frontendApi_doGET_RequestIdReceived() throws InterruptedException {
+ public void frontendApi_doGET_RequestIdReceived() {
final Pair<HttpEntity, String> responseAndUuid = makeRequest(
HttpMethod.GET,
null,
OperationalEnvironmentControllerApiTest.GET_CLOUD_RESOURCES_REQUEST_STATUS
);
- assertThatUuidInResponseAndUuidIsInARecentLog(responseAndUuid);
+ assertThatUuidInResponseAndUuidIsInARecentLog(LogName.audit2019, responseAndUuid);
}
@Test
- public void frontendApi_doPOST_RequestIdReceived() throws InterruptedException {
+ public void frontendApi_doPOST_RequestIdReceived() {
final Pair<HttpEntity, String> responseAndUuid = makeRequest(
HttpMethod.POST,
"{}",
ServiceInstanceMsoApiTest.DEACTIVATE_OK_JSON
);
- assertThatUuidInResponseAndUuidIsInARecentLog(responseAndUuid);
+ assertThatUuidInResponseAndUuidIsInARecentLog(LogName.audit2019, responseAndUuid);
}
@Test
"/" + MSO_CREATE_CONFIGURATION,
"i'm not a json"
);
- assertThatUuidInResponseAndUuidIsInARecentLog(responseAndUuid);
+ assertThatUuidInResponseAndUuidIsInARecentLog(LogName.error, responseAndUuid);
}
@Test(groups = { "worksOnlyWithLocalhostVID" })
- public void mopOwningEntityApi_doGET_RequestIdReceived() throws InterruptedException {
+ public void mopOwningEntityApi_doGET_RequestIdReceived() {
final Pair<HttpEntity, String> responseAndUuid = makeRequest(
HttpMethod.GET,
- "/" + GET_CATEGORY_PARAMETER_PROPERTIES + "?familyName=PARAMETER_STANDARDIZATION",
+ "/" + MAINTENANCE_CATEGORY_PARAMETER + "?familyName=PARAMETER_STANDARDIZATION",
null
);
- assertThatUuidInResponseAndUuidIsInARecentLog(responseAndUuid);
+ assertThatUuidInResponseAndUuidIsInARecentLog(LogName.audit2019, responseAndUuid);
/*
test should be for:
}
@Test
- public void schedulerApi_doPOST_RequestIdReceived() throws InterruptedException {
+ public void schedulerApi_doPOST_RequestIdReceived() {
final String anyInstanceId = "any instance id";
SimulatorApi.registerExpectation(
"/change-management/workflow/" + anyInstanceId,
"{}"
);
- assertThatUuidInResponseAndUuidIsInARecentLog(responseAndUuid);
+ assertThatUuidInResponseAndUuidIsInARecentLog(LogName.audit2019, responseAndUuid);
}
final Pair<HttpEntity, String> responseAndUuid = makeRequest(
HttpMethod.GET, "/healthCheck", null
);
- assertThatUuidInResponseAndUuidIsInARecentLog(responseAndUuid);
+ assertThatUuidInResponseAndUuidIsInARecentLog(LogName.audit2019, responseAndUuid);
}
- private void assertThatUuidInResponseAndUuidIsInARecentLog(Pair<HttpEntity, String> responseAndUuid) {
+ private void assertThatUuidInResponseAndUuidIsInARecentLog(LogName logName, Pair<HttpEntity, String> responseAndUuid) {
assertThatResponseHasUuid(responseAndUuid.getLeft(), responseAndUuid.getRight());
- assertThatTermIsInARecentLog(responseAndUuid.getRight());
+ assertThatTermIsInARecentLog(logName, responseAndUuid.getRight());
}
private void assertThatResponseHasUuid(HttpEntity response, String uuid) {
// id" filter, which is great!
Assert.assertNotNull(response);
List<String> ecompRequestIdHeaderValues = response.getHeaders().get(ECOMP_REQUEST_ID_ECHO);
- Assert.assertNotNull(ecompRequestIdHeaderValues);
- Assert.assertTrue(ecompRequestIdHeaderValues.contains(uuid));
+ assertThat(ecompRequestIdHeaderValues, hasItem(equalToIgnoringCase(uuid)));
}
- private void assertThatTermIsInARecentLog(String uuid) {
- final ImmutableList<String> logLines = ImmutableList.of(
- LoggerFormatTest.getLogLines("audit", 20, 0, restTemplate, uri),
- LoggerFormatTest.getLogLines("error", 20, 0, restTemplate, uri)
- );
+ private void assertThatTermIsInARecentLog(LogName logName, String uuid) {
+ final String logLines = LoggerFormatTest.getLogLines(logName, 20, 0, restTemplate, uri);
- // Assert that audit *OR* error has the uuid
- assertThat("uuid not found in any log", logLines, hasItem(containsString(uuid)));
+ assertThat("uuid not found in any log", logLines, containsString(uuid));
}
private Pair<HttpEntity, String> makeRequest(HttpMethod httpMethod, String url, String body) {
private Pair<HttpEntity, String> makeRequest(HttpMethod httpMethod, String url, String body, String expectationFilename) {
final String uuid = UUID.randomUUID().toString();
final HttpHeaders headers = new HttpHeaders();
- headers.add(ECOMP_REQUEST_ID, uuid);
+ headers.add(REQUEST_ID_HEADER, uuid);
headers.add(AUTHORIZATION, "Basic " + AAFGetBasicAuthPreset.VALID_AUTH_VALUE);
headers.setContentType(MediaType.APPLICATION_JSON);
SimulatorApi.registerExpectation("ecompportal_getSessionSlotCheckInterval.json", APPEND);
HttpEntity entity = new HttpEntity<>(body, headers);
- ResponseEntity<String> response = null;
- response = restTemplateErrorAgnostic.exchange(uri + url,
- httpMethod, entity, String.class);
+ ResponseEntity<String> response =
+ restTemplateErrorAgnostic.exchange(uri + url, httpMethod, entity, String.class);
return Pair.of(response, uuid);
}