Search in sources :

Example 1 with JsonPointer

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

the class ThingModifyCommandAdapterTest method deleteFeatureDefinitionFromAdaptable.

@Test
public void deleteFeatureDefinitionFromAdaptable() {
    final DeleteFeatureDefinition expected = DeleteFeatureDefinition.of(TestConstants.THING_ID, TestConstants.FEATURE_ID, TestConstants.DITTO_HEADERS_V_2);
    final TopicPath topicPath = topicPath(TopicPath.Action.DELETE);
    final JsonPointer path = JsonPointer.of("/features/" + TestConstants.FEATURE_ID + "/definition");
    final Adaptable adaptable = Adaptable.newBuilder(topicPath).withPayload(Payload.newBuilder(path).build()).withHeaders(TestConstants.HEADERS_V_2).build();
    final ThingModifyCommand<?> actual = underTest.fromAdaptable(adaptable);
    assertWithExternalHeadersThat(actual).isEqualTo(expected);
}
Also used : TopicPath(org.eclipse.ditto.protocol.TopicPath) DeleteFeatureDefinition(org.eclipse.ditto.things.model.signals.commands.modify.DeleteFeatureDefinition) JsonPointer(org.eclipse.ditto.json.JsonPointer) 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 JsonPointer

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

the class ThingModifyCommandAdapterTest method modifyAttributeFromAdaptable.

@Test
public void modifyAttributeFromAdaptable() {
    final ModifyAttribute expected = ModifyAttribute.of(TestConstants.THING_ID, TestConstants.ATTRIBUTE_POINTER, TestConstants.ATTRIBUTE_VALUE, TestConstants.DITTO_HEADERS_V_2);
    final TopicPath topicPath = topicPath(TopicPath.Action.MODIFY);
    final JsonPointer path = JsonPointer.of("/attributes" + TestConstants.ATTRIBUTE_POINTER);
    final Adaptable adaptable = Adaptable.newBuilder(topicPath).withPayload(Payload.newBuilder(path).withValue(TestConstants.ATTRIBUTE_VALUE).build()).withHeaders(TestConstants.HEADERS_V_2).build();
    final ThingModifyCommand<?> actual = underTest.fromAdaptable(adaptable);
    assertWithExternalHeadersThat(actual).isEqualTo(expected);
}
Also used : TopicPath(org.eclipse.ditto.protocol.TopicPath) ModifyAttribute(org.eclipse.ditto.things.model.signals.commands.modify.ModifyAttribute) JsonPointer(org.eclipse.ditto.json.JsonPointer) 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 JsonPointer

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

the class ThingModifyCommandAdapterTest method deleteAttributesToAdaptable.

@Test
public void deleteAttributesToAdaptable() {
    final TopicPath topicPath = topicPath(TopicPath.Action.DELETE);
    final JsonPointer path = JsonPointer.of("/attributes");
    final Adaptable expected = Adaptable.newBuilder(topicPath).withPayload(Payload.newBuilder(path).build()).withHeaders(TestConstants.HEADERS_V_2).build();
    final DeleteAttributes deleteAttributes = DeleteAttributes.of(TestConstants.THING_ID, TestConstants.HEADERS_V_2_NO_CONTENT_TYPE);
    final Adaptable actual = underTest.toAdaptable(deleteAttributes, channel);
    assertWithExternalHeadersThat(actual).isEqualTo(expected);
}
Also used : TopicPath(org.eclipse.ditto.protocol.TopicPath) DeleteAttributes(org.eclipse.ditto.things.model.signals.commands.modify.DeleteAttributes) JsonPointer(org.eclipse.ditto.json.JsonPointer) 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 JsonPointer

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

the class ThingModifyCommandAdapterTest method modifyThingFromAdaptableWithPolicyIdToCopy.

