summaryrefslogtreecommitdiffstats
path: root/vid-automation/src
diff options
context:
space:
mode:
authorEylon Malin <eylon.malin@intl.att.com>2019-10-10 15:22:07 +0300
committerEylon Malin <eylon.malin@intl.att.com>2019-10-23 08:11:51 +0300
commite8d29ab5e3775472f59a4997fa3a5df9319de306 (patch)
tree5f53a1548e7d191385d77f2fd5df0d96c04d4af1 /vid-automation/src
parentf09e8d114804e4237e79f27ed492835ecb1b17b0 (diff)
use logging interceptor in SDC client
Issue-ID: VID-253 Change-Id: I67947886fd8945a224ee81d5eb0a8fedf1f7317c Signed-off-by: Eylon Malin <eylon.malin@intl.att.com>
Diffstat (limited to 'vid-automation/src')
-rw-r--r--vid-automation/src/main/java/org/onap/simulator/presetGenerator/presets/BasePresets/BaseSDCPreset.java6
-rw-r--r--vid-automation/src/main/java/vid/automation/test/services/SimulatorApi.java33
-rw-r--r--vid-automation/src/test/java/org/onap/vid/api/SdcApiTest.java64
3 files changed, 90 insertions, 13 deletions
diff --git a/vid-automation/src/main/java/org/onap/simulator/presetGenerator/presets/BasePresets/BaseSDCPreset.java b/vid-automation/src/main/java/org/onap/simulator/presetGenerator/presets/BasePresets/BaseSDCPreset.java
index ad8dfb3ac..ba35299a8 100644
--- a/vid-automation/src/main/java/org/onap/simulator/presetGenerator/presets/BasePresets/BaseSDCPreset.java
+++ b/vid-automation/src/main/java/org/onap/simulator/presetGenerator/presets/BasePresets/BaseSDCPreset.java
@@ -4,15 +4,19 @@ import java.util.Map;
public abstract class BaseSDCPreset extends BasePreset {
+ public static final String SDC_ROOT_PATH = "/sdc/v1/catalog/services";
+
@Override
protected String getRootPath() {
- return "/sdc/v1/catalog/services";
+ return SDC_ROOT_PATH;
}
@Override
public Map<String, String> getRequestHeaders() {
Map<String, String> map = super.getRequestHeaders();
map.put("X-ONAP-PartnerName", "VID.VID");
+ map.put("X-ONAP-InvocationID", "[0-9a-fA-F]{8}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{12}");
+ map.put("X-ONAP-RequestID", "[0-9a-fA-F]{8}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{12}");
return map;
}
diff --git a/vid-automation/src/main/java/vid/automation/test/services/SimulatorApi.java b/vid-automation/src/main/java/vid/automation/test/services/SimulatorApi.java
index fd7033c6e..6e15b7b52 100644
--- a/vid-automation/src/main/java/vid/automation/test/services/SimulatorApi.java
+++ b/vid-automation/src/main/java/vid/automation/test/services/SimulatorApi.java
@@ -1,5 +1,6 @@
package vid.automation.test.services;
+import static java.util.stream.Collectors.toList;
import static org.testng.Assert.assertEquals;
import static vid.automation.test.services.DropTestApiField.dropFieldCloudOwnerFromString;
import static vid.automation.test.services.DropTestApiField.dropTestApiFieldFromString;
@@ -55,11 +56,24 @@ public class SimulatorApi {
public List<StringWrapper> values;
}
- public static class HttpRequest{
+ public static class HttpRequest {
public StringWrapper path;
public List<RecordedHeaders> headers;
}
+ public static class RecordedRequests {
+ public String path;
+ public Map<String, List<String>> headers;
+
+ public RecordedRequests(String path, Map<String, List<String>> headers) {
+ this.path = path;
+ this.headers = headers;
+ }
+
+ public RecordedRequests() {
+ }
+ }
+
private static final URI uri; //uri for registration
private static final URI simulationUri; //uri for getting simulated responses
private static final Client client;
@@ -125,7 +139,7 @@ public class SimulatorApi {
public static void registerExpectationFromPresetsCollections(Collection<Collection<BasePreset>> presets, RegistrationStrategy registrationStrategy) {
registerExpectationFromPresets(presets.stream()
.flatMap(Collection::stream)
- .collect(Collectors.toList()), registrationStrategy);
+ .collect(toList()), registrationStrategy);
}
public static void registerExpectationFromPresets(Collection<BasePreset> presets, RegistrationStrategy registrationStrategy) {
@@ -152,16 +166,27 @@ public class SimulatorApi {
The key of the map is a path, and the value is counter
*/
public static Map<String, Long> retrieveRecordedRequestsPathCounter() {
- List<HttpRequest> httpRequests = retrieveRecordedRequests();
+ List<HttpRequest> httpRequests = retrieveRecordedHttpRequests();
return httpRequests.stream().map(x->x.path.value).collect(
Collectors.groupingBy(Function.identity(), Collectors.counting()));
}
- public static List<HttpRequest> retrieveRecordedRequests() {
+ private static List<HttpRequest> retrieveRecordedHttpRequests() {
Response response = client.target(uri).path("retrieveRecordedRequests").request().get();
return response.readEntity(new GenericType<List<HttpRequest>>(){});
}
+ public static List<RecordedRequests> retrieveRecordedRequests() {
+ List<HttpRequest> rawRequests = retrieveRecordedHttpRequests();
+ return rawRequests.stream().map(request->new RecordedRequests(
+ request.path.value,
+ request.headers.stream().collect(
+ Collectors.toMap(
+ x->x.name.value,
+ x->x.values.stream().map(y->y.value).collect(toList())))
+ )).collect(toList());
+ }
+
private static void registerToSimulatorAndAssertSuccess(String name, Object content, RegistrationStrategy registrationStrategy) {
if (registrationStrategy == RegistrationStrategy.CLEAR_THEN_SET) {
clearRegistrations();
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 04dbbc0c5..95fb68a10 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,28 +24,39 @@ 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;
+import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
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.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.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
-import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
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 {
@@ -99,7 +110,7 @@ public class SdcApiTest extends BaseApiTest {
public void getServiceModelALaCarteInstantiation() {
registerToSimulatorWithPresets(A_LA_CARTE_INSTANTIATION_TYPE_UUID, A_LA_CARTE_INSTANTIATION_TYPE_INVARIANT_UUID, A_LA_CARTE_INSTANTIATION_TYPE_FILE_PATH);
ResponseEntity<String> response = restTemplate.getForEntity(buildUri(SDC_GET_SERVICE_MODEL + A_LA_CARTE_INSTANTIATION_TYPE_UUID), String.class);
- Assert.assertEquals(response.getStatusCode(), HttpStatus.OK);
+ assertEquals(response.getStatusCode(), HttpStatus.OK);
String aLaCarteInstantiationTypeExpectedResponse = loadResourceAsString(A_LA_CARTE_INSTANTIATION_TYPE_EXPECTED_RESPONSE);
assertThat(response.getBody(), jsonEquals(aLaCarteInstantiationTypeExpectedResponse)
.when(IGNORING_ARRAY_ORDER)
@@ -111,7 +122,7 @@ public class SdcApiTest extends BaseApiTest {
public void getServiceModelMacroInstantiation() {
registerToSimulatorWithPresets(MACRO_INSTANTIATION_TYPE_UUID, MACRO_INSTANTIATION_TYPE_INVARIANT_UUID, MACRO_INSTANTIATION_TYPE_FILE_PATH);
ResponseEntity<String> response = restTemplate.getForEntity(buildUri(SDC_GET_SERVICE_MODEL + MACRO_INSTANTIATION_TYPE_UUID), String.class);
- Assert.assertEquals(response.getStatusCode(), HttpStatus.OK);
+ assertEquals(response.getStatusCode(), HttpStatus.OK);
String macroInstantiationTypeExpectedResponse = loadResourceAsString(MACRO_INSTANTIATION_TYPE_EXPECTED_RESPONSE);
assertThat(response.getBody(), jsonEquals(macroInstantiationTypeExpectedResponse)
.when(IGNORING_ARRAY_ORDER)
@@ -123,7 +134,7 @@ public class SdcApiTest extends BaseApiTest {
public void getServiceModelWithoutInstantiationType(){
registerToSimulatorWithPresets(MACRO_INSTANTIATION_TYPE_UUID, MACRO_INSTANTIATION_TYPE_INVARIANT_UUID, EMPTY_INSTANTIATION_TYPE_FILE_PATH);
ResponseEntity<String> response = restTemplate.getForEntity(buildUri(SDC_GET_SERVICE_MODEL + MACRO_INSTANTIATION_TYPE_UUID), String.class);
- Assert.assertEquals(response.getStatusCode(), HttpStatus.OK);
+ assertEquals(response.getStatusCode(), HttpStatus.OK);
String emptyInstantiationTypeExpectedResponse = loadResourceAsString(EMPTY_INSTANTIATION_TYPE_EXPECTED_RESPONSE);
assertThat("The response is in the format of JSON", response.getBody(), is(jsonStringEquals(turnOffInstantiationUI(emptyInstantiationTypeExpectedResponse))));
}
@@ -132,7 +143,7 @@ public class SdcApiTest extends BaseApiTest {
public void getServiceModelBothInstantiationType(){
registerToSimulatorWithPresets(MACRO_INSTANTIATION_TYPE_UUID, MACRO_INSTANTIATION_TYPE_INVARIANT_UUID, BOTH_INSTANTIATION_TYPE_FILE_PATH);
ResponseEntity<String> response = restTemplate.getForEntity(buildUri(SDC_GET_SERVICE_MODEL + MACRO_INSTANTIATION_TYPE_UUID), String.class);
- Assert.assertEquals(response.getStatusCode(), HttpStatus.OK);
+ assertEquals(response.getStatusCode(), HttpStatus.OK);
String macroInstantiationTypeExpectedResponse = loadResourceAsString(MACRO_INSTANTIATION_TYPE_EXPECTED_RESPONSE);
assertThat(response.getBody(), jsonEquals(macroInstantiationTypeExpectedResponse)
.when(IGNORING_ARRAY_ORDER)
@@ -143,7 +154,7 @@ public class SdcApiTest extends BaseApiTest {
public void getServiceModelWithGroupsAndCheckMinMaxInitialParams(){
registerToSimulatorWithPresets(MIN_MAX_INITIAL_UUID, MIN_MAX_INITIAL_INVARIANT_UUID, MIN_MAX_INITIAL_FILE_PATH);
ResponseEntity<String> response = restTemplate.getForEntity(buildUri(SDC_GET_SERVICE_MODEL + MIN_MAX_INITIAL_UUID), String.class);
- Assert.assertEquals(response.getStatusCode(), HttpStatus.OK);
+ assertEquals(response.getStatusCode(), HttpStatus.OK);
String minMaxInitialExpectedResponse = loadResourceAsString("sdcApiTest/minMaxInitialExpectedResponse.json");
assertThat("The response is in the format of JSON", response.getBody(), is(jsonStringEquals(turnOffInstantiationUI(minMaxInitialExpectedResponse))));
}
@@ -152,7 +163,7 @@ public class SdcApiTest extends BaseApiTest {
public void getServiceModelWithGroupsAndCheckMinMaxInitialParamsOldCsar(){
registerToSimulatorWithPresets(MIN_MAX_INITIAL_UUID_OLD_CSAR, MIN_MAX_INITIAL_INVARIANT_UUID_OLD_CSAR, MIN_MAX_INITIAL_FILE_PATH_OLD_CSAR);
ResponseEntity<String> response = restTemplate.getForEntity(buildUri(SDC_GET_SERVICE_MODEL + MIN_MAX_INITIAL_UUID_OLD_CSAR), String.class);
- Assert.assertEquals(response.getStatusCode(), HttpStatus.OK);
+ assertEquals(response.getStatusCode(), HttpStatus.OK);
String minMaxInitialExpectedResponseOldCsar = loadResourceAsString("sdcApiTest/minMaxInitialExpectedResponseOldCsar.json");
assertThat("The response is in the format of JSON", response.getBody(), is(jsonStringEquals(minMaxInitialExpectedResponseOldCsar)));
}
@@ -162,7 +173,7 @@ public class SdcApiTest extends BaseApiTest {
public void getServiceModelWithServiceRoleGrouping(){
registerToSimulatorWithPresets(GROUPING_SERVICE_ROLE_UUID, GROUPING_SERVICE_ROLE_INVARIANT_UUID, GROUPING_SERVICE_ROLE_FILE_PATH);
ResponseEntity<String> response = restTemplate.getForEntity(buildUri(SDC_GET_SERVICE_MODEL + GROUPING_SERVICE_ROLE_UUID), String.class);
- Assert.assertEquals(response.getStatusCode(), HttpStatus.OK);
+ assertEquals(response.getStatusCode(), HttpStatus.OK);
String groupingServiceRoleExpectedResponse = loadResourceAsString(GROUPING_SERVICE_ROLE_EXPECTED_RESPONSE);
assertThat("The response is in the format of JSON", response.getBody(), is(jsonStringEquals(groupingServiceRoleExpectedResponse)));
}
@@ -211,4 +222,41 @@ public class SdcApiTest extends BaseApiTest {
response.at(base + "/volumeGroups").size(), is(not(0)));
}
+
+ @Test
+ public void whenCallSdc_thenRequestRecordedInMetricsLog() {
+
+ ModelInfo modelInfo = ModelInfo.transportWithPnfsService;
+
+ registerExpectationFromPresets(ImmutableList.of(
+ new PresetSDCGetServiceToscaModelGet(modelInfo),
+ 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("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)));
+ });
+ }
}