CreatePolicy extends AbstractCommand<CreatePolicy> implements PolicyModifyCommand<CreatePolicy> { public static CreatePolicy of(final Policy policy, final DittoHeaders dittoHeaders) { return new CreatePolicy(policy, dittoHeaders); } private  CreatePolicy(final Policy policy, final DittoHeaders dittoHeaders); static CreatePolicy of(final Policy policy, final DittoHeaders dittoHeaders); static CreatePolicy fromJson(final String jsonString, final DittoHeaders dittoHeaders); static CreatePolicy 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 CreatePolicy 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(expected = NullPointerException.class) public void tryToCreateInstanceWithNullPolicy() { CreatePolicy.of(null, TestConstants.EMPTY_DITTO_HEADERS); }
@Test(expected = PolicyIdInvalidException.class) public void tryToCreateInstanceWithInvalidPolicyId() { final Policy policy = PoliciesModelFactory.newPolicyBuilder("test.ns:foo/bar") .set(TestConstants.Policy.POLICY_ENTRY) .build(); CreatePolicy.of(policy, TestConstants.EMPTY_DITTO_HEADERS); }
@Test public void createInstanceWithValidPolicyId() { final Policy policy = PoliciesModelFactory.newPolicyBuilder("test.ns:foo-bar") .set(TestConstants.Policy.POLICY_ENTRY) .build(); final CreatePolicy createPolicy = CreatePolicy.of(policy, TestConstants.EMPTY_DITTO_HEADERS); assertThat(createPolicy).isNotNull(); }
@Test public void toJsonReturnsExpected() { final CreatePolicy underTest = CreatePolicy.of(TestConstants.Policy.POLICY, TestConstants.EMPTY_DITTO_HEADERS); final JsonObject actualJson = underTest.toJson(FieldType.regularOrSpecial()); assertThat(actualJson).isEqualTo(KNOWN_JSON); }