1 package org.onap.vid.api;
3 import com.google.common.collect.ImmutableList;
4 import org.apache.commons.lang3.StringUtils;
5 import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
6 import org.apache.commons.lang3.builder.ToStringStyle;
7 import org.junit.Assert;
8 import org.onap.simulator.presetGenerator.presets.BasePresets.BasePreset;
9 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetSubscribersGet;
10 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetSubscribersGetInvalidResponse;
11 import org.onap.simulator.presetGenerator.presets.mso.PresetMSOOrchestrationRequestsManyStatusesGet;
12 import org.onap.simulator.presetGenerator.presets.mso.PresetMSOOrchestrationRequestsManyStatusesInvalidResponseGet;
13 import org.onap.simulator.presetGenerator.presets.sdc.PresetSDCGetServiceToscaModelGet;
14 import org.onap.simulator.presetGenerator.presets.sdc.PresetSDCGetServiceToscaModelGetEmptyResult;
15 import org.onap.simulator.presetGenerator.presets.sdc.PresetSDCGetServiceToscaModelGetInvalidResponse;
16 import org.onap.vid.model.probe.ExternalComponentStatus;
17 import org.onap.vid.model.probe.HttpRequestMetadata;
18 import org.onap.simulator.presetGenerator.presets.scheduler.PresetGetSchedulerChangeManagementInvalidResponse;
19 import org.onap.simulator.presetGenerator.presets.scheduler.PresetGetSchedulerChangeManagements;
20 import org.springframework.core.ParameterizedTypeReference;
21 import org.springframework.http.HttpMethod;
22 import org.springframework.http.ResponseEntity;
23 import org.testng.annotations.BeforeClass;
24 import org.testng.annotations.DataProvider;
25 import org.testng.annotations.Test;
26 import vid.automation.test.services.SimulatorApi;
28 import java.lang.reflect.Method;
29 import java.util.Collection;
30 import java.util.List;
32 import static org.hamcrest.CoreMatchers.*;
33 import static vid.automation.test.services.SimulatorApi.RegistrationStrategy.CLEAR_THEN_SET;
35 public class ProbeApiTest extends BaseApiTest {
37 private static final String MSO_QUERY_PARAMS = "filter=requestExecutionDate:EQUALS:01-01-2100";
38 private static final String AAI_QUERY_PARMAS = "business/customers?subscriber-type=INFRA&depth=0";
39 private static final String SDC_PATH_PARAMS = "46401eec-35bd-4e96-ad0d-0356ff6b8c8d/toscaModel";
40 private static final String SCHEDULER_PATH = "http://localhost:1080/scheduler/v1/ChangeManagement/schedules/scheduleDetails/";
49 public static Object[][] probePresetAndResponse(Method test) {
50 return new Object[][]{
54 new PresetAAIGetSubscribersGet(),
55 new PresetMSOOrchestrationRequestsManyStatusesGet(),
56 new PresetSDCGetServiceToscaModelGet("46401eec-35bd-4e96-ad0d-0356ff6b8c8d", "serviceCreationTest.zip"),
57 new PresetGetSchedulerChangeManagements()
59 ImmutableList.of(new ExternalComponentStatus(ExternalComponentStatus.Component.AAI,
61 new HttpRequestMetadata(HttpMethod.GET,
64 "{\"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",
67 ), new ExternalComponentStatus(ExternalComponentStatus.Component.MSO,
69 new HttpRequestMetadata(HttpMethod.GET,
73 " \"requestList\": [{ " +
75 " \"requestId\": \"rq1234d1-5a33-55df-13ab-12abad84e333\", " +
76 " \"startTime\": \"Thu, 04 Jun 2009 02:51:59 GMT\", " +
77 " \"instanceReferences\": { " +
78 " \"serviceInstanceId\": \"bc305d54-75b4-431b-adb2-eb6b9e546014\" " +
80 " \"requestScope\": \"vnf\", " +
81 " \"requestType\": \"updateInstance\", " +
82 " \"requestDetails\": { " +
83 " \"modelInfo\": { " +
84 " \"modelType\": \"service\", " +
85 " \"modelInvariantId\": \"sn5256d1-5a33-55df-13ab-12abad84e764\", " +
86 " \"modelVersionId\": \"ab6478e4-ea33-3346-ac12-ab1",
89 ), new ExternalComponentStatus(ExternalComponentStatus.Component.SDC,
91 new HttpRequestMetadata(HttpMethod.GET,
97 ), new ExternalComponentStatus(ExternalComponentStatus.Component.SCHEDULER,
99 new HttpRequestMetadata(HttpMethod.GET,
102 StringUtils.substring(new PresetGetSchedulerChangeManagements().getResponseBody().toString(), 0, 500),
110 new PresetAAIGetSubscribersGetInvalidResponse(200),
111 new PresetMSOOrchestrationRequestsManyStatusesInvalidResponseGet(200),
112 new PresetSDCGetServiceToscaModelGetEmptyResult("46401eec-35bd-4e96-ad0d-0356ff6b8c8d"),
113 new PresetGetSchedulerChangeManagementInvalidResponse(200)
115 ImmutableList.of(new ExternalComponentStatus(ExternalComponentStatus.Component.AAI,
117 new HttpRequestMetadata(HttpMethod.GET,
120 "this payload is an invalid json",
121 "com.fasterxml.jackson.core.JsonParseException"
123 ), new ExternalComponentStatus(ExternalComponentStatus.Component.MSO,
125 new HttpRequestMetadata(HttpMethod.GET,
128 "this payload is an invalid json",
129 "com.fasterxml.jackson.core.JsonParseException"
131 ), new ExternalComponentStatus(ExternalComponentStatus.Component.SDC,
133 new HttpRequestMetadata(HttpMethod.GET,
137 "error reading model 46401eec-35bd-4e96-ad0d-0356ff6b8c8d from SDC"
139 ), new ExternalComponentStatus(ExternalComponentStatus.Component.SCHEDULER,
141 new HttpRequestMetadata(HttpMethod.GET,
144 "this payload is an invalid json",
145 "javax.ws.rs.ProcessingException"
152 new PresetAAIGetSubscribersGetInvalidResponse(500),
153 new PresetMSOOrchestrationRequestsManyStatusesInvalidResponseGet(406),
154 new PresetSDCGetServiceToscaModelGetInvalidResponse("46401eec-35bd-4e96-ad0d-0356ff6b8c8d", 404),
155 new PresetGetSchedulerChangeManagementInvalidResponse(400)
157 ImmutableList.of(new ExternalComponentStatus(ExternalComponentStatus.Component.AAI,
159 new HttpRequestMetadata(HttpMethod.GET,
162 "this payload is an invalid json",
163 "No subscriber received"
165 ), new ExternalComponentStatus(ExternalComponentStatus.Component.MSO,
167 new HttpRequestMetadata(HttpMethod.GET,
170 "this payload is an invalid json",
171 "org.apache.http.HttpException: Get with status=406 (200 or 202 expected), url= http"
173 ), new ExternalComponentStatus(ExternalComponentStatus.Component.SDC,
175 new HttpRequestMetadata(HttpMethod.GET,
178 "simulated error description from sdc",
179 "model 46401eec-35bd-4e96-ad0d-0356ff6b8c8d not found in SDC" +
180 " (consider updating vid probe configuration 'probe.sdc.model.uuid')"
182 ), new ExternalComponentStatus(ExternalComponentStatus.Component.SCHEDULER,
184 new HttpRequestMetadata(HttpMethod.GET,
187 "this payload is an invalid json",
188 "org.apache.http.HttpException: Get with status = 400, url = " + SCHEDULER_PATH
196 @Test(dataProvider = "probePresetAndResponse")
197 public void probeRequest_returnsResponseAsExpected(String desc, Collection<BasePreset> presets, Collection<ExternalComponentStatus> expectedStatuses) {
198 SimulatorApi.registerExpectationFromPresets(presets, CLEAR_THEN_SET);
199 ResponseEntity<List<ExternalComponentStatus>> response = restTemplate.exchange(
201 org.springframework.http.HttpMethod.GET,
203 new ParameterizedTypeReference<List<ExternalComponentStatus>>() {
205 List<ExternalComponentStatus> probeResults = response.getBody();
206 Assert.assertEquals(4, probeResults.size());
207 assertResultAsExpected(ExternalComponentStatus.Component.AAI, probeResults, expectedStatuses);
208 assertResultAsExpected(ExternalComponentStatus.Component.SDC, probeResults, expectedStatuses);
209 assertResultAsExpected(ExternalComponentStatus.Component.MSO, probeResults, expectedStatuses);
210 assertResultAsExpected(ExternalComponentStatus.Component.SCHEDULER, probeResults, expectedStatuses);
213 private void assertResultAsExpected(ExternalComponentStatus.Component component, List<ExternalComponentStatus> probeResults, Collection<ExternalComponentStatus> expectedStatuses) {
214 ExternalComponentStatus expectedStatus = expectedStatuses.stream().filter(x -> x.getComponent() == component)
215 .findFirst().orElseThrow(() -> new AssertionError("Missing setup for " + component + " expected result"));
216 ExternalComponentStatus componentStatus = probeResults.stream().filter(x -> x.getComponent() == component)
217 .findFirst().orElseThrow(() -> new AssertionError(component.name()+" result not found in response"));
219 Assert.assertThat("wrong metadata for " + component, requestMetadataReflected(componentStatus.getMetadata()),
220 is(requestMetadataReflected(expectedStatus.getMetadata())));
222 Assert.assertThat("wrong url for " + component, componentStatus.getMetadata().getUrl(),
223 both(endsWith(expectedStatus.getMetadata().getUrl())).and(startsWith("http")));
225 Assert.assertThat("wrong description for " + component, componentStatus.getMetadata().getDescription(),
226 anyOf(equalTo(expectedStatus.getMetadata().getDescription()), startsWith(expectedStatus.getMetadata().getDescription())));
228 Assert.assertThat("wrong status for " + component, componentStatus.isAvailable(), is(expectedStatus.isAvailable()));
231 //serialize fields except of fields we cannot know ahead of time
232 private static String requestMetadataReflected(HttpRequestMetadata metadata) {
233 return new ReflectionToStringBuilder(metadata, ToStringStyle.SHORT_PREFIX_STYLE)
234 .setExcludeFieldNames("duration", "url", "description")