ModifyPolicy extends AbstractCommand<ModifyPolicy> implements PolicyModifyCommand<ModifyPolicy> { @Deprecated public static ModifyPolicy of(final String policyId, final Policy policy, final DittoHeaders dittoHeaders) { return of(PolicyId.of(policyId), policy, dittoHeaders); } private  ModifyPolicy(final PolicyId policyId, final Policy policy, final DittoHeaders dittoHeaders); @Deprecated static ModifyPolicy of(final String policyId, final Policy policy, final DittoHeaders dittoHeaders); static ModifyPolicy of(final PolicyId policyId, final Policy policy, final DittoHeaders dittoHeaders); static ModifyPolicy fromJson(final String jsonString, final DittoHeaders dittoHeaders); static ModifyPolicy fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders); Policy getPolicy(); @Override PolicyId getEntityId(); @Override Optional<JsonValue> getEntity(final JsonSchemaVersion schemaVersion); @Override JsonPointer getResourcePath(); @Override Category getCategory(); @Override ModifyPolicy setDittoHeaders(final DittoHeaders dittoHeaders); @SuppressWarnings("squid:MethodCyclomaticComplexity") @Override boolean equals(@Nullable final Object obj); @SuppressWarnings("squid:S109") @Override int hashCode(); @Override String toString(); static final String NAME; static final String TYPE; }
@Test public void tryToCreateInstanceWithInvalidPolicyId() { assertThatExceptionOfType(PolicyIdInvalidException.class) .isThrownBy(() -> ModifyPolicy.of("undefined", TestConstants.Policy.POLICY, TestConstants.EMPTY_DITTO_HEADERS)); }
@Test(expected = NullPointerException.class) public void tryToCreateInstanceWithNullPolicy() { ModifyPolicy.of(TestConstants.Policy.POLICY_ID, null, TestConstants.EMPTY_DITTO_HEADERS); }
@Test public void toJsonReturnsExpected() { final ModifyPolicy underTest = ModifyPolicy.of(TestConstants.Policy.POLICY_ID, TestConstants.Policy.POLICY, TestConstants.EMPTY_DITTO_HEADERS); final JsonObject actualJson = underTest.toJson(FieldType.regularOrSpecial()); assertThat(actualJson).isEqualTo(KNOWN_JSON); }
@Test public void parseModifyPolicyCommand() { final GlobalCommandRegistry commandRegistry = GlobalCommandRegistry.getInstance(); final ModifyPolicy command = ModifyPolicy.of(TestConstants.Policy.POLICY_ID, TestConstants.Policy.POLICY, TestConstants.DITTO_HEADERS); final JsonObject jsonObject = command.toJson(FieldType.regularOrSpecial()); final Command parsedCommand = commandRegistry.parse(jsonObject, TestConstants.DITTO_HEADERS); assertThat(parsedCommand).isEqualTo(command); }