Skip to content
Snippets Groups Projects
Commit b10011cc authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Added test case for task #3892

parent eee6557b
No related branches found
No related tags found
No related merge requests found
...@@ -119,8 +119,14 @@ public class NodeDAO { ...@@ -119,8 +119,14 @@ public class NodeDAO {
return Optional.of(node); return Optional.of(node);
} }
public Node setNode(Node newNode) { public Node setNode(Node newNode) {
return setNode(newNode, false);
}
/**
* If recursive flag is true the update is applied to children too.
*/
public Node setNode(Node newNode, boolean recursive) {
String vosPath = NodeUtils.getVosPath(newNode); String vosPath = NodeUtils.getVosPath(newNode);
......
...@@ -3,7 +3,10 @@ package it.inaf.oats.vospace.persistence; ...@@ -3,7 +3,10 @@ package it.inaf.oats.vospace.persistence;
import it.inaf.oats.vospace.datamodel.NodeProperties; import it.inaf.oats.vospace.datamodel.NodeProperties;
import it.inaf.oats.vospace.exception.InternalFaultException; import it.inaf.oats.vospace.exception.InternalFaultException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
import javax.sql.DataSource; import javax.sql.DataSource;
import net.ivoa.xml.vospace.v2.ContainerNode; import net.ivoa.xml.vospace.v2.ContainerNode;
import net.ivoa.xml.vospace.v2.DataNode; import net.ivoa.xml.vospace.v2.DataNode;
...@@ -58,7 +61,7 @@ public class NodeDAOTest { ...@@ -58,7 +61,7 @@ public class NodeDAOTest {
assertEquals("true", NodeProperties.getNodePropertyAsListByURI(root, NodeProperties.PUBLIC_READ_URI).get(0)); assertEquals("true", NodeProperties.getNodePropertyAsListByURI(root, NodeProperties.PUBLIC_READ_URI).get(0));
assertEquals("group1 group2", getProperty(root.getNodes().get(0), "ivo://ivoa.net/vospace/core#groupread")); assertEquals("group1 group2", NodeProperties.getNodePropertyByURI(root.getNodes().get(0), NodeProperties.GROUP_READ_URI));
} }
@Test @Test
...@@ -114,9 +117,7 @@ public class NodeDAOTest { ...@@ -114,9 +117,7 @@ public class NodeDAOTest {
@Test @Test
public void testSetNode() { public void testSetNode() {
Property publicReadProperty = new Property(); Property publicReadProperty = getProperty(NodeProperties.PUBLIC_READ_URI, String.valueOf(false));
publicReadProperty.setUri(NodeProperties.PUBLIC_READ_URI);
publicReadProperty.setValue(String.valueOf(false));
Node node = new DataNode(); Node node = new DataNode();
node.setUri("vos://example.com!vospace/mydata3"); node.setUri("vos://example.com!vospace/mydata3");
...@@ -136,13 +137,61 @@ public class NodeDAOTest { ...@@ -136,13 +137,61 @@ public class NodeDAOTest {
assertEquals("true", NodeProperties.getNodePropertyByURI(node, NodeProperties.PUBLIC_READ_URI)); assertEquals("true", NodeProperties.getNodePropertyByURI(node, NodeProperties.PUBLIC_READ_URI));
} }
private String getProperty(Node node, String uri) { //@Test
for (Property property : node.getProperties()) { public void testSetNodeRecursiveGroup() {
if (uri.equals(property.getUri())) {
return property.getValue(); Property parentGroupRead = getProperty(NodeProperties.GROUP_READ_URI, "group1 group2");
Property parentGroupWrite = getProperty(NodeProperties.GROUP_WRITE_URI, "group2 group3");
Node node = new DataNode();
node.setUri("vos://example.com!vospace/mydata4");
node.getProperties().add(parentGroupRead);
node.getProperties().add(parentGroupWrite);
dao.createNode(node);
Node child1 = new DataNode();
child1.setUri("vos://example.com!vospace/mydata4/child1");
child1.getProperties().add(getProperty(NodeProperties.GROUP_READ_URI, "group3"));
child1.getProperties().add(getProperty(NodeProperties.GROUP_WRITE_URI, "group3 group4"));
dao.createNode(child1);
Node child2 = new DataNode();
child2.setUri("vos://example.com!vospace/mydata4/child1/child2");
child2.getProperties().add(getProperty(NodeProperties.GROUP_READ_URI, "group2 group5"));
child2.getProperties().add(getProperty(NodeProperties.GROUP_WRITE_URI, "group6"));
dao.createNode(child2);
parentGroupRead.setValue("group1 group5"); // remove group2; add group5
parentGroupWrite.setValue("group2 group6"); // remove group3; add group6
// Recursively set node
dao.setNode(node, true);
node = dao.listNode("/mydata4").get();
child1 = dao.listNode("/mydata4/child1").get();
child2 = dao.listNode("/mydata4/child1/child2").get();
checkGroups(NodeProperties.getNodePropertyAsListByURI(node, NodeProperties.GROUP_READ_URI), "group1", "group5");
checkGroups(NodeProperties.getNodePropertyAsListByURI(node, NodeProperties.GROUP_WRITE_URI), "group2", "group6");
checkGroups(NodeProperties.getNodePropertyAsListByURI(child1, NodeProperties.GROUP_READ_URI), "group3", "group5");
checkGroups(NodeProperties.getNodePropertyAsListByURI(child1, NodeProperties.GROUP_WRITE_URI), "group4", "group6");
checkGroups(NodeProperties.getNodePropertyAsListByURI(child2, NodeProperties.GROUP_READ_URI), "group5");
checkGroups(NodeProperties.getNodePropertyAsListByURI(child2, NodeProperties.GROUP_WRITE_URI), "group6");
} }
private Property getProperty(String uri, String value) {
Property property = new Property();
property.setUri(uri);
property.setValue(value);
return property;
} }
return null;
private void checkGroups(List<String> groups, String... expectedGroups) {
Set<String> set1 = new HashSet<>(Arrays.asList(expectedGroups));
Set<String> set2 = new HashSet<>(groups);
assertEquals(set1, set2);
} }
private List<View> getViews() { private List<View> getViews() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment