diff --git a/.checkstyle b/.checkstyle deleted file mode 100644 index 15ff199..0000000 --- a/.checkstyle +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - diff --git a/checkstyle.xml b/checkstyle.xml deleted file mode 100644 index 052d3c4..0000000 --- a/checkstyle.xml +++ /dev/null @@ -1,117 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/ies-4-contentrepository-core-cs-cleanup.xml b/ies-4-contentrepository-core-cs-cleanup.xml deleted file mode 100644 index 57b9c20..0000000 --- a/ies-4-contentrepository-core-cs-cleanup.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - diff --git a/ies-4-contentrepository-core-cs-formatter.xml b/ies-4-contentrepository-core-cs-formatter.xml deleted file mode 100644 index 3f398f2..0000000 --- a/ies-4-contentrepository-core-cs-formatter.xml +++ /dev/null @@ -1,149 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/pom.xml b/pom.xml index ce5074c..39fefb9 100644 --- a/pom.xml +++ b/pom.xml @@ -1,3 +1,4 @@ + 4.0.0 @@ -7,6 +8,11 @@ IES Content Repository Core IES contentrepository domain und use-case implementations + + Sitepark + https://www.sitepark.com + + The MIT License @@ -14,11 +20,6 @@ - - Sitepark - https://www.sitepark.com - - veltrup@sitepark @@ -34,6 +35,13 @@ + + scm:git:git@github.com:sitepark/ies-contentrepository-core.git + scm:git:git@github.com:sitepark/ies-contentrepository-core.git + HEAD + https://github.com/sitepark/ies-contentrepository-core + + 5.10.2 4.8.3 @@ -42,13 +50,6 @@ true - - scm:git:git@github.com:sitepark/ies-contentrepository-core.git - scm:git:git@github.com:sitepark/ies-contentrepository-core.git - https://github.com/sitepark/ies-contentrepository-core - HEAD - - @@ -213,10 +214,10 @@ sign-artifacts - verify sign + verify @@ -224,7 +225,7 @@ maven-release-plugin 3.0.1 - ci(release): + ci(release): @{project.version} @@ -232,6 +233,13 @@ org.apache.maven.plugins maven-enforcer-plugin 3.4.1 + + + io.github.thefolle + glowing-waffle + 1.2.0 + + enforce-maven @@ -240,7 +248,7 @@ - + 3.8 @@ -252,30 +260,22 @@ verify-release - none enforce + none false No Snapshots Allowed! - + true - - - io.github.thefolle - glowing-waffle - 1.2.0 - - org.jacoco @@ -310,47 +310,78 @@ generate-code-coverage-report - test report + test - org.apache.maven.plugins - maven-checkstyle-plugin - 3.3.1 + com.diffplug.spotless + spotless-maven-plugin + 2.43.0 - checkstyle.xml - UTF-8 - true - true - false + + + + google-java-format + + + + + 1.19.2 + + true + false + + + + + + + pom.xml + + + + -1 + + - checkstyle - verify + spotless-check check + verify - + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + com.diffplug.spotless + spotless-maven-plugin + + + + + + + + + com.github.spotbugs spotbugs-maven-plugin 4.8.3.0 - - - verify - - check - - - Max Low @@ -367,20 +398,19 @@ ${spotbugs.version} - - - org.apache.maven.plugins - maven-pmd-plugin - 3.21.2 - pmd - verify check + verify + + + org.apache.maven.plugins + maven-pmd-plugin + 3.21.2 pmd-ruleset.xml @@ -389,9 +419,19 @@ true 5 true - false + false + + + + pmd + + check + + verify + + - \ No newline at end of file + diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/domain/databind/DatabindModule.java b/src/main/java/com/sitepark/ies/contentrepository/core/domain/databind/DatabindModule.java index da5f6f9..7fcdf73 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/domain/databind/DatabindModule.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/domain/databind/DatabindModule.java @@ -6,9 +6,9 @@ public class DatabindModule extends SimpleModule { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - public DatabindModule() { - super.addDeserializer(Filter.class, new FilterDeserializer()); - } + public DatabindModule() { + super.addDeserializer(Filter.class, new FilterDeserializer()); + } } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/domain/databind/UniquePropertyPolymorphicDeserializer.java b/src/main/java/com/sitepark/ies/contentrepository/core/domain/databind/UniquePropertyPolymorphicDeserializer.java index d6e0322..af7fcd1 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/domain/databind/UniquePropertyPolymorphicDeserializer.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/domain/databind/UniquePropertyPolymorphicDeserializer.java @@ -1,17 +1,16 @@ package com.sitepark.ies.contentrepository.core.domain.databind; -import java.io.IOException; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.Map.Entry; - import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.deser.std.StdDeserializer; import com.fasterxml.jackson.databind.node.ObjectNode; +import java.io.IOException; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Map.Entry; /** * Deserializes documents without a specific field designated for @@ -20,47 +19,48 @@ */ public class UniquePropertyPolymorphicDeserializer extends StdDeserializer { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - // the registry of unique field names to Class types - private final Map> registry; + // the registry of unique field names to Class types + private final Map> registry; - public UniquePropertyPolymorphicDeserializer(Class clazz) { - super(clazz); - this.registry = new HashMap>(); - } + public UniquePropertyPolymorphicDeserializer(Class clazz) { + super(clazz); + this.registry = new HashMap>(); + } - public void register(String uniqueProperty, Class clazz) { - this.registry.put(uniqueProperty, clazz); - } + public void register(String uniqueProperty, Class clazz) { + this.registry.put(uniqueProperty, clazz); + } - /* - * (non-Javadoc) - * - * @see com.fasterxml.jackson.databind.JsonDeserializer#deserialize(com.fasterxml.jackson.core.JsonParser, - * com.fasterxml.jackson.databind.DeserializationContext) - */ - @Override - public T deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { - Class clazz = null; + /* + * (non-Javadoc) + * + * @see com.fasterxml.jackson.databind.JsonDeserializer#deserialize(com.fasterxml.jackson.core.JsonParser, + * com.fasterxml.jackson.databind.DeserializationContext) + */ + @Override + public T deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { + Class clazz = null; - ObjectMapper mapper = (ObjectMapper) jp.getCodec(); - ObjectNode obj = (ObjectNode) mapper.readTree(jp); - Iterator> elementsIterator = obj.fields(); + ObjectMapper mapper = (ObjectMapper) jp.getCodec(); + ObjectNode obj = (ObjectNode) mapper.readTree(jp); + Iterator> elementsIterator = obj.fields(); - while (elementsIterator.hasNext()) { - Entry element = elementsIterator.next(); - String name = element.getKey(); - if (registry.containsKey(name)) { - clazz = registry.get(name); - break; - } - } + while (elementsIterator.hasNext()) { + Entry element = elementsIterator.next(); + String name = element.getKey(); + if (registry.containsKey(name)) { + clazz = registry.get(name); + break; + } + } - if (clazz == null) { - ctxt.reportInputMismatch(this, "No registered unique properties found for polymorphic deserialization"); - } + if (clazz == null) { + ctxt.reportInputMismatch( + this, "No registered unique properties found for polymorphic deserialization"); + } - return mapper.treeToValue(obj, clazz); - } + return mapper.treeToValue(obj, clazz); + } } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/Anchor.java b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/Anchor.java index ccc5ecf..a5b52d8 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/Anchor.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/Anchor.java @@ -1,88 +1,83 @@ package com.sitepark.ies.contentrepository.core.domain.entity; - +import com.fasterxml.jackson.annotation.JsonValue; +import com.sitepark.ies.contentrepository.core.domain.exception.InvalidAnchorException; import java.io.Serializable; import java.util.Objects; import java.util.regex.Pattern; -import com.fasterxml.jackson.annotation.JsonValue; -import com.sitepark.ies.contentrepository.core.domain.exception.InvalidAnchorException; - public final class Anchor implements Serializable { - private static final long serialVersionUID = 1L; - - public static final String VALID_CHARS_REGEX = "[a-zA-Z0-9_.\\-]+"; + private static final long serialVersionUID = 1L; - private static final Pattern VALIDATOR_PATTERN = Pattern.compile(VALID_CHARS_REGEX); + public static final String VALID_CHARS_REGEX = "[a-zA-Z0-9_.\\-]+"; - private static final Pattern ONLY_NUMBERS_PATTERN = Pattern.compile("[0-9]+"); + private static final Pattern VALIDATOR_PATTERN = Pattern.compile(VALID_CHARS_REGEX); - /** - * Used to reset anchor when saving entries. - */ - public static final Anchor EMPTY = new Anchor(""); + private static final Pattern ONLY_NUMBERS_PATTERN = Pattern.compile("[0-9]+"); - @JsonValue - private final String name; + /** + * Used to reset anchor when saving entries. + */ + public static final Anchor EMPTY = new Anchor(""); - private Anchor(String name) { - this.name = name; - } + @JsonValue private final String name; - public static Anchor ofString(String name) { + private Anchor(String name) { + this.name = name; + } - if (name == null) { - return null; - } + public static Anchor ofString(String name) { - if (name.isBlank()) { - return EMPTY; - } + if (name == null) { + return null; + } - Anchor.validate(name); - return new Anchor(name); - } + if (name.isBlank()) { + return EMPTY; + } - public String getName() { - return this.name; - } + Anchor.validate(name); + return new Anchor(name); + } - /** - * @throws InvalidAnchorException - */ - private static void validate(String name) { + public String getName() { + return this.name; + } - if (ONLY_NUMBERS_PATTERN.matcher(name).matches()) { - throw new InvalidAnchorException(name, "Anchor must not only consist of numbers"); - } + /** + * @throws InvalidAnchorException + */ + private static void validate(String name) { - if (!VALIDATOR_PATTERN.matcher(name).matches()) { - throw new InvalidAnchorException( - name, - "Anchor contains invalid characters. Allowd are: " + VALID_CHARS_REGEX); - } - } + if (ONLY_NUMBERS_PATTERN.matcher(name).matches()) { + throw new InvalidAnchorException(name, "Anchor must not only consist of numbers"); + } - @Override - public int hashCode() { - return this.name != null ? this.name.hashCode() : 0; - } + if (!VALIDATOR_PATTERN.matcher(name).matches()) { + throw new InvalidAnchorException( + name, "Anchor contains invalid characters. Allowd are: " + VALID_CHARS_REGEX); + } + } + @Override + public int hashCode() { + return this.name != null ? this.name.hashCode() : 0; + } - @Override - public boolean equals(Object o) { + @Override + public boolean equals(Object o) { - if (!(o instanceof Anchor)) { - return false; - } + if (!(o instanceof Anchor)) { + return false; + } - Anchor anchor = (Anchor)o; - return Objects.equals(this.name, anchor.name); - } + Anchor anchor = (Anchor) o; + return Objects.equals(this.name, anchor.name); + } - @Override - public String toString() { - return this == EMPTY ? "EMPTY" : this.name; - } + @Override + public String toString() { + return this == EMPTY ? "EMPTY" : this.name; + } } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/BulkOperationKey.java b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/BulkOperationKey.java index 9e9fdf2..0a95e5e 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/BulkOperationKey.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/BulkOperationKey.java @@ -1,19 +1,18 @@ package com.sitepark.ies.contentrepository.core.domain.entity; public enum BulkOperationKey { + PURGE_LOCK("contentrepository.purge.lock"), + PURGE_DEPUBLISH("contentrepository.purge.depublish"), + PURGE_PURGE("contentrepository.purge.purge"), + PURGE_CLEANUP("contentrepository.purge.cleanup"); - PURGE_LOCK("contentrepository.purge.lock"), - PURGE_DEPUBLISH("contentrepository.purge.depublish"), - PURGE_PURGE("contentrepository.purge.purge"), - PURGE_CLEANUP("contentrepository.purge.cleanup"); + private final String name; - private final String name; + private BulkOperationKey(String name) { + this.name = name; + } - private BulkOperationKey(String name) { - this.name = name; - } - - public String getName() { - return this.name; - } + public String getName() { + return this.name; + } } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/ChangeSet.java b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/ChangeSet.java index e6d8dc9..9637b90 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/ChangeSet.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/ChangeSet.java @@ -1,7 +1,7 @@ package com.sitepark.ies.contentrepository.core.domain.entity; public class ChangeSet { - public boolean isEmpty() { - return true; - } + public boolean isEmpty() { + return true; + } } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/Entity.java b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/Entity.java index 9908cff..81a1635 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/Entity.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/Entity.java @@ -1,199 +1,202 @@ package com.sitepark.ies.contentrepository.core.domain.entity; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; import java.time.OffsetDateTime; import java.util.Objects; import java.util.Optional; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; - @JsonDeserialize(builder = Entity.EntityBuilder.class) public class Entity { - private final String id; - private final Anchor anchor; - private final String name; - private final String parent; - private final OffsetDateTime version; - private final boolean isGroup; - - protected Entity(Builder builder) { - this.id = builder.id; - this.anchor = builder.anchor; - this.name = builder.name; - this.parent = builder.parent; - this.version = builder.version; - this.isGroup = builder.isGroup; - } - - public Optional getId() { - if (this.id == null) { - return Optional.empty(); - } else { - return Optional.of(this.id); - } - } - - public Optional getAnchor() { - return Optional.ofNullable(this.anchor); - } - - public Optional getName() { - return Optional.ofNullable(this.name); - } - - public Optional getParent() { - if (this.parent == null) { - return Optional.empty(); - } else { - return Optional.of(this.parent); - } - } - - public Optional getVersion() { - if (this.version == null) { - return Optional.empty(); - } else { - return Optional.of(this.version); - } - } - - public boolean isGroup() { - return this.isGroup; - } - - public static Builder builder() { - return new EntityBuilder(); - } - - public Builder toBuilder() { - return new EntityBuilder(this); - } - - @Override - public final int hashCode() { - - return Objects.hash( - this.id, - this.anchor, - this.name, - this.parent, - this.version, - this.isGroup); - } - - @Override - public final boolean equals(Object o) { - - if (!(o instanceof Entity)) { - return false; - } - - Entity that = (Entity)o; - - return Objects.equals(this.id, that.id) && - Objects.equals(this.anchor, that.anchor) && - Objects.equals(this.name, that.name) && - Objects.equals(this.parent, that.parent) && - Objects.equals(this.version, that.version) && - Objects.equals(this.isGroup, that.isGroup); - } - - @Override - public String toString() { - return "Entity [id=" + id + ", anchor=" + anchor + ", name=" + name + ", parent=" + parent + ", version=" - + version + ", isGroup=" + isGroup + "]"; - } - - public static abstract class Builder> { - - private String id; - private Anchor anchor; - private String name; - private String parent; - private OffsetDateTime version; - private boolean isGroup; - - protected Builder() { - } - - protected Builder(Entity entity) { - this.id = entity.id; - this.anchor = entity.anchor; - this.name = entity.name; - this.parent = entity.parent; - this.version = entity.version; - this.isGroup = entity.isGroup; - } - - public B id(String id) { - Objects.requireNonNull(id, "id is null"); - if (!Identifier.isId(id)) { - throw new IllegalArgumentException(id + " is not an id"); - } - this.id = id; - return this.self(); - } - - public B anchor(String anchor) { - Objects.requireNonNull(anchor, "anchor is null"); - this.anchor = Anchor.ofString(anchor); - return this.self(); - } - - public B anchor(Anchor anchor) { - Objects.requireNonNull(anchor, "anchor is null"); - this.anchor = anchor; - return this.self(); - } - - public B name(String name) { - Objects.requireNonNull(name, "name is null"); - if (name.isBlank()) { - throw new IllegalArgumentException("name is blank"); - } - this.name = name; - return this.self(); - } - - public B parent(String parent) { - Objects.requireNonNull(parent, "parent is null"); - if (!Identifier.isId(parent)) { - throw new IllegalArgumentException(parent + " is not an id"); - } - this.parent = parent; - return this.self(); - } - - public B version(OffsetDateTime version) { - Objects.requireNonNull(version, "version is null"); - this.version = version; - return this.self(); - } - - public B isGroup(boolean isGroup) { - this.isGroup = isGroup; - return this.self(); - } - - protected abstract B self(); - - public Entity build() { - return new Entity(this); - } - } - - @JsonPOJOBuilder(withPrefix = "", buildMethodName = "build") - protected static class EntityBuilder extends Builder { - protected EntityBuilder() {} - - protected EntityBuilder(Entity entity) { - super(entity); - } - - @Override - protected EntityBuilder self() { - return this; - } - } + private final String id; + private final Anchor anchor; + private final String name; + private final String parent; + private final OffsetDateTime version; + private final boolean isGroup; + + protected Entity(Builder builder) { + this.id = builder.id; + this.anchor = builder.anchor; + this.name = builder.name; + this.parent = builder.parent; + this.version = builder.version; + this.isGroup = builder.isGroup; + } + + public Optional getId() { + if (this.id == null) { + return Optional.empty(); + } else { + return Optional.of(this.id); + } + } + + public Optional getAnchor() { + return Optional.ofNullable(this.anchor); + } + + public Optional getName() { + return Optional.ofNullable(this.name); + } + + public Optional getParent() { + if (this.parent == null) { + return Optional.empty(); + } else { + return Optional.of(this.parent); + } + } + + public Optional getVersion() { + if (this.version == null) { + return Optional.empty(); + } else { + return Optional.of(this.version); + } + } + + public boolean isGroup() { + return this.isGroup; + } + + public static Builder builder() { + return new EntityBuilder(); + } + + public Builder toBuilder() { + return new EntityBuilder(this); + } + + @Override + public final int hashCode() { + + return Objects.hash(this.id, this.anchor, this.name, this.parent, this.version, this.isGroup); + } + + @Override + public final boolean equals(Object o) { + + if (!(o instanceof Entity)) { + return false; + } + + Entity that = (Entity) o; + + return Objects.equals(this.id, that.id) + && Objects.equals(this.anchor, that.anchor) + && Objects.equals(this.name, that.name) + && Objects.equals(this.parent, that.parent) + && Objects.equals(this.version, that.version) + && Objects.equals(this.isGroup, that.isGroup); + } + + @Override + public String toString() { + return "Entity [id=" + + id + + ", anchor=" + + anchor + + ", name=" + + name + + ", parent=" + + parent + + ", version=" + + version + + ", isGroup=" + + isGroup + + "]"; + } + + public abstract static class Builder> { + + private String id; + private Anchor anchor; + private String name; + private String parent; + private OffsetDateTime version; + private boolean isGroup; + + protected Builder() {} + + protected Builder(Entity entity) { + this.id = entity.id; + this.anchor = entity.anchor; + this.name = entity.name; + this.parent = entity.parent; + this.version = entity.version; + this.isGroup = entity.isGroup; + } + + public B id(String id) { + Objects.requireNonNull(id, "id is null"); + if (!Identifier.isId(id)) { + throw new IllegalArgumentException(id + " is not an id"); + } + this.id = id; + return this.self(); + } + + public B anchor(String anchor) { + Objects.requireNonNull(anchor, "anchor is null"); + this.anchor = Anchor.ofString(anchor); + return this.self(); + } + + public B anchor(Anchor anchor) { + Objects.requireNonNull(anchor, "anchor is null"); + this.anchor = anchor; + return this.self(); + } + + public B name(String name) { + Objects.requireNonNull(name, "name is null"); + if (name.isBlank()) { + throw new IllegalArgumentException("name is blank"); + } + this.name = name; + return this.self(); + } + + public B parent(String parent) { + Objects.requireNonNull(parent, "parent is null"); + if (!Identifier.isId(parent)) { + throw new IllegalArgumentException(parent + " is not an id"); + } + this.parent = parent; + return this.self(); + } + + public B version(OffsetDateTime version) { + Objects.requireNonNull(version, "version is null"); + this.version = version; + return this.self(); + } + + public B isGroup(boolean isGroup) { + this.isGroup = isGroup; + return this.self(); + } + + protected abstract B self(); + + public Entity build() { + return new Entity(this); + } + } + + @JsonPOJOBuilder(withPrefix = "", buildMethodName = "build") + protected static class EntityBuilder extends Builder { + protected EntityBuilder() {} + + protected EntityBuilder(Entity entity) { + super(entity); + } + + @Override + protected EntityBuilder self() { + return this; + } + } } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/EntityBulkExecution.java b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/EntityBulkExecution.java index 9b5e85a..2632ae8 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/EntityBulkExecution.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/EntityBulkExecution.java @@ -1,5 +1,6 @@ package com.sitepark.ies.contentrepository.core.domain.entity; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -7,128 +8,122 @@ import java.util.Objects; import java.util.Optional; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; - public class EntityBulkExecution { - private final String[] topic; - - private final List operations; - - private final EntityBulkOperation finalizer; - - protected EntityBulkExecution(Builder builder) { - this.topic = builder.topic; - this.operations = Collections.unmodifiableList(builder.operations); - this.finalizer = builder.finalizer; - } - - @SuppressFBWarnings("EI_EXPOSE_REP") - public String[] getTopic() { - return this.topic.clone(); - } - - @SuppressFBWarnings("EI_EXPOSE_REP") - public List getOperations() { - return this.operations; - } - - public Optional getFinalizer() { - return Optional.ofNullable(this.finalizer); - } - - @Override - public final int hashCode() { - return Objects.hash( - Arrays.hashCode(this.topic), - this.operations, - this.finalizer); - } - - - @Override - public final boolean equals(Object o) { - - if (!(o instanceof EntityBulkExecution)) { - return false; - } - - EntityBulkExecution execution = (EntityBulkExecution)o; - - return Arrays.equals(this.topic, execution.topic) && - Objects.equals(this.operations, execution.operations) && - Objects.equals(this.finalizer, execution.finalizer); - } - - @Override - public String toString() { - StringBuilder b = new StringBuilder(100) - .append("EntityBulkExecution[topic:") - .append(Arrays.toString(this.topic)) - .append(", operations:") - .append(this.operations) - .append(", finalizer:") - .append(this.finalizer) - .append(']'); - return b.toString(); - } - - public static Builder builder() { - return new Builder(); - } - - public static class Builder { - - private String[] topic; - - private final List operations = new ArrayList<>(); - - private EntityBulkOperation finalizer; - - protected Builder() { - } - - /** - * Topics are used to display all bulk operations for a specific topic. - * Topics are hierarchical and the path of the topic is specified via - * a string array. Topics are freely definable. - * If e.g. all Topics of level1 are queried, all - * BulkExecutions recursively below level1 are returned. - */ - public Builder topic(String... topic) { - Objects.requireNonNull(topic, "topic is null"); - for (String part : topic) { - Objects.requireNonNull(part, "operations contains null values"); - } - - this.topic = topic.clone(); - return this; - } - - @SuppressWarnings("PMD.UseArraysAsList") - public Builder operation(EntityBulkOperation... operations) { - Objects.requireNonNull(operations, "operations is null"); - for (EntityBulkOperation operation : operations) { - Objects.requireNonNull(operation, "operations contains null values"); - this.operations.add(operation); - } - return this; - } - - public Builder finalizer(EntityBulkOperation finalizer) { - Objects.requireNonNull(finalizer, "finalizer is null"); - this.finalizer = finalizer; - return this; - } - - public EntityBulkExecution build() { - if (this.topic == null) { - throw new IllegalStateException("topic must be set"); - } - if (this.operations.isEmpty()) { - throw new IllegalStateException("operation must be set"); - } - return new EntityBulkExecution(this); - } - } + private final String[] topic; + + private final List operations; + + private final EntityBulkOperation finalizer; + + protected EntityBulkExecution(Builder builder) { + this.topic = builder.topic; + this.operations = Collections.unmodifiableList(builder.operations); + this.finalizer = builder.finalizer; + } + + @SuppressFBWarnings("EI_EXPOSE_REP") + public String[] getTopic() { + return this.topic.clone(); + } + + @SuppressFBWarnings("EI_EXPOSE_REP") + public List getOperations() { + return this.operations; + } + + public Optional getFinalizer() { + return Optional.ofNullable(this.finalizer); + } + + @Override + public final int hashCode() { + return Objects.hash(Arrays.hashCode(this.topic), this.operations, this.finalizer); + } + + @Override + public final boolean equals(Object o) { + + if (!(o instanceof EntityBulkExecution)) { + return false; + } + + EntityBulkExecution execution = (EntityBulkExecution) o; + + return Arrays.equals(this.topic, execution.topic) + && Objects.equals(this.operations, execution.operations) + && Objects.equals(this.finalizer, execution.finalizer); + } + + @Override + public String toString() { + StringBuilder b = + new StringBuilder(100) + .append("EntityBulkExecution[topic:") + .append(Arrays.toString(this.topic)) + .append(", operations:") + .append(this.operations) + .append(", finalizer:") + .append(this.finalizer) + .append(']'); + return b.toString(); + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + + private String[] topic; + + private final List operations = new ArrayList<>(); + + private EntityBulkOperation finalizer; + + protected Builder() {} + + /** + * Topics are used to display all bulk operations for a specific topic. + * Topics are hierarchical and the path of the topic is specified via + * a string array. Topics are freely definable. + * If e.g. all Topics of level1 are queried, all + * BulkExecutions recursively below level1 are returned. + */ + public Builder topic(String... topic) { + Objects.requireNonNull(topic, "topic is null"); + for (String part : topic) { + Objects.requireNonNull(part, "operations contains null values"); + } + + this.topic = topic.clone(); + return this; + } + + @SuppressWarnings("PMD.UseArraysAsList") + public Builder operation(EntityBulkOperation... operations) { + Objects.requireNonNull(operations, "operations is null"); + for (EntityBulkOperation operation : operations) { + Objects.requireNonNull(operation, "operations contains null values"); + this.operations.add(operation); + } + return this; + } + + public Builder finalizer(EntityBulkOperation finalizer) { + Objects.requireNonNull(finalizer, "finalizer is null"); + this.finalizer = finalizer; + return this; + } + + public EntityBulkExecution build() { + if (this.topic == null) { + throw new IllegalStateException("topic must be set"); + } + if (this.operations.isEmpty()) { + throw new IllegalStateException("operation must be set"); + } + return new EntityBulkExecution(this); + } + } } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/EntityBulkOperation.java b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/EntityBulkOperation.java index 46f6dda..0ae87a1 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/EntityBulkOperation.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/EntityBulkOperation.java @@ -1,119 +1,115 @@ package com.sitepark.ies.contentrepository.core.domain.entity; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.function.Consumer; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; - public class EntityBulkOperation { - private final BulkOperationKey key; - - private final List entityList; - - private final Consumer consumer; - - protected EntityBulkOperation(Builder builder) { - this.key = builder.key; - this.entityList = Collections.unmodifiableList(builder.entityList); - this.consumer = builder.consumer; - } - - public BulkOperationKey getKey() { - return this.key; - } - - @SuppressFBWarnings("EI_EXPOSE_REP") - public List getEntityList() { - return this.entityList; - } - - public Consumer getConsumer() { - return this.consumer; - } - - @Override - public final int hashCode() { - return Objects.hash( - this.key, - this.entityList, - this.consumer); - } - - @Override - public final boolean equals(Object o) { - - if (!(o instanceof EntityBulkOperation)) { - return false; - } - - EntityBulkOperation op = (EntityBulkOperation)o; - - return Objects.equals(this.key, op.key) && - Objects.equals(this.entityList, op.entityList) && - Objects.equals(this.consumer, op.consumer); - } - - @Override - public String toString() { - StringBuilder b = new StringBuilder(100) - .append("EntityBulkOperation[key:") - .append(this.key) - .append(", entityList:") - .append(this.entityList) - .append(", consumer:") - .append(this.consumer) - .append(']'); - return b.toString(); - } - - public static Builder builder() { - return new Builder(); - } - - public static class Builder { - - private BulkOperationKey key; - - private final List entityList = new ArrayList<>(); - - private Consumer consumer; - - protected Builder() { - } - - public Builder key(BulkOperationKey key) { - Objects.requireNonNull(key, "key is null"); - this.key = key; - return this; - } - - public Builder entityList(List entityList) { - Objects.requireNonNull(entityList, "entityList is null"); - this.entityList.addAll(entityList); - return this; - } - - public Builder consumer(Consumer consumer) { - Objects.requireNonNull(consumer, "consumer is null"); - this.consumer = consumer; - return this; - } - - public EntityBulkOperation build() { - if (this.key == null) { - throw new IllegalStateException("key must be set"); - } - if (this.entityList.isEmpty()) { - throw new IllegalStateException("entity must be set"); - } - if (this.consumer == null) { - throw new IllegalStateException("consumer must be set"); - } - return new EntityBulkOperation(this); - } - } + private final BulkOperationKey key; + + private final List entityList; + + private final Consumer consumer; + + protected EntityBulkOperation(Builder builder) { + this.key = builder.key; + this.entityList = Collections.unmodifiableList(builder.entityList); + this.consumer = builder.consumer; + } + + public BulkOperationKey getKey() { + return this.key; + } + + @SuppressFBWarnings("EI_EXPOSE_REP") + public List getEntityList() { + return this.entityList; + } + + public Consumer getConsumer() { + return this.consumer; + } + + @Override + public final int hashCode() { + return Objects.hash(this.key, this.entityList, this.consumer); + } + + @Override + public final boolean equals(Object o) { + + if (!(o instanceof EntityBulkOperation)) { + return false; + } + + EntityBulkOperation op = (EntityBulkOperation) o; + + return Objects.equals(this.key, op.key) + && Objects.equals(this.entityList, op.entityList) + && Objects.equals(this.consumer, op.consumer); + } + + @Override + public String toString() { + StringBuilder b = + new StringBuilder(100) + .append("EntityBulkOperation[key:") + .append(this.key) + .append(", entityList:") + .append(this.entityList) + .append(", consumer:") + .append(this.consumer) + .append(']'); + return b.toString(); + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + + private BulkOperationKey key; + + private final List entityList = new ArrayList<>(); + + private Consumer consumer; + + protected Builder() {} + + public Builder key(BulkOperationKey key) { + Objects.requireNonNull(key, "key is null"); + this.key = key; + return this; + } + + public Builder entityList(List entityList) { + Objects.requireNonNull(entityList, "entityList is null"); + this.entityList.addAll(entityList); + return this; + } + + public Builder consumer(Consumer consumer) { + Objects.requireNonNull(consumer, "consumer is null"); + this.consumer = consumer; + return this; + } + + public EntityBulkOperation build() { + if (this.key == null) { + throw new IllegalStateException("key must be set"); + } + if (this.entityList.isEmpty()) { + throw new IllegalStateException("entity must be set"); + } + if (this.consumer == null) { + throw new IllegalStateException("consumer must be set"); + } + return new EntityBulkOperation(this); + } + } } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/EntityLock.java b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/EntityLock.java index 006b9c6..7b58331 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/EntityLock.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/EntityLock.java @@ -6,152 +6,147 @@ public final class EntityLock implements Serializable { - private final String entity; - private final String user; - private final OffsetDateTime created; - private final OffsetDateTime lastAccess; - private final long ttl; - - private static final long serialVersionUID = 1L; - - private EntityLock(Builder builder) { - this.entity = builder.entity; - this.user = builder.user; - this.created = builder.created; - this.lastAccess = builder.lastAccess; - this.ttl = builder.ttl; - } - - public String getEntity() { - return entity; - } - - public String getUser() { - return user; - } - - public OffsetDateTime getCreated() { - return created; - } - - public OffsetDateTime getLastAccess() { - return lastAccess; - } - - public long getTtl() { - return ttl; - } - - @Override - public final int hashCode() { - return Objects.hash( - this.entity, - this.user, - this.created, - this.lastAccess, - this.ttl); - } - - @Override - public final boolean equals(Object o) { - - if (!(o instanceof EntityLock)) { - return false; - } - - EntityLock lock = (EntityLock)o; - - return Objects.equals(this.entity, lock.entity) && - Objects.equals(this.user, lock.user) && - Objects.equals(this.created, lock.created) && - Objects.equals(this.lastAccess, lock.lastAccess) && - Objects.equals(this.ttl, lock.ttl); - } - - public static Builder builder() { - return new Builder(); - } - - public Builder toBuilder() { - return new Builder(this); - } - - @Override - public String toString() { - StringBuilder b = new StringBuilder(100) - .append("EntityLock[entity:") - .append(this.entity) - .append(", user:") - .append(this.user) - .append(", created:") - .append(this.created) - .append(", lastAccess:") - .append(this.lastAccess) - .append(", ttl:") - .append(this.ttl) - .append(']'); - return b.toString(); - } - - public static class Builder { - - private String entity; - private String user; - private OffsetDateTime created; - private OffsetDateTime lastAccess; - private long ttl; - - protected Builder() { - } - - protected Builder(EntityLock entityLock) { - this.entity = entityLock.entity; - this.user = entityLock.user; - this.created = entityLock.created; - this.lastAccess = entityLock.lastAccess; - this.ttl = entityLock.ttl; - } - - public Builder entity(String entity) { - Objects.requireNonNull(entity, "entity is null"); - if (!Identifier.isId(entity)) { - throw new IllegalArgumentException(entity + " is not an id"); - } - this.entity = entity; - return this; - } - - public Builder user(String user) { - Objects.requireNonNull(user, "user is null"); - if (!Identifier.isId(user)) { - throw new IllegalArgumentException(user + " is not an id"); - } - this.user = user; - return this; - } - - public Builder created(OffsetDateTime created) { - Objects.requireNonNull(created, "created is null"); - this.created = created; - return this; - } - - public Builder lastAccess(OffsetDateTime lastAccess) { - Objects.requireNonNull(lastAccess, "lastAccess is null"); - this.lastAccess = lastAccess; - return this; - } - - public Builder ttl(long ttl) { - if (ttl <= 0) { - throw new IllegalArgumentException("ttl should be greater then 0"); - } - this.ttl = ttl; - return this; - } - - public EntityLock build() { - return new EntityLock(this); - } - } + private final String entity; + private final String user; + private final OffsetDateTime created; + private final OffsetDateTime lastAccess; + private final long ttl; + + private static final long serialVersionUID = 1L; + + private EntityLock(Builder builder) { + this.entity = builder.entity; + this.user = builder.user; + this.created = builder.created; + this.lastAccess = builder.lastAccess; + this.ttl = builder.ttl; + } + + public String getEntity() { + return entity; + } + + public String getUser() { + return user; + } + + public OffsetDateTime getCreated() { + return created; + } + + public OffsetDateTime getLastAccess() { + return lastAccess; + } + + public long getTtl() { + return ttl; + } + + @Override + public final int hashCode() { + return Objects.hash(this.entity, this.user, this.created, this.lastAccess, this.ttl); + } + + @Override + public final boolean equals(Object o) { + + if (!(o instanceof EntityLock)) { + return false; + } + + EntityLock lock = (EntityLock) o; + + return Objects.equals(this.entity, lock.entity) + && Objects.equals(this.user, lock.user) + && Objects.equals(this.created, lock.created) + && Objects.equals(this.lastAccess, lock.lastAccess) + && Objects.equals(this.ttl, lock.ttl); + } + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder(this); + } + + @Override + public String toString() { + StringBuilder b = + new StringBuilder(100) + .append("EntityLock[entity:") + .append(this.entity) + .append(", user:") + .append(this.user) + .append(", created:") + .append(this.created) + .append(", lastAccess:") + .append(this.lastAccess) + .append(", ttl:") + .append(this.ttl) + .append(']'); + return b.toString(); + } + + public static class Builder { + + private String entity; + private String user; + private OffsetDateTime created; + private OffsetDateTime lastAccess; + private long ttl; + + protected Builder() {} + + protected Builder(EntityLock entityLock) { + this.entity = entityLock.entity; + this.user = entityLock.user; + this.created = entityLock.created; + this.lastAccess = entityLock.lastAccess; + this.ttl = entityLock.ttl; + } + + public Builder entity(String entity) { + Objects.requireNonNull(entity, "entity is null"); + if (!Identifier.isId(entity)) { + throw new IllegalArgumentException(entity + " is not an id"); + } + this.entity = entity; + return this; + } + + public Builder user(String user) { + Objects.requireNonNull(user, "user is null"); + if (!Identifier.isId(user)) { + throw new IllegalArgumentException(user + " is not an id"); + } + this.user = user; + return this; + } + + public Builder created(OffsetDateTime created) { + Objects.requireNonNull(created, "created is null"); + this.created = created; + return this; + } + + public Builder lastAccess(OffsetDateTime lastAccess) { + Objects.requireNonNull(lastAccess, "lastAccess is null"); + this.lastAccess = lastAccess; + return this; + } + + public Builder ttl(long ttl) { + if (ttl <= 0) { + throw new IllegalArgumentException("ttl should be greater then 0"); + } + this.ttl = ttl; + return this; + } + + public EntityLock build() { + return new EntityLock(this); + } + } } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/EntityTree.java b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/EntityTree.java index b37576c..055298f 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/EntityTree.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/EntityTree.java @@ -9,162 +9,156 @@ import java.util.Set; import java.util.stream.Collectors; - @SuppressWarnings("PMD.UseConcurrentHashMap") public class EntityTree { - private final Map> children = new HashMap<>(); - - private final Map parents = new HashMap<>(); - - private final Map index = new HashMap<>(); - - /** - * Returns all roots of the tree. - * - * Roots are all entries without a parent - */ - public List getRoots() { - return this.getRootIdList().stream() - .map(id -> { - Entity entity = this.index.get(id); - if (entity == null) { - throw new IllegalStateException("Entity with id " + id + " missing"); - } - return entity; - }) - .collect(Collectors.toList()); - } - - private Set getRootIdList() { - Set knownRoots = this.children.get(null); - Set roots = new HashSet<>(); - if (knownRoots != null) { - roots.addAll(knownRoots); - } - for (String parent : this.parents.values()) { - if (parent != null && !this.parents.containsKey(parent)) { - roots.add(parent); - } - } - return roots; - } - - /** - * Places an element in the tree. - * - * If no parent present, it is set as root element. - */ - public void add(Entity entity) { - - if (entity == null) { - return; - } - - this.parents.put(entity.getId().get(), entity.getParent().orElse(null)); - Set siblings = this.children.get(entity.getParent().orElse(null)); - if (siblings == null) { - siblings = new HashSet<>(); - this.children.put(entity.getParent().orElse(null), siblings); - } - siblings.add(entity.getId().get()); - this.index.put(entity.getId().get(), entity); - } - - public Entity get(String id) { - return this.index.get(id); - } - - public List getChildren(String parent) { - Set children = this.children.get(parent); - return children.stream() - .map(id -> this.index.get(id)) - .collect(Collectors.toList()); - } - - /** - * Liefert die Unterelemente des Parent rekusive. - */ - public List getChildrenRecursive(String root) { - Set children = this.getChildrenIdListRecursive(root); - return children.stream() - .map(id -> this.index.get(id)) - .collect(Collectors.toList()); - } - - private Set getChildrenIdListRecursive(String root) { - Set list = new LinkedHashSet<>(); - Set children = this.children.get(root); - if (children != null) { - list.addAll(children); - for (String id : children) { - Set grandChildren = this.getChildrenIdListRecursive(id); - list.addAll(grandChildren); - } - } - - return list; - } - - /** - * Returns all elements of the tree in hierarchical order - */ - public List getAll() { - Set rootIdList = this.getRootIdList(); - List list = new ArrayList<>(); - for (String rootId : rootIdList) { - Entity root = this.index.get(rootId); - if (root == null) { - throw new IllegalStateException("Entity with id " + rootId + " missing"); - } - list.add(root); - List childrenOrRoot = this.getChildrenRecursive(rootId); - list.addAll(childrenOrRoot); - } - return list; - } - - public boolean hasChildren(String parent) { - return this.children.containsKey(parent); - } - - @Override - public String toString() { - return this.toString(0); - } - - public String toString(int indent) { - return this.toString(indent, null); - } - - public String toString(int indent, String parent) { - java.lang.StringBuilder b = new java.lang.StringBuilder(); - this.toString(indent, parent, new java.lang.StringBuilder(), b); - return b.toString(); - } - - private void toString(int indent, String parent, java.lang.StringBuilder indentPrefix, - java.lang.StringBuilder b) { - - if (parent == null) { - Set roots = this.getRootIdList(); - for (String child : roots) { - this.toString(indent, child, indentPrefix, b); - } - } else { - b.append(indentPrefix.toString()) - .append(this.index.get(parent)) - .append('\n'); - - if (this.hasChildren(parent)) { - for (int i = 0; i < indent; i++) { - indentPrefix.append(' '); - } - for (String child : this.children.get(parent)) { - this.toString(indent, child, indentPrefix, b); - } - indentPrefix.delete(indentPrefix.length() - indent, indentPrefix.length()); - } - } - } + private final Map> children = new HashMap<>(); + + private final Map parents = new HashMap<>(); + + private final Map index = new HashMap<>(); + + /** + * Returns all roots of the tree. + * + * Roots are all entries without a parent + */ + public List getRoots() { + return this.getRootIdList().stream() + .map( + id -> { + Entity entity = this.index.get(id); + if (entity == null) { + throw new IllegalStateException("Entity with id " + id + " missing"); + } + return entity; + }) + .collect(Collectors.toList()); + } + + private Set getRootIdList() { + Set knownRoots = this.children.get(null); + Set roots = new HashSet<>(); + if (knownRoots != null) { + roots.addAll(knownRoots); + } + for (String parent : this.parents.values()) { + if (parent != null && !this.parents.containsKey(parent)) { + roots.add(parent); + } + } + return roots; + } + + /** + * Places an element in the tree. + * + * If no parent present, it is set as root element. + */ + public void add(Entity entity) { + + if (entity == null) { + return; + } + + this.parents.put(entity.getId().get(), entity.getParent().orElse(null)); + Set siblings = this.children.get(entity.getParent().orElse(null)); + if (siblings == null) { + siblings = new HashSet<>(); + this.children.put(entity.getParent().orElse(null), siblings); + } + siblings.add(entity.getId().get()); + this.index.put(entity.getId().get(), entity); + } + + public Entity get(String id) { + return this.index.get(id); + } + + public List getChildren(String parent) { + Set children = this.children.get(parent); + return children.stream().map(id -> this.index.get(id)).collect(Collectors.toList()); + } + + /** + * Liefert die Unterelemente des Parent rekusive. + */ + public List getChildrenRecursive(String root) { + Set children = this.getChildrenIdListRecursive(root); + return children.stream().map(id -> this.index.get(id)).collect(Collectors.toList()); + } + + private Set getChildrenIdListRecursive(String root) { + Set list = new LinkedHashSet<>(); + Set children = this.children.get(root); + if (children != null) { + list.addAll(children); + for (String id : children) { + Set grandChildren = this.getChildrenIdListRecursive(id); + list.addAll(grandChildren); + } + } + + return list; + } + + /** + * Returns all elements of the tree in hierarchical order + */ + public List getAll() { + Set rootIdList = this.getRootIdList(); + List list = new ArrayList<>(); + for (String rootId : rootIdList) { + Entity root = this.index.get(rootId); + if (root == null) { + throw new IllegalStateException("Entity with id " + rootId + " missing"); + } + list.add(root); + List childrenOrRoot = this.getChildrenRecursive(rootId); + list.addAll(childrenOrRoot); + } + return list; + } + + public boolean hasChildren(String parent) { + return this.children.containsKey(parent); + } + + @Override + public String toString() { + return this.toString(0); + } + + public String toString(int indent) { + return this.toString(indent, null); + } + + public String toString(int indent, String parent) { + java.lang.StringBuilder b = new java.lang.StringBuilder(); + this.toString(indent, parent, new java.lang.StringBuilder(), b); + return b.toString(); + } + + private void toString( + int indent, String parent, java.lang.StringBuilder indentPrefix, java.lang.StringBuilder b) { + + if (parent == null) { + Set roots = this.getRootIdList(); + for (String child : roots) { + this.toString(indent, child, indentPrefix, b); + } + } else { + b.append(indentPrefix.toString()).append(this.index.get(parent)).append('\n'); + + if (this.hasChildren(parent)) { + for (int i = 0; i < indent; i++) { + indentPrefix.append(' '); + } + for (String child : this.children.get(parent)) { + this.toString(indent, child, indentPrefix, b); + } + indentPrefix.delete(indentPrefix.length() - indent, indentPrefix.length()); + } + } + } } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/HistoryEntry.java b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/HistoryEntry.java index 7739dee..aaecbb8 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/HistoryEntry.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/HistoryEntry.java @@ -6,168 +6,164 @@ public final class HistoryEntry implements Serializable { - private final long entity; - private final String initiator; - private final Long user; - private final long timestamp; - private final HistoryEntryType type; - private final String comment; - - private static final long serialVersionUID = 1L; - - private HistoryEntry(Builder builder) { - this.entity = builder.entity; - this.initiator = builder.initiator; - this.user = builder.user; - this.timestamp = builder.timestamp; - this.type = builder.type; - this.comment = builder.comment; - } - - public long getEntity() { - return entity; - } - - /** - * The initiator can be a user of a system-service or other subjects who - * could authenticate themselves to work with the system. - */ - public String getInitiator() { - return initiator; - } - - /** - * If the initiator is a user of the IES, this returns the ID of the user. - */ - public Optional getUser() { - return Optional.ofNullable(this.user); - } - - public long getTimestamp() { - return timestamp; - } - - public HistoryEntryType getType() { - return type; - } - - public String getComment() { - return comment; - } - - @Override - public final int hashCode() { - return Objects.hash( - this.entity, - this.initiator, - this.user, - this.timestamp, - this.type, - this.comment); - } - - @Override - public final boolean equals(Object o) { - - if (!(o instanceof HistoryEntry)) { - return false; - } - - HistoryEntry entry = (HistoryEntry)o; - - return Objects.equals(this.entity, entry.entity) && - Objects.equals(this.initiator, entry.initiator) && - Objects.equals(this.user, entry.user) && - Objects.equals(this.timestamp, entry.timestamp) && - Objects.equals(this.type, entry.type) && - Objects.equals(this.comment, entry.comment); - } - - @Override - public String toString() { - StringBuilder b = new StringBuilder(100) - .append("HistoryEntry[entity:") - .append(this.entity) - .append(", initiator:") - .append(this.initiator) - .append(", user:") - .append(this.user) - .append(", timestamp:") - .append(this.timestamp) - .append(", type:") - .append(this.type) - .append(", comment:") - .append(this.comment) - .append(']'); - return b.toString(); - } - - public static Builder builder() { - return new Builder(); - } - - public Builder toBuilder() { - return new Builder(this); - } - - public static final class Builder { - - private long entity; - private String initiator; - private Long user; - private long timestamp; - private HistoryEntryType type; - private String comment; - - private Builder() { } - - private Builder(HistoryEntry historyEntry) { - this.entity = historyEntry.entity; - this.initiator = historyEntry.initiator; - this.user = historyEntry.user; - this.timestamp = historyEntry.timestamp; - this.type = historyEntry.type; - this.comment = historyEntry.comment; - } - - public Builder entity(long entity) { - this.entity = entity; - return this; - } - - public Builder initiator(String initiator) { - Objects.requireNonNull(initiator, "initiator is null"); - this.initiator = initiator; - return this; - } - - public Builder user(Long user) { - this.user = user; - return this; - } - - public Builder timestamp(long timestamp) { - if (timestamp <= 0) { - throw new IllegalArgumentException("timestamp must be greater than 0"); - } - this.timestamp = timestamp; - return this; - } - - public Builder type(HistoryEntryType type) { - Objects.requireNonNull(type, "type is null"); - this.type = type; - return this; - } - - public Builder comment(String comment) { - Objects.requireNonNull(comment, "comment is null"); - this.comment = comment; - return this; - } - - public HistoryEntry build() { - return new HistoryEntry(this); - } - } -} \ No newline at end of file + private final long entity; + private final String initiator; + private final Long user; + private final long timestamp; + private final HistoryEntryType type; + private final String comment; + + private static final long serialVersionUID = 1L; + + private HistoryEntry(Builder builder) { + this.entity = builder.entity; + this.initiator = builder.initiator; + this.user = builder.user; + this.timestamp = builder.timestamp; + this.type = builder.type; + this.comment = builder.comment; + } + + public long getEntity() { + return entity; + } + + /** + * The initiator can be a user of a system-service or other subjects who + * could authenticate themselves to work with the system. + */ + public String getInitiator() { + return initiator; + } + + /** + * If the initiator is a user of the IES, this returns the ID of the user. + */ + public Optional getUser() { + return Optional.ofNullable(this.user); + } + + public long getTimestamp() { + return timestamp; + } + + public HistoryEntryType getType() { + return type; + } + + public String getComment() { + return comment; + } + + @Override + public final int hashCode() { + return Objects.hash( + this.entity, this.initiator, this.user, this.timestamp, this.type, this.comment); + } + + @Override + public final boolean equals(Object o) { + + if (!(o instanceof HistoryEntry)) { + return false; + } + + HistoryEntry entry = (HistoryEntry) o; + + return Objects.equals(this.entity, entry.entity) + && Objects.equals(this.initiator, entry.initiator) + && Objects.equals(this.user, entry.user) + && Objects.equals(this.timestamp, entry.timestamp) + && Objects.equals(this.type, entry.type) + && Objects.equals(this.comment, entry.comment); + } + + @Override + public String toString() { + StringBuilder b = + new StringBuilder(100) + .append("HistoryEntry[entity:") + .append(this.entity) + .append(", initiator:") + .append(this.initiator) + .append(", user:") + .append(this.user) + .append(", timestamp:") + .append(this.timestamp) + .append(", type:") + .append(this.type) + .append(", comment:") + .append(this.comment) + .append(']'); + return b.toString(); + } + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder(this); + } + + public static final class Builder { + + private long entity; + private String initiator; + private Long user; + private long timestamp; + private HistoryEntryType type; + private String comment; + + private Builder() {} + + private Builder(HistoryEntry historyEntry) { + this.entity = historyEntry.entity; + this.initiator = historyEntry.initiator; + this.user = historyEntry.user; + this.timestamp = historyEntry.timestamp; + this.type = historyEntry.type; + this.comment = historyEntry.comment; + } + + public Builder entity(long entity) { + this.entity = entity; + return this; + } + + public Builder initiator(String initiator) { + Objects.requireNonNull(initiator, "initiator is null"); + this.initiator = initiator; + return this; + } + + public Builder user(Long user) { + this.user = user; + return this; + } + + public Builder timestamp(long timestamp) { + if (timestamp <= 0) { + throw new IllegalArgumentException("timestamp must be greater than 0"); + } + this.timestamp = timestamp; + return this; + } + + public Builder type(HistoryEntryType type) { + Objects.requireNonNull(type, "type is null"); + this.type = type; + return this; + } + + public Builder comment(String comment) { + Objects.requireNonNull(comment, "comment is null"); + this.comment = comment; + return this; + } + + public HistoryEntry build() { + return new HistoryEntry(this); + } + } +} diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/HistoryEntryType.java b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/HistoryEntryType.java index 2995e81..4362c62 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/HistoryEntryType.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/HistoryEntryType.java @@ -1,9 +1,9 @@ package com.sitepark.ies.contentrepository.core.domain.entity; public enum HistoryEntryType { - CREATED, - UPDATED, - MOVED, - REMOVED, - RESTORED + CREATED, + UPDATED, + MOVED, + REMOVED, + RESTORED } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/Identifier.java b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/Identifier.java index 2bceb2d..4841dab 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/Identifier.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/Identifier.java @@ -1,103 +1,99 @@ package com.sitepark.ies.contentrepository.core.domain.entity; +import com.fasterxml.jackson.annotation.JsonCreator; import java.util.Objects; import java.util.Optional; -import com.fasterxml.jackson.annotation.JsonCreator; - public final class Identifier { - private static final int MAX_ID_LENGTH = 19; - - private static final String ZERO_ID = "0"; - - private final String id; - - private final Anchor anchor; - - private Identifier(String id) { - this.id = id; - this.anchor = null; - } - - private Identifier(Anchor anchor) { - this.id = null; - this.anchor = anchor; - } - - public static Identifier ofId(String id) { - return new Identifier(id); - } - - public static Identifier ofAnchor(Anchor anchor) { - Objects.requireNonNull(anchor, "anchor is null"); - return new Identifier(anchor); - } - - @JsonCreator - public static Identifier ofString(String identifier) { - Objects.requireNonNull(identifier, "identifier is null"); - if (identifier.isBlank()) { - throw new IllegalArgumentException("identifier is blank"); - } - if (isId(identifier)) { - return new Identifier(identifier); - } - return new Identifier(Anchor.ofString(identifier)); - } - - public Optional getId() { - return Optional.ofNullable(this.id); - } - - public Optional getAnchor() { - return Optional.ofNullable(this.anchor); - } - - public static boolean isId(String str) { - - if (ZERO_ID.equals(str)) { - throw new IllegalArgumentException("id should be greater than 0"); - } - - int length = str.length(); - if (length > MAX_ID_LENGTH) { - return false; - } - - for (int i = 0; i < length; i++) { - char c = str.charAt(i); - if (c < '0' || c > '9') { - return false; - } - } - return true; - } - - @Override - public int hashCode() { - return Objects.hash(this.id, this.anchor); - } - - - @Override - public boolean equals(Object o) { - - if (!(o instanceof Identifier)) { - return false; - } - - Identifier that = (Identifier)o; - return - Objects.equals(this.id, that.id) && - Objects.equals(this.anchor, that.anchor); - } - - @Override - public String toString() { - if (this.id != null) { - return this.id; - } - return this.anchor.toString(); - } + private static final int MAX_ID_LENGTH = 19; + + private static final String ZERO_ID = "0"; + + private final String id; + + private final Anchor anchor; + + private Identifier(String id) { + this.id = id; + this.anchor = null; + } + + private Identifier(Anchor anchor) { + this.id = null; + this.anchor = anchor; + } + + public static Identifier ofId(String id) { + return new Identifier(id); + } + + public static Identifier ofAnchor(Anchor anchor) { + Objects.requireNonNull(anchor, "anchor is null"); + return new Identifier(anchor); + } + + @JsonCreator + public static Identifier ofString(String identifier) { + Objects.requireNonNull(identifier, "identifier is null"); + if (identifier.isBlank()) { + throw new IllegalArgumentException("identifier is blank"); + } + if (isId(identifier)) { + return new Identifier(identifier); + } + return new Identifier(Anchor.ofString(identifier)); + } + + public Optional getId() { + return Optional.ofNullable(this.id); + } + + public Optional getAnchor() { + return Optional.ofNullable(this.anchor); + } + + public static boolean isId(String str) { + + if (ZERO_ID.equals(str)) { + throw new IllegalArgumentException("id should be greater than 0"); + } + + int length = str.length(); + if (length > MAX_ID_LENGTH) { + return false; + } + + for (int i = 0; i < length; i++) { + char c = str.charAt(i); + if (c < '0' || c > '9') { + return false; + } + } + return true; + } + + @Override + public int hashCode() { + return Objects.hash(this.id, this.anchor); + } + + @Override + public boolean equals(Object o) { + + if (!(o instanceof Identifier)) { + return false; + } + + Identifier that = (Identifier) o; + return Objects.equals(this.id, that.id) && Objects.equals(this.anchor, that.anchor); + } + + @Override + public String toString() { + if (this.id != null) { + return this.id; + } + return this.anchor.toString(); + } } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/MediaReference.java b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/MediaReference.java index fef465b..45a9ba6 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/MediaReference.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/MediaReference.java @@ -4,90 +4,89 @@ public class MediaReference { - private final String mediaId; - final String usedBy; - private final MediaReferenceType type; - - protected MediaReference(Builder builder) { - this.mediaId = builder.mediaId; - this.usedBy = builder.usedBy; - this.type = builder.type; - } - - public String getMediaId() { - return this.mediaId; - } - - public String getUsedBy() { - return this.usedBy; - } - - public MediaReferenceType getType() { - return this.type; - } - - @Override - public final int hashCode() { - return Objects.hash( - this.mediaId, - this.usedBy, - this.type); - } - - @Override - public final boolean equals(Object o) { - - if (!(o instanceof MediaReference)) { - return false; - } - - MediaReference ref = (MediaReference)o; - - return Objects.equals(this.mediaId, ref.mediaId) && - Objects.equals(this.usedBy, ref.usedBy) && - Objects.equals(this.type, ref.type); - } - - public static Builder builder() { - return new Builder(); - } - - public Builder toBuilder() { - return new Builder(this); - } - - public static class Builder { - - private String mediaId; - private String usedBy; - private MediaReferenceType type; - - protected Builder() {} - - protected Builder(MediaReference media) { - this.mediaId = media.mediaId; - this.usedBy = media.usedBy; - this.type = media.type; - } - - public Builder mediaId(String mediaId) { - Objects.requireNonNull(mediaId, "mediaId is null"); - this.mediaId = mediaId; - return this; - } - - public Builder usedBy(String usedBy) { - Objects.requireNonNull(usedBy, "usedBy is null"); - this.usedBy = usedBy; - return this; - } - public Builder type(MediaReferenceType type) { - Objects.requireNonNull(type, "type is null"); - this.type = type; - return this; - } - public MediaReference build() { - return new MediaReference(this); - } - } + private final String mediaId; + final String usedBy; + private final MediaReferenceType type; + + protected MediaReference(Builder builder) { + this.mediaId = builder.mediaId; + this.usedBy = builder.usedBy; + this.type = builder.type; + } + + public String getMediaId() { + return this.mediaId; + } + + public String getUsedBy() { + return this.usedBy; + } + + public MediaReferenceType getType() { + return this.type; + } + + @Override + public final int hashCode() { + return Objects.hash(this.mediaId, this.usedBy, this.type); + } + + @Override + public final boolean equals(Object o) { + + if (!(o instanceof MediaReference)) { + return false; + } + + MediaReference ref = (MediaReference) o; + + return Objects.equals(this.mediaId, ref.mediaId) + && Objects.equals(this.usedBy, ref.usedBy) + && Objects.equals(this.type, ref.type); + } + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder(this); + } + + public static class Builder { + + private String mediaId; + private String usedBy; + private MediaReferenceType type; + + protected Builder() {} + + protected Builder(MediaReference media) { + this.mediaId = media.mediaId; + this.usedBy = media.usedBy; + this.type = media.type; + } + + public Builder mediaId(String mediaId) { + Objects.requireNonNull(mediaId, "mediaId is null"); + this.mediaId = mediaId; + return this; + } + + public Builder usedBy(String usedBy) { + Objects.requireNonNull(usedBy, "usedBy is null"); + this.usedBy = usedBy; + return this; + } + + public Builder type(MediaReferenceType type) { + Objects.requireNonNull(type, "type is null"); + this.type = type; + return this; + } + + public MediaReference build() { + return new MediaReference(this); + } + } } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/MediaReferenceType.java b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/MediaReferenceType.java index a679115..5f3920f 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/MediaReferenceType.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/MediaReferenceType.java @@ -1,5 +1,5 @@ package com.sitepark.ies.contentrepository.core.domain.entity; public enum MediaReferenceType { - EMBEDDED + EMBEDDED } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/RecycleBinItem.java b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/RecycleBinItem.java index 060b349..4f70262 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/RecycleBinItem.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/RecycleBinItem.java @@ -7,125 +7,129 @@ public final class RecycleBinItem { - private final String id; - private final String parent; - private final Entity entity; - private final List children; - - private RecycleBinItem(Builder builder) { - this.id = builder.id; - this.parent = builder.parent; - this.entity = builder.entity; - this.children = builder.children; - } - - public String getId() { - return this.id; - } - - public String getParent() { - return this.parent; - } - - public Entity getEntity() { - return this.entity; - } - - public List getChildren() { - return Collections.unmodifiableList(this.children); - } - - @Override - public final int hashCode() { - return Objects.hash( - this.id, - this.parent, - this.entity, - this.children); - } - - @Override - public final boolean equals(Object o) { - - if (!(o instanceof RecycleBinItem)) { - return false; - } - - RecycleBinItem item = (RecycleBinItem)o; - - return Objects.equals(this.id, item.id) && - Objects.equals(this.parent, item.parent) && - Objects.equals(this.entity, item.entity) && - Objects.equals(this.children, item.children); - } - - @Override - public String toString() { - return "RecycleBinItem [id=" + id + ", parent=" + parent + ", entity=" + entity + ", children=" + children - + "]"; - } - - public static Builder builder() { - return new Builder(); - } - - public Builder toBuilder() { - return new Builder(this); - } - - public static final class Builder { - - private String id; - private String parent; - private Entity entity; - private List children = new ArrayList<>(); - - private Builder() {} - private Builder(RecycleBinItem recycleBinItem) { - this.id = recycleBinItem.id; - this.parent = recycleBinItem.parent; - this.entity = recycleBinItem.entity; - this.children = new ArrayList<>(recycleBinItem.children); - } - - public Builder id(String id) { - Objects.requireNonNull(id, "id is null"); - if (!Identifier.isId(id)) { - throw new IllegalArgumentException(id + " is not an id"); - } - this.id = id; - return this; - } - - public Builder parent(String parent) { - Objects.requireNonNull(parent, "parent is null"); - if (!Identifier.isId(parent)) { - throw new IllegalArgumentException(parent + " is not an id"); - } - this.parent = parent; - return this; - } - - public Builder entity(Entity entity) { - Objects.requireNonNull(entity, "entity is null"); - this.entity = entity; - return this; - } - - public Builder children(List children) { - Objects.requireNonNull(children, "children is null"); - this.children = new ArrayList<>(children); - return this; - } - - public Builder child(RecycleBinItem child) { - Objects.requireNonNull(child, "child is null"); - this.children.add(child); - return this; - } - - public RecycleBinItem build() { - return new RecycleBinItem(this); - } - } -} \ No newline at end of file + private final String id; + private final String parent; + private final Entity entity; + private final List children; + + private RecycleBinItem(Builder builder) { + this.id = builder.id; + this.parent = builder.parent; + this.entity = builder.entity; + this.children = builder.children; + } + + public String getId() { + return this.id; + } + + public String getParent() { + return this.parent; + } + + public Entity getEntity() { + return this.entity; + } + + public List getChildren() { + return Collections.unmodifiableList(this.children); + } + + @Override + public final int hashCode() { + return Objects.hash(this.id, this.parent, this.entity, this.children); + } + + @Override + public final boolean equals(Object o) { + + if (!(o instanceof RecycleBinItem)) { + return false; + } + + RecycleBinItem item = (RecycleBinItem) o; + + return Objects.equals(this.id, item.id) + && Objects.equals(this.parent, item.parent) + && Objects.equals(this.entity, item.entity) + && Objects.equals(this.children, item.children); + } + + @Override + public String toString() { + return "RecycleBinItem [id=" + + id + + ", parent=" + + parent + + ", entity=" + + entity + + ", children=" + + children + + "]"; + } + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder(this); + } + + public static final class Builder { + + private String id; + private String parent; + private Entity entity; + private List children = new ArrayList<>(); + + private Builder() {} + + private Builder(RecycleBinItem recycleBinItem) { + this.id = recycleBinItem.id; + this.parent = recycleBinItem.parent; + this.entity = recycleBinItem.entity; + this.children = new ArrayList<>(recycleBinItem.children); + } + + public Builder id(String id) { + Objects.requireNonNull(id, "id is null"); + if (!Identifier.isId(id)) { + throw new IllegalArgumentException(id + " is not an id"); + } + this.id = id; + return this; + } + + public Builder parent(String parent) { + Objects.requireNonNull(parent, "parent is null"); + if (!Identifier.isId(parent)) { + throw new IllegalArgumentException(parent + " is not an id"); + } + this.parent = parent; + return this; + } + + public Builder entity(Entity entity) { + Objects.requireNonNull(entity, "entity is null"); + this.entity = entity; + return this; + } + + public Builder children(List children) { + Objects.requireNonNull(children, "children is null"); + this.children = new ArrayList<>(children); + return this; + } + + public Builder child(RecycleBinItem child) { + Objects.requireNonNull(child, "child is null"); + this.children.add(child); + return this; + } + + public RecycleBinItem build() { + return new RecycleBinItem(this); + } + } +} diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/RecycleBinItemFilter.java b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/RecycleBinItemFilter.java index 6b9321e..279deae 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/RecycleBinItemFilter.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/RecycleBinItemFilter.java @@ -6,97 +6,95 @@ public final class RecycleBinItemFilter { - private final LocalDateTime from; - - private final LocalDateTime to; - - private final Long user; - - private RecycleBinItemFilter(Builder builder) { - this.from = builder.from; - this.to = builder.to; - this.user = builder.user; - } - - public Optional getFrom() { - return Optional.ofNullable(this.from); - } - - public Optional getTo() { - return Optional.ofNullable(this.to); - } - - public Optional getUser() { - return Optional.ofNullable(this.user); - } - - @Override - public final int hashCode() { - return Objects.hash( - this.from, - this.to, - this.user); - } - - @Override - public final boolean equals(Object o) { - - if (!(o instanceof RecycleBinItemFilter)) { - return false; - } - - RecycleBinItemFilter filter = (RecycleBinItemFilter)o; - - return Objects.equals(this.from, filter.from) && - Objects.equals(this.to, filter.to) && - Objects.equals(this.user, filter.user); - } - - public static Builder builder() { - return new Builder(); - } - - public Builder toBuilder() { - return new Builder(this); - } - - public static final class Builder { - - private LocalDateTime from; - - private LocalDateTime to; - - private Long user; - - private Builder() {} - private Builder(RecycleBinItemFilter recycleBinItemFilter) { - this.from = recycleBinItemFilter.from; - this.to = recycleBinItemFilter.to; - this.user = recycleBinItemFilter.user; - } - - public Builder from(LocalDateTime from) { - Objects.requireNonNull(from, "from is null"); - this.from = from; - return this; - } - - public Builder to(LocalDateTime to) { - Objects.requireNonNull(to, "to is null"); - this.to = to; - return this; - } - - public Builder user(long user) { - if (user <= 0) { - throw new IllegalArgumentException("user should be greater then 0"); - } - this.user = user; - return this; - } - - public RecycleBinItemFilter build() { - return new RecycleBinItemFilter(this); - } - } + private final LocalDateTime from; + + private final LocalDateTime to; + + private final Long user; + + private RecycleBinItemFilter(Builder builder) { + this.from = builder.from; + this.to = builder.to; + this.user = builder.user; + } + + public Optional getFrom() { + return Optional.ofNullable(this.from); + } + + public Optional getTo() { + return Optional.ofNullable(this.to); + } + + public Optional getUser() { + return Optional.ofNullable(this.user); + } + + @Override + public final int hashCode() { + return Objects.hash(this.from, this.to, this.user); + } + + @Override + public final boolean equals(Object o) { + + if (!(o instanceof RecycleBinItemFilter)) { + return false; + } + + RecycleBinItemFilter filter = (RecycleBinItemFilter) o; + + return Objects.equals(this.from, filter.from) + && Objects.equals(this.to, filter.to) + && Objects.equals(this.user, filter.user); + } + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder(this); + } + + public static final class Builder { + + private LocalDateTime from; + + private LocalDateTime to; + + private Long user; + + private Builder() {} + + private Builder(RecycleBinItemFilter recycleBinItemFilter) { + this.from = recycleBinItemFilter.from; + this.to = recycleBinItemFilter.to; + this.user = recycleBinItemFilter.user; + } + + public Builder from(LocalDateTime from) { + Objects.requireNonNull(from, "from is null"); + this.from = from; + return this; + } + + public Builder to(LocalDateTime to) { + Objects.requireNonNull(to, "to is null"); + this.to = to; + return this; + } + + public Builder user(long user) { + if (user <= 0) { + throw new IllegalArgumentException("user should be greater then 0"); + } + this.user = user; + return this; + } + + public RecycleBinItemFilter build() { + return new RecycleBinItemFilter(this); + } + } } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/Anchor.java b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/Anchor.java index c103698..286558c 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/Anchor.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/Anchor.java @@ -1,20 +1,21 @@ package com.sitepark.ies.contentrepository.core.domain.entity.filter; -import java.util.Objects; - import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.Objects; public class Anchor implements Filter { - @SuppressWarnings("PMD.AvoidFieldNameMatchingTypeName") // so that when deserializing it has the desired format - private final com.sitepark.ies.contentrepository.core.domain.entity.Anchor anchor; + @SuppressWarnings( + "PMD.AvoidFieldNameMatchingTypeName") // so that when deserializing it has the desired format + private final com.sitepark.ies.contentrepository.core.domain.entity.Anchor anchor; - protected Anchor(@JsonProperty("anchor") com.sitepark.ies.contentrepository.core.domain.entity.Anchor anchor) { - Objects.requireNonNull(anchor, "anchor is null"); - this.anchor = anchor; - } + protected Anchor( + @JsonProperty("anchor") com.sitepark.ies.contentrepository.core.domain.entity.Anchor anchor) { + Objects.requireNonNull(anchor, "anchor is null"); + this.anchor = anchor; + } - public com.sitepark.ies.contentrepository.core.domain.entity.Anchor getAnchor() { - return this.anchor; - } + public com.sitepark.ies.contentrepository.core.domain.entity.Anchor getAnchor() { + return this.anchor; + } } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/AnchorList.java b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/AnchorList.java index 57d8aee..534e914 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/AnchorList.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/AnchorList.java @@ -1,26 +1,25 @@ package com.sitepark.ies.contentrepository.core.domain.entity.filter; -import java.util.List; -import java.util.Objects; - import com.fasterxml.jackson.annotation.JsonProperty; - import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import java.util.List; +import java.util.Objects; public class AnchorList implements Filter { - @SuppressWarnings("PMD.AvoidFieldNameMatchingTypeName") // so that when deserializing it has the desired format - - private final List anchorList; - - protected AnchorList(@JsonProperty("anchorList") - com.sitepark.ies.contentrepository.core.domain.entity.Anchor... anchorList) { - Objects.requireNonNull(anchorList, "anchorList is null"); - this.anchorList = List.of(anchorList); - } - - @SuppressFBWarnings("EI_EXPOSE_REP") - public List getAnchorList() { - return this.anchorList; - } + @SuppressWarnings( + "PMD.AvoidFieldNameMatchingTypeName") // so that when deserializing it has the desired format + private final List anchorList; + + protected AnchorList( + @JsonProperty("anchorList") + com.sitepark.ies.contentrepository.core.domain.entity.Anchor... anchorList) { + Objects.requireNonNull(anchorList, "anchorList is null"); + this.anchorList = List.of(anchorList); + } + + @SuppressFBWarnings("EI_EXPOSE_REP") + public List getAnchorList() { + return this.anchorList; + } } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/And.java b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/And.java index ef318ba..e07ecef 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/And.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/And.java @@ -1,24 +1,23 @@ package com.sitepark.ies.contentrepository.core.domain.entity.filter; -import java.util.List; -import java.util.Objects; - import com.fasterxml.jackson.annotation.JsonProperty; - import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import java.util.List; +import java.util.Objects; public class And implements Filter { - @SuppressWarnings("PMD.AvoidFieldNameMatchingTypeName") // so that when deserializing it has the desired format - private final List and; + @SuppressWarnings( + "PMD.AvoidFieldNameMatchingTypeName") // so that when deserializing it has the desired format + private final List and; - protected And(@JsonProperty("and") Filter... and) { - Objects.requireNonNull(and, "and is null"); - this.and = List.of(and); - } + protected And(@JsonProperty("and") Filter... and) { + Objects.requireNonNull(and, "and is null"); + this.and = List.of(and); + } - @SuppressFBWarnings("EI_EXPOSE_REP") - public List getAnd() { - return this.and; - } + @SuppressFBWarnings("EI_EXPOSE_REP") + public List getAnd() { + return this.and; + } } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/Filter.java b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/Filter.java index e830380..5fe32a7 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/Filter.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/Filter.java @@ -3,60 +3,62 @@ @SuppressWarnings("PMD.TooManyMethods") public interface Filter { - public static IsGroup isGroup(Boolean isGroup) { - return new IsGroup(isGroup); - } - - public static Id id(String id) { - return new Id(id); - } - - public static IdList idList(String... idlist) { - return new IdList(idlist); - } - - public static Anchor anchor(com.sitepark.ies.contentrepository.core.domain.entity.Anchor anchor) { - return new Anchor(anchor); - } - - public static AnchorList anchorList(com.sitepark.ies.contentrepository.core.domain.entity.Anchor... anchorList) { - return new AnchorList(anchorList); - } - - public static Parent parent(String parent) { - return new Parent(parent); - } - - public static ParentList parentList(String... parentList) { - return new ParentList(parentList); - } - - public static ParentAnchor parentAnchor(com.sitepark.ies.contentrepository.core.domain.entity.Anchor parentAnchor) { - return new ParentAnchor(parentAnchor); - } - - public static ParentAnchorList parentAnchorList( - com.sitepark.ies.contentrepository.core.domain.entity.Anchor... parentAnchorList) { - return new ParentAnchorList(parentAnchorList); - } - - public static Root root(String root) { - return new Root(root); - } - - public static RootList rootList(String... rootList) { - return new RootList(rootList); - } - - public static Or or(Filter... filterList) { - return new Or(filterList); - } - - public static And and(Filter... filterList) { - return new And(filterList); - } - - public static Not not(Filter filter) { - return new Not(filter); - } + public static IsGroup isGroup(Boolean isGroup) { + return new IsGroup(isGroup); + } + + public static Id id(String id) { + return new Id(id); + } + + public static IdList idList(String... idlist) { + return new IdList(idlist); + } + + public static Anchor anchor(com.sitepark.ies.contentrepository.core.domain.entity.Anchor anchor) { + return new Anchor(anchor); + } + + public static AnchorList anchorList( + com.sitepark.ies.contentrepository.core.domain.entity.Anchor... anchorList) { + return new AnchorList(anchorList); + } + + public static Parent parent(String parent) { + return new Parent(parent); + } + + public static ParentList parentList(String... parentList) { + return new ParentList(parentList); + } + + public static ParentAnchor parentAnchor( + com.sitepark.ies.contentrepository.core.domain.entity.Anchor parentAnchor) { + return new ParentAnchor(parentAnchor); + } + + public static ParentAnchorList parentAnchorList( + com.sitepark.ies.contentrepository.core.domain.entity.Anchor... parentAnchorList) { + return new ParentAnchorList(parentAnchorList); + } + + public static Root root(String root) { + return new Root(root); + } + + public static RootList rootList(String... rootList) { + return new RootList(rootList); + } + + public static Or or(Filter... filterList) { + return new Or(filterList); + } + + public static And and(Filter... filterList) { + return new And(filterList); + } + + public static Not not(Filter filter) { + return new Not(filter); + } } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/FilterDeserializer.java b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/FilterDeserializer.java index bdc1785..f9b9d94 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/FilterDeserializer.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/FilterDeserializer.java @@ -4,20 +4,20 @@ public class FilterDeserializer extends UniquePropertyPolymorphicDeserializer { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - public FilterDeserializer() { - super(Filter.class); - super.register("id", Id.class); - super.register("idList", IdList.class); - super.register("parent", Parent.class); - super.register("parentList", ParentList.class); - super.register("root", Root.class); - super.register("rootList", RootList.class); - super.register("anchor", Anchor.class); - super.register("anchorList", AnchorList.class); - super.register("and", And.class); - super.register("or", Or.class); - super.register("not", Not.class); - } + public FilterDeserializer() { + super(Filter.class); + super.register("id", Id.class); + super.register("idList", IdList.class); + super.register("parent", Parent.class); + super.register("parentList", ParentList.class); + super.register("root", Root.class); + super.register("rootList", RootList.class); + super.register("anchor", Anchor.class); + super.register("anchorList", AnchorList.class); + super.register("and", And.class); + super.register("or", Or.class); + super.register("not", Not.class); + } } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/Id.java b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/Id.java index 040065e..6775efe 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/Id.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/Id.java @@ -1,20 +1,20 @@ package com.sitepark.ies.contentrepository.core.domain.entity.filter; -import java.util.Objects; - import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.Objects; public class Id implements Filter { - @SuppressWarnings("PMD.AvoidFieldNameMatchingTypeName") // so that when deserializing it has the desired format - private final String id; + @SuppressWarnings( + "PMD.AvoidFieldNameMatchingTypeName") // so that when deserializing it has the desired format + private final String id; - protected Id(@JsonProperty("id") String id) { - Objects.requireNonNull(id, "id is null"); - this.id = id; - } + protected Id(@JsonProperty("id") String id) { + Objects.requireNonNull(id, "id is null"); + this.id = id; + } - public String getId() { - return this.id; - } + public String getId() { + return this.id; + } } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/IdList.java b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/IdList.java index d505fbd..430e0dd 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/IdList.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/IdList.java @@ -1,25 +1,23 @@ package com.sitepark.ies.contentrepository.core.domain.entity.filter; -import java.util.List; -import java.util.Objects; - import com.fasterxml.jackson.annotation.JsonProperty; - import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import java.util.List; +import java.util.Objects; public class IdList implements Filter { - @SuppressWarnings("PMD.AvoidFieldNameMatchingTypeName") // so that when deserializing it has the desired format - - private final List idList; + @SuppressWarnings( + "PMD.AvoidFieldNameMatchingTypeName") // so that when deserializing it has the desired format + private final List idList; - protected IdList(@JsonProperty("idList") String... idList) { - Objects.requireNonNull(idList, "idList is null"); - this.idList = List.of(idList); - } + protected IdList(@JsonProperty("idList") String... idList) { + Objects.requireNonNull(idList, "idList is null"); + this.idList = List.of(idList); + } - @SuppressFBWarnings("EI_EXPOSE_REP") - public List getIdList() { - return this.idList; - } + @SuppressFBWarnings("EI_EXPOSE_REP") + public List getIdList() { + return this.idList; + } } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/IsGroup.java b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/IsGroup.java index 42a29b5..8e9b60c 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/IsGroup.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/IsGroup.java @@ -4,14 +4,15 @@ public class IsGroup implements Filter { - @SuppressWarnings("PMD.AvoidFieldNameMatchingTypeName") // so that when deserializing it has the desired format - private final boolean isGroup; + @SuppressWarnings( + "PMD.AvoidFieldNameMatchingTypeName") // so that when deserializing it has the desired format + private final boolean isGroup; - protected IsGroup(@JsonProperty("isGroup") boolean isGroup) { - this.isGroup = isGroup; - } + protected IsGroup(@JsonProperty("isGroup") boolean isGroup) { + this.isGroup = isGroup; + } - public boolean isGroup() { - return this.isGroup; - } + public boolean isGroup() { + return this.isGroup; + } } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/Not.java b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/Not.java index 4681d4c..9b34370 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/Not.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/Not.java @@ -1,20 +1,20 @@ package com.sitepark.ies.contentrepository.core.domain.entity.filter; -import java.util.Objects; - import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.Objects; public class Not implements Filter { - @SuppressWarnings("PMD.AvoidFieldNameMatchingTypeName") // so that when deserializing it has the desired format - private final Filter not; + @SuppressWarnings( + "PMD.AvoidFieldNameMatchingTypeName") // so that when deserializing it has the desired format + private final Filter not; - protected Not(@JsonProperty("not") Filter not) { - Objects.requireNonNull(not, "not is null"); - this.not = not; - } + protected Not(@JsonProperty("not") Filter not) { + Objects.requireNonNull(not, "not is null"); + this.not = not; + } - public Filter getNot() { - return this.not; - } + public Filter getNot() { + return this.not; + } } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/Or.java b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/Or.java index a105d85..6bc10ce 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/Or.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/Or.java @@ -1,24 +1,23 @@ package com.sitepark.ies.contentrepository.core.domain.entity.filter; -import java.util.List; -import java.util.Objects; - import com.fasterxml.jackson.annotation.JsonProperty; - import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import java.util.List; +import java.util.Objects; public class Or implements Filter { - @SuppressWarnings("PMD.AvoidFieldNameMatchingTypeName") // so that when deserializing it has the desired format - private final List or; + @SuppressWarnings( + "PMD.AvoidFieldNameMatchingTypeName") // so that when deserializing it has the desired format + private final List or; - protected Or(@JsonProperty("or") Filter... or) { - Objects.requireNonNull(or, "or is null"); - this.or = List.of(or); - } + protected Or(@JsonProperty("or") Filter... or) { + Objects.requireNonNull(or, "or is null"); + this.or = List.of(or); + } - @SuppressFBWarnings("EI_EXPOSE_REP") - public List getOr() { - return this.or; - } -} \ No newline at end of file + @SuppressFBWarnings("EI_EXPOSE_REP") + public List getOr() { + return this.or; + } +} diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/Parent.java b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/Parent.java index bc04ee8..fe7855e 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/Parent.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/Parent.java @@ -1,20 +1,20 @@ package com.sitepark.ies.contentrepository.core.domain.entity.filter; -import java.util.Objects; - import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.Objects; public class Parent implements Filter { - @SuppressWarnings("PMD.AvoidFieldNameMatchingTypeName") // so that when deserializing it has the desired format - private final String parent; + @SuppressWarnings( + "PMD.AvoidFieldNameMatchingTypeName") // so that when deserializing it has the desired format + private final String parent; - protected Parent(@JsonProperty("parent") String parent) { - Objects.requireNonNull(parent, "parent is null"); - this.parent = parent; - } + protected Parent(@JsonProperty("parent") String parent) { + Objects.requireNonNull(parent, "parent is null"); + this.parent = parent; + } - public String getParent() { - return this.parent; - } + public String getParent() { + return this.parent; + } } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/ParentAnchor.java b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/ParentAnchor.java index c2bb4f4..d47bbc4 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/ParentAnchor.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/ParentAnchor.java @@ -1,21 +1,22 @@ package com.sitepark.ies.contentrepository.core.domain.entity.filter; -import java.util.Objects; - import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.Objects; public class ParentAnchor implements Filter { - @SuppressWarnings("PMD.AvoidFieldNameMatchingTypeName") // so that when deserializing it has the desired format - private final com.sitepark.ies.contentrepository.core.domain.entity.Anchor parentAnchor; + @SuppressWarnings( + "PMD.AvoidFieldNameMatchingTypeName") // so that when deserializing it has the desired format + private final com.sitepark.ies.contentrepository.core.domain.entity.Anchor parentAnchor; - protected ParentAnchor(@JsonProperty("parentAnchor") - com.sitepark.ies.contentrepository.core.domain.entity.Anchor parentAnchor) { - Objects.requireNonNull(parentAnchor, "parentAnchor is null"); - this.parentAnchor = parentAnchor; - } + protected ParentAnchor( + @JsonProperty("parentAnchor") + com.sitepark.ies.contentrepository.core.domain.entity.Anchor parentAnchor) { + Objects.requireNonNull(parentAnchor, "parentAnchor is null"); + this.parentAnchor = parentAnchor; + } - public com.sitepark.ies.contentrepository.core.domain.entity.Anchor getParentAnchor() { - return this.parentAnchor; - } + public com.sitepark.ies.contentrepository.core.domain.entity.Anchor getParentAnchor() { + return this.parentAnchor; + } } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/ParentAnchorList.java b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/ParentAnchorList.java index 23a9f26..3278adc 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/ParentAnchorList.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/ParentAnchorList.java @@ -1,26 +1,25 @@ package com.sitepark.ies.contentrepository.core.domain.entity.filter; -import java.util.List; -import java.util.Objects; - import com.fasterxml.jackson.annotation.JsonProperty; - import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import java.util.List; +import java.util.Objects; public class ParentAnchorList implements Filter { - @SuppressWarnings("PMD.AvoidFieldNameMatchingTypeName") // so that when deserializing it has the desired format - - private final List parentAnchorList; - - protected ParentAnchorList(@JsonProperty("parentAnchorList") - com.sitepark.ies.contentrepository.core.domain.entity.Anchor... parentAnchorList) { - Objects.requireNonNull(parentAnchorList, "parentAnchorList is null"); - this.parentAnchorList = List.of(parentAnchorList); - } - - @SuppressFBWarnings("EI_EXPOSE_REP") - public List getParentAnchorList() { - return this.parentAnchorList; - } + @SuppressWarnings( + "PMD.AvoidFieldNameMatchingTypeName") // so that when deserializing it has the desired format + private final List parentAnchorList; + + protected ParentAnchorList( + @JsonProperty("parentAnchorList") + com.sitepark.ies.contentrepository.core.domain.entity.Anchor... parentAnchorList) { + Objects.requireNonNull(parentAnchorList, "parentAnchorList is null"); + this.parentAnchorList = List.of(parentAnchorList); + } + + @SuppressFBWarnings("EI_EXPOSE_REP") + public List getParentAnchorList() { + return this.parentAnchorList; + } } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/ParentList.java b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/ParentList.java index 005d259..6714cd4 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/ParentList.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/ParentList.java @@ -1,24 +1,23 @@ package com.sitepark.ies.contentrepository.core.domain.entity.filter; -import java.util.List; -import java.util.Objects; - import com.fasterxml.jackson.annotation.JsonProperty; - import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import java.util.List; +import java.util.Objects; public class ParentList implements Filter { - @SuppressWarnings("PMD.AvoidFieldNameMatchingTypeName") // so that when deserializing it has the desired format - private final List parentList; + @SuppressWarnings( + "PMD.AvoidFieldNameMatchingTypeName") // so that when deserializing it has the desired format + private final List parentList; - protected ParentList(@JsonProperty("parentList") String... parentList) { - Objects.requireNonNull(parentList, "parentList is null"); - this.parentList = List.of(parentList); - } + protected ParentList(@JsonProperty("parentList") String... parentList) { + Objects.requireNonNull(parentList, "parentList is null"); + this.parentList = List.of(parentList); + } - @SuppressFBWarnings("EI_EXPOSE_REP") - public List getParentList() { - return this.parentList; - } + @SuppressFBWarnings("EI_EXPOSE_REP") + public List getParentList() { + return this.parentList; + } } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/Root.java b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/Root.java index d34228f..0f5e12b 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/Root.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/Root.java @@ -1,21 +1,20 @@ package com.sitepark.ies.contentrepository.core.domain.entity.filter; -import java.util.Objects; - import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.Objects; public class Root implements Filter { - @SuppressWarnings("PMD.AvoidFieldNameMatchingTypeName") // so that when deserializing it has the desired format - private final String root; - - protected Root(@JsonProperty("root") String root) { - Objects.requireNonNull(root, "root is null"); - this.root = root; - } + @SuppressWarnings( + "PMD.AvoidFieldNameMatchingTypeName") // so that when deserializing it has the desired format + private final String root; - public String getRoot() { - return this.root; - } + protected Root(@JsonProperty("root") String root) { + Objects.requireNonNull(root, "root is null"); + this.root = root; + } + public String getRoot() { + return this.root; + } } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/RootList.java b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/RootList.java index cb657af..6468fb2 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/RootList.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/RootList.java @@ -1,24 +1,23 @@ package com.sitepark.ies.contentrepository.core.domain.entity.filter; -import java.util.List; -import java.util.Objects; - import com.fasterxml.jackson.annotation.JsonProperty; - import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import java.util.List; +import java.util.Objects; public class RootList implements Filter { - @SuppressWarnings("PMD.AvoidFieldNameMatchingTypeName") // so that when deserializing it has the desired format - private final List rootList; + @SuppressWarnings( + "PMD.AvoidFieldNameMatchingTypeName") // so that when deserializing it has the desired format + private final List rootList; - protected RootList(@JsonProperty("rootList") String... rootList) { - Objects.requireNonNull(rootList, "rootList is null"); - this.rootList = List.of(rootList); - } + protected RootList(@JsonProperty("rootList") String... rootList) { + Objects.requireNonNull(rootList, "rootList is null"); + this.rootList = List.of(rootList); + } - @SuppressFBWarnings("EI_EXPOSE_REP") - public List getRootList() { - return this.rootList; - } + @SuppressFBWarnings("EI_EXPOSE_REP") + public List getRootList() { + return this.rootList; + } } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/query/CursorBasedQuery.java b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/query/CursorBasedQuery.java index 41978aa..266e217 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/query/CursorBasedQuery.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/query/CursorBasedQuery.java @@ -1,109 +1,103 @@ package com.sitepark.ies.contentrepository.core.domain.entity.query; -import java.util.Objects; - import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import java.util.Objects; @JsonDeserialize(builder = Query.Builder.class) public class CursorBasedQuery extends Query { - private final int first; - - private final String after; - - protected CursorBasedQuery(Builder builder) { - super(builder); - this.first = builder.first; - this.after = builder.after; - } - - public int getFirst() { - return this.first; - } - - public String getAfter() { - return this.after; - } - - @Override - public final int hashCode() { - return Objects.hash( - super.hashCode(), - this.first, - this.after); - } - - @Override - public final boolean equals(Object o) { - - if (!(o instanceof CursorBasedQuery)) { - return false; - } - - CursorBasedQuery that = (CursorBasedQuery)o; - - return - that.canEqual(this) && - super.equals(o) && - Objects.equals(this.first, that.first) && - Objects.equals(this.after, that.after); - } - - /** - * @see - * How to Write an Equality Method in Java - * - */ - @Override - public boolean canEqual(Object other) { - return (other instanceof CursorBasedQuery); - } - - - public static Builder builder() { - return new Builder(); - } - - @Override - public Builder toBuilder() { - return new Builder(this); - } - - @JsonPOJOBuilder(withPrefix = "", buildMethodName = "build") - public static class Builder extends Query.Builder { - - private int first; - - private String after; - - protected Builder() { } - - protected Builder(CursorBasedQuery curserBasedQuery) { - super(curserBasedQuery); - this.first = curserBasedQuery.first; - this.after = curserBasedQuery.after; - } - - public Builder first(int first) { - this.first = first; - return this.self(); - } - - public Builder after(String after) { - Objects.requireNonNull(after, "after is null"); - this.after = after; - return this.self(); - } - - @Override - public CursorBasedQuery build() { - return new CursorBasedQuery(this); - } - - @Override - public Builder self() { - return this; - } - } + private final int first; + + private final String after; + + protected CursorBasedQuery(Builder builder) { + super(builder); + this.first = builder.first; + this.after = builder.after; + } + + public int getFirst() { + return this.first; + } + + public String getAfter() { + return this.after; + } + + @Override + public final int hashCode() { + return Objects.hash(super.hashCode(), this.first, this.after); + } + + @Override + public final boolean equals(Object o) { + + if (!(o instanceof CursorBasedQuery)) { + return false; + } + + CursorBasedQuery that = (CursorBasedQuery) o; + + return that.canEqual(this) + && super.equals(o) + && Objects.equals(this.first, that.first) + && Objects.equals(this.after, that.after); + } + + /** + * @see + * How to Write an Equality Method in Java + * + */ + @Override + public boolean canEqual(Object other) { + return (other instanceof CursorBasedQuery); + } + + public static Builder builder() { + return new Builder(); + } + + @Override + public Builder toBuilder() { + return new Builder(this); + } + + @JsonPOJOBuilder(withPrefix = "", buildMethodName = "build") + public static class Builder extends Query.Builder { + + private int first; + + private String after; + + protected Builder() {} + + protected Builder(CursorBasedQuery curserBasedQuery) { + super(curserBasedQuery); + this.first = curserBasedQuery.first; + this.after = curserBasedQuery.after; + } + + public Builder first(int first) { + this.first = first; + return this.self(); + } + + public Builder after(String after) { + Objects.requireNonNull(after, "after is null"); + this.after = after; + return this.self(); + } + + @Override + public CursorBasedQuery build() { + return new CursorBasedQuery(this); + } + + @Override + public Builder self() { + return this; + } + } } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/query/Query.java b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/query/Query.java index 07e1677..8ad4e1a 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/query/Query.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/query/Query.java @@ -1,139 +1,134 @@ package com.sitepark.ies.contentrepository.core.domain.entity.query; -import java.util.Objects; -import java.util.Optional; - import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; import com.sitepark.ies.contentrepository.core.domain.entity.filter.Filter; import com.sitepark.ies.contentrepository.core.domain.entity.sort.OrderBy; +import java.util.Objects; +import java.util.Optional; @JsonDeserialize(builder = Query.Builder.class) public class Query { - private final Filter filterBy; + private final Filter filterBy; + + private final OrderBy orderBy; + + private final QueryOptions options; + + protected Query(Builder builder) { + this.filterBy = builder.filterBy; + this.orderBy = builder.orderBy; + this.options = builder.options; + } - private final OrderBy orderBy; + public Optional getFilterBy() { + return Optional.ofNullable(this.filterBy); + } - private final QueryOptions options; + public OrderBy getOrderBy() { + return this.orderBy; + } - protected Query(Builder builder) { - this.filterBy = builder.filterBy; - this.orderBy = builder.orderBy; - this.options = builder.options; - } + public QueryOptions getOptions() { + return this.options; + } - public Optional getFilterBy() { - return Optional.ofNullable(this.filterBy); - } + @Override + public int hashCode() { + return Objects.hash(this.filterBy, this.orderBy, this.options); + } - public OrderBy getOrderBy() { - return this.orderBy; - } + @Override + public boolean equals(Object o) { - public QueryOptions getOptions() { - return this.options; - } + if (!(o instanceof Query)) { + return false; + } - @Override - public int hashCode() { - return Objects.hash( - this.filterBy, - this.orderBy, - this.options); - } + Query that = (Query) o; - @Override - public boolean equals(Object o) { + return that.canEqual(this) + && Objects.equals(this.filterBy, that.filterBy) + && Objects.equals(this.orderBy, that.orderBy) + && Objects.equals(this.options, that.options); + } - if (!(o instanceof Query)) { - return false; - } + /** + * @see + * How to Write an Equality Method in Java + * + */ + public boolean canEqual(Object other) { + return (other instanceof Query); + } - Query that = (Query)o; + public static Builder builder() { + return new QueryBuilder(); + } - return - that.canEqual(this) && - Objects.equals(this.filterBy, that.filterBy) && - Objects.equals(this.orderBy, that.orderBy) && - Objects.equals(this.options, that.options); - } + public Builder toBuilder() { + return new QueryBuilder(this); + } - /** - * @see - * How to Write an Equality Method in Java - * - */ - public boolean canEqual(Object other) { - return (other instanceof Query); - } + public abstract static class Builder> { - public static Builder builder() { - return new QueryBuilder(); - } + protected Filter filterBy; - public Builder toBuilder() { - return new QueryBuilder(this); - } + protected OrderBy orderBy; - public static abstract class Builder> { + protected QueryOptions options; - protected Filter filterBy; + protected Builder() {} - protected OrderBy orderBy; + protected Builder(Query query) { + this.filterBy = query.filterBy; + this.orderBy = query.orderBy; + this.options = query.options; + } - protected QueryOptions options; + public B filterBy(Filter filterBy) { + this.filterBy = filterBy; + return this.self(); + } - protected Builder() { } + public B orderBy(OrderBy orderBy) { + Objects.requireNonNull(orderBy, "orderBy is null"); + this.orderBy = orderBy; + return this.self(); + } - protected Builder(Query query) { - this.filterBy = query.filterBy; - this.orderBy = query.orderBy; - this.options = query.options; - } + public B options(QueryOptions options) { + Objects.requireNonNull(options, "options is null"); + this.options = options; + return this.self(); + } - public B filterBy(Filter filterBy) { - this.filterBy = filterBy; - return this.self(); - } + public abstract B self(); - public B orderBy(OrderBy orderBy) { - Objects.requireNonNull(orderBy, "orderBy is null"); - this.orderBy = orderBy; - return this.self(); - } + public abstract Query build(); + } - public B options(QueryOptions options) { - Objects.requireNonNull(options, "options is null"); - this.options = options; - return this.self(); - } + @JsonPOJOBuilder(withPrefix = "", buildMethodName = "build") + public static class QueryBuilder extends Query.Builder { - public abstract B self(); + protected QueryBuilder() {} - public abstract Query build(); - } - - @JsonPOJOBuilder(withPrefix = "", buildMethodName = "build") - public static class QueryBuilder extends Query.Builder { - - protected QueryBuilder() { } - - protected QueryBuilder(Query query) { - super(query); - } - - @Override - public QueryBuilder self() { - return this; - } - - @Override - public Query build() { - if (this.options == null) { - this.options = QueryOptions.builder().build(); - } - return new Query(this); - } - } + protected QueryBuilder(Query query) { + super(query); + } + + @Override + public QueryBuilder self() { + return this; + } + + @Override + public Query build() { + if (this.options == null) { + this.options = QueryOptions.builder().build(); + } + return new Query(this); + } + } } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/query/QueryOptions.java b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/query/QueryOptions.java index 3a14702..944b283 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/query/QueryOptions.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/query/QueryOptions.java @@ -4,61 +4,58 @@ public class QueryOptions { - private final boolean showHidden; + private final boolean showHidden; - protected QueryOptions(Builder builder) { - this.showHidden = builder.showHidden; - } + protected QueryOptions(Builder builder) { + this.showHidden = builder.showHidden; + } - public boolean isShowHidden() { - return this.showHidden; - } + public boolean isShowHidden() { + return this.showHidden; + } - @Override - public final int hashCode() { - return Objects.hash( - this.showHidden); - } + @Override + public final int hashCode() { + return Objects.hash(this.showHidden); + } - @Override - public final boolean equals(Object o) { + @Override + public final boolean equals(Object o) { - if (!(o instanceof QueryOptions)) { - return false; - } + if (!(o instanceof QueryOptions)) { + return false; + } - QueryOptions that = (QueryOptions)o; + QueryOptions that = (QueryOptions) o; - return - Objects.equals(this.showHidden, that.showHidden); - } + return Objects.equals(this.showHidden, that.showHidden); + } - public static Builder builder() { - return new Builder(); - } + public static Builder builder() { + return new Builder(); + } - public Builder toBuilder() { - return new Builder(this); - } + public Builder toBuilder() { + return new Builder(this); + } - public static class Builder { + public static class Builder { - private boolean showHidden; + private boolean showHidden; - protected Builder() { - } + protected Builder() {} - protected Builder(QueryOptions queryOptions) { - this.showHidden = queryOptions.showHidden; - } + protected Builder(QueryOptions queryOptions) { + this.showHidden = queryOptions.showHidden; + } - public Builder showHidden(boolean showHidden) { - this.showHidden = showHidden; - return this; - } + public Builder showHidden(boolean showHidden) { + this.showHidden = showHidden; + return this; + } - public QueryOptions build() { - return new QueryOptions(this); - } - } + public QueryOptions build() { + return new QueryOptions(this); + } + } } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/query/SubTreeQuery.java b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/query/SubTreeQuery.java index f1b2c9d..cb74644 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/query/SubTreeQuery.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/query/SubTreeQuery.java @@ -1,106 +1,100 @@ package com.sitepark.ies.contentrepository.core.domain.entity.query; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Objects; -import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; - -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; - public class SubTreeQuery extends Query { - private final List rootList; - - protected SubTreeQuery(Builder builder) { - super(builder); - this.rootList = Collections.unmodifiableList(builder.rootList); - } - - @SuppressFBWarnings("EI_EXPOSE_REP") - public List getRootList() { - return this.rootList; - } - - @Override - public final int hashCode() { - return Objects.hash( - super.hashCode(), - this.rootList); - } - - @Override - public final boolean equals(Object o) { - - if (!(o instanceof SubTreeQuery)) { - return false; - } - - SubTreeQuery that = (SubTreeQuery)o; - - return - that.canEqual(this) && - super.equals(o) && - Objects.equals(this.rootList, that.rootList); - } - - /** - * @see - * How to Write an Equality Method in Java - * - */ - @Override - public boolean canEqual(Object other) { - return (other instanceof SubTreeQuery); - } - public static Builder builder() { - return new Builder(); - } - - @Override - public Builder toBuilder() { - return new Builder(this); - } - - @JsonPOJOBuilder(withPrefix = "", buildMethodName = "build") - public static class Builder extends Query.Builder { - - private final List rootList = new ArrayList<>(); - - protected Builder() { } - - protected Builder(SubTreeQuery curserBasedQuery) { - super(curserBasedQuery); - this.rootList.addAll(curserBasedQuery.rootList); - } - - public Builder root(Long root) { - Objects.requireNonNull(root, "root is null"); - this.rootList.add(root); - return this.self(); - } - - public Builder rootList(List rootList) { - Objects.requireNonNull(rootList, "rootList is null"); - this.rootList.clear(); - for (Long root : rootList) { - this.root(root); - } - return this.self(); - } - - @Override - public SubTreeQuery build() { - if (this.rootList.isEmpty()) { - throw new IllegalStateException("rootList must not be empty"); - } - return new SubTreeQuery(this); - } - - @Override - public Builder self() { - return this; - } - } + private final List rootList; + + protected SubTreeQuery(Builder builder) { + super(builder); + this.rootList = Collections.unmodifiableList(builder.rootList); + } + + @SuppressFBWarnings("EI_EXPOSE_REP") + public List getRootList() { + return this.rootList; + } + + @Override + public final int hashCode() { + return Objects.hash(super.hashCode(), this.rootList); + } + + @Override + public final boolean equals(Object o) { + + if (!(o instanceof SubTreeQuery)) { + return false; + } + + SubTreeQuery that = (SubTreeQuery) o; + + return that.canEqual(this) && super.equals(o) && Objects.equals(this.rootList, that.rootList); + } + + /** + * @see + * How to Write an Equality Method in Java + * + */ + @Override + public boolean canEqual(Object other) { + return (other instanceof SubTreeQuery); + } + + public static Builder builder() { + return new Builder(); + } + + @Override + public Builder toBuilder() { + return new Builder(this); + } + + @JsonPOJOBuilder(withPrefix = "", buildMethodName = "build") + public static class Builder extends Query.Builder { + + private final List rootList = new ArrayList<>(); + + protected Builder() {} + + protected Builder(SubTreeQuery curserBasedQuery) { + super(curserBasedQuery); + this.rootList.addAll(curserBasedQuery.rootList); + } + + public Builder root(Long root) { + Objects.requireNonNull(root, "root is null"); + this.rootList.add(root); + return this.self(); + } + + public Builder rootList(List rootList) { + Objects.requireNonNull(rootList, "rootList is null"); + this.rootList.clear(); + for (Long root : rootList) { + this.root(root); + } + return this.self(); + } + + @Override + public SubTreeQuery build() { + if (this.rootList.isEmpty()) { + throw new IllegalStateException("rootList must not be empty"); + } + return new SubTreeQuery(this); + } + + @Override + public Builder self() { + return this; + } + } } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/sort/Direction.java b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/sort/Direction.java index 543fb44..17d378a 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/sort/Direction.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/sort/Direction.java @@ -1,6 +1,6 @@ package com.sitepark.ies.contentrepository.core.domain.entity.sort; public enum Direction { - ASC, - DESC + ASC, + DESC } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/sort/Name.java b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/sort/Name.java index 7bb7bcd..b3e536b 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/sort/Name.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/sort/Name.java @@ -6,48 +6,50 @@ @JsonDeserialize(builder = Name.Builder.class) public class Name extends OrderCriteria { - protected Name(Builder builder) { - super(builder); - } - - @Override - public String toString() { - StringBuilder b = new StringBuilder(100) - .append("OrderBy.Name[name:") - .append(this.getName()) - .append(", direction:") - .append(this.getDirection()) - .append(']'); - return b.toString(); - } - - public static Builder builder() { - return new Builder(); - } - - @Override public Builder toBuilder() { - return new Builder(this); - } - - @JsonPOJOBuilder(withPrefix = "", buildMethodName = "build") - public static class Builder extends OrderCriteria.Builder { - - protected Builder() { - super(); - } - - protected Builder(Name name) { - super(name); - } - - @Override - public Name build() { - return new Name(this); - } - - @Override - public Builder self() { - return this; - } - } + protected Name(Builder builder) { + super(builder); + } + + @Override + public String toString() { + StringBuilder b = + new StringBuilder(100) + .append("OrderBy.Name[name:") + .append(this.getName()) + .append(", direction:") + .append(this.getDirection()) + .append(']'); + return b.toString(); + } + + public static Builder builder() { + return new Builder(); + } + + @Override + public Builder toBuilder() { + return new Builder(this); + } + + @JsonPOJOBuilder(withPrefix = "", buildMethodName = "build") + public static class Builder extends OrderCriteria.Builder { + + protected Builder() { + super(); + } + + protected Builder(Name name) { + super(name); + } + + @Override + public Name build() { + return new Name(this); + } + + @Override + public Builder self() { + return this; + } + } } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/sort/OrderBy.java b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/sort/OrderBy.java index bc2a590..5f371a6 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/sort/OrderBy.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/sort/OrderBy.java @@ -1,89 +1,81 @@ package com.sitepark.ies.contentrepository.core.domain.entity.sort; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Objects; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; - -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; - @JsonDeserialize(builder = OrderBy.Builder.class) public class OrderBy { - private final List sort; - - protected OrderBy(Builder builder) { - this.sort = Collections.unmodifiableList(builder.sort); - } - - @SuppressFBWarnings("EI_EXPOSE_REP") - public List getSort() { - return this.sort; - } - - @Override - public final int hashCode() { - return Objects.hash( - this.sort); - } - - @Override - public final boolean equals(Object o) { - - if (!(o instanceof OrderBy)) { - return false; - } - - OrderBy orderBy = (OrderBy)o; - - return Objects.equals(this.sort, orderBy.sort); - } - - @Override - public String toString() { - StringBuilder b = new StringBuilder(100) - .append("OrderBy[sort:") - .append(this.sort) - .append(']'); - return b.toString(); - } - - public static Builder builder() { - return new Builder(); - } - - public Builder toBuilder() { - return new Builder(this); - } - - @JsonPOJOBuilder(withPrefix = "", buildMethodName = "build") - public static class Builder { - - private final List sort = new ArrayList<>(); - - protected Builder() { } - - protected Builder(OrderBy orderBy) { - this.sort.addAll(orderBy.sort); - } - - @SuppressWarnings("PMD.UseArraysAsList") - public Builder sort(OrderCriteria... sortCriteriaList) { - Objects.requireNonNull(sortCriteriaList, "sortCriteriaList is null"); - for (OrderCriteria sortCriteria : sortCriteriaList) { - Objects.requireNonNull( - sortCriteria, - "sortCriteria in sortCriteriaList is null"); - this.sort.add(sortCriteria); - } - return this; - } - - public OrderBy build() { - return new OrderBy(this); - } - } + private final List sort; + + protected OrderBy(Builder builder) { + this.sort = Collections.unmodifiableList(builder.sort); + } + + @SuppressFBWarnings("EI_EXPOSE_REP") + public List getSort() { + return this.sort; + } + + @Override + public final int hashCode() { + return Objects.hash(this.sort); + } + + @Override + public final boolean equals(Object o) { + + if (!(o instanceof OrderBy)) { + return false; + } + + OrderBy orderBy = (OrderBy) o; + + return Objects.equals(this.sort, orderBy.sort); + } + + @Override + public String toString() { + StringBuilder b = new StringBuilder(100).append("OrderBy[sort:").append(this.sort).append(']'); + return b.toString(); + } + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder(this); + } + + @JsonPOJOBuilder(withPrefix = "", buildMethodName = "build") + public static class Builder { + + private final List sort = new ArrayList<>(); + + protected Builder() {} + + protected Builder(OrderBy orderBy) { + this.sort.addAll(orderBy.sort); + } + + @SuppressWarnings("PMD.UseArraysAsList") + public Builder sort(OrderCriteria... sortCriteriaList) { + Objects.requireNonNull(sortCriteriaList, "sortCriteriaList is null"); + for (OrderCriteria sortCriteria : sortCriteriaList) { + Objects.requireNonNull(sortCriteria, "sortCriteria in sortCriteriaList is null"); + this.sort.add(sortCriteria); + } + return this; + } + + public OrderBy build() { + return new OrderBy(this); + } + } } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/sort/OrderCriteria.java b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/sort/OrderCriteria.java index bc9d337..7f10c51 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/sort/OrderCriteria.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/sort/OrderCriteria.java @@ -1,80 +1,77 @@ package com.sitepark.ies.contentrepository.core.domain.entity.sort; -import java.util.Objects; - import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import java.util.Objects; @JsonDeserialize(builder = OrderCriteria.Builder.class) public abstract class OrderCriteria { - private final String name; + private final String name; - private final Direction direction; + private final Direction direction; - protected OrderCriteria(Builder builder) { - this.name = builder.name; - this.direction = builder.direction; - } + protected OrderCriteria(Builder builder) { + this.name = builder.name; + this.direction = builder.direction; + } - public String getName() { - return this.name; - } + public String getName() { + return this.name; + } - public Direction getDirection() { - return this.direction; - } + public Direction getDirection() { + return this.direction; + } - @Override - public final int hashCode() { - return Objects.hash( - this.name, - this.direction); - } + @Override + public final int hashCode() { + return Objects.hash(this.name, this.direction); + } - @Override - public final boolean equals(Object o) { + @Override + public final boolean equals(Object o) { - if (!(o instanceof OrderCriteria)) { - return false; - } + if (!(o instanceof OrderCriteria)) { + return false; + } - OrderCriteria criteria = (OrderCriteria)o; + OrderCriteria criteria = (OrderCriteria) o; - return Objects.equals(this.name, criteria.name) && - Objects.equals(this.direction, criteria.direction); - } + return Objects.equals(this.name, criteria.name) + && Objects.equals(this.direction, criteria.direction); + } - public abstract Builder toBuilder(); + public abstract Builder toBuilder(); - @JsonPOJOBuilder(withPrefix = "", buildMethodName = "build") - public static abstract class Builder> { + @JsonPOJOBuilder(withPrefix = "", buildMethodName = "build") + public abstract static class Builder> { - private String name; + private String name; - private Direction direction = Direction.DESC; + private Direction direction = Direction.DESC; - protected Builder() { } + protected Builder() {} - protected Builder(OrderCriteria sortCriteria) { - this.name = sortCriteria.name; - this.direction = sortCriteria.direction; - } + protected Builder(OrderCriteria sortCriteria) { + this.name = sortCriteria.name; + this.direction = sortCriteria.direction; + } - public B name(String name) { - Objects.requireNonNull(name, "name is null"); - this.name = name; - return this.self(); - } + public B name(String name) { + Objects.requireNonNull(name, "name is null"); + this.name = name; + return this.self(); + } - public B direction(Direction direction) { - Objects.requireNonNull(direction, "direction is null"); - this.direction = direction; - return this.self(); - } + public B direction(Direction direction) { + Objects.requireNonNull(direction, "direction is null"); + this.direction = direction; + return this.self(); + } - public abstract B self(); + public abstract B self(); - public abstract OrderCriteria build(); - } + public abstract OrderCriteria build(); + } } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/domain/exception/AccessDeniedException.java b/src/main/java/com/sitepark/ies/contentrepository/core/domain/exception/AccessDeniedException.java index 4d6c755..710b337 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/domain/exception/AccessDeniedException.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/domain/exception/AccessDeniedException.java @@ -1,13 +1,13 @@ package com.sitepark.ies.contentrepository.core.domain.exception; public class AccessDeniedException extends ContentRepositoryException { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - public AccessDeniedException(String message) { - super(message); - } + public AccessDeniedException(String message) { + super(message); + } - public AccessDeniedException(String message, Throwable t) { - super(message, t); - } -} \ No newline at end of file + public AccessDeniedException(String message, Throwable t) { + super(message, t); + } +} diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/domain/exception/AnchorAlreadyExistsException.java b/src/main/java/com/sitepark/ies/contentrepository/core/domain/exception/AnchorAlreadyExistsException.java index 43ee728..b2cdd3d 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/domain/exception/AnchorAlreadyExistsException.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/domain/exception/AnchorAlreadyExistsException.java @@ -4,29 +4,28 @@ public class AnchorAlreadyExistsException extends ContentRepositoryException { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - private final Anchor anchor; + private final Anchor anchor; - private final long owner; + private final long owner; - public AnchorAlreadyExistsException(Anchor anchor, long owner) { - super(); - this.anchor = anchor; - this.owner = owner; - } + public AnchorAlreadyExistsException(Anchor anchor, long owner) { + super(); + this.anchor = anchor; + this.owner = owner; + } - public Anchor getAnchor() { - return this.anchor; - } + public Anchor getAnchor() { + return this.anchor; + } - public long getOwner() { - return this.owner; - } - - @Override - public String getMessage() { - return "Anchor " + this.anchor + " already exists for entity " + this.owner; - } + public long getOwner() { + return this.owner; + } + @Override + public String getMessage() { + return "Anchor " + this.anchor + " already exists for entity " + this.owner; + } } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/domain/exception/AnchorNotFoundException.java b/src/main/java/com/sitepark/ies/contentrepository/core/domain/exception/AnchorNotFoundException.java index 86fa15e..771b2fc 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/domain/exception/AnchorNotFoundException.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/domain/exception/AnchorNotFoundException.java @@ -4,21 +4,21 @@ public class AnchorNotFoundException extends ContentRepositoryException { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - private final Anchor anchor; + private final Anchor anchor; - public AnchorNotFoundException(Anchor anchor) { - super(); - this.anchor = anchor; - } + public AnchorNotFoundException(Anchor anchor) { + super(); + this.anchor = anchor; + } - public Anchor getAnchor() { - return this.anchor; - } + public Anchor getAnchor() { + return this.anchor; + } - @Override - public String getMessage() { - return "Entity with anchor " + this.anchor + " not found"; - } -} \ No newline at end of file + @Override + public String getMessage() { + return "Entity with anchor " + this.anchor + " not found"; + } +} diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/domain/exception/ContentRepositoryException.java b/src/main/java/com/sitepark/ies/contentrepository/core/domain/exception/ContentRepositoryException.java index a24e1c9..1087ae3 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/domain/exception/ContentRepositoryException.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/domain/exception/ContentRepositoryException.java @@ -2,15 +2,17 @@ public abstract class ContentRepositoryException extends RuntimeException { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - public ContentRepositoryException() { - super(); - } - public ContentRepositoryException(String message) { - super(message); - } - public ContentRepositoryException(String message, Throwable t) { - super(message, t); - } + public ContentRepositoryException() { + super(); + } + + public ContentRepositoryException(String message) { + super(message); + } + + public ContentRepositoryException(String message, Throwable t) { + super(message, t); + } } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/domain/exception/EntityLockedException.java b/src/main/java/com/sitepark/ies/contentrepository/core/domain/exception/EntityLockedException.java index c636302..15be49d 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/domain/exception/EntityLockedException.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/domain/exception/EntityLockedException.java @@ -4,21 +4,21 @@ public class EntityLockedException extends ContentRepositoryException { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - private final EntityLock lock; + private final EntityLock lock; - public EntityLockedException(EntityLock lock) { - super(); - this.lock = lock; - } + public EntityLockedException(EntityLock lock) { + super(); + this.lock = lock; + } - public EntityLock getLock() { - return this.lock; - } + public EntityLock getLock() { + return this.lock; + } - @Override - public String getMessage() { - return "Entity is locked: " + this.lock; - } + @Override + public String getMessage() { + return "Entity is locked: " + this.lock; + } } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/domain/exception/EntityNotFoundException.java b/src/main/java/com/sitepark/ies/contentrepository/core/domain/exception/EntityNotFoundException.java index a85e6bb..6ec6ad2 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/domain/exception/EntityNotFoundException.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/domain/exception/EntityNotFoundException.java @@ -2,21 +2,21 @@ public class EntityNotFoundException extends ContentRepositoryException { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - private final String id; + private final String id; - public EntityNotFoundException(String id) { - super(); - this.id = id; - } + public EntityNotFoundException(String id) { + super(); + this.id = id; + } - public String getId() { - return this.id; - } + public String getId() { + return this.id; + } - @Override - public String getMessage() { - return "Entity with id " + this.id + " not found"; - } + @Override + public String getMessage() { + return "Entity with id " + this.id + " not found"; + } } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/domain/exception/GroupNotEmptyException.java b/src/main/java/com/sitepark/ies/contentrepository/core/domain/exception/GroupNotEmptyException.java index c94ff91..1e63ad1 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/domain/exception/GroupNotEmptyException.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/domain/exception/GroupNotEmptyException.java @@ -1,22 +1,21 @@ package com.sitepark.ies.contentrepository.core.domain.exception; public class GroupNotEmptyException extends ContentRepositoryException { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - private final String id; + private final String id; - public GroupNotEmptyException(String id) { - super(); - this.id = id; - } + public GroupNotEmptyException(String id) { + super(); + this.id = id; + } - public String getId() { - return this.id; - } + public String getId() { + return this.id; + } - @Override - public String getMessage() { - return "Group with id " + this.id + " not empty"; - } - -} \ No newline at end of file + @Override + public String getMessage() { + return "Group with id " + this.id + " not empty"; + } +} diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/domain/exception/InvalidAnchorException.java b/src/main/java/com/sitepark/ies/contentrepository/core/domain/exception/InvalidAnchorException.java index 89ce988..3017e9a 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/domain/exception/InvalidAnchorException.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/domain/exception/InvalidAnchorException.java @@ -2,21 +2,21 @@ public class InvalidAnchorException extends ContentRepositoryException { - private final String name; + private final String name; - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - public InvalidAnchorException(String name, String message) { - super(message); - this.name = name; - } + public InvalidAnchorException(String name, String message) { + super(message); + this.name = name; + } - public String getName() { - return this.name; - } + public String getName() { + return this.name; + } - @Override - public String getMessage() { - return "Invalid anchor '" + this.name + "': " + super.getMessage(); - } + @Override + public String getMessage() { + return "Invalid anchor '" + this.name + "': " + super.getMessage(); + } } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/domain/exception/ParentMissingException.java b/src/main/java/com/sitepark/ies/contentrepository/core/domain/exception/ParentMissingException.java index 4e66c28..c0d6878 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/domain/exception/ParentMissingException.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/domain/exception/ParentMissingException.java @@ -1,5 +1,5 @@ package com.sitepark.ies.contentrepository.core.domain.exception; public class ParentMissingException extends ContentRepositoryException { - private static final long serialVersionUID = 1L; -} \ No newline at end of file + private static final long serialVersionUID = 1L; +} diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/domain/service/ContentDiffer.java b/src/main/java/com/sitepark/ies/contentrepository/core/domain/service/ContentDiffer.java index e42b22c..1dd9a4f 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/domain/service/ContentDiffer.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/domain/service/ContentDiffer.java @@ -4,7 +4,7 @@ import com.sitepark.ies.contentrepository.core.domain.entity.Entity; public class ContentDiffer { - public ChangeSet diff(Entity left, Entity right) { - throw new UnsupportedOperationException(); - } + public ChangeSet diff(Entity left, Entity right) { + throw new UnsupportedOperationException(); + } } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/port/AccessControl.java b/src/main/java/com/sitepark/ies/contentrepository/core/port/AccessControl.java index fc86301..ec17bbe 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/port/AccessControl.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/port/AccessControl.java @@ -2,13 +2,19 @@ public interface AccessControl { - boolean isEntityCreateable(String parent); - boolean isEntityReadable(String id); - boolean isEntityWritable(String id); - boolean isEntityRemovable(String id); - - boolean isGroupCreateable(String parent); - boolean isGroupReadable(String id); - boolean isGroupWritable(String id); - boolean isGroupRemoveable(String id); + boolean isEntityCreateable(String parent); + + boolean isEntityReadable(String id); + + boolean isEntityWritable(String id); + + boolean isEntityRemovable(String id); + + boolean isGroupCreateable(String parent); + + boolean isGroupReadable(String id); + + boolean isGroupWritable(String id); + + boolean isGroupRemoveable(String id); } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/port/ContentRepository.java b/src/main/java/com/sitepark/ies/contentrepository/core/port/ContentRepository.java index 5714f82..c14bdb8 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/port/ContentRepository.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/port/ContentRepository.java @@ -1,18 +1,23 @@ package com.sitepark.ies.contentrepository.core.port; -import java.util.List; -import java.util.Optional; - import com.sitepark.ies.contentrepository.core.domain.entity.Anchor; import com.sitepark.ies.contentrepository.core.domain.entity.Entity; import com.sitepark.ies.contentrepository.core.domain.entity.query.Query; +import java.util.List; +import java.util.Optional; public interface ContentRepository { - boolean isGroup(String id); - boolean isEmptyGroup(String id); - Entity store(Entity entity); - Optional get(String id); - void removeEntity(String id); - Optional resolveAnchor(Anchor anchor); - List getAll(Query query); + boolean isGroup(String id); + + boolean isEmptyGroup(String id); + + Entity store(Entity entity); + + Optional get(String id); + + void removeEntity(String id); + + Optional resolveAnchor(Anchor anchor); + + List getAll(Query query); } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/port/EntityBulkExecutor.java b/src/main/java/com/sitepark/ies/contentrepository/core/port/EntityBulkExecutor.java index 7accf9a..425992b 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/port/EntityBulkExecutor.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/port/EntityBulkExecutor.java @@ -3,5 +3,5 @@ import com.sitepark.ies.contentrepository.core.domain.entity.EntityBulkExecution; public interface EntityBulkExecutor { - String execute(EntityBulkExecution execution); + String execute(EntityBulkExecution execution); } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/port/EntityLockManager.java b/src/main/java/com/sitepark/ies/contentrepository/core/port/EntityLockManager.java index c1fa2d0..51107ee 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/port/EntityLockManager.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/port/EntityLockManager.java @@ -1,14 +1,17 @@ package com.sitepark.ies.contentrepository.core.port; +import com.sitepark.ies.contentrepository.core.domain.entity.EntityLock; import java.util.List; import java.util.Optional; -import com.sitepark.ies.contentrepository.core.domain.entity.EntityLock; - public interface EntityLockManager { - Optional getLock(String id); - EntityLock forceLock(String id); - void lock(String id); - void unlock(String id); - List getLockList(); + Optional getLock(String id); + + EntityLock forceLock(String id); + + void lock(String id); + + void unlock(String id); + + List getLockList(); } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/port/ExtensionsNotifier.java b/src/main/java/com/sitepark/ies/contentrepository/core/port/ExtensionsNotifier.java index de5202b..a61ee35 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/port/ExtensionsNotifier.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/port/ExtensionsNotifier.java @@ -1,5 +1,5 @@ package com.sitepark.ies.contentrepository.core.port; public interface ExtensionsNotifier { - void notifyPurge(String id); + void notifyPurge(String id); } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/port/HistoryManager.java b/src/main/java/com/sitepark/ies/contentrepository/core/port/HistoryManager.java index 27c1efd..ac407cc 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/port/HistoryManager.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/port/HistoryManager.java @@ -1,13 +1,14 @@ package com.sitepark.ies.contentrepository.core.port; -import java.time.OffsetDateTime; -import java.util.List; - import com.sitepark.ies.contentrepository.core.domain.entity.HistoryEntry; import com.sitepark.ies.contentrepository.core.domain.entity.HistoryEntryType; +import java.time.OffsetDateTime; +import java.util.List; public interface HistoryManager { - void purge(String id); - HistoryEntry createEntry(String id, OffsetDateTime date, HistoryEntryType type); - List getHistory(String id); -} \ No newline at end of file + void purge(String id); + + HistoryEntry createEntry(String id, OffsetDateTime date, HistoryEntryType type); + + List getHistory(String id); +} diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/port/IdGenerator.java b/src/main/java/com/sitepark/ies/contentrepository/core/port/IdGenerator.java index e3aafa6..aae6bae 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/port/IdGenerator.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/port/IdGenerator.java @@ -1,5 +1,5 @@ package com.sitepark.ies.contentrepository.core.port; public interface IdGenerator { - String generate(); + String generate(); } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/port/MediaReferenceManager.java b/src/main/java/com/sitepark/ies/contentrepository/core/port/MediaReferenceManager.java index efb86f1..80b4e0a 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/port/MediaReferenceManager.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/port/MediaReferenceManager.java @@ -3,6 +3,7 @@ import com.sitepark.ies.contentrepository.core.domain.entity.MediaReference; public interface MediaReferenceManager { - void removeByReference(String usedBy); - void addReference(MediaReference reference); + void removeByReference(String usedBy); + + void addReference(MediaReference reference); } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/port/Publisher.java b/src/main/java/com/sitepark/ies/contentrepository/core/port/Publisher.java index 0c552aa..dd6af62 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/port/Publisher.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/port/Publisher.java @@ -5,7 +5,9 @@ import java.util.function.Consumer; public interface Publisher { - void republish(String id, LocalDateTime version); - void depublish(String id); - void depublish(List idList, Consumer consumer); + void republish(String id, LocalDateTime version); + + void depublish(String id); + + void depublish(List idList, Consumer consumer); } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/port/RecycleBin.java b/src/main/java/com/sitepark/ies/contentrepository/core/port/RecycleBin.java index 765a6e2..2421aec 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/port/RecycleBin.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/port/RecycleBin.java @@ -1,14 +1,16 @@ package com.sitepark.ies.contentrepository.core.port; -import java.util.List; -import java.util.Optional; - import com.sitepark.ies.contentrepository.core.domain.entity.RecycleBinItem; import com.sitepark.ies.contentrepository.core.domain.entity.RecycleBinItemFilter; +import java.util.List; +import java.util.Optional; public interface RecycleBin { - Optional get(String id); - void add(RecycleBinItem item); - void removeByObject(String id); - List find(RecycleBinItemFilter filter); + Optional get(String id); + + void add(RecycleBinItem item); + + void removeByObject(String id); + + List find(RecycleBinItemFilter filter); } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/port/SearchIndex.java b/src/main/java/com/sitepark/ies/contentrepository/core/port/SearchIndex.java index 50365ca..c82d814 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/port/SearchIndex.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/port/SearchIndex.java @@ -1,6 +1,7 @@ package com.sitepark.ies.contentrepository.core.port; public interface SearchIndex { - void index(String id); - void remove(String id); + void index(String id); + + void remove(String id); } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/port/VersioningManager.java b/src/main/java/com/sitepark/ies/contentrepository/core/port/VersioningManager.java index 3b22206..c29706a 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/port/VersioningManager.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/port/VersioningManager.java @@ -1,17 +1,20 @@ package com.sitepark.ies.contentrepository.core.port; +import com.sitepark.ies.contentrepository.core.domain.entity.Entity; import java.time.LocalDateTime; import java.util.List; -import com.sitepark.ies.contentrepository.core.domain.entity.Entity; - public interface VersioningManager { - void removeAllVersions(String id); - Entity createNewVersion(Entity entity); - Entity revertToVersion(LocalDateTime version); - Entity getVersion(LocalDateTime version); - Entity getNextVersionSince(LocalDateTime date); - List getAllMediaReferences(String id); + void removeAllVersions(String id); + + Entity createNewVersion(Entity entity); + + Entity revertToVersion(LocalDateTime version); + + Entity getVersion(LocalDateTime version); + + Entity getNextVersionSince(LocalDateTime date); + List getAllMediaReferences(String id); } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/usecase/BulkPurge.java b/src/main/java/com/sitepark/ies/contentrepository/core/usecase/BulkPurge.java index ecbc8ff..0684dd8 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/usecase/BulkPurge.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/usecase/BulkPurge.java @@ -1,13 +1,5 @@ package com.sitepark.ies.contentrepository.core.usecase; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - import com.sitepark.ies.contentrepository.core.domain.entity.BulkOperationKey; import com.sitepark.ies.contentrepository.core.domain.entity.Entity; import com.sitepark.ies.contentrepository.core.domain.entity.EntityBulkExecution; @@ -28,231 +20,245 @@ import com.sitepark.ies.contentrepository.core.port.RecycleBin; import com.sitepark.ies.contentrepository.core.port.SearchIndex; import com.sitepark.ies.contentrepository.core.port.VersioningManager; - import jakarta.inject.Inject; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; public class BulkPurge { - private final ContentRepository repository; - - private final EntityLockManager lockManager; - - private final VersioningManager versioningManager; - - private final HistoryManager historyManager; - - private final AccessControl accessControl; - - private final RecycleBin recycleBin; - - private final SearchIndex searchIndex; - - private final MediaReferenceManager mediaReferenceManager; - - private final Publisher publisher; - - private final ExtensionsNotifier extensionsNotifier; + private final ContentRepository repository; - private final EntityBulkExecutor entityBulkExecutor; + private final EntityLockManager lockManager; - private static Logger LOGGER = LogManager.getLogger(); + private final VersioningManager versioningManager; - @Inject - @SuppressWarnings("PMD.ExcessiveParameterList") - protected BulkPurge(ContentRepository repository, EntityLockManager lockManager, - VersioningManager versioningManager, HistoryManager historyManager, AccessControl accessControl, - RecycleBin recycleBin, SearchIndex searchIndex, MediaReferenceManager mediaReferenceManager, - Publisher publisher, ExtensionsNotifier extensionsNotifier, EntityBulkExecutor entityBulkExecutor) { - - this.repository = repository; - this.lockManager = lockManager; - this.historyManager = historyManager; - this.versioningManager = versioningManager; - this.accessControl = accessControl; - this.recycleBin = recycleBin; - this.searchIndex = searchIndex; - this.mediaReferenceManager = mediaReferenceManager; - this.publisher = publisher; - this.extensionsNotifier = extensionsNotifier; - this.entityBulkExecutor = entityBulkExecutor; - } - - /** - * Create a BulkExecution and pass it to the EntityBulkExecutor to execute the purge. - * The return is a BulkExecution ID that can be used to track the progress. - * - * @param input Input argument for the bulk operations - * @return BulkExecution ID that can be used to track the progress - */ - public String bulkPurge(BulkPurgeInput input) { - - List entityList = this.getEntityList(input); - - this.accessControl(entityList); - - EntityBulkOperation lock = this.buildLockOperation(entityList, false); - EntityBulkOperation depublish = this.buildDepublishOperation(entityList); - EntityBulkOperation purge = this.buildPurgeOperation(entityList); - - EntityBulkOperation unlock = this.buildUnlockOperation(entityList); - - EntityBulkExecution execution = EntityBulkExecution.builder() - .topic("contentrepository", "purge") - .operation(lock, depublish, purge) - .finalizer(unlock) - .build(); - - return this.entityBulkExecutor.execute(execution); - } - - private List getEntityList(BulkPurgeInput input) { - Query query = this.buildQuery(input); - return this.repository.getAll(query); - } - - private Query buildQuery(BulkPurgeInput input) { - if (!input.getRootList().isEmpty()) { - return SubTreeQuery.builder() - .rootList(input.getRootList()) - .filterBy(input.getFilter().orElse(null)) - .build(); - } - - return Query.builder() - .filterBy(input.getFilter().get()) - .build(); - } - - private void accessControl(List entityList) { - - entityList.stream().forEach(entity -> { - String id = entity.getId().get(); - if (entity.isGroup()) { - if (!this.accessControl.isGroupRemoveable(id)) { - throw new AccessDeniedException("Not allowed to remove group " + id); - } - } else { - if (!this.accessControl.isEntityRemovable(id)) { - throw new AccessDeniedException("Not allowed to remove entity " + id); - } - } - }); - } - - private EntityBulkOperation buildLockOperation(List entityList, boolean forceLock) { - - return EntityBulkOperation.builder() - .key(BulkOperationKey.PURGE_LOCK) - .entityList(entityList) - .consumer(entity -> { - - String id = entity.getId().get(); - - if (forceLock) { - this.lockManager.forceLock(id); - } else { - this.lockManager.lock(id); - } - }) - .build(); - } - - private EntityBulkOperation buildDepublishOperation(List entityList) { - - return EntityBulkOperation.builder() - .key(BulkOperationKey.PURGE_DEPUBLISH) - .entityList(entityList) - .consumer(entity -> { - String id = entity.getId().get(); - this.publisher.depublish(id); - }) - .build(); - } - - private EntityBulkOperation buildPurgeOperation(List entityList) { - - List nonGroupList = entityList.stream() - .filter(entity -> !entity.isGroup()) - .collect(Collectors.toList()); - - List groupList = entityList.stream() - .filter(entity -> entity.isGroup()) - .collect(Collectors.toList()); - - /* - * Arrange the entityList so that first all group entries are deleted - * and then the groups in the hierarchy from bottom to top. - * This ensures that only empty pools are deleted. - */ - List orderedGroupList = this.orderGroupListHierarchicallyFromBottomToTop(groupList); - List orderedList = new ArrayList<>(); - orderedList.addAll(nonGroupList); - orderedList.addAll(orderedGroupList); - - if (LOGGER.isDebugEnabled()) { - orderedList.stream() - .forEach(entity -> { - LOGGER.debug("purge order: {}", entity); - }); - } - - return EntityBulkOperation.builder() - .key(BulkOperationKey.PURGE_PURGE) - .entityList(orderedList) - .consumer(entity -> { - String id = entity.getId().get(); - - if (this.repository.isGroup(id) && !this.repository.isEmptyGroup(id)) { - throw new GroupNotEmptyException(id); - } - - if (LOGGER.isInfoEnabled()) { - LOGGER.info("purge: {}", entity); - } - - this.searchIndex.remove(id); - this.mediaReferenceManager.removeByReference(id); - this.repository.removeEntity(id); - this.historyManager.purge(id); - this.versioningManager.removeAllVersions(id); - this.recycleBin.removeByObject(id); - this.extensionsNotifier.notifyPurge(id); - }) - .build(); - } - - /** - * Arranges the groups according to their hierarchy from bottom to top. - */ - private List orderGroupListHierarchicallyFromBottomToTop(List groupList) { - - EntityTree tree = new EntityTree(); - groupList.stream().forEach(tree::add); - - List hierarchicalOrder = tree.getAll(); - - Collections.reverse(hierarchicalOrder); - - return hierarchicalOrder; - } - - private EntityBulkOperation buildUnlockOperation(List entityList) { - - return EntityBulkOperation.builder() - .key(BulkOperationKey.PURGE_CLEANUP) - .entityList(entityList) - .consumer(entity -> { - String id = entity.getId().get(); - try { - this.lockManager.unlock(id); - } catch (Exception e) { - if (LOGGER.isTraceEnabled()) { - LOGGER.atTrace() - .withThrowable(e) - .log("Unable to unlock {}", entity); - } - } - }) - .build(); - } + private final HistoryManager historyManager; + + private final AccessControl accessControl; + + private final RecycleBin recycleBin; + + private final SearchIndex searchIndex; + + private final MediaReferenceManager mediaReferenceManager; + + private final Publisher publisher; + + private final ExtensionsNotifier extensionsNotifier; + + private final EntityBulkExecutor entityBulkExecutor; + + private static Logger LOGGER = LogManager.getLogger(); + + @Inject + @SuppressWarnings("PMD.ExcessiveParameterList") + protected BulkPurge( + ContentRepository repository, + EntityLockManager lockManager, + VersioningManager versioningManager, + HistoryManager historyManager, + AccessControl accessControl, + RecycleBin recycleBin, + SearchIndex searchIndex, + MediaReferenceManager mediaReferenceManager, + Publisher publisher, + ExtensionsNotifier extensionsNotifier, + EntityBulkExecutor entityBulkExecutor) { + + this.repository = repository; + this.lockManager = lockManager; + this.historyManager = historyManager; + this.versioningManager = versioningManager; + this.accessControl = accessControl; + this.recycleBin = recycleBin; + this.searchIndex = searchIndex; + this.mediaReferenceManager = mediaReferenceManager; + this.publisher = publisher; + this.extensionsNotifier = extensionsNotifier; + this.entityBulkExecutor = entityBulkExecutor; + } + + /** + * Create a BulkExecution and pass it to the EntityBulkExecutor to execute the purge. + * The return is a BulkExecution ID that can be used to track the progress. + * + * @param input Input argument for the bulk operations + * @return BulkExecution ID that can be used to track the progress + */ + public String bulkPurge(BulkPurgeInput input) { + + List entityList = this.getEntityList(input); + + this.accessControl(entityList); + + EntityBulkOperation lock = this.buildLockOperation(entityList, false); + EntityBulkOperation depublish = this.buildDepublishOperation(entityList); + EntityBulkOperation purge = this.buildPurgeOperation(entityList); + + EntityBulkOperation unlock = this.buildUnlockOperation(entityList); + + EntityBulkExecution execution = + EntityBulkExecution.builder() + .topic("contentrepository", "purge") + .operation(lock, depublish, purge) + .finalizer(unlock) + .build(); + + return this.entityBulkExecutor.execute(execution); + } + + private List getEntityList(BulkPurgeInput input) { + Query query = this.buildQuery(input); + return this.repository.getAll(query); + } + + private Query buildQuery(BulkPurgeInput input) { + if (!input.getRootList().isEmpty()) { + return SubTreeQuery.builder() + .rootList(input.getRootList()) + .filterBy(input.getFilter().orElse(null)) + .build(); + } + + return Query.builder().filterBy(input.getFilter().get()).build(); + } + + private void accessControl(List entityList) { + + entityList.stream() + .forEach( + entity -> { + String id = entity.getId().get(); + if (entity.isGroup()) { + if (!this.accessControl.isGroupRemoveable(id)) { + throw new AccessDeniedException("Not allowed to remove group " + id); + } + } else { + if (!this.accessControl.isEntityRemovable(id)) { + throw new AccessDeniedException("Not allowed to remove entity " + id); + } + } + }); + } + + private EntityBulkOperation buildLockOperation(List entityList, boolean forceLock) { + + return EntityBulkOperation.builder() + .key(BulkOperationKey.PURGE_LOCK) + .entityList(entityList) + .consumer( + entity -> { + String id = entity.getId().get(); + + if (forceLock) { + this.lockManager.forceLock(id); + } else { + this.lockManager.lock(id); + } + }) + .build(); + } + + private EntityBulkOperation buildDepublishOperation(List entityList) { + + return EntityBulkOperation.builder() + .key(BulkOperationKey.PURGE_DEPUBLISH) + .entityList(entityList) + .consumer( + entity -> { + String id = entity.getId().get(); + this.publisher.depublish(id); + }) + .build(); + } + + private EntityBulkOperation buildPurgeOperation(List entityList) { + + List nonGroupList = + entityList.stream().filter(entity -> !entity.isGroup()).collect(Collectors.toList()); + + List groupList = + entityList.stream().filter(entity -> entity.isGroup()).collect(Collectors.toList()); + + /* + * Arrange the entityList so that first all group entries are deleted + * and then the groups in the hierarchy from bottom to top. + * This ensures that only empty pools are deleted. + */ + List orderedGroupList = this.orderGroupListHierarchicallyFromBottomToTop(groupList); + List orderedList = new ArrayList<>(); + orderedList.addAll(nonGroupList); + orderedList.addAll(orderedGroupList); + + if (LOGGER.isDebugEnabled()) { + orderedList.stream() + .forEach( + entity -> { + LOGGER.debug("purge order: {}", entity); + }); + } + + return EntityBulkOperation.builder() + .key(BulkOperationKey.PURGE_PURGE) + .entityList(orderedList) + .consumer( + entity -> { + String id = entity.getId().get(); + + if (this.repository.isGroup(id) && !this.repository.isEmptyGroup(id)) { + throw new GroupNotEmptyException(id); + } + + if (LOGGER.isInfoEnabled()) { + LOGGER.info("purge: {}", entity); + } + + this.searchIndex.remove(id); + this.mediaReferenceManager.removeByReference(id); + this.repository.removeEntity(id); + this.historyManager.purge(id); + this.versioningManager.removeAllVersions(id); + this.recycleBin.removeByObject(id); + this.extensionsNotifier.notifyPurge(id); + }) + .build(); + } + + /** + * Arranges the groups according to their hierarchy from bottom to top. + */ + private List orderGroupListHierarchicallyFromBottomToTop(List groupList) { + + EntityTree tree = new EntityTree(); + groupList.stream().forEach(tree::add); + + List hierarchicalOrder = tree.getAll(); + + Collections.reverse(hierarchicalOrder); + + return hierarchicalOrder; + } + + private EntityBulkOperation buildUnlockOperation(List entityList) { + + return EntityBulkOperation.builder() + .key(BulkOperationKey.PURGE_CLEANUP) + .entityList(entityList) + .consumer( + entity -> { + String id = entity.getId().get(); + try { + this.lockManager.unlock(id); + } catch (Exception e) { + if (LOGGER.isTraceEnabled()) { + LOGGER.atTrace().withThrowable(e).log("Unable to unlock {}", entity); + } + } + }) + .build(); + } } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/usecase/BulkPurgeInput.java b/src/main/java/com/sitepark/ies/contentrepository/core/usecase/BulkPurgeInput.java index f4a6065..c816a36 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/usecase/BulkPurgeInput.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/usecase/BulkPurgeInput.java @@ -1,120 +1,114 @@ package com.sitepark.ies.contentrepository.core.usecase; +import com.sitepark.ies.contentrepository.core.domain.entity.filter.Filter; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.Optional; -import com.sitepark.ies.contentrepository.core.domain.entity.filter.Filter; +public final class BulkPurgeInput { -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + private final List rootList; -public final class BulkPurgeInput { + private final Filter filterBy; + + private final boolean forceLock; + + private BulkPurgeInput(Builder builder) { + this.rootList = Collections.unmodifiableList(builder.rootList); + this.filterBy = builder.filterBy; + this.forceLock = builder.forceLock; + } + + @SuppressFBWarnings("EI_EXPOSE_REP") + public List getRootList() { + return this.rootList; + } + + public Optional getFilter() { + return Optional.ofNullable(this.filterBy); + } + + public boolean isForceLock() { + return this.forceLock; + } + + @Override + public final int hashCode() { + return Objects.hash(this.rootList, this.filterBy, this.forceLock); + } + + @Override + public final boolean equals(Object o) { + + if (!(o instanceof BulkPurgeInput)) { + return false; + } + + BulkPurgeInput that = (BulkPurgeInput) o; + + return Objects.equals(this.rootList, that.rootList) + && Objects.equals(this.filterBy, that.filterBy) + && Objects.equals(this.forceLock, that.forceLock); + } + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder(this); + } + + public static final class Builder { + + private final List rootList = new ArrayList<>(); + + private Filter filterBy; + + private boolean forceLock; + + private Builder() {} + + private Builder(BulkPurgeInput bulkPurgeRequest) { + this.rootList.addAll(bulkPurgeRequest.rootList); + this.filterBy = bulkPurgeRequest.filterBy; + this.forceLock = bulkPurgeRequest.forceLock; + } + + public Builder rootList(List rootList) { + Objects.requireNonNull(rootList, "rootList is null"); + this.rootList.clear(); + for (Long root : rootList) { + this.root(root); + } + return this; + } + + public Builder root(Long root) { + Objects.requireNonNull(root, "root is null"); + this.rootList.add(root); + return this; + } + + public Builder filterBy(Filter filterBy) { + Objects.requireNonNull(filterBy, "filterBy is null"); + this.filterBy = filterBy; + return this; + } - private final List rootList; + public Builder forceLock(boolean forceLock) { + this.forceLock = forceLock; + return this; + } - private final Filter filterBy; - - private final boolean forceLock; - - private BulkPurgeInput(Builder builder) { - this.rootList = Collections.unmodifiableList(builder.rootList); - this.filterBy = builder.filterBy; - this.forceLock = builder.forceLock; - } - - @SuppressFBWarnings("EI_EXPOSE_REP") - public List getRootList() { - return this.rootList; - } - - public Optional getFilter() { - return Optional.ofNullable(this.filterBy); - } - - public boolean isForceLock() { - return this.forceLock; - } - - @Override - public final int hashCode() { - return Objects.hash( - this.rootList, - this.filterBy, - this.forceLock); - } - - @Override - public final boolean equals(Object o) { - - if (!(o instanceof BulkPurgeInput)) { - return false; - } - - BulkPurgeInput that = (BulkPurgeInput)o; - - return Objects.equals(this.rootList, that.rootList) && - Objects.equals(this.filterBy, that.filterBy) && - Objects.equals(this.forceLock, that.forceLock); - } - - public static Builder builder() { - return new Builder(); - } - - public Builder toBuilder() { - return new Builder(this); - } - - public static final class Builder { - - private final List rootList = new ArrayList<>(); - - private Filter filterBy; - - private boolean forceLock; - - private Builder() { } - - private Builder(BulkPurgeInput bulkPurgeRequest) { - this.rootList.addAll(bulkPurgeRequest.rootList); - this.filterBy = bulkPurgeRequest.filterBy; - this.forceLock = bulkPurgeRequest.forceLock; - } - - public Builder rootList(List rootList) { - Objects.requireNonNull(rootList, "rootList is null"); - this.rootList.clear(); - for (Long root : rootList) { - this.root(root); - } - return this; - } - - public Builder root(Long root) { - Objects.requireNonNull(root, "root is null"); - this.rootList.add(root); - return this; - } - - public Builder filterBy(Filter filterBy) { - Objects.requireNonNull(filterBy, "filterBy is null"); - this.filterBy = filterBy; - return this; - } - - public Builder forceLock(boolean forceLock) { - this.forceLock = forceLock; - return this; - } - - public BulkPurgeInput build() { - if (this.rootList.isEmpty() && this.filterBy == null) { - throw new IllegalStateException( - "Either rootList or filterBy must be specified"); - } - return new BulkPurgeInput(this); - } - } + public BulkPurgeInput build() { + if (this.rootList.isEmpty() && this.filterBy == null) { + throw new IllegalStateException("Either rootList or filterBy must be specified"); + } + return new BulkPurgeInput(this); + } + } } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/usecase/GetAllEntities.java b/src/main/java/com/sitepark/ies/contentrepository/core/usecase/GetAllEntities.java index 152f814..aa4bad1 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/usecase/GetAllEntities.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/usecase/GetAllEntities.java @@ -1,23 +1,21 @@ package com.sitepark.ies.contentrepository.core.usecase; -import java.util.List; - import com.sitepark.ies.contentrepository.core.domain.entity.Entity; import com.sitepark.ies.contentrepository.core.domain.entity.query.Query; import com.sitepark.ies.contentrepository.core.port.ContentRepository; - import jakarta.inject.Inject; +import java.util.List; public final class GetAllEntities { - private final ContentRepository repository; + private final ContentRepository repository; - @Inject - protected GetAllEntities(ContentRepository repository) { - this.repository = repository; - } + @Inject + protected GetAllEntities(ContentRepository repository) { + this.repository = repository; + } - public List getAllEntities(Query query) { - return this.repository.getAll(query); - } + public List getAllEntities(Query query) { + return this.repository.getAll(query); + } } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/usecase/PurgeEntity.java b/src/main/java/com/sitepark/ies/contentrepository/core/usecase/PurgeEntity.java index f4aa670..babda83 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/usecase/PurgeEntity.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/usecase/PurgeEntity.java @@ -1,8 +1,5 @@ package com.sitepark.ies.contentrepository.core.usecase; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - import com.sitepark.ies.contentrepository.core.domain.exception.AccessDeniedException; import com.sitepark.ies.contentrepository.core.domain.exception.GroupNotEmptyException; import com.sitepark.ies.contentrepository.core.port.AccessControl; @@ -15,87 +12,95 @@ import com.sitepark.ies.contentrepository.core.port.RecycleBin; import com.sitepark.ies.contentrepository.core.port.SearchIndex; import com.sitepark.ies.contentrepository.core.port.VersioningManager; - import jakarta.inject.Inject; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; public final class PurgeEntity { - private final ContentRepository repository; + private final ContentRepository repository; - private final EntityLockManager lockManager; + private final EntityLockManager lockManager; - private final VersioningManager versioningManager; + private final VersioningManager versioningManager; - private final HistoryManager historyManager; + private final HistoryManager historyManager; - private final AccessControl accessControl; + private final AccessControl accessControl; - private final RecycleBin recycleBin; + private final RecycleBin recycleBin; - private final SearchIndex searchIndex; + private final SearchIndex searchIndex; - private final MediaReferenceManager mediaReferenceManager; + private final MediaReferenceManager mediaReferenceManager; - private final Publisher publisher; + private final Publisher publisher; - private final ExtensionsNotifier extensionsNotifier; + private final ExtensionsNotifier extensionsNotifier; - private static Logger LOGGER = LogManager.getLogger(); + private static Logger LOGGER = LogManager.getLogger(); - @Inject - @SuppressWarnings("PMD.ExcessiveParameterList") - protected PurgeEntity(ContentRepository repository, EntityLockManager lockManager, - VersioningManager versioningManager, HistoryManager historyManager, AccessControl accessControl, - RecycleBin recycleBin, SearchIndex searchIndex, MediaReferenceManager mediaReferenceManager, - Publisher publisher, ExtensionsNotifier extensionsNotifier) { + @Inject + @SuppressWarnings("PMD.ExcessiveParameterList") + protected PurgeEntity( + ContentRepository repository, + EntityLockManager lockManager, + VersioningManager versioningManager, + HistoryManager historyManager, + AccessControl accessControl, + RecycleBin recycleBin, + SearchIndex searchIndex, + MediaReferenceManager mediaReferenceManager, + Publisher publisher, + ExtensionsNotifier extensionsNotifier) { - this.repository = repository; - this.lockManager = lockManager; - this.historyManager = historyManager; - this.versioningManager = versioningManager; - this.accessControl = accessControl; - this.recycleBin = recycleBin; - this.searchIndex = searchIndex; - this.mediaReferenceManager = mediaReferenceManager; - this.publisher = publisher; - this.extensionsNotifier = extensionsNotifier; - } + this.repository = repository; + this.lockManager = lockManager; + this.historyManager = historyManager; + this.versioningManager = versioningManager; + this.accessControl = accessControl; + this.recycleBin = recycleBin; + this.searchIndex = searchIndex; + this.mediaReferenceManager = mediaReferenceManager; + this.publisher = publisher; + this.extensionsNotifier = extensionsNotifier; + } - public void purgeEntity(String id) { + public void purgeEntity(String id) { - if (!this.accessControl.isEntityRemovable(id)) { - throw new AccessDeniedException("Not allowed to remove entity " + id); - } + if (!this.accessControl.isEntityRemovable(id)) { + throw new AccessDeniedException("Not allowed to remove entity " + id); + } - if (this.repository.isGroup(id) && !this.repository.isEmptyGroup(id)) { - throw new GroupNotEmptyException(id); - } + if (this.repository.isGroup(id) && !this.repository.isEmptyGroup(id)) { + throw new GroupNotEmptyException(id); + } - try { - this.lockManager.lock(id); + try { + this.lockManager.lock(id); - this.publisher.depublish(id); + this.publisher.depublish(id); - if (LOGGER.isInfoEnabled()) { - LOGGER.info("purge: {}", this.repository.get(id)); - } + if (LOGGER.isInfoEnabled()) { + LOGGER.info("purge: {}", this.repository.get(id)); + } - this.searchIndex.remove(id); + this.searchIndex.remove(id); - this.mediaReferenceManager.removeByReference(id); + this.mediaReferenceManager.removeByReference(id); - this.repository.removeEntity(id); + this.repository.removeEntity(id); - this.historyManager.purge(id); + this.historyManager.purge(id); - this.versioningManager.removeAllVersions(id); + this.versioningManager.removeAllVersions(id); - this.recycleBin.removeByObject(id); + this.recycleBin.removeByObject(id); - this.extensionsNotifier.notifyPurge(id); + this.extensionsNotifier.notifyPurge(id); - } finally { - this.lockManager.unlock(id); - } - } + } finally { + this.lockManager.unlock(id); + } + } } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/usecase/RecoverEntity.java b/src/main/java/com/sitepark/ies/contentrepository/core/usecase/RecoverEntity.java index 542a2d0..33760a0 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/usecase/RecoverEntity.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/usecase/RecoverEntity.java @@ -1,8 +1,5 @@ package com.sitepark.ies.contentrepository.core.usecase; -import java.time.OffsetDateTime; -import java.util.Optional; - import com.sitepark.ies.contentrepository.core.domain.entity.Entity; import com.sitepark.ies.contentrepository.core.domain.entity.HistoryEntryType; import com.sitepark.ies.contentrepository.core.domain.entity.RecycleBinItem; @@ -13,48 +10,53 @@ import com.sitepark.ies.contentrepository.core.port.HistoryManager; import com.sitepark.ies.contentrepository.core.port.RecycleBin; import com.sitepark.ies.contentrepository.core.port.SearchIndex; +import java.time.OffsetDateTime; +import java.util.Optional; public class RecoverEntity { - private final ContentRepository repository; + private final ContentRepository repository; - private final HistoryManager historyManager; + private final HistoryManager historyManager; - private final AccessControl accessControl; + private final AccessControl accessControl; - private final RecycleBin recycleBin; + private final RecycleBin recycleBin; - private final SearchIndex searchIndex; + private final SearchIndex searchIndex; - protected RecoverEntity( - ContentRepository repository, - HistoryManager historyManager, - AccessControl accessControl, - RecycleBin recycleBin, - SearchIndex searchIndex) { - this.repository = repository; - this.historyManager = historyManager; - this.accessControl = accessControl; - this.recycleBin = recycleBin; - this.searchIndex = searchIndex; - } + protected RecoverEntity( + ContentRepository repository, + HistoryManager historyManager, + AccessControl accessControl, + RecycleBin recycleBin, + SearchIndex searchIndex) { + this.repository = repository; + this.historyManager = historyManager; + this.accessControl = accessControl; + this.recycleBin = recycleBin; + this.searchIndex = searchIndex; + } - public void recover(String id) { + public void recover(String id) { - Optional recycleBinItem = this.recycleBin.get(id); - recycleBinItem.orElseThrow(() -> new EntityNotFoundException(id)); + Optional recycleBinItem = this.recycleBin.get(id); + recycleBinItem.orElseThrow(() -> new EntityNotFoundException(id)); - if (!this.accessControl.isGroupCreateable(recycleBinItem.get().getParent())) { - throw new AccessDeniedException("Not allowed to recover entity " + recycleBinItem.get().getId() - + " in group " + recycleBinItem.get().getParent()); - } + if (!this.accessControl.isGroupCreateable(recycleBinItem.get().getParent())) { + throw new AccessDeniedException( + "Not allowed to recover entity " + + recycleBinItem.get().getId() + + " in group " + + recycleBinItem.get().getParent()); + } - Entity entity = recycleBinItem.get().getEntity(); + Entity entity = recycleBinItem.get().getEntity(); - this.repository.store(entity); + this.repository.store(entity); - this.historyManager.createEntry(id, OffsetDateTime.now(), HistoryEntryType.RESTORED); + this.historyManager.createEntry(id, OffsetDateTime.now(), HistoryEntryType.RESTORED); - this.searchIndex.index(id); - } + this.searchIndex.index(id); + } } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/usecase/RemoveEntity.java b/src/main/java/com/sitepark/ies/contentrepository/core/usecase/RemoveEntity.java index 54ed780..1a2098e 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/usecase/RemoveEntity.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/usecase/RemoveEntity.java @@ -1,8 +1,5 @@ package com.sitepark.ies.contentrepository.core.usecase; -import java.time.OffsetDateTime; -import java.util.Optional; - import com.sitepark.ies.contentrepository.core.domain.entity.Entity; import com.sitepark.ies.contentrepository.core.domain.entity.EntityLock; import com.sitepark.ies.contentrepository.core.domain.entity.HistoryEntryType; @@ -16,60 +13,68 @@ import com.sitepark.ies.contentrepository.core.port.Publisher; import com.sitepark.ies.contentrepository.core.port.RecycleBin; import com.sitepark.ies.contentrepository.core.port.SearchIndex; +import java.time.OffsetDateTime; +import java.util.Optional; public final class RemoveEntity { - private final ContentRepository repository; - private final EntityLockManager lockManager; - private final HistoryManager historyManager; - private final AccessControl accessControl; - private final RecycleBin recycleBin; - private final SearchIndex searchIndex; - private final Publisher publisher; - - protected RemoveEntity(ContentRepository repository, EntityLockManager lockManager, - HistoryManager historyManager, AccessControl accessControl, - RecycleBin recycleBin, SearchIndex searchIndex, Publisher publisher) { - - this.repository = repository; - this.lockManager = lockManager; - this.historyManager = historyManager; - this.accessControl = accessControl; - this.recycleBin = recycleBin; - this.searchIndex = searchIndex; - this.publisher = publisher; - } - - public void remove(String id) { - - if (!this.accessControl.isEntityRemovable(id)) { - throw new AccessDeniedException("Not allowed to remove entity " + id); - } - - Optional entity = this.repository.get(id); - if (entity.isEmpty()) { - return; - } - - try { - Optional lock = this.lockManager.getLock(id); - lock.ifPresent(l -> { - throw new EntityLockedException(l); - }); - - this.searchIndex.remove(id); - - this.publisher.depublish(id); - - this.repository.removeEntity(id); - - this.historyManager.createEntry(id, OffsetDateTime.now(), HistoryEntryType.REMOVED); - - RecycleBinItem recycleBinItem = RecycleBinItem.builder().build(); - this.recycleBin.add(recycleBinItem); - - } finally { - this.lockManager.unlock(id); - } - } + private final ContentRepository repository; + private final EntityLockManager lockManager; + private final HistoryManager historyManager; + private final AccessControl accessControl; + private final RecycleBin recycleBin; + private final SearchIndex searchIndex; + private final Publisher publisher; + + protected RemoveEntity( + ContentRepository repository, + EntityLockManager lockManager, + HistoryManager historyManager, + AccessControl accessControl, + RecycleBin recycleBin, + SearchIndex searchIndex, + Publisher publisher) { + + this.repository = repository; + this.lockManager = lockManager; + this.historyManager = historyManager; + this.accessControl = accessControl; + this.recycleBin = recycleBin; + this.searchIndex = searchIndex; + this.publisher = publisher; + } + + public void remove(String id) { + + if (!this.accessControl.isEntityRemovable(id)) { + throw new AccessDeniedException("Not allowed to remove entity " + id); + } + + Optional entity = this.repository.get(id); + if (entity.isEmpty()) { + return; + } + + try { + Optional lock = this.lockManager.getLock(id); + lock.ifPresent( + l -> { + throw new EntityLockedException(l); + }); + + this.searchIndex.remove(id); + + this.publisher.depublish(id); + + this.repository.removeEntity(id); + + this.historyManager.createEntry(id, OffsetDateTime.now(), HistoryEntryType.REMOVED); + + RecycleBinItem recycleBinItem = RecycleBinItem.builder().build(); + this.recycleBin.add(recycleBinItem); + + } finally { + this.lockManager.unlock(id); + } + } } diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/usecase/StoreEntity.java b/src/main/java/com/sitepark/ies/contentrepository/core/usecase/StoreEntity.java index a74477b..9bb7276 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/usecase/StoreEntity.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/usecase/StoreEntity.java @@ -1,7 +1,5 @@ package com.sitepark.ies.contentrepository.core.usecase; -import java.util.Optional; - import com.sitepark.ies.contentrepository.core.domain.entity.ChangeSet; import com.sitepark.ies.contentrepository.core.domain.entity.Entity; import com.sitepark.ies.contentrepository.core.domain.entity.EntityLock; @@ -18,100 +16,108 @@ import com.sitepark.ies.contentrepository.core.port.IdGenerator; import com.sitepark.ies.contentrepository.core.port.SearchIndex; import com.sitepark.ies.contentrepository.core.port.VersioningManager; +import java.util.Optional; public final class StoreEntity { - private final ContentRepository repository; - private final EntityLockManager lockManager; - private final VersioningManager versioningManager; - private final HistoryManager historyManager; - private final AccessControl accessControl; - private final IdGenerator idGenerator; - private final SearchIndex searchIndex; - private final ContentDiffer contentDiffer; - - protected StoreEntity(ContentRepository repository, EntityLockManager lockManager, - VersioningManager versioningManager, HistoryManager historyManager, AccessControl accessControl, - IdGenerator idGenerator, SearchIndex searchIndex, ContentDiffer contentDiffer) { - this.repository = repository; - this.lockManager = lockManager; - this.versioningManager = versioningManager; - this.historyManager = historyManager; - this.accessControl = accessControl; - this.idGenerator = idGenerator; - this.searchIndex = searchIndex; - this.contentDiffer = contentDiffer; - } - - public String store(Entity entity) { - if (entity.getId().isEmpty()) { - return this.create(entity); - } else { - return this.update(entity); - } - } - - private String create(Entity newEntity) { - - Optional parent = newEntity.getParent(); - parent.orElseThrow(() -> new ParentMissingException()); - - String parentId = parent.get(); - - if (!this.accessControl.isEntityCreateable(parentId)) { - throw new AccessDeniedException("Not allowed to create entity in group " + parent); - } - - String generatedId = this.idGenerator.generate(); - - Entity entityWithId = newEntity.toBuilder().id(generatedId).build(); - - Entity versioned = this.versioningManager.createNewVersion(entityWithId); - - this.repository.store(versioned); - this.historyManager.createEntry(generatedId, versioned.getVersion().get(), - HistoryEntryType.CREATED); - this.searchIndex.index(generatedId); - - return versioned.getId().get(); - } - - private String update(Entity updateEntity) { - - updateEntity.getId() - .orElseThrow(() -> new IllegalArgumentException("Update failed, identifier missing")); - - String id = updateEntity.getId().get(); - - Optional existsEntity = this.repository.get(id); - existsEntity.orElseThrow(() -> new EntityNotFoundException(id)); - - if (!this.accessControl.isEntityWritable(id)) { - throw new AccessDeniedException("Not allowed to update entity " + id); - } - - try { - Optional lock = this.lockManager.getLock(id); - lock.ifPresent(l -> { - throw new EntityLockedException(l); - }); - - ChangeSet changeSet = this.contentDiffer.diff(updateEntity, existsEntity.get()); - if (changeSet.isEmpty()) { - return updateEntity.getId().get(); - } - - Entity versioned = this.versioningManager.createNewVersion(updateEntity); - - this.repository.store(versioned); - this.historyManager.createEntry(id, versioned.getVersion().get(), - HistoryEntryType.UPDATED); - this.searchIndex.index(id); - - return versioned.getId().get(); - - } finally { - this.lockManager.unlock(id); - } - } + private final ContentRepository repository; + private final EntityLockManager lockManager; + private final VersioningManager versioningManager; + private final HistoryManager historyManager; + private final AccessControl accessControl; + private final IdGenerator idGenerator; + private final SearchIndex searchIndex; + private final ContentDiffer contentDiffer; + + protected StoreEntity( + ContentRepository repository, + EntityLockManager lockManager, + VersioningManager versioningManager, + HistoryManager historyManager, + AccessControl accessControl, + IdGenerator idGenerator, + SearchIndex searchIndex, + ContentDiffer contentDiffer) { + this.repository = repository; + this.lockManager = lockManager; + this.versioningManager = versioningManager; + this.historyManager = historyManager; + this.accessControl = accessControl; + this.idGenerator = idGenerator; + this.searchIndex = searchIndex; + this.contentDiffer = contentDiffer; + } + + public String store(Entity entity) { + if (entity.getId().isEmpty()) { + return this.create(entity); + } else { + return this.update(entity); + } + } + + private String create(Entity newEntity) { + + Optional parent = newEntity.getParent(); + parent.orElseThrow(() -> new ParentMissingException()); + + String parentId = parent.get(); + + if (!this.accessControl.isEntityCreateable(parentId)) { + throw new AccessDeniedException("Not allowed to create entity in group " + parent); + } + + String generatedId = this.idGenerator.generate(); + + Entity entityWithId = newEntity.toBuilder().id(generatedId).build(); + + Entity versioned = this.versioningManager.createNewVersion(entityWithId); + + this.repository.store(versioned); + this.historyManager.createEntry( + generatedId, versioned.getVersion().get(), HistoryEntryType.CREATED); + this.searchIndex.index(generatedId); + + return versioned.getId().get(); + } + + private String update(Entity updateEntity) { + + updateEntity + .getId() + .orElseThrow(() -> new IllegalArgumentException("Update failed, identifier missing")); + + String id = updateEntity.getId().get(); + + Optional existsEntity = this.repository.get(id); + existsEntity.orElseThrow(() -> new EntityNotFoundException(id)); + + if (!this.accessControl.isEntityWritable(id)) { + throw new AccessDeniedException("Not allowed to update entity " + id); + } + + try { + Optional lock = this.lockManager.getLock(id); + lock.ifPresent( + l -> { + throw new EntityLockedException(l); + }); + + ChangeSet changeSet = this.contentDiffer.diff(updateEntity, existsEntity.get()); + if (changeSet.isEmpty()) { + return updateEntity.getId().get(); + } + + Entity versioned = this.versioningManager.createNewVersion(updateEntity); + + this.repository.store(versioned); + this.historyManager.createEntry(id, versioned.getVersion().get(), HistoryEntryType.UPDATED); + this.searchIndex.index(id); + + return versioned.getId().get(); + + } finally { + this.lockManager.unlock(id); + } + } } diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index 9fe359a..095dd31 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -1,24 +1,23 @@ module com.sitepark.ies.contentrepository.core { + exports com.sitepark.ies.contentrepository.core.domain.entity; + exports com.sitepark.ies.contentrepository.core.domain.entity.filter; + exports com.sitepark.ies.contentrepository.core.domain.entity.sort; + exports com.sitepark.ies.contentrepository.core.domain.entity.query; + exports com.sitepark.ies.contentrepository.core.domain.exception; + exports com.sitepark.ies.contentrepository.core.port; + exports com.sitepark.ies.contentrepository.core.usecase; - exports com.sitepark.ies.contentrepository.core.domain.entity; - exports com.sitepark.ies.contentrepository.core.domain.entity.filter; - exports com.sitepark.ies.contentrepository.core.domain.entity.sort; - exports com.sitepark.ies.contentrepository.core.domain.entity.query; - exports com.sitepark.ies.contentrepository.core.domain.exception; - exports com.sitepark.ies.contentrepository.core.port; - exports com.sitepark.ies.contentrepository.core.usecase; + requires jakarta.inject; + requires org.eclipse.jdt.annotation; + requires com.github.spotbugs.annotations; + requires com.fasterxml.jackson.databind; + requires com.fasterxml.jackson.annotation; + requires com.fasterxml.jackson.datatype.jdk8; + requires org.apache.logging.log4j; + requires com.fasterxml.jackson.datatype.jsr310; - requires jakarta.inject; - requires org.eclipse.jdt.annotation; - requires com.github.spotbugs.annotations; - requires com.fasterxml.jackson.databind; - requires com.fasterxml.jackson.annotation; - requires com.fasterxml.jackson.datatype.jdk8; - requires org.apache.logging.log4j; - requires com.fasterxml.jackson.datatype.jsr310; - - opens com.sitepark.ies.contentrepository.core.domain.entity; - opens com.sitepark.ies.contentrepository.core.domain.entity.filter; - opens com.sitepark.ies.contentrepository.core.domain.entity.sort; - opens com.sitepark.ies.contentrepository.core.domain.entity.query; -} \ No newline at end of file + opens com.sitepark.ies.contentrepository.core.domain.entity; + opens com.sitepark.ies.contentrepository.core.domain.entity.filter; + opens com.sitepark.ies.contentrepository.core.domain.entity.sort; + opens com.sitepark.ies.contentrepository.core.domain.entity.query; +} diff --git a/src/test/java/com/sitepark/ies/contentrepository/core/domain/databind/UniquePropertyPolymorphicDeserializerTest.java b/src/test/java/com/sitepark/ies/contentrepository/core/domain/databind/UniquePropertyPolymorphicDeserializerTest.java index e767a09..29a1706 100644 --- a/src/test/java/com/sitepark/ies/contentrepository/core/domain/databind/UniquePropertyPolymorphicDeserializerTest.java +++ b/src/test/java/com/sitepark/ies/contentrepository/core/domain/databind/UniquePropertyPolymorphicDeserializerTest.java @@ -5,88 +5,84 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import java.io.IOException; -import java.util.Arrays; -import java.util.Iterator; -import java.util.Map.Entry; - -import org.junit.jupiter.api.Test; - import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; +import java.io.IOException; +import java.util.Arrays; +import java.util.Iterator; +import java.util.Map.Entry; +import org.junit.jupiter.api.Test; class UniquePropertyPolymorphicDeserializerTest { - @Test - @SuppressWarnings("PMD.CloseResource") - void test() throws IOException { + @Test + @SuppressWarnings("PMD.CloseResource") + void test() throws IOException { - UniquePropertyPolymorphicDeserializer deserializer = - new UniquePropertyPolymorphicDeserializer<>(A.class); + UniquePropertyPolymorphicDeserializer deserializer = + new UniquePropertyPolymorphicDeserializer<>(A.class); - deserializer.register("b", B.class); - deserializer.register("c", C.class); + deserializer.register("b", B.class); + deserializer.register("c", C.class); - JsonParser jp = mock(); - DeserializationContext ctxt = mock(); - ObjectMapper mapper = mock(); - ObjectNode obj = mock(); + JsonParser jp = mock(); + DeserializationContext ctxt = mock(); + ObjectMapper mapper = mock(); + ObjectNode obj = mock(); - Entry element = mock(); + Entry element = mock(); - Iterator> elementsIterator = - Arrays.asList(element).iterator(); + Iterator> elementsIterator = Arrays.asList(element).iterator(); - when(mapper.readTree(any(JsonParser.class))).thenReturn(obj); - when(jp.getCodec()).thenReturn(mapper); - when(obj.fields()).thenReturn(elementsIterator); - when(element.getKey()).thenReturn("c"); + when(mapper.readTree(any(JsonParser.class))).thenReturn(obj); + when(jp.getCodec()).thenReturn(mapper); + when(obj.fields()).thenReturn(elementsIterator); + when(element.getKey()).thenReturn("c"); - deserializer.deserialize(jp, ctxt); + deserializer.deserialize(jp, ctxt); - verify(mapper).treeToValue(obj, C.class); - } + verify(mapper).treeToValue(obj, C.class); + } - @Test - @SuppressWarnings("PMD.CloseResource") - void testNotRegistered() throws IOException { + @Test + @SuppressWarnings("PMD.CloseResource") + void testNotRegistered() throws IOException { - UniquePropertyPolymorphicDeserializer deserializer = - new UniquePropertyPolymorphicDeserializer<>(A.class); + UniquePropertyPolymorphicDeserializer deserializer = + new UniquePropertyPolymorphicDeserializer<>(A.class); - deserializer.register("b", B.class); - deserializer.register("c", C.class); + deserializer.register("b", B.class); + deserializer.register("c", C.class); - JsonParser jp = mock(); - DeserializationContext ctxt = mock(); - ObjectMapper mapper = mock(); - ObjectNode obj = mock(); + JsonParser jp = mock(); + DeserializationContext ctxt = mock(); + ObjectMapper mapper = mock(); + ObjectNode obj = mock(); - Entry element = mock(); + Entry element = mock(); - Iterator> elementsIterator = - Arrays.asList(element).iterator(); + Iterator> elementsIterator = Arrays.asList(element).iterator(); - when(mapper.readTree(any(JsonParser.class))).thenReturn(obj); - when(jp.getCodec()).thenReturn(mapper); - when(obj.fields()).thenReturn(elementsIterator); - when(element.getKey()).thenReturn("d"); + when(mapper.readTree(any(JsonParser.class))).thenReturn(obj); + when(jp.getCodec()).thenReturn(mapper); + when(obj.fields()).thenReturn(elementsIterator); + when(element.getKey()).thenReturn("d"); - deserializer.deserialize(jp, ctxt); + deserializer.deserialize(jp, ctxt); - verify(ctxt).reportInputMismatch( - any(UniquePropertyPolymorphicDeserializer.class), - any(String.class)); - } - private static class A { }; + verify(ctxt) + .reportInputMismatch(any(UniquePropertyPolymorphicDeserializer.class), any(String.class)); + } - private static final class B extends A { - }; + private static class A {} + ; - private static final class C extends A { - }; + private static final class B extends A {} + ; + private static final class C extends A {} + ; } diff --git a/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/AnchorTest.java b/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/AnchorTest.java index f376f07..76e8078 100644 --- a/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/AnchorTest.java +++ b/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/AnchorTest.java @@ -4,78 +4,86 @@ import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.jupiter.api.Test; - import com.sitepark.ies.contentrepository.core.domain.exception.InvalidAnchorException; - import nl.jqno.equalsverifier.EqualsVerifier; +import org.junit.jupiter.api.Test; @SuppressWarnings("PMD.AvoidDuplicateLiterals") class AnchorTest { - @Test - @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") - void testEquals() { - EqualsVerifier.forClass(Anchor.class) - .verify(); - } - - @Test - void testToString() { - Anchor anchor = Anchor.ofString("abc"); - assertEquals("abc", anchor.toString(), "name of anchor expected"); - } - - @Test - void testToStringForEmptyAnchor() { - Anchor anchor = Anchor.EMPTY; - assertEquals("EMPTY", anchor.toString(), "EMPTY expected"); - } - - @Test - void testOfString() { - Anchor anchor = Anchor.ofString("abc"); - assertEquals("abc", anchor.getName(), "expected name"); - } - - @Test - void testOfStringWithNull() { - Anchor anchor = Anchor.ofString(null); - assertNull(anchor, "anchor should be null"); - } - - @Test - void testOfStringWithBlank() { - Anchor anchor = Anchor.ofString(" "); - assertEquals(Anchor.EMPTY, anchor, "anchor should be empty"); - } - - @Test - void testOfStringWithOnlyNumbers() { - assertThrows(InvalidAnchorException.class, () -> { - Anchor.ofString("123"); - }, "anchor must not only contain numbers"); - } - - @Test - void testOfStringWithContainsSpace() { - assertThrows(InvalidAnchorException.class, () -> { - Anchor.ofString("12 3"); - }, "anchor must not contain spaces"); - } - - @Test - void testOfStringWithAmp() { - assertThrows(InvalidAnchorException.class, () -> { - Anchor.ofString("12&3"); - }, "anchor must not contain amp"); - } - - @Test - void testOfStringWithOtherSpezialCharacter() { - assertThrows(InvalidAnchorException.class, () -> { - Anchor.ofString("12$3"); - }, "anchor must not contain special characters"); - } - + @Test + @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") + void testEquals() { + EqualsVerifier.forClass(Anchor.class).verify(); + } + + @Test + void testToString() { + Anchor anchor = Anchor.ofString("abc"); + assertEquals("abc", anchor.toString(), "name of anchor expected"); + } + + @Test + void testToStringForEmptyAnchor() { + Anchor anchor = Anchor.EMPTY; + assertEquals("EMPTY", anchor.toString(), "EMPTY expected"); + } + + @Test + void testOfString() { + Anchor anchor = Anchor.ofString("abc"); + assertEquals("abc", anchor.getName(), "expected name"); + } + + @Test + void testOfStringWithNull() { + Anchor anchor = Anchor.ofString(null); + assertNull(anchor, "anchor should be null"); + } + + @Test + void testOfStringWithBlank() { + Anchor anchor = Anchor.ofString(" "); + assertEquals(Anchor.EMPTY, anchor, "anchor should be empty"); + } + + @Test + void testOfStringWithOnlyNumbers() { + assertThrows( + InvalidAnchorException.class, + () -> { + Anchor.ofString("123"); + }, + "anchor must not only contain numbers"); + } + + @Test + void testOfStringWithContainsSpace() { + assertThrows( + InvalidAnchorException.class, + () -> { + Anchor.ofString("12 3"); + }, + "anchor must not contain spaces"); + } + + @Test + void testOfStringWithAmp() { + assertThrows( + InvalidAnchorException.class, + () -> { + Anchor.ofString("12&3"); + }, + "anchor must not contain amp"); + } + + @Test + void testOfStringWithOtherSpezialCharacter() { + assertThrows( + InvalidAnchorException.class, + () -> { + Anchor.ofString("12$3"); + }, + "anchor must not contain special characters"); + } } diff --git a/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/BulkOperationKeyTest.java b/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/BulkOperationKeyTest.java index 6b8cf76..cda9502 100644 --- a/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/BulkOperationKeyTest.java +++ b/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/BulkOperationKeyTest.java @@ -6,11 +6,9 @@ class BulkOperationKeyTest { - @Test - void testGetName() { - assertEquals( - "contentrepository.purge.lock", - BulkOperationKey.PURGE_LOCK.getName(), - "unexpected name"); - } + @Test + void testGetName() { + assertEquals( + "contentrepository.purge.lock", BulkOperationKey.PURGE_LOCK.getName(), "unexpected name"); + } } diff --git a/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/ChangeSetTest.java b/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/ChangeSetTest.java index 4017383..eabc42f 100644 --- a/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/ChangeSetTest.java +++ b/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/ChangeSetTest.java @@ -6,10 +6,9 @@ class ChangeSetTest { - @Test - void testIsEmpty() { - ChangeSet changeSet = new ChangeSet(); - assertTrue(changeSet.isEmpty(), "changeSet should be empty"); - } - + @Test + void testIsEmpty() { + ChangeSet changeSet = new ChangeSet(); + assertTrue(changeSet.isEmpty(), "changeSet should be empty"); + } } diff --git a/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/EntityBulkExecutionTest.java b/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/EntityBulkExecutionTest.java index 71456e7..b742359 100644 --- a/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/EntityBulkExecutionTest.java +++ b/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/EntityBulkExecutionTest.java @@ -6,139 +6,135 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; -import java.util.Arrays; -import java.util.List; - -import org.junit.jupiter.api.Test; - import com.jparams.verifier.tostring.NameStyle; import com.jparams.verifier.tostring.ToStringVerifier; - import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import java.util.Arrays; +import java.util.List; import nl.jqno.equalsverifier.EqualsVerifier; +import org.junit.jupiter.api.Test; @SuppressWarnings("PMD.AvoidDuplicateLiterals") @SuppressFBWarnings({ - "PI_DO_NOT_REUSE_PUBLIC_IDENTIFIERS_CLASS_NAMES", - "NP_NULL_PARAM_DEREF_NONVIRTUAL", - "NP_NULL_PARAM_DEREF_ALL_TARGETS_DANGEROUS" + "PI_DO_NOT_REUSE_PUBLIC_IDENTIFIERS_CLASS_NAMES", + "NP_NULL_PARAM_DEREF_NONVIRTUAL", + "NP_NULL_PARAM_DEREF_ALL_TARGETS_DANGEROUS" }) class EntityBulkExecutionTest { - @Test - @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") - void testEquals() { - EqualsVerifier.forClass(EntityBulkExecution.class) - .verify(); - } - - @Test - @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") - public void testToString() { - ToStringVerifier.forClass(EntityBulkExecution.class) - .withClassName(NameStyle.SIMPLE_NAME) - .verify(); - } - - @Test - void testSetTopic() { - EntityBulkOperation op = mock(EntityBulkOperation.class); - EntityBulkExecution execution = EntityBulkExecution.builder() - .topic("topic") - .operation(op) - .build(); - - String[] expected = new String[] {"topic"}; - - assertArrayEquals(expected, execution.getTopic(), "unexpected topics"); - } - - @Test - void testSetNullTopic() { - assertThrows(NullPointerException.class, () -> { - EntityBulkExecution.builder().topic((String[])null); - }, "topic must not be null"); - } - - @Test - void testSetNullTopicPart() { - assertThrows(NullPointerException.class, () -> { - EntityBulkExecution.builder().topic((String)null); - }, "topic part must not be null"); - } - - @Test - void testMissingTopic() { - assertThrows(IllegalStateException.class, () -> { - EntityBulkOperation op = mock(EntityBulkOperation.class); - EntityBulkExecution.builder() - .operation(op) - .build(); - }, "topic must be set"); - } - - @Test - void testSetOperation() { - EntityBulkOperation op = mock(EntityBulkOperation.class); - EntityBulkExecution execution = EntityBulkExecution.builder() - .topic("topic") - .operation(op) - .build(); - - List expected = Arrays.asList(op); - - assertEquals(expected, execution.getOperations(), "unexpected operations"); - } - - @Test - void testSetNullOperation() { - assertThrows(NullPointerException.class, () -> { - EntityBulkExecution.builder().operation((EntityBulkOperation)null); - }, "operation must not be null"); - } - - @Test - void testSetNullOperationArray() { - assertThrows(NullPointerException.class, () -> { - EntityBulkExecution.builder().operation((EntityBulkOperation[])null); - }, "operations must not be null"); - } - - @Test - void testMissingOperation() { - assertThrows(IllegalStateException.class, () -> { - EntityBulkExecution.builder() - .topic("topic") - .build(); - }, "operation must be set"); - } - - @Test - void testSetFinalizer() { - EntityBulkOperation op = mock(EntityBulkOperation.class); - EntityBulkOperation finalizer = mock(EntityBulkOperation.class); - EntityBulkExecution execution = EntityBulkExecution.builder() - .topic("topic") - .operation(op) - .finalizer(finalizer) - .build(); - - assertEquals( - finalizer, - execution.getFinalizer().get(), - "unexpected finalizer"); - } - - @Test - void testEmptyFinalizer() { - EntityBulkOperation op = mock(EntityBulkOperation.class); - EntityBulkExecution execution = EntityBulkExecution.builder() - .topic("topic") - .operation(op) - .build(); - - assertTrue( - execution.getFinalizer().isEmpty(), - "finalizer optional should be empty"); - } + @Test + @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") + void testEquals() { + EqualsVerifier.forClass(EntityBulkExecution.class).verify(); + } + + @Test + @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") + public void testToString() { + ToStringVerifier.forClass(EntityBulkExecution.class) + .withClassName(NameStyle.SIMPLE_NAME) + .verify(); + } + + @Test + void testSetTopic() { + EntityBulkOperation op = mock(EntityBulkOperation.class); + EntityBulkExecution execution = + EntityBulkExecution.builder().topic("topic").operation(op).build(); + + String[] expected = new String[] {"topic"}; + + assertArrayEquals(expected, execution.getTopic(), "unexpected topics"); + } + + @Test + void testSetNullTopic() { + assertThrows( + NullPointerException.class, + () -> { + EntityBulkExecution.builder().topic((String[]) null); + }, + "topic must not be null"); + } + + @Test + void testSetNullTopicPart() { + assertThrows( + NullPointerException.class, + () -> { + EntityBulkExecution.builder().topic((String) null); + }, + "topic part must not be null"); + } + + @Test + void testMissingTopic() { + assertThrows( + IllegalStateException.class, + () -> { + EntityBulkOperation op = mock(EntityBulkOperation.class); + EntityBulkExecution.builder().operation(op).build(); + }, + "topic must be set"); + } + + @Test + void testSetOperation() { + EntityBulkOperation op = mock(EntityBulkOperation.class); + EntityBulkExecution execution = + EntityBulkExecution.builder().topic("topic").operation(op).build(); + + List expected = Arrays.asList(op); + + assertEquals(expected, execution.getOperations(), "unexpected operations"); + } + + @Test + void testSetNullOperation() { + assertThrows( + NullPointerException.class, + () -> { + EntityBulkExecution.builder().operation((EntityBulkOperation) null); + }, + "operation must not be null"); + } + + @Test + void testSetNullOperationArray() { + assertThrows( + NullPointerException.class, + () -> { + EntityBulkExecution.builder().operation((EntityBulkOperation[]) null); + }, + "operations must not be null"); + } + + @Test + void testMissingOperation() { + assertThrows( + IllegalStateException.class, + () -> { + EntityBulkExecution.builder().topic("topic").build(); + }, + "operation must be set"); + } + + @Test + void testSetFinalizer() { + EntityBulkOperation op = mock(EntityBulkOperation.class); + EntityBulkOperation finalizer = mock(EntityBulkOperation.class); + EntityBulkExecution execution = + EntityBulkExecution.builder().topic("topic").operation(op).finalizer(finalizer).build(); + + assertEquals(finalizer, execution.getFinalizer().get(), "unexpected finalizer"); + } + + @Test + void testEmptyFinalizer() { + EntityBulkOperation op = mock(EntityBulkOperation.class); + EntityBulkExecution execution = + EntityBulkExecution.builder().topic("topic").operation(op).build(); + + assertTrue(execution.getFinalizer().isEmpty(), "finalizer optional should be empty"); + } } diff --git a/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/EntityBulkOperationTest.java b/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/EntityBulkOperationTest.java index e8a7d50..2ad614b 100644 --- a/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/EntityBulkOperationTest.java +++ b/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/EntityBulkOperationTest.java @@ -4,139 +4,144 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.mock; -import java.util.Arrays; -import java.util.function.Consumer; - -import org.junit.jupiter.api.Test; - import com.jparams.verifier.tostring.NameStyle; import com.jparams.verifier.tostring.ToStringVerifier; - import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import java.util.Arrays; +import java.util.function.Consumer; import nl.jqno.equalsverifier.EqualsVerifier; +import org.junit.jupiter.api.Test; @SuppressFBWarnings({ - "PI_DO_NOT_REUSE_PUBLIC_IDENTIFIERS_CLASS_NAMES", - "NP_NULL_PARAM_DEREF_NONVIRTUAL", - "NP_NULL_PARAM_DEREF_ALL_TARGETS_DANGEROUS" + "PI_DO_NOT_REUSE_PUBLIC_IDENTIFIERS_CLASS_NAMES", + "NP_NULL_PARAM_DEREF_NONVIRTUAL", + "NP_NULL_PARAM_DEREF_ALL_TARGETS_DANGEROUS" }) class EntityBulkOperationTest { - @Test - @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") - void testEquals() { - EqualsVerifier.forClass(EntityBulkOperation.class) - .verify(); - } - - @Test - @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") - public void testToString() { - ToStringVerifier.forClass(EntityBulkOperation.class) - .withClassName(NameStyle.SIMPLE_NAME) - .verify(); - } - - @Test - void testSetKey() { - Entity entity = mock(); - Consumer consumer = mock(); - EntityBulkOperation op = EntityBulkOperation.builder() - .key(BulkOperationKey.PURGE_LOCK) - .entityList(Arrays.asList(entity)) - .consumer(consumer) - .build(); - - assertEquals( - BulkOperationKey.PURGE_LOCK, - op.getKey(), - "unexpected key"); - } - - @Test - void testSetNullKey() { - assertThrows(NullPointerException.class, () -> { - EntityBulkOperation.builder().key(null); - }, "key must not be null"); - } - - @Test - void testMissingKeys() { - Entity entity = mock(); - Consumer consumer = mock(); - assertThrows(IllegalStateException.class, () -> { - EntityBulkOperation.builder() - .entityList(Arrays.asList(entity)) - .consumer(consumer) - .build(); - }, "key must not be missing"); - } - - @Test - void testSetEntity() { - Entity entity = mock(); - Consumer consumer = mock(); - EntityBulkOperation op = EntityBulkOperation.builder() - .key(BulkOperationKey.PURGE_LOCK) - .entityList(Arrays.asList(entity)) - .consumer(consumer) - .build(); - - assertEquals( - Arrays.asList(entity), - op.getEntityList(), - "unexpected entityLlist"); - } - - @Test - void testSetNullEntityList() { - assertThrows(NullPointerException.class, () -> { - EntityBulkOperation.builder().entityList(null); - }, "entityList must not be null"); - } - - @Test - void testMissingEntity() { - Consumer consumer = mock(); - assertThrows(IllegalStateException.class, () -> { - EntityBulkOperation.builder() - .key(BulkOperationKey.PURGE_LOCK) - .consumer(consumer) - .build(); - }, "entity must not be missing"); - } - - @Test - void testSetConsumer() { - Entity entity = mock(); - Consumer consumer = mock(); - EntityBulkOperation op = EntityBulkOperation.builder() - .key(BulkOperationKey.PURGE_LOCK) - .entityList(Arrays.asList(entity)) - .consumer(consumer) - .build(); - - assertEquals( - consumer, - op.getConsumer(), - "unexpected consumer"); - } - - @Test - void testSetNullConsumer() { - assertThrows(NullPointerException.class, () -> { - EntityBulkOperation.builder().consumer(null); - }, "consumer must not be null"); - } - - @Test - void testMissingComsumer() { - Entity entity = mock(); - assertThrows(IllegalStateException.class, () -> { - EntityBulkOperation.builder() - .key(BulkOperationKey.PURGE_LOCK) - .entityList(Arrays.asList(entity)) - .build(); - }, "entity must not be missing"); - } + @Test + @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") + void testEquals() { + EqualsVerifier.forClass(EntityBulkOperation.class).verify(); + } + + @Test + @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") + public void testToString() { + ToStringVerifier.forClass(EntityBulkOperation.class) + .withClassName(NameStyle.SIMPLE_NAME) + .verify(); + } + + @Test + void testSetKey() { + Entity entity = mock(); + Consumer consumer = mock(); + EntityBulkOperation op = + EntityBulkOperation.builder() + .key(BulkOperationKey.PURGE_LOCK) + .entityList(Arrays.asList(entity)) + .consumer(consumer) + .build(); + + assertEquals(BulkOperationKey.PURGE_LOCK, op.getKey(), "unexpected key"); + } + + @Test + void testSetNullKey() { + assertThrows( + NullPointerException.class, + () -> { + EntityBulkOperation.builder().key(null); + }, + "key must not be null"); + } + + @Test + void testMissingKeys() { + Entity entity = mock(); + Consumer consumer = mock(); + assertThrows( + IllegalStateException.class, + () -> { + EntityBulkOperation.builder() + .entityList(Arrays.asList(entity)) + .consumer(consumer) + .build(); + }, + "key must not be missing"); + } + + @Test + void testSetEntity() { + Entity entity = mock(); + Consumer consumer = mock(); + EntityBulkOperation op = + EntityBulkOperation.builder() + .key(BulkOperationKey.PURGE_LOCK) + .entityList(Arrays.asList(entity)) + .consumer(consumer) + .build(); + + assertEquals(Arrays.asList(entity), op.getEntityList(), "unexpected entityLlist"); + } + + @Test + void testSetNullEntityList() { + assertThrows( + NullPointerException.class, + () -> { + EntityBulkOperation.builder().entityList(null); + }, + "entityList must not be null"); + } + + @Test + void testMissingEntity() { + Consumer consumer = mock(); + assertThrows( + IllegalStateException.class, + () -> { + EntityBulkOperation.builder().key(BulkOperationKey.PURGE_LOCK).consumer(consumer).build(); + }, + "entity must not be missing"); + } + + @Test + void testSetConsumer() { + Entity entity = mock(); + Consumer consumer = mock(); + EntityBulkOperation op = + EntityBulkOperation.builder() + .key(BulkOperationKey.PURGE_LOCK) + .entityList(Arrays.asList(entity)) + .consumer(consumer) + .build(); + + assertEquals(consumer, op.getConsumer(), "unexpected consumer"); + } + + @Test + void testSetNullConsumer() { + assertThrows( + NullPointerException.class, + () -> { + EntityBulkOperation.builder().consumer(null); + }, + "consumer must not be null"); + } + + @Test + void testMissingComsumer() { + Entity entity = mock(); + assertThrows( + IllegalStateException.class, + () -> { + EntityBulkOperation.builder() + .key(BulkOperationKey.PURGE_LOCK) + .entityList(Arrays.asList(entity)) + .build(); + }, + "entity must not be missing"); + } } diff --git a/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/EntityLockTest.java b/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/EntityLockTest.java index fe1f602..cd03cec 100644 --- a/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/EntityLockTest.java +++ b/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/EntityLockTest.java @@ -3,178 +3,188 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import java.time.OffsetDateTime; -import java.time.ZoneOffset; - -import org.junit.jupiter.api.Test; - import com.jparams.verifier.tostring.NameStyle; import com.jparams.verifier.tostring.ToStringVerifier; - import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import java.time.OffsetDateTime; +import java.time.ZoneOffset; import nl.jqno.equalsverifier.EqualsVerifier; +import org.junit.jupiter.api.Test; @SuppressWarnings("PMD.AvoidDuplicateLiterals") @SuppressFBWarnings({ - "PI_DO_NOT_REUSE_PUBLIC_IDENTIFIERS_CLASS_NAMES", - "NP_NULL_PARAM_DEREF_NONVIRTUAL", - "NP_NULL_PARAM_DEREF_ALL_TARGETS_DANGEROUS" + "PI_DO_NOT_REUSE_PUBLIC_IDENTIFIERS_CLASS_NAMES", + "NP_NULL_PARAM_DEREF_NONVIRTUAL", + "NP_NULL_PARAM_DEREF_ALL_TARGETS_DANGEROUS" }) class EntityLockTest { - @Test - @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") - void testEquals() { - EqualsVerifier.forClass(EntityLock.class) - .verify(); - } - - @Test - @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") - public void testToString() { - ToStringVerifier.forClass(EntityLock.class) - .withClassName(NameStyle.SIMPLE_NAME) - .verify(); - } - - @Test - void testSetEntity() { - EntityLock lock = EntityLock.builder() - .entity("123") - .build(); - - assertEquals("123", lock.getEntity(), "unexpected entity"); - } - - @Test - void testSetEntityWithNull() { - assertThrows(NullPointerException.class, () -> { - EntityLock.builder().entity(null); - }, "entity should not be null"); - } - - @Test - void testSetEntityWitZero() { - assertThrows(IllegalArgumentException.class, () -> { - EntityLock.builder().entity("0"); - }, "entity should not be zero"); - } - - @Test - void testSetEntityWitInvalidValue() { - assertThrows(IllegalArgumentException.class, () -> { - EntityLock.builder().entity("1x"); - }, "entity should not be zero"); - } - - @Test - void testSetUser() { - EntityLock lock = EntityLock.builder() - .user("123") - .build(); - - assertEquals("123", lock.getUser(), "unexpected user"); - } - - @Test - void testSetUserWithNull() { - assertThrows(NullPointerException.class, () -> { - EntityLock.builder().user(null); - }, "user should not be null"); - } - - @Test - void testSetUserWitZero() { - assertThrows(IllegalArgumentException.class, () -> { - EntityLock.builder().user("0"); - }, "user should not be zero"); - } - - @Test - void testSetUserWitInvalidValue() { - assertThrows(IllegalArgumentException.class, () -> { - EntityLock.builder().user("1x"); - }, "user should not be zero"); - } - - @Test - void testSetCreated() { - OffsetDateTime created = OffsetDateTime.of(2024, 5, 2, 10, 10, 0, 0, ZoneOffset.UTC); - EntityLock lock = EntityLock.builder() - .created(created) - .build(); - - assertEquals(created, lock.getCreated(), "unexpected created"); - } - - @Test - void testInvalidCreated() { - assertThrows(NullPointerException.class, () -> { - EntityLock.builder().created(null); - }, "null should not be allowed"); - } - - @Test - void testSetLastAccess() { - OffsetDateTime created = OffsetDateTime.of(2024, 5, 2, 10, 10, 0, 0, ZoneOffset.UTC); - EntityLock lock = EntityLock.builder() - .lastAccess(created) - .build(); - - assertEquals(created, lock.getLastAccess(), "unexpected lastAccess"); - } - - @Test - void testInvalidLastAccess() { - assertThrows(NullPointerException.class, () -> { - EntityLock.builder().lastAccess(null); - }, "null should not be allowed"); - } - - @Test - void testSetTtl() { - EntityLock lock = EntityLock.builder() - .ttl(123) - .build(); - - assertEquals(123, lock.getTtl(), "unexpected ttl"); - } - - @Test - void testInvalidTtl() { - assertThrows(IllegalArgumentException.class, () -> { - EntityLock.builder().ttl(0); - }, "ttl must be greater than 0"); - } - - @Test - void testToBuilder() { - - OffsetDateTime created = OffsetDateTime.of(2024, 5, 2, 10, 10, 0, 0, ZoneOffset.UTC); - - OffsetDateTime lastAccess = OffsetDateTime.of(2024, 5, 2, 11, 10, 0, 0, ZoneOffset.UTC); - - EntityLock lock = EntityLock.builder() - .entity("1") - .user("2") - .created(created) - .lastAccess(lastAccess) - .ttl(5) - .build(); - - EntityLock copy = lock.toBuilder() - .user("10") - .build(); - - EntityLock expected = EntityLock.builder() - .entity("1") - .user("10") - .created(created) - .lastAccess(lastAccess) - .ttl(5) - .build(); - - assertEquals(expected, copy, "unexpected entityLock"); - } - + @Test + @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") + void testEquals() { + EqualsVerifier.forClass(EntityLock.class).verify(); + } + + @Test + @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") + public void testToString() { + ToStringVerifier.forClass(EntityLock.class).withClassName(NameStyle.SIMPLE_NAME).verify(); + } + + @Test + void testSetEntity() { + EntityLock lock = EntityLock.builder().entity("123").build(); + + assertEquals("123", lock.getEntity(), "unexpected entity"); + } + + @Test + void testSetEntityWithNull() { + assertThrows( + NullPointerException.class, + () -> { + EntityLock.builder().entity(null); + }, + "entity should not be null"); + } + + @Test + void testSetEntityWitZero() { + assertThrows( + IllegalArgumentException.class, + () -> { + EntityLock.builder().entity("0"); + }, + "entity should not be zero"); + } + + @Test + void testSetEntityWitInvalidValue() { + assertThrows( + IllegalArgumentException.class, + () -> { + EntityLock.builder().entity("1x"); + }, + "entity should not be zero"); + } + + @Test + void testSetUser() { + EntityLock lock = EntityLock.builder().user("123").build(); + + assertEquals("123", lock.getUser(), "unexpected user"); + } + + @Test + void testSetUserWithNull() { + assertThrows( + NullPointerException.class, + () -> { + EntityLock.builder().user(null); + }, + "user should not be null"); + } + + @Test + void testSetUserWitZero() { + assertThrows( + IllegalArgumentException.class, + () -> { + EntityLock.builder().user("0"); + }, + "user should not be zero"); + } + + @Test + void testSetUserWitInvalidValue() { + assertThrows( + IllegalArgumentException.class, + () -> { + EntityLock.builder().user("1x"); + }, + "user should not be zero"); + } + + @Test + void testSetCreated() { + OffsetDateTime created = OffsetDateTime.of(2024, 5, 2, 10, 10, 0, 0, ZoneOffset.UTC); + EntityLock lock = EntityLock.builder().created(created).build(); + + assertEquals(created, lock.getCreated(), "unexpected created"); + } + + @Test + void testInvalidCreated() { + assertThrows( + NullPointerException.class, + () -> { + EntityLock.builder().created(null); + }, + "null should not be allowed"); + } + + @Test + void testSetLastAccess() { + OffsetDateTime created = OffsetDateTime.of(2024, 5, 2, 10, 10, 0, 0, ZoneOffset.UTC); + EntityLock lock = EntityLock.builder().lastAccess(created).build(); + + assertEquals(created, lock.getLastAccess(), "unexpected lastAccess"); + } + + @Test + void testInvalidLastAccess() { + assertThrows( + NullPointerException.class, + () -> { + EntityLock.builder().lastAccess(null); + }, + "null should not be allowed"); + } + + @Test + void testSetTtl() { + EntityLock lock = EntityLock.builder().ttl(123).build(); + + assertEquals(123, lock.getTtl(), "unexpected ttl"); + } + + @Test + void testInvalidTtl() { + assertThrows( + IllegalArgumentException.class, + () -> { + EntityLock.builder().ttl(0); + }, + "ttl must be greater than 0"); + } + + @Test + void testToBuilder() { + + OffsetDateTime created = OffsetDateTime.of(2024, 5, 2, 10, 10, 0, 0, ZoneOffset.UTC); + + OffsetDateTime lastAccess = OffsetDateTime.of(2024, 5, 2, 11, 10, 0, 0, ZoneOffset.UTC); + + EntityLock lock = + EntityLock.builder() + .entity("1") + .user("2") + .created(created) + .lastAccess(lastAccess) + .ttl(5) + .build(); + + EntityLock copy = lock.toBuilder().user("10").build(); + + EntityLock expected = + EntityLock.builder() + .entity("1") + .user("10") + .created(created) + .lastAccess(lastAccess) + .ttl(5) + .build(); + + assertEquals(expected, copy, "unexpected entityLock"); + } } diff --git a/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/EntityTest.java b/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/EntityTest.java index c2fb932..8530bff 100644 --- a/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/EntityTest.java +++ b/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/EntityTest.java @@ -4,11 +4,6 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import java.time.OffsetDateTime; -import java.time.ZoneOffset; - -import org.junit.jupiter.api.Test; - import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; @@ -16,234 +11,245 @@ import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import com.jparams.verifier.tostring.NameStyle; import com.jparams.verifier.tostring.ToStringVerifier; - import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import java.time.OffsetDateTime; +import java.time.ZoneOffset; import nl.jqno.equalsverifier.EqualsVerifier; +import org.junit.jupiter.api.Test; @SuppressWarnings("PMD.AvoidDuplicateLiterals") @SuppressFBWarnings({ - "PI_DO_NOT_REUSE_PUBLIC_IDENTIFIERS_CLASS_NAMES", - "NP_NULL_PARAM_DEREF_NONVIRTUAL", - "NP_NULL_PARAM_DEREF_ALL_TARGETS_DANGEROUS" + "PI_DO_NOT_REUSE_PUBLIC_IDENTIFIERS_CLASS_NAMES", + "NP_NULL_PARAM_DEREF_NONVIRTUAL", + "NP_NULL_PARAM_DEREF_ALL_TARGETS_DANGEROUS" }) class EntityTest { - @Test - @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") - void testEquals() { - EqualsVerifier.forClass(Entity.class).verify(); - } - - @Test - @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") - public void testToString() { - ToStringVerifier.forClass(Entity.class) - .withClassName(NameStyle.SIMPLE_NAME) - .verify(); - } - - @Test - void testSetId() { - Entity entity = Entity.builder() - .id("123") - .build(); - assertEquals("123", entity.getId().get(), "unexpected id"); - } - - @Test - void testSetIdWithNull() { - assertThrows(NullPointerException.class, () -> { - Entity.builder().id(null); - }, "id should not be null"); - } - - @Test - void testSetIdWithZero() { - assertThrows(IllegalArgumentException.class, () -> { - Entity.builder().id("0"); - }, "id should not be zero"); - } - - @Test - void testSetIdWithInvalidValid() { - assertThrows(IllegalArgumentException.class, () -> { - Entity.builder().id("0x"); - }, "id should not be invalid"); - } - - @Test - void testGetEmptyId() { - Entity entity = Entity.builder().build(); - assertTrue(entity.getId().isEmpty(), "id optional should be empty"); - } - - @Test - void testSetAnchorAsString() { - Entity entity = Entity.builder() - .anchor("abc") - .build(); - assertEquals( - Anchor.ofString("abc"), - entity.getAnchor().get(), - "unexpected anchor"); - } - - @Test - void testSetAnchorWithNullString() { - assertThrows(NullPointerException.class, () -> { - Entity.builder().anchor((String)null); - }, "anchor should not be allowed to be null"); - } - - @Test - void testSetAnchorAsAnchor() { - Entity entity = Entity.builder() - .anchor(Anchor.ofString("abc")) - .build(); - assertEquals( - Anchor.ofString("abc"), - entity.getAnchor().get(), - "unexpected anchor"); - } - - @Test - void testSetAnchorWithNullAnchor() { - assertThrows(NullPointerException.class, () -> { - Entity.builder().anchor((String)null); - }, "anchor should not be allowed to be null"); - } - - @Test - void testSetName() { - Entity entity = Entity.builder() - .name("abc") - .build(); - assertEquals("abc", entity.getName().get(), "unexpected name"); - } - - @Test - void testSetNameWithNull() { - assertThrows(NullPointerException.class, () -> { - Entity.builder().name(null); - }, "name should not be allowed to be null"); - } - - @Test - void testSetNameWithBlank() { - assertThrows(IllegalArgumentException.class, () -> { - Entity.builder().name(" "); - }, "name should not be allowed to be blank"); - } - - @Test - void testSetParent() { - Entity entity = Entity.builder() - .parent("123") - .build(); - assertEquals("123", entity.getParent().get(), "unexpected parent"); - } - - @Test - void testSetParentWithNull() { - assertThrows(NullPointerException.class, () -> { - Entity.builder().parent(null); - }, "parent should not be null"); - } - - @Test - void testSetParentWithZero() { - assertThrows(IllegalArgumentException.class, () -> { - Entity.builder().parent("0"); - }, "parent should not be zero"); - } - - @Test - void testSetParentWithInvalidValid() { - assertThrows(IllegalArgumentException.class, () -> { - Entity.builder().parent("0x"); - }, "parent should not be invalid"); - } - - @Test - void testGetEmptyParent() { - Entity entity = Entity.builder().build(); - assertTrue(entity.getParent().isEmpty(), "id optional should be empty"); - } - - @Test - void testSetVersion() { - OffsetDateTime version = OffsetDateTime.of(2024, 5, 2, 10, 10, 0, 0, ZoneOffset.UTC); - Entity entity = Entity.builder() - .version(version) - .build(); - assertEquals(version, entity.getVersion().get(), "unexpected version"); - } - - @Test - void testGetEmptyVersion() { - Entity entity = Entity.builder().build(); - assertTrue(entity.getVersion().isEmpty(), "id optional should be empty"); - } - - @Test - void testSetIsGroup() { - Entity entity = Entity.builder() - .isGroup(true) - .build(); - assertTrue(entity.isGroup(), "isGroup should be true"); - } - - @Test - void testToBuilder() { - OffsetDateTime version = OffsetDateTime.of(2024, 5, 2, 10, 10, 0, 0, ZoneOffset.UTC); - Entity entity = Entity.builder() - .id("100560100000014842") - .name("060 Rathaus") - .parent("100560100000014840") - .version(version) - .isGroup(false) - .build(); - - Entity copy = entity.toBuilder() - .name("abc") - .build(); - - Entity expected = Entity.builder() - .id("100560100000014842") - .name("abc") - .parent("100560100000014840") - .version(version) - .isGroup(false) - .build(); - - assertEquals(expected, copy, "unexpected copy values"); - } - - - @Test - void testSerialize() throws JsonProcessingException { - - OffsetDateTime version = OffsetDateTime.of(2024, 5, 2, 10, 10, 0, 0, ZoneOffset.UTC); - - ObjectMapper mapper = new ObjectMapper(); - mapper.registerModule(new Jdk8Module()); - mapper.registerModule(new JavaTimeModule()); - mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); - - Entity entity = Entity.builder() - .id("100560100000014842") - .name("060 Rathaus") - .parent("100560100000014840") - .version(version) - .isGroup(false) - .build(); - - String json = mapper.writeValueAsString(entity); - - String expected = "{\"id\":\"100560100000014842\",\"anchor\":null," + - "\"name\":\"060 Rathaus\",\"parent\":\"100560100000014840\"," + - "\"version\":\"2024-05-02T10:10:00Z\",\"group\":false}"; - - assertEquals(expected, json, "unexpected json"); - } + @Test + @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") + void testEquals() { + EqualsVerifier.forClass(Entity.class).verify(); + } + + @Test + @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") + public void testToString() { + ToStringVerifier.forClass(Entity.class).withClassName(NameStyle.SIMPLE_NAME).verify(); + } + + @Test + void testSetId() { + Entity entity = Entity.builder().id("123").build(); + assertEquals("123", entity.getId().get(), "unexpected id"); + } + + @Test + void testSetIdWithNull() { + assertThrows( + NullPointerException.class, + () -> { + Entity.builder().id(null); + }, + "id should not be null"); + } + + @Test + void testSetIdWithZero() { + assertThrows( + IllegalArgumentException.class, + () -> { + Entity.builder().id("0"); + }, + "id should not be zero"); + } + + @Test + void testSetIdWithInvalidValid() { + assertThrows( + IllegalArgumentException.class, + () -> { + Entity.builder().id("0x"); + }, + "id should not be invalid"); + } + + @Test + void testGetEmptyId() { + Entity entity = Entity.builder().build(); + assertTrue(entity.getId().isEmpty(), "id optional should be empty"); + } + + @Test + void testSetAnchorAsString() { + Entity entity = Entity.builder().anchor("abc").build(); + assertEquals(Anchor.ofString("abc"), entity.getAnchor().get(), "unexpected anchor"); + } + + @Test + void testSetAnchorWithNullString() { + assertThrows( + NullPointerException.class, + () -> { + Entity.builder().anchor((String) null); + }, + "anchor should not be allowed to be null"); + } + + @Test + void testSetAnchorAsAnchor() { + Entity entity = Entity.builder().anchor(Anchor.ofString("abc")).build(); + assertEquals(Anchor.ofString("abc"), entity.getAnchor().get(), "unexpected anchor"); + } + + @Test + void testSetAnchorWithNullAnchor() { + assertThrows( + NullPointerException.class, + () -> { + Entity.builder().anchor((String) null); + }, + "anchor should not be allowed to be null"); + } + + @Test + void testSetName() { + Entity entity = Entity.builder().name("abc").build(); + assertEquals("abc", entity.getName().get(), "unexpected name"); + } + + @Test + void testSetNameWithNull() { + assertThrows( + NullPointerException.class, + () -> { + Entity.builder().name(null); + }, + "name should not be allowed to be null"); + } + + @Test + void testSetNameWithBlank() { + assertThrows( + IllegalArgumentException.class, + () -> { + Entity.builder().name(" "); + }, + "name should not be allowed to be blank"); + } + + @Test + void testSetParent() { + Entity entity = Entity.builder().parent("123").build(); + assertEquals("123", entity.getParent().get(), "unexpected parent"); + } + + @Test + void testSetParentWithNull() { + assertThrows( + NullPointerException.class, + () -> { + Entity.builder().parent(null); + }, + "parent should not be null"); + } + + @Test + void testSetParentWithZero() { + assertThrows( + IllegalArgumentException.class, + () -> { + Entity.builder().parent("0"); + }, + "parent should not be zero"); + } + + @Test + void testSetParentWithInvalidValid() { + assertThrows( + IllegalArgumentException.class, + () -> { + Entity.builder().parent("0x"); + }, + "parent should not be invalid"); + } + + @Test + void testGetEmptyParent() { + Entity entity = Entity.builder().build(); + assertTrue(entity.getParent().isEmpty(), "id optional should be empty"); + } + + @Test + void testSetVersion() { + OffsetDateTime version = OffsetDateTime.of(2024, 5, 2, 10, 10, 0, 0, ZoneOffset.UTC); + Entity entity = Entity.builder().version(version).build(); + assertEquals(version, entity.getVersion().get(), "unexpected version"); + } + + @Test + void testGetEmptyVersion() { + Entity entity = Entity.builder().build(); + assertTrue(entity.getVersion().isEmpty(), "id optional should be empty"); + } + + @Test + void testSetIsGroup() { + Entity entity = Entity.builder().isGroup(true).build(); + assertTrue(entity.isGroup(), "isGroup should be true"); + } + + @Test + void testToBuilder() { + OffsetDateTime version = OffsetDateTime.of(2024, 5, 2, 10, 10, 0, 0, ZoneOffset.UTC); + Entity entity = + Entity.builder() + .id("100560100000014842") + .name("060 Rathaus") + .parent("100560100000014840") + .version(version) + .isGroup(false) + .build(); + + Entity copy = entity.toBuilder().name("abc").build(); + + Entity expected = + Entity.builder() + .id("100560100000014842") + .name("abc") + .parent("100560100000014840") + .version(version) + .isGroup(false) + .build(); + + assertEquals(expected, copy, "unexpected copy values"); + } + + @Test + void testSerialize() throws JsonProcessingException { + + OffsetDateTime version = OffsetDateTime.of(2024, 5, 2, 10, 10, 0, 0, ZoneOffset.UTC); + + ObjectMapper mapper = new ObjectMapper(); + mapper.registerModule(new Jdk8Module()); + mapper.registerModule(new JavaTimeModule()); + mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); + + Entity entity = + Entity.builder() + .id("100560100000014842") + .name("060 Rathaus") + .parent("100560100000014840") + .version(version) + .isGroup(false) + .build(); + + String json = mapper.writeValueAsString(entity); + + String expected = + "{\"id\":\"100560100000014842\",\"anchor\":null," + + "\"name\":\"060 Rathaus\",\"parent\":\"100560100000014840\"," + + "\"version\":\"2024-05-02T10:10:00Z\",\"group\":false}"; + + assertEquals(expected, json, "unexpected json"); + } } diff --git a/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/EntityTreeTest.java b/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/EntityTreeTest.java index 7ca3e3a..94514f2 100644 --- a/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/EntityTreeTest.java +++ b/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/EntityTreeTest.java @@ -7,141 +7,144 @@ import java.util.List; import java.util.stream.Collectors; - import org.hamcrest.Matchers; import org.junit.jupiter.api.Test; class EntityTreeTest { - @Test - void testGetRoots() { - EntityTree tree = new EntityTree(); - - tree.add(Entity.builder().id("1").build()); - tree.add(Entity.builder().id("2").build()); - tree.add(Entity.builder().id("10").parent("1").build()); - tree.add(Entity.builder().id("11").parent("1").build()); - tree.add(Entity.builder().id("20").parent("2").build()); + @Test + void testGetRoots() { + EntityTree tree = new EntityTree(); - List all = tree.getRoots().stream() - .map(entity -> entity.getId().get()) - .collect(Collectors.toList()); + tree.add(Entity.builder().id("1").build()); + tree.add(Entity.builder().id("2").build()); + tree.add(Entity.builder().id("10").parent("1").build()); + tree.add(Entity.builder().id("11").parent("1").build()); + tree.add(Entity.builder().id("20").parent("2").build()); - assertThat("Unexpected entries", all, Matchers.contains("1", "2")); - } + List all = + tree.getRoots().stream().map(entity -> entity.getId().get()).collect(Collectors.toList()); - @Test - void testGetRootsWithInvalidState() { - EntityTree tree = new EntityTree(); + assertThat("Unexpected entries", all, Matchers.contains("1", "2")); + } - tree.add(Entity.builder().id("1").build()); - tree.add(Entity.builder().id("20").parent("2").build()); + @Test + void testGetRootsWithInvalidState() { + EntityTree tree = new EntityTree(); - assertThrows(IllegalStateException.class, () -> { - tree.getRoots(); - }, "Entity 2 is missing. Here an IllegalStateException should be thrown"); - } + tree.add(Entity.builder().id("1").build()); + tree.add(Entity.builder().id("20").parent("2").build()); - @Test - void testGetChildren() { + assertThrows( + IllegalStateException.class, + () -> { + tree.getRoots(); + }, + "Entity 2 is missing. Here an IllegalStateException should be thrown"); + } - EntityTree tree = new EntityTree(); + @Test + void testGetChildren() { - tree.add(Entity.builder().id("1").build()); - tree.add(Entity.builder().id("2").build()); - tree.add(Entity.builder().id("10").parent("1").build()); - tree.add(Entity.builder().id("11").parent("1").build()); - tree.add(Entity.builder().id("20").parent("2").build()); + EntityTree tree = new EntityTree(); - List all = tree.getChildren("1").stream() - .map(entity -> entity.getId().get()) - .collect(Collectors.toList()); + tree.add(Entity.builder().id("1").build()); + tree.add(Entity.builder().id("2").build()); + tree.add(Entity.builder().id("10").parent("1").build()); + tree.add(Entity.builder().id("11").parent("1").build()); + tree.add(Entity.builder().id("20").parent("2").build()); - assertThat("Unexpected chilldren", all, Matchers.contains("11", "10")); - } + List all = + tree.getChildren("1").stream() + .map(entity -> entity.getId().get()) + .collect(Collectors.toList()); - @Test - void testaddWithNull() { + assertThat("Unexpected chilldren", all, Matchers.contains("11", "10")); + } - EntityTree tree = new EntityTree(); - tree.add(null); + @Test + void testaddWithNull() { - assertTrue(tree.getAll().isEmpty(), "tree should be empty"); - } + EntityTree tree = new EntityTree(); + tree.add(null); - @Test - void testHasChildren() { + assertTrue(tree.getAll().isEmpty(), "tree should be empty"); + } - EntityTree tree = new EntityTree(); + @Test + void testHasChildren() { - tree.add(Entity.builder().id("1").build()); - tree.add(Entity.builder().id("10").parent("1").build()); + EntityTree tree = new EntityTree(); - assertTrue(tree.hasChildren("1"), "entity should have children"); + tree.add(Entity.builder().id("1").build()); + tree.add(Entity.builder().id("10").parent("1").build()); - } + assertTrue(tree.hasChildren("1"), "entity should have children"); + } - @Test - void testGet() { + @Test + void testGet() { - EntityTree tree = new EntityTree(); - tree.add(Entity.builder().id("1").build()); + EntityTree tree = new EntityTree(); + tree.add(Entity.builder().id("1").build()); - Entity entity = tree.get("1"); + Entity entity = tree.get("1"); - assertEquals("1", entity.getId().get(), "unexpected entity"); - } + assertEquals("1", entity.getId().get(), "unexpected entity"); + } - @Test - void testGetAll() { - EntityTree tree = new EntityTree(); + @Test + void testGetAll() { + EntityTree tree = new EntityTree(); - tree.add(Entity.builder().id("1").build()); - tree.add(Entity.builder().id("2").build()); - tree.add(Entity.builder().id("10").parent("1").build()); - tree.add(Entity.builder().id("11").parent("1").build()); - tree.add(Entity.builder().id("20").parent("2").build()); + tree.add(Entity.builder().id("1").build()); + tree.add(Entity.builder().id("2").build()); + tree.add(Entity.builder().id("10").parent("1").build()); + tree.add(Entity.builder().id("11").parent("1").build()); + tree.add(Entity.builder().id("20").parent("2").build()); - List all = tree.getAll().stream() - .map(entity -> entity.getId().get()) - .collect(Collectors.toList()); + List all = + tree.getAll().stream().map(entity -> entity.getId().get()).collect(Collectors.toList()); - assertThat("Unexpected entries", all, Matchers.containsInAnyOrder("1", "10", "11", "2", "20")); - } + assertThat("Unexpected entries", all, Matchers.containsInAnyOrder("1", "10", "11", "2", "20")); + } - @Test - void testGetAllWithInvalidState() { - EntityTree tree = new EntityTree(); + @Test + void testGetAllWithInvalidState() { + EntityTree tree = new EntityTree(); - tree.add(Entity.builder().id("1").build()); - tree.add(Entity.builder().id("20").parent("2").build()); + tree.add(Entity.builder().id("1").build()); + tree.add(Entity.builder().id("20").parent("2").build()); - assertThrows(IllegalStateException.class, () -> { - tree.getAll(); - }, "Entity 2 is missing. Here an IllegalStateException should be thrown"); - } + assertThrows( + IllegalStateException.class, + () -> { + tree.getAll(); + }, + "Entity 2 is missing. Here an IllegalStateException should be thrown"); + } - @Test - void testToString() { - EntityTree tree = new EntityTree(); - tree.add(Entity.builder().id("1").build()); + @Test + void testToString() { + EntityTree tree = new EntityTree(); + tree.add(Entity.builder().id("1").build()); - String s = tree.toString(); - assertTrue(s.contains("id=1,"), "entity with id 1 not found"); - } + String s = tree.toString(); + assertTrue(s.contains("id=1,"), "entity with id 1 not found"); + } - @Test - void testToStringWithIndent() { - EntityTree tree = new EntityTree(); + @Test + void testToStringWithIndent() { + EntityTree tree = new EntityTree(); - tree.add(Entity.builder().id("1").build()); - tree.add(Entity.builder().id("2").build()); - tree.add(Entity.builder().id("10").parent("1").build()); - tree.add(Entity.builder().id("11").parent("1").build()); - tree.add(Entity.builder().id("20").parent("2").build()); + tree.add(Entity.builder().id("1").build()); + tree.add(Entity.builder().id("2").build()); + tree.add(Entity.builder().id("10").parent("1").build()); + tree.add(Entity.builder().id("11").parent("1").build()); + tree.add(Entity.builder().id("20").parent("2").build()); - String s = tree.toString(3); + String s = tree.toString(3); - assertTrue(s.contains("\n Entity"), "indent missing"); - } + assertTrue(s.contains("\n Entity"), "indent missing"); + } } diff --git a/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/HistoryEntryTest.java b/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/HistoryEntryTest.java index a3b1088..9641327 100644 --- a/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/HistoryEntryTest.java +++ b/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/HistoryEntryTest.java @@ -4,153 +4,145 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import org.junit.jupiter.api.Test; - import com.jparams.verifier.tostring.NameStyle; import com.jparams.verifier.tostring.ToStringVerifier; - import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import nl.jqno.equalsverifier.EqualsVerifier; +import org.junit.jupiter.api.Test; @SuppressWarnings("PMD.AvoidDuplicateLiterals") @SuppressFBWarnings({ - "PI_DO_NOT_REUSE_PUBLIC_IDENTIFIERS_CLASS_NAMES", - "NP_NULL_PARAM_DEREF_NONVIRTUAL", - "NP_NULL_PARAM_DEREF_ALL_TARGETS_DANGEROUS" + "PI_DO_NOT_REUSE_PUBLIC_IDENTIFIERS_CLASS_NAMES", + "NP_NULL_PARAM_DEREF_NONVIRTUAL", + "NP_NULL_PARAM_DEREF_ALL_TARGETS_DANGEROUS" }) class HistoryEntryTest { - @Test - @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") - void testEquals() { - EqualsVerifier.forClass(HistoryEntry.class) - .verify(); - } - - @Test - @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") - public void testToString() { - ToStringVerifier.forClass(HistoryEntry.class) - .withClassName(NameStyle.SIMPLE_NAME) - .verify(); - } - - @Test - void testSetEntity() { - HistoryEntry entry = HistoryEntry.builder() - .entity(123) - .build(); - - assertEquals(123, entry.getEntity(), "unexpected entry"); - } - - @Test - void testSetInitiator() { - HistoryEntry entry = HistoryEntry.builder() - .initiator("initiator") - .build(); - - assertEquals("initiator", entry.getInitiator(), "unexpected initiator"); - } - - @Test - void testSetNullInitiator() { - assertThrows(NullPointerException.class, () -> { - HistoryEntry.builder().initiator(null); - }, "initiator must not be null"); - } - - @Test - void testSetUser() { - HistoryEntry entry = HistoryEntry.builder() - .user(123L) - .build(); - - assertEquals(123, entry.getUser().get(), "unexpected user"); - } - - @Test - void testEmptyUser() { - HistoryEntry entry = HistoryEntry.builder() - .build(); - - assertTrue(entry.getUser().isEmpty(), "user should be empty"); - } - - - @Test - void testSetTimestamp() { - HistoryEntry entry = HistoryEntry.builder() - .timestamp(123L) - .build(); - - assertEquals(123, entry.getTimestamp(), "unexpected timestamp"); - } - - @Test - void testSetInvalidTimestamp() { - assertThrows(IllegalArgumentException.class, () -> { - HistoryEntry.builder().timestamp(0); - }, "timestamp must be greater than 0"); - } - - @Test - void testSetType() { - HistoryEntry entry = HistoryEntry.builder() - .type(HistoryEntryType.CREATED) - .build(); - - assertEquals(HistoryEntryType.CREATED, entry.getType(), "unexpected type"); - } - - @Test - void testSetNullType() { - assertThrows(NullPointerException.class, () -> { - HistoryEntry.builder().type(null); - }, "type must not be null"); - } - - @Test - void testSetComment() { - HistoryEntry entry = HistoryEntry.builder() - .comment("comment") - .build(); - - assertEquals("comment", entry.getComment(), "unexpected comment"); - } - - @Test - void testSetNullComment() { - assertThrows(NullPointerException.class, () -> { - HistoryEntry.builder().comment(null); - }, "comment must not be null"); - } - - @Test - void testToBuilder() { - HistoryEntry entry = HistoryEntry.builder() - .entity(123) - .initiator("initiator") - .user(345L) - .timestamp(123L) - .type(HistoryEntryType.CREATED) - .comment("comment") - .build(); - - HistoryEntry copy = entry.toBuilder() - .entity(678) - .build(); - - HistoryEntry expected = HistoryEntry.builder() - .entity(678) - .initiator("initiator") - .user(345L) - .timestamp(123L) - .type(HistoryEntryType.CREATED) - .comment("comment") - .build(); - - assertEquals(expected, copy, "unexpected copy"); - } - + @Test + @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") + void testEquals() { + EqualsVerifier.forClass(HistoryEntry.class).verify(); + } + + @Test + @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") + public void testToString() { + ToStringVerifier.forClass(HistoryEntry.class).withClassName(NameStyle.SIMPLE_NAME).verify(); + } + + @Test + void testSetEntity() { + HistoryEntry entry = HistoryEntry.builder().entity(123).build(); + + assertEquals(123, entry.getEntity(), "unexpected entry"); + } + + @Test + void testSetInitiator() { + HistoryEntry entry = HistoryEntry.builder().initiator("initiator").build(); + + assertEquals("initiator", entry.getInitiator(), "unexpected initiator"); + } + + @Test + void testSetNullInitiator() { + assertThrows( + NullPointerException.class, + () -> { + HistoryEntry.builder().initiator(null); + }, + "initiator must not be null"); + } + + @Test + void testSetUser() { + HistoryEntry entry = HistoryEntry.builder().user(123L).build(); + + assertEquals(123, entry.getUser().get(), "unexpected user"); + } + + @Test + void testEmptyUser() { + HistoryEntry entry = HistoryEntry.builder().build(); + + assertTrue(entry.getUser().isEmpty(), "user should be empty"); + } + + @Test + void testSetTimestamp() { + HistoryEntry entry = HistoryEntry.builder().timestamp(123L).build(); + + assertEquals(123, entry.getTimestamp(), "unexpected timestamp"); + } + + @Test + void testSetInvalidTimestamp() { + assertThrows( + IllegalArgumentException.class, + () -> { + HistoryEntry.builder().timestamp(0); + }, + "timestamp must be greater than 0"); + } + + @Test + void testSetType() { + HistoryEntry entry = HistoryEntry.builder().type(HistoryEntryType.CREATED).build(); + + assertEquals(HistoryEntryType.CREATED, entry.getType(), "unexpected type"); + } + + @Test + void testSetNullType() { + assertThrows( + NullPointerException.class, + () -> { + HistoryEntry.builder().type(null); + }, + "type must not be null"); + } + + @Test + void testSetComment() { + HistoryEntry entry = HistoryEntry.builder().comment("comment").build(); + + assertEquals("comment", entry.getComment(), "unexpected comment"); + } + + @Test + void testSetNullComment() { + assertThrows( + NullPointerException.class, + () -> { + HistoryEntry.builder().comment(null); + }, + "comment must not be null"); + } + + @Test + void testToBuilder() { + HistoryEntry entry = + HistoryEntry.builder() + .entity(123) + .initiator("initiator") + .user(345L) + .timestamp(123L) + .type(HistoryEntryType.CREATED) + .comment("comment") + .build(); + + HistoryEntry copy = entry.toBuilder().entity(678).build(); + + HistoryEntry expected = + HistoryEntry.builder() + .entity(678) + .initiator("initiator") + .user(345L) + .timestamp(123L) + .type(HistoryEntryType.CREATED) + .comment("comment") + .build(); + + assertEquals(expected, copy, "unexpected copy"); + } } diff --git a/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/HistoryEntryTypeTest.java b/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/HistoryEntryTypeTest.java index cd6c90c..ccc16dd 100644 --- a/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/HistoryEntryTypeTest.java +++ b/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/HistoryEntryTypeTest.java @@ -6,12 +6,8 @@ class HistoryEntryTypeTest { - @Test - void testName() { - assertEquals( - "CREATED", - HistoryEntryType.CREATED.name(), - "unexpected name"); - } - + @Test + void testName() { + assertEquals("CREATED", HistoryEntryType.CREATED.name(), "unexpected name"); + } } diff --git a/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/IdentifierTest.java b/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/IdentifierTest.java index 8a577be..633a327 100644 --- a/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/IdentifierTest.java +++ b/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/IdentifierTest.java @@ -3,114 +3,110 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import java.util.Optional; - -import org.junit.jupiter.api.Test; - import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import java.util.Optional; import nl.jqno.equalsverifier.EqualsVerifier; +import org.junit.jupiter.api.Test; @SuppressWarnings("PMD.AvoidDuplicateLiterals") @SuppressFBWarnings({ - "PI_DO_NOT_REUSE_PUBLIC_IDENTIFIERS_CLASS_NAMES", - "NP_NULL_PARAM_DEREF_NONVIRTUAL", - "NP_NULL_PARAM_DEREF_ALL_TARGETS_DANGEROUS" + "PI_DO_NOT_REUSE_PUBLIC_IDENTIFIERS_CLASS_NAMES", + "NP_NULL_PARAM_DEREF_NONVIRTUAL", + "NP_NULL_PARAM_DEREF_ALL_TARGETS_DANGEROUS" }) class IdentifierTest { - @Test - @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") - void testEquals() { - EqualsVerifier.forClass(Identifier.class) - .verify(); - } - - @Test - void testToStringWithId() { - Identifier identifier = Identifier.ofString("123"); - assertEquals( - "123", - identifier.toString(), - "unexpected identifier-string"); - } - - @Test - void testToStringWithNull() { - assertThrows(NullPointerException.class, () -> { - Identifier.ofString(null); - }); - } - - @Test - void testToStringWithZero() { - assertThrows(IllegalArgumentException.class, () -> { - Identifier.ofString("0"); - }); - } - - @Test - void testToStringWithBlank() { - assertThrows(IllegalArgumentException.class, () -> { - Identifier.ofString(" "); - }); - } - - @Test - void testToStringWithAnchor() { - Identifier identifier = Identifier.ofString("abc"); - assertEquals( - "abc", - identifier.toString(), - "unexpected identifier-string"); - } - - @Test - void testOfStringToId() { - Identifier identifier = Identifier.ofString("123"); - assertEquals(Optional.of("123"), identifier.getId(), "id exprected"); - } - - @Test - void testOfStringToAnchor() { - Identifier identifier = Identifier.ofString("abc"); - Anchor anchor = Anchor.ofString("abc"); - assertEquals(Optional.of(anchor), identifier.getAnchor(), "anchor exprected"); - } - - @Test - void testOfStringWithLongString() { - Identifier identifier = Identifier.ofString("abcdefghijklmnopqrstuvwxyz"); - Anchor anchor = Anchor.ofString("abcdefghijklmnopqrstuvwxyz"); - assertEquals(Optional.of(anchor), identifier.getAnchor(), "anchor exprected"); - } - - @Test - void testOfStringWithDot() { - Identifier identifier = Identifier.ofString("123.b"); - Anchor anchor = Anchor.ofString("123.b"); - assertEquals(Optional.of(anchor), identifier.getAnchor(), "anchor exprected"); - } - - @Test - void testOfId() { - Identifier identifier = Identifier.ofId("123"); - assertEquals(Optional.of("123"), identifier.getId(), "id exprected"); - } - - @Test - void testOfAnchor() { - Anchor anchor = Anchor.ofString("abc"); - Identifier identifier = Identifier.ofAnchor(anchor); - assertEquals( - Optional.of(Anchor.ofString("abc")), - identifier.getAnchor(), - "anchor exprected"); - } - - @Test - void testOfAnchorWithNull() { - assertThrows(NullPointerException.class, () -> { - Identifier.ofAnchor(null); - }); - } + @Test + @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") + void testEquals() { + EqualsVerifier.forClass(Identifier.class).verify(); + } + + @Test + void testToStringWithId() { + Identifier identifier = Identifier.ofString("123"); + assertEquals("123", identifier.toString(), "unexpected identifier-string"); + } + + @Test + void testToStringWithNull() { + assertThrows( + NullPointerException.class, + () -> { + Identifier.ofString(null); + }); + } + + @Test + void testToStringWithZero() { + assertThrows( + IllegalArgumentException.class, + () -> { + Identifier.ofString("0"); + }); + } + + @Test + void testToStringWithBlank() { + assertThrows( + IllegalArgumentException.class, + () -> { + Identifier.ofString(" "); + }); + } + + @Test + void testToStringWithAnchor() { + Identifier identifier = Identifier.ofString("abc"); + assertEquals("abc", identifier.toString(), "unexpected identifier-string"); + } + + @Test + void testOfStringToId() { + Identifier identifier = Identifier.ofString("123"); + assertEquals(Optional.of("123"), identifier.getId(), "id exprected"); + } + + @Test + void testOfStringToAnchor() { + Identifier identifier = Identifier.ofString("abc"); + Anchor anchor = Anchor.ofString("abc"); + assertEquals(Optional.of(anchor), identifier.getAnchor(), "anchor exprected"); + } + + @Test + void testOfStringWithLongString() { + Identifier identifier = Identifier.ofString("abcdefghijklmnopqrstuvwxyz"); + Anchor anchor = Anchor.ofString("abcdefghijklmnopqrstuvwxyz"); + assertEquals(Optional.of(anchor), identifier.getAnchor(), "anchor exprected"); + } + + @Test + void testOfStringWithDot() { + Identifier identifier = Identifier.ofString("123.b"); + Anchor anchor = Anchor.ofString("123.b"); + assertEquals(Optional.of(anchor), identifier.getAnchor(), "anchor exprected"); + } + + @Test + void testOfId() { + Identifier identifier = Identifier.ofId("123"); + assertEquals(Optional.of("123"), identifier.getId(), "id exprected"); + } + + @Test + void testOfAnchor() { + Anchor anchor = Anchor.ofString("abc"); + Identifier identifier = Identifier.ofAnchor(anchor); + assertEquals(Optional.of(Anchor.ofString("abc")), identifier.getAnchor(), "anchor exprected"); + } + + @Test + void testOfAnchorWithNull() { + assertThrows( + NullPointerException.class, + () -> { + Identifier.ofAnchor(null); + }); + } } diff --git a/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/MediaReferenceTest.java b/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/MediaReferenceTest.java index c5d44a3..4998e30 100644 --- a/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/MediaReferenceTest.java +++ b/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/MediaReferenceTest.java @@ -3,97 +3,94 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.jupiter.api.Test; - import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import nl.jqno.equalsverifier.EqualsVerifier; +import org.junit.jupiter.api.Test; @SuppressWarnings("PMD.AvoidDuplicateLiterals") @SuppressFBWarnings({ - "PI_DO_NOT_REUSE_PUBLIC_IDENTIFIERS_CLASS_NAMES", - "NP_NULL_PARAM_DEREF_NONVIRTUAL", - "NP_NULL_PARAM_DEREF_ALL_TARGETS_DANGEROUS" + "PI_DO_NOT_REUSE_PUBLIC_IDENTIFIERS_CLASS_NAMES", + "NP_NULL_PARAM_DEREF_NONVIRTUAL", + "NP_NULL_PARAM_DEREF_ALL_TARGETS_DANGEROUS" }) class MediaReferenceTest { - @Test - @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") - void testEquals() { - EqualsVerifier.forClass(MediaReference.class) - .verify(); - } - - @Test - void testSetMediaId() { - MediaReference ref = MediaReference.builder() - .mediaId("123") - .build(); - - assertEquals("123", ref.getMediaId(), "unexpected mediaId"); - } - - @Test - void testInvalidMediaId() { - assertThrows(NullPointerException.class, () -> { - MediaReference.builder().mediaId(null); - }, "mediaId should't be null"); - } - - @Test - void testSetUsedBy() { - MediaReference ref = MediaReference.builder() - .usedBy("123") - .build(); - - assertEquals("123", ref.getUsedBy(), "unexpected usedBy"); - } - - @Test - void testInvalidUsedBy() { - assertThrows(NullPointerException.class, () -> { - MediaReference.builder().usedBy(null); - }, "usedBy should't be null"); - } - - @Test - void testSetType() { - MediaReference ref = MediaReference.builder() - .type(MediaReferenceType.EMBEDDED) - .build(); - - assertEquals( - MediaReferenceType.EMBEDDED, - ref.getType(), - "unexpected type"); - } - - @Test - void testSetNullType() { - assertThrows(NullPointerException.class, () -> { - MediaReference.builder().type(null); - }, "usedBy must not be null"); - } - - @Test - void testToBuilder() { - - MediaReference ref = MediaReference.builder() - .mediaId("123") - .usedBy("345") - .type(MediaReferenceType.EMBEDDED) - .build(); - - MediaReference copy = ref.toBuilder() - .usedBy("678") - .build(); - - MediaReference expected = MediaReference.builder() - .mediaId("123") - .usedBy("678") - .type(MediaReferenceType.EMBEDDED) - .build(); - - assertEquals(expected, copy, "unexpected mediaReference"); - } - + @Test + @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") + void testEquals() { + EqualsVerifier.forClass(MediaReference.class).verify(); + } + + @Test + void testSetMediaId() { + MediaReference ref = MediaReference.builder().mediaId("123").build(); + + assertEquals("123", ref.getMediaId(), "unexpected mediaId"); + } + + @Test + void testInvalidMediaId() { + assertThrows( + NullPointerException.class, + () -> { + MediaReference.builder().mediaId(null); + }, + "mediaId should't be null"); + } + + @Test + void testSetUsedBy() { + MediaReference ref = MediaReference.builder().usedBy("123").build(); + + assertEquals("123", ref.getUsedBy(), "unexpected usedBy"); + } + + @Test + void testInvalidUsedBy() { + assertThrows( + NullPointerException.class, + () -> { + MediaReference.builder().usedBy(null); + }, + "usedBy should't be null"); + } + + @Test + void testSetType() { + MediaReference ref = MediaReference.builder().type(MediaReferenceType.EMBEDDED).build(); + + assertEquals(MediaReferenceType.EMBEDDED, ref.getType(), "unexpected type"); + } + + @Test + void testSetNullType() { + assertThrows( + NullPointerException.class, + () -> { + MediaReference.builder().type(null); + }, + "usedBy must not be null"); + } + + @Test + void testToBuilder() { + + MediaReference ref = + MediaReference.builder() + .mediaId("123") + .usedBy("345") + .type(MediaReferenceType.EMBEDDED) + .build(); + + MediaReference copy = ref.toBuilder().usedBy("678").build(); + + MediaReference expected = + MediaReference.builder() + .mediaId("123") + .usedBy("678") + .type(MediaReferenceType.EMBEDDED) + .build(); + + assertEquals(expected, copy, "unexpected mediaReference"); + } } diff --git a/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/MediaReferenceTypeTest.java b/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/MediaReferenceTypeTest.java index e09149c..c46acb3 100644 --- a/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/MediaReferenceTypeTest.java +++ b/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/MediaReferenceTypeTest.java @@ -6,12 +6,8 @@ class MediaReferenceTypeTest { - @Test - void testName() { - assertEquals( - "EMBEDDED", - MediaReferenceType.EMBEDDED.name(), - "unexpected name"); - } - + @Test + void testName() { + assertEquals("EMBEDDED", MediaReferenceType.EMBEDDED.name(), "unexpected name"); + } } diff --git a/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/RecycleBinItemFilterTest.java b/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/RecycleBinItemFilterTest.java index 1eae278..c971a14 100644 --- a/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/RecycleBinItemFilterTest.java +++ b/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/RecycleBinItemFilterTest.java @@ -5,98 +5,80 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import java.time.LocalDateTime; - -import org.junit.jupiter.api.Test; - import nl.jqno.equalsverifier.EqualsVerifier; +import org.junit.jupiter.api.Test; class RecycleBinItemFilterTest { - @Test - @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") - void testEquals() { - EqualsVerifier.forClass(RecycleBinItemFilter.class) - .verify(); - } - - @Test - void testSetFrom() { - LocalDateTime date = LocalDateTime.of(2023, 11, 3, 9, 33); - RecycleBinItemFilter filter = RecycleBinItemFilter.builder() - .from(date) - .build(); - - assertEquals(date, filter.getFrom().get(), "unexpected from"); - } - - @Test - void testEmptyFrom() { - RecycleBinItemFilter filter = RecycleBinItemFilter.builder() - .build(); - assertTrue(filter.getFrom().isEmpty(), "from should be empty"); - } - - @Test - void testSetTo() { - LocalDateTime date = LocalDateTime.of(2023, 11, 3, 9, 33); - RecycleBinItemFilter filter = RecycleBinItemFilter.builder() - .to(date) - .build(); - - assertEquals(date, filter.getTo().get(), "unexpected to"); - } - - @Test - void testEmptyTo() { - RecycleBinItemFilter filter = RecycleBinItemFilter.builder() - .build(); - assertTrue(filter.getTo().isEmpty(), "to should be empty"); - } - - @Test - void testSetUser() { - RecycleBinItemFilter filter = RecycleBinItemFilter.builder() - .user(123) - .build(); - - assertEquals(123, filter.getUser().get(), "unexpected user"); - } - - @Test - void testSetInvalidUser() { - assertThrows(IllegalArgumentException.class, () -> { - RecycleBinItemFilter.builder().user(0); - }); - } - - @Test - void testEmptyUser() { - RecycleBinItemFilter filter = RecycleBinItemFilter.builder() - .build(); - assertTrue(filter.getUser().isEmpty(), "user should be empty"); - } - - @Test - void testToBuilder() { - - LocalDateTime from = LocalDateTime.of(2023, 11, 3, 9, 33); - LocalDateTime to = LocalDateTime.of(2023, 12, 3, 9, 33); - RecycleBinItemFilter filter = RecycleBinItemFilter.builder() - .from(from) - .to(to) - .user(123) - .build(); - - RecycleBinItemFilter copy = filter.toBuilder() - .user(345) - .build(); - - RecycleBinItemFilter expected = RecycleBinItemFilter.builder() - .from(from) - .to(to) - .user(345) - .build(); - - assertEquals(expected, copy, "unexpected mediaReference"); - } + @Test + @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") + void testEquals() { + EqualsVerifier.forClass(RecycleBinItemFilter.class).verify(); + } + + @Test + void testSetFrom() { + LocalDateTime date = LocalDateTime.of(2023, 11, 3, 9, 33); + RecycleBinItemFilter filter = RecycleBinItemFilter.builder().from(date).build(); + + assertEquals(date, filter.getFrom().get(), "unexpected from"); + } + + @Test + void testEmptyFrom() { + RecycleBinItemFilter filter = RecycleBinItemFilter.builder().build(); + assertTrue(filter.getFrom().isEmpty(), "from should be empty"); + } + + @Test + void testSetTo() { + LocalDateTime date = LocalDateTime.of(2023, 11, 3, 9, 33); + RecycleBinItemFilter filter = RecycleBinItemFilter.builder().to(date).build(); + + assertEquals(date, filter.getTo().get(), "unexpected to"); + } + + @Test + void testEmptyTo() { + RecycleBinItemFilter filter = RecycleBinItemFilter.builder().build(); + assertTrue(filter.getTo().isEmpty(), "to should be empty"); + } + + @Test + void testSetUser() { + RecycleBinItemFilter filter = RecycleBinItemFilter.builder().user(123).build(); + + assertEquals(123, filter.getUser().get(), "unexpected user"); + } + + @Test + void testSetInvalidUser() { + assertThrows( + IllegalArgumentException.class, + () -> { + RecycleBinItemFilter.builder().user(0); + }); + } + + @Test + void testEmptyUser() { + RecycleBinItemFilter filter = RecycleBinItemFilter.builder().build(); + assertTrue(filter.getUser().isEmpty(), "user should be empty"); + } + + @Test + void testToBuilder() { + + LocalDateTime from = LocalDateTime.of(2023, 11, 3, 9, 33); + LocalDateTime to = LocalDateTime.of(2023, 12, 3, 9, 33); + RecycleBinItemFilter filter = + RecycleBinItemFilter.builder().from(from).to(to).user(123).build(); + + RecycleBinItemFilter copy = filter.toBuilder().user(345).build(); + + RecycleBinItemFilter expected = + RecycleBinItemFilter.builder().from(from).to(to).user(345).build(); + + assertEquals(expected, copy, "unexpected mediaReference"); + } } diff --git a/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/RecycleBinItemTest.java b/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/RecycleBinItemTest.java index 76e092c..2fcd241 100644 --- a/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/RecycleBinItemTest.java +++ b/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/RecycleBinItemTest.java @@ -4,168 +4,167 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.mock; -import java.util.Arrays; -import java.util.List; - -import org.junit.jupiter.api.Test; - import com.jparams.verifier.tostring.NameStyle; import com.jparams.verifier.tostring.ToStringVerifier; - import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import java.util.Arrays; +import java.util.List; import nl.jqno.equalsverifier.EqualsVerifier; +import org.junit.jupiter.api.Test; @SuppressWarnings("PMD.AvoidDuplicateLiterals") @SuppressFBWarnings({ - "PI_DO_NOT_REUSE_PUBLIC_IDENTIFIERS_CLASS_NAMES", - "NP_NULL_PARAM_DEREF_NONVIRTUAL", - "NP_NULL_PARAM_DEREF_ALL_TARGETS_DANGEROUS" + "PI_DO_NOT_REUSE_PUBLIC_IDENTIFIERS_CLASS_NAMES", + "NP_NULL_PARAM_DEREF_NONVIRTUAL", + "NP_NULL_PARAM_DEREF_ALL_TARGETS_DANGEROUS" }) class RecycleBinItemTest { - @Test - @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") - void testEquals() { - RecycleBinItem a = RecycleBinItem.builder().id("1").build(); - RecycleBinItem b = RecycleBinItem.builder().id("2").build(); - EqualsVerifier.forClass(RecycleBinItem.class) - .withPrefabValues(RecycleBinItem.class, a, b) - .verify(); - } - - @Test - @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") - public void testToString() { - ToStringVerifier.forClass(RecycleBinItem.class) - .withClassName(NameStyle.SIMPLE_NAME) - .verify(); - } - - @Test - void testSetId() { - RecycleBinItem item = RecycleBinItem.builder() - .id("123") - .build(); - - assertEquals("123", item.getId(), "unexpected id"); - } - - @Test - void testSetIdWithNull() { - assertThrows(NullPointerException.class, () -> { - RecycleBinItem.builder().id(null); - }, "id should not be null"); - } - - @Test - void testSetIdWitZero() { - assertThrows(IllegalArgumentException.class, () -> { - RecycleBinItem.builder().id("0"); - }, "id should not be zero"); - } - - @Test - void testSetIdWitInvalidValue() { - assertThrows(IllegalArgumentException.class, () -> { - RecycleBinItem.builder().id("1x"); - }, "id should not be zero"); - } - - @Test - void testSetParent() { - RecycleBinItem item = RecycleBinItem.builder() - .parent("123") - .build(); - - assertEquals("123", item.getParent(), "unexpected parent"); - } - - @Test - void testSetParentWithNull() { - assertThrows(NullPointerException.class, () -> { - RecycleBinItem.builder().parent(null); - }, "parent should not be null"); - } - - @Test - void testSetParentWitZero() { - assertThrows(IllegalArgumentException.class, () -> { - RecycleBinItem.builder().parent("0"); - }, "parent should not be zero"); - } - - @Test - void testSetParentWitInvalidValue() { - assertThrows(IllegalArgumentException.class, () -> { - RecycleBinItem.builder().parent("1x"); - }, "parent should not be zero"); - } - - @Test - void testSetEntity() { - Entity entity = mock(); - RecycleBinItem item = RecycleBinItem.builder() - .entity(entity) - .build(); - - assertEquals(entity, item.getEntity(), "unexpected entity"); - } - - @Test - void testSetChild() { - RecycleBinItem child = mock(RecycleBinItem.class); - RecycleBinItem item = RecycleBinItem.builder() - .child(child) - .build(); - List expected = Arrays.asList(child); - assertEquals(expected, item.getChildren(), "unexpected children"); - } - - @Test - void testSetNullChild() { - assertThrows(NullPointerException.class, () -> { - RecycleBinItem.builder().child(null); - }, "child must not be null"); - } - - @Test - void testSetChildren() { - List children = Arrays.asList(mock(RecycleBinItem.class)); - RecycleBinItem item = RecycleBinItem.builder() - .children(children) - .build(); - assertEquals(children, item.getChildren(), "unexpected children"); - } - - @Test - void testSetNullChildren() { - assertThrows(NullPointerException.class, () -> { - RecycleBinItem.builder().children(null); - }, "children must not be null"); - } - - @Test - void testToBuilder() { - Entity entity = mock(); - List children = Arrays.asList(mock(RecycleBinItem.class)); - RecycleBinItem item = RecycleBinItem.builder() - .id("123") - .parent("345") - .entity(entity) - .children(children) - .build(); - - RecycleBinItem copy = item.toBuilder() - .parent("678") - .build(); - - RecycleBinItem expected = RecycleBinItem.builder() - .id("123") - .parent("678") - .entity(entity) - .children(children) - .build(); - - assertEquals(expected, copy, "unexpected copy"); - } + @Test + @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") + void testEquals() { + RecycleBinItem a = RecycleBinItem.builder().id("1").build(); + RecycleBinItem b = RecycleBinItem.builder().id("2").build(); + EqualsVerifier.forClass(RecycleBinItem.class) + .withPrefabValues(RecycleBinItem.class, a, b) + .verify(); + } + + @Test + @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") + public void testToString() { + ToStringVerifier.forClass(RecycleBinItem.class).withClassName(NameStyle.SIMPLE_NAME).verify(); + } + + @Test + void testSetId() { + RecycleBinItem item = RecycleBinItem.builder().id("123").build(); + + assertEquals("123", item.getId(), "unexpected id"); + } + + @Test + void testSetIdWithNull() { + assertThrows( + NullPointerException.class, + () -> { + RecycleBinItem.builder().id(null); + }, + "id should not be null"); + } + + @Test + void testSetIdWitZero() { + assertThrows( + IllegalArgumentException.class, + () -> { + RecycleBinItem.builder().id("0"); + }, + "id should not be zero"); + } + + @Test + void testSetIdWitInvalidValue() { + assertThrows( + IllegalArgumentException.class, + () -> { + RecycleBinItem.builder().id("1x"); + }, + "id should not be zero"); + } + + @Test + void testSetParent() { + RecycleBinItem item = RecycleBinItem.builder().parent("123").build(); + + assertEquals("123", item.getParent(), "unexpected parent"); + } + + @Test + void testSetParentWithNull() { + assertThrows( + NullPointerException.class, + () -> { + RecycleBinItem.builder().parent(null); + }, + "parent should not be null"); + } + + @Test + void testSetParentWitZero() { + assertThrows( + IllegalArgumentException.class, + () -> { + RecycleBinItem.builder().parent("0"); + }, + "parent should not be zero"); + } + + @Test + void testSetParentWitInvalidValue() { + assertThrows( + IllegalArgumentException.class, + () -> { + RecycleBinItem.builder().parent("1x"); + }, + "parent should not be zero"); + } + + @Test + void testSetEntity() { + Entity entity = mock(); + RecycleBinItem item = RecycleBinItem.builder().entity(entity).build(); + + assertEquals(entity, item.getEntity(), "unexpected entity"); + } + + @Test + void testSetChild() { + RecycleBinItem child = mock(RecycleBinItem.class); + RecycleBinItem item = RecycleBinItem.builder().child(child).build(); + List expected = Arrays.asList(child); + assertEquals(expected, item.getChildren(), "unexpected children"); + } + + @Test + void testSetNullChild() { + assertThrows( + NullPointerException.class, + () -> { + RecycleBinItem.builder().child(null); + }, + "child must not be null"); + } + + @Test + void testSetChildren() { + List children = Arrays.asList(mock(RecycleBinItem.class)); + RecycleBinItem item = RecycleBinItem.builder().children(children).build(); + assertEquals(children, item.getChildren(), "unexpected children"); + } + + @Test + void testSetNullChildren() { + assertThrows( + NullPointerException.class, + () -> { + RecycleBinItem.builder().children(null); + }, + "children must not be null"); + } + + @Test + void testToBuilder() { + Entity entity = mock(); + List children = Arrays.asList(mock(RecycleBinItem.class)); + RecycleBinItem item = + RecycleBinItem.builder().id("123").parent("345").entity(entity).children(children).build(); + + RecycleBinItem copy = item.toBuilder().parent("678").build(); + + RecycleBinItem expected = + RecycleBinItem.builder().id("123").parent("678").entity(entity).children(children).build(); + + assertEquals(expected, copy, "unexpected copy"); + } } diff --git a/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/FilterTest.java b/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/FilterTest.java index bc15a7e..c3700e8 100644 --- a/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/FilterTest.java +++ b/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/filter/FilterTest.java @@ -12,196 +12,178 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; -import java.util.Arrays; - -import org.junit.jupiter.api.Test; - import com.fasterxml.jackson.databind.ObjectMapper; import com.sitepark.ies.contentrepository.core.domain.databind.DatabindModule; +import java.util.Arrays; +import org.junit.jupiter.api.Test; @SuppressWarnings("PMD.AvoidDuplicateLiterals") class FilterTest { - @Test - void testIsGroup() { - IsGroup filter = Filter.isGroup(true); - assertTrue(filter.isGroup(), "unexpected isGroup"); - } - - @Test - void testId() { - Id filter = Filter.id("123"); - assertEquals("123", filter.getId(), "unexpected id"); - } - - @Test - void testIdList() { - IdList filter = Filter.idList("123"); - assertEquals(Arrays.asList("123"), filter.getIdList(), "unexpected idList"); - } - - @Test - void testAnchor() { - com.sitepark.ies.contentrepository.core.domain.entity.Anchor anchor = - com.sitepark.ies.contentrepository.core.domain.entity.Anchor.ofString("abc"); - Anchor filter = Filter.anchor(anchor); - assertEquals( - anchor, - filter.getAnchor(), - "unexpected anchorList"); - } - - @Test - void testAnchorList() { - com.sitepark.ies.contentrepository.core.domain.entity.Anchor anchor = - com.sitepark.ies.contentrepository.core.domain.entity.Anchor.ofString("abc"); - AnchorList filter = Filter.anchorList(anchor); - assertEquals( - Arrays.asList(anchor), - filter.getAnchorList(), - "unexpected anchorList"); - } - - @Test - void testParent() { - Parent filter = Filter.parent("123"); - assertEquals("123", filter.getParent(), "unexpected parent"); - } - - @Test - void testParentList() { - ParentList filter = Filter.parentList("123"); - assertEquals(Arrays.asList("123"), filter.getParentList(), "unexpected parentList"); - } - - @Test - void testParentAnchor() { - com.sitepark.ies.contentrepository.core.domain.entity.Anchor anchor = - com.sitepark.ies.contentrepository.core.domain.entity.Anchor.ofString("abc"); - ParentAnchor filter = Filter.parentAnchor(anchor); - assertEquals( - anchor, - filter.getParentAnchor(), - "unexpected parentAnchor"); - } - - @Test - void testParentAnchorList() { - com.sitepark.ies.contentrepository.core.domain.entity.Anchor anchor = - com.sitepark.ies.contentrepository.core.domain.entity.Anchor.ofString("abc"); - ParentAnchorList filter = Filter.parentAnchorList(anchor); - assertEquals( - Arrays.asList(anchor), - filter.getParentAnchorList(), - "unexpected parentAnchorList"); - } - - @Test - void testRoot() { - Root filter = Filter.root("123"); - assertEquals("123", filter.getRoot(), "unexpected root"); - } - - @Test - void testRootList() { - RootList filter = Filter.rootList("123"); - assertEquals(Arrays.asList("123"), filter.getRootList(), "unexpected rootList"); - } - - @Test - void testOr() { - Filter a = mock(); - Filter b = mock(); - Or filter = Filter.or(a, b); - assertEquals(Arrays.asList(a, b), filter.getOr(), "unexpected or"); - } - - @Test - void testAnd() { - Filter a = mock(); - Filter b = mock(); - And filter = Filter.and(a, b); - assertEquals(Arrays.asList(a, b), filter.getAnd(), "unexpected and"); - } - - @Test - void testNot() { - Filter a = mock(); - Not filter = Filter.not(a); - assertEquals(a, filter.getNot(), "unexpected not"); - } - - @Test - void testSerialize() throws Exception { - - Filter filter = - or( - idList("6"), - anchor(com.sitepark.ies.contentrepository.core.domain.entity.Anchor.ofString("abc")), - and( - root("5"), - parent("7"), - not(parent("9")) - ) - ); - - ObjectMapper objectMapper = new ObjectMapper(); - String json = objectMapper.writeValueAsString(filter); - - assertEquals( - "{\"or\":[" + - "{\"idList\":[\"6\"]}," + - "{\"anchor\":\"abc\"}," + - "{\"and\":[" + - "{\"root\":\"5\"}," + - "{\"parent\":\"7\"}," + - "{\"not\":{\"parent\":\"9\"}}" + - "]}" + - "]}", - json, - "unexpected json-data"); - - } - - @Test - @SuppressWarnings("PMD.JUnitTestContainsTooManyAsserts") - void testDeserialize() throws Exception { - - ObjectMapper objectMapper = new ObjectMapper(); - objectMapper.registerModule(new DatabindModule()); - - String json = "{\"or\":[" + - "{\"idList\":[\"6\"]}," + - "{\"anchor\":\"abc\"}," + - "{\"and\":[" + - "{\"root\":\"5\"}," + - "{\"parent\":\"7\"}," + - "{\"not\":{\"parent\":\"9\"}}" + - "]" + - "}]}"; - - Filter filter = objectMapper.readValue(json, Filter.class); - - assertInstanceOf(Or.class, filter); - - Or or = (Or)filter; - - assertInstanceOf(IdList.class, or.getOr().get(0)); - assertInstanceOf(Anchor.class, or.getOr().get(1)); - assertEquals("abc", ((Anchor)(or.getOr().get(1))).getAnchor().getName(), "wront root"); - assertInstanceOf(And.class, or.getOr().get(2)); - - And and = (And)or.getOr().get(2); - - assertInstanceOf(Root.class, and.getAnd().get(0)); - assertEquals("5", ((Root)and.getAnd().get(0)).getRoot(), "wront root"); - assertInstanceOf(Parent.class, and.getAnd().get(1)); - assertEquals("7", ((Parent)and.getAnd().get(1)).getParent(), "wront parent"); - assertInstanceOf(Not.class, and.getAnd().get(2)); - - Not not = (Not)and.getAnd().get(2); - - assertInstanceOf(Parent.class, not.getNot()); - assertEquals("9", ((Parent)not.getNot()).getParent(), "wront parent (in not)"); - } + @Test + void testIsGroup() { + IsGroup filter = Filter.isGroup(true); + assertTrue(filter.isGroup(), "unexpected isGroup"); + } + + @Test + void testId() { + Id filter = Filter.id("123"); + assertEquals("123", filter.getId(), "unexpected id"); + } + + @Test + void testIdList() { + IdList filter = Filter.idList("123"); + assertEquals(Arrays.asList("123"), filter.getIdList(), "unexpected idList"); + } + + @Test + void testAnchor() { + com.sitepark.ies.contentrepository.core.domain.entity.Anchor anchor = + com.sitepark.ies.contentrepository.core.domain.entity.Anchor.ofString("abc"); + Anchor filter = Filter.anchor(anchor); + assertEquals(anchor, filter.getAnchor(), "unexpected anchorList"); + } + + @Test + void testAnchorList() { + com.sitepark.ies.contentrepository.core.domain.entity.Anchor anchor = + com.sitepark.ies.contentrepository.core.domain.entity.Anchor.ofString("abc"); + AnchorList filter = Filter.anchorList(anchor); + assertEquals(Arrays.asList(anchor), filter.getAnchorList(), "unexpected anchorList"); + } + + @Test + void testParent() { + Parent filter = Filter.parent("123"); + assertEquals("123", filter.getParent(), "unexpected parent"); + } + + @Test + void testParentList() { + ParentList filter = Filter.parentList("123"); + assertEquals(Arrays.asList("123"), filter.getParentList(), "unexpected parentList"); + } + + @Test + void testParentAnchor() { + com.sitepark.ies.contentrepository.core.domain.entity.Anchor anchor = + com.sitepark.ies.contentrepository.core.domain.entity.Anchor.ofString("abc"); + ParentAnchor filter = Filter.parentAnchor(anchor); + assertEquals(anchor, filter.getParentAnchor(), "unexpected parentAnchor"); + } + + @Test + void testParentAnchorList() { + com.sitepark.ies.contentrepository.core.domain.entity.Anchor anchor = + com.sitepark.ies.contentrepository.core.domain.entity.Anchor.ofString("abc"); + ParentAnchorList filter = Filter.parentAnchorList(anchor); + assertEquals( + Arrays.asList(anchor), filter.getParentAnchorList(), "unexpected parentAnchorList"); + } + + @Test + void testRoot() { + Root filter = Filter.root("123"); + assertEquals("123", filter.getRoot(), "unexpected root"); + } + + @Test + void testRootList() { + RootList filter = Filter.rootList("123"); + assertEquals(Arrays.asList("123"), filter.getRootList(), "unexpected rootList"); + } + + @Test + void testOr() { + Filter a = mock(); + Filter b = mock(); + Or filter = Filter.or(a, b); + assertEquals(Arrays.asList(a, b), filter.getOr(), "unexpected or"); + } + + @Test + void testAnd() { + Filter a = mock(); + Filter b = mock(); + And filter = Filter.and(a, b); + assertEquals(Arrays.asList(a, b), filter.getAnd(), "unexpected and"); + } + + @Test + void testNot() { + Filter a = mock(); + Not filter = Filter.not(a); + assertEquals(a, filter.getNot(), "unexpected not"); + } + + @Test + void testSerialize() throws Exception { + + Filter filter = + or( + idList("6"), + anchor(com.sitepark.ies.contentrepository.core.domain.entity.Anchor.ofString("abc")), + and(root("5"), parent("7"), not(parent("9")))); + + ObjectMapper objectMapper = new ObjectMapper(); + String json = objectMapper.writeValueAsString(filter); + + assertEquals( + "{\"or\":[" + + "{\"idList\":[\"6\"]}," + + "{\"anchor\":\"abc\"}," + + "{\"and\":[" + + "{\"root\":\"5\"}," + + "{\"parent\":\"7\"}," + + "{\"not\":{\"parent\":\"9\"}}" + + "]}" + + "]}", + json, + "unexpected json-data"); + } + + @Test + @SuppressWarnings("PMD.JUnitTestContainsTooManyAsserts") + void testDeserialize() throws Exception { + + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.registerModule(new DatabindModule()); + + String json = + "{\"or\":[" + + "{\"idList\":[\"6\"]}," + + "{\"anchor\":\"abc\"}," + + "{\"and\":[" + + "{\"root\":\"5\"}," + + "{\"parent\":\"7\"}," + + "{\"not\":{\"parent\":\"9\"}}" + + "]" + + "}]}"; + + Filter filter = objectMapper.readValue(json, Filter.class); + + assertInstanceOf(Or.class, filter); + + Or or = (Or) filter; + + assertInstanceOf(IdList.class, or.getOr().get(0)); + assertInstanceOf(Anchor.class, or.getOr().get(1)); + assertEquals("abc", ((Anchor) (or.getOr().get(1))).getAnchor().getName(), "wront root"); + assertInstanceOf(And.class, or.getOr().get(2)); + + And and = (And) or.getOr().get(2); + + assertInstanceOf(Root.class, and.getAnd().get(0)); + assertEquals("5", ((Root) and.getAnd().get(0)).getRoot(), "wront root"); + assertInstanceOf(Parent.class, and.getAnd().get(1)); + assertEquals("7", ((Parent) and.getAnd().get(1)).getParent(), "wront parent"); + assertInstanceOf(Not.class, and.getAnd().get(2)); + + Not not = (Not) and.getAnd().get(2); + + assertInstanceOf(Parent.class, not.getNot()); + assertEquals("9", ((Parent) not.getNot()).getParent(), "wront parent (in not)"); + } } diff --git a/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/query/CursorBasedQueryTest.java b/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/query/CursorBasedQueryTest.java index ea3aa7e..0c370a1 100644 --- a/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/query/CursorBasedQueryTest.java +++ b/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/query/CursorBasedQueryTest.java @@ -2,55 +2,41 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.jupiter.api.Test; - import nl.jqno.equalsverifier.EqualsVerifier; +import org.junit.jupiter.api.Test; @SuppressWarnings("PMD.AvoidDuplicateLiterals") class CursorBasedQueryTest { - @Test - @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") - void testEquals() { - EqualsVerifier.forClass(CursorBasedQuery.class) - // see https://jqno.nl/equalsverifier/manual/inheritance/ - .withRedefinedSuperclass() - .verify(); - } - - @Test - void testSetName() { - CursorBasedQuery query = CursorBasedQuery.builder() - .first(3) - .build(); - assertEquals(3, query.getFirst(), "unexpected first"); - } - - @Test - void testSetAfter() { - CursorBasedQuery query = CursorBasedQuery.builder() - .after("test") - .build(); - assertEquals("test", query.getAfter(), "unexpected after"); - } - - @Test - void testToBuilder() { - CursorBasedQuery query = CursorBasedQuery.builder() - .first(3) - .after("test") - .build(); - - CursorBasedQuery copy = query.toBuilder() - .first(4) - .build(); - - CursorBasedQuery expected = CursorBasedQuery.builder() - .first(4) - .after("test") - .build(); - - assertEquals(expected, copy, "unexpected copy"); - } - + @Test + @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") + void testEquals() { + EqualsVerifier.forClass(CursorBasedQuery.class) + // see https://jqno.nl/equalsverifier/manual/inheritance/ + .withRedefinedSuperclass() + .verify(); + } + + @Test + void testSetName() { + CursorBasedQuery query = CursorBasedQuery.builder().first(3).build(); + assertEquals(3, query.getFirst(), "unexpected first"); + } + + @Test + void testSetAfter() { + CursorBasedQuery query = CursorBasedQuery.builder().after("test").build(); + assertEquals("test", query.getAfter(), "unexpected after"); + } + + @Test + void testToBuilder() { + CursorBasedQuery query = CursorBasedQuery.builder().first(3).after("test").build(); + + CursorBasedQuery copy = query.toBuilder().first(4).build(); + + CursorBasedQuery expected = CursorBasedQuery.builder().first(4).after("test").build(); + + assertEquals(expected, copy, "unexpected copy"); + } } diff --git a/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/query/QueryOptionsTest.java b/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/query/QueryOptionsTest.java index b01c391..eca717c 100644 --- a/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/query/QueryOptionsTest.java +++ b/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/query/QueryOptionsTest.java @@ -2,41 +2,31 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.jupiter.api.Test; - import nl.jqno.equalsverifier.EqualsVerifier; +import org.junit.jupiter.api.Test; class QueryOptionsTest { - @Test - @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") - void testEquals() { - EqualsVerifier.forClass(QueryOptions.class) - .verify(); - } - - @Test - void testSetShowHidden() { - QueryOptions options = QueryOptions.builder() - .showHidden(true) - .build(); - assertEquals(true, options.isShowHidden(), "unexpected showHidden"); - } - - @Test - void testToBuilder() { - QueryOptions options = QueryOptions.builder() - .showHidden(true) - .build(); - - QueryOptions copy = options.toBuilder() - .showHidden(false) - .build(); - - QueryOptions expected = QueryOptions.builder() - .showHidden(false) - .build(); - - assertEquals(expected, copy, "unexpected copy"); - } + @Test + @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") + void testEquals() { + EqualsVerifier.forClass(QueryOptions.class).verify(); + } + + @Test + void testSetShowHidden() { + QueryOptions options = QueryOptions.builder().showHidden(true).build(); + assertEquals(true, options.isShowHidden(), "unexpected showHidden"); + } + + @Test + void testToBuilder() { + QueryOptions options = QueryOptions.builder().showHidden(true).build(); + + QueryOptions copy = options.toBuilder().showHidden(false).build(); + + QueryOptions expected = QueryOptions.builder().showHidden(false).build(); + + assertEquals(expected, copy, "unexpected copy"); + } } diff --git a/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/query/QueryTest.java b/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/query/QueryTest.java index 2a75254..232233c 100644 --- a/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/query/QueryTest.java +++ b/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/query/QueryTest.java @@ -5,112 +5,99 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; -import org.junit.jupiter.api.Test; - import com.sitepark.ies.contentrepository.core.domain.entity.filter.Filter; import com.sitepark.ies.contentrepository.core.domain.entity.sort.OrderBy; - import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import nl.jqno.equalsverifier.EqualsVerifier; +import org.junit.jupiter.api.Test; @SuppressFBWarnings({ - "PI_DO_NOT_REUSE_PUBLIC_IDENTIFIERS_CLASS_NAMES", - "NP_NULL_PARAM_DEREF_NONVIRTUAL", - "NP_NULL_PARAM_DEREF_ALL_TARGETS_DANGEROUS" + "PI_DO_NOT_REUSE_PUBLIC_IDENTIFIERS_CLASS_NAMES", + "NP_NULL_PARAM_DEREF_NONVIRTUAL", + "NP_NULL_PARAM_DEREF_ALL_TARGETS_DANGEROUS" }) class QueryTest { - @Test - @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") - void testEqualsWithRedefinedCursorBasedQuery() { - EqualsVerifier.forClass(Query.class) - // see https://jqno.nl/equalsverifier/manual/inheritance/ - .withRedefinedSubclass(CursorBasedQuery.class) - .verify(); - } - - @Test - @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") - void testEqualsWithRedefinedSubTreeQuery() { - EqualsVerifier.forClass(Query.class) - // see https://jqno.nl/equalsverifier/manual/inheritance/ - .withRedefinedSubclass(SubTreeQuery.class) - .verify(); - } - - @Test - void testSetFilter() { - Filter filter = mock(Filter.class); - Query query = Query.builder() - .filterBy(filter) - .build(); - assertEquals(filter, query.getFilterBy().get(), "unexpected filter"); - } - - @Test - void testWithNullFilter() { - Query query = Query.builder() - .filterBy(null).build(); - assertTrue(query.getFilterBy().isEmpty(), "empty filter expected"); - } - - @Test - void testSetOrderBy() { - OrderBy orderBy = mock(OrderBy.class); - Query query = Query.builder() - .orderBy(orderBy) - .build(); - assertEquals(orderBy, query.getOrderBy(), "unexpected orderBy"); - } - - @Test - void testWithNullOrderBy() { - assertThrows(NullPointerException.class, () -> { - Query.builder().orderBy(null); - }, "orderBy must not be null"); - } - - @Test - void testSetOptions() { - QueryOptions options = mock(QueryOptions.class); - Query query = Query.builder() - .options(options) - .build(); - assertEquals(options, query.getOptions(), "unexpected options"); - } - - @Test - void testWithNullOptions() { - assertThrows(NullPointerException.class, () -> { - Query.builder().options(null); - }, "options must not be null"); - } - - @Test - void testToBuilder() { - - Filter filter = mock(Filter.class); - OrderBy orderBy = mock(OrderBy.class); - QueryOptions options = mock(QueryOptions.class); - - Query query = Query.builder() - .filterBy(filter) - .orderBy(orderBy) - .options(options) - .build(); - - Filter filter2 = mock(Filter.class); - - Query copy = query.toBuilder() - .filterBy(filter2) - .build(); - - Query expected = Query.builder() - .filterBy(filter2) - .orderBy(orderBy) - .options(options) - .build(); - - assertEquals(expected, copy, "unexpected copy"); - } + @Test + @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") + void testEqualsWithRedefinedCursorBasedQuery() { + EqualsVerifier.forClass(Query.class) + // see https://jqno.nl/equalsverifier/manual/inheritance/ + .withRedefinedSubclass(CursorBasedQuery.class) + .verify(); + } + + @Test + @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") + void testEqualsWithRedefinedSubTreeQuery() { + EqualsVerifier.forClass(Query.class) + // see https://jqno.nl/equalsverifier/manual/inheritance/ + .withRedefinedSubclass(SubTreeQuery.class) + .verify(); + } + + @Test + void testSetFilter() { + Filter filter = mock(Filter.class); + Query query = Query.builder().filterBy(filter).build(); + assertEquals(filter, query.getFilterBy().get(), "unexpected filter"); + } + + @Test + void testWithNullFilter() { + Query query = Query.builder().filterBy(null).build(); + assertTrue(query.getFilterBy().isEmpty(), "empty filter expected"); + } + + @Test + void testSetOrderBy() { + OrderBy orderBy = mock(OrderBy.class); + Query query = Query.builder().orderBy(orderBy).build(); + assertEquals(orderBy, query.getOrderBy(), "unexpected orderBy"); + } + + @Test + void testWithNullOrderBy() { + assertThrows( + NullPointerException.class, + () -> { + Query.builder().orderBy(null); + }, + "orderBy must not be null"); + } + + @Test + void testSetOptions() { + QueryOptions options = mock(QueryOptions.class); + Query query = Query.builder().options(options).build(); + assertEquals(options, query.getOptions(), "unexpected options"); + } + + @Test + void testWithNullOptions() { + assertThrows( + NullPointerException.class, + () -> { + Query.builder().options(null); + }, + "options must not be null"); + } + + @Test + void testToBuilder() { + + Filter filter = mock(Filter.class); + OrderBy orderBy = mock(OrderBy.class); + QueryOptions options = mock(QueryOptions.class); + + Query query = Query.builder().filterBy(filter).orderBy(orderBy).options(options).build(); + + Filter filter2 = mock(Filter.class); + + Query copy = query.toBuilder().filterBy(filter2).build(); + + Query expected = Query.builder().filterBy(filter2).orderBy(orderBy).options(options).build(); + + assertEquals(expected, copy, "unexpected copy"); + } } diff --git a/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/query/SubTreeQueryTest.java b/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/query/SubTreeQueryTest.java index a007edf..867087c 100644 --- a/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/query/SubTreeQueryTest.java +++ b/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/query/SubTreeQueryTest.java @@ -3,106 +3,101 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.util.Arrays; import java.util.List; - -import org.junit.jupiter.api.Test; - -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import nl.jqno.equalsverifier.EqualsVerifier; +import org.junit.jupiter.api.Test; @SuppressFBWarnings({ - "PI_DO_NOT_REUSE_PUBLIC_IDENTIFIERS_CLASS_NAMES", - "NP_NULL_PARAM_DEREF_NONVIRTUAL", - "NP_NULL_PARAM_DEREF_ALL_TARGETS_DANGEROUS" + "PI_DO_NOT_REUSE_PUBLIC_IDENTIFIERS_CLASS_NAMES", + "NP_NULL_PARAM_DEREF_NONVIRTUAL", + "NP_NULL_PARAM_DEREF_ALL_TARGETS_DANGEROUS" }) class SubTreeQueryTest { - @Test - @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") - void testEquals() { - EqualsVerifier.forClass(SubTreeQuery.class) - // see https://jqno.nl/equalsverifier/manual/inheritance/ - .withRedefinedSuperclass() - .verify(); - } - - @Test - void testSetRoot() { - SubTreeQuery query = SubTreeQuery.builder() - .root(123L) - .build(); - List expected = Arrays.asList(123L); - assertEquals(expected, query.getRootList(), "unexpected root"); - } - - @Test - void testSetNullRoot() { - assertThrows(NullPointerException.class, () -> { - SubTreeQuery.builder().root(null); - }, "root must not be null"); - } - - @Test - void testSetRootList() { - SubTreeQuery query = SubTreeQuery.builder() - .rootList(Arrays.asList(123L)) - .build(); - List expected = Arrays.asList(123L); - assertEquals(expected, query.getRootList(), "unexpected rootList"); - } - - @Test - void testSetNullRootList() { - assertThrows(NullPointerException.class, () -> { - SubTreeQuery.builder().rootList(null); - }, "rootList must not be null"); - } - - @Test - void testSetNullRootListItem() { - assertThrows(NullPointerException.class, () -> { - SubTreeQuery.builder().rootList(Arrays.asList((Long)null)); - }, "rootList item must not be null"); - } - - @Test - void testEmptyRootList() { - assertThrows(IllegalStateException.class, () -> { - SubTreeQuery.builder().build(); - }, "rootList must not be empty"); - } - - @Test - void testToBuilderWithNewRootList() { - SubTreeQuery query = SubTreeQuery.builder() - .rootList(Arrays.asList(123L)) - .build(); - - SubTreeQuery copy = query.toBuilder() - .rootList(Arrays.asList(345L)) - .build(); - - SubTreeQuery expected = SubTreeQuery.builder() - .rootList(Arrays.asList(345L)) - .build(); - - assertEquals(expected, copy, "unexpected copy"); - } - @Test - void testToBuilderAppendRoot() { - SubTreeQuery query = SubTreeQuery.builder() - .rootList(Arrays.asList(123L)) - .build(); - - SubTreeQuery copy = query.toBuilder() - .root(345L) - .build(); - - SubTreeQuery expected = SubTreeQuery.builder() - .rootList(Arrays.asList(123L, 345L)) - .build(); - - assertEquals(expected, copy, "unexpected copy"); - } + @Test + @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") + void testEquals() { + EqualsVerifier.forClass(SubTreeQuery.class) + // see https://jqno.nl/equalsverifier/manual/inheritance/ + .withRedefinedSuperclass() + .verify(); + } + + @Test + void testSetRoot() { + SubTreeQuery query = SubTreeQuery.builder().root(123L).build(); + List expected = Arrays.asList(123L); + assertEquals(expected, query.getRootList(), "unexpected root"); + } + + @Test + void testSetNullRoot() { + assertThrows( + NullPointerException.class, + () -> { + SubTreeQuery.builder().root(null); + }, + "root must not be null"); + } + + @Test + void testSetRootList() { + SubTreeQuery query = SubTreeQuery.builder().rootList(Arrays.asList(123L)).build(); + List expected = Arrays.asList(123L); + assertEquals(expected, query.getRootList(), "unexpected rootList"); + } + + @Test + void testSetNullRootList() { + assertThrows( + NullPointerException.class, + () -> { + SubTreeQuery.builder().rootList(null); + }, + "rootList must not be null"); + } + + @Test + void testSetNullRootListItem() { + assertThrows( + NullPointerException.class, + () -> { + SubTreeQuery.builder().rootList(Arrays.asList((Long) null)); + }, + "rootList item must not be null"); + } + + @Test + void testEmptyRootList() { + assertThrows( + IllegalStateException.class, + () -> { + SubTreeQuery.builder().build(); + }, + "rootList must not be empty"); + } + + @Test + void testToBuilderWithNewRootList() { + SubTreeQuery query = SubTreeQuery.builder().rootList(Arrays.asList(123L)).build(); + + SubTreeQuery copy = query.toBuilder().rootList(Arrays.asList(345L)).build(); + + SubTreeQuery expected = SubTreeQuery.builder().rootList(Arrays.asList(345L)).build(); + + assertEquals(expected, copy, "unexpected copy"); + } + + @Test + void testToBuilderAppendRoot() { + SubTreeQuery query = SubTreeQuery.builder().rootList(Arrays.asList(123L)).build(); + + SubTreeQuery copy = query.toBuilder().root(345L).build(); + + SubTreeQuery expected = SubTreeQuery.builder().rootList(Arrays.asList(123L, 345L)).build(); + + assertEquals(expected, copy, "unexpected copy"); + } } diff --git a/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/sort/DummyOrderCriteria.java b/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/sort/DummyOrderCriteria.java index 8349216..bcbc32b 100644 --- a/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/sort/DummyOrderCriteria.java +++ b/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/sort/DummyOrderCriteria.java @@ -2,36 +2,35 @@ public class DummyOrderCriteria extends OrderCriteria { - protected DummyOrderCriteria(Builder builder) { - super(builder); - } - - public static Builder builder() { - return new Builder(); - } - - @Override - public Builder toBuilder() { - return new Builder(this); - } - - public static class Builder extends OrderCriteria.Builder { - - protected Builder() { - } - - protected Builder(DummyOrderCriteria sortCriteria) { - super(sortCriteria); - } - - @Override - public Builder self() { - return this; - } - - @Override - public DummyOrderCriteria build() { - return new DummyOrderCriteria(this); - } - } + protected DummyOrderCriteria(Builder builder) { + super(builder); + } + + public static Builder builder() { + return new Builder(); + } + + @Override + public Builder toBuilder() { + return new Builder(this); + } + + public static class Builder extends OrderCriteria.Builder { + + protected Builder() {} + + protected Builder(DummyOrderCriteria sortCriteria) { + super(sortCriteria); + } + + @Override + public Builder self() { + return this; + } + + @Override + public DummyOrderCriteria build() { + return new DummyOrderCriteria(this); + } + } } diff --git a/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/sort/NameTest.java b/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/sort/NameTest.java index 6316a96..b4bca69 100644 --- a/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/sort/NameTest.java +++ b/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/sort/NameTest.java @@ -3,50 +3,39 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import org.junit.jupiter.api.Test; - import com.jparams.verifier.tostring.ToStringVerifier; - import nl.jqno.equalsverifier.EqualsVerifier; +import org.junit.jupiter.api.Test; class NameTest { - @Test - @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") - void testEquals() { - EqualsVerifier.forClass(Name.class) - .verify(); - } - - @Test - @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") - public void testToString() { - ToStringVerifier.forClass(Name.class) - .verify(); - } + @Test + @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") + void testEquals() { + EqualsVerifier.forClass(Name.class).verify(); + } - @Test - void testSetName() { - Name orderByName = Name.builder() - .build(); - assertNotNull(orderByName, "build() should not return null"); - } + @Test + @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") + public void testToString() { + ToStringVerifier.forClass(Name.class).verify(); + } - @Test - void testToBuilder() { + @Test + void testSetName() { + Name orderByName = Name.builder().build(); + assertNotNull(orderByName, "build() should not return null"); + } - Name orderByName = Name.builder() - .build(); + @Test + void testToBuilder() { - Name copy = orderByName.toBuilder() - .direction(Direction.ASC) - .build(); + Name orderByName = Name.builder().build(); - Name expected = Name.builder() - .direction(Direction.ASC) - .build(); + Name copy = orderByName.toBuilder().direction(Direction.ASC).build(); - assertEquals(expected, copy, "unexpected copy"); - } + Name expected = Name.builder().direction(Direction.ASC).build(); + assertEquals(expected, copy, "unexpected copy"); + } } diff --git a/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/sort/OrderByTest.java b/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/sort/OrderByTest.java index 8706a36..c8d3b42 100644 --- a/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/sort/OrderByTest.java +++ b/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/sort/OrderByTest.java @@ -4,81 +4,71 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.mock; -import java.util.Arrays; -import java.util.List; - -import org.junit.jupiter.api.Test; - import com.jparams.verifier.tostring.NameStyle; import com.jparams.verifier.tostring.ToStringVerifier; - import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import java.util.Arrays; +import java.util.List; import nl.jqno.equalsverifier.EqualsVerifier; +import org.junit.jupiter.api.Test; @SuppressFBWarnings({ - "PI_DO_NOT_REUSE_PUBLIC_IDENTIFIERS_CLASS_NAMES", - "NP_NULL_PARAM_DEREF_NONVIRTUAL", - "NP_NULL_PARAM_DEREF_ALL_TARGETS_DANGEROUS" + "PI_DO_NOT_REUSE_PUBLIC_IDENTIFIERS_CLASS_NAMES", + "NP_NULL_PARAM_DEREF_NONVIRTUAL", + "NP_NULL_PARAM_DEREF_ALL_TARGETS_DANGEROUS" }) class OrderByTest { - @Test - @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") - void testEquals() { - EqualsVerifier.forClass(OrderBy.class) - .verify(); - } - - @Test - @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") - public void testToString() { - ToStringVerifier.forClass(OrderBy.class) - .withClassName(NameStyle.SIMPLE_NAME) - .verify(); - } - - @Test - void testSetSort() { - OrderCriteria criteria = mock(OrderCriteria.class); - OrderBy orderBy = OrderBy.builder() - .sort(criteria) - .build(); - List expected = Arrays.asList(criteria); - assertEquals(expected, orderBy.getSort(), "unexpected sortlist"); - } - - @Test - void testSetNullSortArray() { - assertThrows(NullPointerException.class, () -> { - OrderBy.builder().sort((OrderCriteria[])null); - }, "sort array must not be null"); - } - - @Test - void testSetNullSort() { - assertThrows(NullPointerException.class, () -> { - OrderBy.builder().sort((OrderCriteria)null); - }, "sort must not be null"); - } - - @Test - void testToBuilder() { - OrderCriteria a = mock(OrderCriteria.class); - OrderCriteria b = mock(OrderCriteria.class); - OrderBy orderBy = OrderBy.builder() - .sort(a) - .build(); - - OrderBy copy = orderBy.toBuilder() - .sort(b) - .build(); - - OrderBy expected = OrderBy.builder() - .sort(a) - .sort(b) - .build(); - - assertEquals(expected, copy, "unexpected copy"); - } - + @Test + @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") + void testEquals() { + EqualsVerifier.forClass(OrderBy.class).verify(); + } + + @Test + @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") + public void testToString() { + ToStringVerifier.forClass(OrderBy.class).withClassName(NameStyle.SIMPLE_NAME).verify(); + } + + @Test + void testSetSort() { + OrderCriteria criteria = mock(OrderCriteria.class); + OrderBy orderBy = OrderBy.builder().sort(criteria).build(); + List expected = Arrays.asList(criteria); + assertEquals(expected, orderBy.getSort(), "unexpected sortlist"); + } + + @Test + void testSetNullSortArray() { + assertThrows( + NullPointerException.class, + () -> { + OrderBy.builder().sort((OrderCriteria[]) null); + }, + "sort array must not be null"); + } + + @Test + void testSetNullSort() { + assertThrows( + NullPointerException.class, + () -> { + OrderBy.builder().sort((OrderCriteria) null); + }, + "sort must not be null"); + } + + @Test + void testToBuilder() { + OrderCriteria a = mock(OrderCriteria.class); + OrderCriteria b = mock(OrderCriteria.class); + OrderBy orderBy = OrderBy.builder().sort(a).build(); + + OrderBy copy = orderBy.toBuilder().sort(b).build(); + + OrderBy expected = OrderBy.builder().sort(a).sort(b).build(); + + assertEquals(expected, copy, "unexpected copy"); + } } diff --git a/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/sort/OrderCriteriaTest.java b/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/sort/OrderCriteriaTest.java index 8f1ce70..c34fee0 100644 --- a/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/sort/OrderCriteriaTest.java +++ b/src/test/java/com/sitepark/ies/contentrepository/core/domain/entity/sort/OrderCriteriaTest.java @@ -2,58 +2,45 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.jupiter.api.Test; - import nl.jqno.equalsverifier.EqualsVerifier; +import org.junit.jupiter.api.Test; class OrderCriteriaTest { - @Test - @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") - void testEquals() { - EqualsVerifier.forClass(OrderCriteria.class) - .verify(); - } - - @Test - void testSetName() { - OrderCriteria criteria = DummyOrderCriteria.builder() - .name("name") - .build(); - assertEquals("name", criteria.getName(), "unexpected name"); - } - - @Test - void testSetDirection() { - OrderCriteria criteria = DummyOrderCriteria.builder() - .direction(Direction.ASC) - .build(); - assertEquals(Direction.ASC, criteria.getDirection(), "unexpected direction"); - } - - @Test - void testDefaultDirection() { - OrderCriteria criteria = DummyOrderCriteria.builder() - .build(); - assertEquals(Direction.DESC, criteria.getDirection(), "unexpected direction"); - } - - @Test - void testToBuilder() { - OrderCriteria criteria = DummyOrderCriteria.builder() - .name("name") - .direction(Direction.ASC) - .build(); - - OrderCriteria copy = criteria.toBuilder() - .name("name2") - .build(); - - OrderCriteria expected = DummyOrderCriteria.builder() - .name("name2") - .direction(Direction.ASC) - .build(); - - assertEquals(expected, copy, "unexpected copy"); - } + @Test + @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") + void testEquals() { + EqualsVerifier.forClass(OrderCriteria.class).verify(); + } + + @Test + void testSetName() { + OrderCriteria criteria = DummyOrderCriteria.builder().name("name").build(); + assertEquals("name", criteria.getName(), "unexpected name"); + } + + @Test + void testSetDirection() { + OrderCriteria criteria = DummyOrderCriteria.builder().direction(Direction.ASC).build(); + assertEquals(Direction.ASC, criteria.getDirection(), "unexpected direction"); + } + + @Test + void testDefaultDirection() { + OrderCriteria criteria = DummyOrderCriteria.builder().build(); + assertEquals(Direction.DESC, criteria.getDirection(), "unexpected direction"); + } + + @Test + void testToBuilder() { + OrderCriteria criteria = + DummyOrderCriteria.builder().name("name").direction(Direction.ASC).build(); + + OrderCriteria copy = criteria.toBuilder().name("name2").build(); + + OrderCriteria expected = + DummyOrderCriteria.builder().name("name2").direction(Direction.ASC).build(); + + assertEquals(expected, copy, "unexpected copy"); + } } diff --git a/src/test/java/com/sitepark/ies/contentrepository/core/domain/exception/AnchorAlreadyExistsExceptionTest.java b/src/test/java/com/sitepark/ies/contentrepository/core/domain/exception/AnchorAlreadyExistsExceptionTest.java index dca73ff..e17c012 100644 --- a/src/test/java/com/sitepark/ies/contentrepository/core/domain/exception/AnchorAlreadyExistsExceptionTest.java +++ b/src/test/java/com/sitepark/ies/contentrepository/core/domain/exception/AnchorAlreadyExistsExceptionTest.java @@ -3,30 +3,28 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -import org.junit.jupiter.api.Test; - import com.sitepark.ies.contentrepository.core.domain.entity.Anchor; +import org.junit.jupiter.api.Test; class AnchorAlreadyExistsExceptionTest { - @Test - void testGetAnchor() { - Anchor anchor = Anchor.ofString("abc"); - AnchorAlreadyExistsException a = new AnchorAlreadyExistsException(anchor, 0); - assertEquals(anchor, a.getAnchor(), "unexpected anchor"); - } - - @Test - void testGetOwner() { - AnchorAlreadyExistsException a = new AnchorAlreadyExistsException(null, 123); - assertEquals(123, a.getOwner(), "unexpected owner"); - } - - @Test - void testGetMessage() { - Anchor anchor = Anchor.ofString("abc"); - AnchorAlreadyExistsException a = new AnchorAlreadyExistsException(anchor, 0); - assertTrue(a.getMessage().contains(" abc "), "anchor missing in message"); - } - + @Test + void testGetAnchor() { + Anchor anchor = Anchor.ofString("abc"); + AnchorAlreadyExistsException a = new AnchorAlreadyExistsException(anchor, 0); + assertEquals(anchor, a.getAnchor(), "unexpected anchor"); + } + + @Test + void testGetOwner() { + AnchorAlreadyExistsException a = new AnchorAlreadyExistsException(null, 123); + assertEquals(123, a.getOwner(), "unexpected owner"); + } + + @Test + void testGetMessage() { + Anchor anchor = Anchor.ofString("abc"); + AnchorAlreadyExistsException a = new AnchorAlreadyExistsException(anchor, 0); + assertTrue(a.getMessage().contains(" abc "), "anchor missing in message"); + } } diff --git a/src/test/java/com/sitepark/ies/contentrepository/core/domain/exception/AnchorNotFoundExceptionTest.java b/src/test/java/com/sitepark/ies/contentrepository/core/domain/exception/AnchorNotFoundExceptionTest.java index 0cdf04d..015fd52 100644 --- a/src/test/java/com/sitepark/ies/contentrepository/core/domain/exception/AnchorNotFoundExceptionTest.java +++ b/src/test/java/com/sitepark/ies/contentrepository/core/domain/exception/AnchorNotFoundExceptionTest.java @@ -3,24 +3,22 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -import org.junit.jupiter.api.Test; - import com.sitepark.ies.contentrepository.core.domain.entity.Anchor; +import org.junit.jupiter.api.Test; class AnchorNotFoundExceptionTest { - @Test - void testGetAnchor() { - Anchor anchor = Anchor.ofString("abc"); - AnchorNotFoundException a = new AnchorNotFoundException(anchor); - assertEquals(anchor, a.getAnchor(), "unexpected anchor"); - } - - @Test - void testGetMessage() { - Anchor anchor = Anchor.ofString("abc"); - AnchorNotFoundException a = new AnchorNotFoundException(anchor); - assertTrue(a.getMessage().contains(" abc "), "anchor missing in message"); - } + @Test + void testGetAnchor() { + Anchor anchor = Anchor.ofString("abc"); + AnchorNotFoundException a = new AnchorNotFoundException(anchor); + assertEquals(anchor, a.getAnchor(), "unexpected anchor"); + } + @Test + void testGetMessage() { + Anchor anchor = Anchor.ofString("abc"); + AnchorNotFoundException a = new AnchorNotFoundException(anchor); + assertTrue(a.getMessage().contains(" abc "), "anchor missing in message"); + } } diff --git a/src/test/java/com/sitepark/ies/contentrepository/core/domain/exception/EntityLockedExceptionTest.java b/src/test/java/com/sitepark/ies/contentrepository/core/domain/exception/EntityLockedExceptionTest.java index 3875b79..ebb1849 100644 --- a/src/test/java/com/sitepark/ies/contentrepository/core/domain/exception/EntityLockedExceptionTest.java +++ b/src/test/java/com/sitepark/ies/contentrepository/core/domain/exception/EntityLockedExceptionTest.java @@ -4,24 +4,22 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; -import org.junit.jupiter.api.Test; - import com.sitepark.ies.contentrepository.core.domain.entity.EntityLock; +import org.junit.jupiter.api.Test; class EntityLockedExceptionTest { - @Test - void testGetLock() { - EntityLock lock = mock(); - EntityLockedException a = new EntityLockedException(lock); - assertEquals(lock, a.getLock(), "unexpected lock"); - } - - @Test - void testGetMessage() { - EntityLock lock = mock(); - EntityLockedException a = new EntityLockedException(lock); - assertTrue(a.getMessage().contains(lock.toString()), "lock expected in message"); - } + @Test + void testGetLock() { + EntityLock lock = mock(); + EntityLockedException a = new EntityLockedException(lock); + assertEquals(lock, a.getLock(), "unexpected lock"); + } + @Test + void testGetMessage() { + EntityLock lock = mock(); + EntityLockedException a = new EntityLockedException(lock); + assertTrue(a.getMessage().contains(lock.toString()), "lock expected in message"); + } } diff --git a/src/test/java/com/sitepark/ies/contentrepository/core/domain/exception/EntityNotFoundExceptionTest.java b/src/test/java/com/sitepark/ies/contentrepository/core/domain/exception/EntityNotFoundExceptionTest.java index ec34776..d64ed25 100644 --- a/src/test/java/com/sitepark/ies/contentrepository/core/domain/exception/EntityNotFoundExceptionTest.java +++ b/src/test/java/com/sitepark/ies/contentrepository/core/domain/exception/EntityNotFoundExceptionTest.java @@ -8,15 +8,15 @@ @SuppressWarnings("PMD.AvoidDuplicateLiterals") class EntityNotFoundExceptionTest { - @Test - void testGetLock() { - EntityNotFoundException a = new EntityNotFoundException("123"); - assertEquals("123", a.getId(), "unexpected id"); - } + @Test + void testGetLock() { + EntityNotFoundException a = new EntityNotFoundException("123"); + assertEquals("123", a.getId(), "unexpected id"); + } - @Test - void testGetMessage() { - EntityNotFoundException a = new EntityNotFoundException("123"); - assertTrue(a.getMessage().contains("123"), "id expected in message"); - } + @Test + void testGetMessage() { + EntityNotFoundException a = new EntityNotFoundException("123"); + assertTrue(a.getMessage().contains("123"), "id expected in message"); + } } diff --git a/src/test/java/com/sitepark/ies/contentrepository/core/domain/exception/GroupNotEmptyExceptionTest.java b/src/test/java/com/sitepark/ies/contentrepository/core/domain/exception/GroupNotEmptyExceptionTest.java index e39bda3..d354e8c 100644 --- a/src/test/java/com/sitepark/ies/contentrepository/core/domain/exception/GroupNotEmptyExceptionTest.java +++ b/src/test/java/com/sitepark/ies/contentrepository/core/domain/exception/GroupNotEmptyExceptionTest.java @@ -8,15 +8,15 @@ @SuppressWarnings("PMD.AvoidDuplicateLiterals") class GroupNotEmptyExceptionTest { - @Test - void testGetLock() { - GroupNotEmptyException a = new GroupNotEmptyException("123"); - assertEquals("123", a.getId(), "unexpected id"); - } + @Test + void testGetLock() { + GroupNotEmptyException a = new GroupNotEmptyException("123"); + assertEquals("123", a.getId(), "unexpected id"); + } - @Test - void testGetMessage() { - GroupNotEmptyException a = new GroupNotEmptyException("123"); - assertTrue(a.getMessage().contains("123"), "id expected in message"); - } + @Test + void testGetMessage() { + GroupNotEmptyException a = new GroupNotEmptyException("123"); + assertTrue(a.getMessage().contains("123"), "id expected in message"); + } } diff --git a/src/test/java/com/sitepark/ies/contentrepository/core/domain/exception/InvalidAnchorExceptionTest.java b/src/test/java/com/sitepark/ies/contentrepository/core/domain/exception/InvalidAnchorExceptionTest.java index 7e80d9b..4bde1b1 100644 --- a/src/test/java/com/sitepark/ies/contentrepository/core/domain/exception/InvalidAnchorExceptionTest.java +++ b/src/test/java/com/sitepark/ies/contentrepository/core/domain/exception/InvalidAnchorExceptionTest.java @@ -7,15 +7,15 @@ class InvalidAnchorExceptionTest { - @Test - void testGetAnchor() { - InvalidAnchorException a = new InvalidAnchorException("abc", null); - assertEquals("abc", a.getName(), "unexpected name"); - } + @Test + void testGetAnchor() { + InvalidAnchorException a = new InvalidAnchorException("abc", null); + assertEquals("abc", a.getName(), "unexpected name"); + } - @Test - void testGetMessage() { - InvalidAnchorException a = new InvalidAnchorException("abc", null); - assertTrue(a.getMessage().contains("'abc'"), "name missing in message"); - } + @Test + void testGetMessage() { + InvalidAnchorException a = new InvalidAnchorException("abc", null); + assertTrue(a.getMessage().contains("'abc'"), "name missing in message"); + } } diff --git a/src/test/java/com/sitepark/ies/contentrepository/core/domain/service/ContentDifferTest.java b/src/test/java/com/sitepark/ies/contentrepository/core/domain/service/ContentDifferTest.java index 09fb691..25821a3 100644 --- a/src/test/java/com/sitepark/ies/contentrepository/core/domain/service/ContentDifferTest.java +++ b/src/test/java/com/sitepark/ies/contentrepository/core/domain/service/ContentDifferTest.java @@ -6,12 +6,14 @@ class ContentDifferTest { - @Test - void testDiff() { - assertThrows(UnsupportedOperationException.class, () -> { - ContentDiffer differ = new ContentDiffer(); - differ.diff(null, null); - }, "should be unsupported"); - } - + @Test + void testDiff() { + assertThrows( + UnsupportedOperationException.class, + () -> { + ContentDiffer differ = new ContentDiffer(); + differ.diff(null, null); + }, + "should be unsupported"); + } } diff --git a/src/test/java/com/sitepark/ies/contentrepository/core/usecase/BulkPurgeInputTest.java b/src/test/java/com/sitepark/ies/contentrepository/core/usecase/BulkPurgeInputTest.java index 23b899b..2be3659 100644 --- a/src/test/java/com/sitepark/ies/contentrepository/core/usecase/BulkPurgeInputTest.java +++ b/src/test/java/com/sitepark/ies/contentrepository/core/usecase/BulkPurgeInputTest.java @@ -5,151 +5,126 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; -import java.util.Arrays; - -import org.junit.jupiter.api.Test; - import com.sitepark.ies.contentrepository.core.domain.entity.filter.Filter; - import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import java.util.Arrays; import nl.jqno.equalsverifier.EqualsVerifier; +import org.junit.jupiter.api.Test; @SuppressFBWarnings({ - "PI_DO_NOT_REUSE_PUBLIC_IDENTIFIERS_CLASS_NAMES", - "NP_NULL_PARAM_DEREF_NONVIRTUAL", - "NP_NULL_PARAM_DEREF_ALL_TARGETS_DANGEROUS" + "PI_DO_NOT_REUSE_PUBLIC_IDENTIFIERS_CLASS_NAMES", + "NP_NULL_PARAM_DEREF_NONVIRTUAL", + "NP_NULL_PARAM_DEREF_ALL_TARGETS_DANGEROUS" }) class BulkPurgeInputTest { - @Test - @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") - void testEquals() { - EqualsVerifier.forClass(BulkPurgeInput.class) - .verify(); - } - - @Test - void testSetRootList() { - - BulkPurgeInput input = BulkPurgeInput.builder() - .rootList(Arrays.asList(123L)) - .build(); - assertEquals( - Arrays.asList(123L), - input.getRootList(), - "unexpected rootList"); - } - - @Test - void testNullSetRootList() { - assertThrows(NullPointerException.class, () -> { - BulkPurgeInput.builder().rootList(null); - }, "rootList must not be null"); - } - - @Test - void testSetRoot() { - - BulkPurgeInput input = BulkPurgeInput.builder() - .root(123L) - .build(); - assertEquals( - Arrays.asList(123L), - input.getRootList(), - "unexpected root"); - } - - @Test - void testSetNullRoot() { - assertThrows(NullPointerException.class, () -> { - BulkPurgeInput.builder().root(null); - }, "root must not be null"); - } - - @Test - void testSetFilter() { - - Filter filter = mock(); - - BulkPurgeInput input = BulkPurgeInput.builder() - .filterBy(filter) - .build(); - assertEquals( - filter, - input.getFilter().get(), - "unexpected root"); - } - - @Test - void testSetNullFilter() { - assertThrows(NullPointerException.class, () -> { - BulkPurgeInput.builder().filterBy(null); - }, "filterBy must not be null"); - } - - @Test - void testForceLock() { - BulkPurgeInput input = BulkPurgeInput.builder() - .root(123L) - .forceLock(true) - .build(); - assertTrue(input.isForceLock(), "unexpected forceLock"); - } - - @Test - void testRootAndFilterNotSet() { - assertThrows(IllegalStateException.class, () -> { - BulkPurgeInput.builder().build(); - }); - } - - @Test - void testToBuilderWithNewRootList() { - - Filter filter = mock(); - - BulkPurgeInput input = BulkPurgeInput.builder() - .root(123L) - .filterBy(filter) - .forceLock(true) - .build(); - - BulkPurgeInput copy = input.toBuilder() - .rootList(Arrays.asList(345L)) - .build(); - - BulkPurgeInput expected = BulkPurgeInput.builder() - .root(345L) - .filterBy(filter) - .forceLock(true) - .build(); - - assertEquals(expected, copy, "unexpected copy"); - } - - @Test - void testToBuilderAppendRootList() { - - Filter filter = mock(); - - BulkPurgeInput input = BulkPurgeInput.builder() - .root(123L) - .filterBy(filter) - .forceLock(true) - .build(); - - BulkPurgeInput copy = input.toBuilder() - .root(345L) - .build(); - - BulkPurgeInput expected = BulkPurgeInput.builder() - .rootList(Arrays.asList(123L, 345L)) - .filterBy(filter) - .forceLock(true) - .build(); - - assertEquals(expected, copy, "unexpected copy"); - } - - + @Test + @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") + void testEquals() { + EqualsVerifier.forClass(BulkPurgeInput.class).verify(); + } + + @Test + void testSetRootList() { + + BulkPurgeInput input = BulkPurgeInput.builder().rootList(Arrays.asList(123L)).build(); + assertEquals(Arrays.asList(123L), input.getRootList(), "unexpected rootList"); + } + + @Test + void testNullSetRootList() { + assertThrows( + NullPointerException.class, + () -> { + BulkPurgeInput.builder().rootList(null); + }, + "rootList must not be null"); + } + + @Test + void testSetRoot() { + + BulkPurgeInput input = BulkPurgeInput.builder().root(123L).build(); + assertEquals(Arrays.asList(123L), input.getRootList(), "unexpected root"); + } + + @Test + void testSetNullRoot() { + assertThrows( + NullPointerException.class, + () -> { + BulkPurgeInput.builder().root(null); + }, + "root must not be null"); + } + + @Test + void testSetFilter() { + + Filter filter = mock(); + + BulkPurgeInput input = BulkPurgeInput.builder().filterBy(filter).build(); + assertEquals(filter, input.getFilter().get(), "unexpected root"); + } + + @Test + void testSetNullFilter() { + assertThrows( + NullPointerException.class, + () -> { + BulkPurgeInput.builder().filterBy(null); + }, + "filterBy must not be null"); + } + + @Test + void testForceLock() { + BulkPurgeInput input = BulkPurgeInput.builder().root(123L).forceLock(true).build(); + assertTrue(input.isForceLock(), "unexpected forceLock"); + } + + @Test + void testRootAndFilterNotSet() { + assertThrows( + IllegalStateException.class, + () -> { + BulkPurgeInput.builder().build(); + }); + } + + @Test + void testToBuilderWithNewRootList() { + + Filter filter = mock(); + + BulkPurgeInput input = + BulkPurgeInput.builder().root(123L).filterBy(filter).forceLock(true).build(); + + BulkPurgeInput copy = input.toBuilder().rootList(Arrays.asList(345L)).build(); + + BulkPurgeInput expected = + BulkPurgeInput.builder().root(345L).filterBy(filter).forceLock(true).build(); + + assertEquals(expected, copy, "unexpected copy"); + } + + @Test + void testToBuilderAppendRootList() { + + Filter filter = mock(); + + BulkPurgeInput input = + BulkPurgeInput.builder().root(123L).filterBy(filter).forceLock(true).build(); + + BulkPurgeInput copy = input.toBuilder().root(345L).build(); + + BulkPurgeInput expected = + BulkPurgeInput.builder() + .rootList(Arrays.asList(123L, 345L)) + .filterBy(filter) + .forceLock(true) + .build(); + + assertEquals(expected, copy, "unexpected copy"); + } } diff --git a/src/test/java/com/sitepark/ies/contentrepository/core/usecase/BulkPurgeTest.java b/src/test/java/com/sitepark/ies/contentrepository/core/usecase/BulkPurgeTest.java index b4f7d68..4620705 100644 --- a/src/test/java/com/sitepark/ies/contentrepository/core/usecase/BulkPurgeTest.java +++ b/src/test/java/com/sitepark/ies/contentrepository/core/usecase/BulkPurgeTest.java @@ -7,10 +7,6 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import java.util.Arrays; - -import org.junit.jupiter.api.Test; - import com.sitepark.ies.contentrepository.core.domain.entity.Entity; import com.sitepark.ies.contentrepository.core.domain.entity.EntityBulkExecution; import com.sitepark.ies.contentrepository.core.domain.entity.EntityBulkOperation; @@ -26,148 +22,125 @@ import com.sitepark.ies.contentrepository.core.port.RecycleBin; import com.sitepark.ies.contentrepository.core.port.SearchIndex; import com.sitepark.ies.contentrepository.core.port.VersioningManager; +import java.util.Arrays; +import org.junit.jupiter.api.Test; class BulkPurgeTest { - @Test - void testAccessDeniedForEntity() { - - BulkPurgeInput input = BulkPurgeInput.builder() - .root(123L) - .build(); - - Entity entity = Entity.builder() - .id("200") - .build(); - - ContentRepository repository = mock(); - when(repository.getAll(any())).thenReturn(Arrays.asList(entity)); - - AccessControl accessControl = mock(); - when(accessControl.isEntityRemovable(anyString())).thenReturn(false); - - BulkPurge bulkPurge = new BulkPurge( - repository, - null, - null, - null, - accessControl, - null, - null, - null, - null, - null, - null); - - assertThrows(AccessDeniedException.class, () -> { - bulkPurge.bulkPurge(input); - }, "AccessDeniedException expected"); - } - - @Test - void testAccessDeniedForGroup() { - - BulkPurgeInput input = BulkPurgeInput.builder() - .root(123L) - .build(); - - Entity entity = Entity.builder() - .id("200") - .isGroup(true) - .build(); - - ContentRepository repository = mock(); - when(repository.getAll(any())).thenReturn(Arrays.asList(entity)); - - AccessControl accessControl = mock(); - when(accessControl.isGroupRemoveable(anyString())).thenReturn(false); - - BulkPurge bulkPurge = new BulkPurge( - repository, - null, - null, - null, - accessControl, - null, - null, - null, - null, - null, - null); - - assertThrows(AccessDeniedException.class, () -> { - bulkPurge.bulkPurge(input); - }, "AccessDeniedException expected"); - } - - @Test - @SuppressWarnings("PMD.JUnitTestContainsTooManyAsserts") - void test() { - - BulkPurgeInput input = BulkPurgeInput.builder() - .root(123L) - .build(); - - Entity entity = Entity.builder() - .id("200") - .build(); - - ContentRepository repository = mock(); - when(repository.getAll(any())).thenReturn(Arrays.asList(entity)); - - AccessControl accessControl = mock(); - when(accessControl.isEntityRemovable(anyString())).thenReturn(true); - - EntityBulkExecutor entityBulkExecutor = mock(); - when(entityBulkExecutor.execute(any(EntityBulkExecution.class))).thenAnswer(args -> { - - EntityBulkExecution execution = args.getArgument(0); - - for (EntityBulkOperation operation : execution.getOperations()) { - operation.getConsumer().accept(entity); - } - execution.getFinalizer().get().getConsumer().accept(entity); - - return "123"; - }); - - EntityLockManager lockManager = mock(); - Publisher publisher = mock(); - SearchIndex searchIndex = mock(); - MediaReferenceManager mediaReferenceManager = mock(); - HistoryManager historyManager = mock(); - VersioningManager versioningManager = mock(); - RecycleBin recycleBin = mock(); - ExtensionsNotifier extensionsNotifier = mock(); - - BulkPurge bulkPurge = new BulkPurge( - repository, - lockManager, - versioningManager, - historyManager, - accessControl, - recycleBin, - searchIndex, - mediaReferenceManager, - publisher, - extensionsNotifier, - entityBulkExecutor); - - bulkPurge.bulkPurge(input); - - verify(lockManager).lock(anyString()); - verify(publisher).depublish(anyString()); - - verify(searchIndex).remove(anyString()); - verify(mediaReferenceManager).removeByReference(anyString()); - verify(repository).removeEntity(anyString()); - verify(historyManager).purge(anyString()); - verify(versioningManager).removeAllVersions(anyString()); - verify(recycleBin).removeByObject(anyString()); - verify(extensionsNotifier).notifyPurge(anyString()); - - verify(lockManager).unlock(anyString()); - - - } + @Test + void testAccessDeniedForEntity() { + + BulkPurgeInput input = BulkPurgeInput.builder().root(123L).build(); + + Entity entity = Entity.builder().id("200").build(); + + ContentRepository repository = mock(); + when(repository.getAll(any())).thenReturn(Arrays.asList(entity)); + + AccessControl accessControl = mock(); + when(accessControl.isEntityRemovable(anyString())).thenReturn(false); + + BulkPurge bulkPurge = + new BulkPurge( + repository, null, null, null, accessControl, null, null, null, null, null, null); + + assertThrows( + AccessDeniedException.class, + () -> { + bulkPurge.bulkPurge(input); + }, + "AccessDeniedException expected"); + } + + @Test + void testAccessDeniedForGroup() { + + BulkPurgeInput input = BulkPurgeInput.builder().root(123L).build(); + + Entity entity = Entity.builder().id("200").isGroup(true).build(); + + ContentRepository repository = mock(); + when(repository.getAll(any())).thenReturn(Arrays.asList(entity)); + + AccessControl accessControl = mock(); + when(accessControl.isGroupRemoveable(anyString())).thenReturn(false); + + BulkPurge bulkPurge = + new BulkPurge( + repository, null, null, null, accessControl, null, null, null, null, null, null); + + assertThrows( + AccessDeniedException.class, + () -> { + bulkPurge.bulkPurge(input); + }, + "AccessDeniedException expected"); + } + + @Test + @SuppressWarnings("PMD.JUnitTestContainsTooManyAsserts") + void test() { + + BulkPurgeInput input = BulkPurgeInput.builder().root(123L).build(); + + Entity entity = Entity.builder().id("200").build(); + + ContentRepository repository = mock(); + when(repository.getAll(any())).thenReturn(Arrays.asList(entity)); + + AccessControl accessControl = mock(); + when(accessControl.isEntityRemovable(anyString())).thenReturn(true); + + EntityBulkExecutor entityBulkExecutor = mock(); + when(entityBulkExecutor.execute(any(EntityBulkExecution.class))) + .thenAnswer( + args -> { + EntityBulkExecution execution = args.getArgument(0); + + for (EntityBulkOperation operation : execution.getOperations()) { + operation.getConsumer().accept(entity); + } + execution.getFinalizer().get().getConsumer().accept(entity); + + return "123"; + }); + + EntityLockManager lockManager = mock(); + Publisher publisher = mock(); + SearchIndex searchIndex = mock(); + MediaReferenceManager mediaReferenceManager = mock(); + HistoryManager historyManager = mock(); + VersioningManager versioningManager = mock(); + RecycleBin recycleBin = mock(); + ExtensionsNotifier extensionsNotifier = mock(); + + BulkPurge bulkPurge = + new BulkPurge( + repository, + lockManager, + versioningManager, + historyManager, + accessControl, + recycleBin, + searchIndex, + mediaReferenceManager, + publisher, + extensionsNotifier, + entityBulkExecutor); + + bulkPurge.bulkPurge(input); + + verify(lockManager).lock(anyString()); + verify(publisher).depublish(anyString()); + + verify(searchIndex).remove(anyString()); + verify(mediaReferenceManager).removeByReference(anyString()); + verify(repository).removeEntity(anyString()); + verify(historyManager).purge(anyString()); + verify(versioningManager).removeAllVersions(anyString()); + verify(recycleBin).removeByObject(anyString()); + verify(extensionsNotifier).notifyPurge(anyString()); + + verify(lockManager).unlock(anyString()); + } } diff --git a/src/test/java/com/sitepark/ies/contentrepository/core/usecase/GetAllEntitiesTest.java b/src/test/java/com/sitepark/ies/contentrepository/core/usecase/GetAllEntitiesTest.java index 7690051..28aefff 100644 --- a/src/test/java/com/sitepark/ies/contentrepository/core/usecase/GetAllEntitiesTest.java +++ b/src/test/java/com/sitepark/ies/contentrepository/core/usecase/GetAllEntitiesTest.java @@ -5,29 +5,24 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import com.sitepark.ies.contentrepository.core.domain.entity.Entity; +import com.sitepark.ies.contentrepository.core.port.ContentRepository; import java.util.Arrays; import java.util.List; - import org.junit.jupiter.api.Test; -import com.sitepark.ies.contentrepository.core.domain.entity.Entity; -import com.sitepark.ies.contentrepository.core.port.ContentRepository; - class GetAllEntitiesTest { - @Test - void test() { + @Test + void test() { - ContentRepository repository = mock(); - Entity entity = mock(); - List list = Arrays.asList(entity); - when(repository.getAll(any())).thenReturn(list); + ContentRepository repository = mock(); + Entity entity = mock(); + List list = Arrays.asList(entity); + when(repository.getAll(any())).thenReturn(list); - var getAllEntities = new GetAllEntities(repository); + var getAllEntities = new GetAllEntities(repository); - assertEquals( - list, - getAllEntities.getAllEntities(null), - "unexpected entities"); - } + assertEquals(list, getAllEntities.getAllEntities(null), "unexpected entities"); + } } diff --git a/src/test/java/com/sitepark/ies/contentrepository/core/usecase/PurgeEntityTest.java b/src/test/java/com/sitepark/ies/contentrepository/core/usecase/PurgeEntityTest.java index 7fa03bf..80fbbbc 100644 --- a/src/test/java/com/sitepark/ies/contentrepository/core/usecase/PurgeEntityTest.java +++ b/src/test/java/com/sitepark/ies/contentrepository/core/usecase/PurgeEntityTest.java @@ -8,9 +8,6 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import org.junit.jupiter.api.Test; -import org.mockito.InOrder; - import com.sitepark.ies.contentrepository.core.domain.entity.EntityLock; import com.sitepark.ies.contentrepository.core.domain.exception.AccessDeniedException; import com.sitepark.ies.contentrepository.core.domain.exception.EntityLockedException; @@ -25,193 +22,180 @@ import com.sitepark.ies.contentrepository.core.port.RecycleBin; import com.sitepark.ies.contentrepository.core.port.SearchIndex; import com.sitepark.ies.contentrepository.core.port.VersioningManager; +import org.junit.jupiter.api.Test; +import org.mockito.InOrder; class PurgeEntityTest { - @Test - void testAccessDenied() { - - AccessControl accessControl = mock(AccessControl.class); - when(accessControl.isEntityRemovable(anyString())).thenReturn(false); - - var purgeEntity = new PurgeEntity( - null, - null, - null, - null, - accessControl, - null, - null, - null, - null, - null); - assertThrows(AccessDeniedException.class, () -> { - purgeEntity.purgeEntity("10"); - }, "access should be denied"); - } - - @Test - void testGroupNotEmptyException() { - - AccessControl accessControl = mock(AccessControl.class); - when(accessControl.isEntityRemovable(anyString())).thenReturn(true); - - ContentRepository repository = mock(ContentRepository.class); - when(repository.isGroup(anyString())).thenReturn(true); - when(repository.isEmptyGroup(anyString())).thenReturn(false); - - var purgeEntity = new PurgeEntity( - repository, - null, - null, - null, - accessControl, - null, - null, - null, - null, - null); - assertThrows(GroupNotEmptyException.class, () -> { - purgeEntity.purgeEntity("10"); - }, "only empty groups may be purged"); - } - - @Test - void testEntityIsLocked() { - - ContentRepository repository = mock(ContentRepository.class); - when(repository.isGroup("10")).thenReturn(false); - AccessControl accessControl = mock(AccessControl.class); - when(accessControl.isEntityRemovable(anyString())).thenReturn(true); - - EntityLockManager lockManager = mock(EntityLockManager.class); - doThrow( - new EntityLockedException(EntityLock.builder().entity("10").build())) - .when(lockManager) - .lock(anyString()); - - var purgeEntity = new PurgeEntity( - repository, - lockManager, - null, - null, - accessControl, - null, - null, - null, - null, - null); - //purgeEntity.purgeEntity(10L); - - EntityLockedException entityLockedException = assertThrows(EntityLockedException.class, () -> { - purgeEntity.purgeEntity("10"); - }, "entity should be locked"); - assertEquals("10", entityLockedException.getLock().getEntity(), "unexpected entity id"); - } - - @SuppressWarnings("PMD") - @Test - void testPurgeEntity() { - - AccessControl accessControl = mock(AccessControl.class); - when(accessControl.isEntityRemovable(anyString())).thenReturn(true); - - ContentRepository repository = mock(ContentRepository.class); - EntityLockManager lockManager = mock(EntityLockManager.class); - VersioningManager versioningManager = mock(VersioningManager.class); - HistoryManager historyManager = mock(HistoryManager.class); - - RecycleBin recycleBin = mock(RecycleBin.class); - SearchIndex searchIndex = mock(SearchIndex.class); - MediaReferenceManager mediaReferenceManager = mock(MediaReferenceManager.class); - Publisher publisher = mock(Publisher.class); - ExtensionsNotifier extensionsNotifier = mock(ExtensionsNotifier.class); - - PurgeEntity purgeEntity = new PurgeEntity( - repository, - lockManager, - versioningManager, - historyManager, - accessControl, - recycleBin, - searchIndex, - mediaReferenceManager, - publisher, - extensionsNotifier); - purgeEntity.purgeEntity("10"); - - InOrder inOrder = inOrder( - publisher, - searchIndex, - mediaReferenceManager, - repository, - historyManager, - versioningManager, - recycleBin, - extensionsNotifier - ); - - inOrder.verify(publisher).depublish("10"); - inOrder.verify(searchIndex).remove("10"); - inOrder.verify(mediaReferenceManager).removeByReference("10"); - inOrder.verify(repository).removeEntity("10"); - inOrder.verify(historyManager).purge("10"); - inOrder.verify(versioningManager).removeAllVersions("10"); - inOrder.verify(recycleBin).removeByObject("10"); - inOrder.verify(extensionsNotifier).notifyPurge("10"); - } - - @SuppressWarnings("PMD") - @Test - void testPurgeGroup() { - - AccessControl accessControl = mock(AccessControl.class); - when(accessControl.isEntityRemovable(anyString())).thenReturn(true); - - ContentRepository repository = mock(ContentRepository.class); - when(repository.isGroup(anyString())).thenReturn(true); - when(repository.isEmptyGroup(anyString())).thenReturn(true); - EntityLockManager lockManager = mock(EntityLockManager.class); - VersioningManager versioningManager = mock(VersioningManager.class); - HistoryManager historyManager = mock(HistoryManager.class); - - RecycleBin recycleBin = mock(RecycleBin.class); - SearchIndex searchIndex = mock(SearchIndex.class); - MediaReferenceManager mediaReferenceManager = mock(MediaReferenceManager.class); - Publisher publisher = mock(Publisher.class); - ExtensionsNotifier extensionsNotifier = mock(ExtensionsNotifier.class); - - PurgeEntity purgeEntity = new PurgeEntity( - repository, - lockManager, - versioningManager, - historyManager, - accessControl, - recycleBin, - searchIndex, - mediaReferenceManager, - publisher, - extensionsNotifier); - purgeEntity.purgeEntity("10"); - - InOrder inOrder = inOrder( - publisher, - searchIndex, - mediaReferenceManager, - repository, - historyManager, - versioningManager, - recycleBin, - extensionsNotifier - ); - - inOrder.verify(publisher).depublish("10"); - inOrder.verify(searchIndex).remove("10"); - inOrder.verify(mediaReferenceManager).removeByReference("10"); - inOrder.verify(repository).removeEntity("10"); - inOrder.verify(historyManager).purge("10"); - inOrder.verify(versioningManager).removeAllVersions("10"); - inOrder.verify(recycleBin).removeByObject("10"); - inOrder.verify(extensionsNotifier).notifyPurge("10"); - } + @Test + void testAccessDenied() { + + AccessControl accessControl = mock(AccessControl.class); + when(accessControl.isEntityRemovable(anyString())).thenReturn(false); + + var purgeEntity = + new PurgeEntity(null, null, null, null, accessControl, null, null, null, null, null); + assertThrows( + AccessDeniedException.class, + () -> { + purgeEntity.purgeEntity("10"); + }, + "access should be denied"); + } + + @Test + void testGroupNotEmptyException() { + + AccessControl accessControl = mock(AccessControl.class); + when(accessControl.isEntityRemovable(anyString())).thenReturn(true); + + ContentRepository repository = mock(ContentRepository.class); + when(repository.isGroup(anyString())).thenReturn(true); + when(repository.isEmptyGroup(anyString())).thenReturn(false); + + var purgeEntity = + new PurgeEntity(repository, null, null, null, accessControl, null, null, null, null, null); + assertThrows( + GroupNotEmptyException.class, + () -> { + purgeEntity.purgeEntity("10"); + }, + "only empty groups may be purged"); + } + + @Test + void testEntityIsLocked() { + + ContentRepository repository = mock(ContentRepository.class); + when(repository.isGroup("10")).thenReturn(false); + AccessControl accessControl = mock(AccessControl.class); + when(accessControl.isEntityRemovable(anyString())).thenReturn(true); + + EntityLockManager lockManager = mock(EntityLockManager.class); + doThrow(new EntityLockedException(EntityLock.builder().entity("10").build())) + .when(lockManager) + .lock(anyString()); + + var purgeEntity = + new PurgeEntity( + repository, lockManager, null, null, accessControl, null, null, null, null, null); + // purgeEntity.purgeEntity(10L); + + EntityLockedException entityLockedException = + assertThrows( + EntityLockedException.class, + () -> { + purgeEntity.purgeEntity("10"); + }, + "entity should be locked"); + assertEquals("10", entityLockedException.getLock().getEntity(), "unexpected entity id"); + } + + @SuppressWarnings("PMD") + @Test + void testPurgeEntity() { + + AccessControl accessControl = mock(AccessControl.class); + when(accessControl.isEntityRemovable(anyString())).thenReturn(true); + + ContentRepository repository = mock(ContentRepository.class); + EntityLockManager lockManager = mock(EntityLockManager.class); + VersioningManager versioningManager = mock(VersioningManager.class); + HistoryManager historyManager = mock(HistoryManager.class); + + RecycleBin recycleBin = mock(RecycleBin.class); + SearchIndex searchIndex = mock(SearchIndex.class); + MediaReferenceManager mediaReferenceManager = mock(MediaReferenceManager.class); + Publisher publisher = mock(Publisher.class); + ExtensionsNotifier extensionsNotifier = mock(ExtensionsNotifier.class); + + PurgeEntity purgeEntity = + new PurgeEntity( + repository, + lockManager, + versioningManager, + historyManager, + accessControl, + recycleBin, + searchIndex, + mediaReferenceManager, + publisher, + extensionsNotifier); + purgeEntity.purgeEntity("10"); + + InOrder inOrder = + inOrder( + publisher, + searchIndex, + mediaReferenceManager, + repository, + historyManager, + versioningManager, + recycleBin, + extensionsNotifier); + + inOrder.verify(publisher).depublish("10"); + inOrder.verify(searchIndex).remove("10"); + inOrder.verify(mediaReferenceManager).removeByReference("10"); + inOrder.verify(repository).removeEntity("10"); + inOrder.verify(historyManager).purge("10"); + inOrder.verify(versioningManager).removeAllVersions("10"); + inOrder.verify(recycleBin).removeByObject("10"); + inOrder.verify(extensionsNotifier).notifyPurge("10"); + } + + @SuppressWarnings("PMD") + @Test + void testPurgeGroup() { + + AccessControl accessControl = mock(AccessControl.class); + when(accessControl.isEntityRemovable(anyString())).thenReturn(true); + + ContentRepository repository = mock(ContentRepository.class); + when(repository.isGroup(anyString())).thenReturn(true); + when(repository.isEmptyGroup(anyString())).thenReturn(true); + EntityLockManager lockManager = mock(EntityLockManager.class); + VersioningManager versioningManager = mock(VersioningManager.class); + HistoryManager historyManager = mock(HistoryManager.class); + + RecycleBin recycleBin = mock(RecycleBin.class); + SearchIndex searchIndex = mock(SearchIndex.class); + MediaReferenceManager mediaReferenceManager = mock(MediaReferenceManager.class); + Publisher publisher = mock(Publisher.class); + ExtensionsNotifier extensionsNotifier = mock(ExtensionsNotifier.class); + + PurgeEntity purgeEntity = + new PurgeEntity( + repository, + lockManager, + versioningManager, + historyManager, + accessControl, + recycleBin, + searchIndex, + mediaReferenceManager, + publisher, + extensionsNotifier); + purgeEntity.purgeEntity("10"); + + InOrder inOrder = + inOrder( + publisher, + searchIndex, + mediaReferenceManager, + repository, + historyManager, + versioningManager, + recycleBin, + extensionsNotifier); + + inOrder.verify(publisher).depublish("10"); + inOrder.verify(searchIndex).remove("10"); + inOrder.verify(mediaReferenceManager).removeByReference("10"); + inOrder.verify(repository).removeEntity("10"); + inOrder.verify(historyManager).purge("10"); + inOrder.verify(versioningManager).removeAllVersions("10"); + inOrder.verify(recycleBin).removeByObject("10"); + inOrder.verify(extensionsNotifier).notifyPurge("10"); + } } diff --git a/src/test/java/com/sitepark/ies/contentrepository/core/usecase/RecoverEntityTest.java b/src/test/java/com/sitepark/ies/contentrepository/core/usecase/RecoverEntityTest.java index 48a821a..404b706 100644 --- a/src/test/java/com/sitepark/ies/contentrepository/core/usecase/RecoverEntityTest.java +++ b/src/test/java/com/sitepark/ies/contentrepository/core/usecase/RecoverEntityTest.java @@ -7,10 +7,6 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import java.util.Optional; - -import org.junit.jupiter.api.Test; - import com.sitepark.ies.contentrepository.core.domain.entity.RecycleBinItem; import com.sitepark.ies.contentrepository.core.domain.exception.AccessDeniedException; import com.sitepark.ies.contentrepository.core.port.AccessControl; @@ -18,61 +14,58 @@ import com.sitepark.ies.contentrepository.core.port.HistoryManager; import com.sitepark.ies.contentrepository.core.port.RecycleBin; import com.sitepark.ies.contentrepository.core.port.SearchIndex; +import java.util.Optional; +import org.junit.jupiter.api.Test; class RecoverEntityTest { - @Test - void testAccessDenied() { + @Test + void testAccessDenied() { - ContentRepository repository = mock(); - HistoryManager historyManager = mock(); - RecycleBin recycleBin = mock(); - SearchIndex searchIndex = mock(); + ContentRepository repository = mock(); + HistoryManager historyManager = mock(); + RecycleBin recycleBin = mock(); + SearchIndex searchIndex = mock(); - RecycleBinItem recycleBinItem = mock(); - when(recycleBin.get(anyString())).thenReturn(Optional.of(recycleBinItem)); + RecycleBinItem recycleBinItem = mock(); + when(recycleBin.get(anyString())).thenReturn(Optional.of(recycleBinItem)); - AccessControl accessControl = mock(); - when(accessControl.isGroupCreateable(anyString())).thenReturn(false); + AccessControl accessControl = mock(); + when(accessControl.isGroupCreateable(anyString())).thenReturn(false); - RecoverEntity recoverEntity = new RecoverEntity( - repository, - historyManager, - accessControl, - recycleBin, - searchIndex); + RecoverEntity recoverEntity = + new RecoverEntity(repository, historyManager, accessControl, recycleBin, searchIndex); - assertThrows(AccessDeniedException.class, () -> { - recoverEntity.recover("123"); - }, "recover should be denied access"); - } + assertThrows( + AccessDeniedException.class, + () -> { + recoverEntity.recover("123"); + }, + "recover should be denied access"); + } - @Test - @SuppressWarnings("PMD.JUnitTestContainsTooManyAsserts") - void test() { + @Test + @SuppressWarnings("PMD.JUnitTestContainsTooManyAsserts") + void test() { - ContentRepository repository = mock(); - HistoryManager historyManager = mock(); - RecycleBin recycleBin = mock(); - SearchIndex searchIndex = mock(); + ContentRepository repository = mock(); + HistoryManager historyManager = mock(); + RecycleBin recycleBin = mock(); + SearchIndex searchIndex = mock(); - RecycleBinItem recycleBinItem = mock(); - when(recycleBin.get(anyString())).thenReturn(Optional.of(recycleBinItem)); + RecycleBinItem recycleBinItem = mock(); + when(recycleBin.get(anyString())).thenReturn(Optional.of(recycleBinItem)); - AccessControl accessControl = mock(); - when(accessControl.isGroupCreateable(any())).thenReturn(true); + AccessControl accessControl = mock(); + when(accessControl.isGroupCreateable(any())).thenReturn(true); - RecoverEntity recoverEntity = new RecoverEntity( - repository, - historyManager, - accessControl, - recycleBin, - searchIndex); + RecoverEntity recoverEntity = + new RecoverEntity(repository, historyManager, accessControl, recycleBin, searchIndex); - recoverEntity.recover("123"); + recoverEntity.recover("123"); - verify(repository).store(any()); - verify(historyManager).createEntry(any(), any(), any()); - verify(searchIndex).index(anyString()); - } + verify(repository).store(any()); + verify(historyManager).createEntry(any(), any(), any()); + verify(searchIndex).index(anyString()); + } } diff --git a/src/test/java/com/sitepark/ies/contentrepository/core/usecase/RemoveEntityTest.java b/src/test/java/com/sitepark/ies/contentrepository/core/usecase/RemoveEntityTest.java index 54e50b9..3defb77 100644 --- a/src/test/java/com/sitepark/ies/contentrepository/core/usecase/RemoveEntityTest.java +++ b/src/test/java/com/sitepark/ies/contentrepository/core/usecase/RemoveEntityTest.java @@ -7,10 +7,6 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import java.util.Optional; - -import org.junit.jupiter.api.Test; - import com.sitepark.ies.contentrepository.core.domain.entity.Entity; import com.sitepark.ies.contentrepository.core.domain.entity.EntityLock; import com.sitepark.ies.contentrepository.core.domain.exception.AccessDeniedException; @@ -22,92 +18,88 @@ import com.sitepark.ies.contentrepository.core.port.Publisher; import com.sitepark.ies.contentrepository.core.port.RecycleBin; import com.sitepark.ies.contentrepository.core.port.SearchIndex; +import java.util.Optional; +import org.junit.jupiter.api.Test; class RemoveEntityTest { - @Test - void testAccessDenied() { - - AccessControl accessControl = mock(); - when(accessControl.isEntityRemovable(anyString())).thenReturn(false); - - RemoveEntity removeEntity = new RemoveEntity( - null, - null, - null, - accessControl, - null, - null, - null); - - assertThrows(AccessDeniedException.class, () -> { - removeEntity.remove("123"); - }, "remove should be denied access"); - } - - @Test - void testLocked() { - - AccessControl accessControl = mock(); - when(accessControl.isEntityRemovable(anyString())).thenReturn(true); - - ContentRepository repository = mock(); - Entity entity = mock(); - when(repository.get(anyString())).thenReturn(Optional.of(entity)); - - EntityLock lock = mock(); - EntityLockManager lockManager = mock(); - when(lockManager.getLock(anyString())).thenReturn(Optional.of(lock)); - - RemoveEntity removeEntity = new RemoveEntity( - repository, - lockManager, - null, - accessControl, - null, - null, - null); - - assertThrows(EntityLockedException.class, () -> { - removeEntity.remove("123"); - }, "entity should be locked"); - } - - @Test - @SuppressWarnings("PMD.JUnitTestContainsTooManyAsserts") - void test() { - - AccessControl accessControl = mock(); - when(accessControl.isEntityRemovable(anyString())).thenReturn(true); - - ContentRepository repository = mock(); - Entity entity = mock(); - when(repository.get(anyString())).thenReturn(Optional.of(entity)); - - EntityLockManager lockManager = mock(); - HistoryManager historyManager = mock(); - RecycleBin recycleBin = mock(); - SearchIndex searchIndex = mock(); - Publisher publisher = mock(); - - RemoveEntity removeEntity = new RemoveEntity( - repository, - lockManager, - historyManager, - accessControl, - recycleBin, - searchIndex, - publisher); - - removeEntity.remove("123"); - - verify(repository).get(anyString()); - verify(lockManager).getLock(anyString()); - verify(searchIndex).remove(anyString()); - verify(publisher).depublish(anyString()); - verify(repository).removeEntity(anyString()); - verify(historyManager).createEntry(anyString(), any(), any()); - verify(recycleBin).add(any()); - verify(lockManager).unlock(anyString()); - } + @Test + void testAccessDenied() { + + AccessControl accessControl = mock(); + when(accessControl.isEntityRemovable(anyString())).thenReturn(false); + + RemoveEntity removeEntity = new RemoveEntity(null, null, null, accessControl, null, null, null); + + assertThrows( + AccessDeniedException.class, + () -> { + removeEntity.remove("123"); + }, + "remove should be denied access"); + } + + @Test + void testLocked() { + + AccessControl accessControl = mock(); + when(accessControl.isEntityRemovable(anyString())).thenReturn(true); + + ContentRepository repository = mock(); + Entity entity = mock(); + when(repository.get(anyString())).thenReturn(Optional.of(entity)); + + EntityLock lock = mock(); + EntityLockManager lockManager = mock(); + when(lockManager.getLock(anyString())).thenReturn(Optional.of(lock)); + + RemoveEntity removeEntity = + new RemoveEntity(repository, lockManager, null, accessControl, null, null, null); + + assertThrows( + EntityLockedException.class, + () -> { + removeEntity.remove("123"); + }, + "entity should be locked"); + } + + @Test + @SuppressWarnings("PMD.JUnitTestContainsTooManyAsserts") + void test() { + + AccessControl accessControl = mock(); + when(accessControl.isEntityRemovable(anyString())).thenReturn(true); + + ContentRepository repository = mock(); + Entity entity = mock(); + when(repository.get(anyString())).thenReturn(Optional.of(entity)); + + EntityLockManager lockManager = mock(); + HistoryManager historyManager = mock(); + RecycleBin recycleBin = mock(); + SearchIndex searchIndex = mock(); + Publisher publisher = mock(); + + RemoveEntity removeEntity = + new RemoveEntity( + repository, + lockManager, + historyManager, + accessControl, + recycleBin, + searchIndex, + publisher); + + removeEntity.remove("123"); + + verify(repository).get(anyString()); + verify(lockManager).getLock(anyString()); + verify(searchIndex).remove(anyString()); + verify(publisher).depublish(anyString()); + verify(repository).removeEntity(anyString()); + verify(historyManager).createEntry(anyString(), any(), any()); + verify(recycleBin).add(any()); + verify(lockManager).unlock(anyString()); + } } diff --git a/src/test/java/com/sitepark/ies/contentrepository/core/usecase/StoreEntityTest.java b/src/test/java/com/sitepark/ies/contentrepository/core/usecase/StoreEntityTest.java index 607f6a9..1291e03 100644 --- a/src/test/java/com/sitepark/ies/contentrepository/core/usecase/StoreEntityTest.java +++ b/src/test/java/com/sitepark/ies/contentrepository/core/usecase/StoreEntityTest.java @@ -8,12 +8,6 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import java.time.OffsetDateTime; -import java.time.ZoneOffset; -import java.util.Optional; - -import org.junit.jupiter.api.Test; - import com.sitepark.ies.contentrepository.core.domain.entity.ChangeSet; import com.sitepark.ies.contentrepository.core.domain.entity.Entity; import com.sitepark.ies.contentrepository.core.domain.entity.EntityLock; @@ -29,241 +23,213 @@ import com.sitepark.ies.contentrepository.core.port.IdGenerator; import com.sitepark.ies.contentrepository.core.port.SearchIndex; import com.sitepark.ies.contentrepository.core.port.VersioningManager; +import java.time.OffsetDateTime; +import java.time.ZoneOffset; +import java.util.Optional; +import org.junit.jupiter.api.Test; @SuppressWarnings("PMD.AvoidDuplicateLiterals") class StoreEntityTest { - @Test - void testParentMissing() { - - Entity entity = mock(); - when(entity.getParent()).thenReturn(Optional.empty()); - - StoreEntity storeEntity = new StoreEntity( - null, - null, - null, - null, - null, - null, - null, - null); - - assertThrows(ParentMissingException.class, () -> { - storeEntity.store(entity); - }, "entity must have a parent"); - } - - @Test - void testCreateAccessDenied() { - - Entity entity = mock(); - when(entity.getParent()).thenReturn(Optional.of("123")); - - AccessControl accessControl = mock(); - when(accessControl.isEntityCreateable(anyString())).thenReturn(false); - - StoreEntity storeEntity = new StoreEntity( - null, - null, - null, - null, - accessControl, - null, - null, - null); - - assertThrows(AccessDeniedException.class, () -> { - storeEntity.store(entity); - }, "should be access denied"); - } - - @Test - @SuppressWarnings("PMD.JUnitTestContainsTooManyAsserts") - void testCreate() { - - Entity entity = Entity.builder() - .parent("345") - .build(); - - AccessControl accessControl = mock(); - when(accessControl.isEntityCreateable(anyString())).thenReturn(true); - - ContentRepository repository = mock(); - VersioningManager versioningManager = mock(); - HistoryManager historyManager = mock(); - IdGenerator idGenerator = mock(); - SearchIndex searchIndex = mock(); - ContentDiffer contentDiffer = mock(); - - when(idGenerator.generate()).thenReturn("123"); - - OffsetDateTime version = OffsetDateTime.of(2024, 5, 2, 10, 10, 0, 0, ZoneOffset.UTC); - - when(versioningManager.createNewVersion(any(Entity.class))).thenAnswer(args -> { - Entity arg = args.getArgument(0); - return arg.toBuilder().version(version).build(); - }); - - StoreEntity storeEntity = new StoreEntity( - repository, - null, - versioningManager, - historyManager, - accessControl, - idGenerator, - searchIndex, - contentDiffer); - - String id = storeEntity.store(entity); - - verify(repository).store(any()); - verify(historyManager).createEntry(anyString(), any(), any()); - verify(searchIndex).index(anyString()); - - assertEquals("123", id, "unexpected generated id"); - } - - @Test - void testUpdateNotFound() { - - Entity entity = Entity.builder() - .id("123") - .parent("345") - .build(); - - ContentRepository repository = mock(); - - when(repository.get(anyString())).thenReturn(Optional.empty()); - - StoreEntity storeEntity = new StoreEntity( - repository, - null, - null, - null, - null, - null, - null, - null); - - assertThrows(EntityNotFoundException.class, () -> { - storeEntity.store(entity); - }, "should be not found"); - } - - @Test - void testUpdateAccessDenied() { - - Entity entity = Entity.builder() - .id("123") - .parent("345") - .build(); - - AccessControl accessControl = mock(); - when(accessControl.isEntityWritable(anyString())).thenReturn(false); - - ContentRepository repository = mock(); - - when(repository.get(anyString())).thenReturn(Optional.of(entity)); - - StoreEntity storeEntity = new StoreEntity( - repository, - null, - null, - null, - accessControl, - null, - null, - null); - - assertThrows(AccessDeniedException.class, () -> { - storeEntity.store(entity); - }, "should be access denied"); - } - - @Test - void testUpdateEntityIsLocked() { - - Entity entity = Entity.builder() - .id("123") - .parent("345") - .build(); - - AccessControl accessControl = mock(); - when(accessControl.isEntityWritable(anyString())).thenReturn(true); - - ContentRepository repository = mock(); - when(repository.get(anyString())).thenReturn(Optional.of(entity)); - - EntityLock entityLock = mock(); - EntityLockManager lockManager = mock(); - when(lockManager.getLock(anyString())).thenReturn(Optional.of(entityLock)); - - - StoreEntity storeEntity = new StoreEntity( - repository, - lockManager, - null, - null, - accessControl, - null, - null, - null); - - assertThrows(EntityLockedException.class, () -> { - storeEntity.store(entity); - }, "entity should be locked"); - } - - @Test - @SuppressWarnings("PMD.JUnitTestContainsTooManyAsserts") - void testUpdate() { - - Entity entity = Entity.builder() - .id("123") - .parent("345") - .build(); - - AccessControl accessControl = mock(); - when(accessControl.isEntityWritable(anyString())).thenReturn(true); - - ContentRepository repository = mock(); - EntityLockManager lockManager = mock(); - VersioningManager versioningManager = mock(); - HistoryManager historyManager = mock(); - SearchIndex searchIndex = mock(); - ContentDiffer contentDiffer = mock(); - ChangeSet changeSet = mock(); - - when(repository.get(anyString())).thenReturn(Optional.of(entity)); - when(contentDiffer.diff(any(), any())).thenReturn(changeSet); - when(changeSet.isEmpty()).thenReturn(false); - - OffsetDateTime version = OffsetDateTime.of(2024, 5, 2, 10, 10, 0, 0, ZoneOffset.UTC); - - when(versioningManager.createNewVersion(any(Entity.class))).thenAnswer(args -> { - Entity arg = args.getArgument(0); - return arg.toBuilder().version(version).build(); - }); - - StoreEntity storeEntity = new StoreEntity( - repository, - lockManager, - versioningManager, - historyManager, - accessControl, - null, - searchIndex, - contentDiffer); - - String id = storeEntity.store(entity); - - verify(repository).store(any()); - verify(historyManager).createEntry(anyString(), any(), any()); - verify(searchIndex).index(anyString()); - verify(lockManager).unlock(anyString()); - - assertEquals("123", id, "unexpected generated id"); - } + @Test + void testParentMissing() { + + Entity entity = mock(); + when(entity.getParent()).thenReturn(Optional.empty()); + + StoreEntity storeEntity = new StoreEntity(null, null, null, null, null, null, null, null); + + assertThrows( + ParentMissingException.class, + () -> { + storeEntity.store(entity); + }, + "entity must have a parent"); + } + + @Test + void testCreateAccessDenied() { + + Entity entity = mock(); + when(entity.getParent()).thenReturn(Optional.of("123")); + + AccessControl accessControl = mock(); + when(accessControl.isEntityCreateable(anyString())).thenReturn(false); + + StoreEntity storeEntity = + new StoreEntity(null, null, null, null, accessControl, null, null, null); + + assertThrows( + AccessDeniedException.class, + () -> { + storeEntity.store(entity); + }, + "should be access denied"); + } + + @Test + @SuppressWarnings("PMD.JUnitTestContainsTooManyAsserts") + void testCreate() { + + Entity entity = Entity.builder().parent("345").build(); + + AccessControl accessControl = mock(); + when(accessControl.isEntityCreateable(anyString())).thenReturn(true); + + ContentRepository repository = mock(); + VersioningManager versioningManager = mock(); + HistoryManager historyManager = mock(); + IdGenerator idGenerator = mock(); + SearchIndex searchIndex = mock(); + ContentDiffer contentDiffer = mock(); + + when(idGenerator.generate()).thenReturn("123"); + + OffsetDateTime version = OffsetDateTime.of(2024, 5, 2, 10, 10, 0, 0, ZoneOffset.UTC); + + when(versioningManager.createNewVersion(any(Entity.class))) + .thenAnswer( + args -> { + Entity arg = args.getArgument(0); + return arg.toBuilder().version(version).build(); + }); + + StoreEntity storeEntity = + new StoreEntity( + repository, + null, + versioningManager, + historyManager, + accessControl, + idGenerator, + searchIndex, + contentDiffer); + + String id = storeEntity.store(entity); + + verify(repository).store(any()); + verify(historyManager).createEntry(anyString(), any(), any()); + verify(searchIndex).index(anyString()); + + assertEquals("123", id, "unexpected generated id"); + } + + @Test + void testUpdateNotFound() { + + Entity entity = Entity.builder().id("123").parent("345").build(); + + ContentRepository repository = mock(); + + when(repository.get(anyString())).thenReturn(Optional.empty()); + + StoreEntity storeEntity = new StoreEntity(repository, null, null, null, null, null, null, null); + + assertThrows( + EntityNotFoundException.class, + () -> { + storeEntity.store(entity); + }, + "should be not found"); + } + + @Test + void testUpdateAccessDenied() { + + Entity entity = Entity.builder().id("123").parent("345").build(); + + AccessControl accessControl = mock(); + when(accessControl.isEntityWritable(anyString())).thenReturn(false); + + ContentRepository repository = mock(); + + when(repository.get(anyString())).thenReturn(Optional.of(entity)); + + StoreEntity storeEntity = + new StoreEntity(repository, null, null, null, accessControl, null, null, null); + + assertThrows( + AccessDeniedException.class, + () -> { + storeEntity.store(entity); + }, + "should be access denied"); + } + + @Test + void testUpdateEntityIsLocked() { + + Entity entity = Entity.builder().id("123").parent("345").build(); + + AccessControl accessControl = mock(); + when(accessControl.isEntityWritable(anyString())).thenReturn(true); + + ContentRepository repository = mock(); + when(repository.get(anyString())).thenReturn(Optional.of(entity)); + + EntityLock entityLock = mock(); + EntityLockManager lockManager = mock(); + when(lockManager.getLock(anyString())).thenReturn(Optional.of(entityLock)); + + StoreEntity storeEntity = + new StoreEntity(repository, lockManager, null, null, accessControl, null, null, null); + + assertThrows( + EntityLockedException.class, + () -> { + storeEntity.store(entity); + }, + "entity should be locked"); + } + + @Test + @SuppressWarnings("PMD.JUnitTestContainsTooManyAsserts") + void testUpdate() { + + Entity entity = Entity.builder().id("123").parent("345").build(); + + AccessControl accessControl = mock(); + when(accessControl.isEntityWritable(anyString())).thenReturn(true); + + ContentRepository repository = mock(); + EntityLockManager lockManager = mock(); + VersioningManager versioningManager = mock(); + HistoryManager historyManager = mock(); + SearchIndex searchIndex = mock(); + ContentDiffer contentDiffer = mock(); + ChangeSet changeSet = mock(); + + when(repository.get(anyString())).thenReturn(Optional.of(entity)); + when(contentDiffer.diff(any(), any())).thenReturn(changeSet); + when(changeSet.isEmpty()).thenReturn(false); + + OffsetDateTime version = OffsetDateTime.of(2024, 5, 2, 10, 10, 0, 0, ZoneOffset.UTC); + + when(versioningManager.createNewVersion(any(Entity.class))) + .thenAnswer( + args -> { + Entity arg = args.getArgument(0); + return arg.toBuilder().version(version).build(); + }); + + StoreEntity storeEntity = + new StoreEntity( + repository, + lockManager, + versioningManager, + historyManager, + accessControl, + null, + searchIndex, + contentDiffer); + + String id = storeEntity.store(entity); + + verify(repository).store(any()); + verify(historyManager).createEntry(anyString(), any(), any()); + verify(searchIndex).index(anyString()); + verify(lockManager).unlock(anyString()); + assertEquals("123", id, "unexpected generated id"); + } }