+/*-
+ * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
package org.onap.vid.api;
+import static net.javacrumbs.jsonunit.JsonMatchers.jsonEquals;
+import static net.javacrumbs.jsonunit.JsonMatchers.jsonPartEquals;
import static net.javacrumbs.jsonunit.JsonMatchers.jsonStringEquals;
+import static net.javacrumbs.jsonunit.core.Option.IGNORING_ARRAY_ORDER;
+import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNot.not;
+import static org.onap.simulator.presetGenerator.presets.BasePresets.BaseSDCPreset.SDC_ROOT_PATH;
+import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static vid.automation.test.services.SimulatorApi.RegistrationStrategy.APPEND;
import static vid.automation.test.services.SimulatorApi.RegistrationStrategy.CLEAR_THEN_SET;
import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.collect.ImmutableList;
import org.onap.simulator.presetGenerator.presets.BasePresets.BasePreset;
+import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetSubscribersGet;
import org.onap.simulator.presetGenerator.presets.sdc.PresetSDCGetServiceMetadataGet;
import org.onap.simulator.presetGenerator.presets.sdc.PresetSDCGetServiceToscaModelGet;
+import org.onap.vid.more.LoggerFormatTest;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
-import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import vid.automation.test.infra.FeatureTogglingTest;
import vid.automation.test.infra.Features;
+import vid.automation.test.infra.ModelInfo;
public class SdcApiTest extends BaseApiTest {
public void getServiceModelALaCarteInstantiation() {
registerToSimulatorWithPresets(A_LA_CARTE_INSTANTIATION_TYPE_UUID, A_LA_CARTE_INSTANTIATION_TYPE_INVARIANT_UUID, A_LA_CARTE_INSTANTIATION_TYPE_FILE_PATH);
ResponseEntity<String> response = restTemplate.getForEntity(buildUri(SDC_GET_SERVICE_MODEL + A_LA_CARTE_INSTANTIATION_TYPE_UUID), String.class);
- Assert.assertEquals(response.getStatusCode(), HttpStatus.OK);
+ assertEquals(response.getStatusCode(), HttpStatus.OK);
String aLaCarteInstantiationTypeExpectedResponse = loadResourceAsString(A_LA_CARTE_INSTANTIATION_TYPE_EXPECTED_RESPONSE);
- assertThat("The response is in the format of JSON", response.getBody(), is(jsonStringEquals(turnOffInstantiationUI(aLaCarteInstantiationTypeExpectedResponse))));
+ assertThat(response.getBody(), jsonEquals(aLaCarteInstantiationTypeExpectedResponse)
+ .when(IGNORING_ARRAY_ORDER)
+ .whenIgnoringPaths("service.vidNotions.instantiationUI"));
}
public void getServiceModelMacroInstantiation() {
registerToSimulatorWithPresets(MACRO_INSTANTIATION_TYPE_UUID, MACRO_INSTANTIATION_TYPE_INVARIANT_UUID, MACRO_INSTANTIATION_TYPE_FILE_PATH);
ResponseEntity<String> response = restTemplate.getForEntity(buildUri(SDC_GET_SERVICE_MODEL + MACRO_INSTANTIATION_TYPE_UUID), String.class);
- Assert.assertEquals(response.getStatusCode(), HttpStatus.OK);
+ assertEquals(response.getStatusCode(), HttpStatus.OK);
String macroInstantiationTypeExpectedResponse = loadResourceAsString(MACRO_INSTANTIATION_TYPE_EXPECTED_RESPONSE);
- assertThat("The response is in the format of JSON", response.getBody(), is(jsonStringEquals(turnOffInstantiationUI(macroInstantiationTypeExpectedResponse))));
+ assertThat(response.getBody(), jsonEquals(macroInstantiationTypeExpectedResponse)
+ .when(IGNORING_ARRAY_ORDER)
+ .whenIgnoringPaths("service.vidNotions.viewEditUI"));
}
public void getServiceModelWithoutInstantiationType(){
registerToSimulatorWithPresets(MACRO_INSTANTIATION_TYPE_UUID, MACRO_INSTANTIATION_TYPE_INVARIANT_UUID, EMPTY_INSTANTIATION_TYPE_FILE_PATH);
ResponseEntity<String> response = restTemplate.getForEntity(buildUri(SDC_GET_SERVICE_MODEL + MACRO_INSTANTIATION_TYPE_UUID), String.class);
- Assert.assertEquals(response.getStatusCode(), HttpStatus.OK);
+ assertEquals(response.getStatusCode(), HttpStatus.OK);
String emptyInstantiationTypeExpectedResponse = loadResourceAsString(EMPTY_INSTANTIATION_TYPE_EXPECTED_RESPONSE);
- assertThat("The response is in the format of JSON", response.getBody(), is(jsonStringEquals(turnOffInstantiationUI(emptyInstantiationTypeExpectedResponse))));
+
+ final String body = response.getBody();
+
+ assertThat(body, jsonEquals(emptyInstantiationTypeExpectedResponse)
+ .when(IGNORING_ARRAY_ORDER)
+ .whenIgnoringPaths("service.vidNotions.instantiationUI", "service.vidNotions.instantiationType"));
+
+ assertThat(body, jsonPartEquals("service.vidNotions.instantiationType",
+ Features.FLAG_2002_IDENTIFY_INVARIANT_MACRO_UUID_BY_BACKEND.isActive()
+ ? "ALaCarte" : "ClientConfig"));
}
@Test
public void getServiceModelBothInstantiationType(){
registerToSimulatorWithPresets(MACRO_INSTANTIATION_TYPE_UUID, MACRO_INSTANTIATION_TYPE_INVARIANT_UUID, BOTH_INSTANTIATION_TYPE_FILE_PATH);
ResponseEntity<String> response = restTemplate.getForEntity(buildUri(SDC_GET_SERVICE_MODEL + MACRO_INSTANTIATION_TYPE_UUID), String.class);
- Assert.assertEquals(response.getStatusCode(), HttpStatus.OK);
+ assertEquals(response.getStatusCode(), HttpStatus.OK);
String macroInstantiationTypeExpectedResponse = loadResourceAsString(MACRO_INSTANTIATION_TYPE_EXPECTED_RESPONSE);
- assertThat("The response is in the format of JSON", response.getBody(), is(jsonStringEquals(turnOffInstantiationUI(macroInstantiationTypeExpectedResponse))));
+ assertThat(response.getBody(), jsonEquals(macroInstantiationTypeExpectedResponse)
+ .when(IGNORING_ARRAY_ORDER)
+ .whenIgnoringPaths("service.vidNotions.viewEditUI"));
}
@Test
public void getServiceModelWithGroupsAndCheckMinMaxInitialParams(){
registerToSimulatorWithPresets(MIN_MAX_INITIAL_UUID, MIN_MAX_INITIAL_INVARIANT_UUID, MIN_MAX_INITIAL_FILE_PATH);
ResponseEntity<String> response = restTemplate.getForEntity(buildUri(SDC_GET_SERVICE_MODEL + MIN_MAX_INITIAL_UUID), String.class);
- Assert.assertEquals(response.getStatusCode(), HttpStatus.OK);
+ assertEquals(response.getStatusCode(), HttpStatus.OK);
String minMaxInitialExpectedResponse = loadResourceAsString("sdcApiTest/minMaxInitialExpectedResponse.json");
- assertThat("The response is in the format of JSON", response.getBody(), is(jsonStringEquals(turnOffInstantiationUI(minMaxInitialExpectedResponse))));
+ assertThat(response.getBody(), jsonEquals(minMaxInitialExpectedResponse)
+ .when(IGNORING_ARRAY_ORDER)
+ .whenIgnoringPaths("service.vidNotions.instantiationUI", "service.vidNotions.instantiationType"));
}
@Test
public void getServiceModelWithGroupsAndCheckMinMaxInitialParamsOldCsar(){
registerToSimulatorWithPresets(MIN_MAX_INITIAL_UUID_OLD_CSAR, MIN_MAX_INITIAL_INVARIANT_UUID_OLD_CSAR, MIN_MAX_INITIAL_FILE_PATH_OLD_CSAR);
ResponseEntity<String> response = restTemplate.getForEntity(buildUri(SDC_GET_SERVICE_MODEL + MIN_MAX_INITIAL_UUID_OLD_CSAR), String.class);
- Assert.assertEquals(response.getStatusCode(), HttpStatus.OK);
+ assertEquals(response.getStatusCode(), HttpStatus.OK);
String minMaxInitialExpectedResponseOldCsar = loadResourceAsString("sdcApiTest/minMaxInitialExpectedResponseOldCsar.json");
assertThat("The response is in the format of JSON", response.getBody(), is(jsonStringEquals(minMaxInitialExpectedResponseOldCsar)));
}
@Test
@FeatureTogglingTest(Features.FLAG_1902_VNF_GROUPING)
- public void getServiceModelWithServiceRoleGrouping(){
+ public void getServiceModelWithServiceRoleGrouping() throws Exception {
registerToSimulatorWithPresets(GROUPING_SERVICE_ROLE_UUID, GROUPING_SERVICE_ROLE_INVARIANT_UUID, GROUPING_SERVICE_ROLE_FILE_PATH);
ResponseEntity<String> response = restTemplate.getForEntity(buildUri(SDC_GET_SERVICE_MODEL + GROUPING_SERVICE_ROLE_UUID), String.class);
- Assert.assertEquals(response.getStatusCode(), HttpStatus.OK);
+ assertEquals(response.getStatusCode(), HttpStatus.OK);
String groupingServiceRoleExpectedResponse = loadResourceAsString(GROUPING_SERVICE_ROLE_EXPECTED_RESPONSE);
- assertThat("The response is in the format of JSON", response.getBody(), is(jsonStringEquals(groupingServiceRoleExpectedResponse)));
+ assertThat(response.getBody(), jsonEquals(groupingServiceRoleExpectedResponse)
+ .when(IGNORING_ARRAY_ORDER)
+ .whenIgnoringPaths("service.vidNotions.instantiationUI"));
+
+ //assert that instantiationUI is not legacy
+ JsonNode instantiationUI = objectMapper.readValue(response.getBody(), JsonNode.class).get("service").get("vidNotions").get("instantiationUI");
+ assertThat(instantiationUI.asText(), not(equalTo("legacy")));
}
private void registerToSimulatorWithPresets(String uuid, String invariantUuid, String pathPath){
registerExpectationFromPresets(presets, CLEAR_THEN_SET);
}
- private String turnOffInstantiationUI(String expectedJson) {
- if (!Features.FLAG_5G_IN_NEW_INSTANTIATION_UI.isActive()) {
- // replaces the instantiationUI field-value with "legacy", whatever it was
- return expectedJson.replaceFirst("(\"instantiationUI\": *\")[^\"]*(\",)", "$1legacy$2");
- } else {
- return expectedJson;
- }
- }
-
@Test
public void withModelFromE2eWithToscaParserButNewFlow_requestModels_expectVnfRelatedVfModulesNotNull() {
// using json-pointers instead of path, because vnf name has
// dots and spaces
- final String myVnf = "vMMEvProbe_FE_AIC3-11.2.1_VF 1";
+ final String myVnf = "vFLORENCEvProbe_FE_AIC3-11.2.1_VF 1";
final String base = "/vnfs/" + myVnf;
assertFalse(response.at(base).isMissingNode(),
response.at(base + "/volumeGroups").size(), is(not(0)));
}
+
+ @Test
+ public void whenCallSdc_thenRequestRecordedInMetricsLog() {
+
+ ModelInfo modelInfo = ModelInfo.transportWithPnfsService;
+ String internalPath = SDC_GET_SERVICE_MODEL + modelInfo.modelVersionId;
+ registerExpectationFromPresets(ImmutableList.of(
+ new PresetSDCGetServiceToscaModelGet(modelInfo),
+ new PresetSDCGetServiceMetadataGet(modelInfo),
+ new PresetAAIGetSubscribersGet() //for read logs permissions
+ ), CLEAR_THEN_SET);
+
+ ResponseEntity<String> response = restTemplate.getForEntity(
+ buildUri(internalPath), String.class);
+
+ final String requestId = response.getHeaders().getFirst("X-ECOMP-RequestID-echo");
+
+ LoggerFormatTest.assertHeadersAndMetricLogs(restTemplate, uri, requestId, SDC_ROOT_PATH, 2);
+ LoggerFormatTest.verifyExistenceOfIncomingReqsInAuditLogs(restTemplate, uri, requestId, internalPath);
+ }
+
}