Skip to content

Commit

Permalink
Added builders to model objects
Browse files Browse the repository at this point in the history
  • Loading branch information
sdstoehr committed Dec 21, 2024
1 parent a866908 commit d061c4e
Show file tree
Hide file tree
Showing 32 changed files with 389 additions and 13 deletions.
14 changes: 14 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@
<version>3.0.2</version>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.36</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
Expand All @@ -69,6 +76,13 @@
<version>3.13.0</version>
<configuration>
<release>17</release>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.36</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/de/sstoehr/harreader/model/Har.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Builder;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
* Main HTTP Archive Class.
* @see <a href="http://www.softwareishard.com/blog/har-12-spec/">speicification</a>
* @see <a href="http://www.softwareishard.com/blog/har-12-spec/">specification</a>
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
@Builder(toBuilder = true)
public record Har(@Nonnull HarLog log) {

public Har(@Nullable HarLog log) {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/de/sstoehr/harreader/model/HarCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Builder;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand All @@ -18,6 +19,7 @@
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
@Builder(toBuilder = true)
public record HarCache(
@Nullable HarCacheInfo beforeRequest,
@Nullable HarCacheInfo afterRequest,
Expand Down Expand Up @@ -55,6 +57,7 @@ public void setAdditionalField(String key, Object value) {
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
@Builder(toBuilder = true)
public record HarCacheInfo(@Nullable @JsonFormat(shape = JsonFormat.Shape.STRING) ZonedDateTime expires,
@Nullable @JsonFormat(shape = JsonFormat.Shape.STRING) ZonedDateTime lastAccess,
@Nullable String eTag,
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/de/sstoehr/harreader/model/HarContent.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Builder;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand All @@ -16,6 +17,7 @@
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
@Builder(toBuilder = true)
public record HarContent(
@Nullable Long size,
@Nullable Long compression,
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/de/sstoehr/harreader/model/HarCookie.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Builder;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand All @@ -18,6 +19,7 @@
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
@Builder(toBuilder = true)
public record HarCookie(
@Nullable String name,
@Nullable String value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Builder;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand All @@ -16,6 +17,7 @@
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
@Builder(toBuilder = true)
public record HarCreatorBrowser(
@Nullable String name,
@Nullable String version,
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/de/sstoehr/harreader/model/HarEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Builder;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand All @@ -18,6 +19,7 @@
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
@Builder(toBuilder = true)
public record HarEntry(
@Nullable String pageref,
@Nullable @JsonFormat(shape = JsonFormat.Shape.STRING) ZonedDateTime startedDateTime,
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/de/sstoehr/harreader/model/HarHeader.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Builder;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand All @@ -16,6 +17,7 @@
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
@Builder(toBuilder = true)
public record HarHeader(
@Nullable String name,
@Nullable String value,
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/de/sstoehr/harreader/model/HarLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Builder;
import lombok.Singular;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand All @@ -18,12 +20,13 @@
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
@Builder(toBuilder = true)
public record HarLog(
@Nonnull String version,
@Nonnull HarCreatorBrowser creator,
@Nullable HarCreatorBrowser browser,
@Nonnull List<HarPage> pages,
@Nonnull List<HarEntry> entries,
@Nonnull @Singular("page") List<HarPage> pages,
@Nonnull @Singular("entry") List<HarEntry> entries,
@Nullable String comment,
@Nonnull Map<String, Object> additional) {

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/de/sstoehr/harreader/model/HarPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Builder;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand All @@ -18,6 +19,7 @@
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
@Builder(toBuilder = true)
public record HarPage(
@Nullable @JsonFormat(shape = JsonFormat.Shape.STRING) ZonedDateTime startedDateTime,
@Nullable String id,
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/de/sstoehr/harreader/model/HarPageTiming.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Builder;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand All @@ -16,6 +17,7 @@
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
@Builder(toBuilder = true)
public record HarPageTiming(
@Nonnull Integer onContentLoad,
@Nonnull Integer onLoad,
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/de/sstoehr/harreader/model/HarPostData.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Builder;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand All @@ -18,6 +19,7 @@
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
@Builder(toBuilder = true)
public record HarPostData(
@Nullable String mimeType,
@Nonnull List<HarPostDataParam> params,
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/de/sstoehr/harreader/model/HarPostDataParam.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Builder;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand All @@ -16,12 +17,13 @@
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
@Builder(toBuilder = true)
public record HarPostDataParam(@Nullable String name,
@Nullable String value,
@Nullable String fileName,
@Nullable String contentType,
@Nullable String comment,
@Nonnull Map<String, Object> additional) {
@Nullable String value,
@Nullable String fileName,
@Nullable String contentType,
@Nullable String comment,
@Nonnull Map<String, Object> additional) {

public HarPostDataParam() {
this(null, null, null, null, null, new HashMap<>());
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/de/sstoehr/harreader/model/HarQueryParam.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Builder;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand All @@ -16,6 +17,7 @@
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
@Builder(toBuilder = true)
public record HarQueryParam(
@Nullable String name,
@Nullable String value,
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/de/sstoehr/harreader/model/HarRequest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package de.sstoehr.harreader.model;

import com.fasterxml.jackson.annotation.*;
import lombok.Builder;
import lombok.Singular;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand All @@ -15,13 +17,14 @@
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
@Builder(toBuilder = true)
public record HarRequest(
@Nullable String method,
@Nullable String url,
@Nullable String httpVersion,
@Nonnull List<HarCookie> cookies,
@Nonnull List<HarHeader> headers,
@Nonnull List<HarQueryParam> queryString,
@Nonnull @Singular("cookie") List<HarCookie> cookies,
@Nonnull @Singular("header") List<HarHeader> headers,
@Nonnull @Singular("queryString") List<HarQueryParam> queryString,
@Nonnull HarPostData postData,
@Nonnull Long headersSize,
@Nonnull Long bodySize,
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/de/sstoehr/harreader/model/HarResponse.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package de.sstoehr.harreader.model;

import com.fasterxml.jackson.annotation.*;
import lombok.Builder;
import lombok.Singular;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand All @@ -15,12 +17,13 @@
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
@Builder(toBuilder = true)
public record HarResponse(
int status,
@Nullable String statusText,
@Nullable String httpVersion,
@Nonnull List<HarCookie> cookies,
@Nonnull List<HarHeader> headers,
@Nonnull @Singular("cookie") List<HarCookie> cookies,
@Nonnull @Singular("header") List<HarHeader> headers,
@Nonnull HarContent content,
@Nullable String redirectURL,
@Nonnull Long headersSize,
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/de/sstoehr/harreader/model/HarTiming.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Builder;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand All @@ -14,6 +15,7 @@

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
@Builder(toBuilder = true)
public record HarTiming(
@Nonnull Integer blocked,
@Nonnull Integer dns,
Expand Down
16 changes: 16 additions & 0 deletions src/test/java/de/sstoehr/harreader/model/HarCacheTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,22 @@ void testNullability() {
testNullability(new HarCache());
}

@Test
void testBuilder() {
HarCache cache = HarCache.builder().build();
testNullability(cache);

cache = HarCache.builder()
.beforeRequest(HarCache.HarCacheInfo.builder().build())
.afterRequest(HarCache.HarCacheInfo.builder().build())
.comment("comment")
.build();

assertNotNull(cache.beforeRequest());
assertNotNull(cache.afterRequest());
assertEquals("comment", cache.comment());
}

@Test
void equalsContract() {
EqualsVerifier.simple().forClass(HarCache.class).verify();
Expand Down
22 changes: 22 additions & 0 deletions src/test/java/de/sstoehr/harreader/model/HarContentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,28 @@ void testNullability() {
testNullability(new HarContent());
}

@Test
void testBuilder() {
HarContent content = HarContent.builder().build();
testNullability(content);

content = HarContent.builder()
.size(123L)
.compression(45L)
.mimeType("mime/type")
.text("my content")
.encoding("base64")
.comment("my comment")
.build();

assertEquals(123L, (long) content.size());
assertEquals(45L, (long) content.compression());
assertEquals("mime/type", content.mimeType());
assertEquals("my content", content.text());
assertEquals("base64", content.encoding());
assertEquals("my comment", content.comment());
}

@Test
void equalsContract() {
EqualsVerifier.simple().forClass(HarContent.class).verify();
Expand Down
Loading

0 comments on commit d061c4e

Please sign in to comment.