toggle e2e template test with proper feature flag
[vid.git] / vid-automation / src / main / java / vid / automation / test / test / TemplateInstantiationTest.java
1 package vid.automation.test.test;
2
3 import static org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetCloudOwnersByCloudRegionId.PRESET_SOME_LEGACY_REGION_TO_ATT_AIC;
4 import static org.onap.simulator.presetGenerator.presets.mso.PresetMSOOrchestrationRequestGet.COMPLETE;
5 import static org.onap.simulator.presetGenerator.presets.mso.PresetMSOServiceInstanceGen2WithNames.Keys.SERVICE_NAME;
6 import static org.onap.vid.api.TestUtils.generateRandomAlphaNumeric;
7 import static vid.automation.test.Constants.BrowseASDC.NewServicePopup.SET_BUTTON;
8 import static vid.automation.test.Constants.DrawingBoard.CONTEXT_MENU_BUTTON_HEADER;
9 import static vid.automation.test.Constants.DrawingBoard.CONTEXT_MENU_HEADER_EDIT_ITEM;
10 import static vid.automation.test.Constants.DrawingBoard.DEPLOY_BUTTON;
11 import static vid.automation.test.infra.Features.FLAG_2004_INSTANTIATION_TEMPLATES_POPUP;
12 import static vid.automation.test.services.SimulatorApi.RegistrationStrategy.APPEND;
13 import static vid.automation.test.services.SimulatorApi.RegistrationStrategy.CLEAR_THEN_SET;
14 import static vid.automation.test.services.SimulatorApi.registerExpectationFromPresets;
15
16 import com.google.common.collect.ImmutableList;
17 import com.google.common.collect.ImmutableMap;
18 import java.util.List;
19 import org.onap.sdc.ci.tests.datatypes.UserCredentials;
20 import org.onap.sdc.ci.tests.utilities.GeneralUIUtils;
21 import org.onap.simulator.presetGenerator.presets.mso.PresetMSOCreateServiceInstanceAlacarte;
22 import org.onap.simulator.presetGenerator.presets.mso.PresetMSOOrchestrationRequestGet;
23 import org.onap.simulator.presetGenerator.presets.mso.PresetMSOServiceInstanceGen2WithNames.Keys;
24 import org.onap.vid.api.AsyncInstantiationBase;
25 import org.testng.annotations.AfterClass;
26 import org.testng.annotations.BeforeClass;
27 import org.testng.annotations.Test;
28 import vid.automation.test.infra.Click;
29 import vid.automation.test.infra.FeatureTogglingTest;
30 import vid.automation.test.infra.Get;
31 import vid.automation.test.infra.Input;
32 import vid.automation.test.infra.ModelInfo;
33 import vid.automation.test.sections.DrawingBoardPage;
34 import vid.automation.test.sections.SideMenu;
35 import vid.automation.test.sections.VidBasePage;
36 import vid.automation.test.services.AsyncJobsService;
37
38 public class TemplateInstantiationTest extends ModernUITestBase {
39
40     private AsyncInstantiationBase asyncInstantiationBase;
41
42     @BeforeClass
43     protected void setUp() {
44         AsyncJobsService asyncJobsService = new AsyncJobsService();
45         asyncJobsService.dropAllAsyncJobs();
46         asyncInstantiationBase = new AsyncInstantiationBase();
47         asyncInstantiationBase.init();
48         UserCredentials userCredentials = getUserCredentials();
49         //login for API test (needed besides selenium test via browser)
50         asyncInstantiationBase.login(userCredentials);
51     }
52
53     @AfterClass
54     protected void tearDown() {
55         AsyncJobsService asyncJobsService = new AsyncJobsService();
56         asyncJobsService.muteAllAsyncJobs();
57     }
58
59     /*
60         In this test we create an simple aLaCarte service via api,
61         Then browse SDC -> search for same model uuid -> deploy ->
62         template popup is opened -> select the service -> click load template ->
63         drawing board is opened -> edit service instance name -> deploy ->
64         instantiation status is opened -> wait for service to completed.
65      */
66     @FeatureTogglingTest(FLAG_2004_INSTANTIATION_TEMPLATES_POPUP)
67     @Test
68     public void instantiateALaCarteServiceFromTemplateTest() {
69
70         final ModelInfo modelInfo = ModelInfo.aLaCarteServiceCreationNewUI;
71         String templateInstanceName = "template"+generateRandomAlphaNumeric(10);
72         String requestorID = getUserCredentials().getUserId();
73         String serviceRequestId = uuid();
74         String serviceInstanceId = uuid();
75
76         //prepare presets for first instantiation (template), and rest of scenario till deploy
77         prepareServicePreset(modelInfo, true);
78         registerExpectationFromPresets(
79             ImmutableList.of(
80                 new PresetMSOCreateServiceInstanceAlacarte(
81                     ImmutableMap.of(Keys.SERVICE_NAME, templateInstanceName),
82                     serviceRequestId, serviceInstanceId,
83                     requestorID, modelInfo),
84                 PRESET_SOME_LEGACY_REGION_TO_ATT_AIC,
85                 new PresetMSOOrchestrationRequestGet(COMPLETE, serviceRequestId)
86             ),
87             APPEND
88         );
89
90         //create service instance via API
91         final List<String> jobsIds = asyncInstantiationBase.createBulkOfInstances(false, 1,
92             ImmutableMap.of(SERVICE_NAME, templateInstanceName), "asyncInstantiation/vidRequestCreateALaCarteForTemplate.json");
93         asyncInstantiationBase.waitForJobsToSuccessfullyCompleted(1, jobsIds);
94
95         String newInstanceName = "template"+generateRandomAlphaNumeric(10);
96         String serviceRequestId2 = uuid();
97         String serviceInstanceId2 = uuid();
98
99         //load template and and edit service instance name
100         browseSdcAndClickDeploy(modelInfo);
101         selectTemplateByNameAndLoadTemplate(templateInstanceName);
102         VidBasePage.goToIframe();
103         editServiceInstanceName(newInstanceName);
104
105         //prepare presets for second service instance deploy
106         registerExpectationFromPresets(
107             ImmutableList.of(
108                 new PresetMSOCreateServiceInstanceAlacarte(
109                     ImmutableMap.of(Keys.SERVICE_NAME, newInstanceName),
110                     serviceRequestId2, serviceInstanceId2,
111                     requestorID, modelInfo),
112                 PRESET_SOME_LEGACY_REGION_TO_ATT_AIC,
113                 new PresetMSOOrchestrationRequestGet(COMPLETE, serviceRequestId2)
114             ),
115             CLEAR_THEN_SET
116         );
117
118         //deploy the service and wait for completion
119         Click.byTestId(DEPLOY_BUTTON);
120         VidBasePage.goToIframe();
121         new DrawingBoardPage().verifyServiceCompletedOnTime(newInstanceName, "service deployed from template");
122     }
123
124     private void browseSdcAndClickDeploy(ModelInfo modelInfo) {
125         SideMenu.navigateToBrowseASDCPage();
126         GeneralUIUtils.ultimateWait();
127         loadTemplatesPopupOnBrowseASDCPage(modelInfo.modelVersionId);
128     }
129
130     private void selectTemplateByNameAndLoadTemplate(String templateInstanceName) {
131         Click.byText(templateInstanceName);
132         Click.byTestId("LoadTemplateButton");
133     }
134
135     private void editServiceInstanceName(String newInstanceName) {
136         GeneralUIUtils.getClickableButtonBy(Get.getXpathForDataTestId(CONTEXT_MENU_BUTTON_HEADER), 60).click();
137         Click.byTestId(CONTEXT_MENU_HEADER_EDIT_ITEM);
138         GeneralUIUtils.ultimateWait();
139         Input.replaceText(newInstanceName, "instanceName");
140         Click.byTestId(SET_BUTTON);
141     }
142
143 }