Skip to content

Commit

Permalink
test: add new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sitepark-veltrup committed Nov 2, 2023
1 parent 1b38f77 commit e80935a
Show file tree
Hide file tree
Showing 7 changed files with 475 additions and 35 deletions.
134 changes: 119 additions & 15 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,41 @@
</license>
</licenses>

<organization>
<name>Sitepark</name>
<url>https://www.sitepark.com</url>
</organization>

<developers>
<developer>
<id>veltrup@sitepark</id>
<name>Holger Veltrup</name>
<email>veltrup@sitepark.com</email>
<url>https://github.com/sitepark-veltrup</url>
<organization>Sitepark</organization>
<organizationUrl>https://www.sitepark.com</organizationUrl>
<roles>
<role>developer</role>
</roles>
<timezone>Europe/Berlin</timezone>
</developer>
</developers>

<properties>
<junit.version>5.10.0</junit.version>
<spotbugs.version>4.8.0</spotbugs.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>21</maven.compiler.release>
<gpg.skip>true</gpg.skip>
</properties>

<scm>
<connection>scm:git:git@github.com:sitepark-com/ies-contentrepository-core.git</connection>
<developerConnection>scm:git:git@github.com:sitepark-com/ies-contentrepository-core.git</developerConnection>
<url>https://github.com/sitepark-com/ies-contentrepository-core</url>
<connection>scm:git:git@github.com:sitepark/ies-contentrepository-core.git</connection>
<developerConnection>scm:git:git@github.com:sitepark/ies-contentrepository-core.git</developerConnection>
<url>https://github.com/sitepark/ies-contentrepository-core</url>
<tag>HEAD</tag>
</scm>

<distributionManagement>
<repository>
<id>release</id>
<url>https://develop.sitepark.com/nexus/content/repositories/releases</url>
</repository>
<snapshotRepository>
<id>snapshot</id>
<url>https://develop.sitepark.com/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>

<dependencyManagement>
<dependencies>
<dependency>
Expand Down Expand Up @@ -145,6 +156,12 @@
<version>3.15.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jparams</groupId>
<artifactId>to-string-verifier</artifactId>
<version>1.4.8</version>
<scope>test</scope>
</dependency>

</dependencies>
<build>
Expand All @@ -154,12 +171,15 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.3.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.1</version>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
Expand All @@ -173,6 +193,90 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.6.0</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<scmCommentPrefix>ci(release): </scmCommentPrefix>
<tagNameFormat>@{project.version}</tagNameFormat>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.4.1</version>
<executions>
<execution>
<id>enforce-maven</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<banDuplicatePomDependencyVersions />
<requireMavenVersion>
<version>3.8</version>
</requireMavenVersion>
<requireJavaVersion>
<version>21</version>
</requireJavaVersion>
</rules>
</configuration>
</execution>
<execution>
<id>verify-release</id>
<phase>none</phase>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireReleaseDeps>
<failWhenParentIsSnapshot>false</failWhenParentIsSnapshot>
<message>No Snapshots Allowed!</message>
</requireReleaseDeps>
<requireReleaseDepsInPlugins
implementation="org.apache.maven.enforcer.rule.requireReleaseDepsInPlugins" />
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>io.github.thefolle</groupId>
<artifactId>glowing-waffle</artifactId>
<version>1.2.0</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ private static void validate(String name) {
}

if (!VALIDATOR_PATTERN.matcher(name).matches()) {
throw new InvalidAnchorException(name, "Anchor contains Spaces");
throw new InvalidAnchorException(
name,
"Anchor contains invalid characters. Allowd are: " + VALID_CHARS_REGEX);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,15 @@ public final boolean equals(Object o) {
@Override
public String toString() {
return new StringBuilder()
.append("Entity[")
.append("name: ")
.append(this.getName().orElse("UNNAMED"))
.append(" (")
.append("id: ").append(this.id)
.append(", ")
.append("anchor: ").append(this.anchor)
.append(", ")
.append("parent: ").append(this.parent)
.append(", ")
.append("version: ").append(this.version)
.append(", ")
.append("isGroup: ").append(this.isGroup)
.append(')').toString();
.append(", id: ").append(this.id)
.append(", anchor: ").append(this.anchor)
.append(", parent: ").append(this.parent)
.append(", version: ").append(this.version)
.append(", isGroup: ").append(this.isGroup)
.append(']').toString();
}

public static abstract class Builder<B extends Builder<B>> {
Expand Down Expand Up @@ -168,7 +165,6 @@ public B name(String name) {
if (name.isBlank()) {
throw new IllegalArgumentException("name is blank");
}
assert !name.isBlank();
this.name = name;
return this.self();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ public class EntityTree {
*/
public List<Entity> getRoots() {
return this.getRootIdList().stream()
.map(id -> this.index.get(id))
.map(id -> {
Entity entity = this.index.get(id);
if (entity == null) {
throw new IllegalStateException("Entity with id " + id + " missing");
}
return entity;
})
.collect(Collectors.toList());
}

Expand Down Expand Up @@ -108,9 +114,10 @@ public List<Entity> getAll() {
List<Entity> list = new ArrayList<>();
for (Long rootId : rootIdList) {
Entity root = this.index.get(rootId);
if (root != null) {
list.add(root);
if (root == null) {
throw new IllegalStateException("Entity with id " + rootId + " missing");
}
list.add(root);
List<Entity> childrenOrRoot = this.getChildrenRecursive(rootId);
list.addAll(childrenOrRoot);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
package com.sitepark.ies.contentrepository.core.domain.entity;

import static org.junit.jupiter.api.Assertions.assertEquals;
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;

@SuppressWarnings("PMD.AvoidDuplicateLiterals")
class AnchorTest {

@Test
Expand All @@ -13,4 +20,62 @@ void testEquals() {
.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");
}

}
Loading

0 comments on commit e80935a

Please sign in to comment.