Skip to content

Commit

Permalink
Issue #106 extend protocol adapter
Browse files Browse the repository at this point in the history
* RetrievePolicyId(Response) mapping strategies where missing
* Add tests as well

Signed-off-by: Joel Bartelheimer <joel.bartelheimer@bosch.io>
  • Loading branch information
jbartelh committed Nov 8, 2021
1 parent 7e6a36c commit 7cc7cbb
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.eclipse.ditto.things.model.signals.commands.query.RetrieveFeatureProperties;
import org.eclipse.ditto.things.model.signals.commands.query.RetrieveFeatureProperty;
import org.eclipse.ditto.things.model.signals.commands.query.RetrieveFeatures;
import org.eclipse.ditto.things.model.signals.commands.query.RetrievePolicyId;
import org.eclipse.ditto.things.model.signals.commands.query.RetrieveThing;
import org.eclipse.ditto.things.model.signals.commands.query.RetrieveThingDefinition;
import org.eclipse.ditto.things.model.signals.commands.query.ThingQueryCommand;
Expand Down Expand Up @@ -87,6 +88,9 @@ private static Map<String, JsonifiableMapper<ThingQueryCommand<?>>> initMappingS
RetrieveFeatureDesiredProperty.of(thingIdFrom(adaptable), featureIdFrom(adaptable),
featurePropertyPointerFrom(adaptable), dittoHeadersFrom(adaptable)));

mappingStrategies.put(RetrievePolicyId.TYPE, adaptable ->
RetrievePolicyId.of(thingIdFrom(adaptable), dittoHeadersFrom(adaptable)));

return mappingStrategies;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.eclipse.ditto.things.model.signals.commands.query.RetrieveFeaturePropertyResponse;
import org.eclipse.ditto.things.model.signals.commands.query.RetrieveFeatureResponse;
import org.eclipse.ditto.things.model.signals.commands.query.RetrieveFeaturesResponse;
import org.eclipse.ditto.things.model.signals.commands.query.RetrievePolicyIdResponse;
import org.eclipse.ditto.things.model.signals.commands.query.RetrieveThingDefinitionResponse;
import org.eclipse.ditto.things.model.signals.commands.query.RetrieveThingResponse;
import org.eclipse.ditto.things.model.signals.commands.query.ThingQueryCommandResponse;
Expand Down Expand Up @@ -99,6 +100,11 @@ private static Map<String, JsonifiableMapper<ThingQueryCommandResponse<?>>> init
featurePropertyPointerFrom(adaptable), featurePropertyValueFrom(adaptable),
dittoHeadersFrom(adaptable)));

mappingStrategies.put(RetrievePolicyIdResponse.TYPE,
adaptable -> RetrievePolicyIdResponse.of(thingIdFrom(adaptable),
policyIdFrom(adaptable),
dittoHeadersFrom(adaptable)));

return mappingStrategies;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.eclipse.ditto.things.model.signals.commands.query.RetrieveFeatureProperties;
import org.eclipse.ditto.things.model.signals.commands.query.RetrieveFeatureProperty;
import org.eclipse.ditto.things.model.signals.commands.query.RetrieveFeatures;
import org.eclipse.ditto.things.model.signals.commands.query.RetrievePolicyId;
import org.eclipse.ditto.things.model.signals.commands.query.RetrieveThing;
import org.eclipse.ditto.things.model.signals.commands.query.RetrieveThingDefinition;
import org.eclipse.ditto.things.model.signals.commands.query.ThingQueryCommand;
Expand Down Expand Up @@ -280,6 +281,43 @@ public void retrieveDefinitionToAdaptable() {
assertWithExternalHeadersThat(actual).isEqualTo(expected);
}


