Search in sources :

Example 1 with JsonFieldSelector

use of org.eclipse.ditto.json.JsonFieldSelector in project ditto by eclipse.

the class ThingQueryCommandAdapterTest method retrieveFeatureDesiredPropertiesWithFieldsToAdaptable.

@Test
public void retrieveFeatureDesiredPropertiesWithFieldsToAdaptable() {
    final JsonFieldSelector selectedFields = JsonFieldSelector.newInstance("foo");
    final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE);
    final JsonPointer path = JsonPointer.of("/features/" + TestConstants.FEATURE_ID + "/desiredProperties");
    final Adaptable expected = Adaptable.newBuilder(topicPath).withPayload(Payload.newBuilder(path).withFields(selectedFields).build()).withHeaders(TestConstants.HEADERS_V_2).build();
    final RetrieveFeatureDesiredProperties retrieveFeatureDesiredProperties = RetrieveFeatureDesiredProperties.of(TestConstants.THING_ID, TestConstants.FEATURE_ID, selectedFields, TestConstants.HEADERS_V_2_NO_CONTENT_TYPE);
    final Adaptable actual = underTest.toAdaptable(retrieveFeatureDesiredProperties, channel);
    assertWithExternalHeadersThat(actual).isEqualTo(expected);
}
Also used : JsonFieldSelector(org.eclipse.ditto.json.JsonFieldSelector) TopicPath(org.eclipse.ditto.protocol.TopicPath) RetrieveFeatureDesiredProperties(org.eclipse.ditto.things.model.signals.commands.query.RetrieveFeatureDesiredProperties) JsonPointer(org.eclipse.ditto.json.JsonPointer) JsonifiableAdaptable(org.eclipse.ditto.protocol.JsonifiableAdaptable) Adaptable(org.eclipse.ditto.protocol.Adaptable) ProtocolAdapterTest(org.eclipse.ditto.protocol.adapter.ProtocolAdapterTest) LiveTwinTest(org.eclipse.ditto.protocol.LiveTwinTest) Test(org.junit.Test)

Example 2 with JsonFieldSelector

use of org.eclipse.ditto.json.JsonFieldSelector in project ditto by eclipse.

the class ThingQueryCommandAdapterTest method retrieveThingWithFieldsFromAdaptable.

@Test
public void retrieveThingWithFieldsFromAdaptable() {
    final JsonFieldSelector selectedFields = JsonFieldSelector.newInstance("thingId");
    final RetrieveThing expected = RetrieveThing.getBuilder(TestConstants.THING_ID, TestConstants.DITTO_HEADERS_V_2).withSelectedFields(selectedFields).build();
    final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE);
    final JsonPointer path = JsonPointer.empty();
    final Adaptable adaptable = Adaptable.newBuilder(topicPath).withPayload(Payload.newBuilder(path).withFields(selectedFields).build()).withHeaders(TestConstants.HEADERS_V_2).build();
    final ThingQueryCommand<?> actual = underTest.fromAdaptable(adaptable);
    assertWithExternalHeadersThat(actual).isEqualTo(expected);
}
Also used : JsonFieldSelector(org.eclipse.ditto.json.JsonFieldSelector) TopicPath(org.eclipse.ditto.protocol.TopicPath) RetrieveThing(org.eclipse.ditto.things.model.signals.commands.query.RetrieveThing) JsonPointer(org.eclipse.ditto.json.JsonPointer) JsonifiableAdaptable(org.eclipse.ditto.protocol.JsonifiableAdaptable) Adaptable(org.eclipse.ditto.protocol.Adaptable) ProtocolAdapterTest(org.eclipse.ditto.protocol.adapter.ProtocolAdapterTest) LiveTwinTest(org.eclipse.ditto.protocol.LiveTwinTest) Test(org.junit.Test)

Example 3 with JsonFieldSelector

use of org.eclipse.ditto.json.JsonFieldSelector in project ditto by eclipse.

the class ThingQueryCommandAdapterTest method retrieveAttributesWithFieldsToAdaptable.

@Test
public void retrieveAttributesWithFieldsToAdaptable() {
    final JsonFieldSelector selectedFields = JsonFieldSelector.newInstance("foo");
    final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE);
    final JsonPointer path = JsonPointer.of("/attributes");
    final Adaptable expected = Adaptable.newBuilder(topicPath).withPayload(Payload.newBuilder(path).withFields(selectedFields).build()).withHeaders(TestConstants.HEADERS_V_2).build();
    final RetrieveAttributes retrieveAttributes = RetrieveAttributes.of(TestConstants.THING_ID, selectedFields, TestConstants.HEADERS_V_2_NO_CONTENT_TYPE);
    final Adaptable actual = underTest.toAdaptable(retrieveAttributes, channel);
    assertWithExternalHeadersThat(actual).isEqualTo(expected);
}
Also used : RetrieveAttributes(org.eclipse.ditto.things.model.signals.commands.query.RetrieveAttributes) JsonFieldSelector(org.eclipse.ditto.json.JsonFieldSelector) TopicPath(org.eclipse.ditto.protocol.TopicPath) JsonPointer(org.eclipse.ditto.json.JsonPointer) JsonifiableAdaptable(org.eclipse.ditto.protocol.JsonifiableAdaptable) Adaptable(org.eclipse.ditto.protocol.Adaptable) ProtocolAdapterTest(org.eclipse.ditto.protocol.adapter.ProtocolAdapterTest) LiveTwinTest(org.eclipse.ditto.protocol.LiveTwinTest) Test(org.junit.Test)

