Skip to content

Commit

Permalink
Merge pull request #93 from jimmarino/feat/align-message-types
Browse files Browse the repository at this point in the history
feat: Update TCK to more closely align with the DSP specification and add testcases
  • Loading branch information
jimmarino authored Sep 23, 2024
2 parents 33d98f1 + b6e3c9c commit a60c946
Show file tree
Hide file tree
Showing 40 changed files with 1,116 additions and 324 deletions.
6 changes: 3 additions & 3 deletions DEPENDENCIES
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ maven/mavencentral/commons-beanutils/commons-beanutils/1.9.4, Apache-2.0, approv
maven/mavencentral/commons-collections/commons-collections/3.2.2, Apache-2.0, approved, #15185
maven/mavencentral/info.picocli/picocli/4.6.2, Apache-2.0, approved, clearlydefined
maven/mavencentral/jakarta.json/jakarta.json-api/2.1.3, EPL-2.0 OR GPL-2.0-only with Classpath-exception-2.0, approved, ee4j.jsonp
maven/mavencentral/net.bytebuddy/byte-buddy-agent/1.14.8, Apache-2.0, approved, #7164
maven/mavencentral/net.bytebuddy/byte-buddy-agent/1.15.0, Apache-2.0, approved, #16009
maven/mavencentral/net.bytebuddy/byte-buddy/1.14.18, Apache-2.0 AND BSD-3-Clause, approved, #7163
maven/mavencentral/net.bytebuddy/byte-buddy/1.14.8, Apache-2.0 AND BSD-3-Clause, approved, #7163
maven/mavencentral/net.bytebuddy/byte-buddy/1.15.0, Apache-2.0 AND BSD-3-Clause, approved, #16008
maven/mavencentral/net.sf.saxon/Saxon-HE/10.6, MPL-2.0 AND W3C, approved, #7945
maven/mavencentral/org.antlr/antlr4-runtime/4.9.3, BSD-3-Clause, approved, #322
maven/mavencentral/org.apiguardian/apiguardian-api/1.1.2, Apache-2.0, approved, clearlydefined
Expand Down Expand Up @@ -51,7 +51,7 @@ maven/mavencentral/org.junit.platform/junit-platform-suite-api/1.10.3, EPL-2.0,
maven/mavencentral/org.junit.platform/junit-platform-suite-commons/1.10.3, EPL-2.0, approved, #15214
maven/mavencentral/org.junit.platform/junit-platform-suite-engine/1.10.3, EPL-2.0, approved, #15258
maven/mavencentral/org.junit/junit-bom/5.10.3, EPL-2.0, approved, #9844
maven/mavencentral/org.mockito/mockito-core/5.6.0, MIT AND (Apache-2.0 AND MIT) AND Apache-2.0, approved, #10932
maven/mavencentral/org.mockito/mockito-core/5.13.0, MIT, approved, clearlydefined
maven/mavencentral/org.objenesis/objenesis/3.3, Apache-2.0, approved, clearlydefined
maven/mavencentral/org.opentest4j/opentest4j/1.3.0, Apache-2.0, approved, #9713
maven/mavencentral/org.ow2.asm/asm-commons/9.6, BSD-3-Clause, approved, #10775
Expand Down
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
# Compliance Verfication Framework
# Compliance Verification Framework
To build:

```bash
./gradlew clean build
```

To execute:

```bash
java -jar runtimes/dsp-tck/build/libs/dsp-tck-runtime.jar -config config/tck/sample.tck.properties
```
16 changes: 16 additions & 0 deletions boot/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright (c) 2023 Metaform Systems, Inc.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Metaform Systems, Inc. - initial API and implementation
*
*
*/


Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2024 Metaform Systems, Inc.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Metaform Systems, Inc. - initial API and implementation
*
*/
package org.eclipse.dataspacetck.core.spi.boot;

