Skip to content

Commit

Permalink
add node property tests with immutable and invalid props
Browse files Browse the repository at this point in the history
  • Loading branch information
pdowler committed Jan 15, 2024
1 parent f17553d commit a74308f
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cadc-test-vos/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ sourceCompatibility = 1.8

group = 'org.opencadc'

version = '2.1.3'
version = '2.1.4'

description = 'OpenCADC VOSpace test library'
def git_url = 'https://github.com/opencadc/vos'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
******************* CANADIAN ASTRONOMY DATA CENTRE *******************
************** CENTRE CANADIEN DE DONNÉES ASTRONOMIQUES **************
*
* (c) 2023. (c) 2023.
* (c) 2024. (c) 2024.
* Government of Canada Gouvernement du Canada
* National Research Council Conseil national de recherches
* Ottawa, Canada, K1A 0R6 Ottawa, Canada, K1A 0R6
Expand Down Expand Up @@ -142,6 +142,10 @@ public void testContainerNode() {
URL nodeURL = getNodeURL(nodesServiceURL, name);
VOSURI nodeURI = getVOSURI(name);
ContainerNode testNode = new ContainerNode(name);
// try to add an immutable prop at creation: should be ignored
// --- use length aka file size since we are not writing file content
NodeProperty immutable = new NodeProperty(VOS.PROPERTY_URI_CONTENTLENGTH, "123");
testNode.getProperties().add(immutable);

// cleanup
if (nodelockSupported) {
Expand All @@ -164,6 +168,7 @@ public void testContainerNode() {
ContainerNode persistedNode = (ContainerNode) result.node;
Assert.assertEquals(testNode, persistedNode);
Assert.assertEquals(nodeURI, result.vosURI);
Assert.assertFalse(persistedNode.getProperties().contains(immutable)); // ignored

// POST an update to the node
NodeProperty nodeProperty = new NodeProperty(VOS.PROPERTY_URI_LANGUAGE, "English");
Expand All @@ -183,7 +188,20 @@ public void testContainerNode() {
if (nodelockSupported) {
Assert.assertTrue(updatedNode.isLocked);
}

Assert.assertFalse(updatedNode.getProperties().contains(immutable)); // ignored

// fail to update with a sketch property URI
URI illegal = new URI(VOS.VOSPACE_URI_NAMESPACE + "core#make-stuff-up");
NodeProperty illegalProp = new NodeProperty(illegal, "that should not work");
testNode.getProperties().add(illegalProp);
try {
post(nodeURL, nodeURI, testNode, true, 400);
Assert.fail("expected IllegalArgumentException, but updated testNode with " + illegal);
} catch (IllegalArgumentException expected) {
log.info("caught expected Exception: " + expected);
}
testNode.getProperties().remove(illegalProp);

// failed to add a subdirectory (node locked)
if (nodelockSupported) {
String subDirName = name + "/subDir";
Expand Down Expand Up @@ -233,15 +251,23 @@ public void testDataNode() {
// PUT the node
log.info("put: " + nodeURI + " -> " + nodeURL);
DataNode testNode = new DataNode(name);
// try to add an immutable prop at creation: should be ignored
// --- use length aka file size since we are not writing file content
NodeProperty immutable = new NodeProperty(VOS.PROPERTY_URI_CONTENTLENGTH, "123");
testNode.getProperties().add(immutable);
put(nodeURL, nodeURI, testNode);

// GET the new node
NodeReader.NodeReaderResult result = get(nodeURL, 200, XML_CONTENT_TYPE);
log.info("found: " + result.vosURI + " owner: " + result.node.ownerDisplay);
Assert.assertTrue(result.node instanceof DataNode);
DataNode persistedNode = (DataNode) result.node;
for (NodeProperty np : persistedNode.getProperties()) {
log.info("persisted prop: " + np.getKey() + " = " + np.getValue());
}
Assert.assertEquals(testNode, persistedNode);
Assert.assertEquals(nodeURI, result.vosURI);
Assert.assertFalse(persistedNode.getProperties().contains(immutable)); // ignored

// POST an update to the node
NodeProperty nodeProperty = new NodeProperty(VOS.PROPERTY_URI_LANGUAGE, "English");
Expand All @@ -251,10 +277,26 @@ public void testDataNode() {
// GET the updated node
result = get(nodeURL, 200, XML_CONTENT_TYPE);
DataNode updatedNode = (DataNode) result.node;
for (NodeProperty np : updatedNode.getProperties()) {
log.info("updated prop: " + np.getKey() + " = " + np.getValue());
}
Assert.assertEquals(testNode, updatedNode);
Assert.assertEquals(nodeURI, result.vosURI);
Assert.assertEquals(testNode.getName(), updatedNode.getName());
Assert.assertTrue(updatedNode.getProperties().contains(nodeProperty));
Assert.assertFalse(updatedNode.getProperties().contains(immutable)); // ignored

// fail to update with a sketch property URI
URI illegal = new URI(VOS.VOSPACE_URI_NAMESPACE + "core#make-stuff-up");
NodeProperty illegalProp = new NodeProperty(illegal, "that should not work");
testNode.getProperties().add(illegalProp);
try {
post(nodeURL, nodeURI, testNode, true, 400);
Assert.fail("expected IllegalArgumentException, but updated testNode with " + illegal);
} catch (IllegalArgumentException expected) {
log.info("caught expected Exception: " + expected);
}
testNode.getProperties().remove(illegalProp);

if (cleanupOnSuccess) {
delete(nodeURL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,15 @@ public NodeReader.NodeReaderResult get(URL url, int responseCode, String content
}
}

public void post(URL nodeURL, VOSURI vosURI, Node node) throws IOException {
post(nodeURL, vosURI, node, true);
public void post(URL nodeURL, VOSURI vosURI, Node node) throws Exception {
post(nodeURL, vosURI, node, true, 200);
}

public void post(URL nodeURL, VOSURI vosURI, Node node, boolean verify) throws IOException {
public void post(URL nodeURL, VOSURI vosURI, Node node, boolean verify) throws Exception {
post(nodeURL, vosURI, node, verify, 200);
}

public void post(URL nodeURL, VOSURI vosURI, Node node, boolean verify, int expectedCode) throws Exception {
StringBuilder sb = new StringBuilder();
NodeWriter writer = new NodeWriter();
writer.write(vosURI, node, sb, VOS.Detail.max);
Expand All @@ -278,8 +282,12 @@ public void post(URL nodeURL, VOSURI vosURI, Node node, boolean verify) throws I
if (!verify && post.getResponseCode() == 404) {
return;
}
Assert.assertEquals("expected POST response code = 200",
200, post.getResponseCode());
Assert.assertEquals("expected POST response code = " + expectedCode,
expectedCode, post.getResponseCode());
if (expectedCode >= 400) {
Assert.assertNotNull(post.getThrowable());
throw (Exception) post.getThrowable();
}
Assert.assertNull("expected POST throwable == null", post.getThrowable());
}

Expand Down Expand Up @@ -329,7 +337,7 @@ protected void cleanupNodeTree(String[] nodes) throws MalformedURLException {
}

protected void makeWritable(String[] subdirNames, GroupURI accessGroup)
throws NodeParsingException, NodeNotSupportedException, IOException {
throws Exception {
for (String nodeName : subdirNames) {
URL nodeURL = getNodeURL(nodesServiceURL, nodeName);
NodeReader.NodeReaderResult result = get(nodeURL, 200, XML_CONTENT_TYPE);
Expand Down

0 comments on commit a74308f

Please sign in to comment.