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.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;
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.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;
37 public class ViewEditServiceInstanceTest extends VidBaseTestCase {
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";
56 ///////////////////////////////////////////////
57 /// Activate / Deactivate service instance ///
58 //////////////////////////////////////////////
60 @FeatureTogglingTest(value = FLAG_COLLECTION_RESOURCE_SUPPORT)
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);
82 viewEditPage.clickDeleteButton();
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();
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);
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);
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);
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);
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();
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();
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));
164 public static Object[][] serviceStatusesAndExpectedResults() {
165 return new Object[][] {
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);
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);
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();
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);
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();
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();
254 dateFormat.parse(getTimeatampValue(Constants.ViewEdit.MSO_COMMIT_LOG));
255 } catch (ParseException e) {
256 System.err.println("Timestamp isn't a date");
259 viewEditPage.clickCloseButton();
262 private String getTimeatampValue(String dataTestsId) {
263 String logText = Get.byTestId(dataTestsId).getText();
264 Matcher matcher = Pattern.compile("\"timestamp\": \"(.*?)\"").matcher(logText);
266 return matcher.group(1);
270 /////////////////////////////////////////////
271 /// Dissociate pnf from service instance ///
272 ////////////////////////////////////////////
275 public void testGetAssociatedPnfsForServiceInstance() {
276 SimulatorApi.clearAll();
277 BulkRegistration.searchExistingServiceInstance();
278 BulkRegistration.getAssociatedPnfs();
280 goToExistingInstanceById(serviceInstanceId);
281 for (String pnf: pnfs) {
282 viewEditPage.getPnf(pnf);
287 public void testPnfsNotExistForServiceInstance() {
288 SimulatorApi.clearAll();
289 BulkRegistration.searchExistingServiceInstance();
291 goToExistingInstanceById(serviceInstanceId);
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();
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);
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();
323 private void assertNoPnfExists() {
324 WebElement pnfElement = Get.byClassAndText("tree-node", "PNF: ");
325 Assert.assertNull("Pnf found under service instance", pnfElement);
328 private void dissociatePnf(String pnfName) throws InterruptedException {
329 viewEditPage.clickDissociatePnfButton(pnfName);
330 assertDissociateConfirmModal(pnfName);
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);
340 // Wait.modalToDisappear();
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);
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());
367 public void before() throws Exception {
368 User user = usersService.getUser(Constants.Users.USP_VOICE_VIRTUAL_USP);
369 relogin(user.credentials);
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
377 viewEditPage.clickCloseButton(3);
378 } catch (Exception e) {