Skip to content

Commit

Permalink
[#106] fixed things-service unit tests after merge from dev
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Jaeckle <thomas.jaeckle@bosch.io>
  • Loading branch information
thjaeckle committed Dec 14, 2021
1 parent 91f7ca2 commit 7c645b5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@
*/
package org.eclipse.ditto.things.service.persistence.actors;

import org.eclipse.ditto.json.JsonObject;
import org.eclipse.ditto.json.JsonPointer;
import org.eclipse.ditto.json.JsonValue;
import javax.annotation.Nullable;

import org.eclipse.ditto.base.model.entity.Revision;
import org.eclipse.ditto.base.model.headers.DittoHeaders;
import org.eclipse.ditto.base.model.headers.entitytag.EntityTag;
import org.eclipse.ditto.json.JsonFieldSelector;
import org.eclipse.ditto.json.JsonObject;
import org.eclipse.ditto.json.JsonPointer;
import org.eclipse.ditto.json.JsonValue;
import org.eclipse.ditto.policies.model.PolicyId;
import org.eclipse.ditto.things.api.commands.sudo.SudoRetrieveThingResponse;
import org.eclipse.ditto.things.model.Attributes;
import org.eclipse.ditto.things.model.Feature;
import org.eclipse.ditto.things.model.FeatureDefinition;
Expand All @@ -28,7 +32,6 @@
import org.eclipse.ditto.things.model.ThingDefinition;
import org.eclipse.ditto.things.model.ThingId;
import org.eclipse.ditto.things.model.ThingRevision;
import org.eclipse.ditto.things.api.commands.sudo.SudoRetrieveThingResponse;
import org.eclipse.ditto.things.model.signals.commands.modify.MergeThingResponse;
import org.eclipse.ditto.things.model.signals.commands.modify.ModifyAttributeResponse;
import org.eclipse.ditto.things.model.signals.commands.modify.ModifyAttributesResponse;
Expand Down Expand Up @@ -67,9 +70,9 @@ private ETagTestUtils() {
// Thing

public static RetrieveThingResponse retrieveThingResponse(final Thing expectedThing,
final JsonObject expectedJsonRepresentation, final DittoHeaders dittoHeaders) {
@Nullable final JsonFieldSelector thingFieldSelector, final DittoHeaders dittoHeaders) {
final DittoHeaders dittoHeadersWithETag = appendETagToDittoHeaders(expectedThing, dittoHeaders);
return RetrieveThingResponse.of(expectedThing.getEntityId().get(), expectedJsonRepresentation.toString(),
return RetrieveThingResponse.of(expectedThing.getEntityId().get(), expectedThing, thingFieldSelector, null,
dittoHeadersWithETag);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public void unavailableExpectedIfPersistenceActorTerminates() throws Exception {
// retrieve created thing
final RetrieveThing retrieveThing = RetrieveThing.of(thingId, dittoHeadersV2);
underTest.tell(retrieveThing, getRef());
expectMsgEquals(ETagTestUtils.retrieveThingResponse(thing, thing.toJson(), dittoHeadersV2));
expectMsgEquals(ETagTestUtils.retrieveThingResponse(thing, null, dittoHeadersV2));

// terminate thing persistence actor
final String thingActorPath = String.format("akka://AkkaTestSystem/user/%s/pa", thingId);
Expand Down Expand Up @@ -479,7 +479,7 @@ public void retrieveThingV2() {
assertThingInResponse(createThingResponse.getThingCreated().orElse(null), thing);

underTest.tell(retrieveThingCommand, getRef());
expectMsgEquals(ETagTestUtils.retrieveThingResponse(thing, thing.toJson(), dittoHeadersV2));
expectMsgEquals(ETagTestUtils.retrieveThingResponse(thing, null, dittoHeadersV2));
}
};
}
Expand Down Expand Up @@ -891,7 +891,7 @@ public void ensureSequenceNumberCorrectness() {
.withSelectedFields(versionFieldSelector)
.build();
underTest.tell(retrieveThing, getRef());
expectMsgEquals(ETagTestUtils.retrieveThingResponse(thingExpected, thingExpected.toJson(versionFieldSelector),
expectMsgEquals(ETagTestUtils.retrieveThingResponse(thingExpected, versionFieldSelector,
dittoHeadersV2));
}
};
Expand Down Expand Up @@ -938,7 +938,7 @@ public void ensureSequenceNumberCorrectnessAfterRecovery() {

Awaitility.await().atMost(10L, TimeUnit.SECONDS).untilAsserted(() -> {
underTestAfterRestart.tell(retrieveThing, getRef());
expectMsgEquals(ETagTestUtils.retrieveThingResponse(thingExpected, thingExpected.toJson(versionFieldSelector),
expectMsgEquals(ETagTestUtils.retrieveThingResponse(thingExpected, versionFieldSelector,
dittoHeadersV2));
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,14 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.eclipse.ditto.things.model.TestConstants.Thing.THING_V2;
import static org.eclipse.ditto.things.service.persistence.actors.ETagTestUtils.retrieveThingResponse;
import static org.mutabilitydetector.unittesting.MutabilityAssert.assertInstancesOf;
import static org.mutabilitydetector.unittesting.MutabilityMatchers.areImmutable;

import org.eclipse.ditto.base.model.headers.DittoHeaders;
import org.eclipse.ditto.internal.utils.persistentactors.commands.CommandStrategy;
import org.eclipse.ditto.json.JsonFactory;
import org.eclipse.ditto.json.JsonFieldSelector;
import org.eclipse.ditto.json.JsonObject;
import org.eclipse.ditto.base.model.headers.DittoHeaders;
import org.eclipse.ditto.things.model.ThingId;
import org.eclipse.ditto.internal.utils.persistentactors.commands.CommandStrategy;
import org.eclipse.ditto.things.model.signals.commands.exceptions.ThingNotAccessibleException;
import org.eclipse.ditto.things.model.signals.commands.query.RetrieveThing;
import org.eclipse.ditto.things.model.signals.commands.query.RetrieveThingResponse;
Expand Down Expand Up @@ -82,23 +80,21 @@ public void isDefinedIfContextHasThingAndThingIdsAreEqual() {
public void retrieveThingFromContextIfCommandHasNoSnapshotRevisionAndNoSelectedFields() {
final CommandStrategy.Context<ThingId> context = getDefaultContext();
final RetrieveThing command = RetrieveThing.of(context.getState(), DittoHeaders.empty());
final JsonObject expectedThingJson = THING_V2.toJson(command.getImplementedSchemaVersion());
final RetrieveThingResponse expectedResponse =
ETagTestUtils.retrieveThingResponse(THING_V2, expectedThingJson, DittoHeaders.empty());
ETagTestUtils.retrieveThingResponse(THING_V2, null, DittoHeaders.empty());

assertQueryResult(underTest, THING_V2, command, expectedResponse);
}

@Test
public void retrieveThingFromContextIfCommandHasNoSnapshotRevisionButSelectedFields() {
final CommandStrategy.Context<ThingId> context = getDefaultContext();
final JsonFieldSelector fieldSelector = JsonFactory.newFieldSelector("/attribute/location");
final JsonFieldSelector fieldSelector = JsonFactory.newFieldSelector("/attributes/location");
final RetrieveThing command = RetrieveThing.getBuilder(context.getState(), DittoHeaders.empty())
.withSelectedFields(fieldSelector)
.build();
final JsonObject expectedThingJson = THING_V2.toJson(command.getImplementedSchemaVersion(), fieldSelector);
final RetrieveThingResponse expectedResponse =
ETagTestUtils.retrieveThingResponse(THING_V2, expectedThingJson, DittoHeaders.empty());
ETagTestUtils.retrieveThingResponse(THING_V2, fieldSelector, DittoHeaders.empty());

assertQueryResult(underTest, THING_V2, command, expectedResponse);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ public void toJournalReturnsBsonDocument() {
" \"_metadata\" : null,\n" +
" \"thingId\" : \"pap.th.tMJyAjktUVP:YlmZXbTQ\",\n" +
" \"thing\" : {\n" +
" \"__schemaVersion\" : 2,\n" +
" \"__lifecycle\" : \"ACTIVE\",\n" +
" \"_revision\" : 1,\n" +
" \"_modified\" : \"2021-02-24T14:17:37.581679843Z\",\n" +
Expand Down Expand Up @@ -115,7 +114,6 @@ public void fromJournalReturnsEvent() {
" \"_metadata\" : null,\n" +
" \"thingId\" : \"pap.th.tMJyAjktUVP:YlmZXbTQ\",\n" +
" \"thing\" : {\n" +
" \"__schemaVersion\" : 2,\n" +
" \"__lifecycle\" : \"ACTIVE\",\n" +
" \"_revision\" : 1,\n" +
" \"_modified\" : \"2021-02-24T14:17:37.581679843Z\",\n" +
Expand Down

0 comments on commit 7c645b5

Please sign in to comment.