ImmutableThing implements Thing { @Deprecated static Thing of(@Nullable final String thingId, @Nullable final AccessControlList accessControlList, @Nullable final Attributes attributes, @Nullable final Features features, @Nullable final ThingLifecycle lifecycle, @Nullable final ThingRevision revision, @Nullable final Instant modified, @Nullable final Instant created, @Nullable final Metadata metadata) { return of(ThingId.of(thingId), accessControlList, attributes, features, lifecycle, revision, modified, created, metadata); } private  ImmutableThing(@Nullable final ThingId thingId,
            @Nullable final AccessControlList acl,
            @Nullable final PolicyId policyId,
            @Nullable final ThingDefinition definition,
            @Nullable final Attributes attributes,
            @Nullable final Features features,
            @Nullable final ThingLifecycle lifecycle,
            @Nullable final ThingRevision revision,
            @Nullable final Instant modified,
            @Nullable final Instant created,
            @Nullable final Metadata metadata); @Override Optional<ThingRevision> getRevision(); @Override Optional<Instant> getModified(); @Override Optional<Instant> getCreated(); @Override boolean isDeleted(); @Override Optional<ThingId> getEntityId(); @Override Optional<String> getNamespace(); @Override Optional<Attributes> getAttributes(); @Override Thing setAttributes(@Nullable final Attributes attributes); @Override Thing removeAttributes(); @Override Thing setAttribute(final JsonPointer attributePath, final JsonValue attributeValue); @Override Thing removeAttribute(final JsonPointer attributePath); @Override Optional<ThingDefinition> getDefinition(); @Override Thing setDefinition(@Nullable final CharSequence definitionIdentifier); @Override Thing removeDefinition(); @Override Optional<Features> getFeatures(); @Override Thing removeFeatures(); @Override Thing setFeatures(@Nullable final Features features); @Override Thing setFeature(final Feature feature); @Override Thing removeFeature(final String featureId); @Override Thing setFeatureDefinition(final String featureId, final FeatureDefinition definition); @Override Thing removeFeatureDefinition(final String featureId); @Override Thing setFeatureProperties(final String featureId, final FeatureProperties properties); @Override Thing removeFeatureProperties(final String featureId); @Override Thing setFeatureProperty(final String featureId, final JsonPointer propertyJsonPointer,
            final JsonValue propertyValue); @Override Thing removeFeatureProperty(final String featureId, final JsonPointer propertyPath); @Override @Deprecated Optional<AccessControlList> getAccessControlList(); @Override @Deprecated Thing setAccessControlList(final AccessControlList accessControlList); @Override @Deprecated Thing setAclEntry(final AclEntry aclEntry); @Override @Deprecated Thing removeAllPermissionsOf(final AuthorizationSubject authorizationSubject); @Override Optional<PolicyId> getPolicyEntityId(); @Override Thing setPolicyId(@Nullable final PolicyId policyId); @Override Optional<ThingLifecycle> getLifecycle(); @Override Thing setLifecycle(final ThingLifecycle newLifecycle); @Override Optional<Metadata> getMetadata(); @Override JsonObject toJson(final JsonSchemaVersion schemaVersion, final Predicate<JsonField> thePredicate); @Override int hashCode(); @SuppressWarnings({"squid:MethodCyclomaticComplexity", "squid:S1067", "OverlyComplexMethod"}) @Override boolean equals(final Object obj); @Override String toString();  }
