ModifyAttribute extends AbstractCommand<ModifyAttribute> implements ThingModifyCommand<ModifyAttribute> { @Deprecated public static ModifyAttribute of(final String thingId, final JsonPointer attributeJsonPointer, final JsonValue newAttributeValue, final DittoHeaders dittoHeaders) { return of(ThingId.of(thingId), attributeJsonPointer, newAttributeValue, dittoHeaders); } private  ModifyAttribute(final JsonPointer attributePointer, final JsonValue attributeValue, final ThingId thingId,
            final DittoHeaders dittoHeaders); @Deprecated static ModifyAttribute of(final String thingId,
            final JsonPointer attributeJsonPointer,
            final JsonValue newAttributeValue,
            final DittoHeaders dittoHeaders); static ModifyAttribute of(final ThingId thingId,
            final JsonPointer attributeJsonPointer,
            final JsonValue newAttributeValue,
            final DittoHeaders dittoHeaders); static ModifyAttribute fromJson(final String jsonString, final DittoHeaders dittoHeaders); static ModifyAttribute fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders); JsonPointer getAttributePointer(); JsonValue getAttributeValue(); @Override ThingId getThingEntityId(); @Override Optional<JsonValue> getEntity(final JsonSchemaVersion schemaVersion); @Override JsonPointer getResourcePath(); @Override Category getCategory(); @Override ModifyAttribute setDittoHeaders(final DittoHeaders dittoHeaders); @Override boolean changesAuthorization(); @Override int hashCode(); @SuppressWarnings({"squid:MethodCyclomaticComplexity", "squid:S1067", "OverlyComplexMethod"}) @Override boolean equals(@Nullable final Object obj); @Override String toString(); static final String NAME; static final String TYPE; }
@Test public void tryToCreateInstanceWithNullAttribute() { assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> ModifyAttribute.of(TestConstants.Thing.THING_ID, KNOWN_JSON_POINTER, null, TestConstants.EMPTY_DITTO_HEADERS)) .withNoCause(); }
@Test public void tryToCreateInstanceWithNullJsonPointer() { assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> ModifyAttribute.of(TestConstants.Thing.THING_ID, null, KNOWN_ATTRIBUTE, TestConstants.EMPTY_DITTO_HEADERS)) .withNoCause(); }
@Test public void tryToCreateInstanceWithEmptyJsonPointer() { assertThatExceptionOfType(AttributePointerInvalidException.class) .isThrownBy(() -> ModifyAttribute.of(TestConstants.Thing.THING_ID, JsonPointer.empty(), KNOWN_ATTRIBUTE, TestConstants.EMPTY_DITTO_HEADERS)) .withNoCause(); }
@Test() public void tryToCreateInstanceWithValidArguments() { ModifyAttribute.of(TestConstants.Thing.THING_ID, VALID_JSON_POINTER, KNOWN_ATTRIBUTE, TestConstants.EMPTY_DITTO_HEADERS); }
@Test(expected = JsonKeyInvalidException.class) public void tryToCreateInstanceWithInvalidAttributePointer() { ModifyAttribute.of(TestConstants.Thing.THING_ID, INVALID_JSON_POINTER, KNOWN_ATTRIBUTE, TestConstants.EMPTY_DITTO_HEADERS); }
@Test(expected = JsonKeyInvalidException.class) public void createInstanceFromInvalidJsonValue() { final JsonValue invalid = JsonValue.of(JsonObject.of("{\"bar/baz\":false}")); ModifyAttribute.of(TestConstants.Thing.THING_ID, VALID_JSON_POINTER, invalid, TestConstants.EMPTY_DITTO_HEADERS); }
@Test public void tryToCreateInstanceWithValidJsonObjectAsValue() { final JsonValue valid = JsonValue.of(JsonObject.of("{\"bar.baz\":false}")); ModifyAttribute.of(TestConstants.Thing.THING_ID, VALID_JSON_POINTER, valid, TestConstants.EMPTY_DITTO_HEADERS); }
@Test(expected = AttributePointerInvalidException.class) public void createInstanceWithEmptyPointer() { ModifyAttribute.of(TestConstants.Thing.THING_ID, EMPTY_JSON_POINTER, KNOWN_ATTRIBUTE, TestConstants.EMPTY_DITTO_HEADERS); }
@Test public void toJsonReturnsExpected() { final ModifyAttribute underTest = ModifyAttribute.of(TestConstants.Thing.THING_ID, KNOWN_JSON_POINTER, KNOWN_ATTRIBUTE, TestConstants.EMPTY_DITTO_HEADERS); final JsonObject actualJson = underTest.toJson(FieldType.regularOrSpecial()); assertThat(actualJson).isEqualTo(KNOWN_JSON); }