1 package vid.automation.test.test;
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.onap.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;
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;
28 import java.util.regex.Matcher;
29 import java.util.regex.Pattern;
31 import static org.apache.logging.log4j.core.util.Assert.isNonEmpty;
32 import static org.hamcrest.CoreMatchers.is;
33 import static org.hamcrest.MatcherAssert.assertThat;
34 import static org.hamcrest.Matchers.equalTo;
35 import static org.hamcrest.collection.IsEmptyCollection.empty;
36 import static org.testng.AssertJUnit.assertEquals;
37 import static vid.automation.test.infra.Features.FLAG_1810_CR_SOFT_DELETE_ALACARTE_VF_MODULE;
38 import static vid.automation.test.services.SimulatorApi.RegistrationStrategy.APPEND;
40 public class ViewEditServiceInstanceTest extends VidBaseTestCase {
42 private ViewEditPage viewEditPage = new ViewEditPage();
43 VidBasePage vidBasePage =new VidBasePage();
44 private String serviceInstanceId = "3f93c7cb-2fd0-4557-9514-e189b7b04f9d";
45 private String crServiceInstanceId = "3f93c7cb-2fd0-4557-9514-e189b7testCR";
46 private String serviceFabricInstanceId = "c187e9fe-40c3-4862-b73e-84ff056205f61234";
47 private String serviceInstanceId2 ="c187e9fe-40c3-4862-b73e-84ff056205f6";
48 private final String DEACTIVATE_ACTION = "deactivate";
49 private final String ACTIVATE_ACTION = "activate";
50 private List<String> pnfs = Arrays.asList("SANITY6785cce9", "tesai371ve2");
51 private final String serviceInstanceIdeWithoutModelVerId ="9caf5581-40ab-47be-b1f1-909a87724add";
52 private final String crNetworkText ="NETWORK INSTANCE GROUP: l3network-id-rs804s | ROLE: RosemaProtectedOam.OAM | TYPE: Tenant_Layer_3 | # OF NETWORKS: 3";
53 private final String crCollectionText ="COLLECTION: collection-name | TYPE: L3-NETWORK";
54 private final String crInfoText = "\"requestState\": \"COMPLETE\"";
55 SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss");
56 static final String LCP_REGION = "hvf6";
57 static final String CLOUD_OWNER = "AIC";
58 static final String TENANT = "bae71557c5bb4d5aac6743a4e5f1d054";
61 ///////////////////////////////////////////////
62 /// Activate / Deactivate service instance ///
63 //////////////////////////////////////////////
65 @FeatureTogglingTest(value = Features.FLAG_1908_RESUME_MACRO_SERVICE, flagActive = false)
67 public void testViewEditCRServiceInstance() {
68 SimulatorApi.clearAll();
69 BulkRegistration.searchExistingCRServiceInstance("Created");
70 BulkRegistration.activateServiceInstance(ACTIVATE_ACTION);
71 final PresetAAIGetNetworkCollectionDetails presetAAIGetNetworkCollectionDetails = new PresetAAIGetNetworkCollectionDetails(crServiceInstanceId);
72 SimulatorApi.registerExpectationFromPreset(presetAAIGetNetworkCollectionDetails, APPEND);
73 goToExistingInstanceById(crServiceInstanceId);
74 WebElement webElement = Get.byTestId(Constants.ViewEdit.COLLECTIONDIV);
75 Assert.assertNotNull(webElement);
76 Assert.assertEquals(webElement.getText(), crCollectionText);
77 webElement = Get.byTestId(Constants.ViewEdit.COLLECTIONNETWORKDIV);
78 Assert.assertNotNull(webElement);
79 Assert.assertEquals(webElement.getText(), crNetworkText);
80 viewEditPage.clickInfoButton();
81 webElement = Get.byTestId(Constants.ViewEdit.SERVICE_INSTANCE_ID);
82 Assert.assertEquals(webElement.getText(), crServiceInstanceId);
83 webElement = Get.byTestId(Constants.ViewEdit.DETAILS_LOG);
84 Assert.assertTrue(webElement.getText().contains(crInfoText));
85 webElement = Get.byTestId(Constants.ViewEdit.DETAILS_CLOSE_BTN);
87 viewEditPage.clickDeleteButton();
89 private void deleteInstance(String deleteButtonId, String successMessage) {
90 deleteInstance(deleteButtonId, successMessage, Constants.CONFIRM_RESUME_DELETE_TESTS_ID);
93 private void deleteInstance(String deleteButtonId, String successMessage, String confirmButtonId) {
94 navigateToViewEditPageOfuspVoiceVidTest444("7a6ee536-f052-46fa-aa7e-2fca9d674c44");
95 Click.byTestId(deleteButtonId);
96 viewEditPage.selectLcpRegion(LCP_REGION, CLOUD_OWNER);
97 viewEditPage.selectTenant(TENANT);
98 vidBasePage.clickButtonByTestId(confirmButtonId);
99 viewEditPage.assertMsoRequestModal(successMessage);
100 viewEditPage.clickCommitCloseButton();
101 GeneralUIUtils.ultimateWait();
105 public void deleteVolumeGroupInstance_deleteDialogAppears_msoResponseIsOk() {
106 SimulatorApi.clearAll();
107 BulkRegistration.deleteExistingVolumeGroupInstance("CREATED");
108 deleteInstance(Constants.ViewEdit.DELETE_VNF_VOLUME_GROUP_BUTTON_TEST_ID, Constants.ViewEdit.VOLUME_GROUP_DELETED_SUCCESSFULLY_TEXT);
112 public void deleteVfModuleInstance_deleteDialogAppears_msoResponseIsOk() {
113 SimulatorApi.clearAll();
114 BulkRegistration.deleteExistingVfModuleInstance("CREATED");
115 deleteInstance(Constants.ViewEdit.DELETE_VF_MODULE_BUTTON_TEST_ID + "aa", Constants.ViewEdit.VF_MODULE_DELETED_SUCCESSFULLY_TEXT);
118 @FeatureTogglingTest(value = FLAG_1810_CR_SOFT_DELETE_ALACARTE_VF_MODULE)
120 public void softDeleteAndResumeVfModuleInstance_deleteDialogAppears_msoResponseIsOk() {
121 SimulatorApi.clearAll();
122 String vfModuleName = "my_vfModule";
123 BulkRegistration.deleteExistingVfModuleInstance("ACTIVE");
124 deleteInstance(Constants.ViewEdit.DELETE_VF_MODULE_BUTTON_TEST_ID + vfModuleName, Constants.ViewEdit.VF_MODULE_DELETED_SUCCESSFULLY_TEXT, Constants.SOFT_DELETE_TESTS_ID);
125 BulkRegistration.resumeWithHomingDataVfModule("ACTIVE", "Assigned", vfModuleName);
126 navigateToViewEditPageOfuspVoiceVidTest444("7a6ee536-f052-46fa-aa7e-2fca9d674c44");
127 viewEditPage.clickResumeButton(vfModuleName);
128 assertThat("Select lcp region shouldn't be display when homing data is presented",
129 GeneralUIUtils.getDriver().findElements(Get.getXpathForDataTestId(Constants.ViewEdit.LCP_REGION_SELECT_TESTS_ID)),
131 assertThat("Select tenant shouldn't be display when homing data is presented",
132 GeneralUIUtils.getDriver().findElements(Get.getXpathForDataTestId(Constants.ViewEdit.TENANT_SELECT_TESTS_ID)),
134 viewEditPage.clickConfirmButtonInResumeDelete();
135 assertSuccessfulVFModuleCreation();
136 viewEditPage.clickCommitCloseButton();
137 GeneralUIUtils.ultimateWait();
141 public void deleteNetworkInstance_deleteDialogAppears_msoResponseIsOk() {
142 SimulatorApi.clearAll();
143 BulkRegistration.deleteExistingNetworkInstance("CREATED");
144 deleteInstance(Constants.ViewEdit.DELETE_NETWORK_BUTTON_TEST_ID, Constants.ViewEdit.VL_DELETED_SUCCESSFULLY_TEXT);
148 public void deleteVnfInstance_deleteDialogAppears_msoResponseIsOk() {
149 SimulatorApi.clearAll();
150 BulkRegistration.deleteExistingVnfInstance("CREATED");
151 deleteInstance(Constants.ViewEdit.DELETE_VNF_BUTTON_TEST_ID,Constants.ViewEdit.VNF_DELETED_SUCCESSFULLY_TEXT);
155 public void deleteServiceInstance_deleteDialogAppears_msoResponseIsOk() {
156 SimulatorApi.clearAll();
157 BulkRegistration.deleteExistingServiceInstance("ACTIVE");
158 navigateToViewEditPageOfuspVoiceVidTest444("7a6ee536-f052-46fa-aa7e-2fca9d674c44");
159 viewEditPage.clickDeleteButton();
160 vidBasePage.clickConfirmButtonInResumeDelete();
161 viewEditPage.assertMsoRequestModal(Constants.ViewEdit.SERVICE_DELETED_SUCCESSFULLY_TEXT);
162 viewEditPage.clickCommitCloseButton();
163 GeneralUIUtils.ultimateWait();
166 @Test(dataProvider = "serviceStatusesAndExpectedResults")
167 public void testActivateServiceInstanceTransportType(String orchStatus) {
168 SimulatorApi.clearAll();
169 BulkRegistration.searchExistingServiceInstance(orchStatus);
170 BulkRegistration.activateServiceInstance(ACTIVATE_ACTION);
171 goToExistingInstanceById(serviceInstanceId);
172 viewEditPage.assertButtonState(Constants.ViewEdit.ACTIVATE_BUTTON_TEST_ID, true);
173 viewEditPage.assertButtonState(Constants.ViewEdit.DEACTIVATE_BUTTON_TEST_ID,false);
174 assertResumeButtonVisibility(false, false);
175 assertAndCheckShowAssignmentsSdncUrl(orchStatus, serviceInstanceId);
176 viewEditPage.clickActivateButton();
177 viewEditPage.assertMsoRequestModal(Constants.ViewEdit.MSO_SUCCESSFULLY_TEXT);
178 viewEditPage.clickCloseButton();
182 public void testActivateServiceInstanceWithFabric() {
183 String orchStatus = "assiGNed";
184 SimulatorApi.clearAll();
185 BulkRegistration.searchExistingServiceInstanceWithFabric(orchStatus);
186 goToExistingInstanceById(serviceFabricInstanceId);
187 viewEditPage.assertButtonState(Constants.ViewEdit.DEACTIVATE_BUTTON_TEST_ID,false);
188 boolean flagIsActive = Features.FLAG_FABRIC_CONFIGURATION_ASSIGNMENTS.isActive();
190 viewEditPage.assertButtonState(Constants.ViewEdit.ACTIVATE_FABRIC_CONFIGURATION_BUTTON_TEST_ID, true);
191 viewEditPage.clickActivateFabricConfigurationButton();
192 viewEditPage.assertMsoRequestModal(Constants.ViewEdit.MSO_SUCCESSFULLY_TEXT);
193 viewEditPage.clickCloseButton();
197 private void assertAndCheckShowAssignmentsSdncUrl(String orchStatus, String serviceInstanceId) {
198 boolean buttonIsEnable = Features.FLAG_SHOW_ASSIGNMENTS.isActive() && orchStatus.equals("assiGNed");
199 boolean isNotDisplay = GeneralUIUtils.getDriver().findElements(Get.getXpathForDataTestId(Constants.ViewEdit.SHOW_ASSIGNMENTS_BUTTON_TEST_ID)).isEmpty();
200 Assert.assertNotEquals(isNotDisplay, buttonIsEnable);
202 if (buttonIsEnable) {
203 WebElement webElement = Get.byTestId(Constants.ViewEdit.SHOW_ASSIGNMENTS_BUTTON_TEST_ID);
204 String expectedUrl = "https://mtan.onap.org:8448/configAdapter/index#/resource_manager/"+serviceInstanceId;
205 MatcherAssert.assertThat("Show assignments SDNC url is wrong",
206 webElement.getAttribute("href"), equalTo(expectedUrl));
212 public static Object[][] serviceStatusesAndExpectedResults() {
213 return new Object[][] {
222 public void testDeactivateServiceInstanceNotTransportType()throws Exception {
223 SimulatorApi.clearAll();
224 BulkRegistration.searchExistingServiceInstancePortMirroring("Active", "mdt1");
225 goToExistingInstanceById(serviceInstanceId2);
226 viewEditPage.assertButtonState(Constants.ViewEdit.ACTIVATE_BUTTON_TEST_ID, false);
227 viewEditPage.assertButtonState(Constants.ViewEdit.DEACTIVATE_BUTTON_TEST_ID, true);
231 public void testActivateServiceInstanceNotTransportType()throws Exception {
232 SimulatorApi.clearAll();
233 BulkRegistration.searchExistingServiceInstancePortMirroring("Created", "mdt1");
234 goToExistingInstanceById(serviceInstanceId2);
235 viewEditPage.assertButtonState(Constants.ViewEdit.ACTIVATE_BUTTON_TEST_ID, true);
236 viewEditPage.assertButtonState(Constants.ViewEdit.DEACTIVATE_BUTTON_TEST_ID, false);
240 public void testActivateServiceInstanceError()throws Exception {
241 SimulatorApi.clearAll();
242 BulkRegistration.searchExistingServiceInstance("Created");
243 BulkRegistration.activateServiceInstanceError(ACTIVATE_ACTION);
244 goToExistingInstanceById(serviceInstanceId);
245 viewEditPage.assertButtonState(Constants.ViewEdit.ACTIVATE_BUTTON_TEST_ID,true);
246 viewEditPage.assertButtonState(Constants.ViewEdit.DEACTIVATE_BUTTON_TEST_ID,false);
247 viewEditPage.clickActivateButton();
248 viewEditPage.assertMsoRequestModal("Error");
249 viewEditPage.clickCloseButton();
253 public void testDeactivateServiceInstance(){
254 SimulatorApi.clearAll();
255 BulkRegistration.searchExistingServiceInstance("Active");
256 BulkRegistration.activateServiceInstance(DEACTIVATE_ACTION);
257 goToExistingInstanceById(serviceInstanceId);
258 viewEditPage.assertButtonState(Constants.ViewEdit.DEACTIVATE_BUTTON_TEST_ID,true);
259 viewEditPage.assertButtonState(Constants.ViewEdit.ACTIVATE_BUTTON_TEST_ID,false);
260 assertResumeButtonVisibility(true, true);
261 viewEditPage.clickDeactivateButton();
262 viewEditPage.assertMsoRequestModal(Constants.ViewEdit.MSO_SUCCESSFULLY_TEXT);
263 SimulatorApi.clearAll();
264 BulkRegistration.searchExistingServiceInstance("PendingDelete");
265 BulkRegistration.activateServiceInstance(ACTIVATE_ACTION);
266 viewEditPage.clickCloseButton();
267 GeneralUIUtils.findAndWaitByText(serviceInstanceId, 30); //kind of "ultimate wait" for refresh to complete
268 viewEditPage.assertButtonState(Constants.ViewEdit.ACTIVATE_BUTTON_TEST_ID,true);
269 viewEditPage.assertButtonState(Constants.ViewEdit.DEACTIVATE_BUTTON_TEST_ID,false);
273 public void testDeactivateServiceInstanceError()throws Exception {
274 SimulatorApi.clearAll();
275 BulkRegistration.searchExistingServiceInstance("Active");
276 BulkRegistration.activateServiceInstanceError(DEACTIVATE_ACTION);
277 goToExistingInstanceById(serviceInstanceId);
278 viewEditPage.assertButtonState(Constants.ViewEdit.ACTIVATE_BUTTON_TEST_ID,false);
279 viewEditPage.assertButtonState(Constants.ViewEdit.DEACTIVATE_BUTTON_TEST_ID,true);
280 viewEditPage.clickDeactivateButton();
281 viewEditPage.assertMsoRequestModal("Error");
282 viewEditPage.clickCloseButton();
286 public void testTimestampOnDeactivateAndInfoServiceInstance() throws ParseException {
287 SimulatorApi.clearAll();
288 BulkRegistration.searchExistingServiceInstance("Active");
289 BulkRegistration.activateServiceInstance(DEACTIVATE_ACTION);
290 SimulatorApi.registerExpectation(
291 Constants.RegisterToSimulator.SearchForServiceInstance.GET_MSO_INSTANCE_ORCH_STATUS_REQ,
292 ImmutableMap.<String, Object>of("<SERVICE_INSTANCE_ID>", "3f93c7cb-2fd0-4557-9514-e189b7b04f9d"),
293 SimulatorApi.RegistrationStrategy.APPEND);
294 goToExistingInstanceById(serviceInstanceId);
295 Click.byClass("service-info");
296 GeneralUIUtils.ultimateWait();
297 assertEquals("Timestamp isn't the finished time", getTimeatampValue(Constants.ViewEdit.DETAILS_LOG), "Tue, 24 Oct 2017 02:28:39");
298 viewEditPage.clickCloseButton();
299 viewEditPage.clickDeactivateButton();
300 GeneralUIUtils.ultimateWait();
302 dateFormat.parse(getTimeatampValue(Constants.ViewEdit.MSO_COMMIT_LOG));
303 } catch (ParseException e) {
304 System.err.println("Timestamp isn't a date");
307 viewEditPage.clickCloseButton();
310 private String getTimeatampValue(String dataTestsId) {
311 String logText = Get.byTestId(dataTestsId).getText();
312 Matcher matcher = Pattern.compile("\"timestamp\": \"(.*?)\"").matcher(logText);
314 return matcher.group(1);
318 /////////////////////////////////////////////
319 /// Dissociate pnf from service instance ///
320 ////////////////////////////////////////////
323 public void testGetAssociatedPnfsForServiceInstance() {
324 SimulatorApi.clearAll();
325 BulkRegistration.searchExistingServiceInstance();
326 BulkRegistration.getAssociatedPnfs();
328 goToExistingInstanceById(serviceInstanceId);
329 for (String pnf: pnfs) {
330 viewEditPage.getPnf(pnf);
335 public void testPnfsNotExistForServiceInstance() {
336 SimulatorApi.clearAll();
337 BulkRegistration.searchExistingServiceInstance();
339 goToExistingInstanceById(serviceInstanceId);
344 public void testSuccessDissociatePnfFromServiceInstance() throws Exception {
345 SimulatorApi.clearAll();
346 BulkRegistration.searchExistingServiceInstance();
347 BulkRegistration.getAssociatedPnfs();
348 BulkRegistration.dissociatePnf();
349 goToExistingInstanceById(serviceInstanceId);
350 dissociatePnf(pnfs.get(0)); //SANITY6785cce9
351 viewEditPage.assertMsoRequestModal(Constants.ViewEdit.MSO_SUCCESSFULLY_TEXT);
352 viewEditPage.clickCloseButton();
356 public void testFailDissociatePnfFromServiceInstance() throws Exception {
357 SimulatorApi.clearAll();
358 BulkRegistration.searchExistingServiceInstance();
359 BulkRegistration.getAssociatedPnfs();
360 SimulatorApi.registerExpectation(Constants.RegisterToSimulator.pProbe.REMOVE_PNF_RELATIONSHIP_ERROR, SimulatorApi.RegistrationStrategy.APPEND);
362 if (LocalDate.now().isBefore(LocalDate.parse("2018-06-04"))) return; // skip few days to see green build
363 goToExistingInstanceById(serviceInstanceId);
364 dissociatePnf(pnfs.get(0)); //SANITY6785cce9
365 viewEditPage.assertMsoRequestModal("Error");
366 GeneralUIUtils.ultimateWait();
367 viewEditPage.clickCloseButton();
371 private void assertNoPnfExists() {
372 WebElement pnfElement = Get.byClassAndText("tree-node", "PNF: ");
373 Assert.assertNull("Pnf found under service instance", pnfElement);
376 private void dissociatePnf(String pnfName) throws InterruptedException {
377 viewEditPage.clickDissociatePnfButton(pnfName);
378 assertDissociateConfirmModal(pnfName);
381 private void assertDissociateConfirmModal(String pnfName) {
382 Wait.modalToBeDisplayed();
383 Assert.assertTrue(Exists.modal());
384 Assert.assertTrue(Exists.byCssSelectorAndText(".modal-body span", String.format(Constants.ViewEdit.DISSOCIATE_CONFIRM_MODAL_TEXT, pnfName)));
385 WebElement confirmBtn = Get.byId(Constants.ViewEdit.DISSOCIATE_CONFIRM_MODAL_BTN_ID);
386 Assert.assertNotNull(confirmBtn);
388 // Wait.modalToDisappear();
392 public void testErrorMsgNoModelVerIdFromAai() throws Exception {
393 getExtendTest().info("from Bug 480129,this test check the error case, while model version Id not supplied from A&AI");
394 SimulatorApi.clearAll();
395 BulkRegistration.genericSearchExistingServiceInstance();
396 BulkRegistration.searchExistingServiceInstanceWithoutModelVerId();
397 goToExistingInstanceByIdNoWait(serviceInstanceIdeWithoutModelVerId);
398 viewEditPage.checkAndCloseAlert(Constants.ViewEdit.MODEL_VERSION_ID_MISSING_MSG);
399 String errMsg= viewEditPage.getTextByTestID(Constants.ViewEdit.SUBDETAILS_ERROR_MESSAGE_TEST_ID);
400 Assert.assertEquals(Constants.ViewEdit.MODEL_VERSION_ID_MISSING_MSG, errMsg);
403 private void assertResumeButtonVisibility(boolean pendingActivationResumeVisible, boolean assignedResumeVisible) {
404 ImmutableMap<String, Boolean> vfModulesStatuses = ImmutableMap.of(
405 "pendingactivation", pendingActivationResumeVisible,
406 "assigned", assignedResumeVisible,
407 "pending-delete", false);
408 for(Map.Entry<String, Boolean> entry: vfModulesStatuses.entrySet()) {
409 WebElement vfModule = GeneralUIUtils.getWebElementByClassName("vfModuleTreeNode-" + entry.getKey());
410 Assert.assertEquals(isNonEmpty(vfModule.findElements(By.className("resume"))), entry.getValue());
415 public void before() throws Exception {
416 User user = usersService.getUser(Constants.Users.SILVIA_ROBBINS_TYLER_SILVIA);
417 relogin(user.credentials);
420 @AfterMethod(alwaysRun = true)
421 public void finallyClosePopup() {
422 // Tries closing left-out popups, if any
423 // If none -- catch clause will swallow the exception
425 viewEditPage.clickCloseButton(3);
426 } catch (Exception e) {