1 package org.opencomp.vid.more;
3 import org.opencomp.simulator.presetGenerator.presets.BasePresets.BasePreset;
4 import org.opencomp.simulator.presetGenerator.presets.aai.*;
5 import org.opencomp.simulator.presetGenerator.presets.ecompportal_att.PresetGetSessionSlotCheckIntervalGet;
6 import org.opencomp.simulator.presetGenerator.presets.ecompportal_att.PresetGetUserGet;
7 import org.opencomp.simulator.presetGenerator.presets.mso.PresetActivateServiceInstancePost;
8 import org.opencomp.simulator.presetGenerator.presets.mso.PresetDeactivateServiceInstancePost;
9 import org.opencomp.simulator.presetGenerator.presets.mso.PresetMSOCreateServiceInstancePost;
10 import org.opencomp.simulator.presetGenerator.presets.mso.PresetMSOOrchestrationRequestGet;
11 import org.opencomp.simulator.presetGenerator.presets.sdc.PresetSDCGetServiceMetadataGet;
12 import org.opencomp.simulator.presetGenerator.presets.sdc.PresetSDCGetServiceToscaModelGet;
13 import org.opencomp.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.services.SimulatorApi.registerExpectationFromPreset;
32 import static vid.automation.test.services.SimulatorApi.registerExpectationFromPresets;
34 public class SimulatorLoaderTest extends BaseApiTest {
37 protected Invocation.Builder createSimulatorRequestBuilder(BasePreset preset) {
38 WebTarget webTarget = client.target(SimulatorApi.getSimulationUri() + preset.getReqPath());
39 webTarget = addQueryParamsToWebTarget(preset, webTarget);
40 return webTarget.request()
41 .accept("application/json");
44 private WebTarget addQueryParamsToWebTarget(BasePreset preset, WebTarget webTarget) {
45 if (preset.getQueryParams() != null) {
46 for (Map.Entry<String, List> entry : preset.getQueryParams().entrySet()) {
47 webTarget = webTarget.queryParam(entry.getKey(), entry.getValue().toArray());
54 public static Object[][] presetClassesWithPutPost(Method test) {
55 return new Object[][]{
56 {new PresetAAIGetPNFByRegionErrorPut()},
57 {new PresetAAIServiceDesignAndCreationPut("a","b")},
58 {new PresetDeactivateServiceInstancePost()},
59 {new PresetActivateServiceInstancePost()},
60 {new PresetMSOCreateServiceInstancePost()}
64 @Test(dataProvider = "presetClassesWithPutPost")
65 public<C extends BasePreset> void presetPutPost_WhenLoaded_SimulatorReturnsFakeValues(C preset) {
66 registerExpectationFromPreset(preset, RegistrationStrategy.CLEAR_THEN_SET);
68 Response cres = createSimulatorRequestBuilder(preset)
69 .method(preset.getReqMethod().name(),
70 Entity.entity(preset.getRequestBody(), MediaType.APPLICATION_JSON));
72 int status = cres.getStatus();
74 assertEquals(status, preset.getResponseCode());
78 public static Object[][] presetWithGetInstances(Method test) {
79 return new Object[][]{
80 {new PresetAAIGetSubscribersGet()},
81 {new PresetGetSessionSlotCheckIntervalGet()},
82 {new PresetGetUserGet()},
83 {new PresetAAIGetServicesGet()},
84 {new PresetSDCGetServiceMetadataGet("a" , "b", "serviceCreationTest.zip")},
85 {new PresetSDCGetServiceToscaModelGet( "a", "serviceCreationTest.zip")},
86 {new PresetMSOOrchestrationRequestGet()},
87 {new PresetAAIGetNetworkZones()},
88 {new PresetAAISearchNodeQueryEmptyResult()},
89 {new PresetAAIBadBodyForGetServicesGet("not a json")},
93 @Test(dataProvider = "presetWithGetInstances")
94 public <C extends BasePreset> void assertPresetWithGetMethod(C preset) {
95 registerExpectationFromPreset(preset, RegistrationStrategy.CLEAR_THEN_SET);
97 Response cres = createSimulatorRequestBuilder(preset).get();
99 int status = cres.getStatus();
101 assertEquals(status, preset.getResponseCode());
104 @Test(expectedExceptions = { RuntimeException.class }, expectedExceptionsMessageRegExp = ".*SimulatorLoaderTest.*")
105 public void assertPresetThatThrowException() {
107 registerExpectationFromPresets(Collections.singletonList(
111 public HttpMethod getReqMethod() {
112 throw new RuntimeException();
116 public String getReqPath() {
121 protected String getRootPath() {
124 }), RegistrationStrategy.CLEAR_THEN_SET);