DittoProtocolAdapter implements ProtocolAdapter { @Override public Signal<?> fromAdaptable(final Adaptable adaptable) { return adapterResolver.getAdapter(adaptable).fromAdaptable(adaptable); } private  DittoProtocolAdapter(final ErrorRegistry<DittoRuntimeException> errorRegistry,
            final HeaderTranslator headerTranslator); private  DittoProtocolAdapter(final HeaderTranslator headerTranslator,
            final ThingCommandAdapterProvider thingsAdapters, final PolicyCommandAdapterProvider policiesAdapters,
            final AcknowledgementAdapterProvider acknowledgementAdapters, final AdapterResolver adapterResolver); static DittoProtocolAdapter of(final HeaderTranslator headerTranslator); static DittoProtocolAdapter newInstance(); static HeaderTranslator getHeaderTranslator(); @Override Signal<?> fromAdaptable(final Adaptable adaptable); @Override Adaptable toAdaptable(final Command<?> command); @Override Adaptable toAdaptable(final Signal<?> signal); @Override Adaptable toAdaptable(final Signal<?> signal, final TopicPath.Channel channel); @Override Adaptable toAdaptable(final CommandResponse<?> commandResponse, final TopicPath.Channel channel); @Override Adaptable toAdaptable(final ThingCommandResponse<?> thingCommandResponse, final TopicPath.Channel channel); @Override Adaptable toAdaptable(final Command<?> command, final TopicPath.Channel channel); @Override Adaptable toAdaptable(final ThingQueryCommand<?> thingQueryCommand, final TopicPath.Channel channel); Adaptable toAdaptable(final ThingSearchCommand<?> thingSearchCommand, final TopicPath.Channel channel); @Override Adaptable toAdaptable(final ThingQueryCommandResponse<?> thingQueryCommandResponse,
            final TopicPath.Channel channel); @Override Adaptable toAdaptable(final ThingModifyCommand<?> thingModifyCommand, final TopicPath.Channel channel); @Override Adaptable toAdaptable(final ThingModifyCommandResponse<?> thingModifyCommandResponse,
            final TopicPath.Channel channel); @Override Adaptable toAdaptable(final ThingErrorResponse thingErrorResponse, final TopicPath.Channel channel); @Override Adaptable toAdaptable(final Event<?> event, final TopicPath.Channel channel); @Override Adaptable toAdaptable(final ThingEvent<?> thingEvent, final TopicPath.Channel channel); Adaptable toAdaptable(final SubscriptionEvent<?> subscriptionEvent, final TopicPath.Channel channel); @Override Adaptable toAdaptable(final MessageCommand<?, ?> messageCommand); @Override Adaptable toAdaptable(final MessageCommandResponse<?, ?> messageCommandResponse); @Override HeaderTranslator headerTranslator();  }
@Test public void thingModifyCommandFromAdaptableWithPolicyToCopy() { final String policyIdToCopy = "someNameSpace:someId"; final ModifyThing modifyThing = ModifyThing.withCopiedPolicy(TestConstants.THING_ID, TestConstants.THING, policyIdToCopy, DITTO_HEADERS_V_2); final TopicPath topicPath = TopicPath.newBuilder(THING_ID) .things() .twin() .commands() .modify() .build(); final JsonPointer path = JsonPointer.empty(); final Adaptable adaptable = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path) .withValue(TestConstants.THING.toJson(FieldType.notHidden()) .set(ModifyThing.JSON_COPY_POLICY_FROM, policyIdToCopy)) .build()) .withHeaders(TestConstants.HEADERS_V_2) .build(); final ThingModifyCommand actualCommand = (ThingModifyCommand) underTest.fromAdaptable(adaptable); assertWithExternalHeadersThat(actualCommand).isEqualTo(modifyThing); }
@Test public void thingModifyCommandResponseFromAdaptable() { final ModifyThingResponse modifyThingResponseCreated = ModifyThingResponse.created(TestConstants.THING, DITTO_HEADERS_V_2); final ModifyThingResponse modifyThingResponseModified = ModifyThingResponse.modified(TestConstants.THING_ID, DITTO_HEADERS_V_2); final TopicPath topicPath = TopicPath.newBuilder(THING_ID) .things() .twin() .commands() .modify() .build(); final JsonPointer path = JsonPointer.empty(); final ThingModifyCommandResponse actualCommandResponseCreated = (ThingModifyCommandResponse) underTest.fromAdaptable(Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path) .withStatus(HttpStatusCode.CREATED) .withValue(TestConstants.THING.toJson(FieldType.notHidden())) .build()) .withHeaders(TestConstants.HEADERS_V_2) .build()); assertWithExternalHeadersThat(actualCommandResponseCreated).isEqualTo(modifyThingResponseCreated); final ThingModifyCommandResponse actualCommandResponseModified = (ThingModifyCommandResponse) underTest.fromAdaptable(Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path) .withStatus(HttpStatusCode.NO_CONTENT) .build()) .withHeaders(TestConstants.HEADERS_V_2) .build()); assertWithExternalHeadersThat(actualCommandResponseModified).isEqualTo(modifyThingResponseModified); }
@Test public void modifyFeaturePropertyFromAdaptable() { final String topicPathString = "org.eclipse.ditto.client.test/7a96e7a4-b20c-43eb-b669-f75514af30d0/things/twin/commands/modify"; final TopicPath topicPath = ProtocolFactory.newTopicPath(topicPathString); final String jsonString = "{\"path\":\"/features/feature_id_2/properties/complex/bum\",\"value\":\"bar\"}"; final Payload payload = ProtocolFactory.newPayload(jsonString); final Adaptable adaptable = ProtocolFactory.newAdaptableBuilder(topicPath).withPayload(payload).build(); final Jsonifiable<JsonObject> jsonifiable = underTest.fromAdaptable(adaptable); assertThat(jsonifiable).isInstanceOf(ModifyFeatureProperty.class); }