Skip to content

Commit

Permalink
test: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sitepark-veltrup committed Dec 9, 2024
1 parent 04f8e8c commit 2ca7fd3
Show file tree
Hide file tree
Showing 32 changed files with 1,348 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import java.util.Objects;

@JsonDeserialize(builder = DailyScheduling.Builder.class)
public class DailyScheduling implements Scheduling {
public final class DailyScheduling implements Scheduling {

private final LocalTime startTime;

Expand Down Expand Up @@ -48,6 +48,11 @@ public boolean equals(Object o) {
return Objects.equals(this.startTime, that.startTime);
}

@Override
public String toString() {
return "DailyScheduling [startTime=" + startTime + "]";
}

@JsonPOJOBuilder(withPrefix = "", buildMethodName = "build")
public static class Builder {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import java.util.Objects;
import java.util.function.Consumer;

public class LinkCheckerBackgroundExecution {
public final class LinkCheckerBackgroundExecution {

private final int parallel;

Expand Down Expand Up @@ -44,7 +44,7 @@ public Consumer<LinkCheckerLink> getOperation() {

@Override
public final int hashCode() {
return Objects.hash(Arrays.hashCode(this.topic));
return Objects.hash(this.parallel, Arrays.hashCode(this.topic), this.links, this.operation);
}

@Override
Expand All @@ -54,23 +54,33 @@ public final boolean equals(Object o) {
return false;
}

return Arrays.equals(this.topic, that.topic);
return Arrays.equals(this.topic, that.topic)
&& this.parallel == that.parallel
&& Objects.equals(this.links, that.links)
&& Objects.equals(this.operation, that.operation);
}

@Override
public String toString() {
StringBuilder b =
new StringBuilder(100)
.append("EntityBackgroundExecution[topic:")
.append(Arrays.toString(this.topic))
.append(']');
return b.toString();
return "LinkCheckerBackgroundExecution [parallel="
+ parallel
+ ", topic="
+ Arrays.toString(topic)
+ ", links="
+ links
+ ", operation="
+ operation
+ "]";
}

public static Builder builder() {
return new Builder();
}

public Builder toBuilder() {
return new Builder(this);
}

public static class Builder {

private int parallel;
Expand All @@ -83,6 +93,13 @@ public static class Builder {

private Builder() {}

private Builder(LinkCheckerBackgroundExecution instance) {
this.parallel = instance.parallel;
this.topic = instance.topic;
this.links.addAll(instance.links);
this.operation = instance.operation;
}

public Builder parallel(int parallel) {
this.parallel = parallel;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
@JsonDeserialize(builder = LinkCheckerConfig.Builder.class)
public final class LinkCheckerConfig {

private final boolean enabled;

private final int parallel;

private final int timeout;
Expand All @@ -19,12 +21,17 @@ public final class LinkCheckerConfig {
private final List<LinkCheckerExcludePattern> excludes;

protected LinkCheckerConfig(Builder builder) {
this.enabled = builder.enabled;
this.parallel = builder.parallel;
this.timeout = builder.timeout;
this.scheduling = builder.scheduling;
this.excludes = builder.excludes;
}

public boolean isEnabled() {
return this.enabled;
}

public int getParallel() {
return this.parallel;
}
Expand All @@ -51,7 +58,7 @@ public Builder toBuilder() {

@Override
public int hashCode() {
return Objects.hash(this.timeout, this.parallel, this.scheduling, this.excludes);
return Objects.hash(this.enabled, this.timeout, this.parallel, this.scheduling, this.excludes);
}

@Override
Expand All @@ -61,15 +68,33 @@ public boolean equals(Object o) {
return false;
}

return Objects.equals(this.timeout, that.timeout)
return Objects.equals(this.enabled, that.enabled)
&& Objects.equals(this.timeout, that.timeout)
&& Objects.equals(this.parallel, that.parallel)
&& Objects.equals(this.scheduling, that.scheduling)
&& Objects.equals(this.excludes, that.excludes);
}

@Override
public String toString() {
return "LinkCheckerConfig [enabled="
+ enabled
+ ", parallel="
+ parallel
+ ", timeout="
+ timeout
+ ", scheduling="
+ scheduling
+ ", excludes="
+ excludes
+ "]";
}

@JsonPOJOBuilder(withPrefix = "", buildMethodName = "build")
public static class Builder {

private boolean enabled;

private int parallel;

private int timeout;
Expand All @@ -81,8 +106,16 @@ public static class Builder {
protected Builder() {}

protected Builder(LinkCheckerConfig instance) {
this.enabled = instance.enabled;
this.parallel = instance.parallel;
this.timeout = instance.timeout;
this.excludes.addAll(instance.excludes);
this.scheduling = instance.scheduling;
}

public Builder enabled(boolean enabled) {
this.enabled = enabled;
return this;
}

public Builder scheduling(Scheduling scheduling) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
public enum LinkCheckerExcludePatternType {
REGEX,
CONTAINS,
GLOB
GLOB,
EXACT
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.sitepark.ies.publisher.core.linkchecker.domain.entity;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
import java.util.Objects;

public class LinkCheckerLink {
@JsonDeserialize(builder = LinkCheckerLink.Builder.class)
public final class LinkCheckerLink {

private final String hash;

Expand Down Expand Up @@ -38,7 +41,7 @@ public Builder toBuilder() {

@Override
public int hashCode() {
return Objects.hash(this.hash, this.url);
return Objects.hash(this.hash, this.url, this.timeout);
}

@Override
Expand All @@ -48,9 +51,17 @@ public boolean equals(Object o) {
return false;
}

return Objects.equals(this.hash, that.hash) && Objects.equals(this.url, that.url);
return Objects.equals(this.hash, that.hash)
&& Objects.equals(this.url, that.url)
&& Objects.equals(this.timeout, that.timeout);
}

@Override
public String toString() {
return "LinkCheckerLink [hash=" + hash + ", url=" + url + ", timeout=" + timeout + "]";
}

@JsonPOJOBuilder(withPrefix = "", buildMethodName = "build")
public static class Builder {

private String hash;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package com.sitepark.ies.publisher.core.linkchecker.domain.entity;

import com.fasterxml.jackson.annotation.JsonSetter;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

public class LinkCheckerLinkFilter {
@JsonDeserialize(builder = LinkCheckerLinkFilter.Builder.class)
public final class LinkCheckerLinkFilter {

private final List<String> terms;

Expand Down Expand Up @@ -73,6 +76,7 @@ private Builder(LinkCheckerLinkFilter instance) {
this.statusTypes.addAll(instance.statusTypes);
}

@JsonSetter
public Builder terms(Collection<String> terms) {
Objects.requireNonNull(terms, "terms is null");
this.terms.clear();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.sitepark.ies.publisher.core.linkchecker.domain.entity;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

public class LinkCheckerResult {
@JsonDeserialize(builder = LinkCheckerResult.Builder.class)
public final class LinkCheckerResult {

private final List<LinkCheckerResultItem> items;

Expand Down Expand Up @@ -75,6 +78,7 @@ public String toString() {
+ "]";
}

@JsonPOJOBuilder(withPrefix = "", buildMethodName = "build")
public static class Builder {

private final List<LinkCheckerResultItem> items = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.sitepark.ies.publisher.core.linkchecker.domain.entity;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;

@JsonDeserialize(builder = LinkCheckerResultItem.Builder.class)
public final class LinkCheckerResultItem {
private final String url;
private final String hash;
Expand All @@ -26,6 +29,10 @@ public String getUrl() {
return this.url;
}

public String getHash() {
return this.hash;
}

public StatusType getStatus() {
return this.status;
}
Expand Down Expand Up @@ -80,6 +87,7 @@ public String toString() {
+ "]";
}

@JsonPOJOBuilder(withPrefix = "", buildMethodName = "build")
public static class Builder {

private String url;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.sitepark.ies.publisher.core.linkchecker.domain.entity;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

public class LinkCheckerResultStatistic {
@JsonDeserialize(builder = LinkCheckerResultStatistic.Builder.class)
public final class LinkCheckerResultStatistic {

private final List<StatusTypeCount> statusCounts;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.sitepark.ies.publisher.core.linkchecker.domain.entity;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
import java.util.Objects;

@JsonDeserialize(builder = PublishedExternalLink.Builder.class)
public final class PublishedExternalLink {

private final String entity;
Expand Down Expand Up @@ -61,6 +64,20 @@ public boolean equals(Object o) {
&& Objects.equals(this.url, that.url);
}

@Override
public String toString() {
return "PublishedExternalLink [entity="
+ entity
+ ", channel="
+ channel
+ ", section="
+ section
+ ", url="
+ url
+ "]";
}

@JsonPOJOBuilder(withPrefix = "", buildMethodName = "build")
public static class Builder {

private String entity;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.sitepark.ies.publisher.core.linkchecker.domain.exception;

public class LinkCheckerDisabledException extends RuntimeException {

private static final long serialVersionUID = 1L;

public LinkCheckerDisabledException() {
super();
}

public LinkCheckerDisabledException(String message) {
super(message);
}

public LinkCheckerDisabledException(String message, Throwable t) {
super(message, t);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ public interface PublishedExternalLinkRepository {

List<LinkCheckerLink> getLinks(Collection<String> hashes);

List<LinkCheckerLink> getLinks(LinkCheckerLinkFilter filter);

LinkCheckerResult getCheckResult(LinkCheckerLinkFilter filter, int start, int limit);

LinkCheckerResultStatistic getCheckResultsStatistic();

void updateCheckResult(String hash, LinkCheckerResultItem result);

void cleanupUnusedLinks();

void resetResults();
}
Loading

0 comments on commit 2ca7fd3

Please sign in to comment.