Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Johannes Schneider <johannes.schneider@bosch.io>
  • Loading branch information
jokraehe committed Jun 20, 2022
1 parent 77c7438 commit bc93ef1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@
import static org.mutabilitydetector.unittesting.MutabilityAssert.assertInstancesOf;
import static org.mutabilitydetector.unittesting.MutabilityMatchers.areImmutable;

import org.assertj.core.api.AutoCloseableSoftAssertions;
import org.eclipse.ditto.json.JsonFactory;
import org.eclipse.ditto.json.JsonKey;
import org.eclipse.ditto.json.JsonPointer;
import org.junit.Ignore;
import org.junit.Test;

import nl.jqno.equalsverifier.EqualsVerifier;
import org.assertj.core.api.AutoCloseableSoftAssertions;
import org.junit.Test;

/**
* Unit tests for {@link org.eclipse.ditto.base.model.headers.metadata.DefaultMetadataHeaderKey}.
Expand Down Expand Up @@ -79,22 +78,6 @@ public void wildcardPathHasTooManyLevels() {
.withNoCause();
}

@Test
public void wildcardPathHasAsteriskLeaf() {
assertThatIllegalArgumentException()
.isThrownBy(() -> DefaultMetadataHeaderKey.of(JsonPointer.of("/*/*")))
.withMessage("The path of a metadata header key must not contain <*> at level <1>!")
.withNoCause();
}

@Test
public void pathContainsAsteriskAtWrongLevel() {
assertThatIllegalArgumentException()
.isThrownBy(() -> DefaultMetadataHeaderKey.of(JsonPointer.of("/foo/*/baz")))
.withMessage("The path of a metadata header key must not contain <*> at level <1>!")
.withNoCause();
}

@Test
public void tryToParseNullString() {
assertThatNullPointerException()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,21 +141,18 @@ public void createMetadataFromScratch() {
final DittoHeaders dittoHeaders = DittoHeaders.newBuilder()
.putMetadata(MetadataHeaderKey.parse("/scruplusFine"), JsonValue.of("^6,00.32"))
.putMetadata(MetadataHeaderKey.parse("/properties/grumbo/froodNoops"), JsonValue.of(5))
.putMetadata(MetadataHeaderKey.parse("/*/lastSeen"), JsonValue.of(1955))
.putMetadata(MetadataHeaderKey.parse("/properties/*/lastSeen"), JsonValue.of(1955))
.build();
final ModifyFeature modifyFeature = ModifyFeature.of(thingWithoutMetadata.getEntityId().orElseThrow(),
modifiedFeature,
dittoHeaders);
final Metadata expected = Metadata.newBuilder()
.set(JsonPointer.of("scruplusFine"), "^6,00.32")
.set(JsonPointer.of("definition/lastSeen"), 1955)
.set(JsonPointer.of("properties/capacity/value/lastSeen"), 1955)
.set(JsonPointer.of("properties/capacity/unit/lastSeen"), 1955)
.set(JsonPointer.of("properties/grumbo/froodNoops"), 5)
.set(JsonPointer.of("properties/grumbo/lastSeen"), 1955)
.set(JsonPointer.of("properties/capacity/lastSeen"), 1955)
.build();

final MetadataFromCommand underTest = MetadataFromCommand.of(modifyFeature, null, null);
final MetadataFromCommand underTest = MetadataFromCommand.of(modifyFeature, thingWithoutMetadata, null);

assertThat(underTest.get()).isEqualTo(expected);
}
Expand All @@ -175,22 +172,20 @@ public void modifyExistingMetadata() {
final DittoHeaders dittoHeaders = DittoHeaders.newBuilder()
.putMetadata(MetadataHeaderKey.parse("/scruplusFine"), JsonValue.of("^6,00.32"))
.putMetadata(MetadataHeaderKey.parse("/properties/grumbo/froodNoops"), JsonValue.of(5))
.putMetadata(MetadataHeaderKey.parse("/*/lastSeen"), JsonValue.of(1955))
.putMetadata(MetadataHeaderKey.parse("/properties/*/lastSeen"), JsonValue.of(1955))
.build();
final ModifyFeature modifyFeature = ModifyFeature.of(thingWithoutMetadata.getEntityId().orElseThrow(),
modifiedFeature,
dittoHeaders);
final Metadata expected = existingMetadata.toBuilder()
.set(JsonPointer.of("airplaneMode"), "forbidden")
.set(JsonPointer.of("scruplusFine"), "^6,00.32")
.set(JsonPointer.of("definition/lastSeen"), 1955)
.set(JsonPointer.of("properties/capacity/value/lastSeen"), 1955)
.set(JsonPointer.of("properties/capacity/unit/lastSeen"), 1955)
.set(JsonPointer.of("definition/lastSeen"), 2023)
.set(JsonPointer.of("properties/capacity/lastSeen"), 1955)
.set(JsonPointer.of("properties/grumbo/froodNoops"), 5)
.set(JsonPointer.of("properties/grumbo/lastSeen"), 1955)
.build();

final MetadataFromCommand underTest = MetadataFromCommand.of(modifyFeature, null, existingMetadata);
final MetadataFromCommand underTest = MetadataFromCommand.of(modifyFeature, thingWithoutMetadata, existingMetadata);

assertThat(underTest.get()).isEqualTo(expected);
}
Expand All @@ -200,8 +195,8 @@ public void keyWithSpecificPathOverwritesKeyWithWildcardPath() {
final JsonValue metric = JsonValue.of("metric");
final JsonValue nonMetric = JsonValue.of("non-metric");
final DittoHeaders dittoHeaders = DittoHeaders.newBuilder()
.putMetadata(MetadataHeaderKey.parse("/properties/capacity/unit/type"), nonMetric)
.putMetadata(MetadataHeaderKey.parse("/*/type"), metric)
.putMetadata(MetadataHeaderKey.parse("/properties/capacity/type"), nonMetric)
.putMetadata(MetadataHeaderKey.parse("/properties/*/type"), metric)
.build();
final Feature modifiedFeature = fluxCapacitor.toBuilder()
.properties(fluxCapacitorProperties.toBuilder()
Expand All @@ -213,13 +208,10 @@ public void keyWithSpecificPathOverwritesKeyWithWildcardPath() {
modifiedFeature,
dittoHeaders);
final Metadata expected = Metadata.newBuilder()
.set(JsonPointer.of("definition/type"), metric)
.set(JsonPointer.of("properties/capacity/value/type"), metric)
.set(JsonPointer.of("properties/capacity/unit/type"), nonMetric)
.set(JsonPointer.of("properties/grumbo/type"), metric)
.set(JsonPointer.of("properties/capacity/type"), nonMetric)
.build();

final MetadataFromCommand underTest = MetadataFromCommand.of(modifyFeature, null,
final MetadataFromCommand underTest = MetadataFromCommand.of(modifyFeature, thingWithoutMetadata,
thingWithoutMetadata.getMetadata().orElse(null));

assertThat(underTest.get()).isEqualTo(expected);
Expand Down

0 comments on commit bc93ef1

Please sign in to comment.