Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit 998e44a0 authored by Mihai BOZ's avatar Mihai BOZ
Browse files

automated EDTRES-21

parent 3de18c6a
No related branches found
No related tags found
No related merge requests found
Pipeline #257932 failed
Showing
with 207 additions and 19 deletions
......@@ -6,19 +6,29 @@ import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.pagefactory.AjaxElementLocatorFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pages.administration.editResourcesPage.editResourceDocumentPage.SelectResourceDocumentDialog;
import rest.ResourceClient;
/**
* Common Page object for the Subresource Document configuration section. This contains the locators of the page and the methods for the behaviour of the page
*/
public class CommonDocumentConfigurationComponent extends DComponent {
private final static Logger LOG = LoggerFactory.getLogger(CommonDocumentConfigurationComponent.class);
@FindBy(id = "name_id")
private WebElement documentNameInput;
@FindBy(id = "mimeType_id")
private WebElement mimeType;
@FindBy(id = "publishedVersion_id")
private WebElement publishVersion;
@FindBy(id = "sharingEnabled_id-input")
@FindBy(id = "sharingEnabled_id")
private WebElement sharingEnableCheckBox;
@FindBy(css = "document-configuration-panel .mdc-button--unelevated")
private WebElement selectReferenceBtn;
@FindBy(id = "reference-document-name_id")
private WebElement refereceDocumentName;
public CommonDocumentConfigurationComponent(WebDriver driver) {
super(driver);
......@@ -28,4 +38,27 @@ public class CommonDocumentConfigurationComponent extends DComponent {
public String getDocumentPublishedVersion() {
return weToDInput(publishVersion).getText();
}
public void enableSharing() throws Exception {
weToDChecked(sharingEnableCheckBox).check();
LOG.debug("Sharing document was enabled");
}
public void disableSharing() throws Exception {
weToDChecked(sharingEnableCheckBox).uncheck();
LOG.debug("Sharing document was disabled");
}
public SelectResourceDocumentDialog clickOnSelectRefenceBtn(){
weToDButton(selectReferenceBtn).click();
return new SelectResourceDocumentDialog(driver);
}
public String getReferenceDocumentName(){
return weToDInput(refereceDocumentName).getText();
}
}
......@@ -2,6 +2,7 @@ package pages.administration.editResourcesPage.common;
import ddsl.DomiSMPPage;
import ddsl.dcomponents.ConfirmationDialog;
import ddsl.dcomponents.mat.MatSelect;
import ddsl.dobjects.DButton;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
......@@ -32,16 +33,13 @@ public class CommonEditDocumentPage extends DomiSMPPage {
private WebElement generateBtn;
@FindBy(id = "validateResource_id")
private WebElement validateBtn;
@FindBy(css = "smp-titled-label[title=\"Resource identifier:\"] div.smp-tl-value")
private WebElement resourceIdentifierLbl;
@FindBy(css = "smp-titled-label[title=\"Resource scheme:\"] div.smp-tl-value")
private WebElement resourceSchemeLbl;
@FindBy(css = "smp-titled-label[title=\"Document name:\"] div.smp-tl-value")
private WebElement documentNameLbl;
@FindBy(css = "mat-select[formcontrolname=\"selectDocumentSource\"]")
private WebElement viewDocumentDdl;
@FindBy(css = "smp-titled-label[title=\"Document mimeType:\"] div.smp-tl-value")
private WebElement documentMimeTypeLbl;
@FindBy(css = "smp-titled-label[title=\"Current document version:\"] div.smp-tl-value")
private WebElement currentDocumentVersionLbl;
@FindBy(id = "back_id")
// Bottom page buttons
private WebElement backBtn;
@FindBy(id = "saveResource_id")
private WebElement saveBtn;
@FindBy(id = "cancel_id")
......@@ -58,9 +56,7 @@ public class CommonEditDocumentPage extends DomiSMPPage {
private WebElement codeEditorSendValueElement;
@FindBy(css = "div.cm-line")
private List<WebElement> codeEditorReadValueElement;
///// Right Menu buttons
// Right Menu buttons
@FindBy(css = ".panel > expandable-panel:nth-child(2) > div:nth-child(1) > div:nth-child(2) button:nth-of-type(2)")
private WebElement currentDocumentVersionsMenuBtn;
@FindBy(css = ".panel > expandable-panel:nth-child(2) > div:nth-child(1) > div:nth-child(2) button:nth-of-type(3)")
......@@ -108,16 +104,20 @@ public class CommonEditDocumentPage extends DomiSMPPage {
weToDButton(generateBtn).click();
}
public void clickOnSave() {
weToDButton(saveBtn).click();
public void clickOnBack() {
weToDButton(backBtn).click();
}
public void clickOnCancelAndConfirm() {
weToDButton(cancelBtn).click();
new ConfirmationDialog(driver).confirm();
}
public void clickOnSave() {
weToDButton(saveBtn).click();
}
public DButton getRequestReviewBtn() {
return weToDButton(reviewRequestBtn);
}
......@@ -153,7 +153,7 @@ public class CommonEditDocumentPage extends DomiSMPPage {
weToMatSelect(versionDdl).selectByVisibleText(String.valueOf(version));
}
public SubresourceDocumentConfigurationSection getDocumentConfiguration() {
public SubresourceDocumentConfigurationSection getDocumentConfigurationSection() {
weToDButton(documentConfigurationMenuBtn).click();
//Click again to remove the tooltip of the button
weToDButton(documentConfigurationMenuBtn).click();
......@@ -170,4 +170,8 @@ public class CommonEditDocumentPage extends DomiSMPPage {
LOG.debug("Opening Document properties section.");
return new SubresourceDocumentPropertiesSection(driver);
}
public MatSelect getViewDocumentSelect() {
return weToMatSelect(viewDocumentDdl);
}
}
package pages.administration.editResourcesPage.common;
import ddsl.dcomponents.DComponent;
import ddsl.dcomponents.Grid.SmallGrid;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.pagefactory.AjaxElementLocatorFactory;
public class CommonSelectReferenceDialog extends DComponent {
@FindBy(id = "resource-value_id")
private WebElement resourceValueInput;
@FindBy(id = "resource-scheme_id")
private WebElement resourceSchemeInput;
@FindBy(id = "searchbutton_id")
private WebElement searchBtn;
@FindBy(id = "saveButton")
private WebElement saveBtn;
@FindBy(css = ".mat-mdc-dialog-content")
private WebElement panel;
public CommonSelectReferenceDialog(WebDriver driver) {
super(driver);
PageFactory.initElements(new AjaxElementLocatorFactory(driver, data.getWaitTimeShort()), this);
}
public SmallGrid getGrid() {
return new SmallGrid(driver, panel);
}
public void selectResourceReferenceByResourceIdentifier(String resourceIdentifier) {
weToDInput(resourceValueInput).fill(resourceIdentifier);
weToDButton(searchBtn).click();
getGrid().searchAndClickElementInColumn("Res. value", resourceIdentifier);
weToDButton(saveBtn).click();
}
}
......@@ -3,6 +3,8 @@ package pages.administration.editResourcesPage.editResourceDocumentPage;
import org.openqa.selenium.WebDriver;
import pages.administration.editResourcesPage.common.CommonEditDocumentPage;
import javax.xml.parsers.ParserConfigurationException;
/**
* Page object for the Edit resource document page. This contains the locators of the page and the methods for the behaviour of the page
*/
......@@ -17,5 +19,9 @@ public class EditResourceDocumentPage extends CommonEditDocumentPage {
return new EditResourceDocumentWizardDialog(driver);
}
public ResourceDocumentEditor getEditor() throws ParserConfigurationException {
return new ResourceDocumentEditor(this.getDocumentValue());
}
}
package pages.administration.editResourcesPage.editResourceDocumentPage;
import utils.XMLUtils;
import javax.xml.parsers.ParserConfigurationException;
public class ResourceDocumentEditor extends XMLUtils {
public ResourceDocumentEditor(String xmlStr) throws ParserConfigurationException {
super(xmlStr);
}
public void addExtensionTag() {
addNewNode("ServiceGroup", "Extension", "");
setAttributeValueForNode("Extension", "xmlns", "http://docs.oasis-open.org/bdxr/ns/SMP/2016/05");
}
public void addNewExtesionCode(String nodeName, String attributXmlnsValue, String nodeValue) {
addNewNode("Extension", "ext:" + nodeName, nodeValue);
setAttributeValueForNode("ext:" + nodeName, "xmlns:ext", attributXmlnsValue);
}
}
package pages.administration.editResourcesPage.editResourceDocumentPage;
import org.openqa.selenium.WebDriver;
import pages.administration.editResourcesPage.common.CommonSelectReferenceDialog;
public class SelectResourceDocumentDialog extends CommonSelectReferenceDialog {
public SelectResourceDocumentDialog(WebDriver driver) {
super(driver);
}
}
package utils;
import org.apache.xerces.dom.DeferredElementNSImpl;
import org.apache.xerces.dom.ElementImpl;
import org.apache.xml.serialize.OutputFormat;
import org.apache.xml.serialize.XMLSerializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
......@@ -60,7 +62,7 @@ public class XMLUtils {
public void setAttributeValueForNode(String nodeName, String attributeName, String attributeValue) {
NodeList nList = doc.getElementsByTagName(nodeName);
Node nNode = nList.item(0);
((DeferredElementNSImpl) nNode).setAttribute(attributeName, attributeValue);
((ElementImpl) nNode).setAttribute(attributeName, attributeValue);
}
public String getNodeValue(String nodeName) {
......@@ -70,4 +72,18 @@ public class XMLUtils {
}
return null;
}
public String getAttributeValueForNode(String nodeName, String attributeName) {
NodeList nList = doc.getElementsByTagName(nodeName);
Node nNode = nList.item(0);
return ((DeferredElementNSImpl) nNode).getAttribute(attributeName);
}
public void addNewNode(String parentNode, String newNode, String newNodeText) {
Element newElement = doc.createElement(newNode);
newElement.appendChild(doc.createTextNode(newNodeText));
Node parentN = doc.getElementsByTagName(parentNode).item(0); // Or find the specific parent node you want
parentN.appendChild(newElement);
}
}
......@@ -13,6 +13,8 @@ import pages.administration.editResourcesPage.CreateSubresourceDetailsDialog;
import pages.administration.editResourcesPage.EditResourcePage;
import pages.administration.editResourcesPage.editResourceDocumentPage.EditResourceDocumentPage;
import pages.administration.editResourcesPage.editResourceDocumentPage.EditResourceDocumentWizardDialog;
import pages.administration.editResourcesPage.editResourceDocumentPage.ResourceDocumentEditor;
import pages.administration.editResourcesPage.editResourceDocumentPage.SelectResourceDocumentDialog;
import pages.administration.editResourcesPage.editSubresourceDocumentPage.EditSubresourceDocumentPage;
import pages.administration.editResourcesPage.editSubresourceDocumentPage.SubresourceDocumentPropertiesSection;
import pages.administration.editResourcesPage.editSubresourceDocumentPage.SubresourceWizardDialog;
......@@ -313,7 +315,6 @@ public class EditResourcePgTests extends SeleniumTest {
error = editResourceDocumentPage.getAlertArea().getAlertMessage();
soft.assertTrue(error.startsWith("Invalid request [StoreResourceValidation]. Error: ResourceException: Participant identifiers don't match between URL parameter [ResourceIdentifier"), "Wrong error message for invalid participant identifier: ");
soft.assertAll();
}
......@@ -337,7 +338,7 @@ public class EditResourcePgTests extends SeleniumTest {
EditSubresourceDocumentPage editSubresourceDocumentPage = editResourcePage.getSubresourceTab().editSubresouceDocument(subresourceModel);
//validate document metadata
soft.assertEquals(editSubresourceDocumentPage.getDocumentConfiguration().getDocumentPublishedVersion(), "1", "Published version is wrong");
soft.assertEquals(editSubresourceDocumentPage.getDocumentConfigurationSection().getDocumentPublishedVersion(), "1", "Published version is wrong");
SubresourceDocumentPropertiesSection subresourceDocumentPropertiesSection = editSubresourceDocumentPage.getDocumentPropertiesSection();
soft.assertEquals(subresourceDocumentPropertiesSection.getPropertyValue("document.name"), subresourceModel.getIdentifierValue(), "Document name is wrong!");
......@@ -494,6 +495,60 @@ public class EditResourcePgTests extends SeleniumTest {
soft.assertEquals(documentXML.getNodeValue("EndpointURI"), "www.domibustest.com", "EndpointURI value is wrong");
soft.assertAll();
}
@Test(description = "EDTRES-21- Resource Administrator can share a document as reference by clicking on the sharing enabled", priority = 1)
public void resourceAdministratorCanShareADocumentAsAReferenceByClickingOnSharingEnabled() throws Exception {
ResourceModel resourceModelOasis1ToBeShared = ResourceModel.generatePublicResource(ResourceTypes.OASIS1);
ResourceModel resourceModelOasis1UsesReference = ResourceModel.generatePublicResource(ResourceTypes.OASIS1);
//add resource to group
resourceModelOasis1ToBeShared = rest.resources().createResourceForGroup(domainModel, groupModel, resourceModelOasis1ToBeShared);
resourceModelOasis1UsesReference = rest.resources().createResourceForGroup(domainModel, groupModel, resourceModelOasis1UsesReference);
rest.resources().addMembersToResource(domainModel, groupModel, resourceModelOasis1ToBeShared, adminMember);
rest.resources().addMembersToResource(domainModel, groupModel, resourceModelOasis1UsesReference, adminMember);
//Select resource and document to be shared
editResourcePage.refreshPage();
editResourcePage.selectDomain(domainModel, groupModel, resourceModelOasis1ToBeShared);
EditResourceDocumentPage editResourceDocumentPage = editResourcePage.getResourceDetailsTab().clickOnEditDocument();
editResourceDocumentPage.clickOnNewVersion();
//Add extension tag to highlight the reference
ResourceDocumentEditor editor = editResourceDocumentPage.getEditor();
editor.addExtensionTag();
editor.addNewExtesionCode("referenceNode", "test", "referenceValue");
editResourceDocumentPage.setDocumentValue(editor.printDoc());
editResourceDocumentPage.clickOnSave();
editResourceDocumentPage.clickOnPublishAndConfirm();
editResourceDocumentPage.getDocumentConfigurationSection().enableSharing();
editResourceDocumentPage.clickOnSave();
editResourceDocumentPage.clickOnBack();
//Select resource and document which will use as a reference the shared document
editResourcePage.selectDomain(domainModel, groupModel, resourceModelOasis1UsesReference);
editResourceDocumentPage = editResourcePage.getResourceDetailsTab().clickOnEditDocument();
SelectResourceDocumentDialog selectResourceDocumentDialog = editResourceDocumentPage.getDocumentConfigurationSection().clickOnSelectRefenceBtn();
selectResourceDocumentDialog.selectResourceReferenceByResourceIdentifier(resourceModelOasis1ToBeShared.getIdentifierValue());
editResourceDocumentPage.clickOnSave();
soft.assertEquals(editResourceDocumentPage.getDocumentConfigurationSection().getReferenceDocumentName(), resourceModelOasis1ToBeShared.getIdentifierValue(), "Wrong reference name");
soft.assertTrue(editResourceDocumentPage.getViewDocumentSelect().getCurrentText().equals("Reference document"), "View document select current value is wrong");
//Validate that opened document contains the reference
ResourcesPage resourcesPage = editResourceDocumentPage.getSidebar().navigateTo(Pages.SEARCH_RESOURCES);
XMLUtils documentXML = resourcesPage.openURLResouceDocument(resourceModelOasis1UsesReference.getIdentifierValue(), resourceModelOasis1UsesReference.getIdentifierScheme());
soft.assertNotNull(documentXML);
soft.assertEquals(documentXML.getNodeValue("ParticipantIdentifier"), resourceModelOasis1UsesReference.getIdentifierValue(), "Open document does not contain the referenced document");
soft.assertEquals(documentXML.getAttributeValueForNode("ParticipantIdentifier", "scheme"), resourceModelOasis1UsesReference.getIdentifierScheme(), "Open document does not contain the referenced document");
soft.assertEquals(documentXML.getNodeValue("ext:referenceNode"), "referenceValue", "Open document does not contain the referenced document");
soft.assertAll();
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment