Skip to content

Commit

Permalink
Issue #106: Do not validate resource path matching for error responses.
Browse files Browse the repository at this point in the history
Signed-off-by: Juergen Fickel <juergen.fickel@bosch.io>
  • Loading branch information
Juergen Fickel committed Nov 24, 2021
1 parent 4418fb8 commit 8ae818b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,10 @@ private static MatchingValidationResult validateResourcePathsMatch(final Command
if (SignalInformationPoint.isThingCommand(command)) {
final var commandResourcePath = command.getResourcePath();
final var commandResponseResourcePath = commandResponse.getResourcePath();
if (isAcknowledgement(commandResponse) || commandResourcePath.equals(commandResponseResourcePath)) {
if (commandResourcePath.equals(commandResponseResourcePath) ||
isAcknowledgement(commandResponse) ||
isErrorResponseType(commandResponse)) {

result = MatchingValidationResult.success();
} else {
final var pattern = "Resource path of live response <{0}> differs from resource path of command <{1}>.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.eclipse.ditto.base.model.common.ResponseType;
import org.eclipse.ditto.base.model.correlationid.TestNameCorrelationId;
import org.eclipse.ditto.base.model.exceptions.DittoRuntimeException;
import org.eclipse.ditto.base.model.exceptions.TooManyRequestsException;
import org.eclipse.ditto.base.model.headers.DittoHeaders;
import org.eclipse.ditto.base.model.signals.acks.Acknowledgement;
import org.eclipse.ditto.base.model.signals.commands.CommandResponse;
Expand Down Expand Up @@ -323,6 +324,33 @@ public void applyThingCommandResponseWithDifferentResourcePath() {
command.getResourcePath()));
}

@Test
public void applyTooManyRequestsExceptionAsThingErrorResponse() {

// GIVEN
final var command = ModifyAttribute.of(THING_ID,
JsonPointer.of("manufacturer"),
JsonValue.of("ACME"),
getDittoHeadersWithCorrelationId());

final var tooManyRequestsException = TooManyRequestsException.fromMessage("I'm just a random error mate!",
command.getDittoHeaders());
final var thingErrorResponse = ThingErrorResponse.of(THING_ID, tooManyRequestsException);

final var underTest = CommandAndCommandResponseMatchingValidator.getInstance();

// WHEN
final var validationResult = underTest.apply(command, thingErrorResponse);

// THEN
softly.assertThat(validationResult.isSuccess())
.withFailMessage(() -> {
final var failure = validationResult.asFailureOrThrow();
return failure.getDetailMessage();
})
.isTrue();
}

private DittoHeaders getDittoHeadersWithCorrelationId() {
return DittoHeaders.newBuilder().correlationId(testNameCorrelationId.getCorrelationId()).build();
}
Expand Down

0 comments on commit 8ae818b

Please sign in to comment.