Skip to content

Commit

Permalink
Adds tests for ImmutableThing to verify that policyId is validated
Browse files Browse the repository at this point in the history
Signed-off-by: Klem Yannic (INST/ECS1) <Yannic.Klem@bosch-si.com>
  • Loading branch information
Yannic92 committed Jan 21, 2019
1 parent 991aad9 commit cae48f1
Showing 1 changed file with 34 additions and 0 deletions.
Expand Up @@ -10,6 +10,7 @@
*/
package org.eclipse.ditto.model.things;

import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.eclipse.ditto.model.things.TestConstants.Feature.FEATURES;
import static org.eclipse.ditto.model.things.TestConstants.Feature.FLUX_CAPACITOR_ID;
import static org.eclipse.ditto.model.things.TestConstants.Feature.FLUX_CAPACITOR_PROPERTIES;
Expand All @@ -34,6 +35,7 @@
import org.eclipse.ditto.json.assertions.DittoJsonAssertions;
import org.eclipse.ditto.model.base.json.FieldType;
import org.eclipse.ditto.model.base.json.JsonSchemaVersion;
import org.eclipse.ditto.model.policies.PolicyIdInvalidException;
import org.junit.Test;

import nl.jqno.equalsverifier.EqualsVerifier;
Expand Down Expand Up @@ -168,6 +170,38 @@ public void createThingWithoutLifecycle() {
.hasModified(MODIFIED);
}

@Test
public void createThingWithInvalidPolicyId() {
final String invalidPolicyId = "namespace:";
assertThatExceptionOfType(PolicyIdInvalidException.class).isThrownBy(() -> {
ImmutableThing.of(
THING_ID,
invalidPolicyId,
ATTRIBUTES,
FEATURES,
LIFECYCLE,
REVISION,
MODIFIED);
});
}

@Test
public void setInvalidPolicyId() {
final String validPolicyId = "namespace:name";
final String invalidPolicyId = "namespace:";

final Thing thing = ImmutableThing.of(
THING_ID,
validPolicyId,
ATTRIBUTES,
FEATURES,
LIFECYCLE,
REVISION,
MODIFIED);

assertThatExceptionOfType(PolicyIdInvalidException.class).isThrownBy(() -> thing.setPolicyId(invalidPolicyId));
}

@Test
public void createThingWithoutRevision() {
final Thing thing = ImmutableThing.of(THING_ID, ACL, ATTRIBUTES, FEATURES, LIFECYCLE, null, MODIFIED);
Expand Down

0 comments on commit cae48f1

Please sign in to comment.