vid-automation selenium tests
[vid.git] / vid-automation / src / main / java / vid / automation / test / test / InstantiationStatusTest.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.JavascriptExecutor;
7 import org.testng.annotations.AfterClass;
8 import org.testng.annotations.BeforeClass;
9 import org.testng.annotations.BeforeMethod;
10 import org.testng.annotations.Test;
11 import vid.automation.test.infra.FeatureTogglingTest;
12 import vid.automation.test.sections.InstantiationStatusPage;
13 import vid.automation.test.sections.SideMenu;
14 import vid.automation.test.services.AsyncJobsService;
15
16 import java.util.UUID;
17
18 import static vid.automation.test.infra.Features.FLAG_ASYNC_INSTANTIATION;
19 import static vid.automation.test.sections.InstantiationStatusPage.assertInstantiationStatusRow;
20 import static vid.automation.test.sections.InstantiationStatusPage.getNumberOfTableRows;
21
22 @FeatureTogglingTest(FLAG_ASYNC_INSTANTIATION)
23 public class InstantiationStatusTest extends VidBaseTestCase {
24
25
26     private final String serviceModelVersion = "1.0";
27     private final String subscriberId = "ac040e8a-b43a-441b-ab87-603f5b70be55";
28     private final String regionId = "my-expected-region-id";
29     private final String projectName = "a-project-name";
30     final static String owningEntityName  = "expected-owningEntityName";
31     final static String subscriberName  = "expected-subscriberName";
32
33
34     private String currentUUI;
35
36     @BeforeClass
37     protected void dropAllAsyncJobs() {
38         AsyncJobsService asyncJobsService = new AsyncJobsService();
39         asyncJobsService.dropAllAsyncJobs();
40     }
41
42     @AfterClass
43     protected void muteAllAsyncJobs() {
44         AsyncJobsService asyncJobsService = new AsyncJobsService();
45         asyncJobsService.muteAllAsyncJobs();
46     }
47
48     @BeforeMethod
49     protected void createJobsData() {
50         addOneJob();
51         SideMenu.navigateToMacroInstantiationStatus();
52     }
53
54     private String addOneJob() {
55         currentUUI = UUID.randomUUID().toString();
56         final JavascriptExecutor javascriptExecutor = (JavascriptExecutor) GeneralUIUtils.getDriver();
57         Object result = javascriptExecutor.executeScript(
58                 "return (function postJob(){var xhttp = new XMLHttpRequest(); " +
59                         "     " +
60                         "  xhttp.onreadystatechange = function() { " +
61                         "    return this.responseText; " +
62                         "  }; " +
63                         " " +
64                         "  xhttp.open(\"POST\", '/vid/asyncInstantiation/bulk', false); " +
65                         "  xhttp.setRequestHeader(\"Content-type\", \"application/json\"); " +
66                         "  xhttp.send(`{ " +
67                         "    \"modelInfo\": { " +
68                         "      \"modelType\": \"service\", " +
69                         "      \"modelInvariantId\": \"300adb1e-9b0c-4d52-bfb5-fa5393c4eabb\", " +
70                         "      \"modelVersionId\": \"5c9e863f-2716-467b-8799-4a67f378dcaa\", " +
71                         "      \"modelName\": \"AIM_TRANSPORT_00004\", " +
72                         "      \"modelVersion\": \"" + serviceModelVersion + "\" " +
73                         "    }, " +
74                         "    \"owningEntityId\" : \"someID\", " +
75                         "    \"owningEntityName\": \"" + owningEntityName + "\", " +
76                         "    \"projectName\" : \"" + projectName + currentUUI + "\", " +
77                         "    \"globalSubscriberId\":  \"" + subscriberId + "\", " +
78                         "    \"subscriberName\":  \"" + subscriberName + "\", " +
79                         "    \"productFamilyId\" : \"myProductFamilyId\", " +
80                         "    \"instanceName\" : \"MichaelJordan\", " +
81                         "    \"subscriptionServiceType\" : \"mySubType\", " +
82                         "    \"lcpCloudRegionId\" : \"" + regionId + "\", " +
83                         "    \"tenantId\" : \"greatTenant\", " +
84                         "    \"bulkSize\": 1, " +
85                         "    \"isUserProvidedNaming\": \"true\", " +
86                         "    \"vnfs\": {} " +
87                         "} `); " +
88                         " " +
89                         "return JSON.parse(xhttp.responseText).entity;})()"
90         );
91
92         return result.toString();
93     }
94
95     @Test
96     public void testServiceInfoIsPresentedInTable() {
97         InstantiationStatusPage.clickRefreshButton();
98
99         assertInstantiationStatusRow(projectName + currentUUI, ImmutableMap.of(
100                 "subscriberName", subscriberName,
101                 "regionId", regionId,
102                 "serviceModelVersion", serviceModelVersion,
103                 "owningEntityName", owningEntityName
104         ));
105     }
106
107
108     @Test
109     public void testServiceInfoDataUpdatingAfterClickRefresh() {
110         long numberOfRows = getNumberOfTableRows(60);
111
112         addOneJob();
113         InstantiationStatusPage.clickRefreshButton();
114         int numberOfRowsAfterRefresh = getNumberOfTableRows(60);
115         Assert.assertEquals(numberOfRows + 1 , numberOfRowsAfterRefresh);
116     }
117
118 }