Skip to content

Commit

Permalink
#288 add implementation of getEntity(JsonSchemaVersion schemaVersion)…
Browse files Browse the repository at this point in the history
… to MergeThing;

fixed test in ThingMergedStrategyTest for replacing metadata;

Signed-off-by: Stefan Maute <stefan.maute@bosch.io>
  • Loading branch information
Stefan Maute committed Jan 13, 2021
1 parent 5a66616 commit 1e98f67
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,4 @@ abstract class AbstractStrategyTest {
*/
static final long NEXT_REVISION = 1;

/**
* Metadata of a Thing.
*/
static final Metadata METADATA = Metadata.newBuilder().set("hello", "world").build();

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@

import java.time.Instant;

import org.eclipse.ditto.json.JsonArray;
import org.eclipse.ditto.json.JsonPointer;
import org.eclipse.ditto.model.base.entity.metadata.Metadata;
import org.eclipse.ditto.model.base.headers.DittoHeaders;
import org.eclipse.ditto.model.things.Thing;
import org.eclipse.ditto.model.things.ThingLifecycle;
import org.eclipse.ditto.model.things.ThingsModelFactory;
import org.eclipse.ditto.signals.commands.things.TestConstants;
import org.eclipse.ditto.signals.events.things.ThingMerged;
import org.junit.Ignore;
import org.junit.Test;

/**
Expand All @@ -35,6 +34,13 @@
public final class ThingMergedStrategyTest extends AbstractStrategyTest {

private static final Instant TIMESTAMP = Instant.now();
private static final String METADATA_KEY = "description";
private static final String METADATA_VALUE = "description of the location";
private static final Metadata METADATA = Metadata.newBuilder().set(METADATA_KEY, METADATA_VALUE).build();
private static final Metadata EXPECTED_METADATA = Metadata.newBuilder()
.set(TestConstants.Thing.ABSOLUTE_LOCATION_ATTRIBUTE_POINTER.append(JsonPointer.of(METADATA_KEY)),
METADATA_VALUE)
.build();

@Test
public void assertImmutability() {
Expand All @@ -46,7 +52,7 @@ public void appliesEventCorrectly() {
final ThingMergedStrategy strategy = new ThingMergedStrategy();
final ThingMerged event = ThingMerged.of(THING.getEntityId().orElseThrow(),
TestConstants.Thing.ABSOLUTE_LOCATION_ATTRIBUTE_POINTER,
TestConstants.Thing.LOCATION_ATTRIBUTE_VALUE, REVISION, TIMESTAMP, DittoHeaders.empty(), null);
TestConstants.Thing.LOCATION_ATTRIBUTE_VALUE, REVISION, TIMESTAMP, DittoHeaders.empty(), METADATA);

final Thing thingWithMergeApplied = strategy.handle(event, THING, NEXT_REVISION);

Expand All @@ -57,20 +63,23 @@ public void appliesEventCorrectly() {
.setLifecycle(ThingLifecycle.ACTIVE)
.setRevision(NEXT_REVISION)
.setModified(TIMESTAMP)
.setMetadata(EXPECTED_METADATA)
.build();

assertThat(thingWithMergeApplied).isEqualTo(expected);
}

@Test
@Ignore
// TODO either delete this test or get it to work after it is decided who to merge metadata for merged thing event.
public void replacesPreviousMetadata() {
final ThingMergedStrategy strategy = new ThingMergedStrategy();
final ThingMerged event = ThingMerged.of(THING.getEntityId().orElseThrow(),
TestConstants.Thing.ABSOLUTE_LOCATION_ATTRIBUTE_POINTER,
TestConstants.Thing.LOCATION_ATTRIBUTE_VALUE, REVISION, TIMESTAMP, DittoHeaders.empty(), METADATA);

final Metadata previousMetadata = Metadata.newBuilder().set("additives", JsonArray.of("[\"E129\"]")).build();
final Metadata previousMetadata = Metadata.newBuilder()
.set(TestConstants.Thing.ABSOLUTE_LOCATION_ATTRIBUTE_POINTER.append(JsonPointer.of(METADATA_KEY)),
"description")
.build();
final Thing thingWithMergeApplied =
strategy.handle(event, THING.toBuilder().setMetadata(previousMetadata).build(), NEXT_REVISION);

Expand All @@ -81,8 +90,9 @@ public void replacesPreviousMetadata() {
.setLifecycle(ThingLifecycle.ACTIVE)
.setRevision(NEXT_REVISION)
.setModified(TIMESTAMP)
.setMetadata(METADATA)
.setMetadata(EXPECTED_METADATA)
.build();

assertThat(thingWithMergeApplied).isEqualTo(expected);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
public final class ThingModifiedStrategyTest extends AbstractStrategyTest {

private static final Instant TIMESTAMP = Instant.now();
private static final Metadata METADATA = Metadata.newBuilder().set("hello", "world").build();

@Test
public void assertImmutability() {
Expand All @@ -51,6 +52,7 @@ public void appliesEventCorrectly() {
.setModified(TIMESTAMP)
.setMetadata(METADATA)
.build();

assertThat(thingWithEventApplied).isEqualTo(expected);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,11 @@ public Optional<JsonValue> getEntity() {
return Optional.of(value);
}

@Override
public Optional<JsonValue> getEntity(final JsonSchemaVersion schemaVersion) {
return Optional.of(value);
}

@Override
public JsonPointer getResourcePath() {
return path;
Expand Down

0 comments on commit 1e98f67

Please sign in to comment.