Skip to content

Commit 8a3a9c7

Browse files
committed
removed "version" from DittoHeaderDefinition - too generic name for something Ditto does no longer need (only one supported version)
1 parent 2fe29b4 commit 8a3a9c7

File tree

10 files changed

+34
-71
lines changed

10 files changed

+34
-71
lines changed

base/model/src/main/java/org/eclipse/ditto/base/model/headers/AbstractDittoHeaders.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,7 @@ public Optional<ContentType> getDittoContentType() {
181181

182182
@Override
183183
public Optional<JsonSchemaVersion> getSchemaVersion() {
184-
return getStringForDefinition(DittoHeaderDefinition.SCHEMA_VERSION)
185-
.map(Integer::valueOf)
186-
.flatMap(JsonSchemaVersion::forInt);
184+
return Optional.of(JsonSchemaVersion.V_2);
187185
}
188186

189187
@Override

base/model/src/main/java/org/eclipse/ditto/base/model/headers/AbstractDittoHeadersBuilder.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,7 @@ protected void putCharSequence(final HeaderDefinition definition, @Nullable fina
245245

246246
@Override
247247
public S schemaVersion(@Nullable final JsonSchemaVersion schemaVersion) {
248-
if (null != schemaVersion) {
249-
putCharSequence(DittoHeaderDefinition.SCHEMA_VERSION, schemaVersion.toString());
250-
} else {
251-
removeHeader(DittoHeaderDefinition.SCHEMA_VERSION.getKey());
252-
}
248+
// no-op
253249
return myself;
254250
}
255251

base/model/src/main/java/org/eclipse/ditto/base/model/headers/DittoHeaderDefinition.java

-8
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,6 @@ public enum DittoHeaderDefinition implements HeaderDefinition {
5252
*/
5353
CORRELATION_ID("correlation-id", String.class, true, true, HeaderValueValidators.getNonEmptyValidator()),
5454

55-
/**
56-
* Header definition for schema version value.
57-
* <p>
58-
* Key: {@code "version"}, Java type: {@code int}.
59-
* </p>
60-
*/
61-
SCHEMA_VERSION("version", int.class, true, true, HeaderValueValidators.getIntValidator()),
62-
6355
/**
6456
* Header definition for response required value.
6557
* <p>

base/model/src/test/java/org/eclipse/ditto/base/model/headers/BooleanValueValidatorTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public void acceptFalseCharSequence() {
8484

8585
@Test
8686
public void doesNotValidateAsDefinedJavaTypeIsNotBoolean() {
87-
assertThatCode(() -> underTest.accept(DittoHeaderDefinition.SCHEMA_VERSION, BOOLEAN_CHAR_SEQUENCE))
87+
assertThatCode(() -> underTest.accept(DittoHeaderDefinition.CHANNEL, BOOLEAN_CHAR_SEQUENCE))
8888
.doesNotThrowAnyException();
8989
}
9090

base/model/src/test/java/org/eclipse/ditto/base/model/headers/DefaultDittoHeadersBuilderTest.java

+4-25
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ public void emptyReturnsEmptyDittoHeaders() {
7575

7676
DittoBaseAssertions.assertThat(dittoHeaders)
7777
.hasNoCorrelationId()
78-
.hasNoSchemaVersion()
7978
.hasNoAuthorizationSubjects()
8079
.hasNoReadGrantedSubjects();
8180
}
@@ -94,15 +93,6 @@ public void tryToSetEmptyCorrelationId() {
9493
underTest.correlationId("");
9594
}
9695

97-
@Test
98-
public void setNullSchemaVersionRemovesSchemaVersion() {
99-
underTest.schemaVersion(JSON_SCHEMA_VERSION);
100-
underTest.schemaVersion(null);
101-
final DittoHeaders dittoHeaders = underTest.build();
102-
103-
assertThat(dittoHeaders.getSchemaVersion()).isEmpty();
104-
}
105-
10696
@Test
10797
public void buildReturnsExpected() {
10898
final DittoHeaders dittoHeaders = underTest.correlationId(CORRELATION_ID)
@@ -175,17 +165,6 @@ public void jsonRepresentationOfDittoHeadersWithCorrelationIdOnlyIsExpected() {
175165
.contains(JsonFactory.newKey(DittoHeaderDefinition.CORRELATION_ID.getKey()), CORRELATION_ID);
176166
}
177167

178-
@Test
179-
public void jsonRepresentationOfDittoHeadersWithSchemaVersionOnlyIsExpected() {
180-
final DittoHeaders dittoHeaders = underTest.schemaVersion(JSON_SCHEMA_VERSION).build();
181-
final JsonObject jsonObject = dittoHeaders.toJson();
182-
183-
assertThat(jsonObject)
184-
.hasSize(1)
185-
.contains(JsonFactory.newKey(DittoHeaderDefinition.SCHEMA_VERSION.getKey()),
186-
JsonFactory.newValue(JSON_SCHEMA_VERSION.toInt()));
187-
}
188-
189168
@Test
190169
public void jsonRepresentationOfDittoHeadersWithChannelOnlyIsExpected() {
191170
final DittoHeaders dittoHeaders = underTest.channel(CHANNEL).build();
@@ -260,7 +239,7 @@ public void tryToCreateInstanceWithMapContainingInvalidHeader() {
260239

261240
@Test
262241
public void tryToCreateInstanceWithJsonObjectContainingInvalidHeader() {
263-
final String schemaVersionKey = DittoHeaderDefinition.SCHEMA_VERSION.getKey();
242+
final String schemaVersionKey = DittoHeaderDefinition.RESPONSE_REQUIRED.getKey();
264243
final String invalidSchemaVersionValue = "meh";
265244

266245
final JsonObject headersJsonObject = JsonFactory.newObjectBuilder()
@@ -271,7 +250,7 @@ public void tryToCreateInstanceWithJsonObjectContainingInvalidHeader() {
271250

272251
assertThatExceptionOfType(DittoHeaderInvalidException.class)
273252
.isThrownBy(() -> of(headersJsonObject))
274-
.withMessage("The value '%s' of the header '%s' is not a valid int.", invalidSchemaVersionValue,
253+
.withMessage("The value '%s' of the header '%s' is not a valid boolean.", invalidSchemaVersionValue,
275254
schemaVersionKey)
276255
.withNoCause();
277256
}
@@ -304,7 +283,7 @@ public void removePreconditionHeaders() {
304283

305284
@Test
306285
public void tryToPutMapWithInvalidMessageHeader() {
307-
final String key = DittoHeaderDefinition.SCHEMA_VERSION.getKey();
286+
final String key = DittoHeaderDefinition.RESPONSE_REQUIRED.getKey();
308287
final String invalidValue = "bar";
309288

310289
final Map<String, String> invalidHeaders = new HashMap<>();
@@ -313,7 +292,7 @@ public void tryToPutMapWithInvalidMessageHeader() {
313292

314293
assertThatExceptionOfType(DittoHeaderInvalidException.class)
315294
.isThrownBy(() -> underTest.putHeaders(invalidHeaders))
316-
.withMessage("The value '%s' of the header '%s' is not a valid int.", invalidValue, key)
295+
.withMessage("The value '%s' of the header '%s' is not a valid boolean.", invalidValue, key)
317296
.withNoCause();
318297
}
319298

base/model/src/test/java/org/eclipse/ditto/base/model/headers/ImmutableDittoHeadersTest.java

-2
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,6 @@ public void toJsonReturnsExpected() {
494494
final JsonObject expectedHeadersJsonObject = JsonFactory.newObjectBuilder()
495495
.set(DittoHeaderDefinition.AUTHORIZATION_CONTEXT.getKey(), AUTH_CONTEXT.toJson())
496496
.set(DittoHeaderDefinition.CORRELATION_ID.getKey(), KNOWN_CORRELATION_ID)
497-
.set(DittoHeaderDefinition.SCHEMA_VERSION.getKey(), KNOWN_SCHEMA_VERSION.toInt())
498497
.set(DittoHeaderDefinition.CHANNEL.getKey(), KNOWN_CHANNEL)
499498
.set(DittoHeaderDefinition.RESPONSE_REQUIRED.getKey(), KNOWN_RESPONSE_REQUIRED)
500499
.set(DittoHeaderDefinition.DRY_RUN.getKey(), false)
@@ -730,7 +729,6 @@ private static Map<String, String> createMapContainingAllKnownHeaders() {
730729
final Map<String, String> result = new LinkedHashMap<>();
731730
result.put(DittoHeaderDefinition.AUTHORIZATION_CONTEXT.getKey(), AUTH_CONTEXT.toJsonString());
732731
result.put(DittoHeaderDefinition.CORRELATION_ID.getKey(), KNOWN_CORRELATION_ID);
733-
result.put(DittoHeaderDefinition.SCHEMA_VERSION.getKey(), KNOWN_SCHEMA_VERSION.toString());
734732
result.put(DittoHeaderDefinition.CHANNEL.getKey(), KNOWN_CHANNEL);
735733
result.put(DittoHeaderDefinition.RESPONSE_REQUIRED.getKey(), String.valueOf(KNOWN_RESPONSE_REQUIRED));
736734
result.put(DittoHeaderDefinition.DRY_RUN.getKey(), String.valueOf(false));

base/model/src/test/java/org/eclipse/ditto/base/model/headers/IntValueValidatorTest.java

+1-26
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@
1313
package org.eclipse.ditto.base.model.headers;
1414

1515
import static org.assertj.core.api.Assertions.assertThatCode;
16-
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
1716
import static org.assertj.core.api.Assertions.assertThatNullPointerException;
1817
import static org.mutabilitydetector.unittesting.MutabilityAssert.assertInstancesOf;
1918
import static org.mutabilitydetector.unittesting.MutabilityMatchers.areImmutable;
2019

2120
import org.assertj.core.api.AutoCloseableSoftAssertions;
22-
import org.eclipse.ditto.base.model.exceptions.DittoHeaderInvalidException;
2321
import org.junit.Before;
2422
import org.junit.Test;
2523

@@ -48,18 +46,6 @@ public void tryToAcceptNullDefinition() {
4846
.withNoCause();
4947
}
5048

51-
@Test
52-
public void tryToAcceptNullValue() {
53-
final DittoHeaderDefinition headerDefinition = DittoHeaderDefinition.SCHEMA_VERSION;
54-
55-
assertThatExceptionOfType(DittoHeaderInvalidException.class)
56-
.isThrownBy(() -> underTest.accept(headerDefinition, null))
57-
.withMessageContaining("null")
58-
.withMessageContaining(headerDefinition.getKey())
59-
.withMessageEndingWith("is not a valid int.")
60-
.withNoCause();
61-
}
62-
6349
@Test
6450
public void canValidateInteger() {
6551
try (final AutoCloseableSoftAssertions softly = new AutoCloseableSoftAssertions()) {
@@ -70,7 +56,7 @@ public void canValidateInteger() {
7056

7157
@Test
7258
public void acceptValidCharSequence() {
73-
assertThatCode(() -> underTest.accept(DittoHeaderDefinition.SCHEMA_VERSION, "2"))
59+
assertThatCode(() -> underTest.accept(DittoHeaderDefinition.RESPONSE_REQUIRED, "false"))
7460
.doesNotThrowAnyException();
7561
}
7662

@@ -80,15 +66,4 @@ public void doesNotValidateAsDefinedJavaTypeIsNotInt() {
8066
.doesNotThrowAnyException();
8167
}
8268

83-
@Test
84-
public void acceptInvalidCharSequence() {
85-
final String invalidInt = "true";
86-
87-
assertThatExceptionOfType(DittoHeaderInvalidException.class)
88-
.isThrownBy(() -> underTest.accept(DittoHeaderDefinition.SCHEMA_VERSION, invalidInt))
89-
.withMessageContaining(invalidInt)
90-
.withMessageEndingWith("is not a valid int.")
91-
.withNoCause();
92-
}
93-
9469
}

messages/model/src/test/java/org/eclipse/ditto/messages/model/ImmutableMessageHeadersTest.java

-1
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,6 @@ private static Map<String, String> createMapContainingAllKnownHeaders() {
305305
result.put(DittoHeaderDefinition.AUTHORIZATION_CONTEXT.getKey(),
306306
AUTH_CONTEXT_WITHOUT_DUPLICATES.toJsonString());
307307
result.put(DittoHeaderDefinition.CORRELATION_ID.getKey(), "knownCorrelationId");
308-
result.put(DittoHeaderDefinition.SCHEMA_VERSION.getKey(), KNOWN_SCHEMA_VERSION.toString());
309308
result.put(DittoHeaderDefinition.CHANNEL.getKey(), KNOWN_CHANNEL);
310309
result.put(DittoHeaderDefinition.RESPONSE_REQUIRED.getKey(), String.valueOf(KNOWN_RESPONSE_REQUIRED));
311310
result.put(DittoHeaderDefinition.DRY_RUN.getKey(), String.valueOf(false));

wot/integration/src/main/java/org/eclipse/ditto/wot/integration/generator/WotThingModelExtensionResolver.java

+13
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
package org.eclipse.ditto.wot.integration.generator;
1414

1515
import java.util.concurrent.CompletionStage;
16+
import java.util.concurrent.Executor;
1617

1718
import org.eclipse.ditto.base.model.headers.DittoHeaders;
19+
import org.eclipse.ditto.wot.integration.provider.WotThingModelFetcher;
1820
import org.eclipse.ditto.wot.model.ThingModel;
1921

2022
/**
@@ -56,4 +58,15 @@ public interface WotThingModelExtensionResolver {
5658
* be parsed/interpreted as correct WoT ThingModel.
5759
*/
5860
CompletionStage<ThingModel> resolveThingModelRefs(ThingModel thingModel, DittoHeaders dittoHeaders);
61+
62+
/**
63+
* Creates a new instance of WotThingModelExtensionResolver with the given {@code thingModelFetcher}.
64+
*
65+
* @param thingModelFetcher the ThingModel fetcher to fetch linked other ThingModels during the generation process.
66+
* @param executor the executor to use for async tasks.
67+
* @return the created WotThingSkeletonGenerator.
68+
*/
69+
static WotThingModelExtensionResolver of(final WotThingModelFetcher thingModelFetcher, final Executor executor) {
70+
return new DefaultWotThingModelExtensionResolver(thingModelFetcher, executor);
71+
}
5972
}

wot/integration/src/main/java/org/eclipse/ditto/wot/integration/provider/WotThingModelFetcher.java

+13
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
import java.net.URL;
1616
import java.util.concurrent.CompletionStage;
1717

18+
import org.apache.pekko.actor.ActorSystem;
1819
import org.eclipse.ditto.base.model.headers.DittoHeaders;
20+
import org.eclipse.ditto.wot.integration.config.WotConfig;
1921
import org.eclipse.ditto.wot.model.IRI;
2022
import org.eclipse.ditto.wot.model.ThingModel;
2123

@@ -54,4 +56,15 @@ public interface WotThingModelFetcher {
5456
* fetched at the given {@code url}.
5557
*/
5658
CompletionStage<ThingModel> fetchThingModel(URL url, DittoHeaders dittoHeaders);
59+
60+
/**
61+
* Creates a new instance of WotThingModelExtensionResolver with the given {@code actorSystem}.
62+
*
63+
* @param actorSystem the actor system to use.
64+
* @param wotConfig the WoTConfig to use for creating the generator.
65+
* @return the created WotThingSkeletonGenerator.
66+
*/
67+
static WotThingModelFetcher of(final ActorSystem actorSystem, final WotConfig wotConfig) {
68+
return new DefaultWotThingModelFetcher(actorSystem, wotConfig);
69+
}
5770
}

0 commit comments

Comments
 (0)