/**
* Sends formatted messages to the system output.
*/
public interface Monitor {

Monitor enableSuccess();

Monitor enableError();

Monitor enableBold();

Monitor resetMode();

Monitor newLine();

Monitor message(String message);

Monitor debug(String message);
}
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ allprojects {

tasks.test {
useJUnitPlatform()
systemProperty("cvf.launcher", "org.eclipse.dataspacetck.dsp.system.DspSystemLauncher")
systemProperty("dataspacetck.launcher", "org.eclipse.dataspacetck.dsp.system.DspSystemLauncher")
}

tasks.jar {
Expand Down
29 changes: 29 additions & 0 deletions config/tck/sample.tck.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Contains sample configuration options
dataspacetck.dsp.local.connector=false
dataspacetck.debug=true
dataspacetck.dsp.connector.http.url=http://localhost:8282/api/v1/dsp/

# Sets the dataset and offer ids to use for contract negotiation scenarios
CN_01_01_DATASETID=ACN0101
CN_01_01_OFFERID=CD123:ACN0101:456
CN_01_02_DATASETID=ACN0102
CN_01_02_OFFERID=CD123:ACN0102:456
CN_01_03_DATASETID=ACN0103
CN_01_03_OFFERID=CD123:ACN0103:456
CN_01_04_DATASETID=ACN0104
CN_01_04_OFFERID=CD123:ACN0104:456

CN_02_01_DATASETID=ACN0201
CN_02_01_OFFERID=CD123:ACN0201:456
CN_02_02_DATASETID=ACN0202
CN_02_02_OFFERID=CD123:ACN0202:456
CN_02_03_DATASETID=ACN0203
CN_02_03_OFFERID=CD123:ACN0203:456
CN_02_04_DATASETID=ACN0204
CN_02_04_OFFERID=CD123:ACN0204:456
CN_02_05_DATASETID=ACN0205
CN_02_05_OFFERID=CD123:ACN0205:456
CN_02_06_DATASETID=ACN0206
CN_02_06_OFFERID=CD123:ACN0206:456
CN_02_07_DATASETID=ACN0207
CN_02_07_OFFERID=CD123:ACN0207:456
4 changes: 3 additions & 1 deletion core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@
*
*
*/

dependencies {
api(project(":boot"))
}

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.eclipse.dataspacetck.core.api.message;

import com.apicatalog.jsonld.JsonLdError;
import com.apicatalog.jsonld.JsonLdOptions;
import com.apicatalog.jsonld.document.JsonDocument;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down Expand Up @@ -60,29 +61,35 @@ public static String serialize(Object object) {
}
}

public static Map<String, Object> processJsonLd(InputStream stream) {
public static Map<String, Object> processJsonLd(InputStream stream, Map<String, Object> context) {
try {
return processJsonLd(JsonDocument.of(MAPPER.readValue(stream, JsonObject.class)));
return processJsonLd(MAPPER.readValue(stream, JsonObject.class), context);
} catch (IOException e) {
throw new RuntimeException(e);
}
}

public static Map<String, Object> processJsonLd(Map<String, Object> message) {
return processJsonLd(JsonDocument.of(MAPPER.convertValue(message, JsonObject.class)));
public static Map<String, Object> processJsonLd(Map<String, Object> message, Map<String, Object> context) {
return processJsonLd(MAPPER.convertValue(message, JsonObject.class), context);
}

@SuppressWarnings("unchecked")
private static Map<String, Object> processJsonLd(JsonDocument document) {
private static Map<String, Object> processJsonLd(JsonObject document, Map<String, Object> context) {
try {
var jsonArray = expand(document).get();
var options = new JsonLdOptions();
options.setExpandContext(MAPPER.convertValue(context, JsonObject.class));
options.setCompactArrays(true);
var jsonArray = expand(JsonDocument.of(document)).options(options).get();
if (jsonArray.isEmpty()) {
throw new AssertionError("Invalid Json document, expecting a non-empty array");
}
@SuppressWarnings("SequencedCollectionMethodCanBeUsed")
var expanded = jsonArray.get(0);
var compacted = compact(JsonDocument.of(MAPPER.convertValue(expanded, JsonObject.class)), EMPTY_CONTEXT).get();
return MAPPER.convertValue(compacted, Map.class);
return MAPPER.convertValue(expanded, Map.class);

//var compacted = compact(JsonDocument.of(MAPPER.convertValue(expanded, JsonObject.class)), EMPTY_CONTEXT).get();

// return MAPPER.convertValue(compacted, Map.class);
} catch (JsonLdError e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package org.eclipse.dataspacetck.core.api.system;

import java.io.InputStream;
import java.util.function.Function;

/**
Expand All @@ -29,7 +30,7 @@ public interface CallbackEndpoint {
/**
* Registers a response handler for the given callback path.
*/
void registerHandler(String path, Function<Object, Object> consumer);
void registerHandler(String path, Function<InputStream, String> consumer);

/**
* Deregisters a response handler.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
* Constants for system configuration.
*/
public interface SystemsConstants {
String CVF_CALLBACK_ADDRESS = "cvf.callback.address";
String CVF_LAUNCHER = "cvf.launcher";
String TCK_PREFIX = "dataspacetck";
String TCK_CALLBACK_ADDRESS = TCK_PREFIX + ".callback.address";
String TCK_DEFAULT_CALLBACK_ADDRESS = "http://localhost:8083";
String TCK_LAUNCHER = TCK_PREFIX + ".launcher";
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,27 @@

package org.eclipse.dataspacetck.core.spi.system;

import org.eclipse.dataspacetck.core.spi.boot.Monitor;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;

import static java.lang.Boolean.parseBoolean;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;

/**
* Configuration used to start a {@link SystemLauncher}.
*/
public abstract class AbstractConfiguration {
protected Function<String, String> propertyDelegate = k -> null;
protected Map<String, String> extensibleConfiguration = new HashMap<>();
protected Monitor monitor;

public Monitor getMonitor() {
return monitor;
}

public String getPropertyAsString(String key, String defaultValue) {
var value = getProperty(key);
Expand All @@ -39,6 +47,11 @@ public int getPropertyAsInt(String key, int defaultValue) {
return value != null ? parseInt(value) : defaultValue;
}

public long getPropertyAsLong(String key, long defaultValue) {
var value = getProperty(key);
return value != null ? parseLong(value) : defaultValue;
}

public boolean getPropertyAsBoolean(String key, boolean defaultValue) {
var value = getProperty(key);
return value != null ? parseBoolean(value) : defaultValue;
Expand All @@ -57,13 +70,18 @@ private String getProperty(String key) {

public abstract static class Builder<B extends Builder<?>> {

@SuppressWarnings("unchecked")
public B monitor(Monitor monitor) {
getConfiguration().monitor = monitor;
return (B) this;
}

@SuppressWarnings("unchecked")
public B property(String key, String value) {
getConfiguration().extensibleConfiguration.put(key, value);
return (B) this;
}


@SuppressWarnings("unchecked")
public B propertyDelegate(Function<String, String> delegate) {
getConfiguration().propertyDelegate = delegate;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2024 Metaform Systems, Inc.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Metaform Systems, Inc. - initial API and implementation
*
*/

package org.eclipse.dataspacetck.core.system;

/**
* Configuration manipulation functions.
*/
public class ConfigFunctions {

/**
* Returns a configuration value by checking system properties and then env variables. Keys are converted to uppercase and
* "." is replaced by "_" when checking for env variables.
*/
public static String propertyOrEnv(String key, String defaultValue) {
var value = System.getProperty(key);
if (exists(value)) {
return value;
}
var upperKey = key.toUpperCase().replace('.', '_');
value = System.getenv(upperKey);
if (exists(value)) {
return value;
}
return defaultValue;
}

private static boolean exists(String value) {
return value != null && !value.trim().isEmpty();
}

private ConfigFunctions() {
}
}
Loading

0 comments on commit a60c946

Please sign in to comment.