1 package org.onap.vid.more;
3 import org.onap.simulator.presetGenerator.presets.BasePresets.BasePreset;
4 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIBadBodyForGetServicesGet;
5 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetNetworkZones;
6 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetPNFByRegionErrorPut;
7 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetServicesGet;
8 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetSubscribersGet;
9 import org.onap.simulator.presetGenerator.presets.aai.PresetAAISearchNodeQueryEmptyResult;
10 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIServiceDesignAndCreationPut;
11 import org.onap.simulator.presetGenerator.presets.ecompportal_att.PresetGetSessionSlotCheckIntervalGet;
12 import org.onap.simulator.presetGenerator.presets.ecompportal_att.PresetGetUserGet;
13 import org.onap.simulator.presetGenerator.presets.mso.PresetActivateServiceInstancePost;
14 import org.onap.simulator.presetGenerator.presets.mso.PresetDeactivateServiceInstancePost;
15 import org.onap.simulator.presetGenerator.presets.mso.PresetMSOCreateServiceInstancePost;
16 import org.onap.simulator.presetGenerator.presets.mso.PresetMSOOrchestrationRequestGet;
17 import org.onap.simulator.presetGenerator.presets.sdc.PresetSDCGetServiceMetadataGet;
18 import org.onap.simulator.presetGenerator.presets.sdc.PresetSDCGetServiceToscaModelGet;
19 import org.onap.vid.api.BaseApiTest;
20 import org.springframework.http.HttpMethod;
21 import org.testng.annotations.DataProvider;
22 import org.testng.annotations.Test;
23 import vid.automation.test.services.SimulatorApi;
24 import vid.automation.test.services.SimulatorApi.RegistrationStrategy;
26 import javax.ws.rs.client.Entity;
27 import javax.ws.rs.client.Invocation;
28 import javax.ws.rs.client.WebTarget;
29 import javax.ws.rs.core.MediaType;
30 import javax.ws.rs.core.Response;
31 import java.lang.reflect.Method;
32 import java.util.Collections;
33 import java.util.List;
36 import static org.testng.Assert.assertEquals;
37 import static vid.automation.test.services.SimulatorApi.registerExpectationFromPreset;
38 import static vid.automation.test.services.SimulatorApi.registerExpectationFromPresets;
40 public class SimulatorLoaderTest extends BaseApiTest {
43 protected Invocation.Builder createSimulatorRequestBuilder(BasePreset preset) {
44 WebTarget webTarget = client.target(SimulatorApi.getSimulationUri() + preset.getReqPath());
45 webTarget = addQueryParamsToWebTarget(preset, webTarget);
46 return webTarget.request()
47 .accept("application/json");
50 private WebTarget addQueryParamsToWebTarget(BasePreset preset, WebTarget webTarget) {
51 if (preset.getQueryParams() != null) {
52 for (Map.Entry<String, List> entry : preset.getQueryParams().entrySet()) {
53 webTarget = webTarget.queryParam(entry.getKey(), entry.getValue().toArray());
60 public static Object[][] presetClassesWithPutPost(Method test) {
61 return new Object[][]{
62 {new PresetAAIGetPNFByRegionErrorPut()},
63 {new PresetAAIServiceDesignAndCreationPut("a","b")},
64 {new PresetDeactivateServiceInstancePost()},
65 {new PresetActivateServiceInstancePost()},
66 {new PresetMSOCreateServiceInstancePost()}
70 @Test(dataProvider = "presetClassesWithPutPost")
71 public<C extends BasePreset> void presetPutPost_WhenLoaded_SimulatorReturnsFakeValues(C preset) {
72 registerExpectationFromPreset(preset, RegistrationStrategy.CLEAR_THEN_SET);
74 Response cres = createSimulatorRequestBuilder(preset)
75 .method(preset.getReqMethod().name(),
76 Entity.entity(preset.getRequestBody(), MediaType.APPLICATION_JSON));
78 int status = cres.getStatus();
80 assertEquals(status, preset.getResponseCode());
84 public static Object[][] presetWithGetInstances(Method test) {
85 return new Object[][]{
86 {new PresetAAIGetSubscribersGet()},
87 {new PresetGetSessionSlotCheckIntervalGet()},
88 {new PresetGetUserGet()},
89 {new PresetAAIGetServicesGet()},
90 {new PresetSDCGetServiceMetadataGet("a" , "b", "serviceCreationTest.zip")},
91 {new PresetSDCGetServiceToscaModelGet( "a", "serviceCreationTest.zip")},
92 {new PresetMSOOrchestrationRequestGet()},
93 {new PresetAAIGetNetworkZones()},
94 {new PresetAAISearchNodeQueryEmptyResult()},
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);