@Test
public void retrievePolicyIdFromAdaptable() {
final RetrievePolicyId expected =
RetrievePolicyId.of(TestConstants.THING_ID, TestConstants.HEADERS_V_2_NO_CONTENT_TYPE);

final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE);
final JsonPointer path = JsonPointer.of("/policyId");
final Adaptable adaptable = Adaptable.newBuilder(topicPath)
.withPayload(Payload.newBuilder(path)
.build())
.withHeaders(TestConstants.HEADERS_V_2)
.build();
final ThingQueryCommand<?> actual = underTest.fromAdaptable(adaptable);

assertWithExternalHeadersThat(actual).isEqualTo(expected);
}

@Test
public void retrievePolicyIdToAdaptable() {
final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE);
final JsonPointer path = JsonPointer.of("/policyId");

final Adaptable expected = Adaptable.newBuilder(topicPath)
.withPayload(Payload.newBuilder(path).build())
.withHeaders(TestConstants.HEADERS_V_2)
.build();

final RetrievePolicyId retrievePolicyId =
RetrievePolicyId.of(TestConstants.THING_ID, TestConstants.HEADERS_V_2_NO_CONTENT_TYPE);

final Adaptable actual = underTest.toAdaptable(retrievePolicyId, channel);

assertWithExternalHeadersThat(actual).isEqualTo(expected);
}


@Test
public void retrieveFeaturesFromAdaptable() {
final RetrieveFeatures expected =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.eclipse.ditto.things.model.signals.commands.query.RetrieveFeaturePropertyResponse;
import org.eclipse.ditto.things.model.signals.commands.query.RetrieveFeatureResponse;
import org.eclipse.ditto.things.model.signals.commands.query.RetrieveFeaturesResponse;
import org.eclipse.ditto.things.model.signals.commands.query.RetrievePolicyIdResponse;
import org.eclipse.ditto.things.model.signals.commands.query.RetrieveThingDefinitionResponse;
import org.eclipse.ditto.things.model.signals.commands.query.RetrieveThingResponse;
import org.eclipse.ditto.things.model.signals.commands.query.ThingQueryCommandResponse;
Expand Down Expand Up @@ -237,6 +238,48 @@ public void retrieveDefinitionResponseToAdaptable() {
assertWithExternalHeadersThat(actual).isEqualTo(expected);
}

@Test
public void retrievePolicyIdResponseFromAdaptable() {
final RetrievePolicyIdResponse expected =
RetrievePolicyIdResponse.of(THING_ID, TestConstants.POLICY_ID, DITTO_HEADERS_V_2);

final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE);
final JsonPointer path = JsonPointer.of("/policyId");

final Adaptable adaptable = Adaptable.newBuilder(topicPath)
.withPayload(Payload.newBuilder(path)
.withStatus(HttpStatus.OK)
.withValue(JsonValue.of(TestConstants.POLICY_ID))
.build())
.withHeaders(TestConstants.HEADERS_V_2)
.build();
final ThingQueryCommandResponse<?> actual = underTest.fromAdaptable(adaptable);

assertWithExternalHeadersThat(actual).isEqualTo(expected);
}

@Test
public void retrievePolicyIdResponseToAdaptable() {
final JsonPointer path = JsonPointer.of("/policyId");

final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE);

final Adaptable expected = Adaptable.newBuilder(topicPath)
.withPayload(Payload.newBuilder(path)
.withStatus(HttpStatus.OK)
.withValue(JsonValue.of(TestConstants.POLICY_ID))
.build())
.withHeaders(TestConstants.HEADERS_V_2)
.build();

final RetrievePolicyIdResponse retrievePolicyIdResponse =
RetrievePolicyIdResponse.of(THING_ID, TestConstants.POLICY_ID,
TestConstants.HEADERS_V_2_NO_CONTENT_TYPE);
final Adaptable actual = underTest.toAdaptable(retrievePolicyIdResponse, channel);

assertWithExternalHeadersThat(actual).isEqualTo(expected);
}

@Test
public void retrieveFeaturesResponseFromAdaptable() {
final RetrieveFeaturesResponse expected =
Expand Down

0 comments on commit 7cc7cbb

Please sign in to comment.