39110c5503c3518a9b516c46e0c7936b678add28
[vid.git] / vid-automation / src / test / java / org / onap / vid / api / AaiApiTest.java
1 package org.onap.vid.api;
2
3 import static net.javacrumbs.jsonunit.JsonMatchers.jsonEquals;
4 import static org.hamcrest.CoreMatchers.containsString;
5 import static org.hamcrest.MatcherAssert.assertThat;
6 import static org.onap.simulator.presetGenerator.presets.aai.PresetAAIStandardQueryGet.defaultPlacement;
7 import static org.onap.simulator.presetGenerator.presets.aai.PresetAAIStandardQueryGet.ofL3Network;
8 import static org.onap.simulator.presetGenerator.presets.aai.PresetAAIStandardQueryGet.ofServiceInstance;
9 import static org.onap.simulator.presetGenerator.presets.aai.PresetAAIStandardQueryGet.ofVlanTag;
10 import static org.onap.simulator.presetGenerator.presets.aai.PresetAAIStandardQueryGet.ofVnf;
11 import static org.onap.simulator.presetGenerator.presets.aai.PresetBaseAAICustomQuery.FORMAT.SIMPLE;
12 import static org.onap.simulator.presetGenerator.presets.ecompportal_att.EcompPortalPresetsUtils.getEcompPortalPresets;
13 import static org.testng.Assert.assertNotNull;
14 import static org.testng.Assert.assertTrue;
15 import static org.testng.AssertJUnit.assertEquals;
16 import static vid.automation.test.services.SimulatorApi.RegistrationStrategy.APPEND;
17 import static vid.automation.test.services.SimulatorApi.RegistrationStrategy.CLEAR_THEN_SET;
18 import static vid.automation.test.services.SimulatorApi.registerExpectationFromPresets;
19 import static vid.automation.test.utils.TestHelper.GET_SERVICE_MODELS_BY_DISTRIBUTION_STATUS;
20
21 import com.fasterxml.jackson.core.JsonProcessingException;
22 import com.google.common.collect.ImmutableList;
23 import com.google.common.collect.ImmutableMap;
24 import com.google.common.collect.ImmutableMultimap;
25 import java.io.IOException;
26 import java.lang.reflect.Method;
27 import java.net.URISyntaxException;
28 import java.util.List;
29 import java.util.UUID;
30 import net.javacrumbs.jsonunit.JsonAssert;
31 import net.javacrumbs.jsonunit.core.Configuration;
32 import net.javacrumbs.jsonunit.core.Option;
33 import org.apache.commons.text.StringEscapeUtils;
34 import org.apache.http.client.utils.URIBuilder;
35 import org.onap.simulator.presetGenerator.presets.BasePresets.BasePreset;
36 import org.onap.simulator.presetGenerator.presets.aai.AAIBaseGetL3NetworksByCloudRegionPreset;
37 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIBadBodyForGetServicesGet;
38 import org.onap.simulator.presetGenerator.presets.aai.PresetAAICloudRegionAndSourceFromConfigurationPut;
39 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetCloudOwnersByCloudRegionId;
40 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetHomingForVfModule;
41 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetInstanceGroupsByCloudRegion;
42 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetInstanceGroupsByCloudRegionInvalidRequest;
43 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetInstanceGroupsByCloudRegionRequiredMissing;
44 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetL3NetworksByCloudRegion;
45 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetL3NetworksByCloudRegionSpecificState;
46 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetNetworkCollectionDetails;
47 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetNetworkCollectionDetailsInvalidRequest;
48 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetNetworkCollectionDetailsRequiredMissing;
49 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetPortMirroringSourcePorts;
50 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetPortMirroringSourcePortsError;
51 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetRelatedInstanceGroupsByVnfId;
52 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetSubscribersGet;
53 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetVpnsByType;
54 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIModelVersionsByInvariantId;
55 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIStandardQueryGet;
56 import org.onap.simulator.presetGenerator.presets.aai.PresetBaseAAICustomQuery;
57 import org.onap.simulator.presetGenerator.presets.sdc.PresetSDCGetServiceMetadataGet;
58 import org.onap.simulator.presetGenerator.presets.sdc.PresetSDCGetServiceToscaModelGet;
59 import org.onap.vid.model.aai.AaiResponse;
60 import org.onap.vid.model.mso.OperationalEnvironmentList;
61 import org.onap.vid.more.LoggerFormatTest;
62 import org.onap.vid.more.LoggerFormatTest.LogName;
63 import org.springframework.core.ParameterizedTypeReference;
64 import org.springframework.http.HttpMethod;
65 import org.springframework.http.HttpStatus;
66 import org.springframework.http.ResponseEntity;
67 import org.springframework.web.client.HttpClientErrorException;
68 import org.springframework.web.client.HttpServerErrorException;
69 import org.springframework.web.util.UriComponentsBuilder;
70 import org.testng.AssertJUnit;
71 import org.testng.annotations.DataProvider;
72 import org.testng.annotations.Test;
73 import vid.automation.test.infra.FeatureTogglingTest;
74 import vid.automation.test.infra.Features;
75 import vid.automation.test.services.SimulatorApi;
76 import vid.automation.test.utils.TestHelper;
77
78 public class AaiApiTest extends BaseApiAaiTest {
79
80     private static final String AAI_HOMING_DATA_RESPONSE = "viewEdit/aaiHomingDataResponse.json";
81     public static final String GET_OPERATIONAL_ENVIRONMENTS_JSON = "get_operational_environments_aai.json";
82     public static final String GET_OPERATIONAL_ENVIRONMENTS_JSON_ERROR = "get_operational_environments_aai_error.json";
83     public static final String[] AAI_GET_SERVICES_ERROR_SIMULATOR_RESPONSES = {"getServicesAaiErrorResp.json", "create_new_instance/aai_get_full_subscribers.json"};
84     public static final String[] AAI_GET_SERVICES_FINE_SIMULATOR_RESPONSES = {"getServicesAaiFineResp.json", "create_new_instance/aai_get_full_subscribers.json"};
85     public static final String AAI_VNFS_FOR_CHANGE_MANAGEMENT_JSON = "changeManagement/get_vnf_data_by_globalid_and_service_type.json";
86     public static final String AAI_VNFS_FOR_CHANGE_MANAGEMENT_JSON_BY_PARAMS = "registration_to_simulator/changeManagement/get_vnf_data_by_globalid_and_service_type_reduced_response.json";
87     public static final String OPERATIONAL_ENVIRONMENT_TYPE = "VNF";
88     public static final String OPERATIONAL_ENVIRONMENT_STATUS = "Activate";
89     public static final String GET_INSTANCE_GROUPS_BY_CLOUDREGION_EXPECTED_RESPONSE = "{\"results\":[{\"instance-group\":{\"id\":\"AAI-12002-test3-vm230w\",\"description\":\"a9DEa0kpY\",\"instance-group-role\":\"JZmha7QSS4tJ\",\"model-invariant-id\":\"model-id3\",\"model-version-id\":\"a0efd5fc-f7be-4502-936a-a6c6392b958f\",\"instance-group-type\":\"type\",\"resource-version\":\"1520888659539\",\"instance-group-name\":\"wKmBXiO1xm8bK\",\"instance-group-function\":\"testfunction2\",\"relationship-list\":{\"relationship\":[{\"relationDataList\":[{\"relationship-key\":\"cloud-region.cloud-owner\",\"relationship-value\":\"AAI-12002-vm230w\"},{\"relationship-key\":\"cloud-region.cloud-region-id\",\"relationship-value\":\"AAI-region-vm230w\"}],\"relatedToPropertyList\":[{\"property-key\":\"cloud-region.owner-defined-type\",\"property-value\":null}],\"related-to\":\"cloud-region\",\"related-link\":\"/aai/v13/cloud-infrastructure/cloud-regions/cloud-region/AAI-12002-vm230w/AAI-region-vm230w\",\"relationship-label\":\"org.onap.relationships.inventory.Uses\",\"relationship-data\":[{\"relationship-key\":\"cloud-region.cloud-owner\",\"relationship-value\":\"AAI-12002-vm230w\"},{\"relationship-key\":\"cloud-region.cloud-region-id\",\"relationship-value\":\"AAI-region-vm230w\"}],\"related-to-property\":[{\"property-key\":\"cloud-region.owner-defined-type\",\"property-value\":null}]}]}}},{\"instance-group\":{\"id\":\"AAI-12002-test1-vm230w\",\"description\":\"a9DEa0kpY\",\"instance-group-role\":\"JZmha7QSS4tJ\",\"model-invariant-id\":\"model-id1\",\"model-version-id\":\"a0efd5fc-f7be-4502-936a-a6c6392b958f\",\"instance-group-type\":\"type\",\"resource-version\":\"1520886467989\",\"instance-group-name\":\"wKmBXiO1xm8bK\",\"instance-group-function\":\"testfunction2\",\"relationship-list\":{\"relationship\":[{\"relationDataList\":[{\"relationship-key\":\"cloud-region.cloud-owner\",\"relationship-value\":\"AAI-12002-vm230w\"},{\"relationship-key\":\"cloud-region.cloud-region-id\",\"relationship-value\":\"AAI-region-vm230w\"}],\"relatedToPropertyList\":[{\"property-key\":\"cloud-region.owner-defined-type\",\"property-value\":null}],\"related-to\":\"cloud-region\",\"related-link\":\"/aai/v13/cloud-infrastructure/cloud-regions/cloud-region/AAI-12002-vm230w/AAI-region-vm230w\",\"relationship-label\":\"org.onap.relationships.inventory.Uses\",\"relationship-data\":[{\"relationship-key\":\"cloud-region.cloud-owner\",\"relationship-value\":\"AAI-12002-vm230w\"},{\"relationship-key\":\"cloud-region.cloud-region-id\",\"relationship-value\":\"AAI-region-vm230w\"}],\"related-to-property\":[{\"property-key\":\"cloud-region.owner-defined-type\",\"property-value\":null}]}]}}},{\"instance-group\":{\"id\":\"AAI-12002-test2-vm230w\",\"description\":\"a9DEa0kpY\",\"instance-group-role\":\"JZmha7QSS4tJ\",\"model-invariant-id\":\"model-id2\",\"model-version-id\":\"version2\",\"instance-group-type\":\"type\",\"resource-version\":\"1520888629970\",\"instance-group-name\":\"wKmBXiO1xm8bK\",\"instance-group-function\":\"testfunction2\",\"relationship-list\":{\"relationship\":[{\"relationDataList\":[{\"relationship-key\":\"cloud-region.cloud-owner\",\"relationship-value\":\"AAI-12002-vm230w\"},{\"relationship-key\":\"cloud-region.cloud-region-id\",\"relationship-value\":\"AAI-region-vm230w\"}],\"relatedToPropertyList\":[{\"property-key\":\"cloud-region.owner-defined-type\",\"property-value\":null}],\"related-to\":\"cloud-region\",\"related-link\":\"/aai/v13/cloud-infrastructure/cloud-regions/cloud-region/AAI-12002-vm230w/AAI-region-vm230w\",\"relationship-label\":\"org.onap.relationships.inventory.Uses\",\"relationship-data\":[{\"relationship-key\":\"cloud-region.cloud-owner\",\"relationship-value\":\"AAI-12002-vm230w\"},{\"relationship-key\":\"cloud-region.cloud-region-id\",\"relationship-value\":\"AAI-region-vm230w\"}],\"related-to-property\":[{\"property-key\":\"cloud-region.owner-defined-type\",\"property-value\":null}]}]}}}]}\n";
90     public static final String GET_NETWORK_COLLECTION_EXPECTED_RESPONSE = "{\"results\":{\"collection\":{\"collection-id\":\"collection-1-2018-rs804s\",\"model-invariant-id\":\"5761e0a7-defj777\",\"model-version-id\":\"5761e0a7-defj232\",\"collection-name\":\"collection-name\",\"collection-type\":\"L3-NETWORK\",\"collection-role\":\"SUB-INTERFACE\",\"collection-function\":\"collection-function\",\"collection-customization-id\":\"custom-unique-data-id\",\"relationship-list\":{\"relationship\":[{\"relationDataList\":[{\"relationship-key\":\"customer.global-customer-id\",\"relationship-value\":\"customer-1-2017-rs804s\"},{\"relationship-key\":\"service-subscription.service-type\",\"relationship-value\":\"service-value7-rs804s\"},{\"relationship-key\":\"service-instance.service-instance-id\",\"relationship-value\":\"2UJZZ01777-rs804s\"}],\"relatedToPropertyList\":[{\"property-key\":\"service-instance.service-instance-name\",\"property-value\":null}],\"related-to\":\"service-instance\",\"related-link\":\"/aai/v13/business/customers/customer/customer-1-2017-rs804s/service-subscriptions/service-subscription/service-value7-rs804s/service-instances/service-instance/2UJZZ01777-rs804s\",\"relationship-label\":\"org.onap.relationships.inventory.MemberOf\",\"relationship-data\":[{\"relationship-key\":\"customer.global-customer-id\",\"relationship-value\":\"customer-1-2017-rs804s\"},{\"relationship-key\":\"service-subscription.service-type\",\"relationship-value\":\"service-value7-rs804s\"},{\"relationship-key\":\"service-instance.service-instance-id\",\"relationship-value\":\"2UJZZ01777-rs804s\"}],\"related-to-property\":[{\"property-key\":\"service-instance.service-instance-name\",\"property-value\":null}]},{\"relationDataList\":[{\"relationship-key\":\"instance-group.id\",\"relationship-value\":\"instanceGroup-2018-rs804s\"}],\"relatedToPropertyList\":[{\"property-key\":\"instance-group.description\",\"property-value\":\"zr6h\"},{\"property-key\":\"instance-group.instance-group-name\",\"property-value\":\"wKmBXiO1xm8bK\"}],\"related-to\":\"instance-group\",\"related-link\":\"/aai/v13/network/instance-groups/instance-group/instanceGroup-2018-rs804s\",\"relationship-label\":\"org.onap.relationships.inventory.MemberOf\",\"relationship-data\":[{\"relationship-key\":\"instance-group.id\",\"relationship-value\":\"instanceGroup-2018-rs804s\"}],\"related-to-property\":[{\"property-key\":\"instance-group.description\",\"property-value\":\"zr6h\"},{\"property-key\":\"instance-group.instance-group-name\",\"property-value\":\"wKmBXiO1xm8bK\"}]}]},\"resource-version\":\"1521662811309\"},\"networks\":[{\"network-id\":\"l3network-id-rs804s\",\"network-name\":\"oam-net\",\"network-type\":\"Tenant_Layer_3\",\"network-role\":\"RosemaProtectedOam.OAM\",\"network-technology\":\"Contrail\",\"is-bound-to-vpn\":false,\"resource-version\":\"1521662814627\",\"orchestration-status\":\"Created\",\"is-provider-network\":false,\"is-shared-network\":false,\"is-external-network\":false,\"relationship-list\":{\"relationship\":[{\"relationDataList\":[{\"relationship-key\":\"instance-group.id\",\"relationship-value\":\"instanceGroup-2018-rs804s\"}],\"relatedToPropertyList\":[{\"property-key\":\"instance-group.description\",\"property-value\":\"zr6h\"},{\"property-key\":\"instance-group.instance-group-name\",\"property-value\":\"wKmBXiO1xm8bK\"}],\"related-to\":\"instance-group\",\"related-link\":\"/aai/v13/network/instance-groups/instance-group/instanceGroup-2018-rs804s\",\"relationship-label\":\"org.onap.relationships.inventory.MemberOf\",\"relationship-data\":[{\"relationship-key\":\"instance-group.id\",\"relationship-value\":\"instanceGroup-2018-rs804s\"}],\"related-to-property\":[{\"property-key\":\"instance-group.description\",\"property-value\":\"zr6h\"},{\"property-key\":\"instance-group.instance-group-name\",\"property-value\":\"wKmBXiO1xm8bK\"}]}]}},{\"network-id\":\"l3network-id-3-rs804s\",\"network-name\":\"oam-net\",\"network-type\":\"Tenant_Layer_3\",\"network-role\":\"RosemaProtectedOam.OAM\",\"network-technology\":\"Contrail\",\"is-bound-to-vpn\":false,\"resource-version\":\"1521662816043\",\"orchestration-status\":\"Created\",\"is-provider-network\":false,\"is-shared-network\":false,\"is-external-network\":false,\"relationship-list\":{\"relationship\":[{\"relationDataList\":[{\"relationship-key\":\"instance-group.id\",\"relationship-value\":\"instanceGroup-2018-rs804s\"}],\"relatedToPropertyList\":[{\"property-key\":\"instance-group.description\",\"property-value\":\"zr6h\"},{\"property-key\":\"instance-group.instance-group-name\",\"property-value\":\"wKmBXiO1xm8bK\"}],\"related-to\":\"instance-group\",\"related-link\":\"/aai/v13/network/instance-groups/instance-group/instanceGroup-2018-rs804s\",\"relationship-label\":\"org.onap.relationships.inventory.MemberOf\",\"relationship-data\":[{\"relationship-key\":\"instance-group.id\",\"relationship-value\":\"instanceGroup-2018-rs804s\"}],\"related-to-property\":[{\"property-key\":\"instance-group.description\",\"property-value\":\"zr6h\"},{\"property-key\":\"instance-group.instance-group-name\",\"property-value\":\"wKmBXiO1xm8bK\"}]}]}},{\"network-id\":\"l3network-id-2-rs804s\",\"network-name\":\"oam-net\",\"network-type\":\"Tenant_Layer_3\",\"network-role\":\"RosemaProtectedOam.OAM\",\"network-technology\":\"Contrail\",\"is-bound-to-vpn\":false,\"resource-version\":\"1521662815304\",\"orchestration-status\":\"Created\",\"is-provider-network\":false,\"is-shared-network\":false,\"is-external-network\":false,\"relationship-list\":{\"relationship\":[{\"relationDataList\":[{\"relationship-key\":\"instance-group.id\",\"relationship-value\":\"instanceGroup-2018-rs804s\"}],\"relatedToPropertyList\":[{\"property-key\":\"instance-group.description\",\"property-value\":\"zr6h\"},{\"property-key\":\"instance-group.instance-group-name\",\"property-value\":\"wKmBXiO1xm8bK\"}],\"related-to\":\"instance-group\",\"related-link\":\"/aai/v13/network/instance-groups/instance-group/instanceGroup-2018-rs804s\",\"relationship-label\":\"org.onap.relationships.inventory.MemberOf\",\"relationship-data\":[{\"relationship-key\":\"instance-group.id\",\"relationship-value\":\"instanceGroup-2018-rs804s\"}],\"related-to-property\":[{\"property-key\":\"instance-group.description\",\"property-value\":\"zr6h\"},{\"property-key\":\"instance-group.instance-group-name\",\"property-value\":\"wKmBXiO1xm8bK\"}]}]}}],\"service-instance\":{\"service-instance-id\":\"2UJZZ01777-rs804s\",\"resource-version\":\"1521662813382\",\"relationship-list\":{\"relationship\":[{\"relationDataList\":[{\"relationship-key\":\"collection.collection-id\",\"relationship-value\":\"collection-1-2018-rs804s\"}],\"relatedToPropertyList\":null,\"related-to\":\"collection\",\"related-link\":\"/aai/v13/network/collections/collection/collection-1-2018-rs804s\",\"relationship-label\":\"org.onap.relationships.inventory.MemberOf\",\"relationship-data\":[{\"relationship-key\":\"collection.collection-id\",\"relationship-value\":\"collection-1-2018-rs804s\"}],\"related-to-property\":null}]}},\"instance-group\":{\"id\":\"instanceGroup-2018-rs804s\",\"description\":\"zr6h\",\"instance-group-role\":\"JZmha7QSS4tJ\",\"model-invariant-id\":\"5761e0a7-defj777\",\"model-version-id\":\"5761e0a7-defj22\",\"instance-group-type\":\"7DDjOdNL\",\"resource-version\":\"1521662814023\",\"instance-group-name\":\"wKmBXiO1xm8bK\",\"instance-group-function\":\"testfunction2\",\"relationship-list\":{\"relationship\":[{\"relationDataList\":[{\"relationship-key\":\"l3-network.network-id\",\"relationship-value\":\"l3network-id-rs804s\"}],\"relatedToPropertyList\":[{\"property-key\":\"l3-network.network-name\",\"property-value\":\"oam-net\"}],\"related-to\":\"l3-network\",\"related-link\":\"/aai/v13/network/l3-networks/l3-network/l3network-id-rs804s\",\"relationship-label\":\"org.onap.relationships.inventory.MemberOf\",\"relationship-data\":[{\"relationship-key\":\"l3-network.network-id\",\"relationship-value\":\"l3network-id-rs804s\"}],\"related-to-property\":[{\"property-key\":\"l3-network.network-name\",\"property-value\":\"oam-net\"}]},{\"relationDataList\":[{\"relationship-key\":\"collection.collection-id\",\"relationship-value\":\"collection-1-2018-rs804s\"}],\"relatedToPropertyList\":null,\"related-to\":\"collection\",\"related-link\":\"/aai/v13/network/collections/collection/collection-1-2018-rs804s\",\"relationship-label\":\"org.onap.relationships.inventory.MemberOf\",\"relationship-data\":[{\"relationship-key\":\"collection.collection-id\",\"relationship-value\":\"collection-1-2018-rs804s\"}],\"related-to-property\":null},{\"relationDataList\":[{\"relationship-key\":\"l3-network.network-id\",\"relationship-value\":\"l3network-id-3-rs804s\"}],\"relatedToPropertyList\":[{\"property-key\":\"l3-network.network-name\",\"property-value\":\"oam-net\"}],\"related-to\":\"l3-network\",\"related-link\":\"/aai/v13/network/l3-networks/l3-network/l3network-id-3-rs804s\",\"relationship-label\":\"org.onap.relationships.inventory.MemberOf\",\"relationship-data\":[{\"relationship-key\":\"l3-network.network-id\",\"relationship-value\":\"l3network-id-3-rs804s\"}],\"related-to-property\":[{\"property-key\":\"l3-network.network-name\",\"property-value\":\"oam-net\"}]},{\"relationDataList\":[{\"relationship-key\":\"l3-network.network-id\",\"relationship-value\":\"l3network-id-2-rs804s\"}],\"relatedToPropertyList\":[{\"property-key\":\"l3-network.network-name\",\"property-value\":\"oam-net\"}],\"related-to\":\"l3-network\",\"related-link\":\"/aai/v13/network/l3-networks/l3-network/l3network-id-2-rs804s\",\"relationship-label\":\"org.onap.relationships.inventory.MemberOf\",\"relationship-data\":[{\"relationship-key\":\"l3-network.network-id\",\"relationship-value\":\"l3network-id-2-rs804s\"}],\"related-to-property\":[{\"property-key\":\"l3-network.network-name\",\"property-value\":\"oam-net\"}]}]}}}}\n";
91     public static final String GET_AAI_SERVIES_EXPECTED_RESULT = "{\n" +
92             "  \"services\": [{\n" +
93             "    \"uuid\": \"20c4431c-246d-11e7-93ae-92361f002671\",\n" +
94             "    \"invariantUUID\": \"78ca26d0-246d-11e7-93ae-92361f002671\",\n" +
95             "    \"name\": \"vSAMP10aDEV::base::module-0\",\n" +
96             "    \"version\": \"2\",\n" +
97             "    \"toscaModelURL\": null,\n" +
98             "    \"category\": \"resource\",\n" +
99             "    \"lifecycleState\": null,\n" +
100             "    \"lastUpdaterUserId\": null,\n" +
101             "    \"lastUpdaterFullName\": null,\n" +
102             "    \"distributionStatus\": \"DISTRIBUTION_COMPLETE_OK\",\n" +
103             "    \"orchestrationType\": null,\n" +
104             "    \"artifacts\": null,\n" +
105             "    \"resources\": null\n" +
106             "  }, {\n" +
107             "    \"uuid\": \"797a6c41-0f80-4d35-a288-3920c4e06baa\",\n" +
108             "    \"invariantUUID\": \"5b607929-6088-4614-97ef-cac817508e0e\",\n" +
109             "    \"name\": \"CONTRAIL30_L2NODHCP\",\n" +
110             "    \"version\": \"1.0\",\n" +
111             "    \"toscaModelURL\": null,\n" +
112             "    \"category\": \"resource\",\n" +
113             "    \"lifecycleState\": null,\n" +
114             "    \"lastUpdaterUserId\": null,\n" +
115             "    \"lastUpdaterFullName\": null,\n" +
116             "    \"distributionStatus\": \"DISTRIBUTION_COMPLETE_ERROR\",\n" +
117             "    \"orchestrationType\": null,\n" +
118             "    \"artifacts\": null,\n" +
119             "    \"resources\": null\n" +
120             "  }, {\n" +
121             "    \"uuid\": \"f1bde010-cc5f-4765-941f-75f15b24f9fc\",\n" +
122             "    \"invariantUUID\": \"0143d57b-a517-4de9-a0a1-eb76db51f402\",\n" +
123             "    \"name\": \"BkVmxAv061917..base_vPE_AV..module-0\",\n" +
124             "    \"version\": \"2\",\n" +
125             "    \"toscaModelURL\": null,\n" +
126             "    \"category\": \"resource\",\n" +
127             "    \"lifecycleState\": null,\n" +
128             "    \"lastUpdaterUserId\": null,\n" +
129             "    \"lastUpdaterFullName\": null,\n" +
130             "    \"orchestrationType\": null,\n" +
131             "    \"distributionStatus\": \"DISTRIBUTION_COMPLETE_OK\",\n" +
132             "    \"artifacts\": null,\n" +
133             "    \"resources\": null\n" +
134             "  }, {\n" +
135             "    \"uuid\": \"ipe-resource-id-ps-02\",\n" +
136             "    \"invariantUUID\": \"ipe-resource-id-ps-02\",\n" +
137             "    \"name\": \"abc\",\n" +
138             "    \"version\": \"v1.0\",\n" +
139             "    \"toscaModelURL\": null,\n" +
140             "    \"category\": \"resource\",\n" +
141             "    \"lifecycleState\": null,\n" +
142             "    \"lastUpdaterUserId\": null,\n" +
143             "    \"lastUpdaterFullName\": null,\n" +
144             "    \"distributionStatus\": \"DISTRIBUTION_COMPLETE_OK\",\n" +
145             "    \"orchestrationType\": null,\n" +
146             "    \"artifacts\": null,\n" +
147             "    \"resources\": null\n" +
148             "  }, {\n" +
149             "    \"uuid\": \"lmoser410-connector-model-version-id\",\n" +
150             "    \"invariantUUID\": \"lmoser410-connector-model-id\",\n" +
151             "    \"name\": \"connector\",\n" +
152             "    \"version\": \"v1.0\",\n" +
153             "    \"toscaModelURL\": null,\n" +
154             "    \"category\": \"widget\",\n" +
155             "    \"lifecycleState\": null,\n" +
156             "    \"lastUpdaterUserId\": null,\n" +
157             "    \"lastUpdaterFullName\": null,\n" +
158             "    \"distributionStatus\": \"DISTRIBUTION_COMPLETE_OK\",\n" +
159             "    \"orchestrationType\": null,\n" +
160             "    \"artifacts\": null,\n" +
161             "    \"resources\": null\n" +
162             "  }, {\n" +
163             "    \"uuid\": \"ff2ae348-214a-11e7-93ae-92361f002673\",\n" +
164             "    \"invariantUUID\": \"3a97db99-c4bb-498a-a13a-38f65f1ced3d\",\n" +
165             "    \"name\": \"vSAMP10aDEV::base::module-0\",\n" +
166             "    \"version\": \"1.0\",\n" +
167             "    \"toscaModelURL\": null,\n" +
168             "    \"category\": \"resource\",\n" +
169             "    \"lifecycleState\": null,\n" +
170             "    \"lastUpdaterUserId\": null,\n" +
171             "    \"lastUpdaterFullName\": null,\n" +
172             "    \"orchestrationType\": null,\n" +
173             "    \"distributionStatus\": \"DISTRIBUTION_COMPLETE_OK\",\n" +
174             "    \"artifacts\": null,\n" +
175             "    \"resources\": null\n" +
176             "  }, {\n" +
177             "    \"uuid\": \"204c641a-3494-48c8-979a-86856f5fd32a\",\n" +
178             "    \"invariantUUID\": \"3c504d40-b847-424c-9d25-4fb7e0a3e994\",\n" +
179             "    \"name\": \"named-query-element\",\n" +
180             "    \"version\": \"1.0\",\n" +
181             "    \"toscaModelURL\": null,\n" +
182             "    \"category\": \"widget\",\n" +
183             "    \"lifecycleState\": null,\n" +
184             "    \"lastUpdaterUserId\": null,\n" +
185             "    \"lastUpdaterFullName\": null,\n" +
186             "    \"orchestrationType\": null,\n" +
187             "    \"distributionStatus\": \"DISTRIBUTION_COMPLETE_OK\",\n" +
188             "    \"artifacts\": null,\n" +
189             "    \"resources\": null\n" +
190             "  }, {\n" +
191             "    \"uuid\": \"acba1f72-c6e0-477f-9426-ad190151e100\",\n" +
192             "    \"invariantUUID\": \"93e56950-cb19-44e6-ace4-8b50f2d02e45\",\n" +
193             "    \"name\": \"RG_6-19_Test\",\n" +
194             "    \"version\": \"1.0\",\n" +
195             "    \"toscaModelURL\": null,\n" +
196             "    \"category\": \"resource\",\n" +
197             "    \"lifecycleState\": null,\n" +
198             "    \"lastUpdaterUserId\": null,\n" +
199             "    \"lastUpdaterFullName\": null,\n" +
200             "    \"orchestrationType\": null,\n" +
201             "    \"distributionStatus\": \"DISTRIBUTION_COMPLETE_OK\",\n" +
202             "    \"artifacts\": null,\n" +
203             "    \"resources\": null\n" +
204             "  }, {\n" +
205             "    \"uuid\": \"fc65e5e7-45c7-488a-b36d-f453ab3057fe\",\n" +
206             "    \"invariantUUID\": \"ee448504-ceee-47db-8e1b-742115f219db\",\n" +
207             "    \"name\": \"ciServicea268facd387e\",\n" +
208             "    \"version\": \"1.0\",\n" +
209             "    \"toscaModelURL\": null,\n" +
210             "    \"category\": \"service\",\n" +
211             "    \"lifecycleState\": null,\n" +
212             "    \"lastUpdaterUserId\": null,\n" +
213             "    \"lastUpdaterFullName\": null,\n" +
214             "    \"orchestrationType\": null,\n" +
215             "    \"distributionStatus\": \"DISTRIBUTION_COMPLETE_OK\",\n" +
216             "    \"artifacts\": null,\n" +
217             "    \"resources\": null\n" +
218             "  }, {\n" +
219             "    \"uuid\": \"027948b6-25e2-4e39-b87d-d9f5797941de\",\n" +
220             "    \"invariantUUID\": \"56f2d0d3-7943-4159-bf01-b82692ec035e\",\n" +
221             "    \"name\": \"service_sanity_amir\",\n" +
222             "    \"version\": \"2.0\",\n" +
223             "    \"toscaModelURL\": null,\n" +
224             "    \"category\": \"service\",\n" +
225             "    \"lifecycleState\": null,\n" +
226             "    \"lastUpdaterUserId\": null,\n" +
227             "    \"lastUpdaterFullName\": null,\n" +
228             "    \"orchestrationType\": null,\n" +
229             "    \"distributionStatus\": \"DISTRIBUTION_COMPLETE_OK\",\n" +
230             "    \"artifacts\": null,\n" +
231             "    \"resources\": null\n" +
232             "  }, {\n" +
233             "    \"uuid\": \"fbf96e3b-1804-4c89-bf5b-53acb7f2edc0\",\n" +
234             "    \"invariantUUID\": \"56f2d0d3-7943-4159-bf01-b82692ec035e\",\n" +
235             "    \"name\": \"service_sanity_amir\",\n" +
236             "    \"version\": \"3.0\",\n" +
237             "    \"toscaModelURL\": null,\n" +
238             "    \"category\": \"service\",\n" +
239             "    \"lifecycleState\": null,\n" +
240             "    \"lastUpdaterUserId\": null,\n" +
241             "    \"lastUpdaterFullName\": null,\n" +
242             "    \"orchestrationType\": null,\n" +
243             "    \"distributionStatus\": \"DISTRIBUTION_COMPLETE_OK\",\n" +
244             "    \"artifacts\": null,\n" +
245             "    \"resources\": null\n" +
246             "  }],\n" +
247             "  \"readOnly\": false\n" +
248             "}";
249     private static final String AAI_GET_ACTIVE_NETWORKS = "/aai_get_active_networks";
250
251     private String getGetOperationEnvironmentsUri() {
252         return uri.toASCIIString() + "/get_operational_environments";
253     }
254
255     private String getAaiServicesUri() {
256         return uri.toASCIIString() + "/rest/models/services";
257     }
258
259     private String getGetOperationEnvironmentUriWithParameters() {
260         String url = getGetOperationEnvironmentsUri();
261         UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(url)
262                 // Add query parameter
263                 .queryParam("operationalEnvironmentStatus", OPERATIONAL_ENVIRONMENT_STATUS)
264                 .queryParam("operationalEnvironmentType", OPERATIONAL_ENVIRONMENT_TYPE);
265
266         String urlWithParameters = builder.toUriString();
267         return urlWithParameters;
268
269     }
270
271     private AaiResponse<OperationalEnvironmentList> loginAndDoGetWithUrl(String url) {
272         ResponseEntity<AaiResponse<OperationalEnvironmentList>> responseEntity = restTemplate.exchange(
273                 url,
274                 HttpMethod.GET,
275                 null,
276                 new ParameterizedTypeReference<AaiResponse<OperationalEnvironmentList>>() {});
277         AaiResponse<OperationalEnvironmentList> response = responseEntity.getBody();
278         return response;
279     }
280
281     @Test
282     public void testErrorGetOperationalEnvironments() {
283         //Register required response
284         SimulatorApi.registerExpectation(GET_OPERATIONAL_ENVIRONMENTS_JSON_ERROR, APPEND);
285         String url = getGetOperationEnvironmentsUri();
286         AaiResponse<OperationalEnvironmentList> response = loginAndDoGetWithUrl(url);
287         assertEquals(HttpStatus.INTERNAL_SERVER_ERROR.value(), response.getHttpCode());
288         assertEquals("simulated error text", response.getErrorMessage());
289
290
291     }
292
293     //This test requires a simulator which runs on VID
294     @Test
295     public void testSuccessGetOperationalEnvironments() {
296         //Register required response
297         String uuidOfOperationalEnvironment = "f07ca256-96dd-40ad-b4d2-7a77e2a974ed";
298         SimulatorApi.registerExpectation(GET_OPERATIONAL_ENVIRONMENTS_JSON, ImmutableMap.of("UUID_of_Operational_Environment", uuidOfOperationalEnvironment), APPEND);
299         String url = getGetOperationEnvironmentUriWithParameters();
300         AaiResponse<OperationalEnvironmentList> response = loginAndDoGetWithUrl(url);
301         assertEquals(HttpStatus.OK.value(), response.getHttpCode());
302         OperationalEnvironmentList list = response.getT();
303         assertNotNull(list.getOperationalEnvironment());
304         assertEquals(2, list.getOperationalEnvironment().size());
305         assertEquals(uuidOfOperationalEnvironment, list.getOperationalEnvironment().get(0).getOperationalEnvironmentId());
306         assertEquals(1, list.getOperationalEnvironment().get(0).getRelationshipList().getRelationship().size());
307     }
308
309     @Test(dataProvider = "errorCodes")
310     public void getServicesWitErrorResponse(int errorCode) throws IOException, URISyntaxException {
311         TestHelper.resetAaiCache(GET_SERVICE_MODELS_BY_DISTRIBUTION_STATUS, restTemplate, uri);
312         final String expectedResult = "{\"services\":[],\"readOnly\":false}";
313
314         callAaiWithSimulatedErrorResponse(AAI_GET_SERVICES_ERROR_SIMULATOR_RESPONSES,
315                 ImmutableMap.of("500", Integer.toString(errorCode), "ERROR_PAYLOAD", StringEscapeUtils.escapeJson(expectedResult)),
316                 getAaiServicesUri(), "", 200, expectedResult, HttpMethod.GET);
317
318     }
319
320     @Test
321     public void getServicesFineRequest() throws IOException, URISyntaxException {
322         TestHelper.resetAaiCache(GET_SERVICE_MODELS_BY_DISTRIBUTION_STATUS, restTemplate, uri);
323         callAaiWithSimulatedErrorResponse(AAI_GET_SERVICES_FINE_SIMULATOR_RESPONSES,
324                 ImmutableMap.of(),
325                 getAaiServicesUri(), "", 200, GET_AAI_SERVIES_EXPECTED_RESULT, HttpMethod.GET);
326     }
327
328     @Test
329     public void whenGetServicesErrorResponse_badResponseIsNotCached() throws IOException, URISyntaxException {
330         TestHelper.resetAaiCache(GET_SERVICE_MODELS_BY_DISTRIBUTION_STATUS, restTemplate, uri);
331
332
333         final String expectedErrorResult = "{\"services\":[],\"readOnly\":false}";
334         //call AAI with bad response by clear exceptions from simulator, bad response shall not be cached
335         callAaiWithSimulatedErrorResponse(new String[]{}, ImmutableMap.of(), getAaiServicesUri(), "", 200, expectedErrorResult, HttpMethod.GET);
336
337         //call AAI with fine response
338         callAaiWithSimulatedErrorResponse(AAI_GET_SERVICES_FINE_SIMULATOR_RESPONSES,
339                 ImmutableMap.of(),
340                 getAaiServicesUri(), "", 200, GET_AAI_SERVIES_EXPECTED_RESULT, HttpMethod.GET);
341     }
342
343     @DataProvider
344     public static Object[][] errorCodes(Method test) {
345         return new Object[][]{
346                 {500},{505}, {400}, {401}, {405}
347         };
348     }
349
350     @Test
351     public void whenThrowExceptionInsAaiResponseErrorAreLogged() {
352         String notAJson = "not a json";
353         SimulatorApi.registerExpectationFromPreset(new PresetAAIBadBodyForGetServicesGet(notAJson), CLEAR_THEN_SET);
354         SimulatorApi.registerExpectationFromPresets(getEcompPortalPresets(), APPEND);
355         SimulatorApi.registerExpectationFromPreset(new PresetAAIGetSubscribersGet(), APPEND);
356
357         restTemplateErrorAgnostic.getForEntity(uri + "/aai_get_services", String.class);
358         String logLines = LoggerFormatTest.getLogLines(LogName.error, 15, 0, restTemplate, uri);
359
360         assertThat("not found in error log", logLines, containsString("Failed to parse aai response"));
361         assertThat("not found in error log", logLines, containsString(notAJson));
362         assertThat("not found in error log", logLines, containsString("GetServicesAAIRespone"));
363
364     }
365
366     @Test
367     public void portMirroringConfigData_givenValidAaiResponse_yieldCloudRegionId() {
368         SimulatorApi.registerExpectationFromPreset(new PresetAAICloudRegionAndSourceFromConfigurationPut("SOME-RANDOM-UUID", "THE-EXPECTED-REGION-ID"), CLEAR_THEN_SET);
369
370         final String response = restTemplate.getForObject(uri + "/aai_getPortMirroringConfigsData?configurationIds=" + "SOME-RANDOM-UUID", String.class);
371
372         final ImmutableMap<String, ImmutableMap<String, String>> expected = ImmutableMap.of(
373                 "SOME-RANDOM-UUID", ImmutableMap.of(
374                         "cloudRegionId", "THE-EXPECTED-REGION-ID"
375                 ));
376
377         assertResponse(expected, response);
378
379         /*
380         More tests:
381         [ ]  Error responses from AAI (404 etc): descriptive error response, including what tried and what happened
382         [ ]  malformed response from AAI: descriptive error response, including the payload
383         [ ]  empty/missing value for configurationId: client-error http code
384          */
385     }
386
387
388     @Test
389     public void portMirroringSourcePorts_validAAIResponseWithSinglePort_yieldCorrectPortData() {
390         SimulatorApi.registerExpectationFromPreset(
391                 new PresetAAIGetPortMirroringSourcePorts("CONFIGURATION-ID", "INTERFACE-ID", "INTERFACE-NAME", true),
392                 CLEAR_THEN_SET
393         );
394
395         final String response = restTemplate.getForObject(uri + "/aai_getPortMirroringSourcePorts?configurationIds=" + "CONFIGURATION-ID", String.class);
396
397         final ImmutableMap<String, ImmutableList> expected = ImmutableMap.of(
398                 "CONFIGURATION-ID", ImmutableList.of(ImmutableMap.of(
399                         "interfaceId", "INTERFACE-ID", "interfaceName", "INTERFACE-NAME", "isPortMirrored", true
400                 )));
401
402         assertResponse(expected, response);
403     }
404
405     @Test
406     public void portMirroringSourcePorts_nullValueForInterfaceId_yield200OkWithFineDescription() {
407         final PresetAAIGetPortMirroringSourcePorts preset = new PresetAAIGetPortMirroringSourcePorts("CONFIGURATION-ID", null, "INTERFACE-NAME", true);
408         SimulatorApi.registerExpectationFromPreset(
409                 preset,
410                 CLEAR_THEN_SET
411         );
412
413         final String response = restTemplate.getForObject(uri + "/aai_getPortMirroringSourcePorts?configurationIds=" + "CONFIGURATION-ID", String.class);
414
415         final ImmutableMap<String, ImmutableList<ImmutableMap>> expected = ImmutableMap.of(
416                 "CONFIGURATION-ID", ImmutableList.of(ImmutableMap.of(
417                         "errorDescription", "Value of 'interface-id' is missing.",
418                         "rawAaiResponse", preset.getResponseBody().toString()
419                 )));
420
421         assertResponse(expected, response);
422     }
423
424     @Test
425     public void portMirroringSourcePorts_given503ErrorAaiResponse_yield200OkWithErrorMsg() {
426         final PresetAAIGetPortMirroringSourcePortsError preset = new PresetAAIGetPortMirroringSourcePortsError("CONFIGURATION-ID", "INTERFACE-ID", "INTERFACE-NAME", true);
427         SimulatorApi.registerExpectationFromPreset(
428                 preset,
429                 CLEAR_THEN_SET
430         );
431
432         final String response = restTemplate.getForObject(uri + "/aai_getPortMirroringSourcePorts?configurationIds=" + "CONFIGURATION-ID", String.class);
433
434         final ImmutableMap<String, ImmutableList<ImmutableMap>> expected = ImmutableMap.of(
435                 "CONFIGURATION-ID", ImmutableList.of(ImmutableMap.of(
436                         "errorDescription", "Got 503 from aai",
437                         "rawAaiResponse", preset.getResponseBody()
438                 )));
439
440         assertResponse(expected, response);
441     }
442
443     @Test
444     public void portMirroringConfigData_given404ErrorAaiResponse_yield200OkWithErrorMsg() {
445         SimulatorApi.clearAll();
446
447         final String response = restTemplate.getForObject(uri + "/aai_getPortMirroringConfigsData?configurationIds=" + "SOME-RANDOM-UUID", String.class);
448
449         final ImmutableMap<String, ImmutableMap<String, String>> expected = ImmutableMap.of(
450                 "SOME-RANDOM-UUID", ImmutableMap.of(
451                         "errorDescription", "Got 404 from aai",
452                         "rawAaiResponse", ""
453                 ));
454
455         assertResponse(expected, response);
456     }
457
458     @Test
459     public void getNetworkCollectionDetailsByServiceInstanceId_yieldValidResponse() {
460         SimulatorApi.clearAll();
461         final PresetAAIGetNetworkCollectionDetails presetAAIGetNetworkCollectionDetails = new PresetAAIGetNetworkCollectionDetails("SOME-RANDOM-UUID");
462         SimulatorApi.registerExpectationFromPreset(presetAAIGetNetworkCollectionDetails, CLEAR_THEN_SET);
463         final String response = restTemplate.getForObject(uri + "/aai_get_network_collection_details/" + "SOME-RANDOM-UUID", String.class);
464
465         assertResponse(GET_NETWORK_COLLECTION_EXPECTED_RESPONSE, response);
466     }
467
468     @Test
469     public void getNetworkCollectionDetailsByServiceInstanceId_responseWithExtraFields_yieldValidResponse() {
470         SimulatorApi.clearAll();
471         final PresetAAIGetNetworkCollectionDetailsInvalidRequest presetAAIGetNetworkCollectionDetails = new PresetAAIGetNetworkCollectionDetailsInvalidRequest("SOME-RANDOM-UUID");
472         SimulatorApi.registerExpectationFromPreset(presetAAIGetNetworkCollectionDetails, CLEAR_THEN_SET);
473         final String response = restTemplate.getForObject(uri + "/aai_get_network_collection_details/" + "SOME-RANDOM-UUID", String.class);
474
475         assertResponse(GET_NETWORK_COLLECTION_EXPECTED_RESPONSE, response);
476     }
477
478     @Test
479     public void getNetworkCollectionDetailsByServiceInstanceId_given404ErrorAaiResponse_yield200OkWithErrorMsg() {
480         SimulatorApi.clearAll();
481         try {
482             restTemplate.getForObject(uri + "/aai_get_network_collection_details/" + "SOME-RANDOM-UUID", String.class);
483         } catch (HttpClientErrorException e) {
484             assertEquals(HttpStatus.NOT_FOUND, e.getStatusCode());
485         }
486     }
487
488     @Test
489     public void getNetworkCollectionDetailsByServiceInstanceId_responseWithRequiredMissing() {
490         SimulatorApi.clearAll();
491         final PresetAAIGetNetworkCollectionDetailsRequiredMissing presetAAIGetNetworkCollectionDetails = new PresetAAIGetNetworkCollectionDetailsRequiredMissing("SOME-RANDOM-UUID");
492         SimulatorApi.registerExpectationFromPreset(presetAAIGetNetworkCollectionDetails, CLEAR_THEN_SET);
493         try {
494             restTemplate.getForObject(uri + "/aai_get_network_collection_details/" + "SOME-RANDOM-UUID", String.class);
495         } catch (HttpServerErrorException e) {
496             assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, e.getStatusCode());
497         }
498     }
499
500     @Test
501     public void getGetInstanceGroupsByCloudRegion_yieldValidResponse() {
502         SimulatorApi.clearAll();
503         final PresetAAIGetInstanceGroupsByCloudRegion presetAAIGetInstanceGroupsByCloudRegion = new PresetAAIGetInstanceGroupsByCloudRegion("CLOUD%20OWNER", "CLOUD-REGION-ID", "NETWORK%20FUNCTION");
504         SimulatorApi.registerExpectationFromPreset(presetAAIGetInstanceGroupsByCloudRegion, CLEAR_THEN_SET);
505         final String response = restTemplate.getForObject(uri + "/aai_get_instance_groups_by_cloudregion/" + "CLOUD OWNER" + "/" + "CLOUD-REGION-ID" + "/" + "NETWORK FUNCTION", String.class);
506
507         assertResponse(GET_INSTANCE_GROUPS_BY_CLOUDREGION_EXPECTED_RESPONSE, response);
508     }
509
510     @Test
511     public void getGetInstanceGroupsByCloudRegion_responseWithExtraFields_yieldValidResponse() {
512         SimulatorApi.clearAll();
513         final PresetAAIGetInstanceGroupsByCloudRegionInvalidRequest presetAAIGetInstanceGroupsByCloudRegion = new PresetAAIGetInstanceGroupsByCloudRegionInvalidRequest("CLOUD-OWNER", "CLOUD-REGION-ID", "NETWORK-FUNCTION");
514         SimulatorApi.registerExpectationFromPreset(presetAAIGetInstanceGroupsByCloudRegion, CLEAR_THEN_SET);
515         final String response = restTemplate.getForObject(uri + "/aai_get_instance_groups_by_cloudregion/" + "CLOUD-OWNER" + "/" + "CLOUD-REGION-ID" + "/" + "NETWORK-FUNCTION", String.class);
516
517         assertResponse(GET_INSTANCE_GROUPS_BY_CLOUDREGION_EXPECTED_RESPONSE, response);
518     }
519
520     @Test
521     public void getGetInstanceGroupsByCloudRegion_given404ErrorAaiResponse_yield200OkWithErrorMsg() {
522         SimulatorApi.clearAll();
523         try {
524             restTemplate.getForObject(uri + "/aai_get_instance_groups_by_cloudregion/" + "CLOUD-OWNER" + "/" + "CLOUD-REGION-ID" + "/" + "NETWORK-FUNCTION", String.class);
525         } catch (HttpClientErrorException e) {
526             assertEquals(HttpStatus.NOT_FOUND, e.getStatusCode());
527         }
528     }
529
530     @Test
531     public void getGetInstanceGroupsByCloudRegion_responseWithRequiredMissing() {
532         SimulatorApi.clearAll();
533         final PresetAAIGetInstanceGroupsByCloudRegionRequiredMissing presetAAIGetInstanceGroupsByCloudRegion = new PresetAAIGetInstanceGroupsByCloudRegionRequiredMissing("CLOUD-OWNER", "CLOUD-REGION-ID", "NETWORK-FUNCTION");
534         SimulatorApi.registerExpectationFromPreset(presetAAIGetInstanceGroupsByCloudRegion, CLEAR_THEN_SET);
535         try {
536             restTemplate.getForObject(uri + "/aai_get_instance_groups_by_cloudregion/" + "CLOUD-OWNER" + "/" + "CLOUD-REGION-ID" + "/" + "NETWORK-FUNCTION", String.class);
537         } catch (HttpServerErrorException e) {
538             assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, e.getStatusCode());
539         }
540     }
541
542     @Test
543     public void portMirroringConfigData_emptyIdOnAaiResponse_yieldError() {
544         final PresetAAICloudRegionAndSourceFromConfigurationPut presetAAIResponseWitnProblem = new PresetAAICloudRegionAndSourceFromConfigurationPut("SOME-RANDOM-UUID", "");
545         SimulatorApi.registerExpectationFromPreset(presetAAIResponseWitnProblem, CLEAR_THEN_SET);
546
547         final String response = restTemplate.getForObject(uri + "/aai_getPortMirroringConfigsData?configurationIds=" + "SOME-RANDOM-UUID", String.class);
548
549         final ImmutableMap<String, ImmutableMap<String, String>> expected = ImmutableMap.of(
550                 "SOME-RANDOM-UUID", ImmutableMap.of(
551                         "errorDescription", "Node 'properties.cloud-region-id' of node-type 'cloud-region' is blank",
552                         "rawAaiResponse", presetAAIResponseWitnProblem.getResponseBody().toString().replace(" ", "")
553                 ));
554
555         assertResponse(expected, response);
556     }
557
558     @Test
559     public void getGetRelatedInstanceGroupsByVnfId__yieldValidResponse() {
560         String vnfId = "some_vnf_id";
561         final PresetAAIGetRelatedInstanceGroupsByVnfId getRelatedInstanceGroupsByVnfId = new PresetAAIGetRelatedInstanceGroupsByVnfId(vnfId);
562         SimulatorApi.registerExpectationFromPreset(getRelatedInstanceGroupsByVnfId, CLEAR_THEN_SET);
563
564         final String response = restTemplate.getForObject(uri + "/aai_get_instance_groups_by_vnf_instance_id/" + vnfId,
565                 String.class);
566
567         assertResponse("[{\"type\":\"instance-group\",\"name\":\"instance group name\"},{\"type\":\"instance-group\",\"name\":\"instance group name\"}]", response);
568     }
569
570     @Test
571     public void getHomingDataForVfModule(){
572         String vnfId= "0846287b-65bf-45a6-88f6-6a1af4149fac", vfModuleId= "a9b70ac0-5917-4203-a308-0e6920e6d09b";
573         SimulatorApi.registerExpectationFromPreset(new PresetAAIGetHomingForVfModule(vnfId,vfModuleId), CLEAR_THEN_SET);
574         final String response = restTemplate.getForObject(uri + "/aai_get_homing_by_vfmodule/"+ vnfId +"/"+vfModuleId, String.class);
575         String exectedResponse = TestUtils.convertRequest(objectMapper, AAI_HOMING_DATA_RESPONSE);
576         assertResponse(exectedResponse,response);
577     }
578
579     @Test
580     public void getGetRelatedInstanceGroupsByVnfId__yield404NotFound() {
581         final PresetAAIGetRelatedInstanceGroupsByVnfId getRelatedInstanceGroupsByVnfId = new PresetAAIGetRelatedInstanceGroupsByVnfId("abcd");
582         SimulatorApi.registerExpectationFromPreset(getRelatedInstanceGroupsByVnfId, CLEAR_THEN_SET);
583         try {
584             restTemplate.getForObject(uri + "/aai_get_instance_groups_by_vnf_instance_id/" + "dcba", String.class);
585         } catch (HttpClientErrorException e) {
586             assertEquals(HttpStatus.NOT_FOUND, e.getStatusCode());
587         }
588
589     }
590
591     @Test
592     public void portMirroringConfigData_twoResponsesOneValidAndOneInvalid_yieldBothErrorAndOk() {
593         final PresetAAICloudRegionAndSourceFromConfigurationPut presetAAIResponseWitnProblem = new PresetAAICloudRegionAndSourceFromConfigurationPut("ANOTHER-RANDOM-UUID", "");
594         SimulatorApi.registerExpectationFromPreset(presetAAIResponseWitnProblem, CLEAR_THEN_SET);
595         SimulatorApi.registerExpectationFromPreset(new PresetAAICloudRegionAndSourceFromConfigurationPut("SOME-RANDOM-UUID", "THE-EXPECTED-REGION-ID"), APPEND);
596
597         final String response = restTemplate.getForObject(uri + "/aai_getPortMirroringConfigsData?configurationIds=" + "SOME-RANDOM-UUID,ANOTHER-RANDOM-UUID", String.class);
598
599         final ImmutableMap<String, ImmutableMap<String, Object>> expected = ImmutableMap.of(
600                 "SOME-RANDOM-UUID", ImmutableMap.of(
601                         "cloudRegionId", "THE-EXPECTED-REGION-ID"
602                 ),
603                 "ANOTHER-RANDOM-UUID", ImmutableMap.of(
604                         "errorDescription", "Node 'properties.cloud-region-id' of node-type 'cloud-region' is blank",
605                         "rawAaiResponse", presetAAIResponseWitnProblem.getResponseBody().toString().replace(" ", "")
606                 ));
607
608         assertResponse(expected, response);
609     }
610
611     @Test
612     @FeatureTogglingTest(Features.FLAG_PRESENT_PROVIDER_NETWORKS_ASSOCIATIONS)
613     public void networksToVlans_simpleRequest_responseIsCorrect() {
614         // Prepare randomized values
615         // Some of these random values are persisted to match with the
616         // cypress preset "aaiGetNetworksToVlansByServiceInstance.json".
617         String globalCustomerId = UUID.randomUUID().toString();
618         String sdcModelUuid = "5a3ad576-c01d-4bed-8194-0e72b4a3d020";
619         String serviceType = "vMOG";
620         int vlanIdOuter = 34612;
621         int vlanIdOuter2 = 8568012;
622         int vlanIdOuter3 = 4;
623
624         // build hierarchical presets:
625         //
626         //     service instance
627         //               ║
628         //               ╠═  network 1
629         //               ║      ╠═  vlan 1
630         //               ║      ╚═  vlan 2
631         //               ║
632         //               ╠═  network 2
633         //               ║      ╚═  vlan 3
634         //               ║
635         PresetAAIStandardQueryGet vlanTagPreset1 = ofVlanTag(vlanIdOuter);
636         PresetAAIStandardQueryGet vlanTagPreset2 = ofVlanTag(vlanIdOuter2);
637         PresetAAIStandardQueryGet vlanTagPreset3 = ofVlanTag(vlanIdOuter3);
638
639         PresetAAIStandardQueryGet l3NetworkPreset1 = ofL3Network("7989a6d2-ba10-4a5d-8f15-4520bc833090", "DDDEEEFFF", "Provider Network",
640                 ImmutableMultimap.of("vlan-tag", vlanTagPreset1.getReqPath(), "vlan-tag", vlanTagPreset2.getReqPath()), "Failed");
641         PresetAAIStandardQueryGet l3NetworkPreset2 = ofL3Network("e8e2332e-1f84-4237-bc97-3b5b842f52e4","GGGHHHIII", "Network",
642                 ImmutableMultimap.of("vlan-tag", vlanTagPreset3.getReqPath()), "Assigned");
643
644         PresetAAIStandardQueryGet serviceInstance = ofServiceInstance("9cdd1b2a-43a7-47bc-a88e-759ba2399f0b",
645                 "7a6ee536-f052-46fa-aa7e-2fca9d674c44", "6e59c5de-f052-46fa-aa7e-2fca9d674c44", globalCustomerId, serviceType,
646                 ImmutableMultimap.of("l3-network", l3NetworkPreset1.getReqPath(), "l3-network", l3NetworkPreset2.getReqPath()));
647
648         SimulatorApi.registerExpectationFromPresets(ImmutableList.of(
649                 serviceInstance, l3NetworkPreset1, l3NetworkPreset2, vlanTagPreset1, vlanTagPreset2, vlanTagPreset3,
650                 new PresetSDCGetServiceMetadataGet(sdcModelUuid, UUID.randomUUID().toString(), "service-vl-with-5g-network-provider-alacarte.zip"),
651                 new PresetSDCGetServiceToscaModelGet(sdcModelUuid, "service-vl-with-5g-network-provider-alacarte.zip")
652         ), CLEAR_THEN_SET);
653
654         // THE TEST
655         final String response = restTemplate.getForObject(uri + "/aai/standardQuery/vlansByNetworks"
656                         + "?serviceInstanceId=" + serviceInstance.getInstanceId()
657                         + "&serviceType=" + serviceType
658                         + "&globalCustomerId=" + globalCustomerId
659                         + "&sdcModelUuid=" + sdcModelUuid
660                 , String.class);
661
662         assertResponse(JsonAssert.when(Option.IGNORING_ARRAY_ORDER),
663                 getResourceAsString("serviceWithNetwork/aaiGetNetworksToVlansByServiceInstance.json"),
664                 response);
665     }
666
667     @Test
668     @FeatureTogglingTest(Features.FLAG_PRESENT_PROVIDER_NETWORKS_ASSOCIATIONS)
669     public void networksWithVlansToVnf_simpleRequest_responseIsCorrect() {
670         // Prepare randomized values
671         // Some of these random values are persisted to match with the
672         // cypress preset "aaiGetNetworksWithVlansToVnfByServiceInstance.json".
673         String globalCustomerId = UUID.randomUUID().toString();
674         String sdcModelUuid = "5a3ad576-c01d-4bed-8194-0e72b4a3d020";
675         String serviceType = "vMOG";
676         int vlanIdOuter = 34123;
677         int vlanIdOuter2 = 65540;
678         int vlanIdOuter3 = 12345;
679         int vlanIdOuter4 = 67890;
680         int vlanIdOuter5 = 417695;
681         int vlanIdOuter6 = 783243;
682
683         // build hierarchical presets:
684         //
685         //     service instance
686         //               ║
687         //               ╠═  vnf 1
688         //               ║    ╚═  network 1
689         //               ║          ╠═  vlan 1
690         //               ║          ╚═  vlan 2
691         //               ║    ╚═  network 2
692         //               ║          ╠═  vlan 3
693         //               ║          ╚═  vlan 4
694         //               ║
695         //               ╠═  vnf 2
696         //               ║    ╚═  network 3
697         //               ║          ╠═  vlan 5
698         //               ║          ╚═  vlan 6
699         //               ║
700         PresetAAIStandardQueryGet vlanTagPreset1 = ofVlanTag(vlanIdOuter);
701         PresetAAIStandardQueryGet vlanTagPreset2 = ofVlanTag(vlanIdOuter2);
702         PresetAAIStandardQueryGet vlanTagPreset3 = ofVlanTag(vlanIdOuter3);
703         PresetAAIStandardQueryGet vlanTagPreset4 = ofVlanTag(vlanIdOuter4);
704         PresetAAIStandardQueryGet vlanTagPreset5 = ofVlanTag(vlanIdOuter5);
705         PresetAAIStandardQueryGet vlanTagPreset6 = ofVlanTag(vlanIdOuter6);
706
707         PresetAAIStandardQueryGet l3NetworkPreset1 = ofL3Network("36517f3d-2bc2-48f5-aaf8-418520c54330","AAAAABBBBCCCC", "Provider Network",
708                 ImmutableMultimap.of("vlan-tag", vlanTagPreset1.getReqPath(), "vlan-tag", vlanTagPreset2.getReqPath()), "Assigned");
709
710         PresetAAIStandardQueryGet l3NetworkPreset2 = ofL3Network("12347f3d-2bc2-48f5-aaf8-418520c54330","DDDEEEE", "Provider Network",
711                 ImmutableMultimap.of("vlan-tag", vlanTagPreset3.getReqPath(), "vlan-tag", vlanTagPreset4.getReqPath()), "Created");
712
713         PresetAAIStandardQueryGet vnfPreset1 = ofVnf("c015cc0f-0f37-4488-aabf-53795fd93cd3",
714                 ImmutableMultimap.of("l3-network", l3NetworkPreset1.getReqPath() , "l3-network", l3NetworkPreset2.getReqPath()),
715                 defaultPlacement());
716
717         PresetAAIStandardQueryGet l3NetworkPreset3 = ofL3Network("12aa7f3d-2bc2-48f5-aaf8-418520c54330","XXXYYYZZZ", "Network",
718                 ImmutableMultimap.of("vlan-tag", vlanTagPreset5.getReqPath(), "vlan-tag", vlanTagPreset6.getReqPath()), "Created");
719
720         PresetAAIStandardQueryGet vnfPreset2 = ofVnf("c55da606-cf38-42c7-bc3c-be8e23b19299", ImmutableMultimap.of("l3-network", l3NetworkPreset3.getReqPath()),
721                 defaultPlacement());
722
723         PresetAAIStandardQueryGet serviceInstance = ofServiceInstance("9cdd1b2a-43a7-47bc-a88e-759ba2399f0b",
724                 "7a6ee536-f052-46fa-aa7e-2fca9d674c44", "6e59c5de-f052-46fa-aa7e-2fca9d674c44", globalCustomerId, serviceType,
725                 ImmutableMultimap.of("generic-vnf", vnfPreset1.getReqPath(), "generic-vnf", vnfPreset2.getReqPath()));
726
727         SimulatorApi.registerExpectationFromPresets(ImmutableList.of(
728                 serviceInstance, vnfPreset1, vnfPreset2, l3NetworkPreset1, l3NetworkPreset2, l3NetworkPreset3, vlanTagPreset1, vlanTagPreset2, vlanTagPreset3, vlanTagPreset4, vlanTagPreset5, vlanTagPreset6,
729                 new PresetSDCGetServiceMetadataGet(sdcModelUuid, UUID.randomUUID().toString(), "service-vl-with-5g-network-provider-alacarte.zip"),
730                 new PresetSDCGetServiceToscaModelGet(sdcModelUuid, "service-vl-with-5g-network-provider-alacarte.zip")
731         ), CLEAR_THEN_SET);
732
733         // THE TEST
734         final String response = restTemplate.getForObject(uri + "/aai/standardQuery/vlansByNetworks"
735                         + "?serviceInstanceId=" + serviceInstance.getInstanceId()
736                         + "&serviceType=" + serviceType
737                         + "&globalCustomerId=" + globalCustomerId
738                         + "&sdcModelUuid=" + sdcModelUuid
739                 , String.class);
740
741         assertResponse(JsonAssert.when(Option.IGNORING_ARRAY_ORDER),
742                 getResourceAsString("serviceWithNetwork/aaiGetNetworksWithVlansToVnfByServiceInstance.json"),
743                 response);
744     }
745
746     @FeatureTogglingTest(value = Features.FLAG_FLASH_REDUCED_RESPONSE_CHANGEMG, flagActive = false)
747     @Test
748     public void getVnfDataByGlobalIdAndServiceType() {
749
750         SimulatorApi.registerExpectationFromPreset(new PresetBaseAAICustomQuery(
751             SIMPLE,
752             "business/customers/customer/a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb/service-subscriptions/service-subscription/vRichardson/service-instances",
753             "query/vnf-topology-fromServiceInstance"
754         ) {
755             @Override
756             public Object getResponseBody() {
757                 return getResourceAsString(
758                     "registration_to_simulator/changeManagement/get_vnf_data_by_globalid_and_service_type_response.json");
759             }
760         }, CLEAR_THEN_SET);
761
762         String url = uri + "/get_vnf_data_by_globalid_and_service_type/a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb/vRichardson";
763
764         ResponseEntity<String> response = restTemplate.getForEntity(url, String.class);
765
766         assertResponse(JsonAssert.when(Option.IGNORING_ARRAY_ORDER),
767                 getResourceAsString("registration_to_simulator/changeManagement/get_vnf_data_by_globalid_and_service_type_response.json"),
768                 response.getBody());
769     }
770
771     @Test
772     public void whenCallAaiThroughAAIRestInterface_thenRequestRecordedInMetricsLog() {
773         registerExpectationFromPresets(ImmutableList.of(
774             new PresetAAIGetVpnsByType(),
775             new PresetAAIGetSubscribersGet()
776         ),CLEAR_THEN_SET);
777
778         String url = uri + "/aai_get_vpn_list";
779         ResponseEntity<String> response = restTemplate.getForEntity(url, String.class);
780         final String requestId = response.getHeaders().getFirst("X-ECOMP-RequestID-echo");
781         LoggerFormatTest.assertHeadersAndMetricLogs(restTemplate, uri, requestId,"/network/vpn-bindings" , 1);
782     }
783
784     @Test
785     public void getVpnList() {
786         SimulatorApi.registerExpectationFromPreset(new PresetAAIGetVpnsByType(), CLEAR_THEN_SET);
787         String url = uri + "/aai_get_vpn_list";
788         ResponseEntity<String> response = restTemplate.getForEntity(url, String.class);
789         String expected = getResourceAsString("viewEdit/aaiGetVpnList.json");
790         assertThat(response.getBody(), jsonEquals(expected).when(Option.IGNORING_ARRAY_ORDER).when(Option.IGNORING_EXTRA_FIELDS));
791     }
792
793     @DataProvider
794     public static Object[][] getActiveNetworkAaiStates() {
795         return new Object[][] {
796                 {1, "viewEdit/aaiGetActiveNetworks.json"},
797                 {2, "viewEdit/aaiGetActiveNetworks2.json"}
798         };
799     }
800
801     @Test(dataProvider = "getActiveNetworkAaiStates")
802     public void getActiveNetworks_givenSpecificAAIState_cypressPresetMatch(int state, String expectedResultFileName) {
803         SimulatorApi.registerExpectationFromPresets(ImmutableList.of(
804             new PresetAAIGetL3NetworksByCloudRegionSpecificState(state),
805             PresetAAIGetCloudOwnersByCloudRegionId.PRESET_AUK51A_TO_ATT_NC
806         ), CLEAR_THEN_SET);
807         String url = uri + AAI_GET_ACTIVE_NETWORKS
808             + "?cloudRegion=" + AAIBaseGetL3NetworksByCloudRegionPreset.DEFAULT_CLOUD_REGION_ID
809             + "&tenantId=" + AAIBaseGetL3NetworksByCloudRegionPreset.DEFAULT_TENANT_ID;
810         String response = restTemplate.getForObject(url, String.class);
811         System.out.println("response = " + response);
812         String expected = getResourceAsString(expectedResultFileName);
813         assertThat(response, jsonEquals(expected));
814     }
815
816     @Test
817     public void getActiveNetworks() throws JsonProcessingException {
818         String networkRole = "Some role";
819         PresetAAIGetL3NetworksByCloudRegion presetAAIGetL3NetworksByCloudRegion = new PresetAAIGetL3NetworksByCloudRegion(networkRole);
820         List<BasePreset> presets = ImmutableList.of(
821                 presetAAIGetL3NetworksByCloudRegion,
822                 PresetAAIGetCloudOwnersByCloudRegionId.PRESET_AUK51A_TO_ATT_NC
823         );
824         SimulatorApi.registerExpectationFromPresets(presets, CLEAR_THEN_SET);
825         String url = uri + AAI_GET_ACTIVE_NETWORKS +
826                 "?cloudRegion=" + presetAAIGetL3NetworksByCloudRegion.getCloudRegionId() +
827                 "&tenantId=" + presetAAIGetL3NetworksByCloudRegion.getTenantId() +
828                  "&networkRole=" + networkRole;
829         ResponseEntity<String> response = restTemplate.getForEntity(url, String.class);
830
831         assertResponse(JsonAssert.when(Option.IGNORING_EXTRA_FIELDS, Option.IGNORING_ARRAY_ORDER),
832                 presetAAIGetL3NetworksByCloudRegion.getActiveNetworksWithNameAndRelatedToVpnBindingAsJsonString(),
833                 response.getBody());
834     }
835
836     @Test
837     public void getNewestModelVersionByInvariant() throws JsonProcessingException {
838         String invariantId = "f6342be5-d66b-4d03-a1aa-c82c3094c4ea";
839
840         SimulatorApi.registerExpectationFromPreset(new PresetAAIModelVersionsByInvariantId(), CLEAR_THEN_SET );
841
842         String url = uri +
843                 "/aai_get_newest_model_version_by_invariant/" + invariantId;
844         ResponseEntity<String> response = restTemplate.getForEntity(url, String.class);
845
846         assertTrue(response.toString().contains("the-newest-version"));
847     }
848
849     @Test
850     public void getNewestModelVersionByInvariant_modelNotExist_thenEmptyResponse() {
851         String invariantId = "f6342be5-d66b-4d03-a1aa-c82c3094c4ea";
852
853         SimulatorApi.registerExpectationFromPreset(new PresetAAIModelVersionsByInvariantId(), CLEAR_THEN_SET );
854
855         String url = uri +
856                 "/aai_get_newest_model_version_by_invariant/" + "model-not-exist";
857         ResponseEntity<String> response = restTemplate.getForEntity(url, String.class);
858
859         assertTrue(response.getStatusCode().is2xxSuccessful());
860         AssertJUnit.assertNull(response.getBody());
861     }
862
863     @Test
864     @FeatureTogglingTest(Features.FLAG_FLASH_REDUCED_RESPONSE_CHANGEMG)
865     public void getVnfsWithCustomQueryNewReducedResponse() throws URISyntaxException {
866
867         String globalCustomerId = "globalCustomerId1-360-as988q";
868         String serviceType = "TEST1-360";
869         String nfRole = "test360";
870         SimulatorApi.registerExpectationFromPreset(new PresetBaseAAICustomQuery(
871             SIMPLE,
872             "/business/customers/customer/" + globalCustomerId + "/service-subscriptions/service-subscription/"
873                 + serviceType + "/service-instances",
874             "query/vnfs-fromServiceInstance-filter?nfRole=" + nfRole
875             ) {
876             @Override
877             public Object getResponseBody() {
878                 return getResourceAsString(
879                     AAI_VNFS_FOR_CHANGE_MANAGEMENT_JSON_BY_PARAMS);
880             }
881         }, CLEAR_THEN_SET);
882         URIBuilder urlBuilder  = new URIBuilder(uri + "/get_vnf_data_by_globalid_and_service_type/" + globalCustomerId + "/" + serviceType);
883         urlBuilder.addParameter("nfRole", nfRole);
884         ResponseEntity<String> response = restTemplate.getForEntity(urlBuilder.build().toString(), String.class);
885         assertTrue(response.getStatusCode().is2xxSuccessful());
886         assertThat(response.getBody(), jsonEquals(getResourceAsString(AAI_VNFS_FOR_CHANGE_MANAGEMENT_JSON_BY_PARAMS)));
887     }
888
889     private void assertResponse(Object expected, String response) {
890         assertResponse(Configuration.empty(), expected, response);
891     }
892
893     private void assertResponse(Configuration configuration, Object expected, String response) {
894         try {
895             JsonAssert.assertJsonEquals(expected, response, configuration);
896         } catch (Exception | AssertionError e) {
897             System.err.println("response was: " + response);
898             throw e;
899         }
900     }
901 }