PolicyCreated extends AbstractPolicyEvent<PolicyCreated> implements PolicyEvent<PolicyCreated> { public static PolicyCreated of(final Policy policy, final long revision, final DittoHeaders dittoHeaders) { return of(checkNotNull(policy, PROPERTY_NAME_POLICY), revision, null, dittoHeaders); } private  PolicyCreated(final Policy policy,
            final long revision,
            @Nullable final Instant timestamp,
            final DittoHeaders dittoHeaders); static PolicyCreated of(final Policy policy, final long revision, final DittoHeaders dittoHeaders); static PolicyCreated of(final Policy policy,
            final long revision,
            @Nullable final Instant timestamp,
            final DittoHeaders dittoHeaders); static PolicyCreated fromJson(final String jsonString, final DittoHeaders dittoHeaders); static PolicyCreated fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders); Policy getPolicy(); @Override Optional<JsonValue> getEntity(final JsonSchemaVersion schemaVersion); @Override JsonPointer getResourcePath(); @Override PolicyCreated setRevision(final long revision); @Override PolicyCreated setDittoHeaders(final DittoHeaders dittoHeaders); @SuppressWarnings("squid:S109") @Override int hashCode(); @SuppressWarnings("squid:MethodCyclomaticComplexity") @Override boolean equals(@Nullable final Object o); @Override String toString(); static final String NAME; static final String TYPE; }
@Test(expected = NullPointerException.class) public void tryToCreateInstanceWithNullPolicy() { PolicyCreated.of(null, TestConstants.Policy.REVISION_NUMBER, TestConstants.EMPTY_DITTO_HEADERS); }
@Test(expected = PolicyIdInvalidException.class) public void tryToCreateInstanceWithNullPolicyId() { final Policy policyWithNullId = PoliciesModelFactory.newPolicyBuilder((String) null).build(); PolicyCreated.of(policyWithNullId, TestConstants.Policy.REVISION_NUMBER, TestConstants.EMPTY_DITTO_HEADERS); }
@Test(expected = NullPointerException.class) public void tryToCreateInstanceWithNullDittoHeaders() { PolicyCreated.of(TestConstants.Policy.POLICY, TestConstants.Policy.REVISION_NUMBER, null); }
@Test public void toJsonReturnsExpected() { final PolicyCreated underTest = PolicyCreated.of(TestConstants.Policy.POLICY, TestConstants.Policy.REVISION_NUMBER, TestConstants.TIMESTAMP, TestConstants.EMPTY_DITTO_HEADERS); final JsonObject actualJson = underTest.toJson(FieldType.regularOrSpecial()); assertThat(actualJson).isEqualTo(KNOWN_JSON); }
@Test public void toJsonWithoutRevision() { final PolicyCreated underTest = PolicyCreated.of(TestConstants.Policy.POLICY, TestConstants.Policy.REVISION_NUMBER, TestConstants.TIMESTAMP, TestConstants.EMPTY_DITTO_HEADERS); final Predicate<JsonField> isRevision = field -> field.getDefinition().map(definition -> definition == Event.JsonFields.REVISION).orElse(false); final JsonObject actualJson = underTest.toJson(isRevision.negate().and(FieldType.regularOrSpecial())); assertThat(actualJson).isEqualTo(KNOWN_JSON_WITHOUT_REVISION); }
@Test public void parsePolicyCreatedEvent() { final GlobalEventRegistry eventRegistry = GlobalEventRegistry.getInstance(); final PolicyCreated event = PolicyCreated.of(TestConstants.Policy.POLICY, TestConstants.Policy.REVISION_NUMBER, TestConstants.DITTO_HEADERS); final JsonObject jsonObject = event.toJson(FieldType.regularOrSpecial()); final Event parsedEvent = eventRegistry.parse(jsonObject, TestConstants.DITTO_HEADERS); assertThat(parsedEvent).isEqualTo(event); }