summaryrefslogtreecommitdiffstats
path: root/vid-automation/src/test
diff options
context:
space:
mode:
authorEylon Malin <eylon.malin@intl.att.com>2019-10-24 10:19:51 +0300
committerEylon Malin <eylon.malin@intl.att.com>2019-10-24 10:19:51 +0300
commitd5ee5305be7f747aaddd3493485d6f029f72817b (patch)
tree00afe4b4c4cb47486b9098bd5a1b1e6fb191c8f4 /vid-automation/src/test
parent853f316ee0df77bd0aefb57ff14a51ed3b448fdd (diff)
common api tests assertion, for metrics log and outgoing out headers
Issue-ID: VID-253 Signed-off-by: Eylon Malin <eylon.malin@intl.att.com> Change-Id: I3d0f5c215d080b5ae70fe7bb2b42a97fb944dcf9
Diffstat (limited to 'vid-automation/src/test')
-rw-r--r--vid-automation/src/test/java/org/onap/vid/api/SdcApiTest.java29
-rw-r--r--vid-automation/src/test/java/org/onap/vid/more/LoggerFormatTest.java47
2 files changed, 48 insertions, 28 deletions
diff --git a/vid-automation/src/test/java/org/onap/vid/api/SdcApiTest.java b/vid-automation/src/test/java/org/onap/vid/api/SdcApiTest.java
index c6ee5fd62..f22b6de65 100644
--- a/vid-automation/src/test/java/org/onap/vid/api/SdcApiTest.java
+++ b/vid-automation/src/test/java/org/onap/vid/api/SdcApiTest.java
@@ -24,8 +24,6 @@ import static net.javacrumbs.jsonunit.JsonMatchers.jsonEquals;
import static net.javacrumbs.jsonunit.JsonMatchers.jsonStringEquals;
import static net.javacrumbs.jsonunit.core.Option.IGNORING_ARRAY_ORDER;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.contains;
-import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNot.not;
import static org.onap.simulator.presetGenerator.presets.BasePresets.BaseSDCPreset.SDC_ROOT_PATH;
@@ -35,20 +33,15 @@ import static vid.automation.test.services.SimulatorApi.RegistrationStrategy.APP
import static vid.automation.test.services.SimulatorApi.RegistrationStrategy.CLEAR_THEN_SET;
import static vid.automation.test.services.SimulatorApi.registerExpectation;
import static vid.automation.test.services.SimulatorApi.registerExpectationFromPresets;
-import static vid.automation.test.services.SimulatorApi.retrieveRecordedRequests;
import static vid.automation.test.utils.ReadFile.loadResourceAsString;
import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.collect.ImmutableList;
-import java.util.List;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
import org.onap.simulator.presetGenerator.presets.BasePresets.BasePreset;
import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetSubscribersGet;
import org.onap.simulator.presetGenerator.presets.sdc.PresetSDCGetServiceMetadataGet;
import org.onap.simulator.presetGenerator.presets.sdc.PresetSDCGetServiceToscaModelGet;
import org.onap.vid.more.LoggerFormatTest;
-import org.onap.vid.more.LoggerFormatTest.LogName;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.testng.annotations.BeforeClass;
@@ -57,7 +50,6 @@ import org.testng.annotations.Test;
import vid.automation.test.infra.FeatureTogglingTest;
import vid.automation.test.infra.Features;
import vid.automation.test.infra.ModelInfo;
-import vid.automation.test.services.SimulatorApi.RecordedRequests;
public class SdcApiTest extends BaseApiTest {
@@ -234,30 +226,13 @@ public class SdcApiTest extends BaseApiTest {
new PresetSDCGetServiceMetadataGet(modelInfo),
new PresetAAIGetSubscribersGet() //for read logs permissions
), CLEAR_THEN_SET);
- //registerExpectationFromPresets(getEcompPortalPresets(), APPEND);
ResponseEntity<String> response = restTemplate.getForEntity(
buildUri(SDC_GET_SERVICE_MODEL + modelInfo.modelVersionId), String.class);
- String logLines = LoggerFormatTest.getLogLines(LogName.metrics2019, 15, 0, restTemplate, uri);
-
final String requestId = response.getHeaders().getFirst("X-ECOMP-RequestID-echo");
- List<RecordedRequests> requests = retrieveRecordedRequests();
- List<RecordedRequests> sdcRequests = requests.stream().filter(x->x.path.startsWith(SDC_ROOT_PATH)).collect(Collectors.toList());
- assertEquals(sdcRequests.size(), 2);
- sdcRequests.forEach(request->{
- assertThat("X-ONAP-RequestID", request.headers.get("X-ONAP-RequestID"), contains(requestId));
- assertThat("X-ECOMP-RequestID", request.headers.get("X-ECOMP-RequestID"), contains(requestId));
- assertThat("X-ONAP-PartnerName", request.headers.get("X-ONAP-PartnerName"), contains("VID.VID"));
- List<String> invocationIds = request.headers.get("X-ONAP-InvocationID");
- assertEquals(invocationIds.size(), 1);
- List<String> sdcMetricsLogLines =
- Stream.of(logLines.split("\n"))
- .filter(x->x.contains(SDC_ROOT_PATH) && x.contains(requestId) && x.contains(invocationIds.get(0)))
- .collect(Collectors.toList());
- assertThat("not found sdc call in metrics log with requestId and invocationId" + requestId,
- sdcMetricsLogLines.size(), is(equalTo(2)));
- });
+ LoggerFormatTest.assertHeadersAndMetricLogs(restTemplate, uri, requestId, SDC_ROOT_PATH, 2);
}
+
}
diff --git a/vid-automation/src/test/java/org/onap/vid/more/LoggerFormatTest.java b/vid-automation/src/test/java/org/onap/vid/more/LoggerFormatTest.java
index fd05b9dde..6a4bf950f 100644
--- a/vid-automation/src/test/java/org/onap/vid/more/LoggerFormatTest.java
+++ b/vid-automation/src/test/java/org/onap/vid/more/LoggerFormatTest.java
@@ -1,9 +1,16 @@
package org.onap.vid.more;
import static java.util.Collections.reverse;
+import static java.util.stream.Collectors.toList;
+import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.allOf;
+import static org.hamcrest.Matchers.contains;
+import static org.hamcrest.Matchers.containsInRelativeOrder;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
+import static org.hamcrest.Matchers.hasSize;
+import static vid.automation.test.services.SimulatorApi.retrieveRecordedRequests;
import com.fasterxml.jackson.databind.JsonNode;
import java.net.URI;
@@ -22,6 +29,7 @@ import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import vid.automation.test.infra.SkipTestUntil;
import vid.automation.test.services.SimulatorApi;
+import vid.automation.test.services.SimulatorApi.RecordedRequests;
public class LoggerFormatTest extends BaseApiTest {
@@ -102,7 +110,7 @@ public class LoggerFormatTest extends BaseApiTest {
* @return Chronological-ordered list of recent log-lines of a given requestId
*/
public static List<String> getRequestLogLines(String requestId, LogName logname, RestTemplate restTemplate, URI uri) {
- String logLines = LoggerFormatTest.getLogLines(LogName.audit2019, 30, 1, restTemplate, uri);
+ String logLines = LoggerFormatTest.getLogLines(logname, 30, 1, restTemplate, uri);
// Split
List<String> lines = new ArrayList<>(Arrays.asList(logLines.split("(\\r?\\n)")));
@@ -116,6 +124,43 @@ public class LoggerFormatTest extends BaseApiTest {
return lines;
}
+ public static void assertHeadersAndMetricLogs(RestTemplate restTemplate, URI uri, String requestId, String path, int requestsSize) {
+ List<String> logLines =
+ getRequestLogLines(requestId, LogName.metrics2019, restTemplate, uri);
+
+ List<RecordedRequests> requests = retrieveRecordedRequests();
+ List<RecordedRequests> underTestRequests =
+ requests.stream().filter(x->x.path.startsWith(path)).collect(toList());
+
+ assertThat(underTestRequests, hasSize(requestsSize));
+
+ underTestRequests.forEach(request-> {
+ assertThat("X-ONAP-RequestID", request.headers.get("X-ONAP-RequestID"), contains(requestId));
+ assertThat("X-ECOMP-RequestID", request.headers.get("X-ECOMP-RequestID"), contains(requestId));
+ assertThat("X-ONAP-PartnerName", request.headers.get("X-ONAP-PartnerName"), contains("VID.VID"));
+ });
+
+ underTestRequests.forEach(request->{
+
+ List<String> invocationIds = request.headers.get("X-ONAP-InvocationID");
+ assertThat(invocationIds, hasSize(1));
+
+ String invocationId = invocationIds.get(0);
+ assertThat("request id and invocation id must be found in exactly two rows",
+ logLines,
+ containsInRelativeOrder(
+ allOf(
+ containsString("RequestID="+requestId),
+ containsString("InvocationID="+ invocationId),
+ containsString("Invoke")),
+ allOf(
+ containsString("RequestID="+requestId),
+ containsString("InvocationID="+ invocationId),
+ containsString("InvokeReturn"))
+ ));
+ });
+ }
+
private JsonNode getCheckerResults(String logtype, String logLines) {
Map<String, String> params = new HashMap<>();
params.put("format", "raw");