From e8d29ab5e3775472f59a4997fa3a5df9319de306 Mon Sep 17 00:00:00 2001 From: Eylon Malin Date: Thu, 10 Oct 2019 15:22:07 +0300 Subject: use logging interceptor in SDC client Issue-ID: VID-253 Change-Id: I67947886fd8945a224ee81d5eb0a8fedf1f7317c Signed-off-by: Eylon Malin --- .../presets/BasePresets/BaseSDCPreset.java | 6 +++- .../vid/automation/test/services/SimulatorApi.java | 33 +++++++++++++++++++--- 2 files changed, 34 insertions(+), 5 deletions(-) (limited to 'vid-automation/src/main/java') 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 getRequestHeaders() { Map 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 values; } - public static class HttpRequest{ + public static class HttpRequest { public StringWrapper path; public List headers; } + public static class RecordedRequests { + public String path; + public Map> headers; + + public RecordedRequests(String path, Map> 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> presets, RegistrationStrategy registrationStrategy) { registerExpectationFromPresets(presets.stream() .flatMap(Collection::stream) - .collect(Collectors.toList()), registrationStrategy); + .collect(toList()), registrationStrategy); } public static void registerExpectationFromPresets(Collection 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 retrieveRecordedRequestsPathCounter() { - List httpRequests = retrieveRecordedRequests(); + List httpRequests = retrieveRecordedHttpRequests(); return httpRequests.stream().map(x->x.path.value).collect( Collectors.groupingBy(Function.identity(), Collectors.counting())); } - public static List retrieveRecordedRequests() { + private static List retrieveRecordedHttpRequests() { Response response = client.target(uri).path("retrieveRecordedRequests").request().get(); return response.readEntity(new GenericType>(){}); } + public static List retrieveRecordedRequests() { + List 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(); -- cgit 1.2.3-korg