@Test
public void modifyThingFromAdaptableWithPolicyIdToCopy() {
    final String policyIdToCopy = "someNameSpace:someId";
    final ModifyThing expected = ModifyThing.of(TestConstants.THING_ID, TestConstants.THING, null, policyIdToCopy, TestConstants.DITTO_HEADERS_V_2);
    final TopicPath topicPath = topicPath(TopicPath.Action.MODIFY);
    final JsonPointer path = JsonPointer.empty();
    final Adaptable adaptable = Adaptable.newBuilder(topicPath).withPayload(Payload.newBuilder(path).withValue(TestConstants.THING.toJson(FieldType.regularOrSpecial()).set(ModifyThing.JSON_COPY_POLICY_FROM, policyIdToCopy)).build()).withHeaders(TestConstants.HEADERS_V_2).build();
    final ThingModifyCommand<?> actual = underTest.fromAdaptable(adaptable);
    assertWithExternalHeadersThat(actual).isEqualTo(expected);
}
Also used : TopicPath(org.eclipse.ditto.protocol.TopicPath) ModifyThing(org.eclipse.ditto.things.model.signals.commands.modify.ModifyThing) JsonPointer(org.eclipse.ditto.json.JsonPointer) Adaptable(org.eclipse.ditto.protocol.Adaptable) ProtocolAdapterTest(org.eclipse.ditto.protocol.adapter.ProtocolAdapterTest) LiveTwinTest(org.eclipse.ditto.protocol.LiveTwinTest) Test(org.junit.Test)

Example 5 with JsonPointer

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

the class ThingModifyCommandAdapterTest method deleteAttributesFromAdaptable.

@Test
public void deleteAttributesFromAdaptable() {
    final DeleteAttributes expected = DeleteAttributes.of(TestConstants.THING_ID, TestConstants.DITTO_HEADERS_V_2);
    final TopicPath topicPath = topicPath(TopicPath.Action.DELETE);
    final JsonPointer path = JsonPointer.of("/attributes");
    final Adaptable adaptable = Adaptable.newBuilder(topicPath).withPayload(Payload.newBuilder(path).build()).withHeaders(TestConstants.HEADERS_V_2).build();
    final ThingModifyCommand<?> actual = underTest.fromAdaptable(adaptable);
    assertWithExternalHeadersThat(actual).isEqualTo(expected);
}
Also used : TopicPath(org.eclipse.ditto.protocol.TopicPath) DeleteAttributes(org.eclipse.ditto.things.model.signals.commands.modify.DeleteAttributes) JsonPointer(org.eclipse.ditto.json.JsonPointer) Adaptable(org.eclipse.ditto.protocol.Adaptable) ProtocolAdapterTest(org.eclipse.ditto.protocol.adapter.ProtocolAdapterTest) LiveTwinTest(org.eclipse.ditto.protocol.LiveTwinTest) Test(org.junit.Test)

Aggregations

JsonPointer (org.eclipse.ditto.json.JsonPointer)489 Test (org.junit.Test)378 Adaptable (org.eclipse.ditto.protocol.Adaptable)273 ProtocolAdapterTest (org.eclipse.ditto.protocol.adapter.ProtocolAdapterTest)258 LiveTwinTest (org.eclipse.ditto.protocol.LiveTwinTest)232 TopicPath (org.eclipse.ditto.protocol.TopicPath)208 ThingId (org.eclipse.ditto.things.model.ThingId)63 JsonValue (org.eclipse.ditto.json.JsonValue)55 JsonObject (org.eclipse.ditto.json.JsonObject)43 DittoHeaders (org.eclipse.ditto.base.model.headers.DittoHeaders)38 JsonifiableAdaptable (org.eclipse.ditto.protocol.JsonifiableAdaptable)34 Thing (org.eclipse.ditto.things.model.Thing)33 Optional (java.util.Optional)25 Nullable (javax.annotation.Nullable)24 JsonFieldSelector (org.eclipse.ditto.json.JsonFieldSelector)19 DittoRuntimeException (org.eclipse.ditto.base.model.exceptions.DittoRuntimeException)18 JsonKey (org.eclipse.ditto.json.JsonKey)18 Payload (org.eclipse.ditto.protocol.Payload)17 Metadata (org.eclipse.ditto.base.model.entity.metadata.Metadata)15 List (java.util.List)14