Skip to content

Commit

Permalink
test: fix tests duplicating agent body description and removing order…
Browse files Browse the repository at this point in the history
…ing for action notifications
  • Loading branch information
cake-lier committed Jan 17, 2024
1 parent 945464c commit 4165fd8
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 56 deletions.
111 changes: 56 additions & 55 deletions src/test/java/org/hyperagents/yggdrasil/BodyNotificationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.nio.file.Path;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.hc.core5.http.HttpStatus;
Expand Down Expand Up @@ -125,7 +126,7 @@ public void testRun(final VertxTestContext ctx) throws URISyntaxException, IOExc
);
final var testAgentBodyRepresentation =
Files.readString(
Path.of(ClassLoader.getSystemResource("test_agent_body.ttl").toURI()),
Path.of(ClassLoader.getSystemResource("test_agent_body_test.ttl").toURI()),
StandardCharsets.UTF_8
);
final var workspaceWithArtifactAndBodyRepresentation =
Expand Down Expand Up @@ -301,60 +302,60 @@ public void testRun(final VertxTestContext ctx) throws URISyntaxException, IOExc
);
Assertions.assertNull(r.bodyAsString(), RESPONSE_BODY_EMPTY_MESSAGE);
})
.compose(r -> this.callbackMessages.get(2).future())
.onSuccess(m -> {
Assertions.assertEquals(
this.getUrl(
WORKSPACES_PATH
+ MAIN_WORKSPACE_NAME
+ BODIES_PATH
+ TEST_AGENT_NAME
),
m.getKey(),
URIS_EQUAL_MESSAGE
);
Assertions.assertEquals(
JsonObject
.of(
"artifactName",
COUNTER_ARTIFACT_NAME,
"actionName",
"inc",
"eventType",
"actionRequested"
)
.encode(),
m.getValue(),
REPRESENTATIONS_EQUAL_MESSAGE
);
})
.compose(r -> this.callbackMessages.get(3).future())
.onSuccess(m -> {
Assertions.assertEquals(
this.getUrl(
WORKSPACES_PATH
+ MAIN_WORKSPACE_NAME
+ BODIES_PATH
+ TEST_AGENT_NAME
),
m.getKey(),
URIS_EQUAL_MESSAGE
);
Assertions.assertEquals(
JsonObject
.of(
"artifactName",
COUNTER_ARTIFACT_NAME,
"actionName",
"inc",
"eventType",
"actionSucceeded"
)
.encode(),
m.getValue(),
REPRESENTATIONS_EQUAL_MESSAGE
);
})
.compose(r -> this.callbackMessages
.get(2)
.future()
.compose(r1 -> this.callbackMessages
.get(3)
.future()
.onSuccess(r2 -> {
Assertions.assertEquals(
this.getUrl(
WORKSPACES_PATH
+ MAIN_WORKSPACE_NAME
+ BODIES_PATH
+ TEST_AGENT_NAME
),
r1.getKey(),
URIS_EQUAL_MESSAGE
);
Assertions.assertEquals(
this.getUrl(
WORKSPACES_PATH
+ MAIN_WORKSPACE_NAME
+ BODIES_PATH
+ TEST_AGENT_NAME
),
r2.getKey(),
URIS_EQUAL_MESSAGE
);
Assertions.assertEquals(
Set.of(
JsonObject
.of(
"artifactName",
COUNTER_ARTIFACT_NAME,
"actionName",
"inc",
"eventType",
"actionRequested"
)
.encode(),
JsonObject
.of(
"artifactName",
COUNTER_ARTIFACT_NAME,
"actionName",
"inc",
"eventType",
"actionSucceeded"
)
.encode()
),
Set.of(r1.getValue(), r2.getValue()),
REPRESENTATIONS_EQUAL_MESSAGE
);
})))
.onComplete(ctx.succeedingThenComplete());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public void testRun(final VertxTestContext ctx) throws URISyntaxException, IOExc
);
final var testAgentBodyRepresentation =
Files.readString(
Path.of(ClassLoader.getSystemResource("test_agent_body.ttl").toURI()),
Path.of(ClassLoader.getSystemResource("test_agent_body_sub.ttl").toURI()),
StandardCharsets.UTF_8
);
final var subWorkspaceWithArtifactAndBodyRepresentation =
Expand Down
17 changes: 17 additions & 0 deletions src/test/resources/test_agent_body_sub.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@prefix hmas: <https://purl.org/hmas/core/> .
@prefix td: <https://www.w3.org/2019/wot/td#> .
@prefix htv: <http://www.w3.org/2011/http#> .
@prefix hctl: <https://www.w3.org/2019/wot/hypermedia#> .
@prefix wotsec: <https://www.w3.org/2019/wot/security#> .
@prefix dct: <http://purl.org/dc/terms/> .
@prefix js: <https://www.w3.org/2019/wot/json-schema#> .
@prefix saref: <https://w3id.org/saref#> .

<http://localhost:8080/workspaces/sub/agents/test_agent> a td:Thing, hmas:Artifact;
td:title "test_agent";
td:hasSecurityConfiguration [ a wotsec:NoSecurityScheme
] .

<http://localhost:8080/workspaces/sub/agents/test_agent> hmas:isContainedIn <http://localhost:8080/workspaces/sub> .

<http://localhost:8080/workspaces/sub> a hmas:Workspace .
File renamed without changes.

0 comments on commit 4165fd8

Please sign in to comment.