Skip to content

Commit

Permalink
[eclipse-ditto#926] review: changed status code of repsonses to 204 -…
Browse files Browse the repository at this point in the history
… no content

* removed subjectId from DeactivateTokenIntegrationResponse

Signed-off-by: Thomas Jaeckle <thomas.jaeckle@bosch.io>
  • Loading branch information
thjaeckle committed Jan 14, 2021
1 parent 67f872d commit 5c3af06
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 36 deletions.
Expand Up @@ -69,7 +69,6 @@ public final class DittoPublicKeyProvider implements PublicKeyProvider {

private static final Logger LOGGER = LoggerFactory.getLogger(DittoPublicKeyProvider.class);

private static final long JWK_REQUEST_TIMEOUT_MILLISECONDS = 5000;
private static final String OPENID_CONNECT_DISCOVERY_PATH = "/.well-known/openid-configuration";
private static final JsonFieldDefinition<String> JSON_JWKS_URI = JsonFieldDefinition.ofString("jwks_uri");

Expand Down
Expand Up @@ -76,7 +76,7 @@ public int hashCode() {
@Override
public String toString() {
return getClass().getSimpleName() + " [" +
", issuer=" + issuer +
"issuer=" + issuer +
", subjectIssuer=" + subjectIssuer +
"]";
}
Expand Down
Expand Up @@ -87,7 +87,7 @@ protected Result<PolicyEvent<?>> doApply(final Context<PolicyId> context,
SubjectDeleted.of(policyId, label, subjectId, nextRevision, getEventTimestamp(),
dittoHeaders);
final DeactivateTokenIntegrationResponse rawResponse =
DeactivateTokenIntegrationResponse.of(policyId, label, subjectId, dittoHeaders);
DeactivateTokenIntegrationResponse.of(policyId, label, dittoHeaders);
return ResultFactory.newMutationResult(adjustedCommand, event, rawResponse);
}
} else {
Expand Down
Expand Up @@ -65,13 +65,12 @@ public void deactivateTokenIntegration() {
final CommandStrategy.Context<PolicyId> context = getDefaultContext();
final SubjectId subjectId =
SubjectId.newInstance(SubjectIssuer.INTEGRATION, "{{policy-entry:label}}:this-is-me");
final SubjectId expectedSubjectId = SubjectId.newInstance(SubjectIssuer.INTEGRATION, LABEL + ":this-is-me");
final DittoHeaders dittoHeaders = DittoHeaders.empty();
final DeactivateTokenIntegration command =
DeactivateTokenIntegration.of(context.getState(), LABEL, subjectId, dittoHeaders);
assertModificationResult(underTest, TestConstants.Policy.POLICY, command,
SubjectDeleted.class,
DeactivateTokenIntegrationResponse.of(context.getState(), LABEL, expectedSubjectId, dittoHeaders));
DeactivateTokenIntegrationResponse.of(context.getState(), LABEL, dittoHeaders));
}

@Test
Expand Down
Expand Up @@ -51,7 +51,7 @@ public final class ActivatePolicyTokenIntegrationResponse
/**
* Status code of this response.
*/
public static final HttpStatusCode STATUS = HttpStatusCode.OK;
public static final HttpStatusCode STATUS = HttpStatusCode.NO_CONTENT;

private final PolicyId policyId;

Expand Down
Expand Up @@ -58,7 +58,7 @@ public final class ActivateTokenIntegrationResponse
/**
* Status code of this response.
*/
public static final HttpStatusCode STATUS = HttpStatusCode.OK;
public static final HttpStatusCode STATUS = HttpStatusCode.NO_CONTENT;

static final JsonFieldDefinition<String> JSON_LABEL =
JsonFactory.newStringFieldDefinition("label", FieldType.REGULAR, JsonSchemaVersion.V_2);
Expand Down
Expand Up @@ -51,7 +51,7 @@ public final class DeactivatePolicyTokenIntegrationResponse
/**
* Status code of this response.
*/
public static final HttpStatusCode STATUS = HttpStatusCode.OK;
public static final HttpStatusCode STATUS = HttpStatusCode.NO_CONTENT;

private final PolicyId policyId;

Expand Down
Expand Up @@ -35,7 +35,6 @@
import org.eclipse.ditto.model.policies.Label;
import org.eclipse.ditto.model.policies.Policy;
import org.eclipse.ditto.model.policies.PolicyId;
import org.eclipse.ditto.model.policies.SubjectId;
import org.eclipse.ditto.signals.commands.base.AbstractCommandResponse;
import org.eclipse.ditto.signals.commands.policies.PolicyCommandResponse;

Expand All @@ -58,40 +57,35 @@ public final class DeactivateTokenIntegrationResponse
/**
* Status code of this response.
*/
public static final HttpStatusCode STATUS = HttpStatusCode.OK;
public static final HttpStatusCode STATUS = HttpStatusCode.NO_CONTENT;

static final JsonFieldDefinition<String> JSON_LABEL =
JsonFactory.newStringFieldDefinition("label", FieldType.REGULAR, JsonSchemaVersion.V_2);

static final JsonFieldDefinition<String> JSON_SUBJECT_ID =
JsonFactory.newStringFieldDefinition("subjectId", FieldType.REGULAR, JsonSchemaVersion.V_2);

private final PolicyId policyId;
private final Label label;
private final SubjectId subjectId;

private DeactivateTokenIntegrationResponse(final PolicyId policyId, final Label label, final SubjectId subjectId,
private DeactivateTokenIntegrationResponse(final PolicyId policyId, final Label label,
final DittoHeaders dittoHeaders) {

super(TYPE, STATUS, dittoHeaders);
this.policyId = checkNotNull(policyId, "policyId");
this.label = checkNotNull(label, "label");
this.subjectId = checkNotNull(subjectId, "subjectId");
}

/**
* Creates a response to an {@code DeactivateTokenIntegration} command.
*
* @param policyId the policy ID.
* @param label the policy entry label.
* @param subjectId the added subject ID.
* @param dittoHeaders the headers of the preceding command.
* @return the response.
* @throws NullPointerException if any argument is {@code null}.
*/
public static DeactivateTokenIntegrationResponse of(final PolicyId policyId, final Label label, final SubjectId subjectId,
public static DeactivateTokenIntegrationResponse of(final PolicyId policyId, final Label label,
final DittoHeaders dittoHeaders) {
return new DeactivateTokenIntegrationResponse(policyId, label, subjectId, dittoHeaders);
return new DeactivateTokenIntegrationResponse(policyId, label, dittoHeaders);
}

/**
Expand All @@ -109,8 +103,7 @@ public static DeactivateTokenIntegrationResponse fromJson(final JsonObject jsonO
final PolicyId policyId =
PolicyId.of(jsonObject.getValueOrThrow(PolicyCommandResponse.JsonFields.JSON_POLICY_ID));
final Label label = Label.of(jsonObject.getValueOrThrow(JSON_LABEL));
final SubjectId subjectId = SubjectId.newInstance(jsonObject.getValueOrThrow(JSON_SUBJECT_ID));
return new DeactivateTokenIntegrationResponse(policyId, label, subjectId, dittoHeaders);
return new DeactivateTokenIntegrationResponse(policyId, label, dittoHeaders);
}

@Override
Expand All @@ -133,12 +126,11 @@ protected void appendPayload(final JsonObjectBuilder jsonObjectBuilder, final Js
final Predicate<JsonField> predicate = schemaVersion.and(thePredicate);
jsonObjectBuilder.set(PolicyCommandResponse.JsonFields.JSON_POLICY_ID, policyId.toString(), predicate);
jsonObjectBuilder.set(JSON_LABEL, label.toString(), predicate);
jsonObjectBuilder.set(JSON_SUBJECT_ID, subjectId.toString(), predicate);
}

@Override
public DeactivateTokenIntegrationResponse setDittoHeaders(final DittoHeaders dittoHeaders) {
return new DeactivateTokenIntegrationResponse(policyId, label, subjectId, dittoHeaders);
return new DeactivateTokenIntegrationResponse(policyId, label, dittoHeaders);
}

@Override
Expand All @@ -157,13 +149,12 @@ public boolean equals(@Nullable final Object o) {
final DeactivateTokenIntegrationResponse that = (DeactivateTokenIntegrationResponse) o;
return Objects.equals(policyId, that.policyId) &&
Objects.equals(label, that.label) &&
Objects.equals(subjectId, that.subjectId) &&
super.equals(o);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), policyId, label, subjectId);
return Objects.hash(super.hashCode(), policyId, label);
}

@Override
Expand All @@ -172,7 +163,6 @@ public String toString() {
" [" + super.toString() +
", policyId=" + policyId +
", label=" + label +
", subjectId=" + subjectId +
"]";
}

Expand Down
Expand Up @@ -39,7 +39,6 @@ public final class DeactivateTokenIntegrationResponseTest {
.set(PolicyCommandResponse.JsonFields.STATUS, DeactivateTokenIntegrationResponse.STATUS.toInt())
.set(PolicyCommandResponse.JsonFields.JSON_POLICY_ID, TestConstants.Policy.POLICY_ID.toString())
.set(DeactivateTokenIntegrationResponse.JSON_LABEL, TestConstants.Policy.LABEL.toString())
.set(DeactivateTokenIntegrationResponse.JSON_SUBJECT_ID, TestConstants.Policy.SUBJECT_ID.toString())
.build();

@Test
Expand All @@ -59,27 +58,21 @@ public void testHashCodeAndEquals() {
@Test(expected = NullPointerException.class)
public void tryToCreateInstanceWithNullPolicyId() {
DeactivateTokenIntegrationResponse.of(null, TestConstants.Policy.LABEL,
TestConstants.Policy.SUBJECT_ID, TestConstants.EMPTY_DITTO_HEADERS);
TestConstants.EMPTY_DITTO_HEADERS);
}

@Test(expected = NullPointerException.class)
public void tryToCreateInstanceWithNullLabel() {
DeactivateTokenIntegrationResponse.of(TestConstants.Policy.POLICY_ID, null,
TestConstants.Policy.SUBJECT_ID, TestConstants.EMPTY_DITTO_HEADERS);
TestConstants.EMPTY_DITTO_HEADERS);
}


@Test(expected = NullPointerException.class)
public void tryToCreateInstanceWithNullSubject() {
DeactivateTokenIntegrationResponse.of(TestConstants.Policy.POLICY_ID,
TestConstants.Policy.LABEL, null, TestConstants.EMPTY_DITTO_HEADERS);
}

@Test
public void toJsonReturnsExpected() {
final DeactivateTokenIntegrationResponse underTest =
DeactivateTokenIntegrationResponse.of(TestConstants.Policy.POLICY_ID, TestConstants.Policy.LABEL,
TestConstants.Policy.SUBJECT_ID, TestConstants.EMPTY_DITTO_HEADERS);
TestConstants.EMPTY_DITTO_HEADERS);
final JsonObject actualJson = underTest.toJson(FieldType.regularOrSpecial());

assertThat(actualJson).isEqualTo(KNOWN_JSON);
Expand All @@ -92,7 +85,7 @@ public void createInstanceFromValidJson() {

final DeactivateTokenIntegrationResponse expectedCommand =
DeactivateTokenIntegrationResponse.of(TestConstants.Policy.POLICY_ID, TestConstants.Policy.LABEL,
TestConstants.Policy.SUBJECT_ID, TestConstants.EMPTY_DITTO_HEADERS);
TestConstants.EMPTY_DITTO_HEADERS);
assertThat(underTest).isEqualTo(expectedCommand);
}

Expand Down

0 comments on commit 5c3af06

Please sign in to comment.