Skip to content

Commit

Permalink
adjusted Ditto java client to changes of Event / EventsourcedEvent
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 Apr 6, 2021
1 parent 3f32158 commit b188ce7
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static org.eclipse.ditto.json.JsonFactory.newPointer;
import static org.junit.Assert.assertEquals;

import java.time.Instant;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CountDownLatch;
Expand Down Expand Up @@ -410,7 +411,7 @@ public void testUpwardsRegisterForThingChangeWhenSingleFeatureIsDeleted() throws
// delete the Feature
final Message<ThingEvent> featureDeleted =
MessagesModelFactory.<ThingEvent>newMessageBuilder(messageHeaders).payload(
FeatureDeleted.of(thingId1, FEATURE_ID_1, 1, DittoHeaders.empty())).build();
FeatureDeleted.of(thingId1, FEATURE_ID_1, 1, Instant.now(), DittoHeaders.empty(), null)).build();

messaging.receiveEvent(featureDeleted);

Expand Down Expand Up @@ -464,8 +465,7 @@ public void testUpwardsRegisterForFeaturesChangesWhenSingleFeaturePropertyIsCrea
final Message<ThingEvent> featurePropertyCreated =
MessagesModelFactory.<ThingEvent>newMessageBuilder(messageHeaders).payload(
FeaturePropertyCreated.of(thingId1, FEATURE_ID_1, fooPointer, JsonValue.of(fooValue),
1,
DittoHeaders.empty())).build();
1, Instant.now(), DittoHeaders.empty(), null)).build();

messaging.receiveEvent(featurePropertyCreated);

Expand Down Expand Up @@ -510,8 +510,8 @@ public void testUpwardsRegisterForFeatureChangesWhenSingleFeaturePropertyIsUpdat
final Message<ThingEvent> featurePropertyModified =
MessagesModelFactory.<ThingEvent>newMessageBuilder(messageHeaders).payload(
FeaturePropertyModified.of(thingId3, FEATURE_ID_2, fooPointer, JsonValue.of(fooValue),
1,
DittoHeaders.empty())).build();
1, Instant.now(),
DittoHeaders.empty(), null)).build();

messaging.receiveEvent(featurePropertyModified);

Expand Down Expand Up @@ -593,7 +593,8 @@ public void testDownwardsRegisterForSingleAttributeChangeWhenAttributesAreModifi
// change attributes
final Message<ThingEvent> attributesModified =
MessagesModelFactory.<ThingEvent>newMessageBuilder(messageHeaders).payload(
AttributesModified.of(thingId2, newAttributes, 1, DittoHeaders.empty())).build();
AttributesModified.of(thingId2, newAttributes, 1, Instant.now(), DittoHeaders.empty(),
null)).build();

messaging.receiveEvent(attributesModified);

Expand Down Expand Up @@ -634,7 +635,7 @@ public void testDownwardsRegisterForNestedFeaturePropertyChangeWhenFeatureIsModi
// modify the feature
final Message<ThingEvent> featureModified =
MessagesModelFactory.<ThingEvent>newMessageBuilder(messageHeaders).payload(
FeatureModified.of(thingId3, FEATURE2, 1, DittoHeaders.empty())).build();
FeatureModified.of(thingId3, FEATURE2, 1, Instant.now(), DittoHeaders.empty(), null)).build();

messaging.receiveEvent(featureModified);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import static org.eclipse.ditto.client.TestConstants.Thing.THING_ID;
import static org.eclipse.ditto.client.assertions.ClientAssertions.assertThat;

import java.time.Instant;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -238,7 +239,7 @@ public void testReceiveAttributeModifiedEvent() throws Exception {

final Message<ThingEvent> attributeModified = MessagesModelFactory.<ThingEvent>newMessageBuilder(messageHeaders)
.payload(AttributeModified.of(THING_ID, ATTRIBUTE_KEY_NEW, JsonFactory.newValue("value"), 1,
headersWithChannel()))
Instant.now(), headersWithChannel(), null))
.build();

messaging.receiveEvent(attributeModified);
Expand Down Expand Up @@ -267,7 +268,7 @@ public void testReceiveAttributeModifiedEventWithActionAdded() throws Exception

final Message<ThingEvent> attributeCreated = MessagesModelFactory.<ThingEvent>newMessageBuilder(messageHeaders)
.payload(AttributeCreated.of(THING_ID, ATTRIBUTE_KEY_REALLY_NEW, JsonFactory.newValue("value"), 1,
headersWithChannel()))
Instant.now(), headersWithChannel(), null))
.build();

messaging.receiveEvent(attributeCreated);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static org.eclipse.ditto.client.TestConstants.Thing.THING_WITH_INLINE_POLICY;
import static org.eclipse.ditto.client.assertions.ClientAssertions.assertThat;

