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