@Test public void createThingWithoutId() { final Thing thing = ImmutableThing.of((ThingId) null, ACL, ATTRIBUTES, FEATURES, LIFECYCLE, REVISION, MODIFIED, CREATED, METADATA); assertThat(thing) .hasNoId() .hasAcl(ACL) .hasAttributes(ATTRIBUTES) .hasFeatures(FEATURES) .hasLifecycle(LIFECYCLE) .hasRevision(REVISION) .hasModified(MODIFIED) .hasCreated(CREATED) .hasMetadata(METADATA); }
@Test public void createThingWithoutACL() { final Thing thing = ImmutableThing.of(THING_ID, null, ATTRIBUTES, FEATURES, LIFECYCLE, REVISION, MODIFIED, CREATED, METADATA); assertThat(thing) .hasId(THING_ID) .hasNoAcl() .hasAttributes(ATTRIBUTES) .hasFeatures(FEATURES) .hasLifecycle(LIFECYCLE) .hasRevision(REVISION) .hasModified(MODIFIED) .hasCreated(CREATED) .hasMetadata(METADATA); }
@Test public void createThingWithoutPolicyId() { final Thing thing = ImmutableThing.of(THING_ID, null, DEFINITION, ATTRIBUTES, FEATURES, LIFECYCLE, REVISION, MODIFIED, CREATED, METADATA); assertThat(thing) .hasId(THING_ID) .hasNoPolicyId() .hasDefinition(DEFINITION) .hasAttributes(ATTRIBUTES) .hasFeatures(FEATURES) .hasLifecycle(LIFECYCLE) .hasRevision(REVISION) .hasModified(MODIFIED) .hasCreated(CREATED) .hasMetadata(METADATA); }
@Test public void createThingWithoutDefinition() { final Thing thing = ImmutableThing.of(THING_ID, POLICY_ID, null, ATTRIBUTES, FEATURES, LIFECYCLE, REVISION, MODIFIED, CREATED, METADATA); assertThat(thing) .hasId(THING_ID) .hasPolicyId(POLICY_ID) .hasNoDefinition() .hasAttributes(ATTRIBUTES) .hasFeatures(FEATURES) .hasLifecycle(LIFECYCLE) .hasRevision(REVISION) .hasModified(MODIFIED) .hasCreated(CREATED) .hasMetadata(METADATA);; }
@Test public void createThingWithoutAttributes() { final Thing thing = ImmutableThing.of(THING_ID, ACL, null, FEATURES, LIFECYCLE, REVISION, MODIFIED, CREATED, METADATA); assertThat(thing) .hasId(THING_ID) .hasAcl(ACL) .hasNoAttributes() .hasFeatures(FEATURES) .hasLifecycle(LIFECYCLE) .hasRevision(REVISION) .hasModified(MODIFIED) .hasCreated(CREATED) .hasMetadata(METADATA); }
@Test public void createThingWithoutFeatures() { final Thing thing = ImmutableThing.of(THING_ID, ACL, ATTRIBUTES, null, LIFECYCLE, REVISION, MODIFIED, CREATED, METADATA); assertThat(thing) .hasId(THING_ID) .hasAcl(ACL) .hasAttributes(ATTRIBUTES) .hasNoFeatures() .hasLifecycle(LIFECYCLE) .hasRevision(REVISION) .hasModified(MODIFIED) .hasCreated(CREATED) .hasMetadata(METADATA); }
@Test public void createThingWithoutLifecycle() { final Thing thing = ImmutableThing.of(THING_ID, ACL, ATTRIBUTES, FEATURES, null, REVISION, MODIFIED, CREATED, METADATA); assertThat(thing) .hasId(THING_ID) .hasAcl(ACL) .hasAttributes(ATTRIBUTES) .hasFeatures(FEATURES) .hasNoLifecycle() .hasRevision(REVISION) .hasModified(MODIFIED) .hasCreated(CREATED) .hasMetadata(METADATA); }
@Test public void createThingWithInvalidPolicyId() { final String invalidPolicyId = "namespace:"; assertThatExceptionOfType(PolicyIdInvalidException.class).isThrownBy(() -> { ImmutableThing.of( THING_ID, PolicyId.of(invalidPolicyId), DEFINITION, ATTRIBUTES, FEATURES, LIFECYCLE, REVISION, MODIFIED, CREATED, METADATA); }); }
@Test public void createThingWithInvalidDefinition() { final String invalidDefinitionValue = "!namespace:"; assertThatExceptionOfType(DefinitionIdentifierInvalidException.class).isThrownBy(() -> { ThingDefinition invalidDefinition = ImmutableThingDefinition.ofParsed(invalidDefinitionValue); ImmutableThing.of( THING_ID, POLICY_ID, invalidDefinition, ATTRIBUTES, FEATURES, LIFECYCLE, REVISION, MODIFIED, CREATED, METADATA); }); }
@Test public void createThingWithoutRevision() { final Thing thing = ImmutableThing.of(THING_ID, ACL, ATTRIBUTES, FEATURES, LIFECYCLE, null, MODIFIED, CREATED, METADATA); assertThat(thing) .hasId(THING_ID) .hasAcl(ACL) .hasAttributes(ATTRIBUTES) .hasFeatures(FEATURES) .hasLifecycle(LIFECYCLE) .hasNoRevision() .hasModified(MODIFIED) .hasCreated(CREATED) .hasMetadata(METADATA); }
@Test public void createThingWithoutModified() { final Thing thing = ImmutableThing.of(THING_ID, ACL, ATTRIBUTES, FEATURES, LIFECYCLE, REVISION, null, CREATED, METADATA); assertThat(thing) .hasId(THING_ID) .hasAcl(ACL) .hasAttributes(ATTRIBUTES) .hasFeatures(FEATURES) .hasLifecycle(LIFECYCLE) .hasRevision(REVISION) .hasCreated(CREATED) .hasMetadata(METADATA) .hasNoModified(); }
@Test public void createThingWithoutCreated() { final Thing thing = ImmutableThing.of(THING_ID, ACL, ATTRIBUTES, FEATURES, LIFECYCLE, REVISION, MODIFIED, null, METADATA); assertThat(thing) .hasId(THING_ID) .hasAcl(ACL) .hasAttributes(ATTRIBUTES) .hasFeatures(FEATURES) .hasLifecycle(LIFECYCLE) .hasRevision(REVISION) .hasModified(MODIFIED) .hasNoCreated(); }
@Test public void tryToCreateThingWithValidThingIdNamespace() { ImmutableThing.of(ThingId.of("foo.bar", "foobar2000"), ACL, ATTRIBUTES, EMPTY_FEATURES, LIFECYCLE, REVISION, MODIFIED, CREATED, METADATA); }
@Test public void tryToCreateThingWithValidThingIdNamespace2() { ImmutableThing.of(ThingId.of("foo.a42", "foobar2000"), ACL, ATTRIBUTES, EMPTY_FEATURES, LIFECYCLE, REVISION, MODIFIED, CREATED, METADATA); }
@Test public void tryToCreateThingWithValidThingIdNamespace3() { ImmutableThing.of(ThingId.of("ad", "foobar2000"), ACL, ATTRIBUTES, EMPTY_FEATURES, LIFECYCLE, REVISION, MODIFIED, CREATED, METADATA); }
@Test public void tryToCreateThingWithValidThingIdNamespace4() { ImmutableThing.of(ThingId.of("da23", "foobar2000"), ACL, ATTRIBUTES, EMPTY_FEATURES, LIFECYCLE, REVISION, MODIFIED, CREATED, METADATA); }
@Test public void createThingWithInvalidIds() { final List<String> invalidThingIds = Arrays.asList("", "foobar2000", "foo-bar:foobar2000", "foo.bar%bum:foobar2000", ".namespace:foobar2000", "namespace.:foobar2000", "namespace..invalid:foobar2000", "namespace.42:foobar2000"); invalidThingIds.forEach(invalidId -> assertThatExceptionOfType(ThingIdInvalidException.class).isThrownBy( () -> ThingId.of(invalidId))); }
@Test public void createThingWithInvalidCharactersInId() { final String invalidCharacter = "/"; assertThatExceptionOfType(ThingIdInvalidException.class).isThrownBy(() -> ImmutableThing.of( "ns:thingIdWithAnd" + invalidCharacter, ACL, ATTRIBUTES, FEATURES, LIFECYCLE, REVISION, MODIFIED, CREATED, METADATA) ); }