1 package vid.automation.test.test;
3 import static org.apache.logging.log4j.core.util.Assert.isNonEmpty;
4 import static org.hamcrest.CoreMatchers.is;
5 import static org.hamcrest.MatcherAssert.assertThat;
6 import static org.hamcrest.Matchers.equalTo;
7 import static org.hamcrest.collection.IsEmptyCollection.empty;
8 import static org.testng.AssertJUnit.assertEquals;
9 import static vid.automation.test.infra.Features.FLAG_1810_CR_SOFT_DELETE_ALACARTE_VF_MODULE;
10 import static vid.automation.test.infra.Features.FLAG_COLLECTION_RESOURCE_SUPPORT;
11 import static vid.automation.test.services.SimulatorApi.RegistrationStrategy.APPEND;
13 import com.google.common.collect.ImmutableMap;
14 import java.text.ParseException;
15 import java.text.SimpleDateFormat;
16 import java.time.LocalDate;
17 import java.util.Arrays;
18 import java.util.List;
20 import java.util.regex.Matcher;
21 import java.util.regex.Pattern;
22 import org.hamcrest.MatcherAssert;
23 import org.junit.Assert;
24 import org.junit.Before;
25 import org.onap.sdc.ci.tests.utilities.GeneralUIUtils;
26 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetNetworkCollectionDetails;
27 import org.openqa.selenium.By;
28 import org.openqa.selenium.WebElement;
29 import org.testng.annotations.AfterMethod;
30 import org.testng.annotations.DataProvider;
31 import org.testng.annotations.Test;
32 import vid.automation.test.Constants;
33 import vid.automation.test.infra.Click;
34 import vid.automation.test.infra.Exists;
35 import vid.automation.test.infra.FeatureTogglingTest;
36 import vid.automation.test.infra.Features;
37 import vid.automation.test.infra.Get;
38 import vid.automation.test.infra.Wait;
39 import vid.automation.test.model.User;
40 import vid.automation.test.sections.VidBasePage;
41 import vid.automation.test.sections.ViewEditPage;
42 import vid.automation.test.services.BulkRegistration;
43 import vid.automation.test.services.SimulatorApi;
45 public class ViewEditServiceInstanceTest extends VidBaseTestCase {
47 private ViewEditPage viewEditPage = new ViewEditPage();
48 VidBasePage vidBasePage =new VidBasePage();
49 private String serviceInstanceId = "3f93c7cb-2fd0-4557-9514-e189b7b04f9d";
50 private String crServiceInstanceId = "3f93c7cb-2fd0-4557-9514-e189b7testCR";
51 private String serviceFabricInstanceId = "c187e9fe-40c3-4862-b73e-84ff056205f61234";
52 private String serviceInstanceId2 ="c187e9fe-40c3-4862-b73e-84ff056205f6";
53 private final String DEACTIVATE_ACTION = "deactivate";
54 private final String ACTIVATE_ACTION = "activate";
55 private List<String> pnfs = Arrays.asList("SANITY6785cce9", "tesai371ve2");
56 private final String serviceInstanceIdeWithoutModelVerId ="9caf5581-40ab-47be-b1f1-909a87724add";
57 private final String crNetworkText ="NETWORK INSTANCE GROUP: l3network-id-rs804s | ROLE: RosemaProtectedOam.OAM | TYPE: Tenant_Layer_3 | # OF NETWORKS: 3";
58 private final String crCollectionText ="COLLECTION: collection-name | TYPE: L3-NETWORK";
59 private final String crInfoText = "\"requestState\": \"COMPLETE\"";
60 SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss");
61 static final String LCP_REGION = "hvf6";
62 static final String CLOUD_OWNER = "AIC";
63 static final String TENANT = "bae71557c5bb4d5aac6743a4e5f1d054";
66 ///////////////////////////////////////////////
67 /// Activate / Deactivate service instance ///
68 //////////////////////////////////////////////
70 @FeatureTogglingTest(value = FLAG_COLLECTION_RESOURCE_SUPPORT)
72 public void testViewEditCRServiceInstance()throws Exception {
73 SimulatorApi.clearAll();
74 BulkRegistration.searchExistingCRServiceInstance("Created");
75 BulkRegistration.activateServiceInstance(ACTIVATE_ACTION);
76 final PresetAAIGetNetworkCollectionDetails presetAAIGetNetworkCollectionDetails = new PresetAAIGetNetworkCollectionDetails(crServiceInstanceId);
77 SimulatorApi.registerExpectationFromPreset(presetAAIGetNetworkCollectionDetails, APPEND);
78 goToExistingInstanceById(crServiceInstanceId);
79 WebElement webElement = Get.byTestId(Constants.ViewEdit.COLLECTIONDIV);
80 Assert.assertNotNull(webElement);
81 Assert.assertEquals(webElement.getText(), crCollectionText);
82 webElement = Get.byTestId(Constants.ViewEdit.COLLECTIONNETWORKDIV);
83 Assert.assertNotNull(webElement);
84 Assert.assertEquals(webElement.getText(), crNetworkText);
85 viewEditPage.clickInfoButton();
86 webElement = Get.byTestId(Constants.ViewEdit.SERVICE_INSTANCE_ID);
87 Assert.assertEquals(webElement.getText(), crServiceInstanceId);
88 webElement = Get.byTestId(Constants.ViewEdit.DETAILS_LOG);
89 Assert.assertTrue(webElement.getText().contains(crInfoText));
90 webElement = Get.byTestId(Constants.ViewEdit.DETAILS_CLOSE_BTN);
92 viewEditPage.clickDeleteButton();
94 private void deleteInstance(String deleteButtonId, String successMessage) {
95 deleteInstance(deleteButtonId, successMessage, Constants.CONFIRM_RESUME_DELETE_TESTS_ID);
98 private void deleteInstance(String deleteButtonId, String successMessage, String confirmButtonId) {
99 navigateToViewEditPageOfuspVoiceVidTest444("7a6ee536-f052-46fa-aa7e-2fca9d674c44");
100 Click.byTestId(deleteButtonId);
101 viewEditPage.selectLcpRegion(LCP_REGION, CLOUD_OWNER);
102 viewEditPage.selectTenant(TENANT);
103 vidBasePage.clickButtonByTestId(confirmButtonId);
104 viewEditPage.assertMsoRequestModal(successMessage);
105 viewEditPage.clickCommitCloseButton();
106 GeneralUIUtils.ultimateWait();
110 public void deleteVolumeGroupInstance_deleteDialogAppears_msoResponseIsOk() {
111 SimulatorApi.clearAll();
112 BulkRegistration.deleteExistingVolumeGroupInstance("CREATED");
113 deleteInstance(Constants.ViewEdit.DELETE_VNF_VOLUME_GROUP_BUTTON_TEST_ID, Constants.ViewEdit.VOLUME_GROUP_DELETED_SUCCESSFULLY_TEXT);
117 public void deleteVfModuleInstance_deleteDialogAppears_msoResponseIsOk() {
118 SimulatorApi.clearAll();
119 BulkRegistration.deleteExistingVfModuleInstance("CREATED");
120 deleteInstance(Constants.ViewEdit.DELETE_VF_MODULE_BUTTON_TEST_ID + "aa", Constants.ViewEdit.VF_MODULE_DELETED_SUCCESSFULLY_TEXT);
123 @FeatureTogglingTest(value = FLAG_1810_CR_SOFT_DELETE_ALACARTE_VF_MODULE)
125 public void softDeleteAndResumeVfModuleInstance_deleteDialogAppears_msoResponseIsOk() {
126 SimulatorApi.clearAll();
127 String vfModuleName = "my_vfModule";
128 BulkRegistration.deleteExistingVfModuleInstance("ACTIVE");
129 deleteInstance(Constants.ViewEdit.DELETE_VF_MODULE_BUTTON_TEST_ID + vfModuleName, Constants.ViewEdit.VF_MODULE_DELETED_SUCCESSFULLY_TEXT, Constants.SOFT_DELETE_TESTS_ID);
130 BulkRegistration.resumeWithHomingDataVfModule("ACTIVE", "Assigned", vfModuleName);
131 navigateToViewEditPageOfuspVoiceVidTest444("7a6ee536-f052-46fa-aa7e-2fca9d674c44");
132 viewEditPage.clickResumeButton(vfModuleName);
133 assertThat("Select lcp region shouldn't be display when homing data is presented",
134 GeneralUIUtils.getDriver().findElements(Get.getXpathForDataTestId(Constants.ViewEdit.LCP_REGION_SELECT_TESTS_ID)),
136 assertThat("Select tenant shouldn't be display when homing data is presented",
137 GeneralUIUtils.getDriver().findElements(Get.getXpathForDataTestId(Constants.ViewEdit.TENANT_SELECT_TESTS_ID)),
139 viewEditPage.clickConfirmButtonInResumeDelete();
140 assertSuccessfulVFModuleCreation();
141 viewEditPage.clickCommitCloseButton();
142 GeneralUIUtils.ultimateWait();
146 public void deleteNetworkInstance_deleteDialogAppears_msoResponseIsOk() {
147 SimulatorApi.clearAll();
148 BulkRegistration.deleteExistingNetworkInstance("CREATED");
149 deleteInstance(Constants.ViewEdit.DELETE_NETWORK_BUTTON_TEST_ID, Constants.ViewEdit.VL_DELETED_SUCCESSFULLY_TEXT);
153 public void deleteVnfInstance_deleteDialogAppears_msoResponseIsOk() {
154 SimulatorApi.clearAll();
155 BulkRegistration.deleteExistingVnfInstance("CREATED");
156 deleteInstance(Constants.ViewEdit.DELETE_VNF_BUTTON_TEST_ID,Constants.ViewEdit.VNF_DELETED_SUCCESSFULLY_TEXT);
160 public void deleteServiceInstance_deleteDialogAppears_msoResponseIsOk() {
161 SimulatorApi.clearAll();
162 BulkRegistration.deleteExistingServiceInstance("ACTIVE");
163 navigateToViewEditPageOfuspVoiceVidTest444("7a6ee536-f052-46fa-aa7e-2fca9d674c44");
164 viewEditPage.clickDeleteButton();
165 vidBasePage.clickConfirmButtonInResumeDelete();
166 viewEditPage.assertMsoRequestModal(Constants.ViewEdit.SERVICE_DELETED_SUCCESSFULLY_TEXT);
167 viewEditPage.clickCommitCloseButton();
168 GeneralUIUtils.ultimateWait();
171 @Test(dataProvider = "serviceStatusesAndExpectedResults")
172 public void testActivateServiceInstanceTransportType(String orchStatus) {
173 SimulatorApi.clearAll();
174 BulkRegistration.searchExistingServiceInstance(orchStatus);
175 BulkRegistration.activateServiceInstance(ACTIVATE_ACTION);
176 goToExistingInstanceById(serviceInstanceId);
177 viewEditPage.assertButtonState(Constants.ViewEdit.ACTIVATE_BUTTON_TEST_ID, true);
178 viewEditPage.assertButtonState(Constants.ViewEdit.DEACTIVATE_BUTTON_TEST_ID,false);
179 assertResumeButtonVisibility(false, false);
180 assertAndCheckShowAssignmentsSdncUrl(orchStatus, serviceInstanceId);
181 viewEditPage.clickActivateButton();
182 viewEditPage.assertMsoRequestModal(Constants.ViewEdit.MSO_SUCCESSFULLY_TEXT);
183 viewEditPage.clickCloseButton();
187 public void testActivateServiceInstanceWithFabric() {
188 String orchStatus = "assiGNed";
189 SimulatorApi.clearAll();
190 BulkRegistration.searchExistingServiceInstanceWithFabric(orchStatus);
191 goToExistingInstanceById(serviceFabricInstanceId);
192 viewEditPage.assertButtonState(Constants.ViewEdit.DEACTIVATE_BUTTON_TEST_ID,false);
193 boolean flagIsActive = Features.FLAG_FABRIC_CONFIGURATION_ASSIGNMENTS.isActive();
195 viewEditPage.assertButtonState(Constants.ViewEdit.ACTIVATE_FABRIC_CONFIGURATION_BUTTON_TEST_ID, true);
196 viewEditPage.clickActivateFabricConfigurationButton();
197 viewEditPage.assertMsoRequestModal(Constants.ViewEdit.MSO_SUCCESSFULLY_TEXT);
198 viewEditPage.clickCloseButton();
202 private void assertAndCheckShowAssignmentsSdncUrl(String orchStatus, String serviceInstanceId) {
203 boolean buttonIsEnable = Features.FLAG_SHOW_ASSIGNMENTS.isActive() && orchStatus.equals("assiGNed");
204 boolean isNotDisplay = GeneralUIUtils.getDriver().findElements(Get.getXpathForDataTestId(Constants.ViewEdit.SHOW_ASSIGNMENTS_BUTTON_TEST_ID)).isEmpty();
205 Assert.assertNotEquals(isNotDisplay, buttonIsEnable);
207 if (buttonIsEnable) {
208 WebElement webElement = Get.byTestId(Constants.ViewEdit.SHOW_ASSIGNMENTS_BUTTON_TEST_ID);
209 String expectedUrl = "https://mtan.onap.org:8448/configAdapter/index#/resource_manager/"+serviceInstanceId;
210 MatcherAssert.assertThat("Show assignments SDNC url is wrong",
211 webElement.getAttribute("href"), equalTo(expectedUrl));
217 public static Object[][] serviceStatusesAndExpectedResults() {
218 return new Object[][] {
227 public void testDeactivateServiceInstanceNotTransportType()throws Exception {
228 SimulatorApi.clearAll();
229 BulkRegistration.searchExistingServiceInstancePortMirroring("Active", "mdt1");
230 goToExistingInstanceById(serviceInstanceId2);
231 viewEditPage.assertButtonState(Constants.ViewEdit.ACTIVATE_BUTTON_TEST_ID, false);
232 viewEditPage.assertButtonState(Constants.ViewEdit.DEACTIVATE_BUTTON_TEST_ID, true);
236 public void testActivateServiceInstanceNotTransportType()throws Exception {
237 SimulatorApi.clearAll();
238 BulkRegistration.searchExistingServiceInstancePortMirroring("Created", "mdt1");
239 goToExistingInstanceById(serviceInstanceId2);
240 viewEditPage.assertButtonState(Constants.ViewEdit.ACTIVATE_BUTTON_TEST_ID, true);
241 viewEditPage.assertButtonState(Constants.ViewEdit.DEACTIVATE_BUTTON_TEST_ID, false);
245 public void testActivateServiceInstanceError()throws Exception {
246 SimulatorApi.clearAll();
247 BulkRegistration.searchExistingServiceInstance("Created");
248 BulkRegistration.activateServiceInstanceError(ACTIVATE_ACTION);
249 goToExistingInstanceById(serviceInstanceId);
250 viewEditPage.assertButtonState(Constants.ViewEdit.ACTIVATE_BUTTON_TEST_ID,true);
251 viewEditPage.assertButtonState(Constants.ViewEdit.DEACTIVATE_BUTTON_TEST_ID,false);
252 viewEditPage.clickActivateButton();
253 viewEditPage.assertMsoRequestModal("Error");
254 viewEditPage.clickCloseButton();
258 public void testDeactivateServiceInstance(){
259 SimulatorApi.clearAll();
260 BulkRegistration.searchExistingServiceInstance("Active");
261 BulkRegistration.activateServiceInstance(DEACTIVATE_ACTION);
262 goToExistingInstanceById(serviceInstanceId);
263 viewEditPage.assertButtonState(Constants.ViewEdit.DEACTIVATE_BUTTON_TEST_ID,true);
264 viewEditPage.assertButtonState(Constants.ViewEdit.ACTIVATE_BUTTON_TEST_ID,false);
265 assertResumeButtonVisibility(true, true);
266 viewEditPage.clickDeactivateButton();
267 viewEditPage.assertMsoRequestModal(Constants.ViewEdit.MSO_SUCCESSFULLY_TEXT);
268 SimulatorApi.clearAll();
269 BulkRegistration.searchExistingServiceInstance("PendingDelete");
270 BulkRegistration.activateServiceInstance(ACTIVATE_ACTION);
271 viewEditPage.clickCloseButton();
272 GeneralUIUtils.findAndWaitByText(serviceInstanceId, 30); //kind of "ultimate wait" for refresh to complete
273 viewEditPage.assertButtonState(Constants.ViewEdit.ACTIVATE_BUTTON_TEST_ID,true);
274 viewEditPage.assertButtonState(Constants.ViewEdit.DEACTIVATE_BUTTON_TEST_ID,false);
278 public void testDeactivateServiceInstanceError()throws Exception {
279 SimulatorApi.clearAll();
280 BulkRegistration.searchExistingServiceInstance("Active");
281 BulkRegistration.activateServiceInstanceError(DEACTIVATE_ACTION);
282 goToExistingInstanceById(serviceInstanceId);
283 viewEditPage.assertButtonState(Constants.ViewEdit.ACTIVATE_BUTTON_TEST_ID,false);
284 viewEditPage.assertButtonState(Constants.ViewEdit.DEACTIVATE_BUTTON_TEST_ID,true);
285 viewEditPage.clickDeactivateButton();
286 viewEditPage.assertMsoRequestModal("Error");
287 viewEditPage.clickCloseButton();
291 public void testTimestampOnDeactivateAndInfoServiceInstance() throws ParseException {
292 SimulatorApi.clearAll();
293 BulkRegistration.searchExistingServiceInstance("Active");
294 BulkRegistration.activateServiceInstance(DEACTIVATE_ACTION);
295 SimulatorApi.registerExpectation(
296 Constants.RegisterToSimulator.SearchForServiceInstance.GET_MSO_INSTANCE_ORCH_STATUS_REQ,
297 ImmutableMap.<String, Object>of("<SERVICE_INSTANCE_ID>", "3f93c7cb-2fd0-4557-9514-e189b7b04f9d"),
298 SimulatorApi.RegistrationStrategy.APPEND);
299 goToExistingInstanceById(serviceInstanceId);
300 Click.byClass("service-info");
301 GeneralUIUtils.ultimateWait();
302 assertEquals("Timestamp isn't the finished time", getTimeatampValue(Constants.ViewEdit.DETAILS_LOG), "Tue, 24 Oct 2017 02:28:39");
303 viewEditPage.clickCloseButton();
304 viewEditPage.clickDeactivateButton();
305 GeneralUIUtils.ultimateWait();
307 dateFormat.parse(getTimeatampValue(Constants.ViewEdit.MSO_COMMIT_LOG));
308 } catch (ParseException e) {
309 System.err.println("Timestamp isn't a date");
312 viewEditPage.clickCloseButton();
315 private String getTimeatampValue(String dataTestsId) {
316 String logText = Get.byTestId(dataTestsId).getText();
317 Matcher matcher = Pattern.compile("\"timestamp\": \"(.*?)\"").matcher(logText);
319 return matcher.group(1);
323 /////////////////////////////////////////////
324 /// Dissociate pnf from service instance ///
325 ////////////////////////////////////////////
328 public void testGetAssociatedPnfsForServiceInstance() {
329 SimulatorApi.clearAll();
330 BulkRegistration.searchExistingServiceInstance();
331 BulkRegistration.getAssociatedPnfs();
333 goToExistingInstanceById(serviceInstanceId);
334 for (String pnf: pnfs) {
335 viewEditPage.getPnf(pnf);
340 public void testPnfsNotExistForServiceInstance() {
341 SimulatorApi.clearAll();
342 BulkRegistration.searchExistingServiceInstance();
344 goToExistingInstanceById(serviceInstanceId);
349 public void testSuccessDissociatePnfFromServiceInstance() throws Exception {
350 SimulatorApi.clearAll();
351 BulkRegistration.searchExistingServiceInstance();
352 BulkRegistration.getAssociatedPnfs();
353 BulkRegistration.dissociatePnf();
354 goToExistingInstanceById(serviceInstanceId);
355 dissociatePnf(pnfs.get(0)); //SANITY6785cce9
356 viewEditPage.assertMsoRequestModal(Constants.ViewEdit.MSO_SUCCESSFULLY_TEXT);
357 viewEditPage.clickCloseButton();
361 public void testFailDissociatePnfFromServiceInstance() throws Exception {
362 SimulatorApi.clearAll();
363 BulkRegistration.searchExistingServiceInstance();
364 BulkRegistration.getAssociatedPnfs();
365 SimulatorApi.registerExpectation(Constants.RegisterToSimulator.pProbe.REMOVE_PNF_RELATIONSHIP_ERROR, SimulatorApi.RegistrationStrategy.APPEND);
367 if (LocalDate.now().isBefore(LocalDate.parse("2018-06-04"))) return; // skip few days to see green build
368 goToExistingInstanceById(serviceInstanceId);
369 dissociatePnf(pnfs.get(0)); //SANITY6785cce9
370 viewEditPage.assertMsoRequestModal("Error");
371 GeneralUIUtils.ultimateWait();
372 viewEditPage.clickCloseButton();
376 private void assertNoPnfExists() {
377 WebElement pnfElement = Get.byClassAndText("tree-node", "PNF: ");
378 Assert.assertNull("Pnf found under service instance", pnfElement);
381 private void dissociatePnf(String pnfName) throws InterruptedException {
382 viewEditPage.clickDissociatePnfButton(pnfName);
383 assertDissociateConfirmModal(pnfName);
386 private void assertDissociateConfirmModal(String pnfName) {
387 Wait.modalToBeDisplayed();
388 Assert.assertTrue(Exists.modal());
389 Assert.assertTrue(Exists.byCssSelectorAndText(".modal-body span", String.format(Constants.ViewEdit.DISSOCIATE_CONFIRM_MODAL_TEXT, pnfName)));
390 WebElement confirmBtn = Get.byId(Constants.ViewEdit.DISSOCIATE_CONFIRM_MODAL_BTN_ID);
391 Assert.assertNotNull(confirmBtn);
393 // Wait.modalToDisappear();
397 public void testErrorMsgNoModelVerIdFromAai() throws Exception {
398 getExtendTest().info("from Bug 480129,this test check the error case, while model version Id not supplied from A&AI");
399 SimulatorApi.clearAll();
400 BulkRegistration.genericSearchExistingServiceInstance();
401 BulkRegistration.searchExistingServiceInstanceWithoutModelVerId();
402 goToExistingInstanceByIdNoWait(serviceInstanceIdeWithoutModelVerId);
403 viewEditPage.checkAndCloseAlert(Constants.ViewEdit.MODEL_VERSION_ID_MISSING_MSG);
404 String errMsg= viewEditPage.getTextByTestID(Constants.ViewEdit.SUBDETAILS_ERROR_MESSAGE_TEST_ID);
405 Assert.assertEquals(Constants.ViewEdit.MODEL_VERSION_ID_MISSING_MSG, errMsg);
408 private void assertResumeButtonVisibility(boolean pendingActivationResumeVisible, boolean assignedResumeVisible) {
409 ImmutableMap<String, Boolean> vfModulesStatuses = ImmutableMap.of(
410 "pendingactivation", pendingActivationResumeVisible,
411 "assigned", assignedResumeVisible,
412 "pending-delete", false);
413 for(Map.Entry<String, Boolean> entry: vfModulesStatuses.entrySet()) {
414 WebElement vfModule = GeneralUIUtils.getWebElementByClassName("vfModuleTreeNode-" + entry.getKey());
415 Assert.assertEquals(isNonEmpty(vfModule.findElements(By.className("resume"))), entry.getValue());
420 public void before() throws Exception {
421 User user = usersService.getUser(Constants.Users.SILVIA_ROBBINS_TYLER_SILVIA);
422 relogin(user.credentials);
425 @AfterMethod(alwaysRun = true)
426 public void finallyClosePopup() {
427 // Tries closing left-out popups, if any
428 // If none -- catch clause will swallow the exception
430 viewEditPage.clickCloseButton(3);
431 } catch (Exception e) {