aboutsummaryrefslogtreecommitdiffstats
path: root/vid-automation/src/main/java/vid/automation/test/test/InstantiationStatusTest.java
blob: a3480f8c2ced2e34e15f00c37606279ac547c8bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
package vid.automation.test.test;

import static org.onap.simulator.presetGenerator.presets.mso.PresetMSOServiceInstanceGen2WithNames.Keys.SERVICE_NAME;
import static org.onap.simulator.presetGenerator.presets.mso.PresetMSOServiceInstanceGen2WithNames.Keys.VNF_NAME;
import static org.testng.Assert.assertEquals;
import static org.testng.AssertJUnit.assertTrue;
import static vid.automation.test.Constants.DrawingBoard.DEPLOY_BUTTON;
import static vid.automation.test.infra.Features.FLAG_ASYNC_INSTANTIATION;

import com.google.common.collect.ImmutableMap;
import java.util.Collections;
import org.junit.Assert;
import org.onap.sdc.ci.tests.datatypes.UserCredentials;
import org.onap.sdc.ci.tests.utilities.GeneralUIUtils;
import org.onap.simulator.presetGenerator.presets.mso.PresetMSOServiceInstanceGen2WithNames;
import org.onap.vid.api.AsyncInstantiationBase;
import org.onap.vid.api.CreateServiceWithFailedVnf;
import org.onap.vid.api.TestUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import vid.automation.test.Constants;
import vid.automation.test.infra.Click;
import vid.automation.test.infra.FeatureTogglingTest;
import vid.automation.test.infra.Features;
import vid.automation.test.infra.Get;
import vid.automation.test.infra.Wait;
import vid.automation.test.sections.DrawingBoardPage;
import vid.automation.test.sections.InstantiationStatusPage;
import vid.automation.test.sections.SideMenu;
import vid.automation.test.sections.VidBasePage;
import vid.automation.test.services.AsyncJobsService;

@FeatureTogglingTest(FLAG_ASYNC_INSTANTIATION)
public class InstantiationStatusTest extends VidBaseTestCase {

    private final String serviceModelVersion = "5.1";
    private final String regionId = "a93f8383-707e-43fa-8191-a6e69a1aab17";
    final static String owningEntityName  = "Lucine Sarika";
    final static String subscriberName  = "SILVIA ROBBINS";
    private static final String COMPLETED = "COMPLETED";
    private static final String CREATE_BULK_OF_ALACARTE_REQUEST = "asyncInstantiation/vidRequestCreateALaCarte.json";
    private final VidBasePage vidBasePage = new VidBasePage();

    private AsyncInstantiationBase asyncInstantiationBase;

    @BeforeClass
    protected void dropAllAsyncJobs() {
        AsyncJobsService asyncJobsService = new AsyncJobsService();
        asyncJobsService.dropAllAsyncJobs();
        asyncInstantiationBase = new AsyncInstantiationBase();
        asyncInstantiationBase.init();
        UserCredentials userCredentials = getUserCredentials();
        //login for API test (needed besides selenium test via browser)
        asyncInstantiationBase.login(userCredentials);
    }

    @AfterClass
    protected void muteAllAsyncJobs() {
        AsyncJobsService asyncJobsService = new AsyncJobsService();
        asyncJobsService.muteAllAsyncJobs();
    }

    private String addOneJob() {
        String serviceName = TestUtils.generateRandomAlphaNumeric(8);
        final ImmutableMap<PresetMSOServiceInstanceGen2WithNames.Keys, String> names =
                ImmutableMap.of(SERVICE_NAME, serviceName);
        asyncInstantiationBase.createBulkOfInstances(false, 1, names, CREATE_BULK_OF_ALACARTE_REQUEST).get(0);
        return serviceName;
    }

    @Test
    public void testServiceInfoIsPresentedInTable() {
        String serviceName = addOneJob();
        SideMenu.navigateToMacroInstantiationStatus();
        InstantiationStatusPage.clickRefreshButton();

        InstantiationStatusPage.assertInstantiationStatusRow(serviceName, ImmutableMap.of(
                "subscriberName", subscriberName,
                "regionId", regionId,
                "serviceModelVersion", serviceModelVersion,
                "owningEntityName", owningEntityName
        ));
    }

    @Test
    public void testServiceInfoDataUpdatingAfterClickRefresh() {
        addOneJob();
        SideMenu.navigateToMacroInstantiationStatus();
        InstantiationStatusPage.clickRefreshButton();
        long numberOfRows = InstantiationStatusPage.getNumberOfTableRows(60);

        addOneJob();
        InstantiationStatusPage.clickRefreshButton();
        int numberOfRowsAfterRefresh = InstantiationStatusPage.getNumberOfTableRows(60);
        Assert.assertEquals(numberOfRows + 1 , numberOfRowsAfterRefresh);
    }
    
