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