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 vid.automation.test.services.SimulatorApi.RegistrationStrategy.CLEAR_THEN_SET;
11 import com.google.common.collect.ImmutableList;
12 import java.lang.reflect.Method;
13 import java.util.Collection;
14 import java.util.List;
15 import org.apache.commons.lang3.StringUtils;
16 import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
17 import org.apache.commons.lang3.builder.ToStringStyle;
18 import org.junit.Assert;
19 import org.onap.simulator.presetGenerator.presets.BasePresets.BasePreset;
20 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetSubscribersGet;
21 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetSubscribersGetInvalidResponse;
22 import org.onap.simulator.presetGenerator.presets.mso.PresetMSOOrchestrationRequestsManyStatusesGet;
23 import org.onap.simulator.presetGenerator.presets.mso.PresetMSOOrchestrationRequestsManyStatusesInvalidResponseGet;
24 import org.onap.simulator.presetGenerator.presets.scheduler.PresetGetSchedulerChangeManagementInvalidResponse;
25 import org.onap.simulator.presetGenerator.presets.scheduler.PresetGetSchedulerChangeManagements;
26 import org.onap.simulator.presetGenerator.presets.sdc.PresetSDCGetServiceToscaModelGet;
27 import org.onap.simulator.presetGenerator.presets.sdc.PresetSDCGetServiceToscaModelGetEmptyResult;
28 import org.onap.simulator.presetGenerator.presets.sdc.PresetSDCGetServiceToscaModelGetInvalidResponse;
29 import org.onap.vid.model.probe.ExternalComponentStatus;
30 import org.onap.vid.model.probe.HttpRequestMetadata;
31 import org.springframework.core.ParameterizedTypeReference;
32 import org.springframework.http.HttpMethod;
33 import org.springframework.http.ResponseEntity;
34 import org.testng.annotations.BeforeClass;
35 import org.testng.annotations.DataProvider;
36 import org.testng.annotations.Test;
37 import vid.automation.test.services.SimulatorApi;
39 public class ProbeApiTest extends BaseApiTest {
41 private static final String MSO_QUERY_PARAMS = "filter=requestExecutionDate:EQUALS:01-01-2100";
42 private static final String AAI_QUERY_PARMAS = "business/customers?subscriber-type=INFRA&depth=0";
43 private static final String SDC_PATH_PARAMS = "46401eec-35bd-4e96-ad0d-0356ff6b8c8d/toscaModel";
44 private static final String SCHEDULER_PATH = "http://localhost:1080/scheduler/v1/ChangeManagement/schedules/scheduleDetails/";
53 public static Object[][] probePresetAndResponse(Method test) {
54 return new Object[][]{
58 new PresetAAIGetSubscribersGet(),
59 new PresetMSOOrchestrationRequestsManyStatusesGet(),
60 new PresetSDCGetServiceToscaModelGet("46401eec-35bd-4e96-ad0d-0356ff6b8c8d", "serviceCreationTest.zip"),
61 new PresetGetSchedulerChangeManagements()
63 ImmutableList.of(new ExternalComponentStatus(ExternalComponentStatus.Component.AAI,
65 new HttpRequestMetadata(HttpMethod.GET,
68 "{\"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\",\"relationsh",
71 ), new ExternalComponentStatus(ExternalComponentStatus.Component.MSO,
73 new HttpRequestMetadata(HttpMethod.GET,
77 " \"requestList\": [{ " +
79 " \"requestId\": \"rq1234d1-5a33-55df-13ab-12abad84e333\", " +
80 " \"startTime\": \"Thu, 04 Jun 2009 02:51:59 GMT\", " +
81 " \"instanceReferences\": { " +
82 " \"serviceInstanceId\": \"bc305d54-75b4-431b-adb2-eb6b9e546014\" " +
84 " \"requestScope\": \"vnf\", " +
85 " \"requestType\": \"updateInstance\", " +
86 " \"requestDetails\": { " +
87 " \"modelInfo\": { " +
88 " \"modelType\": \"service\", " +
89 " \"modelInvariantId\": \"sn5256d1-5a33-55df-13ab-12abad84e764\", " +
90 " \"modelVersionId\": \"ab6478e4-ea33-3346-ac12-ab1",
93 ), new ExternalComponentStatus(ExternalComponentStatus.Component.SDC,
95 new HttpRequestMetadata(HttpMethod.GET,
101 ), new ExternalComponentStatus(ExternalComponentStatus.Component.SCHEDULER,
103 new HttpRequestMetadata(HttpMethod.GET,
106 StringUtils.substring(new PresetGetSchedulerChangeManagements().getResponseBody().toString(), 0, 500),
114 new PresetAAIGetSubscribersGetInvalidResponse(200),
115 new PresetMSOOrchestrationRequestsManyStatusesInvalidResponseGet(200),
116 new PresetSDCGetServiceToscaModelGetEmptyResult("46401eec-35bd-4e96-ad0d-0356ff6b8c8d"),
117 new PresetGetSchedulerChangeManagementInvalidResponse(200)
119 ImmutableList.of(new ExternalComponentStatus(ExternalComponentStatus.Component.AAI,
121 new HttpRequestMetadata(HttpMethod.GET,
124 "this payload is an invalid json",
125 "com.fasterxml.jackson.core.JsonParseException"
127 ), new ExternalComponentStatus(ExternalComponentStatus.Component.MSO,
129 new HttpRequestMetadata(HttpMethod.GET,
132 "this payload is an invalid json",
133 "com.fasterxml.jackson.core.JsonParseException"
135 ), new ExternalComponentStatus(ExternalComponentStatus.Component.SDC,
137 new HttpRequestMetadata(HttpMethod.GET,
141 "error reading model 46401eec-35bd-4e96-ad0d-0356ff6b8c8d from SDC"
143 ), new ExternalComponentStatus(ExternalComponentStatus.Component.SCHEDULER,
145 new HttpRequestMetadata(HttpMethod.GET,
148 "this payload is an invalid json",
149 "javax.ws.rs.ProcessingException"
156 new PresetAAIGetSubscribersGetInvalidResponse(500),
157 new PresetMSOOrchestrationRequestsManyStatusesInvalidResponseGet(406),
158 new PresetSDCGetServiceToscaModelGetInvalidResponse("46401eec-35bd-4e96-ad0d-0356ff6b8c8d", 404),
159 new PresetGetSchedulerChangeManagementInvalidResponse(400)
161 ImmutableList.of(new ExternalComponentStatus(ExternalComponentStatus.Component.AAI,
163 new HttpRequestMetadata(HttpMethod.GET,
166 "this payload is an invalid json",
167 "No subscriber received"
169 ), new ExternalComponentStatus(ExternalComponentStatus.Component.MSO,
171 new HttpRequestMetadata(HttpMethod.GET,
174 "this payload is an invalid json",
175 "org.apache.http.HttpException: Get with status=406 (200 or 202 expected), url= http"
177 ), new ExternalComponentStatus(ExternalComponentStatus.Component.SDC,
179 new HttpRequestMetadata(HttpMethod.GET,
182 "simulated error description from sdc",
183 "model 46401eec-35bd-4e96-ad0d-0356ff6b8c8d not found in SDC" +
184 " (consider updating vid probe configuration 'probe.sdc.model.uuid')"
186 ), new ExternalComponentStatus(ExternalComponentStatus.Component.SCHEDULER,
188 new HttpRequestMetadata(HttpMethod.GET,
191 "this payload is an invalid json",
192 "org.apache.http.HttpException: Get with status = 400, url = " + SCHEDULER_PATH
200 @Test(dataProvider = "probePresetAndResponse")
201 public void probeRequest_returnsResponseAsExpected(String desc, Collection<BasePreset> presets, Collection<ExternalComponentStatus> expectedStatuses) {
202 SimulatorApi.registerExpectationFromPresets(presets, CLEAR_THEN_SET);
203 ResponseEntity<List<ExternalComponentStatus>> response = restTemplate.exchange(
205 org.springframework.http.HttpMethod.GET,
207 new ParameterizedTypeReference<List<ExternalComponentStatus>>() {
209 List<ExternalComponentStatus> probeResults = response.getBody();
210 Assert.assertEquals(4, probeResults.size());
211 assertResultAsExpected(ExternalComponentStatus.Component.AAI, probeResults, expectedStatuses);
212 assertResultAsExpected(ExternalComponentStatus.Component.SDC, probeResults, expectedStatuses);
213 assertResultAsExpected(ExternalComponentStatus.Component.MSO, probeResults, expectedStatuses);
214 assertResultAsExpected(ExternalComponentStatus.Component.SCHEDULER, probeResults, expectedStatuses);
217 private void assertResultAsExpected(ExternalComponentStatus.Component component, List<ExternalComponentStatus> probeResults, Collection<ExternalComponentStatus> expectedStatuses) {
218 ExternalComponentStatus expectedStatus = expectedStatuses.stream().filter(x -> x.getComponent() == component)
219 .findFirst().orElseThrow(() -> new AssertionError("Missing setup for " + component + " expected result"));
220 ExternalComponentStatus componentStatus = probeResults.stream().filter(x -> x.getComponent() == component)
221 .findFirst().orElseThrow(() -> new AssertionError(component.name()+" result not found in response"));
223 Assert.assertThat("wrong metadata for " + component, requestMetadataReflected(componentStatus.getMetadata()),
224 is(requestMetadataReflected(expectedStatus.getMetadata())));
226 Assert.assertThat("wrong url for " + component, componentStatus.getMetadata().getUrl(),
227 both(endsWith(expectedStatus.getMetadata().getUrl())).and(startsWith("http")));
229 Assert.assertThat("wrong description for " + component, componentStatus.getMetadata().getDescription(),
230 anyOf(equalTo(expectedStatus.getMetadata().getDescription()), startsWith(expectedStatus.getMetadata().getDescription())));
232 Assert.assertThat("wrong status for " + component, componentStatus.isAvailable(), is(expectedStatus.isAvailable()));
235 //serialize fields except of fields we cannot know ahead of time
236 private static String requestMetadataReflected(HttpRequestMetadata metadata) {
237 return new ReflectionToStringBuilder(metadata, ToStringStyle.SHORT_PREFIX_STYLE)
238 .setExcludeFieldNames("duration", "url", "description")