Skip to content

Commit

Permalink
test: fix tests for checkstyle, pmd and spotbugs
Browse files Browse the repository at this point in the history
  • Loading branch information
cake-lier committed Nov 15, 2023
1 parent 0475dd9 commit 4bf49e5
Show file tree
Hide file tree
Showing 16 changed files with 37 additions and 114 deletions.
3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ allprojects {
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
maven { url = uri("https://raw.github.com/jacamo-lang/mvn-repo/master") }
maven { url = uri("https://repo.gradle.org/gradle/libs-releases/") }
maven { url = uri("https://repo.gradle.org/gradle/libs-releases-local/") }
}

group = "org.hyperagents"
Expand Down
14 changes: 2 additions & 12 deletions yggdrasil-cartago/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,6 @@ java {
targetCompatibility = JavaVersion.VERSION_21
}

repositories {
maven {
url = uri("https://raw.github.com/jacamo-lang/mvn-repo/master")
}
maven {
url = uri("https://repo.gradle.org/gradle/libs-releases/") // For current version of Gradle tooling API
}
maven {
url = uri("https://repo.gradle.org/gradle/libs-releases-local/") // For older versions of Gradle tooling API
}
}

dependencies {
implementation(project(":yggdrasil-utils"))
implementation(project(":yggdrasil-websub"))
Expand Down Expand Up @@ -74,6 +62,8 @@ dependencies {
tasks {
test {
useJUnitPlatform()

forkEvery = 1
}

spotbugsMain {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import java.util.Optional;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import org.hyperagents.yggdrasil.cartago.artifacts.Matcher;
import org.hyperagents.yggdrasil.cartago.artifacts.MatcherArtifact;
import org.hyperagents.yggdrasil.eventbus.messageboxes.CartagoMessagebox;
import org.hyperagents.yggdrasil.eventbus.messageboxes.RdfStoreMessagebox;
import org.hyperagents.yggdrasil.eventbus.messages.CartagoMessage;
Expand All @@ -25,10 +25,11 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

@SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert")
@ExtendWith(VertxExtension.class)
public class CartagoProjectInitTest {
private static final String AGENT_IRI = "http://localhost:8080/agents/test";
private static final String MATCHER_SEMANTIC_TYPE = "http://example.org/Matcher";
private static final String AGENT_IRI = "http://www.example.org/agents/default";
private static final String MATCHER_SEMANTIC_TYPE = "http://example.org/MatcherArtifact";
private static final String TDS_EQUAL_MESSAGE = "The Thing Descriptions should be equal";
private static final String NAMES_EQUAL_MESSAGE = "The names should be equal";
public static final String IRIS_EQUAL_MESSAGE = "The IRIs should be equal";
Expand All @@ -55,7 +56,7 @@ public void testConfigurationIsCorrectlyLoaded(final Vertx vertx, final VertxTes
throws URISyntaxException, IOException {
final var expectedThingDescription =
Files.readString(
Path.of(ClassLoader.getSystemResource("default_agent_body.ttl").toURI()),
Path.of(ClassLoader.getSystemResource("default_agent_body_td.ttl").toURI()),
StandardCharsets.UTF_8
);
vertx
Expand All @@ -64,7 +65,7 @@ public void testConfigurationIsCorrectlyLoaded(final Vertx vertx, final VertxTes
new DeploymentOptions()
.setConfig(new JsonObject(Map.of(
"known-artifacts",
Map.of(MATCHER_SEMANTIC_TYPE, Matcher.class.getCanonicalName()),
Map.of(MATCHER_SEMANTIC_TYPE, MatcherArtifact.class.getCanonicalName()),
"app-conf-file",
"src/test/resources/default_conf.jcm"
)))
Expand All @@ -79,7 +80,7 @@ public void testConfigurationIsCorrectlyLoaded(final Vertx vertx, final VertxTes
IRIS_EQUAL_MESSAGE
);
Assertions.assertEquals(
"body_http://www.example.org/agents/default",
"body_" + AGENT_IRI,
defaultAgentBodyCreationMessage.entityName(),
NAMES_EQUAL_MESSAGE
);
Expand Down Expand Up @@ -152,7 +153,7 @@ public void testBadlyFormattedConfigurationDoesNotBreakInitialization(
new DeploymentOptions()
.setConfig(new JsonObject(Map.of(
"known-artifacts",
Map.of(MATCHER_SEMANTIC_TYPE, Matcher.class.getCanonicalName()),
Map.of(MATCHER_SEMANTIC_TYPE, MatcherArtifact.class.getCanonicalName()),
"app-conf-file",
"src/test/resources/bad_conf.jcm"
)))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.hyperagents.yggdrasil.cartago;

import io.vertx.core.DeploymentOptions;
import io.vertx.core.Promise;
import io.vertx.core.Vertx;
import io.vertx.core.eventbus.ReplyException;
import io.vertx.core.json.Json;
Expand All @@ -17,11 +16,10 @@
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.LinkedBlockingQueue;
import org.apache.http.HttpStatus;
import org.hyperagents.yggdrasil.cartago.artifacts.Adder;
import org.hyperagents.yggdrasil.cartago.artifacts.Counter;
import org.hyperagents.yggdrasil.cartago.artifacts.AdderArtifact;
import org.hyperagents.yggdrasil.cartago.artifacts.CounterArtifact;
import org.hyperagents.yggdrasil.eventbus.messageboxes.CartagoMessagebox;
import org.hyperagents.yggdrasil.eventbus.messageboxes.HttpNotificationDispatcherMessagebox;
import org.hyperagents.yggdrasil.eventbus.messageboxes.RdfStoreMessagebox;
Expand All @@ -45,8 +43,8 @@ public class CartagoVerticleTest {
private static final String SUB_WORKSPACE_NAME = "sub";
private static final String AGENT_IRI = "http://localhost:8080/agents/test";
private static final String FOCUSING_AGENT_IRI = "http://localhost:8080/agents/focusing_agent";
private static final String ADDER_SEMANTIC_TYPE = "http://example.org/Adder";
private static final String COUNTER_SEMANTIC_TYPE = "http://example.org/Counter";
private static final String ADDER_SEMANTIC_TYPE = "http://example.org/AdderArtifact";
private static final String COUNTER_SEMANTIC_TYPE = "http://example.org/CounterArtifact";
private static final String CALLBACK_IRI = "http://localhost:8080/callback";
private static final String COUNTER_ARTIFACT_IRI = "http://localhost:8080/workspaces/test/artifacts/c0";
private static final String NONEXISTENT_NAME = "nonexistent";
Expand All @@ -64,15 +62,14 @@ public class CartagoVerticleTest {
private final BlockingQueue<RdfStoreMessage> storeMessageQueue;
private final BlockingQueue<HttpNotificationDispatcherMessage> notificationQueue;
private CartagoMessagebox cartagoMessagebox;
private Optional<String> cartagoVerticleId;

public CartagoVerticleTest() {
this.storeMessageQueue = new LinkedBlockingQueue<>();
this.notificationQueue = new LinkedBlockingQueue<>();
}

@BeforeEach
public void setUp(final Vertx vertx) throws InterruptedException {
public void setUp(final Vertx vertx, final VertxTestContext ctx) {
this.cartagoMessagebox = new CartagoMessagebox(vertx.eventBus());
final var storeMessagebox = new RdfStoreMessagebox(vertx.eventBus());
storeMessagebox.init();
Expand All @@ -81,33 +78,25 @@ public void setUp(final Vertx vertx) throws InterruptedException {
new HttpNotificationDispatcherMessagebox(vertx.eventBus());
notificationMessagebox.init();
notificationMessagebox.receiveMessages(m -> this.notificationQueue.add(m.body()));
final var promise = Promise.<String>promise();
vertx.deployVerticle(
new CartagoVerticle(),
new DeploymentOptions()
.setConfig(new JsonObject(Map.of(
"known-artifacts",
Map.of(
ADDER_SEMANTIC_TYPE,
Adder.class.getCanonicalName(),
AdderArtifact.class.getCanonicalName(),
COUNTER_SEMANTIC_TYPE,
Counter.class.getCanonicalName()
CounterArtifact.class.getCanonicalName()
)
))),
promise
ctx.succeedingThenComplete()
);
final var latch = new CountDownLatch(1);
promise.future()
.onSuccess(i -> {
this.cartagoVerticleId = Optional.of(i);
latch.countDown();
});
latch.await();
}

@AfterEach
public void tearDown(final Vertx vertx, final VertxTestContext ctx) {
this.cartagoVerticleId.ifPresent(i -> vertx.undeploy(i, ctx.succeedingThenComplete()));
vertx.close(ctx.succeedingThenComplete());
}

@Order(1)
Expand Down Expand Up @@ -151,10 +140,6 @@ public void testJoinWorkspaceSucceeds(final VertxTestContext ctx)
Path.of(ClassLoader.getSystemResource("test_agent_body_td.ttl").toURI()),
StandardCharsets.UTF_8
);
final var expectedHypermediaBodyArtifactThingDescription = Files.readString(
Path.of(ClassLoader.getSystemResource("test_agent_hypermedia_body_td.ttl").toURI()),
StandardCharsets.UTF_8
);
this.cartagoMessagebox
.sendMessage(new CartagoMessage.JoinWorkspace(AGENT_IRI, MAIN_WORKSPACE_NAME))
.onSuccess(r -> {
Expand Down Expand Up @@ -190,7 +175,7 @@ public void testJoinWorkspaceSucceeds(final VertxTestContext ctx)
);
Assertions.assertEquals(
hypermediaBodyCreationMessage.entityRepresentation(),
expectedHypermediaBodyArtifactThingDescription,
expectedBodyArtifactThingDescription,
TDS_EQUAL_MESSAGE
);
} catch (final Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import ch.unisg.ics.interactions.wot.td.schemas.ArraySchema;
import ch.unisg.ics.interactions.wot.td.schemas.IntegerSchema;

public class Adder extends HypermediaArtifact {
public class AdderArtifact extends HypermediaArtifact {
@OPERATION
public void add(final int x, final int y, final OpFeedbackParam<Integer> sumParam) {
this.log("adder performs add");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package org.hyperagents.yggdrasil.cartago.artifacts;

import cartago.OPERATION;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

@SuppressFBWarnings("PI_DO_NOT_REUSE_PUBLIC_IDENTIFIERS_CLASS_NAMES")
public class Counter extends HypermediaArtifact {
public class CounterArtifact extends HypermediaArtifact {

public void init() {
this.defineObsProperty("count", 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import ch.unisg.ics.interactions.wot.td.schemas.StringSchema;
import java.util.regex.Pattern;

public class Matcher extends HypermediaArtifact {
public class MatcherArtifact extends HypermediaArtifact {
private Pattern pattern;

public void init() {
Expand Down
2 changes: 1 addition & 1 deletion yggdrasil-cartago/src/test/resources/a0_adder_artifact.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@prefix js: <https://www.w3.org/2019/wot/json-schema#> .
@prefix eve: <http://w3id.org/eve#> .

<http://localhost:8080/workspaces/test/artifacts/a0> a td:Thing, <http://example.org/Adder>,
<http://localhost:8080/workspaces/test/artifacts/a0> a td:Thing, <http://example.org/AdderArtifact>,
<https://ci.mines-stetienne.fr/hmas/core#Artifact>;
td:title "a0";
td:hasSecurityConfiguration [ a wotsec:NoSecurityScheme
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@prefix js: <https://www.w3.org/2019/wot/json-schema#> .
@prefix eve: <http://w3id.org/eve#> .

<http://localhost:8080/workspaces/test/artifacts/c0> a td:Thing, <http://example.org/Counter>,
<http://localhost:8080/workspaces/test/artifacts/c0> a td:Thing, <http://example.org/CounterArtifact>,
<https://ci.mines-stetienne.fr/hmas/core#Artifact>;
td:title "c0";
td:hasSecurityConfiguration [ a wotsec:NoSecurityScheme
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@prefix js: <https://www.w3.org/2019/wot/json-schema#> .
@prefix eve: <http://w3id.org/eve#> .

<http://localhost:8080/workspaces/sub/artifacts/c1> a td:Thing, <http://example.org/Counter>,
<http://localhost:8080/workspaces/sub/artifacts/c1> a td:Thing, <http://example.org/CounterArtifact>,
<https://ci.mines-stetienne.fr/hmas/core#Artifact>;
td:title "c1";
td:hasSecurityConfiguration [ a wotsec:NoSecurityScheme
Expand Down
4 changes: 2 additions & 2 deletions yggdrasil-cartago/src/test/resources/default_conf.jcm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mas example {
workspace test {
artifact m0: org.hyperagents.yggdrasil.cartago.artifacts.Matcher()
artifact m1: org.hyperagents.yggdrasil.cartago.artifacts.Matcher("[a-z]+")
artifact m0: org.hyperagents.yggdrasil.cartago.artifacts.MatcherArtifact()
artifact m1: org.hyperagents.yggdrasil.cartago.artifacts.MatcherArtifact("[a-z]+")
}
}
4 changes: 2 additions & 2 deletions yggdrasil-cartago/src/test/resources/sub2_workspace_td.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
td:hasInputSchema [ a js:ObjectSchema;
js:properties [ a js:StringSchema, eve:ArtifactClass;
js:propertyName "artifactClass";
js:enum <http://example.org/Body>, <http://example.org/Adder>, <http://example.org/Counter>,
js:enum <http://example.org/Body>, <http://example.org/AdderArtifact>, <http://example.org/CounterArtifact>,
<http://example.org/Console>
], [ a js:ArraySchema;
js:propertyName "initParams"
], [ a js:StringSchema, eve:ArtifactName;
js:propertyName "artifactName";
js:enum <http://example.org/Body>, <http://example.org/Adder>, <http://example.org/Counter>,
js:enum <http://example.org/Body>, <http://example.org/AdderArtifact>, <http://example.org/CounterArtifact>,
<http://example.org/Console>
];
js:required "artifactClass", "artifactName"
Expand Down
4 changes: 2 additions & 2 deletions yggdrasil-cartago/src/test/resources/sub_workspace_td.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
td:hasInputSchema [ a js:ObjectSchema;
js:properties [ a js:StringSchema, eve:ArtifactClass;
js:propertyName "artifactClass";
js:enum <http://example.org/Body>, <http://example.org/Adder>, <http://example.org/Counter>,
js:enum <http://example.org/Body>, <http://example.org/AdderArtifact>, <http://example.org/CounterArtifact>,
<http://example.org/Console>
], [ a js:ArraySchema;
js:propertyName "initParams"
], [ a js:StringSchema, eve:ArtifactName;
js:propertyName "artifactName";
js:enum <http://example.org/Body>, <http://example.org/Adder>, <http://example.org/Counter>,
js:enum <http://example.org/Body>, <http://example.org/AdderArtifact>, <http://example.org/CounterArtifact>,
<http://example.org/Console>
];
js:required "artifactClass", "artifactName"
Expand Down

This file was deleted.

4 changes: 2 additions & 2 deletions yggdrasil-cartago/src/test/resources/test_workspace_td.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
td:hasInputSchema [ a js:ObjectSchema;
js:properties [ a js:StringSchema, eve:ArtifactClass;
js:propertyName "artifactClass";
js:enum <http://example.org/Body>, <http://example.org/Adder>, <http://example.org/Counter>,
js:enum <http://example.org/Body>, <http://example.org/AdderArtifact>, <http://example.org/CounterArtifact>,
<http://example.org/Console>
], [ a js:ArraySchema;
js:propertyName "initParams"
], [ a js:StringSchema, eve:ArtifactName;
js:propertyName "artifactName";
js:enum <http://example.org/Body>, <http://example.org/Adder>, <http://example.org/Counter>,
js:enum <http://example.org/Body>, <http://example.org/AdderArtifact>, <http://example.org/CounterArtifact>,
<http://example.org/Console>
];
js:required "artifactClass", "artifactName"
Expand Down

0 comments on commit 4bf49e5

Please sign in to comment.