Skip to content

Commit

Permalink
#1690 use correct HTTP status code for "if-equal": skip on equality
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Jäckle <thomas.jaeckle@beyonnex.io>
  • Loading branch information
thjaeckle committed Jul 17, 2023
1 parent 3a0419a commit ec71965
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ private ConnectionPreconditionFailedException(final DittoHeaders dittoHeaders,
super(ERROR_CODE, HttpStatus.PRECONDITION_FAILED, dittoHeaders, message, description, cause, href);
}

/**
* A mutable builder for a {@link ConnectionPreconditionFailedException}.
*
* @return the builder.
*/
public static Builder newBuilder() {
return new Builder();
}

/**
* A mutable builder for a {@link ConnectionPreconditionFailedException}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public DittoRuntimeExceptionBuilder<?> createPreconditionNotModifiedExceptionBui

@Override
public DittoRuntimeExceptionBuilder<?> createPreconditionNotModifiedForEqualityExceptionBuilder() {
return ConnectionPreconditionNotModifiedException.newBuilder()
return ConnectionPreconditionFailedException.newBuilder()
.message("The previous value was equal to the new value and the 'if-equal' header was set to 'skip'.")
.description("Your changes were not applied, which is probably the expected outcome.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;

import org.eclipse.ditto.json.JsonObject;
import org.eclipse.ditto.base.model.common.HttpStatus;
import org.eclipse.ditto.base.model.exceptions.DittoRuntimeException;
import org.eclipse.ditto.base.model.exceptions.DittoRuntimeExceptionBuilder;
import org.eclipse.ditto.base.model.headers.DittoHeaders;
import org.eclipse.ditto.base.model.json.JsonParsableException;
import org.eclipse.ditto.json.JsonObject;
import org.eclipse.ditto.policies.model.PolicyException;

/**
Expand Down Expand Up @@ -55,6 +55,15 @@ private PolicyPreconditionFailedException(final DittoHeaders dittoHeaders,
super(ERROR_CODE, HttpStatus.PRECONDITION_FAILED, dittoHeaders, message, description, cause, href);
}

/**
* A mutable builder for a {@link org.eclipse.ditto.policies.model.signals.commands.exceptions.PolicyPreconditionFailedException}.
*
* @return the builder.
*/
public static Builder newBuilder() {
return new Builder();
}

/**
* A mutable builder for a {@link org.eclipse.ditto.policies.model.signals.commands.exceptions.PolicyPreconditionFailedException}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public DittoRuntimeExceptionBuilder<?> createPreconditionNotModifiedExceptionBui

@Override
public DittoRuntimeExceptionBuilder<?> createPreconditionNotModifiedForEqualityExceptionBuilder() {
return PolicyPreconditionNotModifiedException.newBuilder()
return PolicyPreconditionFailedException.newBuilder()
.message("The previous value was equal to the new value and the 'if-equal' header was set to 'skip'.")
.description("Your changes were not applied, which is probably the expected outcome.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public void ifEqualDoesThrowExceptionWhenIfEqualSkipAndValueIsEqual() {
final ModifyPolicyImport command = ModifyPolicyImport.of(policyId, policyImport,
DittoHeaders.newBuilder().ifEqual(IfEqual.SKIP).build());

assertThatExceptionOfType(PolicyPreconditionNotModifiedException.class)
assertThatExceptionOfType(PolicyPreconditionFailedException.class)
.isThrownBy(() -> SUT.applyIfEqualHeader(command, policy))
.withMessage("The previous value was equal to the new value and the 'if-equal' header was set to 'skip'.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;

import org.eclipse.ditto.json.JsonObject;
import org.eclipse.ditto.base.model.common.HttpStatus;
import org.eclipse.ditto.base.model.exceptions.DittoRuntimeException;
import org.eclipse.ditto.base.model.exceptions.DittoRuntimeExceptionBuilder;
import org.eclipse.ditto.base.model.headers.DittoHeaders;
import org.eclipse.ditto.base.model.json.JsonParsableException;
import org.eclipse.ditto.json.JsonObject;
import org.eclipse.ditto.things.model.ThingException;

/**
Expand Down Expand Up @@ -55,6 +55,15 @@ private ThingPreconditionFailedException(final DittoHeaders dittoHeaders,
super(ERROR_CODE, HttpStatus.PRECONDITION_FAILED, dittoHeaders, message, description, cause, href);
}

/**
* A mutable builder for a {@link ThingPreconditionFailedException}.
*
* @return the builder.
*/
public static Builder newBuilder() {
return new Builder();
}

/**
* A mutable builder for a {@link ThingPreconditionFailedException}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public DittoRuntimeExceptionBuilder<?> createPreconditionNotModifiedExceptionBui

@Override
public DittoRuntimeExceptionBuilder<?> createPreconditionNotModifiedForEqualityExceptionBuilder() {
return ThingPreconditionNotModifiedException.newBuilder()
return ThingPreconditionFailedException.newBuilder()
.message("The previous value was equal to the new value and the 'if-equal' header was set to 'skip'.")
.description("Your changes were not applied, which is probably the expected outcome.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public void ifEqualDoesThrowExceptionWhenIfEqualSkipAndValueIsEqual() {
final ModifyAttribute command = ModifyAttribute.of(thingId, attributePath, attributeValue,
DittoHeaders.newBuilder().ifEqual(IfEqual.SKIP).build());

assertThatExceptionOfType(ThingPreconditionNotModifiedException.class)
assertThatExceptionOfType(ThingPreconditionFailedException.class)
.isThrownBy(() -> SUT.applyIfEqualHeader(command, thing))
.withMessage("The previous value was equal to the new value and the 'if-equal' header was set to 'skip'.");
}
Expand All @@ -196,7 +196,7 @@ public void ifEqualDoesThrowExceptionWhenIfEqualSkipAndValueIsEqualUsingMerge()
final MergeThing command = MergeThing.of(thingId, JsonPointer.empty(), thing.toJson(),
DittoHeaders.newBuilder().ifEqual(IfEqual.SKIP).build());

assertThatExceptionOfType(ThingPreconditionNotModifiedException.class)
assertThatExceptionOfType(ThingPreconditionFailedException.class)
.isThrownBy(() -> SUT.applyIfEqualHeader(command, thing))
.withMessage("The previous value was equal to the new value and the 'if-equal' header was set to 'skip'.");
}
Expand Down

0 comments on commit ec71965

Please sign in to comment.