import java.time.Instant;
import java.util.Arrays;
import java.util.concurrent.CompletionException;
import java.util.concurrent.CountDownLatch;
Expand All @@ -37,8 +38,6 @@
import org.eclipse.ditto.json.JsonPointer;
import org.eclipse.ditto.model.base.acks.AcknowledgementLabel;
import org.eclipse.ditto.model.base.acks.AcknowledgementRequest;
import org.eclipse.ditto.model.base.auth.AuthorizationModelFactory;
import org.eclipse.ditto.model.base.auth.AuthorizationSubject;
import org.eclipse.ditto.model.base.common.HttpStatus;
import org.eclipse.ditto.model.base.exceptions.DittoRuntimeException;
import org.eclipse.ditto.model.base.headers.DittoHeaders;
Expand Down Expand Up @@ -269,7 +268,8 @@ public void testReceiveCreatedEvent() throws Exception {
MessageHeaders.newBuilder(MessageDirection.FROM, THING_ID, ThingCreated.TYPE).build();

final Message<ThingEvent> thingCreated = MessagesModelFactory.<ThingEvent>newMessageBuilder(messageHeaders)
.payload(ThingCreated.of(Thing.newBuilder().setId(THING_ID).build(), 1, headersWithChannel()))
.payload(ThingCreated.of(Thing.newBuilder().setId(THING_ID).build(), 1, Instant.now(),
headersWithChannel(), null))
.build();

messaging.receiveEvent(thingCreated);
Expand Down Expand Up @@ -301,7 +301,7 @@ private Message<ThingEvent> createThingDeletedMessage() {
MessageHeaders.newBuilder(MessageDirection.FROM, THING_ID, ThingDeleted.TYPE).build();

return MessagesModelFactory.<ThingEvent>newMessageBuilder(messageHeaders)
.payload(ThingDeleted.of(THING_ID, 1, headersWithChannel()))
.payload(ThingDeleted.of(THING_ID, 1, Instant.now(), headersWithChannel(), null))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import static org.eclipse.ditto.client.TestConstants.Thing.THING_ID;
import static org.eclipse.ditto.model.base.acks.AcknowledgementRequest.parseAcknowledgementRequest;

import java.time.Instant;
import java.util.concurrent.CompletionStage;

import org.eclipse.ditto.client.internal.bus.Classification;
Expand Down Expand Up @@ -53,14 +54,15 @@ public void testThingEventAcknowledgement() {
// expect subscription messages
assertThat(expectMsgClass(String.class)).startsWith("START-SEND-");

reply(ThingDeleted.of(THING_ID, 1L, DittoHeaders.newBuilder()
reply(ThingDeleted.of(THING_ID, 1L, Instant.now(), DittoHeaders.newBuilder()
.channel(TopicPath.Channel.TWIN.getName())
.acknowledgementRequest(
parseAcknowledgementRequest("100"),
parseAcknowledgementRequest("301"),
parseAcknowledgementRequest("403")
)
.build()
.build(),
null
));

assertThat(expectMsgClass(Acknowledgement.class).getHttpStatus()).isEqualTo(HttpStatus.CONTINUE);
Expand All @@ -82,15 +84,16 @@ public void testAttributeEventAcknowledgement() {
// expect subscription messages
assertThat(expectMsgClass(String.class)).startsWith("START-SEND-");

reply(AttributeCreated.of(THING_ID, JsonPointer.of("hello"), JsonValue.of("World"), 5L,
reply(AttributeCreated.of(THING_ID, JsonPointer.of("hello"), JsonValue.of("World"), 5L, Instant.now(),
DittoHeaders.newBuilder()
.channel(TopicPath.Channel.TWIN.getName())
.acknowledgementRequest(
parseAcknowledgementRequest("200"),
parseAcknowledgementRequest("403"),
parseAcknowledgementRequest("500")
)
.build())
.build(),
null)
);
assertThat(expectMsgClass(Acknowledgement.class).getHttpStatus()).isEqualTo(HttpStatus.OK);
assertThat(expectMsgClass(Acknowledgement.class).getHttpStatus()).isEqualTo(HttpStatus.FORBIDDEN);
Expand All @@ -113,14 +116,16 @@ public void testFeatureEventAcknowledgement() {
assertThat(expectMsgClass(String.class)).startsWith("START-SEND-");

reply(FeaturePropertyModified.of(THING_ID, "featureId", JsonPointer.of("hello"), JsonValue.of("World"), 5L,
Instant.now(),
DittoHeaders.newBuilder()
.channel(TopicPath.Channel.TWIN.getName())
.acknowledgementRequest(
parseAcknowledgementRequest("409"),
parseAcknowledgementRequest("201"),
parseAcknowledgementRequest("403")
)
.build())
.build(),
null)
);
assertThat(expectMsgClass(Acknowledgement.class).getHttpStatus()).isEqualTo(HttpStatus.CONFLICT);
assertThat(expectMsgClass(Acknowledgement.class).getHttpStatus()).isEqualTo(HttpStatus.CREATED);
Expand Down
Loading

0 comments on commit b188ce7

Please sign in to comment.