diff options
15 files changed, 502 insertions, 77 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/MsoUtil.java b/vid-app-common/src/main/java/org/onap/vid/mso/MsoUtil.java index 626816f7f..8de534a8e 100644 --- a/vid-app-common/src/main/java/org/onap/vid/mso/MsoUtil.java +++ b/vid-app-common/src/main/java/org/onap/vid/mso/MsoUtil.java @@ -21,15 +21,15 @@ package org.onap.vid.mso; +import static org.apache.commons.lang3.StringUtils.firstNonBlank; +import static org.apache.commons.lang3.StringUtils.isEmpty; import static org.onap.vid.utils.KotlinUtilsKt.JACKSON_OBJECT_MAPPER; -import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; import io.joshworks.restclient.http.HttpResponse; import java.io.IOException; -import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.exception.ExceptionUtils; -import org.onap.vid.exceptions.GenericUncheckedException; public class MsoUtil { @@ -76,22 +76,31 @@ public class MsoUtil { } public static String formatExceptionAdditionalInfo(int statusCode, String msoResponse) { - String errorMsg = "Http Code:" + statusCode; - if (!StringUtils.isEmpty(msoResponse)) { - String filteredJson; - try { - filteredJson = StringUtils.defaultIfEmpty( - JACKSON_OBJECT_MAPPER.readTree(msoResponse).path("serviceException").toString().replaceAll("[\\{\\}]","") , - msoResponse - ); - } catch (JsonParseException e) { - filteredJson = msoResponse; - } catch (IOException e) { - throw new GenericUncheckedException(e); - } + final String errorMsg = "Http Code:" + statusCode; + + if (isEmpty(msoResponse)) { + return errorMsg; + } + + try { + JsonNode jsonNode = JACKSON_OBJECT_MAPPER.readTree(msoResponse); - errorMsg = errorMsg + ", " + filteredJson; + return errorMsg + ", " + firstNonBlank( + removeBraces(jsonNode.get("serviceException")), + removeBraces(jsonNode.path("requestError").get("serviceException")), + msoResponse + ); + + } catch (Exception e) { + return errorMsg + ", " + msoResponse; } - return errorMsg; + } + + private static String removeBraces(JsonNode jsonNode) { + if (jsonNode == null || jsonNode.isMissingNode()) { + return null; + } + + return jsonNode.toString().replaceAll("[\\{\\}]", ""); } } diff --git a/vid-app-common/src/main/java/org/onap/vid/properties/FeatureSetsManager.kt b/vid-app-common/src/main/java/org/onap/vid/properties/FeatureSetsManager.kt new file mode 100644 index 000000000..207bde7aa --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/properties/FeatureSetsManager.kt @@ -0,0 +1,82 @@ +package org.onap.vid.properties + +import org.apache.commons.io.filefilter.WildcardFileFilter +import org.springframework.web.context.request.RequestContextHolder.getRequestAttributes +import org.springframework.web.context.request.ServletRequestAttributes +import org.togglz.core.Feature +import org.togglz.core.manager.FeatureManager +import org.togglz.core.manager.FeatureManagerBuilder +import org.togglz.core.repository.file.FileBasedStateRepository +import java.io.File +import java.io.FilenameFilter +import javax.servlet.ServletContext +import javax.servlet.http.HttpServletRequest + + +private const val SLOW_RELOAD = 60_000 +private const val COOKIE_NAME = "features.set" + +class FeatureSetsManager( + private val defaultManager: FeatureManager, + private val nameProvider: AlternativeFeatureSetNameProvider, + private val servletContext: ServletContext +) : FeatureManager by defaultManager { + + override fun isActive(feature: Feature?): Boolean { + return resolvedFeatureManager().isActive(feature) + } + + private fun resolvedFeatureManager(): FeatureManager { + return when (val alternativeFeatureSetName = nameProvider.alternativeFeatureSetName) { + null -> defaultManager + else -> allFeatureManagers.getValue(alternativeFeatureSetName) + } + } + + internal val allFeatureManagers: Map<String, FeatureManager> by lazy { + allFeatureSetFiles().associateBy( + { it.name }, + { newFeatureManager(it) } + ).withDefault { allFeaturesOff } + } + + private val allFeaturesOff = + FeatureManagerBuilder().featureEnum(Features::class.java).build() + + private fun newFeatureManager(file: File): FeatureManager { + return FeatureManagerBuilder() + .featureEnum(Features::class.java) + .stateRepository(FileBasedStateRepository(file, SLOW_RELOAD)) + .build() + } + + private fun allFeatureSetFiles(): Array<File> { + val dir = File(servletContext.getRealPath("/WEB-INF/conf/")) + val fileFilter: FilenameFilter = WildcardFileFilter("*.features.properties") + + return dir.listFiles(fileFilter) ?: emptyArray() + } +} + +interface AlternativeFeatureSetNameProvider { + val alternativeFeatureSetName: String? +} + +class AlternativeFeatureSetNameFromCookie: AlternativeFeatureSetNameProvider { + override val alternativeFeatureSetName: String? + get() = valueFromCookie(currentHttpRequest()) + + internal fun valueFromCookie(httpServletRequest: HttpServletRequest?): String? { + return httpServletRequest + ?.cookies + ?.firstOrNull { it.name == COOKIE_NAME } + ?.value + } + + internal fun currentHttpRequest(): HttpServletRequest? { + return when (val requestAttributes = getRequestAttributes()) { + is ServletRequestAttributes -> requestAttributes.request + else -> null + } + } +} diff --git a/vid-app-common/src/main/java/org/onap/vid/properties/FeaturesTogglingConfiguration.java b/vid-app-common/src/main/java/org/onap/vid/properties/FeaturesTogglingConfiguration.java index 4d4387d4e..96331b7c4 100644 --- a/vid-app-common/src/main/java/org/onap/vid/properties/FeaturesTogglingConfiguration.java +++ b/vid-app-common/src/main/java/org/onap/vid/properties/FeaturesTogglingConfiguration.java @@ -20,6 +20,8 @@ package org.onap.vid.properties; +import java.io.File; +import javax.servlet.ServletContext; import org.apache.commons.lang3.StringUtils; import org.springframework.context.ApplicationListener; import org.springframework.context.annotation.Bean; @@ -30,9 +32,6 @@ import org.togglz.core.manager.FeatureManagerBuilder; import org.togglz.core.repository.file.FileBasedStateRepository; import org.togglz.spring.listener.TogglzApplicationContextBinderApplicationListener; -import javax.servlet.ServletContext; -import java.io.File; - @Configuration public class FeaturesTogglingConfiguration { @Bean @@ -52,11 +51,13 @@ public class FeaturesTogglingConfiguration { filename = StringUtils.trimToNull(filename); - return new FeatureManagerBuilder() + return new FeatureSetsManager( + new FeatureManagerBuilder() .featureEnum(Features.class) .stateRepository(new FileBasedStateRepository( - new File(filename.startsWith("/")? filename : servletContext.getRealPath("/WEB-INF/conf/" + filename)) + new File(filename.startsWith("/") ? filename : servletContext.getRealPath("/WEB-INF/conf/" + filename)) )) - .build(); + .build(), new AlternativeFeatureSetNameFromCookie(), servletContext + ); } } diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/MsoUtilTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/MsoUtilTest.java index 10456bebf..cfde52a56 100644 --- a/vid-app-common/src/test/java/org/onap/vid/mso/MsoUtilTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/mso/MsoUtilTest.java @@ -26,6 +26,7 @@ import static org.assertj.core.api.Assertions.assertThat; import io.joshworks.restclient.http.HttpResponse; import org.onap.vid.testUtils.TestUtils; +import org.testng.annotations.DataProvider; import org.testng.annotations.Test; public class MsoUtilTest { @@ -67,4 +68,26 @@ public class MsoUtilTest { assertThat(result.getStatus()).isEqualTo(SC_OK); } + @DataProvider + public static Object[][] formatExceptionAdditionalInfo() { + return new Object[][]{ + {"message", "Http Code:400, message"}, + + {null, "Http Code:400"}, + + {"{\"requestError\":{\"serviceException\":{\"messageId\":\"SVC0002\",\"text\":\"message\"}}}", + "Http Code:400, \"messageId\":\"SVC0002\",\"text\":\"message\""}, + + {"{\"validJson\": \"Error: message\"}", "Http Code:400, {\"validJson\": \"Error: message\"}"}, + + {"{\"serviceException\":{\"messageId\":\"SVC0002\",\"text\":\"Error: message\"}}", + "Http Code:400, \"messageId\":\"SVC0002\",\"text\":\"Error: message\""}, + }; + } + + @Test(dataProvider = "formatExceptionAdditionalInfo") + public void formatExceptionAdditionalInfo_payloadWithError400_doNotReturnNull(String payload, String expected) { + assertThat(MsoUtil.formatExceptionAdditionalInfo(400, payload)) + .isEqualTo(expected); + } } diff --git a/vid-app-common/src/test/java/org/onap/vid/properties/FeatureSetsManagerTest.kt b/vid-app-common/src/test/java/org/onap/vid/properties/FeatureSetsManagerTest.kt new file mode 100644 index 000000000..9cf7aa662 --- /dev/null +++ b/vid-app-common/src/test/java/org/onap/vid/properties/FeatureSetsManagerTest.kt @@ -0,0 +1,101 @@ +package org.onap.vid.properties + +import org.hamcrest.CoreMatchers.* +import org.hamcrest.MatcherAssert.assertThat +import org.mockito.ArgumentMatchers.anyString +import org.mockito.InjectMocks +import org.mockito.Mock +import org.mockito.Mockito.* +import org.onap.vid.testUtils.TestUtils +import org.springframework.web.context.request.RequestContextHolder +import org.testng.annotations.BeforeMethod +import org.testng.annotations.Test +import org.togglz.core.manager.FeatureManager +import javax.servlet.ServletContext +import javax.servlet.http.Cookie +import javax.servlet.http.HttpServletRequest +import org.hamcrest.CoreMatchers.`is` as _is +import org.mockito.Mockito.`when` as _when + +class FeatureSetsManagerTest { + @Mock + lateinit var defaultFeatureManager: FeatureManager + @Mock + lateinit var servletContext: ServletContext + @Mock + lateinit var alternativeFeatureSetNameProvider: AlternativeFeatureSetNameProvider + @InjectMocks + lateinit var featureSetsManager: FeatureSetsManager + + private val alternativeFeatureSetNameFromCookie = AlternativeFeatureSetNameFromCookie() + + @BeforeMethod + fun setUp() { + TestUtils.initMockitoMocks(this) + } + + @Test + fun `isActive - without alternative features set name - delegates to default and no file loaded`() { + _when(defaultFeatureManager.isActive(Features.FLAG_1810_AAI_LOCAL_CACHE)).thenReturn(true) + _when(alternativeFeatureSetNameProvider.alternativeFeatureSetName).thenReturn(null) + + assertThat(featureSetsManager.isActive(Features.FLAG_1810_AAI_LOCAL_CACHE), _is(true)) + + verifyZeroInteractions(servletContext) // implies no other file loaded + verify(defaultFeatureManager, times(1)).isActive(Features.FLAG_1810_AAI_LOCAL_CACHE) + } + + @Test + fun `isActive - with alternative features set - brings flags from alternative`() { + _when(servletContext.getRealPath(anyString())).thenReturn(this.javaClass.getResource("/").path) + _when(alternativeFeatureSetNameProvider.alternativeFeatureSetName).thenReturn("example.features.properties") + + assertThat(featureSetsManager.isActive(Features.FLAG_1810_AAI_LOCAL_CACHE), _is(true)) + assertThat(featureSetsManager.isActive(Features.FLAG_1902_NEW_VIEW_EDIT), _is(false)) + verifyZeroInteractions(defaultFeatureManager) + } + + @Test + fun `isActive - with non-existing alternative features set - fallback is to all flags off`() { + _when(servletContext.getRealPath(anyString())).thenReturn(this.javaClass.getResource("/").path) + _when(alternativeFeatureSetNameProvider.alternativeFeatureSetName).thenReturn("non-existing") + + assertThat(featureSetsManager, not(nullValue())) + assertThat( + featureSetsManager.features.map { featureSetsManager.isActive(it) }, + not(hasItem(true)) + ) + } + + @Test + fun `valueFromCookie - given no request - return null`() { + assertThat(alternativeFeatureSetNameFromCookie.valueFromCookie(null), _is(nullValue())) + } + + @Test + fun `valueFromCookie - given request - return the correct cookie value`() { + val servletRequestMock = mock(HttpServletRequest::class.java) + _when(servletRequestMock.cookies).thenReturn(arrayOf(Cookie("features.set", "value"))) + + assertThat(alternativeFeatureSetNameFromCookie.valueFromCookie(servletRequestMock), _is("value")) + } + + @Test + fun `valueFromCookie - given request without cookies - return null`() { + val servletRequestMock = mock(HttpServletRequest::class.java) + _when(servletRequestMock.cookies).thenReturn(emptyArray()) + + assertThat(alternativeFeatureSetNameFromCookie.valueFromCookie(servletRequestMock), _is(nullValue())) + } + + @Test + fun `currentHttpRequest - when no current request - return null`() { + assertPrecondition() + assertThat(alternativeFeatureSetNameFromCookie.currentHttpRequest(), _is(nullValue())) + } + + private fun assertPrecondition() { + assertThat("precondition for test not met: static RequestContextHolder.getRequestAttributes should be null", + RequestContextHolder.getRequestAttributes(), _is(nullValue())) + } +} diff --git a/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBusinessLogicTest.java b/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBusinessLogicTest.java index 0749aaf82..a1e4af2c4 100644 --- a/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBusinessLogicTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBusinessLogicTest.java @@ -1223,7 +1223,8 @@ public class AsyncInstantiationBusinessLogicTest extends AsyncInstantiationBaseT String message = "Failed to create service instance"; return new Object[][]{ {500, message}, - {199, "{\"serviceException\":{\"messageId\":\"SVC2000\",\"text\":\"Error: " + message + "\"}}"} + {400, "{\"requestError\":{\"serviceException\":{\"messageId\":\"SVC0002\",\"text\":\"" + message + "\"}}}"}, + {199, "{\"serviceException\":{\"messageId\":\"SVC2000\",\"text\":\"Error: " + message + "\"}}"}, }; } diff --git a/vid-app-common/src/test/resources/example.features.properties b/vid-app-common/src/test/resources/example.features.properties new file mode 100644 index 000000000..e8ac3eb65 --- /dev/null +++ b/vid-app-common/src/test/resources/example.features.properties @@ -0,0 +1 @@ +FLAG_1810_AAI_LOCAL_CACHE=true
\ No newline at end of file diff --git a/vid-automation/src/main/java/org/onap/vid/api/AsyncInstantiationBase.java b/vid-automation/src/main/java/org/onap/vid/api/AsyncInstantiationBase.java index 8855b51f0..66cdee374 100644 --- a/vid-automation/src/main/java/org/onap/vid/api/AsyncInstantiationBase.java +++ b/vid-automation/src/main/java/org/onap/vid/api/AsyncInstantiationBase.java @@ -305,15 +305,19 @@ public class AsyncInstantiationBase extends BaseMsoApiTest { final List<String> jobIds = createBulkOfMacroInstances(presets, false, bulkSize, names); Assert.assertEquals(jobIds.size(),bulkSize); + waitForJobsToSuccessfullyCompleted(bulkSize, jobIds); + return jobIds; + } + + public void waitForJobsToSuccessfullyCompleted(int bulkSize, List<String> jobIds) { assertTrue(String.format("Not all services with ids: %s are in state completed after 30 sec", jobIds.stream().collect(joining(","))), Wait.waitFor(y-> serviceListCall().getBody().stream() .filter(si -> jobIds.contains(si.jobId)) - .filter(si -> si.jobStatus==JobStatus.COMPLETED) + .filter(si -> si.jobStatus== JobStatus.COMPLETED) .count() == bulkSize, null, 30, 1 )); - return jobIds; } protected List<JobAuditStatus> getJobMsoAuditStatusForAlaCarte(String jobUUID, String requestId, String serviceInstanceId){ diff --git a/vid-automation/src/main/java/vid/automation/test/infra/Features.java b/vid-automation/src/main/java/vid/automation/test/infra/Features.java index 6be6870c2..f55053497 100644 --- a/vid-automation/src/main/java/vid/automation/test/infra/Features.java +++ b/vid-automation/src/main/java/vid/automation/test/infra/Features.java @@ -56,6 +56,7 @@ public enum Features implements Feature { FLAG_2002_IDENTIFY_INVARIANT_MACRO_UUID_BY_BACKEND, FLAG_2004_CREATE_ANOTHER_INSTANCE_FROM_TEMPLATE, FLAG_2002_UNLIMITED_MAX, + FLAG_2004_INSTANTIATION_TEMPLATES_POPUP, ; public boolean isActive() { diff --git a/vid-automation/src/main/java/vid/automation/test/test/CreateInstanceDialogBaseTest.java b/vid-automation/src/main/java/vid/automation/test/test/CreateInstanceDialogBaseTest.java index df3b41d06..2a122119d 100644 --- a/vid-automation/src/main/java/vid/automation/test/test/CreateInstanceDialogBaseTest.java +++ b/vid-automation/src/main/java/vid/automation/test/test/CreateInstanceDialogBaseTest.java @@ -1,20 +1,17 @@ package vid.automation.test.test; +import java.util.ArrayList; import org.junit.Assert; import org.onap.sdc.ci.tests.utilities.GeneralUIUtils; import org.openqa.selenium.WebElement; import vid.automation.test.Constants; import vid.automation.test.infra.Click; import vid.automation.test.infra.Exists; -import vid.automation.test.infra.Get; import vid.automation.test.infra.SelectOption; import vid.automation.test.model.Service; import vid.automation.test.model.ServiceModel; import vid.automation.test.sections.ViewEditPage; -import java.util.ArrayList; -import java.util.List; - public class CreateInstanceDialogBaseTest extends VidBaseTestCase { protected ViewEditPage viewEditPage= new ViewEditPage(); @@ -147,24 +144,4 @@ public class CreateInstanceDialogBaseTest extends VidBaseTestCase { Assert.assertTrue(field + " " + Constants.REQUIRED, byclassAndText); } - protected void cancelPopup() { - viewEditPage.clickCancelButtonByTestID(); - GeneralUIUtils.ultimateWait(); - } - - - - public static void AssertUnselectedOptionInMultiselectById(String multiSelectId, String unselectedOption){ - Click.byId(multiSelectId); - WebElement element = Get.byClassAndText(Constants.MULTI_SELECT_UNSELECTED_CLASS, unselectedOption); - Assert.assertTrue("The option "+ unselectedOption +" is already selected",element != null); - Click.byId(multiSelectId); - } - - public void validateDynamicFields(List<String> dynamicFields) { - for (String field : dynamicFields) { - WebElement fieldElement = GeneralUIUtils.findByText(field); - Assert.assertNotNull("couldn't find dynamic field: " + field, fieldElement); - } - } } diff --git a/vid-automation/src/main/java/vid/automation/test/test/ModernUITestBase.java b/vid-automation/src/main/java/vid/automation/test/test/ModernUITestBase.java new file mode 100644 index 000000000..dd6a0f6b8 --- /dev/null +++ b/vid-automation/src/main/java/vid/automation/test/test/ModernUITestBase.java @@ -0,0 +1,34 @@ +package vid.automation.test.test; + +import static vid.automation.test.infra.ModelInfo.pasqualeVmxVpeBvService488Annotations; + +import com.google.common.collect.ImmutableList; +import java.util.UUID; +import org.jetbrains.annotations.NotNull; +import vid.automation.test.infra.ModelInfo; +import vid.automation.test.sections.ViewEditPage; + +public class ModernUITestBase extends VidBaseTestCase { + + protected ViewEditPage viewEditPage = new ViewEditPage(); + + protected void prepareServicePreset(ModelInfo modelInfo, boolean deploy) { + String subscriberId = "e433710f-9217-458d-a79d-1c7aff376d89"; + + if (deploy) { + registerExpectationForServiceDeployment( + ImmutableList.of( + modelInfo, + pasqualeVmxVpeBvService488Annotations + ), + subscriberId, null); + } else { + registerExpectationForServiceBrowseAndDesign(ImmutableList.of(modelInfo), subscriberId); + } + } + + @NotNull + protected String uuid() { + return UUID.randomUUID().toString(); + } +} diff --git a/vid-automation/src/main/java/vid/automation/test/test/NewServiceInstanceTest.java b/vid-automation/src/main/java/vid/automation/test/test/NewServiceInstanceTest.java index 68a3cdefe..eb3406f5f 100644 --- a/vid-automation/src/main/java/vid/automation/test/test/NewServiceInstanceTest.java +++ b/vid-automation/src/main/java/vid/automation/test/test/NewServiceInstanceTest.java @@ -11,6 +11,7 @@ import static org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetCloudOw import static org.onap.simulator.presetGenerator.presets.mso.PresetMSOOrchestrationRequestGet.COMPLETE; import static org.onap.simulator.presetGenerator.presets.mso.PresetMSOOrchestrationRequestGet.DEFAULT_SERVICE_INSTANCE_ID; import static org.testng.Assert.assertEquals; +import static org.testng.AssertJUnit.assertNotNull; import static org.testng.AssertJUnit.assertTrue; import static vid.automation.test.infra.Features.FLAG_1902_VNF_GROUPING; import static vid.automation.test.infra.Features.FLAG_1908_COLLECTION_RESOURCE_NEW_INSTANTIATION_UI; @@ -28,7 +29,6 @@ import static vid.automation.test.infra.ModelInfo.macroSriovNoDynamicFieldsEcomp import static vid.automation.test.infra.ModelInfo.macroSriovNoDynamicFieldsEcompNamingFalseFullModelDetailsVnfEcompNamingFalse; import static vid.automation.test.infra.ModelInfo.macroSriovWithDynamicFieldsEcompNamingFalsePartialModelDetailsVnfEcompNamingFalse; import static vid.automation.test.infra.ModelInfo.macroSriovWithDynamicFieldsEcompNamingTruePartialModelDetails; -import static vid.automation.test.infra.ModelInfo.pasqualeVmxVpeBvService488Annotations; import static vid.automation.test.infra.ModelInfo.transportWithPnfsService; import static vid.automation.test.services.SimulatorApi.RegistrationStrategy.APPEND; import static vid.automation.test.services.SimulatorApi.registerExpectationFromPreset; @@ -48,13 +48,11 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.UUID; import java.util.stream.Collectors; import org.apache.commons.lang3.mutable.MutableInt; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.hamcrest.Matchers; -import org.jetbrains.annotations.NotNull; import org.onap.sdc.ci.tests.datatypes.UserCredentials; import org.onap.sdc.ci.tests.utilities.GeneralUIUtils; import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetL3NetworksByCloudRegionSpecificState; @@ -106,7 +104,7 @@ import vid.automation.test.test.NewServiceInstanceTest.ServiceData.IS_GENERATED_ import vid.automation.test.utils.ReadFile; @FeatureTogglingTest(FLAG_ENABLE_WEBPACK_MODERN_UI) -public class NewServiceInstanceTest extends CreateInstanceDialogBaseTest { +public class NewServiceInstanceTest extends ModernUITestBase { public static final String COMPLETED = "COMPLETED"; private static final String IN_PROGRESS = "IN_PROGRESS"; @@ -1384,12 +1382,13 @@ public class NewServiceInstanceTest extends CreateInstanceDialogBaseTest { } } - @NotNull - private String uuid() { - return UUID.randomUUID().toString(); + public void validateDynamicFields(List<String> dynamicFields) { + for (String field : dynamicFields) { + WebElement fieldElement = GeneralUIUtils.findByText(field); + assertNotNull("couldn't find dynamic field: " + field, fieldElement); + } } - private void assertNotificationAreaVisibilityBehaviourAndSetBulkSize(int size) { WebElement webElement = Get.byId("notification-area"); Assert.assertNull(webElement, "notification area should be invisible if only 1 qty."); @@ -1400,22 +1399,6 @@ public class NewServiceInstanceTest extends CreateInstanceDialogBaseTest { Assert.assertNotNull(webElement, "notification area should be visible if more then 1 qty."); } - //@Step("prepare service preset") - private void prepareServicePreset(ModelInfo modelInfo, boolean deploy) { - String subscriberId = "e433710f-9217-458d-a79d-1c7aff376d89"; - - if (deploy) { - registerExpectationForServiceDeployment( - ImmutableList.of( - modelInfo, - pasqualeVmxVpeBvService488Annotations - ), - subscriberId, null); - } else { - registerExpectationForServiceBrowseAndDesign(ImmutableList.of(modelInfo), subscriberId); - } - } - static class ServiceData { ServiceData(String modelUuid, List<String> dynamicFields, IS_GENERATED_NAMING isServiceGeneratedNaming, diff --git a/vid-automation/src/main/java/vid/automation/test/test/TemplateInstantiationTest.java b/vid-automation/src/main/java/vid/automation/test/test/TemplateInstantiationTest.java new file mode 100644 index 000000000..f2b0fb19c --- /dev/null +++ b/vid-automation/src/main/java/vid/automation/test/test/TemplateInstantiationTest.java @@ -0,0 +1,143 @@ +package vid.automation.test.test; + +import static org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetCloudOwnersByCloudRegionId.PRESET_SOME_LEGACY_REGION_TO_ATT_AIC; +import static org.onap.simulator.presetGenerator.presets.mso.PresetMSOOrchestrationRequestGet.COMPLETE; +import static org.onap.simulator.presetGenerator.presets.mso.PresetMSOServiceInstanceGen2WithNames.Keys.SERVICE_NAME; +import static org.onap.vid.api.TestUtils.generateRandomAlphaNumeric; +import static vid.automation.test.Constants.BrowseASDC.NewServicePopup.SET_BUTTON; +import static vid.automation.test.Constants.DrawingBoard.CONTEXT_MENU_BUTTON_HEADER; +import static vid.automation.test.Constants.DrawingBoard.CONTEXT_MENU_HEADER_EDIT_ITEM; +import static vid.automation.test.Constants.DrawingBoard.DEPLOY_BUTTON; +import static vid.automation.test.infra.Features.FLAG_2004_INSTANTIATION_TEMPLATES_POPUP; +import static vid.automation.test.services.SimulatorApi.RegistrationStrategy.APPEND; +import static vid.automation.test.services.SimulatorApi.RegistrationStrategy.CLEAR_THEN_SET; +import static vid.automation.test.services.SimulatorApi.registerExpectationFromPresets; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import java.util.List; +import org.onap.sdc.ci.tests.datatypes.UserCredentials; +import org.onap.sdc.ci.tests.utilities.GeneralUIUtils; +import org.onap.simulator.presetGenerator.presets.mso.PresetMSOCreateServiceInstanceAlacarte; +import org.onap.simulator.presetGenerator.presets.mso.PresetMSOOrchestrationRequestGet; +import org.onap.simulator.presetGenerator.presets.mso.PresetMSOServiceInstanceGen2WithNames.Keys; +import org.onap.vid.api.AsyncInstantiationBase; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import vid.automation.test.infra.Click; +import vid.automation.test.infra.FeatureTogglingTest; +import vid.automation.test.infra.Get; +import vid.automation.test.infra.Input; +import vid.automation.test.infra.ModelInfo; +import vid.automation.test.sections.DrawingBoardPage; +import vid.automation.test.sections.SideMenu; +import vid.automation.test.sections.VidBasePage; +import vid.automation.test.services.AsyncJobsService; + +public class TemplateInstantiationTest extends ModernUITestBase { + + private AsyncInstantiationBase asyncInstantiationBase; + + @BeforeClass + protected void setUp() { + AsyncJobsService asyncJobsService = new AsyncJobsService(); + asyncJobsService.dropAllAsyncJobs(); + asyncInstantiationBase = new AsyncInstantiationBase(); + asyncInstantiationBase.init(); + UserCredentials userCredentials = getUserCredentials(); + //login for API test (needed besides selenium test via browser) + asyncInstantiationBase.login(userCredentials); + } + + @AfterClass + protected void tearDown() { + AsyncJobsService asyncJobsService = new AsyncJobsService(); + asyncJobsService.muteAllAsyncJobs(); + } + + /* + In this test we create an simple aLaCarte service via api, + Then browse SDC -> search for same model uuid -> deploy -> + template popup is opened -> select the service -> click load template -> + drawing board is opened -> edit service instance name -> deploy -> + instantiation status is opened -> wait for service to completed. + */ + @FeatureTogglingTest(FLAG_2004_INSTANTIATION_TEMPLATES_POPUP) + @Test + public void instantiateALaCarteServiceFromTemplateTest() { + + final ModelInfo modelInfo = ModelInfo.aLaCarteServiceCreationNewUI; + String templateInstanceName = "template"+generateRandomAlphaNumeric(10); + String requestorID = getUserCredentials().getUserId(); + String serviceRequestId = uuid(); + String serviceInstanceId = uuid(); + + //prepare presets for first instantiation (template), and rest of scenario till deploy + prepareServicePreset(modelInfo, true); + registerExpectationFromPresets( + ImmutableList.of( + new PresetMSOCreateServiceInstanceAlacarte( + ImmutableMap.of(Keys.SERVICE_NAME, templateInstanceName), + serviceRequestId, serviceInstanceId, + requestorID, modelInfo), + PRESET_SOME_LEGACY_REGION_TO_ATT_AIC, + new PresetMSOOrchestrationRequestGet(COMPLETE, serviceRequestId) + ), + APPEND + ); + + //create service instance via API + final List<String> jobsIds = asyncInstantiationBase.createBulkOfInstances(false, 1, + ImmutableMap.of(SERVICE_NAME, templateInstanceName), "asyncInstantiation/vidRequestCreateALaCarteForTemplate.json"); + asyncInstantiationBase.waitForJobsToSuccessfullyCompleted(1, jobsIds); + + String newInstanceName = "template"+generateRandomAlphaNumeric(10); + String serviceRequestId2 = uuid(); + String serviceInstanceId2 = uuid(); + + //load template and and edit service instance name + browseSdcAndClickDeploy(modelInfo); + selectTemplateByNameAndLoadTemplate(templateInstanceName); + VidBasePage.goToIframe(); + editServiceInstanceName(newInstanceName); + + //prepare presets for second service instance deploy + registerExpectationFromPresets( + ImmutableList.of( + new PresetMSOCreateServiceInstanceAlacarte( + ImmutableMap.of(Keys.SERVICE_NAME, newInstanceName), + serviceRequestId2, serviceInstanceId2, + requestorID, modelInfo), + PRESET_SOME_LEGACY_REGION_TO_ATT_AIC, + new PresetMSOOrchestrationRequestGet(COMPLETE, serviceRequestId2) + ), + CLEAR_THEN_SET + ); + + //deploy the service and wait for completion + Click.byTestId(DEPLOY_BUTTON); + VidBasePage.goToIframe(); + new DrawingBoardPage().verifyServiceCompletedOnTime(newInstanceName, "service deployed from template"); + } + + private void browseSdcAndClickDeploy(ModelInfo modelInfo) { + SideMenu.navigateToBrowseASDCPage(); + GeneralUIUtils.ultimateWait(); + loadTemplatesPopupOnBrowseASDCPage(modelInfo.modelVersionId); + } + + private void selectTemplateByNameAndLoadTemplate(String templateInstanceName) { + Click.byText(templateInstanceName); + Click.byTestId("LoadTemplateButton"); + } + + private void editServiceInstanceName(String newInstanceName) { + GeneralUIUtils.getClickableButtonBy(Get.getXpathForDataTestId(CONTEXT_MENU_BUTTON_HEADER), 60).click(); + Click.byTestId(CONTEXT_MENU_HEADER_EDIT_ITEM); + GeneralUIUtils.ultimateWait(); + Input.replaceText(newInstanceName, "instanceName"); + Click.byTestId(SET_BUTTON); + } + +} diff --git a/vid-automation/src/main/java/vid/automation/test/test/VidBaseTestCase.java b/vid-automation/src/main/java/vid/automation/test/test/VidBaseTestCase.java index c2733f0fb..fd3dd47a6 100644 --- a/vid-automation/src/main/java/vid/automation/test/test/VidBaseTestCase.java +++ b/vid-automation/src/main/java/vid/automation/test/test/VidBaseTestCase.java @@ -523,13 +523,21 @@ public class VidBaseTestCase extends SetupCDTest{ loadServicePopupOnBrowseASDCPage(modelVersionId); } - protected void loadServicePopupOnBrowseASDCPage(String modelVersionId ) { + protected void loadServicePopupOnBrowseASDCPage(String modelVersionId) { + loadServicePopupOnBrowseASDCPage(modelVersionId, "Model version"); + } + + protected void loadTemplatesPopupOnBrowseASDCPage (String modelVersionId) { + loadServicePopupOnBrowseASDCPage(modelVersionId, "Templates"); + } + + protected void loadServicePopupOnBrowseASDCPage(String modelVersionId, String expectedText) { DeployModernUIMacroDialog deployMacroDialog = new DeployModernUIMacroDialog(); VidBasePage.goOutFromIframe(); deployMacroDialog.clickDeployServiceButtonByServiceUUID(modelVersionId); deployMacroDialog.goToIframe(); GeneralUIUtils.ultimateWait(); - Wait.byText("Model version"); + Wait.byText(expectedText); } public void assertSetButtonDisabled(String buttonTestId) { diff --git a/vid-automation/src/main/resources/asyncInstantiation/vidRequestCreateALaCarteForTemplate.json b/vid-automation/src/main/resources/asyncInstantiation/vidRequestCreateALaCarteForTemplate.json new file mode 100644 index 000000000..5b831b937 --- /dev/null +++ b/vid-automation/src/main/resources/asyncInstantiation/vidRequestCreateALaCarteForTemplate.json @@ -0,0 +1,57 @@ +{ + "action": "Create", + "isDirty": true, + "vnfs": {}, + "vrfs": {}, + "instanceParams": [{} + ], + "validationCounter": 0, + "existingNames": { + "alacartewithvnfzvcjg": "" + }, + "existingVNFCounterMap": { + "e9ed1da0-c078-426a-8e84-6f4e85eace59": 0 + }, + "existingVRFCounterMap": {}, + "existingVnfGroupCounterMap": {}, + "existingNetworksCounterMap": {}, + "networks": {}, + "vnfGroups": {}, + "bulkSize": 1, + "instanceName": "SERVICE_NAME", + "globalSubscriberId": "e433710f-9217-458d-a79d-1c7aff376d89", + "subscriptionServiceType": "TYLER SILVIA", + "owningEntityId": "d61e6f2d-12fa-4cc2-91df-7c244011d6fc", + "projectName": "WATKINS", + "rollbackOnFailure": true, + "aicZoneName": null, + "owningEntityName": "WayneHolland", + "testApi": "VNF_API", + "tenantName": null, + "modelInfo": { + "modelInvariantId": "d1068db8-b933-4919-8972-8bc1aed366c8", + "modelVersionId": "f3862254-8df2-4a0a-8137-0a9fe985860c", + "modelName": "vOCG_1804_SVC", + "modelVersion": "1.0", + "uuid": "f3862254-8df2-4a0a-8137-0a9fe985860c", + "modelUniqueId": "f3862254-8df2-4a0a-8137-0a9fe985860c" + }, + "isALaCarte": true, + "name": "vOCG_1804_SVC", + "version": "1.0", + "description": "updated HEAT", + "category": "Emanuel", + "uuid": "f3862254-8df2-4a0a-8137-0a9fe985860c", + "invariantUuid": "d1068db8-b933-4919-8972-8bc1aed366c8", + "serviceType": "", + "serviceRole": "", + "vidNotions": { + "instantiationUI": "anyAlacarteWhichNotExcluded", + "modelCategory": "other", + "viewEditUI": "legacy", + "instantiationType": "ALaCarte" + }, + "isEcompGeneratedNaming": true, + "isMultiStepDesign": false, + "subscriberName": "SILVIA ROBBINS" +}
\ No newline at end of file |