vid-automation selenium tests
[vid.git] / vid-automation / src / test / java / org / opencomp / vid / api / AaiApiTest.java
1 package org.opencomp.vid.api;
2
3 import com.google.common.collect.ImmutableList;
4 import com.google.common.collect.ImmutableMap;
5 import net.javacrumbs.jsonunit.JsonAssert;
6 import org.apache.commons.text.StringEscapeUtils;
7 import org.codehaus.jackson.map.ObjectMapper;
8 import org.opencomp.simulator.presetGenerator.presets.aai.*;
9 import org.opencomp.vid.model.aai.AaiResponse;
10 import org.opencomp.vid.model.mso.OperationalEnvironmentList;
11 import org.opencomp.vid.more.LoggerFormatTest;
12 import org.springframework.core.ParameterizedTypeReference;
13 import org.springframework.http.HttpMethod;
14 import org.springframework.http.HttpStatus;
15 import org.springframework.http.ResponseEntity;
16 import org.springframework.web.client.HttpClientErrorException;
17 import org.springframework.web.client.HttpServerErrorException;
18 import org.springframework.web.util.UriComponentsBuilder;
19 import org.testng.annotations.DataProvider;
20 import org.testng.annotations.Test;
21 import vid.automation.test.services.SimulatorApi;
22
23 import java.io.IOException;
24 import java.lang.reflect.Method;
25 import java.net.URISyntaxException;
26
27 import static org.hamcrest.CoreMatchers.containsString;
28 import static org.junit.Assert.*;
29 import static org.opencomp.simulator.presetGenerator.presets.ecompportal_att.EcompPortalPresetsUtils.getEcompPortalPresets;
30 import static vid.automation.test.services.SimulatorApi.RegistrationStrategy.APPEND;
31 import static vid.automation.test.services.SimulatorApi.RegistrationStrategy.CLEAR_THEN_SET;
32
33 public class AaiApiTest extends BaseApiAaiTest {
34
35
36     public static final String GET_OPERATIONAL_ENVIRONMENTS_JSON = "get_operational_environments_aai.json";
37     public static final String GET_OPERATIONAL_ENVIRONMENTS_JSON_ERROR = "get_operational_environments_aai_error.json";
38     public static final String[] AAI_GET_SERVICES_ERROR_SIMULATOR_RESPONSES = {"getServicesAaiErrorResp.json", "aai_get_full_subscribers.json"};
39     public static final String[] AAI_GET_SERVICES_FINE_SIMULATOR_RESPONSES = {"getServicesAaiFineResp.json", "aai_get_full_subscribers.json"};
40
41     public static final String OPERATIONAL_ENVIRONMENT_TYPE = "VNF";
42     public static final String OPERATIONAL_ENVIRONMENT_STATUS = "Activate";
43     public static final String BASE_GET_SERVICES_AAI_REQUEST_BODY = "{\"start\" : \"service-design-and-creation/models\", \"query\" : \"query/serviceModels-byDistributionStatus?distributionStatus=DISTRIBUTION_COMPLETE_OK\";}";
44     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";
45     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\":\"HngwProtectedOam.OAM\",\"network-technology\":\"Contrail\",\"is-bound-to-vpn\":false,\"resource-version\":\"1521662814627\",\"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\":\"HngwProtectedOam.OAM\",\"network-technology\":\"Contrail\",\"is-bound-to-vpn\":false,\"resource-version\":\"1521662816043\",\"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\":\"HngwProtectedOam.OAM\",\"network-technology\":\"Contrail\",\"is-bound-to-vpn\":false,\"resource-version\":\"1521662815304\",\"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";
46     public static final String GET_AAI_SERVIES_EXPECTED_RESULT = "{\n" +
47             "  \"services\": [{\n" +
48             "    \"uuid\": \"20c4431c-246d-11e7-93ae-92361f002671\",\n" +
49             "    \"invariantUUID\": \"78ca26d0-246d-11e7-93ae-92361f002671\",\n" +
50             "    \"name\": \"vSAMP10aDEV::base::module-0\",\n" +
51             "    \"version\": \"2\",\n" +
52             "    \"toscaModelURL\": null,\n" +
53             "    \"category\": \"resource\",\n" +
54             "    \"lifecycleState\": null,\n" +
55             "    \"lastUpdaterUserId\": null,\n" +
56             "    \"lastUpdaterFullName\": null,\n" +
57             "    \"distributionStatus\": \"DISTRIBUTION_COMPLETE_OK\",\n" +
58             "    \"artifacts\": null,\n" +
59             "    \"resources\": null\n" +
60             "  }, {\n" +
61             "    \"uuid\": \"797a6c41-0f80-4d35-a288-3920c4e06baa\",\n" +
62             "    \"invariantUUID\": \"5b607929-6088-4614-97ef-cac817508e0e\",\n" +
63             "    \"name\": \"CONTRAIL30_L2NODHCP\",\n" +
64             "    \"version\": \"1.0\",\n" +
65             "    \"toscaModelURL\": null,\n" +
66             "    \"category\": \"resource\",\n" +
67             "    \"lifecycleState\": null,\n" +
68             "    \"lastUpdaterUserId\": null,\n" +
69             "    \"lastUpdaterFullName\": null,\n" +
70             "    \"distributionStatus\": \"DISTRIBUTION_COMPLETE_ERROR\",\n" +
71             "    \"artifacts\": null,\n" +
72             "    \"resources\": null\n" +
73             "  }, {\n" +
74             "    \"uuid\": \"f1bde010-cc5f-4765-941f-75f15b24f9fc\",\n" +
75             "    \"invariantUUID\": \"0143d57b-a517-4de9-a0a1-eb76db51f402\",\n" +
76             "    \"name\": \"BkVmxAv061917..base_vPE_AV..module-0\",\n" +
77             "    \"version\": \"2\",\n" +
78             "    \"toscaModelURL\": null,\n" +
79             "    \"category\": \"resource\",\n" +
80             "    \"lifecycleState\": null,\n" +
81             "    \"lastUpdaterUserId\": null,\n" +
82             "    \"lastUpdaterFullName\": null,\n" +
83             "    \"distributionStatus\": \"DISTRIBUTION_COMPLETE_OK\",\n" +
84             "    \"artifacts\": null,\n" +
85             "    \"resources\": null\n" +
86             "  }, {\n" +
87             "    \"uuid\": \"ipe-resource-id-ps-02\",\n" +
88             "    \"invariantUUID\": \"ipe-resource-id-ps-02\",\n" +
89             "    \"name\": \"abc\",\n" +
90             "    \"version\": \"v1.0\",\n" +
91             "    \"toscaModelURL\": null,\n" +
92             "    \"category\": \"resource\",\n" +
93             "    \"lifecycleState\": null,\n" +
94             "    \"lastUpdaterUserId\": null,\n" +
95             "    \"lastUpdaterFullName\": null,\n" +
96             "    \"distributionStatus\": \"DISTRIBUTION_COMPLETE_OK\",\n" +
97             "    \"artifacts\": null,\n" +
98             "    \"resources\": null\n" +
99             "  }, {\n" +
100             "    \"uuid\": \"lmoser410-connector-model-version-id\",\n" +
101             "    \"invariantUUID\": \"lmoser410-connector-model-id\",\n" +
102             "    \"name\": \"connector\",\n" +
103             "    \"version\": \"v1.0\",\n" +
104             "    \"toscaModelURL\": null,\n" +
105             "    \"category\": \"widget\",\n" +
106             "    \"lifecycleState\": null,\n" +
107             "    \"lastUpdaterUserId\": null,\n" +
108             "    \"lastUpdaterFullName\": null,\n" +
109             "    \"distributionStatus\": \"DISTRIBUTION_COMPLETE_OK\",\n" +
110             "    \"artifacts\": null,\n" +
111             "    \"resources\": null\n" +
112             "  }, {\n" +
113             "    \"uuid\": \"ff2ae348-214a-11e7-93ae-92361f002673\",\n" +
114             "    \"invariantUUID\": \"3a97db99-c4bb-498a-a13a-38f65f1ced3d\",\n" +
115             "    \"name\": \"vSAMP10aDEV::base::module-0\",\n" +
116             "    \"version\": \"1.0\",\n" +
117             "    \"toscaModelURL\": null,\n" +
118             "    \"category\": \"resource\",\n" +
119             "    \"lifecycleState\": null,\n" +
120             "    \"lastUpdaterUserId\": null,\n" +
121             "    \"lastUpdaterFullName\": null,\n" +
122             "    \"distributionStatus\": \"DISTRIBUTION_COMPLETE_OK\",\n" +
123             "    \"artifacts\": null,\n" +
124             "    \"resources\": null\n" +
125             "  }, {\n" +
126             "    \"uuid\": \"204c641a-3494-48c8-979a-86856f5fd32a\",\n" +
127             "    \"invariantUUID\": \"3c504d40-b847-424c-9d25-4fb7e0a3e994\",\n" +
128             "    \"name\": \"named-query-element\",\n" +
129             "    \"version\": \"1.0\",\n" +
130             "    \"toscaModelURL\": null,\n" +
131             "    \"category\": \"widget\",\n" +
132             "    \"lifecycleState\": null,\n" +
133             "    \"lastUpdaterUserId\": null,\n" +
134             "    \"lastUpdaterFullName\": null,\n" +
135             "    \"distributionStatus\": \"DISTRIBUTION_COMPLETE_OK\",\n" +
136             "    \"artifacts\": null,\n" +
137             "    \"resources\": null\n" +
138             "  }, {\n" +
139             "    \"uuid\": \"acba1f72-c6e0-477f-9426-ad190151e100\",\n" +
140             "    \"invariantUUID\": \"93e56950-cb19-44e6-ace4-8b50f2d02e45\",\n" +
141             "    \"name\": \"RG_6-19_Test\",\n" +
142             "    \"version\": \"1.0\",\n" +
143             "    \"toscaModelURL\": null,\n" +
144             "    \"category\": \"resource\",\n" +
145             "    \"lifecycleState\": null,\n" +
146             "    \"lastUpdaterUserId\": null,\n" +
147             "    \"lastUpdaterFullName\": null,\n" +
148             "    \"distributionStatus\": \"DISTRIBUTION_COMPLETE_OK\",\n" +
149             "    \"artifacts\": null,\n" +
150             "    \"resources\": null\n" +
151             "  }, {\n" +
152             "    \"uuid\": \"fc65e5e7-45c7-488a-b36d-f453ab3057fe\",\n" +
153             "    \"invariantUUID\": \"ee448504-ceee-47db-8e1b-742115f219db\",\n" +
154             "    \"name\": \"ciServicea268facd387e\",\n" +
155             "    \"version\": \"1.0\",\n" +
156             "    \"toscaModelURL\": null,\n" +
157             "    \"category\": \"service\",\n" +
158             "    \"lifecycleState\": null,\n" +
159             "    \"lastUpdaterUserId\": null,\n" +
160             "    \"lastUpdaterFullName\": null,\n" +
161             "    \"distributionStatus\": \"DISTRIBUTION_COMPLETE_OK\",\n" +
162             "    \"artifacts\": null,\n" +
163             "    \"resources\": null\n" +
164             "  }, {\n" +
165             "    \"uuid\": \"027948b6-25e2-4e39-b87d-d9f5797941de\",\n" +
166             "    \"invariantUUID\": \"56f2d0d3-7943-4159-bf01-b82692ec035e\",\n" +
167             "    \"name\": \"service_sanity_amir\",\n" +
168             "    \"version\": \"2.0\",\n" +
169             "    \"toscaModelURL\": null,\n" +
170             "    \"category\": \"service\",\n" +
171             "    \"lifecycleState\": null,\n" +
172             "    \"lastUpdaterUserId\": null,\n" +
173             "    \"lastUpdaterFullName\": null,\n" +
174             "    \"distributionStatus\": \"DISTRIBUTION_COMPLETE_OK\",\n" +
175             "    \"artifacts\": null,\n" +
176             "    \"resources\": null\n" +
177             "  }, {\n" +
178             "    \"uuid\": \"fbf96e3b-1804-4c89-bf5b-53acb7f2edc0\",\n" +
179             "    \"invariantUUID\": \"56f2d0d3-7943-4159-bf01-b82692ec035e\",\n" +
180             "    \"name\": \"service_sanity_amir\",\n" +
181             "    \"version\": \"3.0\",\n" +
182             "    \"toscaModelURL\": null,\n" +
183             "    \"category\": \"service\",\n" +
184             "    \"lifecycleState\": null,\n" +
185             "    \"lastUpdaterUserId\": null,\n" +
186             "    \"lastUpdaterFullName\": null,\n" +
187             "    \"distributionStatus\": \"DISTRIBUTION_COMPLETE_OK\",\n" +
188             "    \"artifacts\": null,\n" +
189             "    \"resources\": null\n" +
190             "  }],\n" +
191             "  \"readOnly\": false\n" +
192             "}";
193
194     static final ObjectMapper om = new ObjectMapper();
195
196     private String getGetOperationEnvironmentsUri() {
197         return uri.toASCIIString() + "/get_operational_environments";
198     }
199
200     private String getAaiServicesUri() {
201         return uri.toASCIIString() + "/rest/models/services";
202     }
203
204     private String getGetOperationEnvironmentUriWithParameters() {
205         String url = getGetOperationEnvironmentsUri();
206         UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(url)
207                 // Add query parameter
208                 .queryParam("operationalEnvironmentStatus", OPERATIONAL_ENVIRONMENT_STATUS)
209                 .queryParam("operationalEnvironmentType", OPERATIONAL_ENVIRONMENT_TYPE);
210
211         String urlWithParameters = builder.toUriString();
212         return urlWithParameters;
213
214     }
215
216     private AaiResponse<OperationalEnvironmentList> loginAndDoGetWithUrl(String url) {
217         ResponseEntity<AaiResponse<OperationalEnvironmentList>> responseEntity = restTemplate.exchange(
218                 url,
219                 HttpMethod.GET,
220                 null,
221                 new ParameterizedTypeReference<AaiResponse<OperationalEnvironmentList>>() {});
222         AaiResponse<OperationalEnvironmentList> response = responseEntity.getBody();
223         return response;
224     }
225
226     @Test
227     public void testErrorGetOperationalEnvironments() {
228         //Register required response
229         SimulatorApi.registerExpectation(GET_OPERATIONAL_ENVIRONMENTS_JSON_ERROR, APPEND);
230         String url = getGetOperationEnvironmentsUri();
231         AaiResponse<OperationalEnvironmentList> response = loginAndDoGetWithUrl(url);
232         assertEquals(HttpStatus.INTERNAL_SERVER_ERROR.value(), response.getHttpCode());
233         assertEquals("simulated error text", response.getErrorMessage());
234
235
236     }
237
238     //This test requires a simulator which runs on VID
239     @Test
240     public void testSuccessGetOperationalEnvironments() {
241         //Register required response
242         String uuidOfOperationalEnvironment = "f07ca256-96dd-40ad-b4d2-7a77e2a974ed";
243         SimulatorApi.registerExpectation(GET_OPERATIONAL_ENVIRONMENTS_JSON, ImmutableMap.of("UUID_of_Operational_Environment", uuidOfOperationalEnvironment), APPEND);
244         String url = getGetOperationEnvironmentUriWithParameters();
245         AaiResponse<OperationalEnvironmentList> response = loginAndDoGetWithUrl(url);
246         assertEquals(HttpStatus.OK.value(), response.getHttpCode());
247         OperationalEnvironmentList list = response.getT();
248         assertNotEquals(null, list.getOperationalEnvironment());
249         assertEquals(2, list.getOperationalEnvironment().size());
250         assertEquals(uuidOfOperationalEnvironment, list.getOperationalEnvironment().get(0).getOperationalEnvironmentId());
251         assertEquals(1, list.getOperationalEnvironment().get(0).getRelationshipList().getRelationship().size());
252     }
253
254
255     @Test
256     public void testVoid(){
257         SimulatorApi.registerExpectation(SimulatorApi.RegistrationStrategy.CLEAR_THEN_SET,
258                 "add_subinterface/aai_get_tenants.json"
259                 , "add_subinterface/aai_get_services.json"
260         );
261     }
262
263
264     @Test(dataProvider = "errorCodes")
265     public void getServicesWitErrorResponse(int errorCode) throws IOException, URISyntaxException {
266         final String expectedResult = "{\"services\":[],\"readOnly\":false}";
267
268         callAaiWithSimulatedErrorResponse(AAI_GET_SERVICES_ERROR_SIMULATOR_RESPONSES,
269                 ImmutableMap.of("500", Integer.toString(errorCode), "ERROR_PAYLOAD", StringEscapeUtils.escapeJson(expectedResult)),
270                 getAaiServicesUri(), "", 200, expectedResult, HttpMethod.GET);
271
272     }
273
274     @Test
275     public void getServicesFineRequest() throws IOException, URISyntaxException {
276
277         callAaiWithSimulatedErrorResponse(AAI_GET_SERVICES_FINE_SIMULATOR_RESPONSES,
278                 ImmutableMap.of(),
279                 getAaiServicesUri(), "", 200, GET_AAI_SERVIES_EXPECTED_RESULT, HttpMethod.GET);
280
281     }
282
283     @DataProvider
284     public static Object[][] errorCodes(Method test) {
285         return new Object[][]{
286                 {500},{505}, {400}, {401}, {405}
287         };
288     }
289
290     @Test
291     public void whenThrowExceptionInsAaiResponseErrorAreLogged() {
292         String notAJson = "not a json";
293         SimulatorApi.registerExpectationFromPreset(new PresetAAIBadBodyForGetServicesGet(notAJson), CLEAR_THEN_SET);
294         SimulatorApi.registerExpectationFromPresets(getEcompPortalPresets(), APPEND);
295         SimulatorApi.registerExpectationFromPreset(new PresetAAIGetSubscribersGet(), APPEND);
296
297         restTemplateErrorAgnostic.getForEntity(uri + "/aai_get_services",String.class);
298         String logLines = LoggerFormatTest.getLogLines("error", 15, 0, restTemplate, uri);
299
300         assertThat("not found in error log", logLines, containsString("Failed to parse aai response"));
301         assertThat("not found in error log", logLines, containsString(notAJson));
302         assertThat("not found in error log", logLines, containsString("GetServicesAAIRespone"));
303
304     }
305
306     @Test
307     public void portMirroringConfigData_givenValidAaiResponse_yieldCloudRegionId() {
308         SimulatorApi.registerExpectationFromPreset(new PresetAAICloudRegionAndSourceFromConfigurationPut("SOME-RANDOM-UUID", "THE-EXPECTED-REGION-ID"), CLEAR_THEN_SET);
309
310         final String response = restTemplate.getForObject(uri + "/aai_getPortMirroringConfigsData?configurationIds=" + "SOME-RANDOM-UUID", String.class);
311
312         final ImmutableMap<String, ImmutableMap<String, String>> expected = ImmutableMap.of(
313                 "SOME-RANDOM-UUID", ImmutableMap.of(
314                         "cloudRegionId", "THE-EXPECTED-REGION-ID"
315                 ));
316
317         assertResponse(expected, response);
318
319         /*
320         More tests:
321         [ ]  Error responses from AAI (404 etc): descriptive error response, including what tried and what happened
322         [ ]  malformed response from AAI: descriptive error response, including the payload
323         [ ]  empty/missing value for configurationId: client-error http code
324          */
325     }
326
327
328     @Test
329     public void portMirroringSourcePorts_validAAIResponseWithSinglePort_yieldCorrectPortData() {
330         SimulatorApi.registerExpectationFromPreset(
331                 new PresetAAIGetPortMirroringSourcePorts("CONFIGURATION-ID", "INTERFACE-ID", "INTERFACE-NAME", true),
332                 CLEAR_THEN_SET
333         );
334
335         final String response = restTemplate.getForObject(uri + "/aai_getPortMirroringSourcePorts?configurationIds=" + "CONFIGURATION-ID", String.class);
336
337         final ImmutableMap<String, ImmutableList> expected = ImmutableMap.of(
338                 "CONFIGURATION-ID", ImmutableList.of(ImmutableMap.of(
339                         "interfaceId", "INTERFACE-ID", "interfaceName", "INTERFACE-NAME", "isPortMirrored", true
340                 )));
341
342         assertResponse(expected, response);
343     }
344
345     @Test
346     public void portMirroringSourcePorts_nullValueForInterfaceId_yield200OkWithFineDescription() {
347         final PresetAAIGetPortMirroringSourcePorts preset = new PresetAAIGetPortMirroringSourcePorts("CONFIGURATION-ID", null, "INTERFACE-NAME", true);
348         SimulatorApi.registerExpectationFromPreset(
349                 preset,
350                 CLEAR_THEN_SET
351         );
352
353         final String response = restTemplate.getForObject(uri + "/aai_getPortMirroringSourcePorts?configurationIds=" + "CONFIGURATION-ID", String.class);
354
355         final ImmutableMap<String, ImmutableList<ImmutableMap>> expected = ImmutableMap.of(
356                 "CONFIGURATION-ID", ImmutableList.of(ImmutableMap.of(
357                         "errorDescription", "Value of 'interface-id' is missing.",
358                         "rawAaiResponse", preset.getResponseBody().toString()
359                 )));
360
361         assertResponse(expected, response);
362     }
363
364     @Test
365     public void portMirroringSourcePorts_given503ErrorAaiResponse_yield200OkWithErrorMsg() {
366         final PresetAAIGetPortMirroringSourcePortsError preset = new PresetAAIGetPortMirroringSourcePortsError("CONFIGURATION-ID", "INTERFACE-ID", "INTERFACE-NAME", true);
367         SimulatorApi.registerExpectationFromPreset(
368                 preset,
369                 CLEAR_THEN_SET
370         );
371
372         final String response = restTemplate.getForObject(uri + "/aai_getPortMirroringSourcePorts?configurationIds=" + "CONFIGURATION-ID", String.class);
373
374         final ImmutableMap<String, ImmutableList<ImmutableMap>> expected = ImmutableMap.of(
375                 "CONFIGURATION-ID", ImmutableList.of(ImmutableMap.of(
376                         "errorDescription", "Got 503 from aai",
377                         "rawAaiResponse", preset.getResponseBody()
378                 )));
379
380         assertResponse(expected, response);
381     }
382
383     @Test
384     public void portMirroringConfigData_given404ErrorAaiResponse_yield200OkWithErrorMsg() {
385         SimulatorApi.clearAll();
386
387         final String response = restTemplate.getForObject(uri + "/aai_getPortMirroringConfigsData?configurationIds=" + "SOME-RANDOM-UUID", String.class);
388
389         final ImmutableMap<String, ImmutableMap<String, String>> expected = ImmutableMap.of(
390                 "SOME-RANDOM-UUID", ImmutableMap.of(
391                         "errorDescription", "Got 404 from aai",
392                         "rawAaiResponse", ""
393                 ));
394
395         assertResponse(expected, response);
396     }
397
398     @Test
399     public void getNetworkCollectionDetailsByServiceInstanceId_yieldValidResponse() {
400         SimulatorApi.clearAll();
401         final PresetAAIGetNetworkCollectionDetails presetAAIGetNetworkCollectionDetails = new PresetAAIGetNetworkCollectionDetails("SOME-RANDOM-UUID");
402         SimulatorApi.registerExpectationFromPreset(presetAAIGetNetworkCollectionDetails, CLEAR_THEN_SET);
403         final String response = restTemplate.getForObject(uri + "/aai_get_network_collection_details/" + "SOME-RANDOM-UUID", String.class);
404
405         assertResponse(GET_NETWORK_COLLECTION_EXPECTED_RESPONSE, response);
406     }
407
408     @Test
409     public void getNetworkCollectionDetailsByServiceInstanceId_responseWithExtraFields_yieldValidResponse() {
410         SimulatorApi.clearAll();
411         final PresetAAIGetNetworkCollectionDetailsInvalidRequest presetAAIGetNetworkCollectionDetails = new PresetAAIGetNetworkCollectionDetailsInvalidRequest("SOME-RANDOM-UUID");
412         SimulatorApi.registerExpectationFromPreset(presetAAIGetNetworkCollectionDetails, CLEAR_THEN_SET);
413         final String response = restTemplate.getForObject(uri + "/aai_get_network_collection_details/" + "SOME-RANDOM-UUID", String.class);
414
415         assertResponse(GET_NETWORK_COLLECTION_EXPECTED_RESPONSE, response);
416     }
417     @Test
418     public void getNetworkCollectionDetailsByServiceInstanceId_given404ErrorAaiResponse_yield200OkWithErrorMsg() {
419         SimulatorApi.clearAll();
420         try {
421             restTemplate.getForObject(uri + "/aai_get_network_collection_details/" + "SOME-RANDOM-UUID", String.class);
422         }catch (HttpClientErrorException e){
423             assertEquals(HttpStatus.NOT_FOUND, e.getStatusCode());
424         }
425     }
426
427     @Test
428     public void getNetworkCollectionDetailsByServiceInstanceId_responseWithRequiredMissing() {
429         SimulatorApi.clearAll();
430         final PresetAAIGetNetworkCollectionDetailsRequiredMissing presetAAIGetNetworkCollectionDetails = new PresetAAIGetNetworkCollectionDetailsRequiredMissing("SOME-RANDOM-UUID");
431         SimulatorApi.registerExpectationFromPreset(presetAAIGetNetworkCollectionDetails, CLEAR_THEN_SET);
432         try {
433             restTemplate.getForObject(uri + "/aai_get_network_collection_details/" + "SOME-RANDOM-UUID", String.class);
434         }catch (HttpServerErrorException e){
435             assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, e.getStatusCode());
436         }
437     }
438
439     @Test
440     public void getGetInstanceGroupsByCloudRegion_yieldValidResponse() {
441         SimulatorApi.clearAll();
442         final PresetAAIGetInstanceGroupsByCloudRegion presetAAIGetInstanceGroupsByCloudRegion = new PresetAAIGetInstanceGroupsByCloudRegion("CLOUD-OWNER", "CLOUD-REGION-ID", "NETWORK-FUNCTION");
443         SimulatorApi.registerExpectationFromPreset(presetAAIGetInstanceGroupsByCloudRegion, CLEAR_THEN_SET);
444         final String response = restTemplate.getForObject(uri + "/aai_get_instance_groups_by_cloudregion/" + "CLOUD-OWNER" + "/" + "CLOUD-REGION-ID" + "/" +"NETWORK-FUNCTION", String.class);
445
446         assertResponse(GET_INSTANCE_GROUPS_BY_CLOUDREGION_EXPECTED_RESPONSE, response);
447     }
448
449     @Test
450     public void getGetInstanceGroupsByCloudRegion_responseWithExtraFields_yieldValidResponse() {
451         SimulatorApi.clearAll();
452         final PresetAAIGetInstanceGroupsByCloudRegionInvalidRequest presetAAIGetInstanceGroupsByCloudRegion = new PresetAAIGetInstanceGroupsByCloudRegionInvalidRequest("CLOUD-OWNER", "CLOUD-REGION-ID", "NETWORK-FUNCTION");
453         SimulatorApi.registerExpectationFromPreset(presetAAIGetInstanceGroupsByCloudRegion, CLEAR_THEN_SET);
454         final String response = restTemplate.getForObject(uri + "/aai_get_instance_groups_by_cloudregion/" + "CLOUD-OWNER" + "/" + "CLOUD-REGION-ID" + "/" +"NETWORK-FUNCTION", String.class);
455
456         assertResponse(GET_INSTANCE_GROUPS_BY_CLOUDREGION_EXPECTED_RESPONSE, response);
457     }
458     @Test
459     public void getGetInstanceGroupsByCloudRegion_given404ErrorAaiResponse_yield200OkWithErrorMsg() {
460         SimulatorApi.clearAll();
461         try {
462             restTemplate.getForObject(uri + "/aai_get_instance_groups_by_cloudregion/" + "CLOUD-OWNER" + "/" + "CLOUD-REGION-ID" + "/" +"NETWORK-FUNCTION", String.class);
463         }catch (HttpClientErrorException e){
464             assertEquals(HttpStatus.NOT_FOUND, e.getStatusCode());
465         }
466     }
467
468     @Test
469     public void getGetInstanceGroupsByCloudRegion_responseWithRequiredMissing() {
470         SimulatorApi.clearAll();
471         final PresetAAIGetInstanceGroupsByCloudRegionRequiredMissing presetAAIGetInstanceGroupsByCloudRegion = new PresetAAIGetInstanceGroupsByCloudRegionRequiredMissing("CLOUD-OWNER", "CLOUD-REGION-ID", "NETWORK-FUNCTION");
472         SimulatorApi.registerExpectationFromPreset(presetAAIGetInstanceGroupsByCloudRegion, CLEAR_THEN_SET);
473         try {
474             restTemplate.getForObject(uri + "/aai_get_instance_groups_by_cloudregion/" + "CLOUD-OWNER" + "/" + "CLOUD-REGION-ID" + "/" +"NETWORK-FUNCTION", String.class);
475         }catch (HttpServerErrorException e){
476             assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, e.getStatusCode());
477         }
478     }
479
480     @Test
481     public void portMirroringConfigData_emptyIdOnAaiResponse_yieldError() {
482         final PresetAAICloudRegionAndSourceFromConfigurationPut presetAAIResponseWitnProblem = new PresetAAICloudRegionAndSourceFromConfigurationPut("SOME-RANDOM-UUID", "");
483         SimulatorApi.registerExpectationFromPreset(presetAAIResponseWitnProblem, CLEAR_THEN_SET);
484
485         final String response = restTemplate.getForObject(uri + "/aai_getPortMirroringConfigsData?configurationIds=" + "SOME-RANDOM-UUID", String.class);
486
487         final ImmutableMap<String, ImmutableMap<String, String>> expected = ImmutableMap.of(
488                 "SOME-RANDOM-UUID", ImmutableMap.of(
489                         "errorDescription", "Node 'properties.cloud-region-id' of node-type 'cloud-region' is blank",
490                         "rawAaiResponse", presetAAIResponseWitnProblem.getResponseBody().toString().replace(" ", "")
491                 ));
492
493         assertResponse(expected, response);
494     }
495
496     @Test
497     public void getGetRelatedInstanceGroupsByVnfId__yieldValidResponse() {
498         String vnfId = "some_vnf_id";
499         final PresetAAIGetRelatedInstanceGroupsByVnfId getRelatedInstanceGroupsByVnfId = new PresetAAIGetRelatedInstanceGroupsByVnfId(vnfId);
500         SimulatorApi.registerExpectationFromPreset(getRelatedInstanceGroupsByVnfId, CLEAR_THEN_SET);
501
502         final String response = restTemplate.getForObject(uri + "/aai_get_instance_groups_by_vnf_instance_id/" + vnfId, String.class);
503
504         assertResponse("[{\"type\":\"instance-group\",\"name\":\"instance group name\"},{\"type\":\"instance-group\",\"name\":\"instance group name\"}]", response);
505     }
506
507     @Test
508     public void getGetRelatedInstanceGroupsByVnfId__yield404NotFound() {
509         final PresetAAIGetRelatedInstanceGroupsByVnfId getRelatedInstanceGroupsByVnfId = new PresetAAIGetRelatedInstanceGroupsByVnfId("abcd");
510         SimulatorApi.registerExpectationFromPreset(getRelatedInstanceGroupsByVnfId, CLEAR_THEN_SET);
511         try {
512             restTemplate.getForObject(uri + "/aai_get_instance_groups_by_vnf_instance_id/" + "dcba", String.class);
513         } catch (HttpClientErrorException e){
514             assertEquals(HttpStatus.NOT_FOUND, e.getStatusCode());
515         }
516
517     }
518
519     @Test
520     public void portMirroringConfigData_twoResponsesOneValidAndOneInvalid_yieldBothErrorAndOk() {
521         final PresetAAICloudRegionAndSourceFromConfigurationPut presetAAIResponseWitnProblem = new PresetAAICloudRegionAndSourceFromConfigurationPut("ANOTHER-RANDOM-UUID", "");
522         SimulatorApi.registerExpectationFromPreset(presetAAIResponseWitnProblem, CLEAR_THEN_SET);
523         SimulatorApi.registerExpectationFromPreset(new PresetAAICloudRegionAndSourceFromConfigurationPut("SOME-RANDOM-UUID", "THE-EXPECTED-REGION-ID"), APPEND);
524
525         final String response = restTemplate.getForObject(uri + "/aai_getPortMirroringConfigsData?configurationIds=" + "SOME-RANDOM-UUID,ANOTHER-RANDOM-UUID", String.class);
526
527         final ImmutableMap<String, ImmutableMap<String, Object>> expected = ImmutableMap.of(
528                 "SOME-RANDOM-UUID", ImmutableMap.of(
529                         "cloudRegionId", "THE-EXPECTED-REGION-ID"
530                 ),
531                 "ANOTHER-RANDOM-UUID", ImmutableMap.of(
532                         "errorDescription", "Node 'properties.cloud-region-id' of node-type 'cloud-region' is blank",
533                         "rawAaiResponse", presetAAIResponseWitnProblem.getResponseBody().toString().replace(" ", "")
534                 ));
535
536         assertResponse(expected, response);
537     }
538
539     private void assertResponse(Object expected, String response) {
540         try {
541             JsonAssert.assertJsonEquals(expected, response);
542         } catch (Exception | AssertionError e) {
543             System.err.println("response was: " + response);
544             throw e;
545         }
546     }
547 }