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