Skip to content

Commit

Permalink
Yaml regularization and sovity messenger fix attempt
Browse files Browse the repository at this point in the history
  • Loading branch information
ununhexium committed Oct 31, 2024
1 parent f518fb0 commit 7e8f1f5
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,59 +18,60 @@
import org.junit.jupiter.api.Test;

import static de.sovity.edc.utils.config.utils.UrlPathUtils.urlPathJoin;
import static org.assertj.core.api.Assertions.assertThat;

class UrlPathUtilsTest {
@Test
void urlPathJoin_empty() {
Assertions.assertThat(urlPathJoin()).isEmpty();
Assertions.assertThat(urlPathJoin("")).isEmpty();
Assertions.assertThat(urlPathJoin("/")).isEqualTo("/");
assertThat(urlPathJoin()).isEmpty();
assertThat(urlPathJoin("")).isEmpty();
assertThat(urlPathJoin("/")).isEqualTo("/");
}

@Test
void urlPathJoin_relative() {
Assertions.assertThat(urlPathJoin("a")).isEqualTo("a");
Assertions.assertThat(urlPathJoin("a/")).isEqualTo("a/");
Assertions.assertThat(urlPathJoin("a", "b")).isEqualTo("a/b");
Assertions.assertThat(urlPathJoin("a/", "b")).isEqualTo("a/b");
Assertions.assertThat(urlPathJoin("a", "/b")).isEqualTo("a/b");
Assertions.assertThat(urlPathJoin("a/", "/b")).isEqualTo("a/b");
assertThat(urlPathJoin("a")).isEqualTo("a");
assertThat(urlPathJoin("a/")).isEqualTo("a/");
assertThat(urlPathJoin("a", "b")).isEqualTo("a/b");
assertThat(urlPathJoin("a/", "b")).isEqualTo("a/b");
assertThat(urlPathJoin("a", "/b")).isEqualTo("a/b");
assertThat(urlPathJoin("a/", "/b")).isEqualTo("a/b");
}

@Test
void urlPathJoin_absolute() {
Assertions.assertThat(urlPathJoin("/a")).isEqualTo("/a");
Assertions.assertThat(urlPathJoin("/a/")).isEqualTo("/a/");
Assertions.assertThat(urlPathJoin("/a", "b")).isEqualTo("/a/b");
Assertions.assertThat(urlPathJoin("/a/", "b")).isEqualTo("/a/b");
Assertions.assertThat(urlPathJoin("/a", "/b")).isEqualTo("/a/b");
Assertions.assertThat(urlPathJoin("/a/", "/b")).isEqualTo("/a/b");
assertThat(urlPathJoin("/a")).isEqualTo("/a");
assertThat(urlPathJoin("/a/")).isEqualTo("/a/");
assertThat(urlPathJoin("/a", "b")).isEqualTo("/a/b");
assertThat(urlPathJoin("/a/", "b")).isEqualTo("/a/b");
assertThat(urlPathJoin("/a", "/b")).isEqualTo("/a/b");
assertThat(urlPathJoin("/a/", "/b")).isEqualTo("/a/b");
}

@Test
void urlPathJoin_immediate_protocol() {
Assertions.assertThat(urlPathJoin("https://")).isEqualTo("https://");
Assertions.assertThat(urlPathJoin("https://", "b")).isEqualTo("https://b");
Assertions.assertThat(urlPathJoin("https://", "/b")).isEqualTo("https://b");
assertThat(urlPathJoin("https://")).isEqualTo("https://");
assertThat(urlPathJoin("https://", "b")).isEqualTo("https://b");
assertThat(urlPathJoin("https://", "/b")).isEqualTo("https://b");
}

@Test
void urlPathJoin_protocol() {
Assertions.assertThat(urlPathJoin("https://a")).isEqualTo("https://a");
Assertions.assertThat(urlPathJoin("https://a/")).isEqualTo("https://a/");
Assertions.assertThat(urlPathJoin("https://a", "b")).isEqualTo("https://a/b");
Assertions.assertThat(urlPathJoin("https://a/", "b")).isEqualTo("https://a/b");
Assertions.assertThat(urlPathJoin("https://a", "/b")).isEqualTo("https://a/b");
Assertions.assertThat(urlPathJoin("https://a/", "/b")).isEqualTo("https://a/b");
assertThat(urlPathJoin("https://a")).isEqualTo("https://a");
assertThat(urlPathJoin("https://a/")).isEqualTo("https://a/");
assertThat(urlPathJoin("https://a", "b")).isEqualTo("https://a/b");
assertThat(urlPathJoin("https://a/", "b")).isEqualTo("https://a/b");
assertThat(urlPathJoin("https://a", "/b")).isEqualTo("https://a/b");
assertThat(urlPathJoin("https://a/", "/b")).isEqualTo("https://a/b");
}

@Test
void urlPathJoin_protocol_overruling_not_enabled() {
Assertions.assertThat(urlPathJoin("https://ignored", "https://a")).isEqualTo("https://ignored/https://a");
Assertions.assertThat(urlPathJoin("https://ignored", "https://a/")).isEqualTo("https://ignored/https://a/");
Assertions.assertThat(urlPathJoin("https://ignored", "https://a", "b")).isEqualTo("https://ignored/https://a/b");
Assertions.assertThat(urlPathJoin("https://ignored", "https://a/", "b")).isEqualTo("https://ignored/https://a/b");
Assertions.assertThat(urlPathJoin("https://ignored", "https://a", "/b")).isEqualTo("https://ignored/https://a/b");
Assertions.assertThat(urlPathJoin("https://ignored", "https://a/", "/b")).isEqualTo("https://ignored/https://a/b");
assertThat(urlPathJoin("https://ignored", "https://a")).isEqualTo("https://ignored/https://a");
assertThat(urlPathJoin("https://ignored", "https://a/")).isEqualTo("https://ignored/https://a/");
assertThat(urlPathJoin("https://ignored", "https://a", "b")).isEqualTo("https://ignored/https://a/b");
assertThat(urlPathJoin("https://ignored", "https://a/", "b")).isEqualTo("https://ignored/https://a/b");
assertThat(urlPathJoin("https://ignored", "https://a", "/b")).isEqualTo("https://ignored/https://a/b");
assertThat(urlPathJoin("https://ignored", "https://a/", "/b")).isEqualTo("https://ignored/https://a/b");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
import de.sovity.edc.extension.messenger.impl.SovityMessageRequest;
import de.sovity.edc.extension.messenger.impl.SovityMessageRequestBodyExtractor;
import lombok.val;
import org.eclipse.edc.policy.engine.spi.PolicyEngine;
import org.eclipse.edc.policy.engine.spi.PolicyScope;
import org.eclipse.edc.policy.model.Policy;
import org.eclipse.edc.protocol.dsp.http.spi.dispatcher.DspHttpRemoteMessageDispatcher;
import org.eclipse.edc.protocol.dsp.http.spi.serialization.JsonLdRemoteMessageSerializer;
import org.eclipse.edc.runtime.metamodel.annotation.Inject;
Expand All @@ -43,6 +46,9 @@ public class SovityMessengerExtension implements ServiceExtension {

public static final String NAME = "SovityMessenger";

@PolicyScope
public static final String MESSENGER_SCOPE = "messenger.sovity";

@Inject
private DspHttpRemoteMessageDispatcher dspHttpRemoteMessageDispatcher;

Expand All @@ -55,6 +61,12 @@ public class SovityMessengerExtension implements ServiceExtension {
@Inject
private Monitor monitor;

@Inject
private ParticipantAgentService participantAgentService;

@Inject
private PolicyEngine policyEngine;

@Inject
private RemoteMessageDispatcherRegistry registry;

Expand All @@ -64,9 +76,6 @@ public class SovityMessengerExtension implements ServiceExtension {
@Inject
private WebService webService;

@Inject
private ParticipantAgentService participantAgentService;

@Override
public String name() {
return NAME;
Expand All @@ -84,8 +93,16 @@ public void initialize(ServiceExtensionContext context) {
private void setupSovityMessengerEmitter(ServiceExtensionContext context, ObjectMapper objectMapper) {
val factory = new MessageEmitter(jsonLdRemoteMessageSerializer);
val bodyExtractor = new SovityMessageRequestBodyExtractor(objectMapper);

dspHttpRemoteMessageDispatcher.registerMessage(SovityMessageRequest.class, factory, bodyExtractor);

dspHttpRemoteMessageDispatcher.registerPolicyScope(
SovityMessageRequest.class,
MESSENGER_SCOPE,
(ignored) -> Policy.Builder.newInstance().build());

policyEngine.registerPostValidator(MESSENGER_SCOPE, (ignored1, ignored2) -> true);

typeTransformerRegistry.register(new JsonObjectFromSovityMessageRequest());

val sovityMessenger = new SovityMessenger(registry, objectMapper, monitor);
Expand Down
18 changes: 16 additions & 2 deletions extensions/wrapper/wrapper-api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import com.diffplug.gradle.spotless.SpotlessTask

plugins {
`java-library`
`maven-publish`
alias(libs.plugins.swagger.plugin) //./gradlew clean resolve
alias(libs.plugins.hidetake.swaggerGenerator) //./gradlew generateSwaggerUI
alias(libs.plugins.openapi.generator6) //./gradlew openApiValidate && ./gradlew openApiGenerate
alias(libs.plugins.spotless)
}

dependencies {
Expand Down Expand Up @@ -41,6 +43,14 @@ tasks.withType<io.swagger.v3.plugins.gradle.tasks.ResolveTask> {
resourcePackages = setOf("de.sovity.edc.ext.wrapper.api")
}

spotless {
yaml {
target("src/**/*.yaml")
jackson()
.feature("ORDER_MAP_ENTRIES_BY_KEYS", true)
}
}

val copyOpenapiYamlToDocs by tasks.registering(Copy::class) {
dependsOn("resolve")
from(openapiFile)
Expand All @@ -51,11 +61,13 @@ val openApiGenerateTypeScriptClient by tasks.registering(org.openapitools.genera
dependsOn("resolve")
dependsOn(copyOpenapiYamlToDocs)
generatorName.set("typescript-fetch")
configOptions.set(mutableMapOf(
configOptions.set(
mutableMapOf(
"supportsES6" to "true",
"npmVersion" to "8.15.0",
"typescriptThreePlus" to "true",
))
)
)

inputSpec.set(openapiFile)
val outputDirectory = buildFile.parentFile.resolve("../clients/typescript-client/src/generated").normalize()
Expand All @@ -68,6 +80,8 @@ val openApiGenerateTypeScriptClient by tasks.registering(org.openapitools.genera
doLast {
outputDirectory.resolve("src/generated").renameTo(outputDirectory)
}

finalizedBy(tasks.withType<SpotlessTask>())
}

tasks.withType<org.gradle.jvm.tasks.Jar> {
Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ quarkus = "2.16.6.Final"
quartz = "2.3.2"
restAssured = "5.5.0"
shadow = "7.1.2"
spotless = "6.25.0"
swagger = "1.6.12"
swaggerCore = "2.2.18"
testcontainers = "1.19.1"
Expand Down Expand Up @@ -231,6 +232,7 @@ openapi-generator6 = { id = "org.openapi.generator", version.ref = "openapiGener
openapi-generator7 = { id = "org.openapi.generator", version.ref = "openapiGenerator7" }
quarkus = { id = "io.quarkus", version.ref = "quarkus" }
shadow = { id = "com.github.johnrengelman.shadow", version.ref = "shadow" }
spotless = { id = "com.diffplug.spotless", version.ref = "spotless" }
swagger-plugin = { id = "io.swagger.core.v3.swagger-gradle-plugin", version.ref = "swaggerCore" }
jooq = { id = "nu.studer.jooq", version.ref = "jooqPlugin" }
flyway = { id = "org.flywaydb.flyway", version.ref = "flywayPlugin" }

0 comments on commit 7e8f1f5

Please sign in to comment.