Merge from ECOMP's repository
[vid.git] / vid-automation / src / main / java / vid / automation / test / test / ViewEditServiceInstanceTest.java
1 package vid.automation.test.test;
2
3 import com.google.common.collect.ImmutableMap;
4 import org.hamcrest.MatcherAssert;
5 import org.junit.Assert;
6 import org.junit.Before;
7 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetNetworkCollectionDetails;
8 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
9 import org.openqa.selenium.By;
10 import org.openqa.selenium.WebElement;
11 import org.testng.annotations.AfterMethod;
12 import org.testng.annotations.DataProvider;
13 import org.testng.annotations.Test;
14 import vid.automation.test.Constants;
15 import vid.automation.test.infra.*;
16 import vid.automation.test.model.User;
17 import vid.automation.test.sections.VidBasePage;
18 import vid.automation.test.sections.ViewEditPage;
19 import vid.automation.test.services.BulkRegistration;
20 import vid.automation.test.services.SimulatorApi;
21
22 import java.text.ParseException;
23 import java.text.SimpleDateFormat;
24 import java.time.LocalDate;
25 import java.util.Arrays;
26 import java.util.List;
27 import java.util.Map;
28 import java.util.regex.Matcher;
29 import java.util.regex.Pattern;
30
31 import static org.hamcrest.Matchers.equalTo;
32 import static org.testng.AssertJUnit.assertEquals;
33 import static vid.automation.test.infra.Features.FLAG_COLLECTION_RESOURCE_SUPPORT;
34 import static vid.automation.test.services.SimulatorApi.RegistrationStrategy.APPEND;
35
36 public class ViewEditServiceInstanceTest extends VidBaseTestCase {
37
38     private ViewEditPage viewEditPage = new ViewEditPage();
39     VidBasePage vidBasePage =new VidBasePage();
40     private String serviceInstanceId = "3f93c7cb-2fd0-4557-9514-e189b7b04f9d";
41     private String crServiceInstanceId = "3f93c7cb-2fd0-4557-9514-e189b7testCR";
42     private  String serviceInstanceId2 ="c187e9fe-40c3-4862-b73e-84ff056205f6";
43     private final String DEACTIVATE_ACTION = "deactivate";
44     private final String ACTIVATE_ACTION = "activate";
45     private List<String> pnfs = Arrays.asList("SANITY6785cce9", "tesai371ve2");
46     private final String serviceInstanceIdeWithoutModelVerId ="9caf5581-40ab-47be-b1f1-909a87724add";
47     private final String crNetworkText ="NETWORK INSTANCE GROUP: l3network-id-rs804s | ROLE: HngwProtectedOam.OAM | TYPE: Tenant_Layer_3 | # OF NETWORKS: 3";
48     private final String crCollectionText ="COLLECTION: collection-name | TYPE: L3-NETWORK";
49     private final String crInfoText = "\"requestState\": \"COMPLETE\"";
50     SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss");
51     static final String LCP_REGION = "mtn6";
52     static final String TENANT = "bae71557c5bb4d5aac6743a4e5f1d054";
53
54
55     ///////////////////////////////////////////////
56     /// Activate / Deactivate service instance ///
57     //////////////////////////////////////////////
58
59     @FeatureTogglingTest(value = FLAG_COLLECTION_RESOURCE_SUPPORT)
60     @Test
61     public void testViewEditCRServiceInstance()throws Exception {
62         SimulatorApi.clearAll();
63         BulkRegistration.searchExistingCRServiceInstance("Created");
64         BulkRegistration.activateServiceInstance(ACTIVATE_ACTION);
65         final PresetAAIGetNetworkCollectionDetails presetAAIGetNetworkCollectionDetails = new PresetAAIGetNetworkCollectionDetails(crServiceInstanceId);
66         SimulatorApi.registerExpectationFromPreset(presetAAIGetNetworkCollectionDetails, APPEND);
67         goToExistingInstanceById(crServiceInstanceId);
68         WebElement webElement = Get.byTestId(Constants.ViewEdit.COLLECTIONDIV);
69         Assert.assertNotNull(webElement);
70         Assert.assertEquals(webElement.getText(), crCollectionText);
71         webElement = Get.byTestId(Constants.ViewEdit.COLLECTIONNETWORKDIV);
72         Assert.assertNotNull(webElement);
73         Assert.assertEquals(webElement.getText(), crNetworkText);
74         viewEditPage.clickInfoButton();
75         webElement = Get.byTestId(Constants.ViewEdit.SERVICE_INSTANCE_ID);
76         Assert.assertEquals(webElement.getText(), crServiceInstanceId);
77         webElement = Get.byTestId(Constants.ViewEdit.DETAILS_LOG);
78         Assert.assertTrue(webElement.getText().contains(crInfoText));
79         webElement = Get.byTestId(Constants.ViewEdit.DETAILS_CLOSE_BTN);
80         webElement.click();
81         viewEditPage.clickDeleteButton();
82     }
83
84     private void deleteInstance(String deleteButtonId, String successMessage) {
85         navigateToViewEditPageOfuspVoiceVidTest444("7a6ee536-f052-46fa-aa7e-2fca9d674c44");
86         Click.byTestId(deleteButtonId);
87         viewEditPage.selectLCPRegion(LCP_REGION);
88         viewEditPage.selectTenant(TENANT);
89         vidBasePage.clickConfirmButtonInResumeDelete();
90         viewEditPage.assertMsoRequestModal(successMessage);
91         viewEditPage.clickCommitCloseButton();
92         GeneralUIUtils.ultimateWait();
93     }
94
95     @Test
96     public void deleteVolumeGroupInstance_deleteDialogAppears_msoResponseIsOk() {
97         SimulatorApi.clearAll();
98         BulkRegistration.deleteExistingVolumeGroupInstance("CREATED");
99         deleteInstance(Constants.ViewEdit.DELETE_VNF_VOLUME_GROUP_BUTTON_TEST_ID, Constants.ViewEdit.VOLUME_GROUP_DELETED_SUCCESSFULLY_TEXT);
100     }
101
102     @Test
103     public void deleteVfModuleInstance_deleteDialogAppears_msoResponseIsOk() {
104         SimulatorApi.clearAll();
105         BulkRegistration.deleteExistingVfModuleInstance("CREATED");
106         deleteInstance(Constants.ViewEdit.DELETE_VF_MODULE_BUTTON_TEST_ID + "aa", Constants.ViewEdit.VF_MODULE_DELETED_SUCCESSFULLY_TEXT);
107     }
108
109     @Test
110     public void deleteNetworkInstance_deleteDialogAppears_msoResponseIsOk() {
111         SimulatorApi.clearAll();
112         BulkRegistration.deleteExistingNetworkInstance("CREATED");
113         deleteInstance(Constants.ViewEdit.DELETE_NETWORK_BUTTON_TEST_ID, Constants.ViewEdit.VL_DELETED_SUCCESSFULLY_TEXT);
114     }
115
116     @Test
117     public void deleteVnfInstance_deleteDialogAppears_msoResponseIsOk() {
118         SimulatorApi.clearAll();
119         BulkRegistration.deleteExistingVnfInstance("CREATED");
120         deleteInstance(Constants.ViewEdit.DELETE_VNF_BUTTON_TEST_ID,Constants.ViewEdit.VNF_DELETED_SUCCESSFULLY_TEXT);
121     }
122
123     @Test
124     public void deleteServiceInstance_deleteDialogAppears_msoResponseIsOk() {
125         SimulatorApi.clearAll();
126         BulkRegistration.deleteExistingServiceInstance("ACTIVE");
127         navigateToViewEditPageOfuspVoiceVidTest444("7a6ee536-f052-46fa-aa7e-2fca9d674c44");
128         viewEditPage.clickDeleteButton();
129         vidBasePage.clickConfirmButtonInResumeDelete();
130         viewEditPage.assertMsoRequestModal(Constants.ViewEdit.SERVICE_DELETED_SUCCESSFULLY_TEXT);
131         viewEditPage.clickCommitCloseButton();
132         GeneralUIUtils.ultimateWait();
133     }
134
135     @Test(dataProvider = "serviceStatusesAndExpectedResults")
136     public void testActivateServiceInstanceTransportType(String orchStatus) {
137         SimulatorApi.clearAll();
138         BulkRegistration.searchExistingServiceInstance(orchStatus);
139         BulkRegistration.activateServiceInstance(ACTIVATE_ACTION);
140         goToExistingInstanceById(serviceInstanceId);
141         viewEditPage.assertButtonState(Constants.ViewEdit.ACTIVATE_BUTTON_TEST_ID, true);
142         viewEditPage.assertButtonState(Constants.ViewEdit.DEACTIVATE_BUTTON_TEST_ID,false);
143         assertResumeButtonVisibility(false, false);
144         assertAndCheckShowAssignmentsSdncUrl(orchStatus, serviceInstanceId);
145         viewEditPage.clickActivateButton();
146         viewEditPage.assertMsoRequestModal(Constants.ViewEdit.MSO_SUCCESSFULLY_TEXT);
147         viewEditPage.clickCloseButton();
148     }
149
150     private void assertAndCheckShowAssignmentsSdncUrl(String orchStatus, String serviceInstanceId) {
151         boolean buttonIsEnable = Features.FLAG_SHOW_ASSIGNMENTS.isActive() && orchStatus.equals("assiGNed");
152         viewEditPage.assertButtonState(Constants.ViewEdit.SHOW_ASSIGNMENTS_BUTTON_TEST_ID, buttonIsEnable);
153         if (buttonIsEnable)  {
154             WebElement webElement = Get.byTestId(Constants.ViewEdit.SHOW_ASSIGNMENTS_BUTTON_TEST_ID);
155             String expectedUrl = "https://mtanjv9sdma51.aic.cip.att.com:8448/configAdapter/index#/resource_manager/"+serviceInstanceId;
156             MatcherAssert.assertThat("Show assignments SDNC url is wrong",
157                     webElement.getAttribute("href"), equalTo(expectedUrl));
158         }
159
160     }
161
162     @DataProvider
163     public static Object[][] serviceStatusesAndExpectedResults() {
164         return new Object[][] {
165                 { "Created" },
166                 {"pendingdeLete" },
167                 {"pending-deLete" },
168                 {"assiGNed" }
169         };
170     }
171
172     @Test
173     public void testDeactivateServiceInstanceNotTransportType()throws Exception {
174         SimulatorApi.clearAll();
175         BulkRegistration.searchExistingServiceInstancePortMirroring("Active", "mdt1");
176         goToExistingInstanceById(serviceInstanceId2);
177         viewEditPage.assertButtonState(Constants.ViewEdit.ACTIVATE_BUTTON_TEST_ID, false);
178         viewEditPage.assertButtonState(Constants.ViewEdit.DEACTIVATE_BUTTON_TEST_ID, true);
179     }
180
181     @Test
182     public void testActivateServiceInstanceNotTransportType()throws Exception {
183         SimulatorApi.clearAll();
184         BulkRegistration.searchExistingServiceInstancePortMirroring("Created", "mdt1");
185         goToExistingInstanceById(serviceInstanceId2);
186         viewEditPage.assertButtonState(Constants.ViewEdit.ACTIVATE_BUTTON_TEST_ID, true);
187         viewEditPage.assertButtonState(Constants.ViewEdit.DEACTIVATE_BUTTON_TEST_ID, false);
188     }
189
190     @Test
191     public void testActivateServiceInstanceError()throws Exception {
192         SimulatorApi.clearAll();
193         BulkRegistration.searchExistingServiceInstance("Created");
194         BulkRegistration.activateServiceInstanceError(ACTIVATE_ACTION);
195         goToExistingInstanceById(serviceInstanceId);
196         viewEditPage.assertButtonState(Constants.ViewEdit.ACTIVATE_BUTTON_TEST_ID,true);
197         viewEditPage.assertButtonState(Constants.ViewEdit.DEACTIVATE_BUTTON_TEST_ID,false);
198         viewEditPage.clickActivateButton();
199         viewEditPage.assertMsoRequestModal("Error");
200         viewEditPage.clickCloseButton();
201     }
202
203     @Test
204     public void testDeactivateServiceInstance(){
205         SimulatorApi.clearAll();
206         BulkRegistration.searchExistingServiceInstance("Active");
207         BulkRegistration.activateServiceInstance(DEACTIVATE_ACTION);
208         goToExistingInstanceById(serviceInstanceId);
209         viewEditPage.assertButtonState(Constants.ViewEdit.DEACTIVATE_BUTTON_TEST_ID,true);
210         viewEditPage.assertButtonState(Constants.ViewEdit.ACTIVATE_BUTTON_TEST_ID,false);
211         assertResumeButtonVisibility(true, true);
212         viewEditPage.clickDeactivateButton();
213         viewEditPage.assertMsoRequestModal(Constants.ViewEdit.MSO_SUCCESSFULLY_TEXT);
214         SimulatorApi.clearAll();
215         BulkRegistration.searchExistingServiceInstance("PendingDelete");
216         BulkRegistration.activateServiceInstance(ACTIVATE_ACTION);
217         viewEditPage.clickCloseButton();
218         GeneralUIUtils.findAndWaitByText(serviceInstanceId, 30); //kind of "ultimate wait" for refresh to complete
219         viewEditPage.assertButtonState(Constants.ViewEdit.ACTIVATE_BUTTON_TEST_ID,true);
220         viewEditPage.assertButtonState(Constants.ViewEdit.DEACTIVATE_BUTTON_TEST_ID,false);
221     }
222
223     @Test
224     public void testDeactivateServiceInstanceError()throws Exception {
225         SimulatorApi.clearAll();
226         BulkRegistration.searchExistingServiceInstance("Active");
227         BulkRegistration.activateServiceInstanceError(DEACTIVATE_ACTION);
228         goToExistingInstanceById(serviceInstanceId);
229         viewEditPage.assertButtonState(Constants.ViewEdit.ACTIVATE_BUTTON_TEST_ID,false);
230         viewEditPage.assertButtonState(Constants.ViewEdit.DEACTIVATE_BUTTON_TEST_ID,true);
231         viewEditPage.clickDeactivateButton();
232         viewEditPage.assertMsoRequestModal("Error");
233         viewEditPage.clickCloseButton();
234     }
235
236     @Test
237     public void testTimestampOnDeactivateAndInfoServiceInstance() throws ParseException {
238         SimulatorApi.clearAll();
239         BulkRegistration.searchExistingServiceInstance("Active");
240         BulkRegistration.activateServiceInstance(DEACTIVATE_ACTION);
241         SimulatorApi.registerExpectation(
242                 Constants.RegisterToSimulator.SearchForServiceInstance.GET_MSO_INSTANCE_ORCH_STATUS_REQ,
243                 ImmutableMap.<String, Object>of("<SERVICE_INSTANCE_ID>", "3f93c7cb-2fd0-4557-9514-e189b7b04f9d"),
244                 SimulatorApi.RegistrationStrategy.APPEND);
245         goToExistingInstanceById(serviceInstanceId);
246         Click.byClass("service-info");
247         GeneralUIUtils.ultimateWait();
248         assertEquals("Timestamp isn't the finished time", getTimeatampValue(Constants.ViewEdit.DETAILS_LOG), "Tue, 24 Oct 2017 02:28:39");
249         viewEditPage.clickCloseButton();
250         viewEditPage.clickDeactivateButton();
251         GeneralUIUtils.ultimateWait();
252         try {
253             dateFormat.parse(getTimeatampValue(Constants.ViewEdit.MSO_COMMIT_LOG));
254         } catch (ParseException e) {
255             System.err.println("Timestamp isn't a date");
256             throw e;
257         }
258         viewEditPage.clickCloseButton();
259     }
260
261     private String getTimeatampValue(String dataTestsId) {
262         String logText = Get.byTestId(dataTestsId).getText();
263         Matcher matcher = Pattern.compile("\"timestamp\": \"(.*?)\"").matcher(logText);
264         matcher.find();
265         return matcher.group(1);
266     }
267
268
269     /////////////////////////////////////////////
270     /// Dissociate pnf from service instance ///
271     ////////////////////////////////////////////
272
273     @Test
274     public void testGetAssociatedPnfsForServiceInstance() {
275         SimulatorApi.clearAll();
276         BulkRegistration.searchExistingServiceInstance();
277         BulkRegistration.getAssociatedPnfs();
278
279         goToExistingInstanceById(serviceInstanceId);
280         for (String pnf: pnfs) {
281             viewEditPage.getPnf(pnf);
282         }
283     }
284
285     @Test
286     public void testPnfsNotExistForServiceInstance() {
287         SimulatorApi.clearAll();
288         BulkRegistration.searchExistingServiceInstance();
289
290         goToExistingInstanceById(serviceInstanceId);
291         assertNoPnfExists();
292     }
293
294      @Test
295     public void testSuccessDissociatePnfFromServiceInstance() throws Exception {
296         SimulatorApi.clearAll();
297         BulkRegistration.searchExistingServiceInstance();
298         BulkRegistration.getAssociatedPnfs();
299         BulkRegistration.dissociatePnf();
300         goToExistingInstanceById(serviceInstanceId);
301         dissociatePnf(pnfs.get(0)); //SANITY6785cce9
302         viewEditPage.assertMsoRequestModal(Constants.ViewEdit.MSO_SUCCESSFULLY_TEXT);
303         viewEditPage.clickCloseButton();
304     }
305
306     @Test
307     public void testFailDissociatePnfFromServiceInstance() throws Exception {
308         SimulatorApi.clearAll();
309         BulkRegistration.searchExistingServiceInstance();
310         BulkRegistration.getAssociatedPnfs();
311         SimulatorApi.registerExpectation(Constants.RegisterToSimulator.pProbe.REMOVE_PNF_RELATIONSHIP_ERROR, SimulatorApi.RegistrationStrategy.APPEND);
312
313         if (LocalDate.now().isBefore(LocalDate.parse("2018-06-04"))) return; // skip few days to see green build
314         goToExistingInstanceById(serviceInstanceId);
315         dissociatePnf(pnfs.get(0)); //SANITY6785cce9
316         viewEditPage.assertMsoRequestModal("Error");
317         GeneralUIUtils.ultimateWait();
318         viewEditPage.clickCloseButton();
319     }
320
321
322     private void assertNoPnfExists() {
323         WebElement pnfElement = Get.byClassAndText("tree-node", "PNF: ");
324         Assert.assertNull("Pnf found under service instance", pnfElement);
325     }
326
327     private void dissociatePnf(String pnfName) throws InterruptedException {
328         viewEditPage.clickDissociatePnfButton(pnfName);
329         assertDissociateConfirmModal(pnfName);
330     }
331
332     private void assertDissociateConfirmModal(String pnfName) {
333         Wait.modalToBeDisplayed();
334         Assert.assertTrue(Exists.modal());
335         Assert.assertTrue(Exists.byCssSelectorAndText(".modal-body span", String.format(Constants.ViewEdit.DISSOCIATE_CONFIRM_MODAL_TEXT, pnfName)));
336         WebElement confirmBtn = Get.byId(Constants.ViewEdit.DISSOCIATE_CONFIRM_MODAL_BTN_ID);
337         Assert.assertNotNull(confirmBtn);
338         confirmBtn.click();
339 //        Wait.modalToDisappear();
340     }
341
342     @Test
343     public void testErrorMsgNoModelVerIdFromAai() throws Exception {
344         getExtendTest().info("from Bug 480129,this test check the error case, while model version Id not supplied from A&AI");
345         SimulatorApi.clearAll();
346         BulkRegistration.genericSearchExistingServiceInstance();
347         BulkRegistration.searchExistingServiceInstanceWithoutModelVerId();
348         goToExistingInstanceByIdNoWait(serviceInstanceIdeWithoutModelVerId);
349         viewEditPage.checkAndCloseAlert(Constants.ViewEdit.MODEL_VERSION_ID_MISSING_MSG);
350         String errMsg= viewEditPage.getTextByTestID(Constants.ViewEdit.SUBDETAILS_ERROR_MESSAGE_TEST_ID);
351         Assert.assertEquals(Constants.ViewEdit.MODEL_VERSION_ID_MISSING_MSG, errMsg);
352     }
353
354     private void assertResumeButtonVisibility(boolean pendingActivationResumeVisible, boolean assignedResumeVisible) {
355         ImmutableMap<String, Boolean> vfModulesStatuses = ImmutableMap.of(
356                 "pendingactivation", pendingActivationResumeVisible,
357                 "assigned", assignedResumeVisible,
358                 "pending-delete", false);
359         for(Map.Entry<String, Boolean> entry: vfModulesStatuses.entrySet()) {
360             WebElement vfModule = GeneralUIUtils.getWebElementByClassName("vfModuleTreeNode-" + entry.getKey());
361             Assert.assertEquals(!vfModule.findElements(By.className("resume")).isEmpty(), entry.getValue());
362         }
363     }
364
365     @Before
366     public void before() throws Exception {
367         User user = usersService.getUser(Constants.Users.USP_VOICE_VIRTUAL_USP);
368         relogin(user.credentials);
369     }
370
371     @AfterMethod(alwaysRun = true)
372     public void finallyClosePopup() {
373         // Tries closing left-out popups, if any
374         // If none -- catch clause will swallow the exception
375         try {
376             viewEditPage.clickCloseButton(3);
377         } catch (Exception e) {
378             // ok, stop
379         }
380     }
381 }