Skip to content

Commit

Permalink
fix: fix deletion of body artifacts, previously generating a bug due …
Browse files Browse the repository at this point in the history
…to incorrect parsing of URI
  • Loading branch information
cake-lier committed Jan 28, 2024
1 parent 266fc42 commit 31c986a
Show file tree
Hide file tree
Showing 9 changed files with 504 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.regex.Pattern;
import java.util.stream.Stream;
import org.apache.commons.lang3.function.Failable;
import org.apache.http.HttpStatus;
Expand Down Expand Up @@ -468,7 +469,12 @@ private void handleDeleteEntity(final IRI requestIri, final Message<RdfStoreMess
final var artifactIri = requestIri.toString();
final var workspaceIri =
RdfModelUtils.createIri(
artifactIri.substring(0, artifactIri.indexOf("/artifacts"))
Pattern.compile("^(https?://.*?:[0-9]+/workspaces/.*?)/(?:artifacts|agents)/.*?$")
.matcher(artifactIri)
.results()
.map(r -> r.group(1))
.findFirst()
.orElseThrow()
);
this.store
.getEntityModel(workspaceIri)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,91 @@ public void testCreateAndGetArtifact(final VertxTestContext ctx)
.onComplete(ctx.succeedingThenComplete());
}

@Test
public void testCreateAndGetBody(final VertxTestContext ctx)
throws URISyntaxException, IOException {
final var bodyRepresentation =
Files.readString(
Path.of(ClassLoader.getSystemResource("test_agent_body_test.ttl").toURI()),
StandardCharsets.UTF_8
);
final var bodyArtifactRepresentation =
Files.readString(
Path.of(ClassLoader.getSystemResource("output_test_agent_body_test.ttl").toURI()),
StandardCharsets.UTF_8
);
final var outputParentWorkspaceRepresentation =
Files.readString(
Path.of(ClassLoader.getSystemResource("test_workspace_body_td.ttl").toURI()),
StandardCharsets.UTF_8
);
this.assertWorkspaceCreated(
ctx,
Files.readString(
Path.of(ClassLoader.getSystemResource("output_test_workspace_td.ttl").toURI()),
StandardCharsets.UTF_8
),
Files.readString(
Path.of(ClassLoader.getSystemResource("platform_test_td.ttl").toURI()),
StandardCharsets.UTF_8
)
)
.compose(r -> this.storeMessagebox
.sendMessage(new RdfStoreMessage.CreateBody(
TEST_WORKSPACE_NAME,
"test",
bodyRepresentation
))
)
.onSuccess(r -> {
try {
RdfStoreVerticleTestHelpers.assertEqualsThingDescriptions(
bodyArtifactRepresentation,
r.body()
);
final var entityUpdatedMessage =
(HttpNotificationDispatcherMessage.EntityChanged) this.notificationQueue.take();
Assertions.assertEquals(
WORKSPACES_PATH + TEST_WORKSPACE_NAME,
entityUpdatedMessage.requestIri(),
URIS_EQUAL_MESSAGE
);
RdfStoreVerticleTestHelpers.assertEqualsThingDescriptions(
outputParentWorkspaceRepresentation,
entityUpdatedMessage.content()
);
final var entityCreatedMessage =
(HttpNotificationDispatcherMessage.EntityCreated) this.notificationQueue.take();
Assertions.assertEquals(
"http://localhost:8080/workspaces/test/agents/",
entityCreatedMessage.requestIri(),
URIS_EQUAL_MESSAGE
);
RdfStoreVerticleTestHelpers.assertEqualsThingDescriptions(
bodyArtifactRepresentation,
entityCreatedMessage.content()
);
} catch (final Exception e) {
ctx.failNow(e);
}
})
.compose(r -> this.storeMessagebox.sendMessage(new RdfStoreMessage.GetEntity(
WORKSPACES_PATH + TEST_WORKSPACE_NAME
)))
.onSuccess(r -> RdfStoreVerticleTestHelpers.assertEqualsThingDescriptions(
outputParentWorkspaceRepresentation,
r.body()
))
.compose(r -> this.storeMessagebox.sendMessage(new RdfStoreMessage.GetEntity(
"http://localhost:8080/workspaces/test/agents/test"
)))
.onSuccess(r -> RdfStoreVerticleTestHelpers.assertEqualsThingDescriptions(
bodyArtifactRepresentation,
r.body()
))
.onComplete(ctx.succeedingThenComplete());
}