    @Test
    @FeatureTogglingTest(Features.FLAG_1902_RETRY_JOB)
    public void testRedeployFromDrawingBoardOfServiceWithFailedVnf() {
        SideMenu.navigateToMacroInstantiationStatus();

        CreateServiceWithFailedVnf createServiceWithFailedVnf = createServiceWithFailedVnfAssertStausAndSimulatorRegistration();
        String originalServiceName = createServiceWithFailedVnf.getNames().get(SERVICE_NAME);

        InstantiationStatusPage.clickRefreshButton();

        //Open job
        InstantiationStatusPage.openDrawingBoardForRetry(originalServiceName);
        DrawingBoardPage.goToIframe();

        Wait.waitByTestId("error-msg-wrapper", 10);
        boolean isErrorShown = Wait.waitByClassAndText("sub-title", "Attention: You are currently viewing instances from the MSO. 1 of the instances failed, please try again.", 10);
        assertTrue(isErrorShown);

        //validate audit info for failed vnf
        String originalVnfName = createServiceWithFailedVnf.getNames().get(VNF_NAME);
        hoverAndClickMenuByName(originalVnfName, "fe042c22-ba82-43c6-b2f6-8f1fc4164091-vSAMP12 1", Constants.DrawingBoard.CONTEXT_MENU_SHOW_AUDIT);
        checkFailedAuditInfoOnRetry(originalVnfName, createServiceWithFailedVnf.getFirstIds().vnfReqId, "Vnf failed.");

        Click.byTestId(DEPLOY_BUTTON);
        VidBasePage.goOutFromIframe();
        GeneralUIUtils.ultimateWait();
        vidBasePage.goToIframe();
        GeneralUIUtils.ultimateWait();

        checkRetryRequestToBeComplete(createServiceWithFailedVnf, originalServiceName);
    }

    private void checkFailedAuditInfoOnRetry(String instanceName, String requestId, String message) {
        WebElement webElement = Get.byTestId("model-item-value-instance_name");
        assertEquals(webElement.getText(), instanceName, "Instance Name must be equal");

        WebElement msoTableElement = Get.byId("service-instantiation-audit-info-mso");
        assertEquals(3, msoTableElement.findElement(By.tagName("thead")).findElements(By.tagName("th")).size(), "Audit info MSO table must contain 3 columns");
        assertEquals(requestId, msoTableElement.findElement(By.id("msoRequestId")).getText(), "Audit info Request Id is not equal");
        assertEquals("Failed", msoTableElement.findElement(By.id("msoJobStatus")).getText(), "Audit info Job Status is not equal");
        assertEquals(message, msoTableElement.findElement(By.id("msoAdditionalInfo")).getText(), "Audit info AdditionalInfo is not equal");

        vidBasePage.screenshotDeployDialog("retry-audit-info-" + instanceName);
        Click.byId(Constants.AuditInfoModal.CANCEL_BUTTON);
        GeneralUIUtils.ultimateWait();
    }

    private CreateServiceWithFailedVnf createServiceWithFailedVnfAssertStausAndSimulatorRegistration() {

        //CreateServiceWithFailedVnf is common for API test and UI test,
        //so if you change it, make sure both test are compatible with your changes
        CreateServiceWithFailedVnf createServiceWithFailedVnf = new CreateServiceWithFailedVnf(asyncInstantiationBase);
        createServiceWithFailedVnf.createServicesWithVnfCompletedWithError();
        createServiceWithFailedVnf.firstTimeAssertion();
        createServiceWithFailedVnf.secondRegistration();
        return createServiceWithFailedVnf;
    }

    private void checkRetryRequestToBeComplete(CreateServiceWithFailedVnf createServiceWithFailedVnf, String originalServiceName) {
        DrawingBoardPage.ServiceStatusChecker serviceStatusChecker = new DrawingBoardPage.ServiceStatusChecker(originalServiceName, Collections.singleton(COMPLETED));
        //there shall be 2 rows with same service name, one with completed with error and one completed
        //so the following line might be buggy, and we need to improve it one day ...
        boolean statusIsShown = Wait.waitFor(serviceStatusChecker, null, 30, 2);
        assertTrue("service " + originalServiceName + " wasn't completed after in time", statusIsShown);
        createServiceWithFailedVnf.simulatorCallsAssertion();
    }

}