Merge automation from ECOMP's repository
[vid.git] / vid-automation / src / main / java / vid / automation / test / test / InstantiationStatusTest.java
1 package vid.automation.test.test;
2
3 import static org.onap.simulator.presetGenerator.presets.mso.PresetMSOServiceInstanceGen2WithNames.Keys.SERVICE_NAME;
4 import static org.onap.simulator.presetGenerator.presets.mso.PresetMSOServiceInstanceGen2WithNames.Keys.VNF_NAME;
5 import static org.testng.Assert.assertEquals;
6 import static org.testng.AssertJUnit.assertTrue;
7 import static vid.automation.test.Constants.DrawingBoard.DEPLOY_BUTTON;
8 import static vid.automation.test.infra.Features.FLAG_ASYNC_INSTANTIATION;
9
10 import com.google.common.collect.ImmutableMap;
11 import java.util.Collections;
12 import org.junit.Assert;
13 import org.onap.sdc.ci.tests.datatypes.UserCredentials;
14 import org.onap.sdc.ci.tests.utilities.GeneralUIUtils;
15 import org.onap.simulator.presetGenerator.presets.mso.PresetMSOServiceInstanceGen2WithNames;
16 import org.onap.vid.api.AsyncInstantiationBase;
17 import org.onap.vid.api.CreateServiceWithFailedVnf;
18 import org.onap.vid.api.TestUtils;
19 import org.openqa.selenium.By;
20 import org.openqa.selenium.WebElement;
21 import org.testng.annotations.AfterClass;
22 import org.testng.annotations.BeforeClass;
23 import org.testng.annotations.Test;
24 import vid.automation.test.Constants;
25 import vid.automation.test.infra.Click;
26 import vid.automation.test.infra.FeatureTogglingTest;
27 import vid.automation.test.infra.Features;
28 import vid.automation.test.infra.Get;
29 import vid.automation.test.infra.Wait;
30 import vid.automation.test.sections.DrawingBoardPage;
31 import vid.automation.test.sections.InstantiationStatusPage;
32 import vid.automation.test.sections.SideMenu;
33 import vid.automation.test.sections.VidBasePage;
34 import vid.automation.test.services.AsyncJobsService;
35
36 @FeatureTogglingTest(FLAG_ASYNC_INSTANTIATION)
37 public class InstantiationStatusTest extends VidBaseTestCase {
38
39     private final String serviceModelVersion = "5.1";
40     private final String regionId = "a93f8383-707e-43fa-8191-a6e69a1aab17";
41     final static String owningEntityName  = "Lucine Sarika";
42     final static String subscriberName  = "SILVIA ROBBINS";
43     private static final String COMPLETED = "COMPLETED";
44     private static final String CREATE_BULK_OF_ALACARTE_REQUEST = "asyncInstantiation/vidRequestCreateALaCarte.json";
45     private final VidBasePage vidBasePage = new VidBasePage();
46
47     private AsyncInstantiationBase asyncInstantiationBase;
48
49     @BeforeClass
50     protected void dropAllAsyncJobs() {
51         AsyncJobsService asyncJobsService = new AsyncJobsService();
52         asyncJobsService.dropAllAsyncJobs();
53         asyncInstantiationBase = new AsyncInstantiationBase();
54         asyncInstantiationBase.init();
55         UserCredentials userCredentials = getUserCredentials();
56         //login for API test (needed besides selenium test via browser)
57         asyncInstantiationBase.login(userCredentials);
58     }
59
60     @AfterClass
61     protected void muteAllAsyncJobs() {
62         AsyncJobsService asyncJobsService = new AsyncJobsService();
63         asyncJobsService.muteAllAsyncJobs();
64     }
65
66     private String addOneJob() {
67         String serviceName = TestUtils.generateRandomAlphaNumeric(8);
68         final ImmutableMap<PresetMSOServiceInstanceGen2WithNames.Keys, String> names =
69                 ImmutableMap.of(SERVICE_NAME, serviceName);
70         asyncInstantiationBase.createBulkOfInstances(false, 1, names, CREATE_BULK_OF_ALACARTE_REQUEST).get(0);
71         return serviceName;
72     }
73
74     @Test
75     public void testServiceInfoIsPresentedInTable() {
76         String serviceName = addOneJob();
77         SideMenu.navigateToMacroInstantiationStatus();
78         InstantiationStatusPage.clickRefreshButton();
79
80         InstantiationStatusPage.assertInstantiationStatusRow(serviceName, ImmutableMap.of(
81                 "subscriberName", subscriberName,
82                 "regionId", regionId,
83                 "serviceModelVersion", serviceModelVersion,
84                 "owningEntityName", owningEntityName
85         ));
86     }
87
88     @Test
89     public void testServiceInfoDataUpdatingAfterClickRefresh() {
90         addOneJob();
91         SideMenu.navigateToMacroInstantiationStatus();
92         InstantiationStatusPage.clickRefreshButton();
93         long numberOfRows = InstantiationStatusPage.getNumberOfTableRows(60);
94
95         addOneJob();
96         InstantiationStatusPage.clickRefreshButton();
97         int numberOfRowsAfterRefresh = InstantiationStatusPage.getNumberOfTableRows(60);
98         Assert.assertEquals(numberOfRows + 1 , numberOfRowsAfterRefresh);
99     }
100     
101     @Test
102     @FeatureTogglingTest(Features.FLAG_1902_RETRY_JOB)
103     public void testRedeployFromDrawingBoardOfServiceWithFailedVnf() {
104         SideMenu.navigateToMacroInstantiationStatus();
105
106         CreateServiceWithFailedVnf createServiceWithFailedVnf = createServiceWithFailedVnfAssertStausAndSimulatorRegistration();
107         String originalServiceName = createServiceWithFailedVnf.getNames().get(SERVICE_NAME);
108
109         InstantiationStatusPage.clickRefreshButton();
110
111         //Open job
112         InstantiationStatusPage.openDrawingBoardForRetry(originalServiceName);
113         DrawingBoardPage.goToIframe();
114
115         Wait.waitByTestId("error-msg-wrapper", 10);
116         boolean isErrorShown = Wait.waitByClassAndText("sub-title", "Attention: You are currently viewing instances from the MSO. 1 of the instances failed, please try again.", 10);
117         assertTrue(isErrorShown);
118
119         //validate audit info for failed vnf
120         String originalVnfName = createServiceWithFailedVnf.getNames().get(VNF_NAME);
121         hoverAndClickMenuByName(originalVnfName, "fe042c22-ba82-43c6-b2f6-8f1fc4164091-vSAMP12 1", Constants.DrawingBoard.CONTEXT_MENU_SHOW_AUDIT);
122         checkFailedAuditInfoOnRetry(originalVnfName, createServiceWithFailedVnf.getFirstIds().vnfReqId, "Vnf failed.");
123
124         Click.byTestId(DEPLOY_BUTTON);
125         VidBasePage.goOutFromIframe();
126         GeneralUIUtils.ultimateWait();
127         vidBasePage.goToIframe();
128         GeneralUIUtils.ultimateWait();
129
130         checkRetryRequestToBeComplete(createServiceWithFailedVnf, originalServiceName);
131     }
132
133     private void checkFailedAuditInfoOnRetry(String instanceName, String requestId, String message) {
134         WebElement webElement = Get.byTestId("model-item-value-instance_name");
135         assertEquals(webElement.getText(), instanceName, "Instance Name must be equal");
136
137         WebElement msoTableElement = Get.byId("service-instantiation-audit-info-mso");
138         assertEquals(3, msoTableElement.findElement(By.tagName("thead")).findElements(By.tagName("th")).size(), "Audit info MSO table must contain 3 columns");
139         assertEquals(requestId, msoTableElement.findElement(By.id("msoRequestId")).getText(), "Audit info Request Id is not equal");
140         assertEquals("Failed", msoTableElement.findElement(By.id("msoJobStatus")).getText(), "Audit info Job Status is not equal");
141         assertEquals(message, msoTableElement.findElement(By.id("msoAdditionalInfo")).getText(), "Audit info AdditionalInfo is not equal");
142
143         vidBasePage.screenshotDeployDialog("retry-audit-info-" + instanceName);
144         Click.byId(Constants.AuditInfoModal.CANCEL_BUTTON);
145         GeneralUIUtils.ultimateWait();
146     }
147
148     private CreateServiceWithFailedVnf createServiceWithFailedVnfAssertStausAndSimulatorRegistration() {
149
150         //CreateServiceWithFailedVnf is common for API test and UI test,
151         //so if you change it, make sure both test are compatible with your changes
152         CreateServiceWithFailedVnf createServiceWithFailedVnf = new CreateServiceWithFailedVnf(asyncInstantiationBase);
153         createServiceWithFailedVnf.createServicesWithVnfCompletedWithError();
154         createServiceWithFailedVnf.firstTimeAssertion();
155         createServiceWithFailedVnf.secondRegistration();
156         return createServiceWithFailedVnf;
157     }
158
159     private void checkRetryRequestToBeComplete(CreateServiceWithFailedVnf createServiceWithFailedVnf, String originalServiceName) {
160         DrawingBoardPage.ServiceStatusChecker serviceStatusChecker = new DrawingBoardPage.ServiceStatusChecker(originalServiceName, Collections.singleton(COMPLETED));
161         //there shall be 2 rows with same service name, one with completed with error and one completed
162         //so the following line might be buggy, and we need to improve it one day ...
163         boolean statusIsShown = Wait.waitFor(serviceStatusChecker, null, 30, 2);
164         assertTrue("service " + originalServiceName + " wasn't completed after in time", statusIsShown);
165         createServiceWithFailedVnf.simulatorCallsAssertion();
166     }
167
168 }