private Future<Message<String>> assertWorkspaceCreated(
final VertxTestContext ctx,
final String outputWorkspaceRepresentation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void testDeleteAndGetWorkspace(final VertxTestContext ctx)
throws URISyntaxException, IOException {
final var deletedWorkspaceDescription =
Files.readString(
Path.of(ClassLoader.getSystemResource("test_workspace_sub_td.ttl").toURI()),
Path.of(ClassLoader.getSystemResource("test_workspace_sub_body_td.ttl").toURI()),
StandardCharsets.UTF_8
);
final var platformDescription =
Expand Down Expand Up @@ -147,6 +147,20 @@ public void testDeleteAndGetWorkspace(final VertxTestContext ctx)
deletionMessage.requestIri(),
URIS_EQUAL_MESSAGE
);
final var bodyDeletionMessage =
(HttpNotificationDispatcherMessage.EntityDeleted) this.notificationQueue.take();
RdfStoreVerticleTestHelpers.assertEqualsThingDescriptions(
Files.readString(
Path.of(ClassLoader.getSystemResource("output_test_agent_body_test.ttl").toURI()),
StandardCharsets.UTF_8
),
bodyDeletionMessage.content()
);
Assertions.assertEquals(
TEST_WORKSPACE_URI + "/agents/test",
bodyDeletionMessage.requestIri(),
URIS_EQUAL_MESSAGE
);
final var subWorkspaceDeletionMessage =
(HttpNotificationDispatcherMessage.EntityDeleted) this.notificationQueue.take();
RdfStoreVerticleTestHelpers.assertEqualsThingDescriptions(
Expand Down Expand Up @@ -211,7 +225,7 @@ public void testDeleteAndGetSubWorkspace(final VertxTestContext ctx)
);
final var parentWorkspaceDescription =
Files.readString(
Path.of(ClassLoader.getSystemResource("output_test_workspace_td.ttl").toURI()),
Path.of(ClassLoader.getSystemResource("test_workspace_body_td.ttl").toURI()),
StandardCharsets.UTF_8
);
final var platformDescription =
Expand All @@ -232,10 +246,7 @@ public void testDeleteAndGetSubWorkspace(final VertxTestContext ctx)
final var parentWorkspaceUpdateMessage =
(HttpNotificationDispatcherMessage.EntityChanged) this.notificationQueue.take();
RdfStoreVerticleTestHelpers.assertEqualsThingDescriptions(
Files.readString(
Path.of(ClassLoader.getSystemResource("output_test_workspace_td.ttl").toURI()),
StandardCharsets.UTF_8
),
parentWorkspaceDescription,
parentWorkspaceUpdateMessage.content()
);
Assertions.assertEquals(
Expand All @@ -246,10 +257,7 @@ public void testDeleteAndGetSubWorkspace(final VertxTestContext ctx)
final var deletionMessage =
(HttpNotificationDispatcherMessage.EntityDeleted) this.notificationQueue.take();
RdfStoreVerticleTestHelpers.assertEqualsThingDescriptions(
Files.readString(
Path.of(ClassLoader.getSystemResource("sub_workspace_c0_td.ttl").toURI()),
StandardCharsets.UTF_8
),
deletedWorkspaceDescription,
deletionMessage.content()
);
Assertions.assertEquals(
Expand Down Expand Up @@ -315,7 +323,7 @@ public void testDeleteAndGetArtifact(final VertxTestContext ctx)
);
final var parentWorkspaceDescription =
Files.readString(
Path.of(ClassLoader.getSystemResource("test_workspace_sub_td.ttl").toURI()),
Path.of(ClassLoader.getSystemResource("test_workspace_sub_body_td.ttl").toURI()),
StandardCharsets.UTF_8
);
final var platformDescription =
Expand Down Expand Up @@ -393,6 +401,84 @@ public void testDeleteAndGetArtifact(final VertxTestContext ctx)
.onComplete(ctx.succeedingThenComplete());
}

@Test
public void testDeleteAndGetBody(final VertxTestContext ctx)
throws URISyntaxException, IOException {
final var deletedBodyDescription =
Files.readString(
Path.of(ClassLoader.getSystemResource("output_test_agent_body_test.ttl").toURI()),
StandardCharsets.UTF_8
);
final var workspaceDescription =
Files.readString(
Path.of(ClassLoader.getSystemResource("test_workspace_sub_td.ttl").toURI()),
StandardCharsets.UTF_8
);
final var platformDescription =
Files.readString(
Path.of(ClassLoader.getSystemResource("platform_test_td.ttl").toURI()),
StandardCharsets.UTF_8
);
this.assertWorkspaceTreeCreated(ctx)
.compose(r -> this.storeMessagebox.sendMessage(new RdfStoreMessage.DeleteEntity(
TEST_WORKSPACE_URI + "/agents/test"
)))
.onSuccess(r -> {
RdfStoreVerticleTestHelpers.assertEqualsThingDescriptions(
deletedBodyDescription,
r.body()
);
try {
final var parentWorkspaceUpdateMessage =
(HttpNotificationDispatcherMessage.EntityChanged) this.notificationQueue.take();
RdfStoreVerticleTestHelpers.assertEqualsThingDescriptions(
Files.readString(
Path.of(ClassLoader.getSystemResource("test_workspace_sub_td.ttl").toURI()),
StandardCharsets.UTF_8
),
parentWorkspaceUpdateMessage.content()
);
Assertions.assertEquals(
TEST_WORKSPACE_URI,
parentWorkspaceUpdateMessage.requestIri(),
URIS_EQUAL_MESSAGE
);
final var deletionMessage =
(HttpNotificationDispatcherMessage.EntityDeleted) this.notificationQueue.take();
RdfStoreVerticleTestHelpers.assertEqualsThingDescriptions(
deletedBodyDescription,
deletionMessage.content()
);
Assertions.assertEquals(
TEST_WORKSPACE_URI + "/agents/test",
deletionMessage.requestIri(),
URIS_EQUAL_MESSAGE
);
} catch (final Exception e) {
ctx.failNow(e);
}
})
.compose(r -> this.storeMessagebox.sendMessage(new RdfStoreMessage.GetEntity(
TEST_WORKSPACE_URI + "/agents/test"
)))
.onFailure(RdfStoreVerticleTestHelpers::assertNotFound)
.recover(r -> this.storeMessagebox.sendMessage(new RdfStoreMessage.GetEntity(
TEST_WORKSPACE_URI
)))
.onSuccess(r -> RdfStoreVerticleTestHelpers.assertEqualsThingDescriptions(
workspaceDescription,
r.body()
))
.compose(r -> this.storeMessagebox.sendMessage(new RdfStoreMessage.GetEntity(
PLATFORM_URI
)))
.onSuccess(r -> RdfStoreVerticleTestHelpers.assertEqualsThingDescriptions(
platformDescription,
r.body()
))
.onComplete(ctx.succeedingThenComplete());
}

private Future<Message<String>> assertWorkspaceTreeCreated(final VertxTestContext ctx)
throws URISyntaxException, IOException {
final var inputWorkspaceRepresentation =
Expand All @@ -410,6 +496,11 @@ private Future<Message<String>> assertWorkspaceTreeCreated(final VertxTestContex
Path.of(ClassLoader.getSystemResource(COUNTER_ARTIFACT_FILE).toURI()),
StandardCharsets.UTF_8
);
final var inputBodyRepresentation =
Files.readString(
Path.of(ClassLoader.getSystemResource("test_agent_body_test.ttl").toURI()),
StandardCharsets.UTF_8
);
return this.storeMessagebox
.sendMessage(new RdfStoreMessage.CreateWorkspace(
"http://localhost:8080/workspaces/",
Expand Down Expand Up @@ -444,6 +535,19 @@ private Future<Message<String>> assertWorkspaceTreeCreated(final VertxTestContex
inputArtifactRepresentation
));
})
.compose(r -> {
try {
this.notificationQueue.take();
this.notificationQueue.take();
} catch (final Exception e) {
ctx.failNow(e);
}
return this.storeMessagebox.sendMessage(new RdfStoreMessage.CreateBody(
"test",
"test",
inputBodyRepresentation
));
})
.onSuccess(r -> {
try {
this.notificationQueue.take();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public void testUpdateAndGetWorkspace(final VertxTestContext ctx)
}

@Test
public void testDeleteAndGetSubWorkspace(final VertxTestContext ctx)
public void testUpdateAndGetSubWorkspace(final VertxTestContext ctx)
throws URISyntaxException, IOException {
final var updatedWorkspaceDescription =
Files.readString(
Expand Down Expand Up @@ -186,7 +186,7 @@ public void testDeleteAndGetSubWorkspace(final VertxTestContext ctx)
}

@Test
public void testDeleteAndGetArtifact(final VertxTestContext ctx)
public void testUpdateAndGetArtifact(final VertxTestContext ctx)
throws URISyntaxException, IOException {
final var updatedArtifactDescription =
Files.readString(
Expand Down Expand Up @@ -222,6 +222,43 @@ public void testDeleteAndGetArtifact(final VertxTestContext ctx)
.onComplete(ctx.succeedingThenComplete());
}

@Test
public void testUpdateAndGetBody(final VertxTestContext ctx)
throws URISyntaxException, IOException {
final var updatedBodyDescription =
Files.readString(
Path.of(ClassLoader.getSystemResource("updated_test_agent_body_test.ttl").toURI()),
StandardCharsets.UTF_8
);
this.assertWorkspaceTreeCreated(ctx)
.compose(r -> this.storeMessagebox.sendMessage(new RdfStoreMessage.UpdateEntity(
"http://localhost:8080/workspaces/test/agents/test",
updatedBodyDescription
)))
.onSuccess(r -> {
RdfStoreVerticleTestHelpers.assertEqualsThingDescriptions(
updatedBodyDescription,
r.body()
);
try {
final var updateMessage =
(HttpNotificationDispatcherMessage.EntityChanged) this.notificationQueue.take();
RdfStoreVerticleTestHelpers.assertEqualsThingDescriptions(
updatedBodyDescription,
updateMessage.content()
);
Assertions.assertEquals(
"http://localhost:8080/workspaces/test/agents/test",
updateMessage.requestIri(),
URIS_EQUAL_MESSAGE
);
} catch (final Exception e) {
ctx.failNow(e);
}
})
.onComplete(ctx.succeedingThenComplete());
}

private Future<Message<String>> assertWorkspaceTreeCreated(final VertxTestContext ctx)
throws URISyntaxException, IOException {
final var inputWorkspaceRepresentation =
Expand All @@ -239,6 +276,11 @@ private Future<Message<String>> assertWorkspaceTreeCreated(final VertxTestContex
Path.of(ClassLoader.getSystemResource("c0_counter_artifact_sub_td.ttl").toURI()),
StandardCharsets.UTF_8
);
final var inputBodyRepresentation =
Files.readString(
Path.of(ClassLoader.getSystemResource("test_agent_body_test.ttl").toURI()),
StandardCharsets.UTF_8
);
return this.storeMessagebox
.sendMessage(new RdfStoreMessage.CreateWorkspace(
"http://localhost:8080/workspaces/",
Expand Down Expand Up @@ -273,6 +315,19 @@ private Future<Message<String>> assertWorkspaceTreeCreated(final VertxTestContex
inputArtifactRepresentation
));
})
.compose(r -> {
try {
this.notificationQueue.take();
this.notificationQueue.take();
} catch (final Exception e) {
ctx.failNow(e);
}
return this.storeMessagebox.sendMessage(new RdfStoreMessage.CreateBody(
"test",
"test",
inputBodyRepresentation
));
})
.onSuccess(r -> {
try {
this.notificationQueue.take();
Expand Down
Loading

0 comments on commit 31c986a

Please sign in to comment.