Resolving testAssociatePnf
[vid.git] / vid-automation / src / main / java / vid / automation / test / test / AssociatePnfTest.java
1 package vid.automation.test.test;
2
3 import org.junit.Assert;
4 import org.onap.sdc.ci.tests.utilities.GeneralUIUtils;
5 import org.openqa.selenium.WebElement;
6 import org.testng.annotations.BeforeMethod;
7 import org.testng.annotations.Test;
8 import vid.automation.test.Constants;
9 import vid.automation.test.infra.Wait;
10 import vid.automation.test.sections.PnfSearchAssociationPage;
11 import vid.automation.test.sections.SideMenu;
12 import vid.automation.test.sections.VidBasePage;
13 import vid.automation.test.sections.ViewEditPage;
14 import vid.automation.test.services.BulkRegistration;
15 import vid.automation.test.services.SimulatorApi;
16
17 public class AssociatePnfTest extends VidBaseTestCase {
18
19     private VidBasePage vidBasePage = new VidBasePage();
20     private ViewEditPage viewEditPage = new ViewEditPage();
21     private PnfSearchAssociationPage pnfSearchAssociationPage =  new PnfSearchAssociationPage();
22     private String serviceInstanceId = "3f93c7cb-2fd0-4557-9514-e189b7b04f9d";
23     private String pnfInstanceName = "MX_960-F722";
24     private String pnfModelName = "pnf 0";
25
26     @BeforeMethod
27     public void navigateToWelcomePage() {
28         SideMenu.navigateToWelcomePage();
29     }
30
31     @Test
32     public void testAssociatePnf() throws Exception {
33         SimulatorApi.clearAll();
34         BulkRegistration.searchExistingServiceInstance();
35         BulkRegistration.associatePnf();
36
37         goToExistingInstanceById(serviceInstanceId);//vid-test-444
38         addPNF(pnfModelName);//vid-test-444
39         searchPNF(pnfInstanceName);
40         testResultSearchPNF();
41         associatePNF();
42         vidBasePage.assertMsoRequestModal(Constants.ViewEdit.MSO_SUCCESSFULLY_TEXT);
43         vidBasePage.clickCloseButton();
44     }
45
46     @Test
47     public void testRainyAssociatePnf() throws Exception {
48         SimulatorApi.clearAll();
49         BulkRegistration.searchExistingServiceInstance();
50         BulkRegistration.associatePnfError();
51
52         goToExistingInstanceById(serviceInstanceId);
53         addPNF(pnfModelName);
54         searchPNF(pnfInstanceName);
55         associatePNF();
56         vidBasePage.assertMsoRequestModal("Error");
57         vidBasePage.clickCloseButton();
58     }
59
60     @Test
61     public void testRainyChoosePnf() throws Exception {
62         SimulatorApi.clearAll();
63         BulkRegistration.searchExistingServiceInstance();
64         BulkRegistration.associatePnfError();
65
66         goToExistingInstanceById(serviceInstanceId);
67         String pnfName= "pnf 1";
68         GeneralUIUtils.clickOnElementByTestId(Constants.ViewEdit.ADD_VNF_BUTTON_TEST_ID, 60);
69         String message = String.format(Constants.ViewEdit.OPTION_IN_DROPDOWN_NOT_EXISTS,
70                 Constants.ViewEdit.ADD_VNF_BUTTON_TEST_ID,"Add network instance");
71         boolean waitForElementResult = Wait.waitByTestId(Constants.ViewEdit.VNF_OPTION_TEST_ID_PREFIX + pnfName, 60);
72         Assert.assertTrue(message, !waitForElementResult);
73     }
74
75     @Test
76     public void testRainySearchPnfInstance() throws Exception {
77         SimulatorApi.clearAll();
78         BulkRegistration.searchExistingServiceInstance();
79         BulkRegistration.associatePnfError();
80
81         goToExistingInstanceById(serviceInstanceId);
82         addPNF(pnfModelName);
83         searchPNF("AAAAA");
84         Wait.angularHttpRequestsLoaded();
85         WebElement errorMessageWebElement = GeneralUIUtils.getWebElementByTestID(Constants.PnfAssociation.NOT_FOUND_ERROR_TEST_ID, 60);
86         Assert.assertEquals("not found PNF instance, error message not equals the expected message","The specified PNF instance AAAAA does not exist in A&AI.\n" +
87                 "Please note: A&AI is case sensitive",errorMessageWebElement.getText());
88         Assert.assertTrue(Constants.PnfAssociation.NOT_FOUND_ERROR_MESSAGE, errorMessageWebElement!=null);
89         assertAssociateButtonState(false);
90     }
91
92     private void assertAssociateButtonState(boolean shouldBeEnabled) {
93         WebElement associateWebElement = GeneralUIUtils.getWebElementByTestID(Constants.PnfAssociation.ASSOCIATE_PNF_TEST_ID, 60);
94         boolean enabledAssociate=associateWebElement.isEnabled();
95
96         if(shouldBeEnabled) {
97             Assert.assertTrue(Constants.PnfAssociation.PNF_ENABLE_ASSOCIATE_ERROR_MESSAGE, enabledAssociate);
98         }else{
99             Assert.assertTrue(Constants.PnfAssociation.PNF_DISABLE_ASSOCIATE_ERROR_MESSAGE, !enabledAssociate);
100         }
101         GeneralUIUtils.ultimateWait();
102     }
103
104     private void associatePNF() throws InterruptedException {
105         pnfSearchAssociationPage.clickAssociateButton();
106     }
107
108     private void addPNF(String name){
109         viewEditPage.selectNodeInstanceToAdd(name);
110         checkServiceModelInfo();
111         assertAssociateButtonState(false);
112     }
113
114     private void searchPNF(String name){
115         pnfSearchAssociationPage.setPnfName(name);
116         pnfSearchAssociationPage.clickSearchButton();
117     }
118
119     private void testResultSearchPNF(){
120         checkPnfProperties();
121         Wait.angularHttpRequestsLoaded();
122         assertAssociateButtonState(true);
123     }
124
125     private void checkServiceModelInfo() {
126         Wait.angularHttpRequestsLoaded();
127         //Service name
128         String elementTestId = Constants.ServiceModelInfo.INFO_TEST_ID_PREFIX + Constants.ServiceModelInfo.SERVIICE_NAME_KEY;
129         String infoItemText = GeneralUIUtils.getWebElementByTestID(elementTestId, 60).getText();
130         Assert.assertEquals(String.format(Constants.ServiceModelInfo.METADETA_ERROR_MESSAGE,elementTestId),infoItemText,"Demo Service 1");
131         //model name
132         elementTestId = Constants.ServiceModelInfo.INFO_TEST_ID_PREFIX + Constants.ServiceModelInfo.MODEL_NAME;
133         infoItemText = GeneralUIUtils.getWebElementByTestID(elementTestId, 60).getText();
134         Assert.assertEquals(String.format(Constants.ServiceModelInfo.METADETA_ERROR_MESSAGE,elementTestId),infoItemText,"Test Pnf");
135         //service instance name
136         elementTestId = Constants.ServiceModelInfo.INFO_TEST_ID_PREFIX + Constants.ServiceModelInfo.SERVICE_INSTANCE_NAME;
137         infoItemText = GeneralUIUtils.getWebElementByTestID(elementTestId, 60).getText();
138         Assert.assertEquals(String.format(Constants.ServiceModelInfo.METADETA_ERROR_MESSAGE,elementTestId),infoItemText,"vid-test-444");
139         //Model Invariant UUID
140         elementTestId = Constants.ServiceModelInfo.INFO_TEST_ID_PREFIX + Constants.ServiceModelInfo.MODEL_INVARIANT_UUID;
141         infoItemText = GeneralUIUtils.getWebElementByTestID(elementTestId, 60).getText();
142         Assert.assertEquals(String.format(Constants.ServiceModelInfo.METADETA_ERROR_MESSAGE,elementTestId),infoItemText,"61eba322-c758-48f6-8942-1a7625aaaffb");
143         //ubscriber NameModel Invariant UUID
144         elementTestId = Constants.ServiceModelInfo.INFO_TEST_ID_PREFIX + Constants.ServiceModelInfo.SUBSCRIBER_NAME_KEY;
145         infoItemText = GeneralUIUtils.getWebElementByTestID(elementTestId, 60).getText();
146         Assert.assertEquals(String.format(Constants.ServiceModelInfo.METADETA_ERROR_MESSAGE,elementTestId),infoItemText,"SILVIA ROBBINS");
147         //Model Version
148         elementTestId = Constants.ServiceModelInfo.INFO_TEST_ID_PREFIX + Constants.ServiceModelInfo.MODEL_VERSION;
149         infoItemText = GeneralUIUtils.getWebElementByTestID(elementTestId, 60).getText();
150         Assert.assertEquals(String.format(Constants.ServiceModelInfo.METADETA_ERROR_MESSAGE,elementTestId),infoItemText,"0.1");
151         //Model UUID
152         elementTestId = Constants.ServiceModelInfo.INFO_TEST_ID_PREFIX + Constants.ServiceModelInfo.MODEL_UUID;
153         infoItemText = GeneralUIUtils.getWebElementByTestID(elementTestId, 60).getText();
154         Assert.assertEquals(String.format(Constants.ServiceModelInfo.METADETA_ERROR_MESSAGE,elementTestId),infoItemText,"089b1c03-ff6b-4914-8c20-a7de3d375e8d");
155         //Model Customization UUID
156         elementTestId = Constants.ServiceModelInfo.INFO_TEST_ID_PREFIX + Constants.ServiceModelInfo.MODEL_CUSTOMIZATION_UUID;
157         infoItemText = GeneralUIUtils.getWebElementByTestID(elementTestId, 60).getText();
158         Assert.assertEquals(String.format(Constants.ServiceModelInfo.METADETA_ERROR_MESSAGE,elementTestId),infoItemText,"cabf6d26-c362-4444-ba06-f850e8af2d35");
159         //Resource Name
160         elementTestId = Constants.ServiceModelInfo.INFO_TEST_ID_PREFIX + Constants.ServiceModelInfo.RESOURCE_NAME;
161         infoItemText = GeneralUIUtils.getWebElementByTestID(elementTestId, 60).getText();
162         Assert.assertEquals(String.format(Constants.ServiceModelInfo.METADETA_ERROR_MESSAGE,elementTestId),infoItemText,pnfModelName);
163      }
164
165     private void checkPnfProperties() {
166         //Pnf Instance unique name
167         String elementTestId = Constants.PnfAssociation.PNF_INSTANCE_NAME_TEST_ID;
168         String infoItemText = GeneralUIUtils.getWebElementByTestID(elementTestId, 60).getText();
169         Assert.assertEquals(String.format(Constants.PnfAssociation.PNF_INSTANCE_ERROR_MESSAGE,elementTestId),infoItemText,pnfInstanceName);
170         //Pnf Instance name2
171         elementTestId = Constants.PnfAssociation.PNF_INSTANCE_NAME2_TEST_ID;
172         infoItemText = GeneralUIUtils.getWebElementByTestID(elementTestId, 60).getText();
173         Assert.assertEquals(String.format(Constants.PnfAssociation.PNF_INSTANCE_ERROR_MESSAGE,elementTestId),infoItemText,"MX_960-F722-name-2");
174         //Pnf Instance name2 source
175         elementTestId = Constants.PnfAssociation.PNF_INSTANCE_NAME2_SOURCE_TEST_ID;
176         infoItemText = GeneralUIUtils.getWebElementByTestID(elementTestId, 60).getText();
177         Assert.assertEquals(String.format(Constants.PnfAssociation.PNF_INSTANCE_ERROR_MESSAGE,elementTestId),infoItemText,"MX_960-F722-name-2-source");
178         //Pnf Instance Id
179         elementTestId = Constants.PnfAssociation.PNF_INSTANCE_ID_TEST_ID;
180         infoItemText = GeneralUIUtils.getWebElementByTestID(elementTestId, 60).getText();
181         Assert.assertEquals(String.format(Constants.PnfAssociation.PNF_INSTANCE_ERROR_MESSAGE,elementTestId),infoItemText,"MX_960-F722-id");
182         //Pnf Instance Equipment type
183         elementTestId = Constants.PnfAssociation.PNF_INSTANCE_EQUIP_TYPE_TEST_ID;
184         infoItemText = GeneralUIUtils.getWebElementByTestID(elementTestId, 60).getText();
185         Assert.assertEquals(String.format(Constants.PnfAssociation.PNF_INSTANCE_ERROR_MESSAGE,elementTestId),infoItemText,"Switch");
186         //Pnf Instance Equipment vendor
187         elementTestId = Constants.PnfAssociation.PNF_INSTANCE_EQUIP_VENDOR_TEST_ID;
188         infoItemText = GeneralUIUtils.getWebElementByTestID(elementTestId, 60).getText();
189         Assert.assertEquals(String.format(Constants.PnfAssociation.PNF_INSTANCE_ERROR_MESSAGE,elementTestId),infoItemText,"Cisco");
190         //Pnf Instance Equipment model
191         elementTestId = Constants.PnfAssociation.PNF_INSTANCE_EQUIP_MODEL_TEST_ID;
192         infoItemText = GeneralUIUtils.getWebElementByTestID(elementTestId, 60).getText();
193         Assert.assertEquals(String.format(Constants.PnfAssociation.PNF_INSTANCE_ERROR_MESSAGE,elementTestId),infoItemText,"ASR1002-X");
194     }
195 }