1 package org.onap.vid.more;
3 import org.onap.simulator.presetGenerator.presets.BasePresets.BasePreset;
4 import org.onap.simulator.presetGenerator.presets.aai.*;
5 import org.onap.simulator.presetGenerator.presets.ecompportal_att.PresetGetSessionSlotCheckIntervalGet;
6 import org.onap.simulator.presetGenerator.presets.ecompportal_att.PresetGetUserGet;
7 import org.onap.simulator.presetGenerator.presets.mso.PresetActivateServiceInstancePost;
8 import org.onap.simulator.presetGenerator.presets.mso.PresetDeactivateServiceInstancePost;
9 import org.onap.simulator.presetGenerator.presets.mso.PresetMSOCreateServiceInstancePost;
10 import org.onap.simulator.presetGenerator.presets.mso.PresetMSOOrchestrationRequestGet;
11 import org.onap.simulator.presetGenerator.presets.sdc.PresetSDCGetServiceMetadataGet;
12 import org.onap.simulator.presetGenerator.presets.sdc.PresetSDCGetServiceToscaModelGet;
13 import org.onap.vid.api.BaseApiTest;
14 import org.springframework.http.HttpMethod;
15 import org.testng.annotations.DataProvider;
16 import org.testng.annotations.Test;
17 import vid.automation.test.services.SimulatorApi;
18 import vid.automation.test.services.SimulatorApi.RegistrationStrategy;
20 import javax.ws.rs.client.Entity;
21 import javax.ws.rs.client.Invocation;
22 import javax.ws.rs.client.WebTarget;
23 import javax.ws.rs.core.MediaType;
24 import javax.ws.rs.core.Response;
25 import java.lang.reflect.Method;
26 import java.util.Collections;
27 import java.util.List;
30 import static org.testng.Assert.assertEquals;
31 import static vid.automation.test.infra.ModelInfo.aLaCarteServiceCreationTest;
32 import static vid.automation.test.services.SimulatorApi.registerExpectationFromPreset;
33 import static vid.automation.test.services.SimulatorApi.registerExpectationFromPresets;
35 public class SimulatorLoaderTest extends BaseApiTest {
38 protected Invocation.Builder createSimulatorRequestBuilder(BasePreset preset) {
39 WebTarget webTarget = client.target(SimulatorApi.getSimulationUri() + preset.getReqPath());
40 webTarget = addQueryParamsToWebTarget(preset, webTarget);
41 Invocation.Builder builder = webTarget.request()
42 .accept("application/json");
43 return addHeadersToBuilder(preset, builder);
46 private WebTarget addQueryParamsToWebTarget(BasePreset preset, WebTarget webTarget) {
47 if (preset.getQueryParams() != null) {
48 for (Map.Entry<String, List> entry : preset.getQueryParams().entrySet()) {
49 webTarget = webTarget.queryParam(entry.getKey(), entry.getValue().toArray());
55 private Invocation.Builder addHeadersToBuilder(BasePreset preset, Invocation.Builder builder) {
56 preset.getRequestHeaders().forEach((key,value)->builder.header(key,value));
61 public static Object[][] presetClassesWithPutPost(Method test) {
62 return new Object[][]{
63 {new PresetAAIGetPNFByRegionErrorPut()},
64 {new PresetAAIServiceDesignAndCreationPut()},
65 {new PresetDeactivateServiceInstancePost()},
66 {new PresetActivateServiceInstancePost()},
67 {new PresetMSOCreateServiceInstancePost()}
71 @Test(dataProvider = "presetClassesWithPutPost")
72 public<C extends BasePreset> void presetPutPost_WhenLoaded_SimulatorReturnsFakeValues(C preset) {
73 registerExpectationFromPreset(preset, RegistrationStrategy.CLEAR_THEN_SET);
75 Response cres = createSimulatorRequestBuilder(preset)
76 .method(preset.getReqMethod().name(),
77 Entity.entity(preset.getRequestBody(), MediaType.APPLICATION_JSON));
79 int status = cres.getStatus();
81 assertEquals(status, preset.getResponseCode());
85 public static Object[][] presetWithGetInstances(Method test) {
86 return new Object[][]{
87 {new PresetAAIGetSubscribersGet()},
88 {new PresetGetSessionSlotCheckIntervalGet()},
89 {new PresetGetUserGet()},
90 {new PresetAAIGetServicesGet()},
91 {new PresetSDCGetServiceMetadataGet(aLaCarteServiceCreationTest)},
92 {new PresetSDCGetServiceToscaModelGet( aLaCarteServiceCreationTest)},
93 {new PresetMSOOrchestrationRequestGet()},
94 {new PresetAAIGetNetworkZones()},
95 {new PresetAAIBadBodyForGetServicesGet("not a json")},
99 @Test(dataProvider = "presetWithGetInstances")
100 public <C extends BasePreset> void assertPresetWithGetMethod(C preset) {
101 registerExpectationFromPreset(preset, RegistrationStrategy.CLEAR_THEN_SET);
103 Response cres = createSimulatorRequestBuilder(preset).get();
105 int status = cres.getStatus();
107 assertEquals(status, preset.getResponseCode());
110 @Test(expectedExceptions = { RuntimeException.class }, expectedExceptionsMessageRegExp = ".*SimulatorLoaderTest.*")
111 public void assertPresetThatThrowException() {
113 registerExpectationFromPresets(Collections.singletonList(
117 public HttpMethod getReqMethod() {
118 throw new RuntimeException();
122 public String getReqPath() {
127 protected String getRootPath() {
130 }), RegistrationStrategy.CLEAR_THEN_SET);