1 package org.onap.vid.api;
3 import static org.hamcrest.CoreMatchers.anyOf;
4 import static org.hamcrest.CoreMatchers.both;
5 import static org.hamcrest.CoreMatchers.endsWith;
6 import static org.hamcrest.CoreMatchers.equalTo;
7 import static org.hamcrest.CoreMatchers.is;
8 import static org.hamcrest.CoreMatchers.startsWith;
9 import static org.hamcrest.MatcherAssert.assertThat;
10 import static org.testng.Assert.assertEquals;
11 import static vid.automation.test.services.SimulatorApi.RegistrationStrategy.CLEAR_THEN_SET;
13 import com.google.common.collect.ImmutableList;
14 import java.lang.reflect.Method;
15 import java.util.Collection;
16 import java.util.List;
17 import org.apache.commons.lang3.StringUtils;
18 import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
19 import org.apache.commons.lang3.builder.ToStringStyle;
20 import org.onap.simulator.presetGenerator.presets.BasePresets.BasePreset;
21 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetSubscribersGet;
22 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetSubscribersGetInvalidResponse;
23 import org.onap.simulator.presetGenerator.presets.mso.PresetMSOOrchestrationRequestsManyStatusesGet;
24 import org.onap.simulator.presetGenerator.presets.mso.PresetMSOOrchestrationRequestsManyStatusesInvalidResponseGet;
25 import org.onap.simulator.presetGenerator.presets.scheduler.PresetGetSchedulerChangeManagementInvalidResponse;
26 import org.onap.simulator.presetGenerator.presets.scheduler.PresetGetSchedulerChangeManagements;
27 import org.onap.simulator.presetGenerator.presets.sdc.PresetSDCGetServiceToscaModelGet;
28 import org.onap.simulator.presetGenerator.presets.sdc.PresetSDCGetServiceToscaModelGetEmptyResult;
29 import org.onap.simulator.presetGenerator.presets.sdc.PresetSDCGetServiceToscaModelGetInvalidResponse;
30 import org.onap.vid.model.probe.ExternalComponentStatus;
31 import org.onap.vid.model.probe.HttpRequestMetadata;
32 import org.springframework.core.ParameterizedTypeReference;
33 import org.springframework.http.HttpMethod;
34 import org.springframework.http.ResponseEntity;
35 import org.testng.annotations.BeforeClass;
36 import org.testng.annotations.DataProvider;
37 import org.testng.annotations.Test;
38 import vid.automation.test.services.SimulatorApi;
40 public class ProbeApiTest extends BaseApiTest {
42 private static final String MSO_QUERY_PARAMS = "filter=requestExecutionDate:EQUALS:01-01-2100";
43 private static final String AAI_QUERY_PARMAS = "business/customers?subscriber-type=INFRA&depth=0";
44 private static final String SDC_PATH_PARAMS = "46401eec-35bd-4e96-ad0d-0356ff6b8c8d/toscaModel";
45 private static final String SCHEDULER_PATH = "/scheduler/v1/ChangeManagement/schedules/scheduleDetails/";
54 public static Object[][] probePresetAndResponse(Method test) {
55 return new Object[][]{
59 new PresetAAIGetSubscribersGet(),
60 new PresetMSOOrchestrationRequestsManyStatusesGet(),
61 new PresetSDCGetServiceToscaModelGet("46401eec-35bd-4e96-ad0d-0356ff6b8c8d", "serviceCreationTest.zip"),
62 new PresetGetSchedulerChangeManagements()
64 ImmutableList.of(new ExternalComponentStatus(ExternalComponentStatus.Component.AAI,
66 new HttpRequestMetadata(HttpMethod.GET,
69 "{\"customer\":[{\"global-customer-id\":\"CAR_2020_ER\",\"subscriber-name\":\"CAR_2020_ER\",\"subscriber-type\":\"INFRA\",\"resource-version\":\"1494001902987\",\"relationship-list\":null},{\"global-customer-id\":\"21014aa2-526b-11e6-beb8-9e71128cae77\",\"subscriber-name\":\"JULIO ERICKSON\",\"subscriber-type\":\"INFRA\",\"resource-version\":\"1494001776295\",\"relationship-list\":null},{\"global-customer-id\":\"DHV1707-TestSubscriber-2\",\"subscriber-name\":\"DALE BRIDGES\",\"subscriber-type\":\"INFRA\",\"resource-version\":\"1498751754450\",\"relat",
72 ), new ExternalComponentStatus(ExternalComponentStatus.Component.MSO,
74 new HttpRequestMetadata(HttpMethod.GET,
78 " \"requestList\": [{ " +
80 " \"requestId\": \"rq1234d1-5a33-55df-13ab-12abad84e333\", " +
81 " \"startTime\": \"Thu, 04 Jun 2009 02:51:59 GMT\", " +
82 " \"instanceReferences\": { " +
83 " \"serviceInstanceId\": \"bc305d54-75b4-431b-adb2-eb6b9e546014\" " +
85 " \"requestScope\": \"vnf\", " +
86 " \"requestType\": \"updateInstance\", " +
87 " \"requestDetails\": { " +
88 " \"modelInfo\": { " +
89 " \"modelType\": \"service\", " +
90 " \"modelInvariantId\": \"sn5256d1-5a33-55df-13ab-12abad84e764\", " +
91 " \"modelVersionId\": \"ab6478e4-ea33-3346-ac12-ab1",
94 ), new ExternalComponentStatus(ExternalComponentStatus.Component.SDC,
96 new HttpRequestMetadata(HttpMethod.GET,
102 ), new ExternalComponentStatus(ExternalComponentStatus.Component.SCHEDULER,
104 new HttpRequestMetadata(HttpMethod.GET,
107 StringUtils.substring(new PresetGetSchedulerChangeManagements().getResponseBody().toString(), 0, 500),
115 new PresetAAIGetSubscribersGetInvalidResponse(200),
116 new PresetMSOOrchestrationRequestsManyStatusesInvalidResponseGet(200),
117 new PresetSDCGetServiceToscaModelGetEmptyResult("46401eec-35bd-4e96-ad0d-0356ff6b8c8d"),
118 new PresetGetSchedulerChangeManagementInvalidResponse(200)
120 ImmutableList.of(new ExternalComponentStatus(ExternalComponentStatus.Component.AAI,
122 new HttpRequestMetadata(HttpMethod.GET,
125 "this payload is an invalid json",
126 "com.fasterxml.jackson.core.JsonParseException"
128 ), new ExternalComponentStatus(ExternalComponentStatus.Component.MSO,
130 new HttpRequestMetadata(HttpMethod.GET,
133 "this payload is an invalid json",
134 "com.fasterxml.jackson.core.JsonParseException"
136 ), new ExternalComponentStatus(ExternalComponentStatus.Component.SDC,
138 new HttpRequestMetadata(HttpMethod.GET,
142 "error reading model 46401eec-35bd-4e96-ad0d-0356ff6b8c8d from SDC"
144 ), new ExternalComponentStatus(ExternalComponentStatus.Component.SCHEDULER,
146 new HttpRequestMetadata(HttpMethod.GET,
149 "this payload is an invalid json",
150 "com.fasterxml.jackson.core.JsonParseException"
157 new PresetAAIGetSubscribersGetInvalidResponse(500),
158 new PresetMSOOrchestrationRequestsManyStatusesInvalidResponseGet(406),
159 new PresetSDCGetServiceToscaModelGetInvalidResponse("46401eec-35bd-4e96-ad0d-0356ff6b8c8d", 404),
160 new PresetGetSchedulerChangeManagementInvalidResponse(400)
162 ImmutableList.of(new ExternalComponentStatus(ExternalComponentStatus.Component.AAI,
164 new HttpRequestMetadata(HttpMethod.GET,
167 "this payload is an invalid json",
168 "No subscriber received"
170 ), new ExternalComponentStatus(ExternalComponentStatus.Component.MSO,
172 new HttpRequestMetadata(HttpMethod.GET,
175 "this payload is an invalid json",
176 "MSO returned no orchestration requests"
178 ), new ExternalComponentStatus(ExternalComponentStatus.Component.SDC,
180 new HttpRequestMetadata(HttpMethod.GET,
183 "simulated error description from sdc",
184 "model 46401eec-35bd-4e96-ad0d-0356ff6b8c8d not found in SDC" +
185 " (consider updating vid probe configuration 'probe.sdc.model.uuid')"
187 ), new ExternalComponentStatus(ExternalComponentStatus.Component.SCHEDULER,
189 new HttpRequestMetadata(HttpMethod.GET,
192 "this payload is an invalid json",
193 "org.apache.http.HttpException"
201 @Test(dataProvider = "probePresetAndResponse")
202 public void probeRequest_returnsResponseAsExpected(String desc, Collection<BasePreset> presets, Collection<ExternalComponentStatus> expectedStatuses) {
203 SimulatorApi.registerExpectationFromPresets(presets, CLEAR_THEN_SET);
204 ResponseEntity<List<ExternalComponentStatus>> response = restTemplate.exchange(
206 org.springframework.http.HttpMethod.GET,
208 new ParameterizedTypeReference<List<ExternalComponentStatus>>() {
210 List<ExternalComponentStatus> probeResults = response.getBody();
211 assertEquals(5, probeResults.size());
212 assertResultAsExpected(ExternalComponentStatus.Component.AAI, probeResults, expectedStatuses);
213 assertResultAsExpected(ExternalComponentStatus.Component.SDC, probeResults, expectedStatuses);
214 assertResultAsExpected(ExternalComponentStatus.Component.MSO, probeResults, expectedStatuses);
215 assertResultAsExpected(ExternalComponentStatus.Component.SCHEDULER, probeResults, expectedStatuses);
218 private void assertResultAsExpected(ExternalComponentStatus.Component component, List<ExternalComponentStatus> probeResults, Collection<ExternalComponentStatus> expectedStatuses) {
219 ExternalComponentStatus expectedStatus = expectedStatuses.stream().filter(x -> x.getComponent() == component)
220 .findFirst().orElseThrow(() -> new AssertionError("Missing setup for " + component + " expected result"));
221 ExternalComponentStatus componentStatus = probeResults.stream().filter(x -> x.getComponent() == component)
222 .findFirst().orElseThrow(() -> new AssertionError(component.name()+" result not found in response"));
224 assertThat("wrong metadata for " + component, requestMetadataReflected(componentStatus.getMetadata()),
225 is(requestMetadataReflected(expectedStatus.getMetadata())));
227 assertThat("wrong url for " + component, componentStatus.getMetadata().getUrl(),
228 both(endsWith(expectedStatus.getMetadata().getUrl())).and(startsWith("http")));
230 assertThat("wrong description for " + component, componentStatus.getMetadata().getDescription(),
231 anyOf(equalTo(expectedStatus.getMetadata().getDescription()), startsWith(expectedStatus.getMetadata().getDescription())));
233 assertThat("wrong status for " + component, componentStatus.isAvailable(), is(expectedStatus.isAvailable()));
236 //serialize fields except of fields we cannot know ahead of time
237 private static String requestMetadataReflected(HttpRequestMetadata metadata) {
238 return new ReflectionToStringBuilder(metadata, ToStringStyle.SHORT_PREFIX_STYLE)
239 .setExcludeFieldNames("duration", "url", "description")