Example 4 with JsonFieldSelector

use of org.eclipse.ditto.json.JsonFieldSelector in project ditto by eclipse.

the class ThingQueryCommandAdapterTest method retrieveFeaturePropertiesWithFieldsToAdaptable.

@Test
public void retrieveFeaturePropertiesWithFieldsToAdaptable() {
    final JsonFieldSelector selectedFields = JsonFieldSelector.newInstance("foo");
    final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE);
    final JsonPointer path = JsonPointer.of("/features/" + TestConstants.FEATURE_ID + "/properties");
    final Adaptable expected = Adaptable.newBuilder(topicPath).withPayload(Payload.newBuilder(path).withFields(selectedFields).build()).withHeaders(TestConstants.HEADERS_V_2).build();
    final RetrieveFeatureProperties retrieveFeatureProperties = RetrieveFeatureProperties.of(TestConstants.THING_ID, TestConstants.FEATURE_ID, selectedFields, TestConstants.HEADERS_V_2_NO_CONTENT_TYPE);
    final Adaptable actual = underTest.toAdaptable(retrieveFeatureProperties, channel);
    assertWithExternalHeadersThat(actual).isEqualTo(expected);
}
Also used : JsonFieldSelector(org.eclipse.ditto.json.JsonFieldSelector) TopicPath(org.eclipse.ditto.protocol.TopicPath) JsonPointer(org.eclipse.ditto.json.JsonPointer) JsonifiableAdaptable(org.eclipse.ditto.protocol.JsonifiableAdaptable) Adaptable(org.eclipse.ditto.protocol.Adaptable) RetrieveFeatureProperties(org.eclipse.ditto.things.model.signals.commands.query.RetrieveFeatureProperties) ProtocolAdapterTest(org.eclipse.ditto.protocol.adapter.ProtocolAdapterTest) LiveTwinTest(org.eclipse.ditto.protocol.LiveTwinTest) Test(org.junit.Test)

Example 5 with JsonFieldSelector

use of org.eclipse.ditto.json.JsonFieldSelector in project ditto by eclipse.

the class ThingQueryCommandAdapterTest method retrieveFeatureDesiredPropertiesWithFieldsFromAdaptable.

@Test
public void retrieveFeatureDesiredPropertiesWithFieldsFromAdaptable() {
    final JsonFieldSelector selectedFields = JsonFieldSelector.newInstance("foo");
    final RetrieveFeatureDesiredProperties expected = RetrieveFeatureDesiredProperties.of(TestConstants.THING_ID, TestConstants.FEATURE_ID, selectedFields, TestConstants.DITTO_HEADERS_V_2);
    final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE);
    final JsonPointer path = JsonPointer.of("/features/" + TestConstants.FEATURE_ID + "/desiredProperties");
    final Adaptable adaptable = Adaptable.newBuilder(topicPath).withPayload(Payload.newBuilder(path).withFields(selectedFields).build()).withHeaders(TestConstants.HEADERS_V_2).build();
    final ThingQueryCommand<?> actual = underTest.fromAdaptable(adaptable);
    assertWithExternalHeadersThat(actual).isEqualTo(expected);
}
Also used : JsonFieldSelector(org.eclipse.ditto.json.JsonFieldSelector) TopicPath(org.eclipse.ditto.protocol.TopicPath) RetrieveFeatureDesiredProperties(org.eclipse.ditto.things.model.signals.commands.query.RetrieveFeatureDesiredProperties) JsonPointer(org.eclipse.ditto.json.JsonPointer) JsonifiableAdaptable(org.eclipse.ditto.protocol.JsonifiableAdaptable) Adaptable(org.eclipse.ditto.protocol.Adaptable) ProtocolAdapterTest(org.eclipse.ditto.protocol.adapter.ProtocolAdapterTest) LiveTwinTest(org.eclipse.ditto.protocol.LiveTwinTest) Test(org.junit.Test)

Aggregations

JsonFieldSelector (org.eclipse.ditto.json.JsonFieldSelector)76 Test (org.junit.Test)53 ThingId (org.eclipse.ditto.things.model.ThingId)36 JsonObject (org.eclipse.ditto.json.JsonObject)33 DittoHeaders (org.eclipse.ditto.base.model.headers.DittoHeaders)22 JsonPointer (org.eclipse.ditto.json.JsonPointer)21 Thing (org.eclipse.ditto.things.model.Thing)18 RetrieveThing (org.eclipse.ditto.things.model.signals.commands.query.RetrieveThing)18 Optional (java.util.Optional)17 ActorRef (akka.actor.ActorRef)16 Nullable (javax.annotation.Nullable)16 TopicPath (org.eclipse.ditto.protocol.TopicPath)16 Objects (java.util.Objects)14 Predicate (java.util.function.Predicate)13 JsonSchemaVersion (org.eclipse.ditto.base.model.json.JsonSchemaVersion)13 Immutable (javax.annotation.concurrent.Immutable)12 JsonField (org.eclipse.ditto.json.JsonField)12 FieldType (org.eclipse.ditto.base.model.json.FieldType)11 CommandStrategy (org.eclipse.ditto.internal.utils.persistentactors.commands.CommandStrategy)11 JsonFactory (org.eclipse.ditto.json.JsonFactory)11