upgrade some 3rd parties dependencies
[vid.git] / vid-automation / src / main / java / vid / automation / test / test / EnvironmentsTest.java
1 package vid.automation.test.test;
2
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertFalse;
5 import static org.junit.Assert.assertTrue;
6 import static vid.automation.test.Constants.TestEnvironments.REFRESH_BUTTON;
7
8 import com.google.common.collect.ImmutableMap;
9 import java.util.List;
10 import java.util.Map;
11 import org.junit.Assert;
12 import org.onap.sdc.ci.tests.utilities.GeneralUIUtils;
13 import org.openqa.selenium.WebElement;
14 import org.springframework.http.HttpStatus;
15 import org.testng.annotations.BeforeMethod;
16 import org.testng.annotations.DataProvider;
17 import org.testng.annotations.Test;
18 import vid.automation.test.Constants;
19 import vid.automation.test.infra.Click;
20 import vid.automation.test.infra.Exists;
21 import vid.automation.test.infra.Features;
22 import vid.automation.test.infra.Get;
23 import vid.automation.test.infra.Input;
24 import vid.automation.test.infra.SelectOption;
25 import vid.automation.test.infra.Wait;
26 import vid.automation.test.model.Environment;
27 import vid.automation.test.sections.SideMenu;
28 import vid.automation.test.sections.TestEnvironmentPage;
29 import vid.automation.test.sections.VidBasePage;
30 import vid.automation.test.services.SimulatorApi;
31 import vid.automation.test.utils.ReadFile;
32
33
34 /*
35
36 1.      Activate
37     a.  Happy scenario
38         i.      Polling screen is displayed
39         ii.      Environment status become active in environments table
40         iii. Button become deactivation
41         iv.      Attach file button is shown
42     b.  Non JSON file content – error is shown
43     c.  Invalid manifest format in the JSON – error is shown
44     d.  MSO Error – 500/400 – error is shown
45 2.      Attach manifest
46     a.  Happy scenario
47     i.  Polling screen is displayed
48     b.  MSO Error – 500/400 – error is shown
49
50 3.      Deactivate
51     a.  Happy scenario
52         i.      Polling screen is displayed
53         ii.     Environment status become inactive in environments table
54         iii.    Button become activation
55         iv.     Attach file button is not shown
56     b.  MSO Error – 500/400 – error is shown
57
58  */
59
60 public class EnvironmentsTest extends VidBaseTestCase {
61
62     public static final String GET_EMPTY_OPERATIONAL_ENVIRONMENT_JSON = "get_empty_operational_environment.json";
63     public static final String GET_OPERATIONAL_ENVIRONMENT_JSON = "get_operational_environment.json";
64     public static final String GET_FULL_OPERATIONAL_ENVIRONMENT_JSON = "get_full_operational_environment.json";
65     public static final String GET_ERROR_OPERATIONAL_ENVIRONMENT_JSON = "get_error_operational_environment.json";
66     public static final String POST_OPERATIONAL_ENVIRONMENT_JSON = "post_operational_environment.json";
67     static final String ENVIRONMENTS_CONF = "environments";
68     static final String NEW_ENVIRONMENT_CONF = "newEnvironment";
69
70     public static final String ENV_ID_FOR_ACTIVATION = "f07ca256-96dd-40ad-b4d2-7a77e2a974eb";
71     public static final String ENV_ID_FOR_DEACTIVATION = "f07ca256-96dd-40ad-b4d2-7a77e2a974ec";
72     private VidBasePage vidBasePage = new VidBasePage();
73
74     public enum FailureType {
75         ACTIVATION_FAILURE,
76         DEACTIVATION_FAILURE,
77         GET_STATUS_FAILURE
78     }
79
80     @BeforeMethod
81     //Sometimes we clear registration while we are in view/edit page
82     //And there is alert so we can not navigate any more.
83     //So we first navigate to welcome page, and only the, clear registration
84     public void navigateToWelcome() {
85         SideMenu.navigateToWelcomePage();
86     }
87
88     @BeforeMethod
89     private void clearAllSimulatorExpectations() {
90         SimulatorApi.clearAll();
91         SimulatorApi.registerExpectation("ecompportal_getSessionSlotCheckInterval.json", SimulatorApi.RegistrationStrategy.APPEND);
92     }
93
94     @Test
95     public void testLeftPanelTestEnvironmentButton() {
96         List<WebElement> leftPanelButtons = Get.byClass(Constants.SideMenu.buttonClass);
97         Assert.assertTrue(Wait.byText(Constants.SideMenu.TEST_ENVIRONMENTS));
98     }
99
100     @Test
101     public void testEnvironmentHeaderLine() {
102         SideMenu.navigateToTestEnvironmentsPage();
103         Assert.assertTrue(Exists.byTestId(Constants.TestEnvironments.PAGE_HEADLINE));
104         Assert.assertTrue(Exists.byTestId(Constants.TestEnvironments.HEADLINE_NEW_BUTTON));
105         Assert.assertTrue(Exists.byTestId(Constants.TestEnvironments.HEADLINE_SEARCH_INPUT));
106     }
107
108     @Test
109     public void testTable() {
110         SimulatorApi.registerExpectation(GET_OPERATIONAL_ENVIRONMENT_JSON, SimulatorApi.RegistrationStrategy.APPEND);
111         vidBasePage.refreshPage();
112         Map <String, List<String>> file = ReadFile.getJsonFile(ENVIRONMENTS_CONF, Map.class);
113         String tableId = Constants.TestEnvironments.ENVIRONMENTS_TABLE;
114         SideMenu.navigateToTestEnvironmentsPage();
115         boolean emptyTableMessage = Exists.byTestId(Constants.TestEnvironments.NO_DATA_MESSAGE);
116         boolean errorMessage = Exists.byTestId(Constants.TestEnvironments.ERROR_MESSAGE);
117         Assert.assertFalse(emptyTableMessage || errorMessage);
118         List<String> headers = Get.tableHeaderValuesByTestId(tableId);
119         Assert.assertEquals(file.get(Constants.TestEnvironments.HEADERS_LIST), headers);
120         List<List<String>> body = Get.tableBodyValuesByTestId(tableId);
121         Assert.assertEquals(file.get(Constants.TestEnvironments.BASIC_LIST), body);
122     }
123
124     @Test
125     public void testSortTable() {
126         SimulatorApi.registerExpectation(GET_OPERATIONAL_ENVIRONMENT_JSON, SimulatorApi.RegistrationStrategy.APPEND);
127         vidBasePage.refreshPage();
128         Map <String, List<String>> file = ReadFile.getJsonFile(ENVIRONMENTS_CONF, Map.class);
129         String tableId = Constants.TestEnvironments.ENVIRONMENTS_TABLE;
130         SideMenu.navigateToTestEnvironmentsPage();
131         Click.byClass(Constants.TestEnvironments.TABLE_HEADER_ASC);
132         GeneralUIUtils.ultimateWait();
133         List<List<String>> body = Get.tableBodyValuesByTestId(tableId);
134         Assert.assertEquals(file.get(Constants.TestEnvironments.SORTED_LIST), body);
135         GeneralUIUtils.ultimateWait();
136     }
137
138     @Test
139     public void testFilterTable() {
140         SimulatorApi.registerExpectation(GET_OPERATIONAL_ENVIRONMENT_JSON, SimulatorApi.RegistrationStrategy.APPEND);
141         vidBasePage.refreshPage();
142         Map <String, List<String>> file = ReadFile.getJsonFile(ENVIRONMENTS_CONF, Map.class);
143         String tableId = Constants.TestEnvironments.ENVIRONMENTS_TABLE;
144         SideMenu.navigateToTestEnvironmentsPage();
145         Input.text(Constants.TestEnvironments.TEXT_TO_FILTER, Constants.TestEnvironments.SEARCH_INPUT);
146         GeneralUIUtils.ultimateWait();
147         List<List<String>> body = Get.tableBodyValuesByTestId(tableId);
148         Assert.assertEquals(file.get(Constants.TestEnvironments.FILTERED_LIST), body);
149         GeneralUIUtils.ultimateWait();
150     }
151
152
153     @Test
154     public void testEmptyTableMessage() {
155         SimulatorApi.registerExpectation(GET_EMPTY_OPERATIONAL_ENVIRONMENT_JSON, SimulatorApi.RegistrationStrategy.APPEND);
156         vidBasePage.refreshPage();
157         SideMenu.navigateToTestEnvironmentsPage();
158         boolean emptyTableMessage = Exists.byTestId(Constants.TestEnvironments.NO_DATA_MESSAGE);
159         Assert.assertTrue(emptyTableMessage);
160         Assert.assertFalse(Exists.byTestId(Constants.TestEnvironments.TRY_AGAIN_BUTTON));
161         Assert.assertFalse(Exists.byTestId(Constants.TestEnvironments.ENVIRONMENTS_TABLE));
162         GeneralUIUtils.ultimateWait();
163     }
164
165     @Test
166     public void testErrorMessage() {
167         SimulatorApi.registerExpectation(GET_ERROR_OPERATIONAL_ENVIRONMENT_JSON, SimulatorApi.RegistrationStrategy.APPEND);
168         vidBasePage.refreshPage();
169         SideMenu.navigateToTestEnvironmentsPage();
170         boolean errorMessage = Exists.byTestId(Constants.TestEnvironments.ERROR_MESSAGE);
171         Assert.assertTrue(errorMessage);
172         Assert.assertTrue(Exists.byTestId(Constants.TestEnvironments.TRY_AGAIN_BUTTON));
173         Assert.assertFalse(Exists.byTestId(Constants.TestEnvironments.ENVIRONMENTS_TABLE));
174         GeneralUIUtils.ultimateWait();
175     }
176
177     @Test
178     public void testNewEnvironmentPopup() {
179         SimulatorApi.registerExpectation(GET_OPERATIONAL_ENVIRONMENT_JSON, SimulatorApi.RegistrationStrategy.APPEND);
180         SimulatorApi.registerExpectation(POST_OPERATIONAL_ENVIRONMENT_JSON, SimulatorApi.RegistrationStrategy.APPEND);
181         SimulatorApi.registerExpectation("environment/status/get_cloud_resources_request_status.json",
182                 ImmutableMap.of("status_message", Constants.TestEnvironments.environmentCreatedSuccesfullyMessage,
183                         "REQUEST-TYPE","Create"), SimulatorApi.RegistrationStrategy.APPEND);
184         vidBasePage.refreshPage();
185         Environment environment = ReadFile.getJsonFile(NEW_ENVIRONMENT_CONF, Environment.class);
186         SideMenu.navigateToTestEnvironmentsPage();
187         Click.byTestId(Constants.TestEnvironments.HEADLINE_NEW_BUTTON);
188         Wait.modalToBeDisplayed();
189         Assert.assertTrue(Exists.byTestId(Constants.TestEnvironments.NEW_ENVIRONMENT_FORM));
190
191         boolean errorMessage = Exists.byTestId(Constants.TestEnvironments.POPUP_ERROR_MESSAGE);
192         Assert.assertFalse(errorMessage);
193
194         Assert.assertFalse(Get.byTestId(Constants.TestEnvironments.SUBMIT_BUTTON).isEnabled());
195         Input.text(environment.operationalEnvironmentName, Constants.TestEnvironments.INSTANCE_NAME_INPUT);
196
197         GeneralUIUtils.ultimateWait();
198         SelectOption.byTestIdAndVisibleText(environment.EcompEnvironmentId, Constants.TestEnvironments.ECOMP_ID_DROP_DOWN);
199
200         String ecompNameText = Input.getValueByTestId(Constants.TestEnvironments.ECOMP_NAME_INPUT);
201         Assert.assertEquals(environment.EcompEnvironmentName, ecompNameText);
202
203         String tenantContextText = Input.getValueByTestId(Constants.TestEnvironments.TENANT_CONTEXT_INPUT);
204         Assert.assertEquals(environment.tenantContext, tenantContextText);
205
206         String environmentTypeDefault = Get.selectedOptionText(Constants.TestEnvironments.ENVIRONMENT_TYPE_DROP_DOWN);
207         Assert.assertEquals(environment.operationalEnvironmentType, environmentTypeDefault);
208
209         if (Features.FLAG_1908_RELEASE_TENANT_ISOLATION.isActive()) {
210             SelectOption.byTestIdAndVisibleText(environment.release, Constants.TestEnvironments.ENVIRONMENT_RELEASE);
211             environment.workloadContext = environment.workloadContext.concat("_" + environment.release);
212         }
213         SelectOption.byTestIdAndVisibleText(environment.workloadContext, Constants.TestEnvironments.WORKLOAD_CONTEXT_DROP_DOWN);
214
215         WebElement submitButton = Get.byTestId(Constants.TestEnvironments.SUBMIT_BUTTON);
216         Assert.assertTrue(submitButton.isEnabled());
217         Click.byTestId(Constants.TestEnvironments.SUBMIT_BUTTON);
218         boolean waitForTextResult = Wait.waitByClassAndText("status", Constants.TestEnvironments.environmentCreatedSuccesfullyMessage, 60);
219         assertTrue(Constants.TestEnvironments.environmentCreatedSuccesfullyMessage + " message didn't appear on time", waitForTextResult);
220
221         vidBasePage.clickCloseButton();
222         GeneralUIUtils.ultimateWait();
223
224         // refresh table
225         Map <String, List<List<String>>> file = ReadFile.getJsonFile(ENVIRONMENTS_CONF, Map.class);
226         String tableId = Constants.TestEnvironments.ENVIRONMENTS_TABLE;
227         SimulatorApi.registerExpectation(GET_FULL_OPERATIONAL_ENVIRONMENT_JSON,
228                 ImmutableMap.of("new_name", environment.operationalEnvironmentName, "new_tenant", environment.tenantContext, "new_ecomp_id", environment.EcompEnvironmentId, "new_ecomp_name", environment.EcompEnvironmentName, "new_workload_context", environment.workloadContext), SimulatorApi.RegistrationStrategy.APPEND);
229         Click.byTestId(REFRESH_BUTTON);
230         Wait.angularHttpRequestsLoaded();
231         List<List<String>> body = Get.tableBodyValuesByTestId(tableId);
232         Assert.assertEquals(file.get(fullListId()), body);
233         GeneralUIUtils.ultimateWait();
234     }
235
236     @Test
237     public void testAaiErrorNewEnvironmentPopup() {
238         SimulatorApi.registerExpectation(GET_ERROR_OPERATIONAL_ENVIRONMENT_JSON, SimulatorApi.RegistrationStrategy.APPEND);
239         vidBasePage.refreshPage();
240         SideMenu.navigateToTestEnvironmentsPage();
241         Click.byTestId(Constants.TestEnvironments.HEADLINE_NEW_BUTTON);
242         Wait.modalToBeDisplayed();
243         Assert.assertTrue(Exists.byTestId(Constants.TestEnvironments.NEW_ENVIRONMENT_FORM));
244         GeneralUIUtils.ultimateWait();
245         boolean errorMessage = Exists.byTestId(Constants.TestEnvironments.POPUP_ERROR_MESSAGE);
246         Assert.assertTrue(errorMessage);
247         Click.byTestId(Constants.TestEnvironments.CANCEL_BUTTON);
248         Wait.modalToDisappear();
249         GeneralUIUtils.ultimateWait();
250     }
251
252     @Test
253     public void testCancelNewPopup() {
254         SideMenu.navigateToTestEnvironmentsPage();
255         Click.byTestId(Constants.TestEnvironments.HEADLINE_NEW_BUTTON);
256         Assert.assertTrue(Exists.modal());
257         Click.byTestId(Constants.TestEnvironments.CANCEL_BUTTON);
258         Wait.modalToDisappear();
259         Assert.assertFalse(Exists.modal());
260         GeneralUIUtils.ultimateWait();
261     }
262
263     @Test
264     public void testCloseNewPopup() {
265         SideMenu.navigateToTestEnvironmentsPage();
266         Click.byTestId(Constants.TestEnvironments.HEADLINE_NEW_BUTTON);
267         Wait.modalToBeDisplayed();
268         Assert.assertTrue(Exists.modal());
269         GeneralUIUtils.ultimateWait();
270         Click.byClass(Constants.TestEnvironments.MODAL_CLOSE_BUTTON_CLASS);
271         Wait.modalToDisappear();
272         GeneralUIUtils.ultimateWait();
273         Assert.assertFalse(Exists.modal());
274         GeneralUIUtils.ultimateWait();
275     }
276
277     @Test
278     public void testApplicationEnvironmentActivation() {
279         String envId = ENV_ID_FOR_ACTIVATION;
280         SimulatorApi.registerExpectation("environment/activate/get_operational_environments_aai1.json", SimulatorApi.RegistrationStrategy.APPEND);
281         SimulatorApi.registerExpectation("environment/activate/post_activate_operational_environment.json",
282                 ImmutableMap.of("ENV-UUID", envId), SimulatorApi.RegistrationStrategy.APPEND);
283         SimulatorApi.registerExpectation("environment/status/get_cloud_resources_request_status.json",
284                 ImmutableMap.of("status_message", Constants.TestEnvironments.environmentActivatedSuccesfullyMessage,
285                         "REQUEST-TYPE","Activate"), SimulatorApi.RegistrationStrategy.APPEND);
286         clickOnActivationButtonAndUploadFile(envId, "manifest.json");
287
288         Click.byId(Constants.generalSubmitButtonId);
289         SimulatorApi.registerExpectation("environment/activate/get_operational_environments_aai1.json",
290                 ImmutableMap.of("INACTIVE", "ACTIVE"), SimulatorApi.RegistrationStrategy.APPEND);
291
292         boolean waitForTextResult = Wait.waitByClassAndText("status", Constants.TestEnvironments.environmentActivatedSuccesfullyMessage, 60);
293         assertTrue(Constants.TestEnvironments.environmentActivatedSuccesfullyMessage + " message didn't appear on time", waitForTextResult);
294
295         vidBasePage.clickCloseButton();
296
297         GeneralUIUtils.ultimateWait();
298
299         WebElement deactivationButton = TestEnvironmentPage.getTestEnvironmentDeactivationButton(envId);
300         assertTrue("Failed to find Deactivate button for test env with id: "+envId, deactivationButton.isDisplayed());
301
302         WebElement status = Get.byId(Constants.TestEnvironments.environmentStatusIdPrefix + envId);
303         assertEquals("ACTIVE", status.getText());
304
305         WebElement attachButton = TestEnvironmentPage.getTestEnvironmentAttachButton(envId);
306         assertTrue("Failed to find Attach button for test env with id: "+envId, attachButton.isDisplayed());
307
308         //make sure page is clickable
309         SideMenu.navigateToTestEnvironmentsPage();
310     }
311
312     @Test
313     public void testApplicationEnvironmentDeactivation() {
314         String envId  = ENV_ID_FOR_DEACTIVATION;
315         SimulatorApi.registerExpectation("environment/activate/get_operational_environments_aai1.json", SimulatorApi.RegistrationStrategy.APPEND);
316         SimulatorApi.registerExpectation("environment/deactivate/post_deactivate_operational_environment.json",
317                 ImmutableMap.of("ENV-UUID", envId), SimulatorApi.RegistrationStrategy.APPEND);
318         SimulatorApi.registerExpectation("environment/status/get_cloud_resources_request_status.json",
319                 ImmutableMap.of("status_message", Constants.TestEnvironments.environmentDeactivatedSuccesfullyMessage,
320                         "REQUEST-TYPE","Deactivate"), SimulatorApi.RegistrationStrategy.APPEND);
321         deactivateEnv(envId);
322
323         SimulatorApi.registerExpectation("environment/deactivate/get_operational_environments_aai1.json", SimulatorApi.RegistrationStrategy.APPEND);
324         GeneralUIUtils.findAndWaitByText(Constants.TestEnvironments.environmentDeactivatedSuccesfullyMessage, 60);
325
326         vidBasePage.clickCloseButton();
327
328         GeneralUIUtils.ultimateWait();
329
330         WebElement activationButton = TestEnvironmentPage.getTestEnvironmentActivationButton(envId);
331         assertTrue("Failed to find Activate button for test env with id: "+envId, activationButton.isDisplayed());
332
333         WebElement status = Get.byId(Constants.TestEnvironments.environmentStatusIdPrefix + envId);
334         assertEquals("INACTIVE", status.getText());
335
336         WebElement attachButton = TestEnvironmentPage.getTestEnvironmentAttachButton(envId);
337         assertFalse("attach button shouldn't be displayed for test env with id: "+envId, attachButton.isDisplayed());
338
339         SideMenu.navigateToTestEnvironmentsPage();
340     }
341
342     private void deactivateEnv(String envId) {
343         vidBasePage.refreshPage();
344         SideMenu.navigateToTestEnvironmentsPage();
345         WebElement deactivationButton = TestEnvironmentPage.getTestEnvironmentDeactivationButton(envId);
346         assertTrue("Failed to find Deactivation button for test env with id: "+envId, deactivationButton.isDisplayed());
347         deactivationButton.click();
348     }
349
350     @DataProvider
351     public static Object[][] badManifestProvider() {
352         return new Object[][]{
353                 {"bad_manifest_structure.json","Manifest structure is wrong"},
354                 {"manifest_with_wrong_recovery_action.json",  "Wrong value for RecoveryAction in manifest. Allowed options are: abort,retry,skip. Wrong value is: leave"}
355         };
356     }
357
358     @Test
359     public void testApplicationEnvironmentActivationBadManifestStructure() {
360         testApplicationEnvironmentActivationBadManifestStructure("bad_manifest_structure.json", "Manifest structure is wrong");
361         testApplicationEnvironmentActivationBadManifestStructure("manifest_with_wrong_recovery_action.json",
362                 "Wrong value for RecoveryAction in manifest. Allowed options are: abort, retry, skip. Wrong value is: leave");
363     }
364
365     //@Test(dataProvider = "badManifestProvider") TODO : use data provider here (for some reason not work with ui-ci framework)
366     public void testApplicationEnvironmentActivationBadManifestStructure(String badManifestFileName, String exceptedErrorMsg) {
367         SimulatorApi.registerExpectation("environment/activate/get_operational_environments_aai1.json", SimulatorApi.RegistrationStrategy.APPEND);
368         clickOnActivationButtonAndUploadFile(ENV_ID_FOR_ACTIVATION, badManifestFileName);
369         WebElement attachButton = Get.byId("submit");
370         assertEquals("Wrong text for submit button in activate modal", "Attach", attachButton.getText());
371         attachButton.click();
372         boolean waitForTextResult = Wait.waitByClassAndText("error", exceptedErrorMsg, 30);
373         assertTrue(exceptedErrorMsg+ " message didn't appear on time", waitForTextResult);
374         GeneralUIUtils.ultimateWait();
375         vidBasePage.clickCloseButton();
376         Wait.modalToDisappear();
377         SideMenu.navigateToTestEnvironmentsPage();
378     }
379
380     @Test
381     public void testApplicationEnvironmentActivationNonJsonManifest() {
382         SimulatorApi.registerExpectation("environment/activate/get_operational_environments_aai1.json", SimulatorApi.RegistrationStrategy.APPEND);
383         String fileName = "non_valid_json.json";
384         clickOnActivationButtonAndUploadFile(ENV_ID_FOR_ACTIVATION, fileName);
385         WebElement errorLabel = Get.byId("errorLabel");
386         assertEquals("wrong error message for non valid json file", "file: " + fileName + " is not a valid JSON", errorLabel.getText());
387         vidBasePage.clickCancelButton();
388         GeneralUIUtils.ultimateWait();
389     }
390
391     private void clickOnActivationButtonAndUploadFile(String envId, String inputFileName) {
392         vidBasePage.refreshPage();
393         SideMenu.navigateToTestEnvironmentsPage();
394         WebElement activationButton = TestEnvironmentPage.getTestEnvironmentActivationButton(envId);
395         assertTrue("Failed to find Activate button for test env with id: "+envId, activationButton.isDisplayed());
396         activationButton.click();
397         updateEnvManifestFile(inputFileName);
398         assertTrue("Manifest file name is wrong in test environment activation modal",
399                 Wait.waitByIdAndText("manifestFileName", inputFileName, 10));
400     }
401
402     private void updateEnvManifestFile(String inputFileName) {
403         GeneralUIUtils.ultimateWait();
404         Input.file("applicationEnvironment/"+inputFileName, "testEnvManifestFileInput");
405         GeneralUIUtils.ultimateWait();
406     }
407
408     @Test
409     public void testAttachManifestFileHappyFlow() {
410         String envId = ENV_ID_FOR_ACTIVATION;
411         SimulatorApi.registerExpectation("environment/activate/post_activate_operational_environment.json",
412                 ImmutableMap.of("ENV-UUID", envId), SimulatorApi.RegistrationStrategy.APPEND);
413         SimulatorApi.registerExpectation("environment/attachManifest/get_attachable_operational_environment.json", SimulatorApi.RegistrationStrategy.APPEND);
414         SimulatorApi.registerExpectation("environment/status/get_cloud_resources_request_status.json",
415                 ImmutableMap.of("status_message", Constants.TestEnvironments.environmentActivatedSuccesfullyMessage), SimulatorApi.RegistrationStrategy.APPEND);
416         vidBasePage.refreshPage();
417         SideMenu.navigateToTestEnvironmentsPage();
418         WebElement attachButton = TestEnvironmentPage.getTestEnvironmentAttachButton(ENV_ID_FOR_ACTIVATION);
419         attachButton.click();
420
421         updateEnvManifestFile("manifest.json");
422
423         Click.byId(Constants.generalSubmitButtonId);
424
425         boolean waitForTextResult = Wait.waitByClassAndText("status", Constants.TestEnvironments.environmentActivatedSuccesfullyMessage, 60);
426         assertTrue(Constants.TestEnvironments.environmentActivatedSuccesfullyMessage + " message didn't appear on time", waitForTextResult);
427
428         vidBasePage.clickCloseButton();
429     }
430     @Test
431     public void testApplicationEnvironmentActivationErrorResponseFromMso() throws Exception {
432         String payload = "ERROR_PAYLOAD";
433         testApplicationEnvironmentActivationErrorResponseFromMso(HttpStatus.INTERNAL_SERVER_ERROR, payload, FailureType.ACTIVATION_FAILURE);
434         testApplicationEnvironmentActivationErrorResponseFromMso(HttpStatus.BAD_REQUEST, payload, FailureType.ACTIVATION_FAILURE);
435         testApplicationEnvironmentActivationErrorResponseFromMso(HttpStatus.INTERNAL_SERVER_ERROR, payload, FailureType.GET_STATUS_FAILURE);
436         testApplicationEnvironmentActivationErrorResponseFromMso(HttpStatus.BAD_REQUEST, payload, FailureType.GET_STATUS_FAILURE);
437     }
438
439
440     public void testApplicationEnvironmentActivationErrorResponseFromMso(HttpStatus errorStatus, String payload, FailureType failureType) {
441
442         String envId = ENV_ID_FOR_ACTIVATION;
443         SimulatorApi.registerExpectation("environment/activate/get_operational_environments_aai1.json", SimulatorApi.RegistrationStrategy.APPEND);
444         switch (failureType) {
445             case ACTIVATION_FAILURE:
446                 SimulatorApi.registerExpectation("environment/activate/mso_error_response_for_post_operational_environment.json",
447                         ImmutableMap.of("ERROR_CODE", errorStatus.value(), "ENV-UUID", envId), SimulatorApi.RegistrationStrategy.APPEND);
448                 break;
449             case GET_STATUS_FAILURE:
450                 SimulatorApi.registerExpectation("environment/activate/post_activate_operational_environment.json",
451                         ImmutableMap.of("ENV-UUID", envId), SimulatorApi.RegistrationStrategy.APPEND);
452                 break;
453         }
454
455         SimulatorApi.registerExpectation("environment/status/get_cloud_resources_request_status_bad_response.json",
456                 ImmutableMap.of("ERROR_CODE", errorStatus.value(), "ENV-UUID", envId), SimulatorApi.RegistrationStrategy.APPEND);
457
458         clickOnActivationButtonAndUploadFile(envId, "manifest.json");
459         Click.byId(Constants.generalSubmitButtonId);
460         Wait.waitByClassAndText("error", "System failure", 60);
461         Wait.waitByClassAndText("log", errorStatus.getReasonPhrase(), 60);
462         Wait.waitByClassAndText("log", payload, 60);
463         vidBasePage.clickCloseButton();
464
465         GeneralUIUtils.waitForAngular();
466
467         WebElement status = Get.byId(Constants.TestEnvironments.environmentStatusIdPrefix + envId);
468         assertEquals(Constants.INACTIVE, status.getText());
469         //make sure page is clickable
470         SideMenu.navigateToTestEnvironmentsPage();
471     }
472
473     @Test
474     public void testApplicationEnvironmentDeactivationErrorResponseFromMso() throws Exception {
475         String payload = "<html><head><title>Error</title></head><body>REASON</body></html>";
476         testApplicationEnvironmentDeactivationErrorResponseFromMso(HttpStatus.INTERNAL_SERVER_ERROR, payload, FailureType.DEACTIVATION_FAILURE);
477         testApplicationEnvironmentDeactivationErrorResponseFromMso(HttpStatus.BAD_REQUEST, payload, FailureType.DEACTIVATION_FAILURE);
478         testApplicationEnvironmentDeactivationErrorResponseFromMso(HttpStatus.INTERNAL_SERVER_ERROR, payload, FailureType.GET_STATUS_FAILURE);
479         testApplicationEnvironmentDeactivationErrorResponseFromMso(HttpStatus.BAD_REQUEST, payload, FailureType.GET_STATUS_FAILURE);
480     }
481
482     public void testApplicationEnvironmentDeactivationErrorResponseFromMso(HttpStatus errorStatus, String payload, FailureType failureType) {
483         String envId  = ENV_ID_FOR_DEACTIVATION;
484         payload = payload.replace("REASON", errorStatus.getReasonPhrase());
485         SimulatorApi.registerExpectation("environment/activate/get_operational_environments_aai1.json", SimulatorApi.RegistrationStrategy.APPEND);
486         switch (failureType) {
487             case DEACTIVATION_FAILURE:
488                 SimulatorApi.registerExpectation("environment/deactivate/error_deactivate_operational_environment.json",
489                         ImmutableMap.of("ERROR_CODE", errorStatus.value(), "ENV-UUID", envId,"ERROR_PAYLOAD", payload), SimulatorApi.RegistrationStrategy.APPEND);
490                 break;
491             case GET_STATUS_FAILURE:
492                 SimulatorApi.registerExpectation("environment/deactivate/post_deactivate_operational_environment.json",
493                         ImmutableMap.of("ENV-UUID", envId), SimulatorApi.RegistrationStrategy.APPEND);
494                 break;
495         }
496         SimulatorApi.registerExpectation("environment/status/get_cloud_resources_request_status_bad_response.json",
497                 ImmutableMap.of("ERROR_CODE", errorStatus.value(), "ENV-UUID", envId, "ERROR_PAYLOAD", payload), SimulatorApi.RegistrationStrategy.APPEND);
498         deactivateEnv(envId);
499
500         Wait.waitByClassAndText("error", "System failure", 60);
501         Wait.waitByClassAndText("log", errorStatus.getReasonPhrase(), 60);
502         Wait.waitByClassAndText("log", payload, 60);
503         vidBasePage.clickCloseButton();
504
505         GeneralUIUtils.ultimateWait();
506
507         WebElement status = Get.byId(Constants.TestEnvironments.environmentStatusIdPrefix + envId);
508         assertEquals(Constants.ACTIVE, status.getText());
509         //make sure page is clickable
510         SideMenu.navigateToTestEnvironmentsPage();
511     }
512
513     private String fullListId() {
514         return Features.FLAG_1908_RELEASE_TENANT_ISOLATION.isActive() ?
515                 Constants.TestEnvironments.FULL_LIST : Constants.TestEnvironments.FULL_LIST_WITHOUT_RELEASE_LABEL;
516     }
517
518
519
520 }