diff options
author | Eylon Malin <eylon.malin@intl.att.com> | 2019-10-10 15:22:07 +0300 |
---|---|---|
committer | Eylon Malin <eylon.malin@intl.att.com> | 2019-10-23 08:11:51 +0300 |
commit | e8d29ab5e3775472f59a4997fa3a5df9319de306 (patch) | |
tree | 5f53a1548e7d191385d77f2fd5df0d96c04d4af1 /vid-automation/src/main | |
parent | f09e8d114804e4237e79f27ed492835ecb1b17b0 (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/main')
2 files changed, 34 insertions, 5 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(); |