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