aboutsummaryrefslogtreecommitdiffstats
path: root/vid-automation/src/test/java/org/opencomp/vid/more
diff options
context:
space:
mode:
Diffstat (limited to 'vid-automation/src/test/java/org/opencomp/vid/more')
-rw-r--r--vid-automation/src/test/java/org/opencomp/vid/more/LoggerFormatTest.java97
-rw-r--r--vid-automation/src/test/java/org/opencomp/vid/more/RequestIdFilterInstalled.java184
-rw-r--r--vid-automation/src/test/java/org/opencomp/vid/more/SimulatorLoaderTest.java127
3 files changed, 408 insertions, 0 deletions
diff --git a/vid-automation/src/test/java/org/opencomp/vid/more/LoggerFormatTest.java b/vid-automation/src/test/java/org/opencomp/vid/more/LoggerFormatTest.java
new file mode 100644
index 000000000..8b3d244b5
--- /dev/null
+++ b/vid-automation/src/test/java/org/opencomp/vid/more/LoggerFormatTest.java
@@ -0,0 +1,97 @@
+package org.opencomp.vid.more;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import org.apache.commons.lang3.StringUtils;
+import org.opencomp.simulator.presetGenerator.presets.aai.PresetAAIGetSubscribersGet;
+import org.opencomp.vid.api.BaseApiTest;
+import org.springframework.http.client.ClientHttpRequestInterceptor;
+import org.springframework.web.client.RestTemplate;
+import org.testng.SkipException;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+import vid.automation.test.services.SimulatorApi;
+
+import java.net.URI;
+import java.time.LocalDate;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static java.util.Collections.singletonList;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.Matchers.greaterThan;
+import static org.hamcrest.Matchers.greaterThanOrEqualTo;
+import static org.junit.Assert.assertThat;
+
+public class LoggerFormatTest extends BaseApiTest {
+
+
+ // See: https://wiki.web.att.com/display/KSAT/REST-based+Log+Checker
+ private final static String logChecker = "http://eelflogcheck.it.att.com:31820/validate";
+
+ @BeforeClass
+ public void login() {
+ super.login();
+ }
+
+ @BeforeClass
+ public void setAaiSubscribers() {
+ SimulatorApi.registerExpectationFromPreset(new PresetAAIGetSubscribersGet(), SimulatorApi.RegistrationStrategy.CLEAR_THEN_SET);
+ }
+
+ @Test
+ public void validateAuditLogsFormat() {
+ validateLogsFormat("audit");
+ }
+
+ @Test(enabled = false) // no total-score is returned for error-log
+ public void validateErrorLogsFormat() {
+ validateLogsFormat("error");
+ }
+
+ @Test
+ public void validateMetricsLogsFormat() {
+ validateLogsFormat("metrics", "metric");
+ }
+
+ private void validateLogsFormat(String logName) {
+ validateLogsFormat(logName, logName);
+ }
+
+ private void validateLogsFormat(String logName, String logType) {
+
+ String logLines = getLogLines(logName);
+ JsonNode response = getCheckerResults(logType, logLines);
+
+ System.out.println(response);
+ double fieldscore = response.path("summary").path("score").path("fieldscore").asDouble();
+ double overall = response.path("summary").path("score").path("overallscore").asDouble();
+
+ assertThat(fieldscore, is(greaterThan(0.95)));
+ assertThat(overall, is(greaterThan(0.95)));
+
+ }
+
+ private String getLogLines(String logname) {
+ return getLogLines(logname, 5000, 30, restTemplate, uri);
+ }
+
+ public static String getLogLines(String logname, int maxRows, int minRows, RestTemplate restTemplate, URI uri) {
+ String logLines = restTemplate.getForObject(uri + "/logger/" + logname + "?limit={maxRows}", String.class, maxRows);
+ assertThat("expecting at least " + minRows + " rows in " + logname,
+ StringUtils.countMatches(logLines, '\n') + 1,
+ is(greaterThanOrEqualTo(minRows)));
+ return logLines;
+ }
+
+ private JsonNode getCheckerResults(String logtype, String logLines) {
+ Map<String, String> params = new HashMap<>();
+ params.put("format", "raw");
+ params.put("type", logtype);
+ params.put("component", "vid");
+ params.put("data", logLines);
+
+ return restTemplate.postForObject(logChecker, params, JsonNode.class);
+ }
+}
diff --git a/vid-automation/src/test/java/org/opencomp/vid/more/RequestIdFilterInstalled.java b/vid-automation/src/test/java/org/opencomp/vid/more/RequestIdFilterInstalled.java
new file mode 100644
index 000000000..637904766
--- /dev/null
+++ b/vid-automation/src/test/java/org/opencomp/vid/more/RequestIdFilterInstalled.java
@@ -0,0 +1,184 @@
+package org.opencomp.vid.more;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.tuple.Pair;
+import org.opencomp.vid.api.BaseApiTest;
+import org.opencomp.vid.api.OperationalEnvironmentControllerApiTest;
+import org.opencomp.vid.api.ServiceInstanceMsoApiTest;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.ResponseEntity;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+import vid.automation.test.services.SimulatorApi;
+
+import java.util.UUID;
+
+import static org.hamcrest.CoreMatchers.*;
+import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.hamcrest.Matchers.nullValue;
+import static org.junit.Assert.assertThat;
+import static org.opencomp.vid.api.CategoryParametersApiTest.GET_CATEGORY_PARAMETER_PROPERTIES;
+import static org.opencomp.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 {
+
+ /*
+ Tests whether every incoming request to VID goes through
+ the requestId filter. This happens by checking the log
+ AND by checking the echoed header.
+
+ The correctness of the Filter itself is done by unit-
+ tests.
+
+ The outgoing (outgress) headers are checked by the REST
+ Clients unit-tests.
+ */
+
+ private static final String ECOMP_REQUEST_ID = "x-ecomp-requestid";
+ private final String ECOMP_REQUEST_ID_ECHO = ECOMP_REQUEST_ID + "-echo";
+
+ @BeforeClass
+ public void login() {
+ super.login();
+ }
+
+ @Test
+ public void frontendApi_doGET_RequestIdReceived() {
+
+ final Pair<HttpEntity, String> responseAndUuid = makeRequest(
+ HttpMethod.GET,
+ "/operationalEnvironment/requestStatus?requestId=" + OperationalEnvironmentControllerApiTest.GET_STATUS_REQUEST_UUID,
+ null,
+ OperationalEnvironmentControllerApiTest.GET_CLOUD_RESOURCES_REQUEST_STATUS
+ );
+ assertThatUuidInResponseAndUuidIsInARecentLog(responseAndUuid);
+
+ }
+
+ @Test
+ public void frontendApi_doPOST_RequestIdReceived() {
+
+ final Pair<HttpEntity, String> responseAndUuid = makeRequest(
+ HttpMethod.POST,
+ "/" + ServiceInstanceMsoApiTest.MSO_DEACTIVATE_SERVICE_INSTANCE,
+ "{}",
+ ServiceInstanceMsoApiTest.DEACTIVATE_OK_JSON
+ );
+ assertThatUuidInResponseAndUuidIsInARecentLog(responseAndUuid);
+ }
+
+ @Test
+ public void frontendApi_doPOSTWithClientError_RequestIdReceived() {
+
+ final Pair<HttpEntity, String> responseAndUuid = makeRequest(
+ HttpMethod.POST,
+ "/" + MSO_CREATE_CONFIGURATION,
+ "i'm not a json"
+ );
+ assertThatUuidInResponseAndUuidIsInARecentLog(responseAndUuid);
+
+ }
+
+
+ @Test(groups = { "worksOnlyWithLocalhostVID" })
+ public void mopOwningEntityApi_doGET_RequestIdReceived() {
+
+ final Pair<HttpEntity, String> responseAndUuid = makeRequest(
+ HttpMethod.GET,
+ "/" + GET_CATEGORY_PARAMETER_PROPERTIES + "?familyName=PARAMETER_STANDARDIZATION",
+ null
+ );
+
+ assertThatUuidInResponseAndUuidIsInARecentLog(responseAndUuid);
+
+ /*
+ test should be for:
+ x few FE requests;
+ x few FE errors requests;
+ - few UI elements requests;
+ x scheduler callback;
+ - MOP of workflows;
+ x MOP of OE;
+ - health-check
+ */
+ }
+
+ @Test
+ public void schedulerApi_doPOST_RequestIdReceived() {
+
+ final String anyInstanceId = "any instance id";
+ SimulatorApi.registerExpectation(
+ "mso_in_place_software_update_ok.json",
+ ImmutableMap.of("SERVICE_INSTANCE_ID", anyInstanceId, "VNF_INSTANCE_ID", anyInstanceId), SimulatorApi.RegistrationStrategy.CLEAR_THEN_SET);
+ final Pair<HttpEntity, String> responseAndUuid = makeRequest(
+ HttpMethod.POST,
+ "/change-management/workflow/" + anyInstanceId,
+ "{}"
+ );
+ assertThatUuidInResponseAndUuidIsInARecentLog(responseAndUuid);
+
+ }
+
+ @Test
+ public void healthcheck_doGET_RequestIdReceived(){
+ final Pair<HttpEntity, String> responseAndUuid = makeRequest(
+ HttpMethod.GET, "/healthCheck", null
+ );
+ assertThatUuidInResponseAndUuidIsInARecentLog(responseAndUuid);
+ }
+
+ private void assertThatUuidInResponseAndUuidIsInARecentLog(Pair<HttpEntity, String> responseAndUuid) {
+ assertThatResponseHasUuid(responseAndUuid.getLeft(), responseAndUuid.getRight());
+ assertThatTermIsInARecentLog(responseAndUuid.getRight());
+ }
+
+ private void assertThatResponseHasUuid(HttpEntity response, String uuid) {
+ // THIS TEST IS NOT JUST NICE TO HAVE, it also lets us know
+ // that the request/response ran through our "promise request
+ // id" filter, which is great!
+ assertThat(response, not(nullValue()));
+ assertThat(response.getHeaders().get(ECOMP_REQUEST_ID_ECHO), containsInAnyOrder(uuid));
+ }
+
+ private void assertThatTermIsInARecentLog(String uuid) {
+ final ImmutableList<String> logLines = ImmutableList.of(
+ LoggerFormatTest.getLogLines("audit", 5, 0, restTemplate, uri),
+ LoggerFormatTest.getLogLines("error", 5, 0, restTemplate, uri)
+ );
+
+ // Assert that audit *OR* error has the uuid
+ assertThat("uuid not found in any log", logLines, hasItem(containsString(uuid)));
+ }
+
+ private Pair<HttpEntity, String> makeRequest(HttpMethod httpMethod, String url, String body) {
+ return makeRequest(httpMethod, url, body, null);
+ }
+
+ 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(AUTHORIZATION, "Basic 123==");
+
+ SimulatorApi.clearExpectations();
+ if (!StringUtils.isEmpty(expectationFilename)) {
+ SimulatorApi.registerExpectation(expectationFilename, APPEND);
+ }
+ SimulatorApi.registerExpectation("aai_get_full_subscribers.json", APPEND);
+ 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);
+
+ return Pair.of(response, uuid);
+ }
+
+}
diff --git a/vid-automation/src/test/java/org/opencomp/vid/more/SimulatorLoaderTest.java b/vid-automation/src/test/java/org/opencomp/vid/more/SimulatorLoaderTest.java
new file mode 100644
index 000000000..2bcf0698f
--- /dev/null
+++ b/vid-automation/src/test/java/org/opencomp/vid/more/SimulatorLoaderTest.java
@@ -0,0 +1,127 @@
+package org.opencomp.vid.more;
+
+import org.opencomp.simulator.presetGenerator.presets.BasePresets.BasePreset;
+import org.opencomp.simulator.presetGenerator.presets.aai.*;
+import org.opencomp.simulator.presetGenerator.presets.ecompportal_att.PresetGetSessionSlotCheckIntervalGet;
+import org.opencomp.simulator.presetGenerator.presets.ecompportal_att.PresetGetUserGet;
+import org.opencomp.simulator.presetGenerator.presets.mso.PresetActivateServiceInstancePost;
+import org.opencomp.simulator.presetGenerator.presets.mso.PresetDeactivateServiceInstancePost;
+import org.opencomp.simulator.presetGenerator.presets.mso.PresetMSOCreateServiceInstancePost;
+import org.opencomp.simulator.presetGenerator.presets.mso.PresetMSOOrchestrationRequestGet;
+import org.opencomp.simulator.presetGenerator.presets.sdc.PresetSDCGetServiceMetadataGet;
+import org.opencomp.simulator.presetGenerator.presets.sdc.PresetSDCGetServiceToscaModelGet;
+import org.opencomp.vid.api.BaseApiTest;
+import org.springframework.http.HttpMethod;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+import vid.automation.test.services.SimulatorApi;
+import vid.automation.test.services.SimulatorApi.RegistrationStrategy;
+
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.Invocation;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.lang.reflect.Method;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import static org.testng.Assert.assertEquals;
+import static vid.automation.test.services.SimulatorApi.registerExpectationFromPreset;
+import static vid.automation.test.services.SimulatorApi.registerExpectationFromPresets;
+
+public class SimulatorLoaderTest extends BaseApiTest {
+
+
+ protected Invocation.Builder createSimulatorRequestBuilder(BasePreset preset) {
+ WebTarget webTarget = client.target(SimulatorApi.getSimulationUri() + preset.getReqPath());
+ webTarget = addQueryParamsToWebTarget(preset, webTarget);
+ return webTarget.request()
+ .accept("application/json");
+ }
+
+ private WebTarget addQueryParamsToWebTarget(BasePreset preset, WebTarget webTarget) {
+ if (preset.getQueryParams() != null) {
+ for (Map.Entry<String, List> entry : preset.getQueryParams().entrySet()) {
+ webTarget = webTarget.queryParam(entry.getKey(), entry.getValue().toArray());
+ }
+ }
+ return webTarget;
+ }
+
+ @DataProvider
+ public static Object[][] presetClassesWithPutPost(Method test) {
+ return new Object[][]{
+ {new PresetAAIGetPNFByRegionErrorPut()},
+ {new PresetAAIServiceDesignAndCreationPut("a","b")},
+ {new PresetDeactivateServiceInstancePost()},
+ {new PresetActivateServiceInstancePost()},
+ {new PresetMSOCreateServiceInstancePost()}
+ };
+ }
+
+ @Test(dataProvider = "presetClassesWithPutPost")
+ public<C extends BasePreset> void presetPutPost_WhenLoaded_SimulatorReturnsFakeValues(C preset) {
+ registerExpectationFromPreset(preset, RegistrationStrategy.CLEAR_THEN_SET);
+
+ Response cres = createSimulatorRequestBuilder(preset)
+ .method(preset.getReqMethod().name(),
+ Entity.entity(preset.getRequestBody(), MediaType.APPLICATION_JSON));
+
+ int status = cres.getStatus();
+
+ assertEquals(status, preset.getResponseCode());
+ }
+
+ @DataProvider
+ public static Object[][] presetWithGetInstances(Method test) {
+ return new Object[][]{
+ {new PresetAAIGetSubscribersGet()},
+ {new PresetGetSessionSlotCheckIntervalGet()},
+ {new PresetGetUserGet()},
+ {new PresetAAIGetServicesGet()},
+ {new PresetSDCGetServiceMetadataGet("a" , "b", "serviceCreationTest.zip")},
+ {new PresetSDCGetServiceToscaModelGet( "a", "serviceCreationTest.zip")},
+ {new PresetMSOOrchestrationRequestGet()},
+ {new PresetAAIGetNetworkZones()},
+ {new PresetAAISearchNodeQueryEmptyResult()},
+ {new PresetAAIBadBodyForGetServicesGet("not a json")},
+ };
+ }
+
+ @Test(dataProvider = "presetWithGetInstances")
+ public <C extends BasePreset> void assertPresetWithGetMethod(C preset) {
+ registerExpectationFromPreset(preset, RegistrationStrategy.CLEAR_THEN_SET);
+
+ Response cres = createSimulatorRequestBuilder(preset).get();
+
+ int status = cres.getStatus();
+
+ assertEquals(status, preset.getResponseCode());
+ }
+
+ @Test(expectedExceptions = { RuntimeException.class }, expectedExceptionsMessageRegExp = ".*SimulatorLoaderTest.*")
+ public void assertPresetThatThrowException() {
+
+ registerExpectationFromPresets(Collections.singletonList(
+ new BasePreset() {
+
+ @Override
+ public HttpMethod getReqMethod() {
+ throw new RuntimeException();
+ }
+
+ @Override
+ public String getReqPath() {
+ return null;
+ }
+
+ @Override
+ protected String getRootPath() {
+ return null;
+ }
+ }), RegistrationStrategy.CLEAR_THEN_SET);
+ }
+
+}