Skip to content

Commit

Permalink
eclipse-ditto#1650 provide WoT TM validation
Browse files Browse the repository at this point in the history
* restructuring of "ditto-wot" module to enable re-usability of non-pekko/non-Ditto specifics
* adding "validator" concept and first sample implementation (WIP)

Signed-off-by: Thomas Jäckle <[email protected]>
  • Loading branch information
thjaeckle committed May 6, 2024
1 parent 3aca212 commit 4029fcf
Show file tree
Hide file tree
Showing 147 changed files with 3,682 additions and 1,141 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -384,11 +384,6 @@ protected void appendPayload(final JsonObjectBuilder jsonObjectBuilder,
getFilter().ifPresent(theFilter -> jsonObjectBuilder.set(JsonFields.FILTER, theFilter));
}

@Override
public String getTypePrefix() {
return TYPE_PREFIX;
}

@Override
public SubscribeForPersistedEvents setDittoHeaders(final DittoHeaders dittoHeaders) {
return new SubscribeForPersistedEvents(entityId, resourcePath, fromHistoricalRevision, toHistoricalRevision,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,108 +14,21 @@

import javax.annotation.concurrent.Immutable;

import org.eclipse.ditto.internal.utils.config.KnownConfigValue;

import org.apache.pekko.http.javadsl.ClientTransport;
import org.eclipse.ditto.internal.utils.config.http.HttpProxyBaseConfig;

/**
* Provides configuration settings for the HTTP proxy.
*/
@Immutable
public interface HttpProxyConfig {

/**
* Indicates whether the HTTP proxy should be enabled.
*
* @return {@code true} if the HTTP proxy should be enabled, {@code false} else.
*/
boolean isEnabled();

/**
* Returns the host name of the HTTP proxy.
*
* @return the host name
*/
String getHostname();

/**
* Returns the port of the HTTP proxy.
*
* @return the port.
*/
int getPort();

/**
* Returns the user name of the HTTP proxy.
*
* @return the user name.
*/
String getUsername();
public interface HttpProxyConfig extends HttpProxyBaseConfig {

/**
* Returns the password of the HTTP proxy.
*
* @return the password.
*/
String getPassword();

/**
* Converts the proxy settings to an Pekko HTTP client transport object.
* Converts the proxy settings to a Pekko HTTP client transport object.
* Does not check whether the proxy is enabled.
*
* @return an Pekko HTTP client transport object matching this config.
* @return a Pekko HTTP client transport object matching this config.
*/
ClientTransport toClientTransport();

/**
* An enumeration of the known config path expressions and their associated default values for
* {@code HttpProxyConfig}.
*/
enum HttpProxyConfigValue implements KnownConfigValue {

/**
* Determines whether the HTTP proxy should be enabled.
*/
ENABLED("enabled", false),

/**
* The host name of the HTTP proxy.
*/
HOST_NAME("hostname", ""),

/**
* The port of the HTTP proxy.
*/
PORT("port", 0),

/**
* The user name of the HTTP proxy.
*/
USER_NAME("username", ""),

/**
* The password of the HTTP proxy.
*/
PASSWORD("password", "");

private final String path;
private final Object defaultValue;

private HttpProxyConfigValue(final String thePath, final Object theDefaultValue) {
path = thePath;
defaultValue = theDefaultValue;
}

@Override
public Object getDefaultValue() {
return defaultValue;
}

@Override
public String getConfigPath() {
return path;
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import static org.mutabilitydetector.unittesting.MutabilityMatchers.areImmutable;

import org.assertj.core.api.JUnitSoftAssertions;
import org.eclipse.ditto.base.service.config.http.HttpProxyConfig.HttpProxyConfigValue;
import org.eclipse.ditto.internal.utils.config.http.HttpProxyBaseConfig;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
Expand Down Expand Up @@ -58,40 +58,40 @@ public void underTestReturnsDefaultValuesIfBaseConfigWasEmpty() {
final DefaultHttpProxyConfig underTest = DefaultHttpProxyConfig.ofHttpProxy(ConfigFactory.empty());

softly.assertThat(underTest.isEnabled())
.as(HttpProxyConfigValue.ENABLED.getConfigPath())
.isEqualTo(HttpProxyConfigValue.ENABLED.getDefaultValue());
.as(HttpProxyBaseConfig.HttpProxyConfigValue.ENABLED.getConfigPath())
.isEqualTo(HttpProxyBaseConfig.HttpProxyConfigValue.ENABLED.getDefaultValue());
softly.assertThat(underTest.getHostname())
.as(HttpProxyConfigValue.HOST_NAME.getConfigPath())
.isEqualTo(HttpProxyConfigValue.HOST_NAME.getDefaultValue());
.as(HttpProxyBaseConfig.HttpProxyConfigValue.HOST_NAME.getConfigPath())
.isEqualTo(HttpProxyBaseConfig.HttpProxyConfigValue.HOST_NAME.getDefaultValue());
softly.assertThat(underTest.getPort())
.as(HttpProxyConfigValue.PORT.getConfigPath())
.isEqualTo(HttpProxyConfigValue.PORT.getDefaultValue());
.as(HttpProxyBaseConfig.HttpProxyConfigValue.PORT.getConfigPath())
.isEqualTo(HttpProxyBaseConfig.HttpProxyConfigValue.PORT.getDefaultValue());
softly.assertThat(underTest.getUsername())
.as(HttpProxyConfigValue.USER_NAME.getConfigPath())
.isEqualTo(HttpProxyConfigValue.USER_NAME.getDefaultValue());
.as(HttpProxyBaseConfig.HttpProxyConfigValue.USER_NAME.getConfigPath())
.isEqualTo(HttpProxyBaseConfig.HttpProxyConfigValue.USER_NAME.getDefaultValue());
softly.assertThat(underTest.getPassword())
.as(HttpProxyConfigValue.PASSWORD.getConfigPath())
.isEqualTo(HttpProxyConfigValue.PASSWORD.getDefaultValue());
.as(HttpProxyBaseConfig.HttpProxyConfigValue.PASSWORD.getConfigPath())
.isEqualTo(HttpProxyBaseConfig.HttpProxyConfigValue.PASSWORD.getDefaultValue());
}

@Test
public void underTestReturnsValuesOfConfigFile() {
final DefaultHttpProxyConfig underTest = DefaultHttpProxyConfig.ofHttpProxy(httpProxyConfig);

softly.assertThat(underTest.isEnabled())
.as(HttpProxyConfigValue.ENABLED.getConfigPath())
.as(HttpProxyBaseConfig.HttpProxyConfigValue.ENABLED.getConfigPath())
.isTrue();
softly.assertThat(underTest.getHostname())
.as(HttpProxyConfigValue.HOST_NAME.getConfigPath())
.as(HttpProxyBaseConfig.HttpProxyConfigValue.HOST_NAME.getConfigPath())
.isEqualTo("example.com");
softly.assertThat(underTest.getPort())
.as(HttpProxyConfigValue.PORT.getConfigPath())
.as(HttpProxyBaseConfig.HttpProxyConfigValue.PORT.getConfigPath())
.isEqualTo(4711);
softly.assertThat(underTest.getUsername())
.as(HttpProxyConfigValue.USER_NAME.getConfigPath())
.as(HttpProxyBaseConfig.HttpProxyConfigValue.USER_NAME.getConfigPath())
.isEqualTo("john.frume");
softly.assertThat(underTest.getPassword())
.as(HttpProxyConfigValue.PASSWORD.getConfigPath())
.as(HttpProxyBaseConfig.HttpProxyConfigValue.PASSWORD.getConfigPath())
.isEqualTo("verySecretPW!");
}

Expand Down
31 changes: 29 additions & 2 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

<properties>
<scala.version>2.13</scala.version> <!-- for scala libraries the scala version is used in their artifactId -->
<scala.full.version>2.13.12</scala.full.version>
<scala.full.version>2.13.14</scala.full.version>
<scala-parser-combinators.version>1.1.2</scala-parser-combinators.version>
<scala-java8-compat.version>1.0.2</scala-java8-compat.version>

Expand All @@ -37,6 +37,7 @@
<!-- ### Compile dependencies versions -->
<minimal-json.version>0.9.5</minimal-json.version>
<jackson-bom.version>2.16.1</jackson-bom.version>
<json-schema-validator.version>1.4.0</json-schema-validator.version>
<typesafe-config.version>1.4.3</typesafe-config.version>
<ssl-config-core.version>0.6.1</ssl-config-core.version>
<kafka-client.version>3.6.1</kafka-client.version>
Expand Down Expand Up @@ -75,7 +76,7 @@
<janino.version>3.1.11</janino.version>

<!-- ### Metrics and Tracing -->
<kamon.version>2.7.0</kamon.version>
<kamon.version>2.7.1</kamon.version>

<jsr305.version>3.0.2</jsr305.version>

Expand Down Expand Up @@ -130,6 +131,22 @@
<scope>import</scope>
</dependency>

<dependency>
<groupId>com.networknt</groupId>
<artifactId>json-schema-validator</artifactId>
<version>${json-schema-validator.version}</version>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>com.typesafe</groupId>
<artifactId>config</artifactId>
Expand Down Expand Up @@ -538,11 +555,21 @@
<artifactId>ditto-rql-query</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.ditto</groupId>
<artifactId>ditto-wot-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.ditto</groupId>
<artifactId>ditto-wot-model</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.ditto</groupId>
<artifactId>ditto-wot-validation</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.ditto</groupId>
<artifactId>ditto-wot-integration</artifactId>
Expand Down
4 changes: 4 additions & 0 deletions connectivity/service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
<groupId>org.eclipse.ditto</groupId>
<artifactId>ditto-wot-model</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.ditto</groupId>
<artifactId>ditto-wot-validation</artifactId>
</dependency>

<dependency>
<groupId>org.eclipse.ditto</groupId>
Expand Down
4 changes: 4 additions & 0 deletions gateway/service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@
<groupId>org.eclipse.ditto</groupId>
<artifactId>ditto-wot-model</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.ditto</groupId>
<artifactId>ditto-wot-validation</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.ditto</groupId>
<artifactId>ditto-internal-models-signalenrichment</artifactId>
Expand Down
5 changes: 5 additions & 0 deletions internal/utils/cache-loaders/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.pekko</groupId>
<artifactId>pekko-slf4j_${scala.version}</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.pekko</groupId>
<artifactId>pekko-testkit_${scala.version}</artifactId>
Expand Down
12 changes: 0 additions & 12 deletions internal/utils/config/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,6 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.pekko</groupId>
<artifactId>pekko-actor_${scala.version}</artifactId>
</dependency>
<dependency>
<groupId>org.apache.pekko</groupId>
<artifactId>pekko-lease-kubernetes_${scala.version}</artifactId>
</dependency>
<dependency>
<groupId>org.apache.pekko</groupId>
<artifactId>pekko-coordination_${scala.version}</artifactId>
</dependency>

<!-- ### Testing ### -->
<dependency>
Expand Down
Loading

0 comments on commit 4029fcf

Please sign in to comment.