diff --git a/pom.xml b/pom.xml
index 1a2e351..531883e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@
de.sstoehr
har-reader
- 2.5.1-SNAPSHOT
+ 3.0.0-SNAPSHOT
jar
har-reader
@@ -35,6 +35,18 @@
${jackson.version}
+
+ com.fasterxml.jackson.datatype
+ jackson-datatype-jsr310
+ ${jackson.version}
+
+
+
+ com.google.code.findbugs
+ jsr305
+ 3.0.2
+
+
org.junit.jupiter
junit-jupiter
@@ -56,7 +68,7 @@
maven-compiler-plugin
3.13.0
- 8
+ 17
@@ -64,7 +76,7 @@
maven-javadoc-plugin
3.11.1
- 1.8
+ 17
diff --git a/src/main/java/de/sstoehr/harreader/HarReader.java b/src/main/java/de/sstoehr/harreader/HarReader.java
index 291d522..28c5458 100644
--- a/src/main/java/de/sstoehr/harreader/HarReader.java
+++ b/src/main/java/de/sstoehr/harreader/HarReader.java
@@ -15,7 +15,7 @@ public class HarReader extends AbstractHarIO {
public HarReader() {
super();
}
-
+
public HarReader(MapperFactory mapperFactory) {
super(mapperFactory);
}
diff --git a/src/main/java/de/sstoehr/harreader/HarWriter.java b/src/main/java/de/sstoehr/harreader/HarWriter.java
index a2f32f2..dabdcce 100644
--- a/src/main/java/de/sstoehr/harreader/HarWriter.java
+++ b/src/main/java/de/sstoehr/harreader/HarWriter.java
@@ -1,10 +1,8 @@
package de.sstoehr.harreader;
import java.io.File;
-import java.io.IOException;
import java.io.OutputStream;
import java.io.Writer;
-import java.util.function.Function;
import com.fasterxml.jackson.databind.ObjectMapper;
diff --git a/src/main/java/de/sstoehr/harreader/jackson/DefaultMapperFactory.java b/src/main/java/de/sstoehr/harreader/jackson/DefaultMapperFactory.java
index 18240da..194d6b0 100644
--- a/src/main/java/de/sstoehr/harreader/jackson/DefaultMapperFactory.java
+++ b/src/main/java/de/sstoehr/harreader/jackson/DefaultMapperFactory.java
@@ -1,10 +1,14 @@
package de.sstoehr.harreader.jackson;
+import java.time.Instant;
+import java.time.ZonedDateTime;
import java.util.Date;
+import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
+import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import de.sstoehr.harreader.HarReaderMode;
public class DefaultMapperFactory implements MapperFactory {
@@ -12,14 +16,18 @@ public class DefaultMapperFactory implements MapperFactory {
public ObjectMapper instance(HarReaderMode mode) {
SimpleModule module = new SimpleModule();
if (mode == HarReaderMode.LAX) {
- module.addDeserializer(Date.class, new ExceptionIgnoringDateDeserializer());
+ module.addDeserializer(ZonedDateTime.class, new ExceptionIgnoringZonedDateTimeDeserializer());
module.addDeserializer(Integer.class, new ExceptionIgnoringIntegerDeserializer());
}
return instance().registerModule(module);
}
public ObjectMapper instance() {
- return new ObjectMapper();
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.registerModule(new JavaTimeModule());
+ mapper.configure(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE, false);
+
+ return mapper;
}
}
diff --git a/src/main/java/de/sstoehr/harreader/jackson/ExceptionIgnoringDateDeserializer.java b/src/main/java/de/sstoehr/harreader/jackson/ExceptionIgnoringDateDeserializer.java
deleted file mode 100644
index b56e048..0000000
--- a/src/main/java/de/sstoehr/harreader/jackson/ExceptionIgnoringDateDeserializer.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package de.sstoehr.harreader.jackson;
-
-import java.io.IOException;
-import java.util.Date;
-
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.databind.DeserializationContext;
-import com.fasterxml.jackson.databind.JsonDeserializer;
-import com.fasterxml.jackson.databind.deser.std.DateDeserializers;
-
-public class ExceptionIgnoringDateDeserializer extends JsonDeserializer {
-
- @Override
- public Date deserialize(JsonParser jp, DeserializationContext ctxt) throws java.io.IOException {
- try {
- DateDeserializers.DateDeserializer dateDeserializer = new DateDeserializers.DateDeserializer();
- return dateDeserializer.deserialize(jp, ctxt);
- } catch (IOException e) {
- //ignore
- }
- return new Date(0L);
- }
-
-}
diff --git a/src/main/java/de/sstoehr/harreader/jackson/ExceptionIgnoringZonedDateTimeDeserializer.java b/src/main/java/de/sstoehr/harreader/jackson/ExceptionIgnoringZonedDateTimeDeserializer.java
new file mode 100644
index 0000000..eaad126
--- /dev/null
+++ b/src/main/java/de/sstoehr/harreader/jackson/ExceptionIgnoringZonedDateTimeDeserializer.java
@@ -0,0 +1,25 @@
+package de.sstoehr.harreader.jackson;
+
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.JsonDeserializer;
+import com.fasterxml.jackson.datatype.jsr310.deser.InstantDeserializer;
+
+import java.io.IOException;
+import java.time.Instant;
+import java.time.ZoneId;
+import java.time.ZonedDateTime;
+
+public class ExceptionIgnoringZonedDateTimeDeserializer extends JsonDeserializer {
+
+ @Override
+ public ZonedDateTime deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
+ try {
+ return InstantDeserializer.ZONED_DATE_TIME.deserialize(jp, ctxt);
+ } catch (IOException e) {
+ //ignore
+ }
+ return ZonedDateTime.ofInstant(Instant.ofEpochSecond(0L), ZoneId.of("UTC"));
+ }
+
+}
diff --git a/src/main/java/de/sstoehr/harreader/model/Har.java b/src/main/java/de/sstoehr/harreader/model/Har.java
index cdc403a..275747a 100644
--- a/src/main/java/de/sstoehr/harreader/model/Har.java
+++ b/src/main/java/de/sstoehr/harreader/model/Har.java
@@ -3,7 +3,8 @@
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
-import java.util.Objects;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
/**
* Main HTTP Archive Class.
@@ -11,34 +12,9 @@
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
-public class Har {
+public record Har(@Nonnull HarLog log) {
- private HarLog log;
-
- /**
- * @return HAR log.
- */
- public HarLog getLog() {
- if (log == null) {
- log = new HarLog();
- }
- return log;
- }
-
- public void setLog(HarLog log) {
- this.log = log;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
- Har har = (Har) o;
- return Objects.equals(log, har.log);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(log);
+ public Har(@Nullable HarLog log) {
+ this.log = (log == null) ? new HarLog() : log;
}
}
diff --git a/src/main/java/de/sstoehr/harreader/model/HarCache.java b/src/main/java/de/sstoehr/harreader/model/HarCache.java
index 00ecfb8..4612fff 100644
--- a/src/main/java/de/sstoehr/harreader/model/HarCache.java
+++ b/src/main/java/de/sstoehr/harreader/model/HarCache.java
@@ -6,10 +6,11 @@
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
-import java.util.Date;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import java.time.ZonedDateTime;
import java.util.HashMap;
import java.util.Map;
-import java.util.Objects;
/**
* Information about a request coming from browser cache.
@@ -17,73 +18,35 @@
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
-public class HarCache {
-
- private HarCacheInfo beforeRequest;
- private HarCacheInfo afterRequest;
- private String comment;
- private final Map additional = new HashMap<>();
-
- /**
- * @return State of the cache entry before the request, null if not present.
- */
- public HarCacheInfo getBeforeRequest() {
- return beforeRequest;
+public record HarCache(
+ @Nullable HarCacheInfo beforeRequest,
+ @Nullable HarCacheInfo afterRequest,
+ @Nullable String comment,
+ @Nonnull Map additional
+) {
+
+ public HarCache() {
+ this(null, null, null, new HashMap<>());
}
- public void setBeforeRequest(HarCacheInfo beforeRequest) {
+ public HarCache(@Nullable HarCacheInfo beforeRequest,
+ @Nullable HarCacheInfo afterRequest,
+ @Nullable String comment,
+ @Nullable Map additional) {
this.beforeRequest = beforeRequest;
- }
-
- /**
- * @return State of the cache entry after the request, null if not present.
- */
- public HarCacheInfo getAfterRequest() {
- return afterRequest;
- }
-
- public void setAfterRequest(HarCacheInfo afterRequest) {
this.afterRequest = afterRequest;
- }
-
- /**
- * @return Comment provided by the user or application, null if not present.
- */
- public String getComment() {
- return comment;
- }
-
- public void setComment(String comment) {
this.comment = comment;
+ this.additional = (additional == null) ? new HashMap<>() : additional;
}
- /**
- * @return Map with additional keys, which are not officially supported by the HAR specification
- */
@JsonAnyGetter
- public Map getAdditional() {
+ public Map additional() {
return additional;
}
@JsonAnySetter
public void setAdditionalField(String key, Object value) {
- this.additional.put(key, value);
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (!(o instanceof HarCache)) return false;
- HarCache harCache = (HarCache) o;
- return Objects.equals(beforeRequest, harCache.beforeRequest) &&
- Objects.equals(afterRequest, harCache.afterRequest) &&
- Objects.equals(comment, harCache.comment) &&
- Objects.equals(additional, harCache.additional);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(beforeRequest, afterRequest, comment, additional);
+ additional.put(key, value);
}
/**
@@ -92,77 +55,36 @@ public int hashCode() {
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
- public static final class HarCacheInfo {
-
- private Date expires;
- private Date lastAccess;
- private String eTag;
- private Integer hitCount;
- private String comment;
- private final Map additional = new HashMap<>();
-
- /**
- * @return Expiration time of entry, null if not present.
- */
- @JsonFormat(shape = JsonFormat.Shape.STRING)
- public Date getExpires() {
- return expires;
+ public record HarCacheInfo(@Nullable @JsonFormat(shape = JsonFormat.Shape.STRING) ZonedDateTime expires,
+ @Nullable @JsonFormat(shape = JsonFormat.Shape.STRING) ZonedDateTime lastAccess,
+ @Nullable String eTag,
+ @Nullable Integer hitCount,
+ @Nullable String comment,
+ @Nonnull Map additional) {
+
+ public HarCacheInfo() {
+ this(null, null, null, null, null, new HashMap<>());
}
- public void setExpires(Date expires) {
+ public HarCacheInfo(@Nullable ZonedDateTime expires,
+ @Nullable ZonedDateTime lastAccess,
+ @Nullable String eTag,
+ @Nullable Integer hitCount,
+ @Nullable String comment,
+ @Nullable Map additional) {
this.expires = expires;
- }
-
- /**
- * @return Last time the entry was opened, null if not present.
- */
- @JsonFormat(shape = JsonFormat.Shape.STRING)
- public Date getLastAccess() {
- return lastAccess;
- }
-
- public void setLastAccess(Date lastAccess) {
this.lastAccess = lastAccess;
- }
-
- /**
- * @return ETag, null if not present.
- */
- public String geteTag() {
- return eTag;
- }
-
- public void seteTag(String eTag) {
this.eTag = eTag;
- }
-
- /**
- * @return Number of times the entry has been opened, null if not present.
- */
- public Integer getHitCount() {
- return hitCount;
- }
-
- public void setHitCount(Integer hitCount) {
this.hitCount = hitCount;
- }
-
- /**
- * @return Comment provided by the user or application, null if not present.
- */
- public String getComment() {
- return comment;
- }
-
- public void setComment(String comment) {
this.comment = comment;
+ this.additional = (additional == null) ? new HashMap<>() : additional;
}
/**
* @return Map with additional keys, which are not officially supported by the HAR specification
*/
@JsonAnyGetter
- public Map getAdditional() {
+ public Map additional() {
return additional;
}
@@ -171,22 +93,5 @@ public void setAdditionalField(String key, Object value) {
this.additional.put(key, value);
}
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (!(o instanceof HarCacheInfo)) return false;
- HarCacheInfo that = (HarCacheInfo) o;
- return Objects.equals(expires, that.expires) &&
- Objects.equals(lastAccess, that.lastAccess) &&
- Objects.equals(eTag, that.eTag) &&
- Objects.equals(hitCount, that.hitCount) &&
- Objects.equals(comment, that.comment) &&
- Objects.equals(additional, that.additional);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(expires, lastAccess, eTag, hitCount, comment, additional);
- }
}
}
diff --git a/src/main/java/de/sstoehr/harreader/model/HarContent.java b/src/main/java/de/sstoehr/harreader/model/HarContent.java
index fd306ab..db64dfd 100644
--- a/src/main/java/de/sstoehr/harreader/model/HarContent.java
+++ b/src/main/java/de/sstoehr/harreader/model/HarContent.java
@@ -5,9 +5,10 @@
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.Map;
-import java.util.Objects;
/**
* Information about the response's content.
@@ -15,89 +16,40 @@
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
-public class HarContent {
-
- private Long size;
- private Long compression;
- private String mimeType;
- private String text;
- private String encoding;
- private String comment;
- private final Map additional = new HashMap<>();
-
- /**
- * @return Length of returned content in bytes, null if not present.
- */
- public Long getSize() {
- return size;
- }
-
- public void setSize(Long size) {
+public record HarContent(
+ @Nullable Long size,
+ @Nullable Long compression,
+ @Nullable String mimeType,
+ @Nullable String text,
+ @Nullable String encoding,
+ @Nullable String comment,
+ @Nonnull Map additional) {
+
+ public HarContent() {
+ this(null, null, null, null, null, null, new HashMap<>());
+ }
+
+ public HarContent(@Nullable Long size,
+ @Nullable Long compression,
+ @Nullable String mimeType,
+ @Nullable String text,
+ @Nullable String encoding,
+ @Nullable String comment,
+ @Nullable Map additional) {
this.size = size;
- }
-
- /**
- * @return Number of bytes saved by compression, null if not present.
- */
- public Long getCompression() {
- return compression;
- }
-
- public void setCompression(Long compression) {
this.compression = compression;
- }
-
- /**
- * @return MIME-Type of response, null if not present. May include the charset.
- */
- public String getMimeType() {
- return mimeType;
- }
-
- public void setMimeType(String mimeType) {
this.mimeType = mimeType;
- }
-
- /**
- * @return Response body loaded from server or cache, null if not present.
- * Binary content may be encoded using encoding specified by {@link #getEncoding()}.
- */
- public String getText() {
- return text;
- }
-
- public void setText(String text) {
this.text = text;
- }
-
- /**
- * @return Encoding used for encoding response body, null if not present.
- * @see #getText()
- */
- public String getEncoding() {
- return encoding;
- }
-
- public void setEncoding(String encoding) {
this.encoding = encoding;
- }
-
- /**
- * @return Comment provided by the user or application, null if not present.
- */
- public String getComment() {
- return comment;
- }
-
- public void setComment(String comment) {
this.comment = comment;
+ this.additional = (additional == null) ? new HashMap<>() : additional;
}
/**
* @return Map with additional keys, which are not officially supported by the HAR specification
*/
@JsonAnyGetter
- public Map getAdditional() {
+ public Map additional() {
return additional;
}
@@ -106,22 +58,4 @@ public void setAdditionalField(String key, Object value) {
this.additional.put(key, value);
}
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (!(o instanceof HarContent)) return false;
- HarContent that = (HarContent) o;
- return Objects.equals(size, that.size) &&
- Objects.equals(compression, that.compression) &&
- Objects.equals(mimeType, that.mimeType) &&
- Objects.equals(text, that.text) &&
- Objects.equals(encoding, that.encoding) &&
- Objects.equals(comment, that.comment) &&
- Objects.equals(additional, that.additional);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(size, compression, mimeType, text, encoding, comment, additional);
- }
}
diff --git a/src/main/java/de/sstoehr/harreader/model/HarCookie.java b/src/main/java/de/sstoehr/harreader/model/HarCookie.java
index 63111a0..aaf55d5 100644
--- a/src/main/java/de/sstoehr/harreader/model/HarCookie.java
+++ b/src/main/java/de/sstoehr/harreader/model/HarCookie.java
@@ -6,10 +6,11 @@
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
-import java.util.Date;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import java.time.ZonedDateTime;
import java.util.HashMap;
import java.util.Map;
-import java.util.Objects;
/**
* Information about a cookie used in request and/or response.
@@ -17,112 +18,46 @@
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
-public class HarCookie {
-
- private String name;
- private String value;
- private String path;
- private String domain;
- private Date expires;
- private Boolean httpOnly;
- private Boolean secure;
- private String comment;
- private final Map additional = new HashMap<>();
-
- /**
- * @return Name of the cookie, null if not present.
- */
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
+public record HarCookie(
+ @Nullable String name,
+ @Nullable String value,
+ @Nullable String path,
+ @Nullable String domain,
+ @Nullable @JsonFormat(shape = JsonFormat.Shape.STRING) ZonedDateTime expires,
+ @Nullable Boolean httpOnly,
+ @Nullable Boolean secure,
+ @Nullable String comment,
+ @Nonnull Map additional) {
+
+ public HarCookie() {
+ this(null, null, null, null, null, null, null, null, new HashMap<>());
+ }
+
+ public HarCookie(@Nullable String name,
+ @Nullable String value,
+ @Nullable String path,
+ @Nullable String domain,
+ @Nullable ZonedDateTime expires,
+ @Nullable Boolean httpOnly,
+ @Nullable Boolean secure,
+ @Nullable String comment,
+ @Nullable Map additional) {
this.name = name;
- }
-
- /**
- * @return Value of the cookie, null if not present.
- */
- public String getValue() {
- return value;
- }
-
- public void setValue(String value) {
this.value = value;
- }
-
- /**
- * @return The cookie's path, null if not present.
- */
- public String getPath() {
- return path;
- }
-
- public void setPath(String path) {
this.path = path;
- }
-
- /**
- * @return The cookie's domain, null if not present.
- */
- public String getDomain() {
- return domain;
- }
-
- public void setDomain(String domain) {
this.domain = domain;
- }
-
- /**
- * @return The cookie's expiration time, null if not present.
- */
- @JsonFormat(shape = JsonFormat.Shape.STRING)
- public Date getExpires() {
- return expires;
- }
-
- public void setExpires(Date expires) {
this.expires = expires;
- }
-
- /**
- * @return Whether the cookie is HTTP only, null if not present.
- */
- public Boolean getHttpOnly() {
- return httpOnly;
- }
-
- public void setHttpOnly(Boolean httpOnly) {
this.httpOnly = httpOnly;
- }
-
- /**
- * @return Whether the cookie was transmitted via SSL, null if not present.
- */
- public Boolean getSecure() {
- return secure;
- }
-
- public void setSecure(Boolean secure) {
this.secure = secure;
- }
-
- /**
- * @return Comment provided by the user or application, null if not present.
- */
- public String getComment() {
- return comment;
- }
-
- public void setComment(String comment) {
this.comment = comment;
+ this.additional = (additional == null) ? new HashMap<>() : additional;
}
/**
* @return Map with additional keys, which are not officially supported by the HAR specification
*/
@JsonAnyGetter
- public Map getAdditional() {
+ public Map additional() {
return additional;
}
@@ -131,24 +66,4 @@ public void setAdditionalField(String key, Object value) {
this.additional.put(key, value);
}
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (!(o instanceof HarCookie)) return false;
- HarCookie harCookie = (HarCookie) o;
- return Objects.equals(name, harCookie.name) &&
- Objects.equals(value, harCookie.value) &&
- Objects.equals(path, harCookie.path) &&
- Objects.equals(domain, harCookie.domain) &&
- Objects.equals(expires, harCookie.expires) &&
- Objects.equals(httpOnly, harCookie.httpOnly) &&
- Objects.equals(secure, harCookie.secure) &&
- Objects.equals(comment, harCookie.comment) &&
- Objects.equals(additional, harCookie.additional);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(name, value, path, domain, expires, httpOnly, secure, comment, additional);
- }
}
diff --git a/src/main/java/de/sstoehr/harreader/model/HarCreatorBrowser.java b/src/main/java/de/sstoehr/harreader/model/HarCreatorBrowser.java
index e05c529..ee888ec 100644
--- a/src/main/java/de/sstoehr/harreader/model/HarCreatorBrowser.java
+++ b/src/main/java/de/sstoehr/harreader/model/HarCreatorBrowser.java
@@ -5,9 +5,10 @@
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.Map;
-import java.util.Objects;
/**
* Information about the application/browser used for creating HAR.
@@ -15,51 +16,31 @@
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
-public class HarCreatorBrowser {
+public record HarCreatorBrowser(
+ @Nullable String name,
+ @Nullable String version,
+ @Nullable String comment,
+ @Nonnull Map additional) {
- private String name;
- private String version;
- private String comment;
- private final Map additional = new HashMap<>();
-
- /**
- * @return Name of the application/browser used for creating HAR, null if not present.
- */
- public String getName() {
- return name;
+ public HarCreatorBrowser() {
+ this(null, null, null, new HashMap<>());
}
- public void setName(String name) {
+ public HarCreatorBrowser(@Nullable String name,
+ @Nullable String version,
+ @Nullable String comment,
+ @Nullable Map additional) {
this.name = name;
- }
-
- /**
- * @return Version of the application/browser used for creating HAR, null if not present.
- */
- public String getVersion() {
- return version;
- }
-
- public void setVersion(String version) {
this.version = version;
- }
-
- /**
- * @return Comment provided by the user or application, null if not present.
- */
- public String getComment() {
- return comment;
- }
-
- public void setComment(String comment) {
this.comment = comment;
+ this.additional = (additional == null) ? new HashMap<>() : additional;
}
/**
* @return Map with additional keys, which are not officially supported by the HAR specification
*/
@JsonAnyGetter
- public Map getAdditional() {
+ public Map additional() {
return additional;
}
@@ -68,19 +49,4 @@ public void setAdditionalField(String key, Object value) {
this.additional.put(key, value);
}
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (!(o instanceof HarCreatorBrowser)) return false;
- HarCreatorBrowser that = (HarCreatorBrowser) o;
- return Objects.equals(name, that.name) &&
- Objects.equals(version, that.version) &&
- Objects.equals(comment, that.comment) &&
- Objects.equals(additional, that.additional);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(name, version, comment, additional);
- }
}
diff --git a/src/main/java/de/sstoehr/harreader/model/HarEntry.java b/src/main/java/de/sstoehr/harreader/model/HarEntry.java
index ba7aaac..b1759ec 100644
--- a/src/main/java/de/sstoehr/harreader/model/HarEntry.java
+++ b/src/main/java/de/sstoehr/harreader/model/HarEntry.java
@@ -6,10 +6,11 @@
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
-import java.util.Date;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import java.time.ZonedDateTime;
import java.util.HashMap;
import java.util.Map;
-import java.util.Objects;
/**
* Information about a single HTTP request.
@@ -17,148 +18,53 @@
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
-public class HarEntry {
-
- private String pageref;
- private Date startedDateTime;
- private Integer time;
- private HarRequest request;
- private HarResponse response;
- private HarCache cache;
- private HarTiming timings;
- private String serverIPAddress;
- private String connection;
- private String comment;
- private final Map additional = new HashMap<>();
-
- /**
- * @return Reference to parent page, to which the request belongs to, null if not present.
- */
- public String getPageref() {
- return pageref;
- }
-
- public void setPageref(String pageref) {
+public record HarEntry(
+ @Nullable String pageref,
+ @Nullable @JsonFormat(shape = JsonFormat.Shape.STRING) ZonedDateTime startedDateTime,
+ @Nullable Integer time,
+ @Nonnull HarRequest request,
+ @Nonnull HarResponse response,
+ @Nonnull HarCache cache,
+ @Nonnull HarTiming timings,
+ @Nullable String serverIPAddress,
+ @Nullable String connection,
+ @Nullable String comment,
+ @Nonnull Map additional) {
+
+ public HarEntry() {
+ this(null, null, null, new HarRequest(), new HarResponse(),
+ new HarCache(), new HarTiming(), null, null, null, new HashMap<>());
+ }
+
+ public HarEntry(@Nullable String pageref,
+ @Nullable ZonedDateTime startedDateTime,
+ @Nullable Integer time,
+ @Nullable HarRequest request,
+ @Nullable HarResponse response,
+ @Nullable HarCache cache,
+ @Nullable HarTiming timings,
+ @Nullable String serverIPAddress,
+ @Nullable String connection,
+ @Nullable String comment,
+ @Nullable Map additional) {
this.pageref = pageref;
- }
-
- /**
- * @return Start time of request, null if not present.
- */
- @JsonFormat(shape = JsonFormat.Shape.STRING)
- public Date getStartedDateTime() {
- return startedDateTime;
- }
-
- public void setStartedDateTime(Date startedDateTime) {
this.startedDateTime = startedDateTime;
- }
-
- /**
- * @return Total request time (in ms), null if not present.
- */
- public Integer getTime() {
- return time;
- }
-
- public void setTime(Integer time) {
this.time = time;
- }
-
- /**
- * @return Detailed request information.
- */
- public HarRequest getRequest() {
- if (request == null) {
- request = new HarRequest();
- }
- return request;
- }
-
- public void setRequest(HarRequest request) {
- this.request = request;
- }
-
- /**
- * @return Detailed response information.
- */
- public HarResponse getResponse() {
- if (response == null) {
- response = new HarResponse();
- }
- return response;
- }
-
- public void setResponse(HarResponse response) {
- this.response = response;
- }
-
- /**
- * @return Information about cache usage.
- */
- public HarCache getCache() {
- if (cache == null) {
- cache = new HarCache();
- }
- return cache;
- }
-
- public void setCache(HarCache cache) {
- this.cache = cache;
- }
-
- /**
- * @return Detailed information about request/response timings.
- */
- public HarTiming getTimings() {
- if (timings == null) {
- timings = new HarTiming();
- }
- return timings;
- }
-
- public void setTimings(HarTiming timings) {
- this.timings = timings;
- }
-
- /**
- * @return Server IP address (result of DNS resolution), null if not present.
- */
- public String getServerIPAddress() {
- return serverIPAddress;
- }
-
- public void setServerIPAddress(String serverIPAddress) {
+ this.request = (request == null) ? new HarRequest() : request;
+ this.response = (response == null) ? new HarResponse() : response;
+ this.cache = (cache == null) ? new HarCache() : cache;
+ this.timings = (timings == null) ? new HarTiming() : timings;
this.serverIPAddress = serverIPAddress;
- }
-
- /**
- * @return Unique ID of TCP/IP connection, null if not present.
- */
- public String getConnection() {
- return connection;
- }
-
- public void setConnection(String connection) {
this.connection = connection;
- }
-
- /**
- * @return Comment provided by the user or application, null if not present.
- */
- public String getComment() {
- return comment;
- }
-
- public void setComment(String comment) {
this.comment = comment;
+ this.additional = (additional == null) ? new HashMap<>() : additional;
}
/**
* @return Map with additional keys, which are not officially supported by the HAR specification
*/
@JsonAnyGetter
- public Map getAdditional() {
+ public Map additional() {
return additional;
}
@@ -167,27 +73,4 @@ public void setAdditionalField(String key, Object value) {
this.additional.put(key, value);
}
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (!(o instanceof HarEntry)) return false;
- HarEntry harEntry = (HarEntry) o;
- return Objects.equals(pageref, harEntry.pageref) &&
- Objects.equals(startedDateTime, harEntry.startedDateTime) &&
- Objects.equals(time, harEntry.time) &&
- Objects.equals(request, harEntry.request) &&
- Objects.equals(response, harEntry.response) &&
- Objects.equals(cache, harEntry.cache) &&
- Objects.equals(timings, harEntry.timings) &&
- Objects.equals(serverIPAddress, harEntry.serverIPAddress) &&
- Objects.equals(connection, harEntry.connection) &&
- Objects.equals(comment, harEntry.comment) &&
- Objects.equals(additional, harEntry.additional);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(pageref, startedDateTime, time, request, response, cache, timings, serverIPAddress,
- connection, comment, additional);
- }
}
diff --git a/src/main/java/de/sstoehr/harreader/model/HarHeader.java b/src/main/java/de/sstoehr/harreader/model/HarHeader.java
index f701fc4..8e68029 100644
--- a/src/main/java/de/sstoehr/harreader/model/HarHeader.java
+++ b/src/main/java/de/sstoehr/harreader/model/HarHeader.java
@@ -5,9 +5,10 @@
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.Map;
-import java.util.Objects;
/**
* Information about a header used in request and/or response.
@@ -15,51 +16,31 @@
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
-public class HarHeader {
+public record HarHeader(
+ @Nullable String name,
+ @Nullable String value,
+ @Nullable String comment,
+ @Nonnull Map additional) {
- private String name;
- private String value;
- private String comment;
- private final Map additional = new HashMap<>();
-
- /**
- * @return Header name, null if not present.
- */
- public String getName() {
- return name;
+ public HarHeader() {
+ this(null, null, null, new HashMap<>());
}
- public void setName(String name) {
+ public HarHeader(@Nullable String name,
+ @Nullable String value,
+ @Nullable String comment,
+ @Nullable Map additional) {
this.name = name;
- }
-
- /**
- * @return Header value, null if not present.
- */
- public String getValue() {
- return value;
- }
-
- public void setValue(String value) {
this.value = value;
- }
-
- /**
- * @return Comment provided by the user or application, null if not present.
- */
- public String getComment() {
- return comment;
- }
-
- public void setComment(String comment) {
this.comment = comment;
+ this.additional = (additional == null) ? new HashMap<>() : additional;
}
/**
* @return Map with additional keys, which are not officially supported by the HAR specification
*/
@JsonAnyGetter
- public Map getAdditional() {
+ public Map additional() {
return additional;
}
@@ -68,19 +49,4 @@ public void setAdditionalField(String key, Object value) {
this.additional.put(key, value);
}
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (!(o instanceof HarHeader)) return false;
- HarHeader harHeader = (HarHeader) o;
- return Objects.equals(name, harHeader.name) &&
- Objects.equals(value, harHeader.value) &&
- Objects.equals(comment, harHeader.comment) &&
- Objects.equals(additional, harHeader.additional);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(name, value, comment, additional);
- }
}
diff --git a/src/main/java/de/sstoehr/harreader/model/HarLog.java b/src/main/java/de/sstoehr/harreader/model/HarLog.java
index aec4796..089ec22 100644
--- a/src/main/java/de/sstoehr/harreader/model/HarLog.java
+++ b/src/main/java/de/sstoehr/harreader/model/HarLog.java
@@ -5,11 +5,12 @@
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
-import java.util.ArrayList;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Objects;
/**
* Root object of exported data.
@@ -17,102 +18,42 @@
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
-public class HarLog {
+public record HarLog(
+ @Nonnull String version,
+ @Nonnull HarCreatorBrowser creator,
+ @Nullable HarCreatorBrowser browser,
+ @Nonnull List pages,
+ @Nonnull List entries,
+ @Nullable String comment,
+ @Nonnull Map additional) {
protected static final String DEFAULT_VERSION = "1.1";
- private String version = DEFAULT_VERSION;
- private HarCreatorBrowser creator;
- private HarCreatorBrowser browser;
- private List pages = new ArrayList<>();
- private List entries = new ArrayList<>();
- private String comment;
- private final Map additional = new HashMap<>();
-
- /**
- * @return Version number of the format.
- * Defaults to {@link #DEFAULT_VERSION}
- */
- public String getVersion() {
- return version;
- }
-
- public void setVersion(String version) {
- if (version == null || version.trim().isEmpty()) {
- version = DEFAULT_VERSION;
- }
- this.version = version;
- }
-
- /**
- * @return Information about the application used to generate HAR.
- */
- public HarCreatorBrowser getCreator() {
- if (creator == null) {
- creator = new HarCreatorBrowser();
- }
- return creator;
+ public HarLog() {
+ this(DEFAULT_VERSION, new HarCreatorBrowser(), null, Collections.emptyList(), Collections.emptyList(), null, new HashMap<>());
}
- public void setCreator(HarCreatorBrowser creator) {
- this.creator = creator;
- }
-
- /**
- * @return Information about the browser used, may be null.
- */
- public HarCreatorBrowser getBrowser() {
- return browser;
- }
-
- public void setBrowser(HarCreatorBrowser browser) {
+ public HarLog(@Nullable String version,
+ @Nullable HarCreatorBrowser creator,
+ @Nullable HarCreatorBrowser browser,
+ @Nullable List pages,
+ @Nullable List entries,
+ @Nullable String comment,
+ @Nullable Map additional) {
+ this.version = (version == null || version.isBlank()) ? DEFAULT_VERSION : version;
+ this.creator = (creator == null) ? new HarCreatorBrowser() : creator;
this.browser = browser;
- }
-
- /**
- * @return List of all exported pages, may be empty.
- */
- public List getPages() {
- if (pages == null) {
- pages = new ArrayList<>();
- }
- return pages;
- }
-
- public void setPages(List pages) {
- this.pages = pages;
- }
-
- /**
- * @return List of all exported requests, may be empty.
- */
- public List getEntries() {
- if (entries == null) {
- entries = new ArrayList<>();
- }
- return entries;
- }
-
- public void setEntries(List entries) {
- this.entries = entries;
- }
-
- /**
- * @return Comment provided by the user or application, null if not present.
- */
- public String getComment() {
- return comment;
- }
-
- public void setComment(String comment) {
+ this.pages = (pages == null) ? Collections.emptyList() : pages;
+ this.entries = (entries == null) ? Collections.emptyList() : entries;
this.comment = comment;
+ this.additional = (additional == null) ? new HashMap<>() : additional;
}
/**
* @return Map with additional keys, which are not officially supported by the HAR specification
*/
@JsonAnyGetter
- public Map getAdditional() {
+ public Map additional() {
return additional;
}
@@ -121,22 +62,4 @@ public void setAdditionalField(String key, Object value) {
this.additional.put(key, value);
}
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (!(o instanceof HarLog)) return false;
- HarLog harLog = (HarLog) o;
- return Objects.equals(version, harLog.version) &&
- Objects.equals(creator, harLog.creator) &&
- Objects.equals(browser, harLog.browser) &&
- Objects.equals(pages, harLog.pages) &&
- Objects.equals(entries, harLog.entries) &&
- Objects.equals(comment, harLog.comment) &&
- Objects.equals(additional, harLog.additional);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(version, creator, browser, pages, entries, comment, additional);
- }
}
diff --git a/src/main/java/de/sstoehr/harreader/model/HarPage.java b/src/main/java/de/sstoehr/harreader/model/HarPage.java
index 318b145..7a21987 100644
--- a/src/main/java/de/sstoehr/harreader/model/HarPage.java
+++ b/src/main/java/de/sstoehr/harreader/model/HarPage.java
@@ -6,10 +6,11 @@
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
-import java.util.Date;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import java.time.ZonedDateTime;
import java.util.HashMap;
import java.util.Map;
-import java.util.Objects;
/**
* Information about an exported page.
@@ -17,79 +18,37 @@
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
-public class HarPage {
-
- private Date startedDateTime;
- private String id;
- private String title;
- private HarPageTiming pageTimings;
- private String comment;
- private final Map additional = new HashMap<>();
-
- /**
- * @return Start time of page load, null if not present.
- */
- @JsonFormat(shape = JsonFormat.Shape.STRING)
- public Date getStartedDateTime() {
- return startedDateTime;
- }
-
- public void setStartedDateTime(Date startedDateTime) {
+public record HarPage(
+ @Nullable @JsonFormat(shape = JsonFormat.Shape.STRING) ZonedDateTime startedDateTime,
+ @Nullable String id,
+ @Nullable String title,
+ @Nonnull HarPageTiming pageTimings,
+ @Nullable String comment,
+ @Nonnull Map additional) {
+
+ public HarPage() {
+ this(null, null, null, new HarPageTiming(), null, new HashMap<>());
+ }
+
+ public HarPage(@Nullable ZonedDateTime startedDateTime,
+ @Nullable String id,
+ @Nullable String title,
+ @Nullable HarPageTiming pageTimings,
+ @Nullable String comment,
+ @Nullable Map additional) {
this.startedDateTime = startedDateTime;
- }
-
- /**
- * @return Unique identifier, null if not present.
- */
- public String getId() {
- return id;
- }
-
- public void setId(String id) {
this.id = id;
- }
-
- /**
- * @return Page title, null if not present.
- */
- public String getTitle() {
- return title;
- }
-
- public void setTitle(String title) {
this.title = title;
- }
-
- /**
- * @return Detailed information about page loading timings.
- */
- public HarPageTiming getPageTimings() {
- if (pageTimings == null) {
- pageTimings = new HarPageTiming();
- }
- return pageTimings;
- }
-
- public void setPageTimings(HarPageTiming pageTimings) {
- this.pageTimings = pageTimings;
- }
-
- /**
- * @return Comment provided by the user or application, null if not present.
- */
- public String getComment() {
- return comment;
- }
-
- public void setComment(String comment) {
+ this.pageTimings = (pageTimings == null) ? new HarPageTiming() : pageTimings;
this.comment = comment;
+ this.additional = (additional == null) ? new HashMap<>() : additional;
}
/**
* @return Map with additional keys, which are not officially supported by the HAR specification
*/
@JsonAnyGetter
- public Map getAdditional() {
+ public Map additional() {
return additional;
}
@@ -98,21 +57,4 @@ public void setAdditionalField(String key, Object value) {
this.additional.put(key, value);
}
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (!(o instanceof HarPage)) return false;
- HarPage harPage = (HarPage) o;
- return Objects.equals(startedDateTime, harPage.startedDateTime) &&
- Objects.equals(id, harPage.id) &&
- Objects.equals(title, harPage.title) &&
- Objects.equals(pageTimings, harPage.pageTimings) &&
- Objects.equals(comment, harPage.comment) &&
- Objects.equals(additional, harPage.additional);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(startedDateTime, id, title, pageTimings, comment, additional);
- }
}
diff --git a/src/main/java/de/sstoehr/harreader/model/HarPageTiming.java b/src/main/java/de/sstoehr/harreader/model/HarPageTiming.java
index 7671408..4799596 100644
--- a/src/main/java/de/sstoehr/harreader/model/HarPageTiming.java
+++ b/src/main/java/de/sstoehr/harreader/model/HarPageTiming.java
@@ -5,9 +5,10 @@
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.Map;
-import java.util.Objects;
/**
* Information about events occurring during page load.
@@ -15,61 +16,33 @@
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
-public class HarPageTiming {
+public record HarPageTiming(
+ @Nonnull Integer onContentLoad,
+ @Nonnull Integer onLoad,
+ @Nullable String comment,
+ @Nonnull Map additional) {
protected static final Integer DEFAULT_TIME = -1;
- private Integer onContentLoad = DEFAULT_TIME;
- private Integer onLoad = DEFAULT_TIME;
- private String comment;
- private final Map additional = new HashMap<>();
-
- /**
- * @return Duration in ms until content is loaded.
- * {@link #DEFAULT_TIME} when no information available.
- */
- public Integer getOnContentLoad() {
- if (onContentLoad == null) {
- return DEFAULT_TIME;
- }
- return onContentLoad;
- }
-
- public void setOnContentLoad(Integer onContentLoad) {
- this.onContentLoad = onContentLoad;
- }
-
- /**
- * @return Duration in ms until onLoad event is fired.
- * {@link #DEFAULT_TIME} when no information available.
- */
- public Integer getOnLoad() {
- if (onLoad == null) {
- return DEFAULT_TIME;
- }
- return onLoad;
+ public HarPageTiming() {
+ this(DEFAULT_TIME, DEFAULT_TIME, null, new HashMap<>());
}
- public void setOnLoad(Integer onLoad) {
- this.onLoad = onLoad;
- }
-
- /**
- * @return Comment provided by the user or application, null if not present.
- */
- public String getComment() {
- return comment;
- }
-
- public void setComment(String comment) {
+ public HarPageTiming(@Nullable Integer onContentLoad,
+ @Nullable Integer onLoad,
+ @Nullable String comment,
+ @Nullable Map additional) {
+ this.onContentLoad = (onContentLoad == null) ? DEFAULT_TIME : onContentLoad;
+ this.onLoad = (onLoad == null) ? DEFAULT_TIME : onLoad;
this.comment = comment;
+ this.additional = (additional == null) ? new HashMap<>() : additional;
}
/**
* @return Map with additional keys, which are not officially supported by the HAR specification
*/
@JsonAnyGetter
- public Map getAdditional() {
+ public Map additional() {
return additional;
}
@@ -78,19 +51,4 @@ public void setAdditionalField(String key, Object value) {
this.additional.put(key, value);
}
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (!(o instanceof HarPageTiming)) return false;
- HarPageTiming that = (HarPageTiming) o;
- return Objects.equals(onContentLoad, that.onContentLoad) &&
- Objects.equals(onLoad, that.onLoad) &&
- Objects.equals(comment, that.comment) &&
- Objects.equals(additional, that.additional);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(onContentLoad, onLoad, comment, additional);
- }
}
diff --git a/src/main/java/de/sstoehr/harreader/model/HarPostData.java b/src/main/java/de/sstoehr/harreader/model/HarPostData.java
index 953892a..faafed9 100644
--- a/src/main/java/de/sstoehr/harreader/model/HarPostData.java
+++ b/src/main/java/de/sstoehr/harreader/model/HarPostData.java
@@ -5,11 +5,12 @@
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
-import java.util.ArrayList;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Objects;
/**
* Information about POST data.
@@ -17,66 +18,34 @@
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
-public class HarPostData {
-
- private String mimeType;
- private List params = new ArrayList<>();
- private String text;
- private String comment;
- private final Map additional = new HashMap<>();
-
- /**
- * @return MIME type of posted data, null if not present.
- */
- public String getMimeType() {
- return mimeType;
- }
-
- public void setMimeType(String mimeType) {
+public record HarPostData(
+ @Nullable String mimeType,
+ @Nonnull List params,
+ @Nullable String text,
+ @Nullable String comment,
+ @Nonnull Map additional) {
+
+ public HarPostData() {
+ this(null, Collections.emptyList(), null, null, new HashMap<>());
+ }
+
+ public HarPostData(@Nullable String mimeType,
+ @Nullable List params,
+ @Nullable String text,
+ @Nullable String comment,
+ @Nullable Map additional) {
this.mimeType = mimeType;
- }
-
- /**
- * @return List of posted params.
- */
- public List getParams() {
- if (params == null) {
- params = new ArrayList<>();
- }
- return params;
- }
-
- public void setParams(List params) {
- this.params = params;
- }
-
- /**
- * @return Plain text posted data, null if not present.
- */
- public String getText() {
- return text;
- }
-
- public void setText(String text) {
+ this.params = (params == null) ? Collections.emptyList() : params;
this.text = text;
- }
-
- /**
- * @return Comment provided by the user or application, null if not present.
- */
- public String getComment() {
- return comment;
- }
-
- public void setComment(String comment) {
this.comment = comment;
+ this.additional = (additional == null) ? new HashMap<>() : additional;
}
/**
* @return Map with additional keys, which are not officially supported by the HAR specification
*/
@JsonAnyGetter
- public Map getAdditional() {
+ public Map additional() {
return additional;
}
@@ -85,20 +54,4 @@ public void setAdditionalField(String key, Object value) {
this.additional.put(key, value);
}
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (!(o instanceof HarPostData)) return false;
- HarPostData that = (HarPostData) o;
- return Objects.equals(mimeType, that.mimeType) &&
- Objects.equals(params, that.params) &&
- Objects.equals(text, that.text) &&
- Objects.equals(comment, that.comment) &&
- Objects.equals(additional, that.additional);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(mimeType, params, text, comment, additional);
- }
}
diff --git a/src/main/java/de/sstoehr/harreader/model/HarPostDataParam.java b/src/main/java/de/sstoehr/harreader/model/HarPostDataParam.java
index 346440d..ce705eb 100644
--- a/src/main/java/de/sstoehr/harreader/model/HarPostDataParam.java
+++ b/src/main/java/de/sstoehr/harreader/model/HarPostDataParam.java
@@ -5,9 +5,10 @@
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.Map;
-import java.util.Objects;
/**
* Information about POST params.
@@ -15,75 +16,36 @@
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
-public class HarPostDataParam {
-
- private String name;
- private String value;
- private String fileName;
- private String contentType;
- private String comment;
- private final Map additional = new HashMap<>();
-
- /**
- * @return Name of param, null if not present.
- */
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
+public record HarPostDataParam(@Nullable String name,
+ @Nullable String value,
+ @Nullable String fileName,
+ @Nullable String contentType,
+ @Nullable String comment,
+ @Nonnull Map additional) {
+
+ public HarPostDataParam() {
+ this(null, null, null, null, null, new HashMap<>());
+ }
+
+ public HarPostDataParam(@Nullable String name,
+ @Nullable String value,
+ @Nullable String fileName,
+ @Nullable String contentType,
+ @Nullable String comment,
+ @Nullable Map additional) {
this.name = name;
- }
-
- /**
- * @return Value of a param or content of posted file, null if not present.
- */
- public String getValue() {
- return value;
- }
-
- public void setValue(String value) {
this.value = value;
- }
-
- /**
- * @return Name of posted file, null if not present.
- */
- public String getFileName() {
- return fileName;
- }
-
- public void setFileName(String fileName) {
this.fileName = fileName;
- }
-
- /**
- * @return Content type of posted file, null if not present.
- */
- public String getContentType() {
- return contentType;
- }
-
- public void setContentType(String contentType) {
this.contentType = contentType;
- }
-
- /**
- * @return Comment provided by the user or application, null if not present.
- */
- public String getComment() {
- return comment;
- }
-
- public void setComment(String comment) {
this.comment = comment;
+ this.additional = (additional == null) ? new HashMap<>() : additional;
}
/**
* @return Map with additional keys, which are not officially supported by the HAR specification
*/
@JsonAnyGetter
- public Map getAdditional() {
+ public Map additional() {
return additional;
}
@@ -92,21 +54,4 @@ public void setAdditionalField(String key, Object value) {
this.additional.put(key, value);
}
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (!(o instanceof HarPostDataParam)) return false;
- HarPostDataParam that = (HarPostDataParam) o;
- return Objects.equals(name, that.name) &&
- Objects.equals(value, that.value) &&
- Objects.equals(fileName, that.fileName) &&
- Objects.equals(contentType, that.contentType) &&
- Objects.equals(comment, that.comment) &&
- Objects.equals(additional, that.additional);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(name, value, fileName, contentType, comment, additional);
- }
}
diff --git a/src/main/java/de/sstoehr/harreader/model/HarQueryParam.java b/src/main/java/de/sstoehr/harreader/model/HarQueryParam.java
index 723a443..9fd6f3e 100644
--- a/src/main/java/de/sstoehr/harreader/model/HarQueryParam.java
+++ b/src/main/java/de/sstoehr/harreader/model/HarQueryParam.java
@@ -5,9 +5,10 @@
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.Map;
-import java.util.Objects;
/**
* Information about query params.
@@ -15,51 +16,31 @@
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
-public class HarQueryParam {
+public record HarQueryParam(
+ @Nullable String name,
+ @Nullable String value,
+ @Nullable String comment,
+ @Nonnull Map additional) {
- private String name;
- private String value;
- private String comment;
- private final Map additional = new HashMap<>();
-
- /**
- * @return Name of param, null if not present.
- */
- public String getName() {
- return name;
+ public HarQueryParam() {
+ this(null, null, null, new HashMap<>());
}
- public void setName(String name) {
+ public HarQueryParam(@Nullable String name,
+ @Nullable String value,
+ @Nullable String comment,
+ @Nullable Map additional) {
this.name = name;
- }
-
- /**
- * @return Value of param, null if not present.
- */
- public String getValue() {
- return value;
- }
-
- public void setValue(String value) {
this.value = value;
- }
-
- /**
- * @return Comment provided by the user or application, null if not present.
- */
- public String getComment() {
- return comment;
- }
-
- public void setComment(String comment) {
this.comment = comment;
+ this.additional = (additional == null) ? new HashMap<>() : additional;
}
/**
* @return Map with additional keys, which are not officially supported by the HAR specification
*/
@JsonAnyGetter
- public Map getAdditional() {
+ public Map additional() {
return additional;
}
@@ -68,19 +49,4 @@ public void setAdditionalField(String key, Object value) {
this.additional.put(key, value);
}
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (!(o instanceof HarQueryParam)) return false;
- HarQueryParam that = (HarQueryParam) o;
- return Objects.equals(name, that.name) &&
- Objects.equals(value, that.value) &&
- Objects.equals(comment, that.comment) &&
- Objects.equals(additional, that.additional);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(name, value, comment, additional);
- }
}
diff --git a/src/main/java/de/sstoehr/harreader/model/HarRequest.java b/src/main/java/de/sstoehr/harreader/model/HarRequest.java
index aec0ae9..919750e 100644
--- a/src/main/java/de/sstoehr/harreader/model/HarRequest.java
+++ b/src/main/java/de/sstoehr/harreader/model/HarRequest.java
@@ -1,16 +1,13 @@
package de.sstoehr.harreader.model;
-import com.fasterxml.jackson.annotation.JsonAnyGetter;
-import com.fasterxml.jackson.annotation.JsonAnySetter;
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.*;
-import java.util.ArrayList;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Objects;
/**
* Information about a performed request.
@@ -18,173 +15,60 @@
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
-public class HarRequest {
+public record HarRequest(
+ @Nullable String method,
+ @Nullable String url,
+ @Nullable String httpVersion,
+ @Nonnull List cookies,
+ @Nonnull List headers,
+ @Nonnull List queryString,
+ @Nonnull HarPostData postData,
+ @Nonnull Long headersSize,
+ @Nonnull Long bodySize,
+ @Nullable String comment,
+ @Nonnull Map additional) {
protected static final Long DEFAULT_SIZE = -1L;
- private HttpMethod parsedMethod;
- private String method;
- private String url;
- private String httpVersion;
- private List cookies;
- private List headers;
- private List queryString;
- private HarPostData postData;
- private Long headersSize = DEFAULT_SIZE;
- private Long bodySize = DEFAULT_SIZE;
- private String comment;
- private final Map additional = new HashMap<>();
-
- /**
- * @return Request method, null if not present.
- */
- public HttpMethod getMethod() {
- return parsedMethod;
- }
-
- public void setMethod(HttpMethod method) {
- this.parsedMethod = method;
- this.method = method.name();
- }
-
- /**
- * @return Request method, null if not present.
- */
- @JsonProperty("method")
- public String getRawMethod() {
- return method;
- }
-
- @JsonProperty("method")
- public void setRawMethod(String rawMethod) {
- this.parsedMethod = HttpMethod.fromString(rawMethod);
- this.method = rawMethod;
- }
-
- /**
- * @return Absolute URL of the request (fragments are not included), null if not present.
- */
- public String getUrl() {
- return url;
- }
-
- public void setUrl(String url) {
+ public HarRequest() {
+ this(null, null, null, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(),
+ new HarPostData(), DEFAULT_SIZE, DEFAULT_SIZE, null, new HashMap<>());
+ }
+
+ public HarRequest(@Nullable String method,
+ @Nullable String url,
+ @Nullable String httpVersion,
+ @Nullable List cookies,
+ @Nullable List headers,
+ @Nullable List queryString,
+ @Nullable HarPostData postData,
+ @Nullable Long headersSize,
+ @Nullable Long bodySize,
+ @Nullable String comment,
+ @Nullable Map additional) {
+ this.method = method;
this.url = url;
- }
-
- /**
- * @return Request HTTP Version, null if not present.
- */
- public String getHttpVersion() {
- return httpVersion;
- }
-
- public void setHttpVersion(String httpVersion) {
this.httpVersion = httpVersion;
+ this.cookies = (cookies == null) ? Collections.emptyList() : cookies;
+ this.headers = (headers == null) ? Collections.emptyList() : headers;
+ this.queryString = (queryString == null) ? Collections.emptyList() : queryString;
+ this.postData = (postData == null) ? new HarPostData() : postData;
+ this.headersSize = (headersSize == null) ? DEFAULT_SIZE : headersSize;
+ this.bodySize = (bodySize == null) ? DEFAULT_SIZE : bodySize;
+ this.comment = comment;
+ this.additional = (additional == null) ? new HashMap<>() : additional;
}
- /**
- * @return List of cookie objects.
- */
- public List getCookies() {
- if (cookies == null) {
- cookies = new ArrayList<>();
- }
- return cookies;
- }
-
- public void setCookies(List cookies) {
- this.cookies = cookies;
- }
-
- /**
- * @return List of header objects.
- */
- public List getHeaders() {
- if (headers == null) {
- headers = new ArrayList<>();
- }
- return headers;
- }
-
- public void setHeaders(List headers) {
- this.headers = headers;
- }
-
- /**
- * @return List of query parameter objects.
- */
- public List getQueryString() {
- if (queryString == null) {
- queryString = new ArrayList<>();
- }
- return queryString;
- }
-
- public void setQueryString(List queryString) {
- this.queryString = queryString;
- }
-
- /**
- * @return Posted data info.
- */
- public HarPostData getPostData() {
- if (postData == null) {
- postData = new HarPostData();
- }
- return postData;
- }
-
- public void setPostData(HarPostData postData) {
- this.postData = postData;
- }
-
- /**
- * @return Total number of bytes from the start of the HTTP request message until (and including) the double
- * CRLF before the body. {@link #DEFAULT_SIZE} if the info is not available.
- */
- public Long getHeadersSize() {
- if (headersSize == null) {
- return DEFAULT_SIZE;
- }
- return headersSize;
- }
-
- public void setHeadersSize(Long headersSize) {
- this.headersSize = headersSize;
- }
-
- /**
- * @return Size of the request body (POST data payload) in bytes.
- * {@link #DEFAULT_SIZE} if the info is not available.
- */
- public Long getBodySize() {
- if (bodySize == null) {
- return DEFAULT_SIZE;
- }
- return bodySize;
- }
-
- public void setBodySize(Long bodySize) {
- this.bodySize = bodySize;
- }
-
- /**
- * @return Comment provided by the user or application, null if not present.
- */
- public String getComment() {
- return comment;
- }
-
- public void setComment(String comment) {
- this.comment = comment;
+ @JsonIgnore
+ public HttpMethod httpMethod() {
+ return HttpMethod.fromString(method);
}
/**
* @return Map with additional keys, which are not officially supported by the HAR specification
*/
@JsonAnyGetter
- public Map getAdditional() {
+ public Map additional() {
return additional;
}
@@ -193,28 +77,4 @@ public void setAdditionalField(String key, Object value) {
this.additional.put(key, value);
}
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (!(o instanceof HarRequest)) return false;
- HarRequest that = (HarRequest) o;
- return parsedMethod == that.parsedMethod &&
- Objects.equals(method, that.method) &&
- Objects.equals(url, that.url) &&
- Objects.equals(httpVersion, that.httpVersion) &&
- Objects.equals(cookies, that.cookies) &&
- Objects.equals(headers, that.headers) &&
- Objects.equals(queryString, that.queryString) &&
- Objects.equals(postData, that.postData) &&
- Objects.equals(headersSize, that.headersSize) &&
- Objects.equals(bodySize, that.bodySize) &&
- Objects.equals(comment, that.comment) &&
- Objects.equals(additional, that.additional);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(parsedMethod, method, url, httpVersion, cookies, headers, queryString, postData, headersSize,
- bodySize, comment, additional);
- }
}
diff --git a/src/main/java/de/sstoehr/harreader/model/HarResponse.java b/src/main/java/de/sstoehr/harreader/model/HarResponse.java
index 9f005e7..c75a032 100644
--- a/src/main/java/de/sstoehr/harreader/model/HarResponse.java
+++ b/src/main/java/de/sstoehr/harreader/model/HarResponse.java
@@ -1,16 +1,13 @@
package de.sstoehr.harreader.model;
-import com.fasterxml.jackson.annotation.JsonAnyGetter;
-import com.fasterxml.jackson.annotation.JsonAnySetter;
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.*;
-import java.util.ArrayList;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Objects;
/**
* Information about a performed response.
@@ -18,171 +15,61 @@
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
-public class HarResponse {
+public record HarResponse(
+ int status,
+ @Nullable String statusText,
+ @Nullable String httpVersion,
+ @Nonnull List cookies,
+ @Nonnull List headers,
+ @Nonnull HarContent content,
+ @Nullable String redirectURL,
+ @Nonnull Long headersSize,
+ @Nonnull Long bodySize,
+ @Nullable String comment,
+ @Nonnull Map additional) {
protected static final Long DEFAULT_SIZE = -1L;
- private HttpStatus parsedStatus = HttpStatus.UNKNOWN_HTTP_STATUS;
- private int status = HttpStatus.UNKNOWN_HTTP_STATUS.getCode();
- private String statusText;
- private String httpVersion;
- private List cookies;
- private List headers;
- private HarContent content;
- private String redirectURL;
- private Long headersSize = DEFAULT_SIZE;
- private Long bodySize = DEFAULT_SIZE;
- private String comment;
- private final Map additional = new HashMap<>();
-
- /**
- * @return Response status, 0 if not present or unknown.
- */
- public int getStatus() {
- return parsedStatus.getCode();
- }
-
- public void setStatus(int status) {
- this.parsedStatus = HttpStatus.byCode(status);
+ public HarResponse() {
+ this(HttpStatus.UNKNOWN_HTTP_STATUS.getCode(), null, null,
+ Collections.emptyList(), Collections.emptyList(), new HarContent(), null,
+ DEFAULT_SIZE, DEFAULT_SIZE, null, new HashMap<>());
+ }
+
+ public HarResponse(int status,
+ @Nullable String statusText,
+ @Nullable String httpVersion,
+ @Nullable List cookies,
+ @Nullable List headers,
+ @Nullable HarContent content,
+ @Nullable String redirectURL,
+ @Nullable Long headersSize,
+ @Nullable Long bodySize,
+ @Nullable String comment,
+ @Nullable Map additional) {
this.status = status;
- }
-
- /**
- * @return Response status, 0 if not present
- */
- @JsonProperty("status")
- public int getRawStatus() {
- return status;
- }
-
- @JsonProperty("status")
- public void setRawStatus(int rawStatus) {
- this.parsedStatus = HttpStatus.byCode(rawStatus);
- this.status = rawStatus;
- }
-
- /**
- * @return Response status description, null if not present.
- */
- public String getStatusText() {
- return statusText;
- }
-
- public void setStatusText(String statusText) {
this.statusText = statusText;
- }
-
- /**
- * @return Response HTTP Version, null if not present.
- */
- public String getHttpVersion() {
- return httpVersion;
- }
-
- public void setHttpVersion(String httpVersion) {
this.httpVersion = httpVersion;
- }
-
- /**
- * @return List of cookie objects.
- */
- public List getCookies() {
- if (cookies == null) {
- cookies = new ArrayList<>();
- }
- return cookies;
- }
-
- public void setCookies(List cookies) {
- this.cookies = cookies;
- }
-
- /**
- * @return List of header objects.
- */
- public List getHeaders() {
- if (headers == null) {
- headers = new ArrayList<>();
- }
- return headers;
- }
-
- public void setHeaders(List headers) {
- this.headers = headers;
- }
-
- /**
- * @return Details about the response body.
- */
- public HarContent getContent() {
- if (content == null) {
- content = new HarContent();
- }
- return content;
- }
-
- public void setContent(HarContent content) {
- this.content = content;
- }
-
- /**
- * @return Redirection target URL from the Location response header, null if not present.
- */
- public String getRedirectURL() {
- return redirectURL;
- }
-
- public void setRedirectURL(String redirectURL) {
+ this.cookies = (cookies == null) ? Collections.emptyList() : cookies;
+ this.headers = (headers == null) ? Collections.emptyList() : headers;
+ this.content = (content == null) ? new HarContent() : content;
this.redirectURL = redirectURL;
+ this.headersSize = (headersSize == null) ? DEFAULT_SIZE : headersSize;
+ this.bodySize = (bodySize == null) ? DEFAULT_SIZE : bodySize;
+ this.comment = comment;
+ this.additional = (additional == null) ? new HashMap<>() : additional;
}
- /**
- * @return Total number of bytes from the start of the HTTP response message until (and including) the double
- * CRLF before the body. {@link #DEFAULT_SIZE} if the info is not available.
- */
- public Long getHeadersSize() {
- if (headersSize == null) {
- return DEFAULT_SIZE;
- }
- return headersSize;
- }
-
- public void setHeadersSize(Long headersSize) {
- this.headersSize = headersSize;
- }
-
- /**
- * @return Size of the received response body in bytes.
- * Set to zero in case of responses coming from the cache (304).
- * {@link #DEFAULT_SIZE} if the info is not available.
- */
- public Long getBodySize() {
- if (bodySize == null) {
- return DEFAULT_SIZE;
- }
- return bodySize;
- }
-
- public void setBodySize(Long bodySize) {
- this.bodySize = bodySize;
- }
-
- /**
- * @return Comment provided by the user or application, null if not present.
- */
- public String getComment() {
- return comment;
- }
-
- public void setComment(String comment) {
- this.comment = comment;
+ @JsonIgnore
+ public HttpStatus httpStatus() {
+ return HttpStatus.byCode(status);
}
/**
* @return Map with additional keys, which are not officially supported by the HAR specification
*/
@JsonAnyGetter
- public Map getAdditional() {
+ public Map additional() {
return additional;
}
@@ -191,28 +78,4 @@ public void setAdditionalField(String key, Object value) {
this.additional.put(key, value);
}
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (!(o instanceof HarResponse)) return false;
- HarResponse that = (HarResponse) o;
- return parsedStatus == that.parsedStatus &&
- status == that.status &&
- Objects.equals(statusText, that.statusText) &&
- Objects.equals(httpVersion, that.httpVersion) &&
- Objects.equals(cookies, that.cookies) &&
- Objects.equals(headers, that.headers) &&
- Objects.equals(content, that.content) &&
- Objects.equals(redirectURL, that.redirectURL) &&
- Objects.equals(headersSize, that.headersSize) &&
- Objects.equals(bodySize, that.bodySize) &&
- Objects.equals(comment, that.comment) &&
- Objects.equals(additional, that.additional);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(parsedStatus, status, statusText, httpVersion, cookies, headers, content, redirectURL, headersSize,
- bodySize, comment, additional);
- }
}
diff --git a/src/main/java/de/sstoehr/harreader/model/HarTiming.java b/src/main/java/de/sstoehr/harreader/model/HarTiming.java
index 46a0b8f..5251b11 100644
--- a/src/main/java/de/sstoehr/harreader/model/HarTiming.java
+++ b/src/main/java/de/sstoehr/harreader/model/HarTiming.java
@@ -1,141 +1,62 @@
package de.sstoehr.harreader.model;
+
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.Map;
-import java.util.Objects;
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
-public class HarTiming {
+public record HarTiming(
+ @Nonnull Integer blocked,
+ @Nonnull Integer dns,
+ @Nonnull Integer connect,
+ @Nullable Integer send,
+ @JsonProperty("wait") @Nullable Integer waitTime,
+ @Nullable Integer receive,
+ @Nonnull Integer ssl,
+ @Nullable String comment,
+ @Nonnull Map additional) {
protected static final Integer DEFAULT_TIME = -1;
- private Integer blocked;
- private Integer dns;
- private Integer connect;
- private Integer send;
- private Integer wait;
- private Integer receive;
- private Integer ssl;
- private String comment;
- private final Map additional = new HashMap<>();
-
- /**
- * @return Time spent in a queue waiting for a network connection.
- * {@link #DEFAULT_TIME} if the timing does not apply to the current request.
- */
- public Integer getBlocked() {
- if (blocked == null) {
- return DEFAULT_TIME;
- }
- return blocked;
- }
-
- public void setBlocked(Integer blocked) {
- this.blocked = blocked;
- }
-
- /**
- * @return DNS resolution time. The time required to resolve a host name.
- * {@link #DEFAULT_TIME} if the timing does not apply to the current request.
- */
- public Integer getDns() {
- if (dns == null) {
- return DEFAULT_TIME;
- }
- return dns;
- }
-
- public void setDns(Integer dns) {
- this.dns = dns;
- }
-
- /**
- * @return Time required to create TCP connection.
- * {@link #DEFAULT_TIME} if the timing does not apply to the current request.
- */
- public Integer getConnect() {
- if (connect == null) {
- return DEFAULT_TIME;
- }
- return connect;
- }
-
- public void setConnect(Integer connect) {
- this.connect = connect;
- }
-
- /**
- * @return Time required to send HTTP request to the server, null if not present.
- */
- public Integer getSend() {
- return send;
- }
-
- public void setSend(Integer send) {
+ public HarTiming() {
+ this(DEFAULT_TIME, DEFAULT_TIME, DEFAULT_TIME,
+ null, null, null, DEFAULT_TIME, null, new HashMap<>());
+ }
+
+ public HarTiming(@Nullable Integer blocked,
+ @Nullable Integer dns,
+ @Nullable Integer connect,
+ @Nullable Integer send,
+ @Nullable Integer waitTime,
+ @Nullable Integer receive,
+ @Nullable Integer ssl,
+ @Nullable String comment,
+ @Nullable Map additional) {
+ this.blocked = (blocked == null) ? DEFAULT_TIME : blocked;
+ this.dns = (dns == null) ? DEFAULT_TIME : dns;
+ this.connect = (connect == null) ? DEFAULT_TIME : connect;
this.send = send;
- }
-
- /**
- * @return Waiting for a response from the server, null if not present.
- */
- public Integer getWait() {
- return wait;
- }
-
- public void setWait(Integer wait) {
- this.wait = wait;
- }
-
- /**
- * @return Time required to read entire response from the server (or cache), null if not present.
- */
- public Integer getReceive() {
- return receive;
- }
-
- public void setReceive(Integer receive) {
+ this.waitTime = waitTime;
this.receive = receive;
- }
-
- /**
- * @return Time required for SSL/TLS negotiation.
- * If this field is defined then the time is also included in the connect field
- * (to ensure backward compatibility with HAR 1.1).
- * {@link #DEFAULT_TIME} if the timing does not apply to the current request.
- */
- public Integer getSsl() {
- if (ssl == null) {
- return DEFAULT_TIME;
- }
- return ssl;
- }
-
- public void setSsl(Integer ssl) {
- this.ssl = ssl;
- }
-
- /**
- * @return Comment provided by the user or application, null if not present.
- */
- public String getComment() {
- return comment;
- }
-
- public void setComment(String comment) {
+ this.ssl = (ssl == null) ? DEFAULT_TIME : ssl;
this.comment = comment;
+ this.additional = (additional == null) ? new HashMap<>() : additional;
}
/**
* @return Map with additional keys, which are not officially supported by the HAR specification
*/
@JsonAnyGetter
- public Map getAdditional() {
+ public Map additional() {
return additional;
}
@@ -144,24 +65,4 @@ public void setAdditionalField(String key, Object value) {
this.additional.put(key, value);
}
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (!(o instanceof HarTiming)) return false;
- HarTiming harTiming = (HarTiming) o;
- return Objects.equals(blocked, harTiming.blocked) &&
- Objects.equals(dns, harTiming.dns) &&
- Objects.equals(connect, harTiming.connect) &&
- Objects.equals(send, harTiming.send) &&
- Objects.equals(wait, harTiming.wait) &&
- Objects.equals(receive, harTiming.receive) &&
- Objects.equals(ssl, harTiming.ssl) &&
- Objects.equals(comment, harTiming.comment) &&
- Objects.equals(additional, harTiming.additional);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(blocked, dns, connect, send, wait, receive, ssl, comment, additional);
- }
}
diff --git a/src/main/java/de/sstoehr/harreader/model/HttpMethod.java b/src/main/java/de/sstoehr/harreader/model/HttpMethod.java
index b5b8dac..f877549 100644
--- a/src/main/java/de/sstoehr/harreader/model/HttpMethod.java
+++ b/src/main/java/de/sstoehr/harreader/model/HttpMethod.java
@@ -1,9 +1,16 @@
package de.sstoehr.harreader.model;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
public enum HttpMethod {
GET, POST, PUT, HEAD, PROPFIND, OPTIONS, REPORT, DELETE, CONNECT, TRACE, CCM_POST, PATCH, UNKNOWN;
- public static HttpMethod fromString(String method) {
+ @Nonnull
+ public static HttpMethod fromString(@Nullable String method) {
+ if (method == null) {
+ return HttpMethod.UNKNOWN;
+ }
try {
return HttpMethod.valueOf(method.toUpperCase());
} catch (IllegalArgumentException e) {
diff --git a/src/main/java/de/sstoehr/harreader/model/HttpStatus.java b/src/main/java/de/sstoehr/harreader/model/HttpStatus.java
index cf6e429..e0d1257 100644
--- a/src/main/java/de/sstoehr/harreader/model/HttpStatus.java
+++ b/src/main/java/de/sstoehr/harreader/model/HttpStatus.java
@@ -1,5 +1,6 @@
package de.sstoehr.harreader.model;
+import javax.annotation.Nonnull;
import java.util.HashMap;
import java.util.Map;
@@ -48,6 +49,7 @@ public int getCode() {
return code;
}
+ @Nonnull
public static HttpStatus byCode(int code) {
HttpStatus status = CODE_MAP.get(code);
if (status == null) {
diff --git a/src/test/java/de/sstoehr/harreader/HarReaderTest.java b/src/test/java/de/sstoehr/harreader/HarReaderTest.java
index 83bf2e6..2e8c67a 100644
--- a/src/test/java/de/sstoehr/harreader/HarReaderTest.java
+++ b/src/test/java/de/sstoehr/harreader/HarReaderTest.java
@@ -28,7 +28,7 @@ void shouldReadFromFile() throws HarReaderException {
}
@Test
- void shouldReadFromInputStream() throws HarReaderException, IOException {
+ void shouldReadFromInputStream() throws IOException {
File harFile = new File(PATH_TO_VALID_HAR);
InputStream inputStream = Files.newInputStream(harFile.toPath());
Har har = harReader.readFromInputStream(inputStream);
@@ -36,7 +36,7 @@ void shouldReadFromInputStream() throws HarReaderException, IOException {
}
@Test
- void shouldReadFromString() throws HarReaderException, IOException {
+ void shouldReadFromString() throws IOException {
byte[] bytes = Files.readAllBytes(new File(PATH_TO_VALID_HAR).toPath());
String harAsString = new String(bytes, StandardCharsets.UTF_8);
Har har = harReader.readFromString(harAsString);
@@ -44,7 +44,7 @@ void shouldReadFromString() throws HarReaderException, IOException {
}
@Test
- void shouldReadFromBytes() throws HarReaderException, IOException {
+ void shouldReadFromBytes() throws IOException {
byte[] harAsBytes = Files.readAllBytes(new File(PATH_TO_VALID_HAR).toPath());
Har har = harReader.readFromBytes(harAsBytes);
assertNotNull(har);
@@ -57,7 +57,7 @@ void missingLog() throws HarReaderException {
}
@Test
- void invalidDateStrict() throws HarReaderException {
+ void invalidDateStrict() {
File harFile = new File("src/test/resources/sstoehr.invalid-date.har");
assertThrows(HarReaderException.class, () -> harReader.readFromFile(harFile));
}
@@ -70,7 +70,7 @@ void invalidDateLax() throws HarReaderException {
}
@Test
- void invalidIntegerStrict() throws HarReaderException {
+ void invalidIntegerStrict() {
File harFile = new File("src/test/resources/sstoehr.invalid-integer.har");
assertThrows(HarReaderException.class, () -> harReader.readFromFile(harFile));
}
diff --git a/src/test/java/de/sstoehr/harreader/HarWriterTests.java b/src/test/java/de/sstoehr/harreader/HarWriterTests.java
index c9e49ec..5493281 100644
--- a/src/test/java/de/sstoehr/harreader/HarWriterTests.java
+++ b/src/test/java/de/sstoehr/harreader/HarWriterTests.java
@@ -8,18 +8,23 @@
import java.io.StringWriter;
import java.nio.charset.StandardCharsets;
+import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
+import de.sstoehr.harreader.jackson.DefaultMapperFactory;
import org.junit.jupiter.api.Test;
import de.sstoehr.harreader.model.Har;
class HarWriterTests {
- private static final ObjectMapper MAPPER = new ObjectMapper();
+ private static final ObjectMapper MAPPER = new ObjectMapper()
+ .registerModule(new JavaTimeModule())
+ .configure(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE, false);
private static final File HAR_FILE = new File("src/test/resources/sstoehr.har");
@Test
- void shouldWriteHarAsString() throws HarReaderException, IOException, HarWriterException {
+ void shouldWriteHarAsString() throws IOException {
Har expected = MAPPER.readValue(HAR_FILE, Har.class);
Har har = new HarReader().readFromFile(HAR_FILE);
@@ -28,16 +33,16 @@ void shouldWriteHarAsString() throws HarReaderException, IOException, HarWriterE
}
@Test
- void shouldWriteHarAsBytes() throws HarReaderException, IOException, HarWriterException {
+ void shouldWriteHarAsBytes() throws IOException {
Har expected = MAPPER.readValue(HAR_FILE, Har.class);
Har har = new HarReader().readFromFile(HAR_FILE);
- HarWriter writer = new HarWriter();
+ HarWriter writer = new HarWriter(new DefaultMapperFactory());
assertEquals(MAPPER.writeValueAsString(expected), new String(writer.writeAsBytes(har), StandardCharsets.UTF_8));
}
@Test
- void testWriteToOutputStream() throws IOException, HarWriterException {
+ void testWriteToOutputStream() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Har expected = MAPPER.readValue(HAR_FILE, Har.class);
@@ -47,7 +52,7 @@ void testWriteToOutputStream() throws IOException, HarWriterException {
}
@Test
- void testWriteToFile() throws IOException, HarWriterException {
+ void testWriteToFile() throws IOException {
File file = File.createTempFile("pref", "suff");
Har expected = MAPPER.readValue(HAR_FILE, Har.class);
@@ -58,7 +63,7 @@ void testWriteToFile() throws IOException, HarWriterException {
}
@Test
- void testWriteToWriter() throws IOException, HarWriterException {
+ void testWriteToWriter() throws IOException {
StringWriter sw = new StringWriter();
Har expected = MAPPER.readValue(HAR_FILE, Har.class);
diff --git a/src/test/java/de/sstoehr/harreader/model/AbstractMapperTest.java b/src/test/java/de/sstoehr/harreader/model/AbstractMapperTest.java
index 7b1f09d..3234bcd 100644
--- a/src/test/java/de/sstoehr/harreader/model/AbstractMapperTest.java
+++ b/src/test/java/de/sstoehr/harreader/model/AbstractMapperTest.java
@@ -2,19 +2,27 @@
import static org.junit.jupiter.api.Assertions.fail;
-import org.junit.jupiter.api.Test;
-
import com.fasterxml.jackson.databind.ObjectMapper;
+import de.sstoehr.harreader.jackson.DefaultMapperFactory;
+import org.junit.jupiter.api.Assertions;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import java.lang.reflect.Field;
+import java.util.Arrays;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
public abstract class AbstractMapperTest {
protected final static String UNKNOWN_PROPERTY = "{\"unknownProperty\":\"value\"}";
- @Test
abstract void testMapping();
public T map(String input, Class tClass) {
- ObjectMapper mapper = new ObjectMapper();
+ ObjectMapper mapper = (new DefaultMapperFactory()).instance();
try {
return mapper.readValue(input, tClass);
} catch (Exception e) {
@@ -22,4 +30,20 @@ public T map(String input, Class tClass) {
}
return null;
}
+
+ public void testNullability(T object) {
+ Arrays.stream(object.getClass().getDeclaredFields())
+ .forEach(f -> {
+ f.setAccessible(true);
+ try {
+ if (f.isAnnotationPresent(Nonnull.class)) {
+ Assertions.assertNotNull(f.get(object), "Field " + f.getName() + " should not be null");
+ } else if (f.isAnnotationPresent(Nullable.class)) {
+ Assertions.assertNull(f.get(object), "Field " + f.getName() + " should be null");
+ }
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(e);
+ }
+ });
+ }
}
diff --git a/src/test/java/de/sstoehr/harreader/model/HarCacheInfoTest.java b/src/test/java/de/sstoehr/harreader/model/HarCacheInfoTest.java
new file mode 100644
index 0000000..5019730
--- /dev/null
+++ b/src/test/java/de/sstoehr/harreader/model/HarCacheInfoTest.java
@@ -0,0 +1,43 @@
+package de.sstoehr.harreader.model;
+
+import nl.jqno.equalsverifier.EqualsVerifier;
+import org.junit.jupiter.api.Test;
+
+import java.time.Instant;
+import java.time.ZoneId;
+import java.time.ZonedDateTime;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+class HarCacheInfoTest extends AbstractMapperTest {
+
+ private final static ZonedDateTime EXPECTED_EXPIRES = ZonedDateTime.ofInstant(Instant.ofEpochMilli(1388577600000L), ZoneId.of("Z"));
+ private final static ZonedDateTime EXPECTED_LAST_ACCESS = ZonedDateTime.ofInstant(Instant.ofEpochMilli(1370088000000L), ZoneId.of("Z"));
+
+ @Override
+ @Test
+ void testMapping() {
+ HarCache.HarCacheInfo cacheInfo = map("{\"expires\":\"2014-01-01T12:00:00Z\",\"lastAccess\":\"2013-06-01T12:00:00Z\",\"eTag\":\"abc123\"," +
+ "\"hitCount\":3,\"comment\":\"my comment\", \"_unknown\":\"unknown\"}", HarCache.HarCacheInfo.class);
+
+ assertEquals(EXPECTED_EXPIRES, cacheInfo.expires());
+ assertEquals(EXPECTED_LAST_ACCESS, cacheInfo.lastAccess());
+ assertEquals("abc123", cacheInfo.eTag());
+ assertEquals(3, (long) cacheInfo.hitCount());
+ assertEquals("my comment", cacheInfo.comment());
+
+ assertNotNull(cacheInfo.additional());
+ assertEquals("unknown", cacheInfo.additional().get("_unknown"));
+ }
+
+ @Test
+ void testNullability() {
+ testNullability(new HarCache.HarCacheInfo());
+ }
+
+ @Test
+ void equalsContract() {
+ EqualsVerifier.simple().forClass(HarCache.HarCacheInfo.class).verify();
+ }
+}
diff --git a/src/test/java/de/sstoehr/harreader/model/HarCacheTest.java b/src/test/java/de/sstoehr/harreader/model/HarCacheTest.java
index a2d3705..7b03153 100644
--- a/src/test/java/de/sstoehr/harreader/model/HarCacheTest.java
+++ b/src/test/java/de/sstoehr/harreader/model/HarCacheTest.java
@@ -4,46 +4,49 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
-import java.util.Date;
+import java.time.Instant;
+import java.time.ZoneId;
+import java.time.ZonedDateTime;
import org.junit.jupiter.api.Test;
class HarCacheTest extends AbstractMapperTest {
- private final static Date EXPECTED_EXPIRES = new Date() {{
- setTime(1388577600000L);
- }};
- private final static Date EXPECTED_LAST_ACCESS = new Date() {{
- setTime(1370088000000L);
- }};
+ private final static ZonedDateTime EXPECTED_EXPIRES = ZonedDateTime.ofInstant(Instant.ofEpochMilli(1388577600000L), ZoneId.of("Z"));
+ private final static ZonedDateTime EXPECTED_LAST_ACCESS = ZonedDateTime.ofInstant(Instant.ofEpochMilli(1370088000000L), ZoneId.of("Z"));
@Override
+ @Test
public void testMapping() {
- HarCache cache = map("{\"beforeRequest\":{\"expires\":\"2014-01-01T12:00:00\",\"lastAccess\":\"2013-06-01T12:00:00\",\"eTag\":\"abc123\"," +
+ HarCache cache = map("{\"beforeRequest\":{\"expires\":\"2014-01-01T12:00:00Z\",\"lastAccess\":\"2013-06-01T12:00:00Z\",\"eTag\":\"abc123\"," +
"\"hitCount\":3,\"comment\":\"my comment\"},\"afterRequest\":{},\"comment\":\"my comment 2\",\"_unknown\":\"unknown\"}", HarCache.class);
- assertNotNull(cache.getBeforeRequest());
- assertEquals(EXPECTED_EXPIRES, cache.getBeforeRequest().getExpires());
- assertEquals(EXPECTED_LAST_ACCESS, cache.getBeforeRequest().getLastAccess());
- assertEquals("abc123", cache.getBeforeRequest().geteTag());
- assertEquals(3, (long) cache.getBeforeRequest().getHitCount());
- assertEquals("my comment", cache.getBeforeRequest().getComment());
+ assertNotNull(cache.beforeRequest());
+ assertEquals(EXPECTED_EXPIRES, cache.beforeRequest().expires());
+ assertEquals(EXPECTED_LAST_ACCESS, cache.beforeRequest().lastAccess());
+ assertEquals("abc123", cache.beforeRequest().eTag());
+ assertEquals(3, (long) cache.beforeRequest().hitCount());
+ assertEquals("my comment", cache.beforeRequest().comment());
- assertNotNull(cache.getAfterRequest());
+ assertNotNull(cache.afterRequest());
- assertEquals("my comment 2", cache.getComment());
+ assertEquals("my comment 2", cache.comment());
- assertNotNull(cache.getAdditional());
- assertEquals("unknown", cache.getAdditional().get("_unknown"));
+ assertNotNull(cache.additional());
+ assertEquals("unknown", cache.additional().get("_unknown"));
cache = map(UNKNOWN_PROPERTY, HarCache.class);
assertNotNull(cache);
}
+ @Test
+ void testNullability() {
+ testNullability(new HarCache());
+ }
+
@Test
void equalsContract() {
EqualsVerifier.simple().forClass(HarCache.class).verify();
- EqualsVerifier.simple().forClass(HarCache.HarCacheInfo.class).verify();
}
}
diff --git a/src/test/java/de/sstoehr/harreader/model/HarContentTest.java b/src/test/java/de/sstoehr/harreader/model/HarContentTest.java
index 5a88c76..41de3a1 100644
--- a/src/test/java/de/sstoehr/harreader/model/HarContentTest.java
+++ b/src/test/java/de/sstoehr/harreader/model/HarContentTest.java
@@ -7,27 +7,34 @@
import nl.jqno.equalsverifier.EqualsVerifier;
+
class HarContentTest extends AbstractMapperTest {
@Override
+ @Test
public void testMapping() {
HarContent content = map("{\"size\":123,\"compression\":45,\"mimeType\":\"mime/type\"," +
"\"text\":\"my content\",\"encoding\":\"base64\",\"comment\":\"my comment\",\"_unknown\":\"unknown\"}", HarContent.class);
- assertEquals(123L, (long) content.getSize());
- assertEquals(45L, (long) content.getCompression());
- assertEquals("mime/type", content.getMimeType());
- assertEquals("my content", content.getText());
- assertEquals("base64", content.getEncoding());
- assertEquals("my comment", content.getComment());
+ 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());
- assertNotNull(content.getAdditional());
- assertEquals("unknown", content.getAdditional().get("_unknown"));
+ assertNotNull(content.additional());
+ assertEquals("unknown", content.additional().get("_unknown"));
content = map(UNKNOWN_PROPERTY, HarContent.class);
assertNotNull(content);
}
+ @Test
+ void testNullability() {
+ testNullability(new HarContent());
+ }
+
@Test
void equalsContract() {
EqualsVerifier.simple().forClass(HarContent.class).verify();
diff --git a/src/test/java/de/sstoehr/harreader/model/HarCookieTest.java b/src/test/java/de/sstoehr/harreader/model/HarCookieTest.java
index 4a8b681..49a9022 100644
--- a/src/test/java/de/sstoehr/harreader/model/HarCookieTest.java
+++ b/src/test/java/de/sstoehr/harreader/model/HarCookieTest.java
@@ -5,38 +5,44 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
-import java.util.Date;
+import java.time.Instant;
+import java.time.ZoneId;
+import java.time.ZonedDateTime;
import org.junit.jupiter.api.Test;
class HarCookieTest extends AbstractMapperTest {
- private final static Date EXPECTED_EXPIRES = new Date() {{
- setTime(1388577600000L);
- }};
+ private final static ZonedDateTime EXPECTED_EXPIRES = ZonedDateTime.ofInstant(Instant.ofEpochMilli(1388577600000L), ZoneId.of("Z"));
@Override
+ @Test
public void testMapping() {
HarCookie cookie = map("{\"name\":\"aName\",\"value\":\"aValue\",\"path\":\"/\",\"domain\":\"sstoehr.de\"," +
- "\"expires\":\"2014-01-01T12:00:00\",\"httpOnly\":\"true\",\"secure\":\"false\",\"comment\":\"my comment\",\"_unknown\":\"unknown\"}", HarCookie.class);
+ "\"expires\":\"2014-01-01T12:00:00Z\",\"httpOnly\":\"true\",\"secure\":\"false\",\"comment\":\"my comment\",\"_unknown\":\"unknown\"}", HarCookie.class);
assertNotNull(cookie);
- assertEquals("aName", cookie.getName());
- assertEquals("aValue", cookie.getValue());
- assertEquals("/", cookie.getPath());
- assertEquals("sstoehr.de", cookie.getDomain());
- assertEquals(EXPECTED_EXPIRES, cookie.getExpires());
- assertEquals(true, cookie.getHttpOnly());
- assertEquals(false, cookie.getSecure());
- assertEquals("my comment", cookie.getComment());
-
- assertNotNull(cookie.getAdditional());
- assertEquals("unknown", cookie.getAdditional().get("_unknown"));
+ assertEquals("aName", cookie.name());
+ assertEquals("aValue", cookie.value());
+ assertEquals("/", cookie.path());
+ assertEquals("sstoehr.de", cookie.domain());
+ assertEquals(EXPECTED_EXPIRES, cookie.expires());
+ assertEquals(true, cookie.httpOnly());
+ assertEquals(false, cookie.secure());
+ assertEquals("my comment", cookie.comment());
+
+ assertNotNull(cookie.additional());
+ assertEquals("unknown", cookie.additional().get("_unknown"));
cookie = map(UNKNOWN_PROPERTY, HarCookie.class);
assertNotNull(cookie);
}
+ @Test
+ void testNullability() {
+ testNullability(new HarCookie());
+ }
+
@Test
void equalsContract() {
EqualsVerifier.simple().forClass(HarCookie.class).verify();
diff --git a/src/test/java/de/sstoehr/harreader/model/HarCreatorBrowserTest.java b/src/test/java/de/sstoehr/harreader/model/HarCreatorBrowserTest.java
index f87f667..f2bf539 100644
--- a/src/test/java/de/sstoehr/harreader/model/HarCreatorBrowserTest.java
+++ b/src/test/java/de/sstoehr/harreader/model/HarCreatorBrowserTest.java
@@ -10,21 +10,27 @@
class HarCreatorBrowserTest extends AbstractMapperTest {
@Override
+ @Test
public void testMapping() {
HarCreatorBrowser creatorBrowser = map("{\"name\":\"aName\",\"version\":\"aVersion\",\"comment\":\"my comment\",\"_unknown\":\"unknown\"}", HarCreatorBrowser.class);
assertNotNull(creatorBrowser);
- assertEquals("aName", creatorBrowser.getName());
- assertEquals("aVersion", creatorBrowser.getVersion());
- assertEquals("my comment", creatorBrowser.getComment());
+ assertEquals("aName", creatorBrowser.name());
+ assertEquals("aVersion", creatorBrowser.version());
+ assertEquals("my comment", creatorBrowser.comment());
- assertNotNull(creatorBrowser.getAdditional());
- assertEquals("unknown", creatorBrowser.getAdditional().get("_unknown"));
+ assertNotNull(creatorBrowser.additional());
+ assertEquals("unknown", creatorBrowser.additional().get("_unknown"));
creatorBrowser = map(UNKNOWN_PROPERTY, HarCreatorBrowser.class);
assertNotNull(creatorBrowser);
}
+ @Test
+ void testNullability() {
+ testNullability(new HarCreatorBrowser());
+ }
+
@Test
void equalsContract() {
EqualsVerifier.simple().forClass(HarCreatorBrowser.class).verify();
diff --git a/src/test/java/de/sstoehr/harreader/model/HarEntryTest.java b/src/test/java/de/sstoehr/harreader/model/HarEntryTest.java
index 4692f67..1aeed7e 100644
--- a/src/test/java/de/sstoehr/harreader/model/HarEntryTest.java
+++ b/src/test/java/de/sstoehr/harreader/model/HarEntryTest.java
@@ -5,34 +5,35 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
-import java.util.Date;
+import java.time.Instant;
+import java.time.ZoneId;
+import java.time.ZonedDateTime;
import org.junit.jupiter.api.Test;
public class HarEntryTest extends AbstractMapperTest {
- private final static Date EXPECTED_STARTED = new Date() {{
- setTime(1388577600000L);
- }};
+ private final static ZonedDateTime EXPECTED_STARTED = ZonedDateTime.ofInstant(Instant.ofEpochMilli(1388577600000L), ZoneId.of("Z"));
@Override
+ @Test
public void testMapping() {
- HarEntry entry = map("{\"pageref\":\"aPageref\",\"startedDateTime\":\"2014-01-01T12:00:00\",\"time\":12345,"
+ HarEntry entry = map("{\"pageref\":\"aPageref\",\"startedDateTime\":\"2014-01-01T12:00:00Z\",\"time\":12345,"
+ "\"request\":{},\"response\":{},\"cache\":{},\"timings\":{},\"serverIPAddress\":\"1.2.3.4\",\"connection\":\"aConnection\","
+ "\"comment\":\"my comment\", \"_add\": \"additional info\"}", HarEntry.class);
assertNotNull(entry);
- assertEquals("aPageref", entry.getPageref());
- assertEquals(EXPECTED_STARTED, entry.getStartedDateTime());
- assertEquals(12345, (int) entry.getTime());
- assertNotNull(entry.getRequest());
- assertNotNull(entry.getResponse());
- assertNotNull(entry.getCache());
- assertNotNull(entry.getTimings());
- assertEquals("1.2.3.4", entry.getServerIPAddress());
- assertEquals("aConnection", entry.getConnection());
- assertEquals("my comment", entry.getComment());
- assertEquals("additional info", entry.getAdditional().get("_add"));
+ assertEquals("aPageref", entry.pageref());
+ assertEquals(EXPECTED_STARTED, entry.startedDateTime());
+ assertEquals(12345, (int) entry.time());
+ assertNotNull(entry.request());
+ assertNotNull(entry.response());
+ assertNotNull(entry.cache());
+ assertNotNull(entry.timings());
+ assertEquals("1.2.3.4", entry.serverIPAddress());
+ assertEquals("aConnection", entry.connection());
+ assertEquals("my comment", entry.comment());
+ assertEquals("additional info", entry.additional().get("_add"));
entry = map(UNKNOWN_PROPERTY, HarEntry.class);
assertNotNull(entry);
@@ -41,29 +42,30 @@ public void testMapping() {
@Test
public void testRequestNull() {
HarEntry entry = new HarEntry();
- entry.setRequest(null);
- assertNotNull(entry.getRequest());
+ assertNotNull(entry.request());
}
@Test
public void testResponseNull() {
HarEntry entry = new HarEntry();
- entry.setResponse(null);
- assertNotNull(entry.getResponse());
+ assertNotNull(entry.response());
}
@Test
public void testCacheNull() {
HarEntry entry = new HarEntry();
- entry.setCache(null);
- assertNotNull(entry.getCache());
+ assertNotNull(entry.cache());
}
@Test
public void testTimingsNull() {
HarEntry entry = new HarEntry();
- entry.setTimings(null);
- assertNotNull(entry.getTimings());
+ assertNotNull(entry.timings());
+ }
+
+ @Test
+ void testNullability() {
+ testNullability(new HarEntry());
}
@Test
diff --git a/src/test/java/de/sstoehr/harreader/model/HarHeaderTest.java b/src/test/java/de/sstoehr/harreader/model/HarHeaderTest.java
index 93fcfc8..42d9998 100644
--- a/src/test/java/de/sstoehr/harreader/model/HarHeaderTest.java
+++ b/src/test/java/de/sstoehr/harreader/model/HarHeaderTest.java
@@ -10,21 +10,27 @@
class HarHeaderTest extends AbstractMapperTest {
@Override
+ @Test
public void testMapping() {
HarHeader header = map("{\"name\":\"aName\",\"value\":\"aValue\",\"comment\":\"my comment\",\"_unknown\":\"unknown\"}", HarHeader.class);
assertNotNull(header);
- assertEquals("aName", header.getName());
- assertEquals("aValue", header.getValue());
- assertEquals("my comment", header.getComment());
+ assertEquals("aName", header.name());
+ assertEquals("aValue", header.value());
+ assertEquals("my comment", header.comment());
- assertNotNull(header.getAdditional());
- assertEquals("unknown", header.getAdditional().get("_unknown"));
+ assertNotNull(header.additional());
+ assertEquals("unknown", header.additional().get("_unknown"));
header = map(UNKNOWN_PROPERTY, HarHeader.class);
assertNotNull(header);
}
+ @Test
+ void testNullability() {
+ testNullability(new HarHeader());
+ }
+
@Test
void equalsContract() {
EqualsVerifier.simple().forClass(HarHeader.class).verify();
diff --git a/src/test/java/de/sstoehr/harreader/model/HarLogTest.java b/src/test/java/de/sstoehr/harreader/model/HarLogTest.java
index c1812cb..a40c36a 100644
--- a/src/test/java/de/sstoehr/harreader/model/HarLogTest.java
+++ b/src/test/java/de/sstoehr/harreader/model/HarLogTest.java
@@ -20,71 +20,75 @@ class HarLogTest extends AbstractMapperTest {
@Test
void testVersion() {
HarLog log = new HarLog();
- assertEquals(EXPECTED_DEFAULT_VERSION, log.getVersion());
+ assertEquals(EXPECTED_DEFAULT_VERSION, log.version());
- log.setVersion("1.2");
- assertEquals("1.2", log.getVersion());
+ log = new HarLog("1.2", null, null, null, null, null, null);
+ assertEquals("1.2", log.version());
- log.setVersion(null);
- assertEquals(EXPECTED_DEFAULT_VERSION, log.getVersion());
+ log = new HarLog(null, null, null, null, null, null, null);
+ assertEquals(EXPECTED_DEFAULT_VERSION, log.version());
- log.setVersion("");
- assertEquals(EXPECTED_DEFAULT_VERSION, log.getVersion());
+ log = new HarLog("", null, null, null, null, null, null);
+ assertEquals(EXPECTED_DEFAULT_VERSION, log.version());
- log.setVersion(" ");
- assertEquals(EXPECTED_DEFAULT_VERSION, log.getVersion());
+ log = new HarLog(" ", null, null, null, null, null, null);
+ assertEquals(EXPECTED_DEFAULT_VERSION, log.version());
}
@Test
void testPages() {
HarLog log = new HarLog();
- assertEquals(EXPECTED_PAGES_LIST, log.getPages());
+ assertEquals(EXPECTED_PAGES_LIST, log.pages());
- log.setPages(null);
- assertEquals(EXPECTED_PAGES_LIST, log.getPages());
+ log = new HarLog("1.2", null, null, null, null, null, null);
+ assertEquals(EXPECTED_PAGES_LIST, log.pages());
}
@Test
void testEntries() {
HarLog log = new HarLog();
- assertEquals(EXPECTED_ENTRIES_LIST, log.getEntries());
+ assertEquals(EXPECTED_ENTRIES_LIST, log.entries());
- log.setEntries(null);
- assertEquals(EXPECTED_ENTRIES_LIST, log.getEntries());
+ log = new HarLog("1.2", null, null, null, null, null, null);
+ assertEquals(EXPECTED_ENTRIES_LIST, log.entries());
}
@Test
void testCreatorNull() {
HarLog log = new HarLog();
- log.setCreator(null);
- assertNotNull(log.getCreator());
+ assertNotNull(log.creator());
}
@Test
void testBrowserNull() {
HarLog log = new HarLog();
- log.setBrowser(null);
- assertNull(log.getBrowser());
+ assertNull(log.browser());
}
@Override
+ @Test
void testMapping() {
HarLog log = map("{\"creator\": {}, \"browser\": {}, \"comment\": \"My comment\",\"_unknown\":\"unknown\"}", HarLog.class);
- assertEquals(EXPECTED_DEFAULT_VERSION, log.getVersion());
- assertNotNull(log.getCreator());
- assertNotNull(log.getBrowser());
- assertEquals(EXPECTED_PAGES_LIST, log.getPages());
- assertEquals(EXPECTED_ENTRIES_LIST, log.getEntries());
- assertEquals("My comment", log.getComment());
+ assertEquals(EXPECTED_DEFAULT_VERSION, log.version());
+ assertNotNull(log.creator());
+ assertNotNull(log.browser());
+ assertEquals(EXPECTED_PAGES_LIST, log.pages());
+ assertEquals(EXPECTED_ENTRIES_LIST, log.entries());
+ assertEquals("My comment", log.comment());
- assertNotNull(log.getAdditional());
- assertEquals("unknown", log.getAdditional().get("_unknown"));
+ assertNotNull(log.additional());
+ assertEquals("unknown", log.additional().get("_unknown"));
log = map(UNKNOWN_PROPERTY, HarLog.class);
assertNotNull(log);
}
+ @Test
+ void testNullability() {
+ testNullability(new HarLog());
+ }
+
@Test
void equalsContract() {
EqualsVerifier.simple().forClass(HarLog.class).verify();
diff --git a/src/test/java/de/sstoehr/harreader/model/HarPageTest.java b/src/test/java/de/sstoehr/harreader/model/HarPageTest.java
index b03172d..746d181 100644
--- a/src/test/java/de/sstoehr/harreader/model/HarPageTest.java
+++ b/src/test/java/de/sstoehr/harreader/model/HarPageTest.java
@@ -5,28 +5,29 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
-import java.util.Date;
+import java.time.Instant;
+import java.time.ZoneId;
+import java.time.ZonedDateTime;
import org.junit.jupiter.api.Test;
class HarPageTest extends AbstractMapperTest {
- private final static Date EXPECTED_STARTED = new Date() {{
- setTime(1388577600000L);
- }};
+ private final static ZonedDateTime EXPECTED_STARTED = ZonedDateTime.ofInstant(Instant.ofEpochMilli(1388577600000L), ZoneId.of("Z"));
@Override
+ @Test
void testMapping() {
- HarPage page = map("{\"startedDateTime\":\"2014-01-01T12:00:00\",\"id\":\"anId\","
+ HarPage page = map("{\"startedDateTime\":\"2014-01-01T12:00:00Z\",\"id\":\"anId\","
+ "\"title\":\"aTitle\",\"pageTimings\":{},\"comment\":\"my comment\", \"_add\": \"additional info\"}", HarPage.class);
assertNotNull(page);
- assertEquals(EXPECTED_STARTED, page.getStartedDateTime());
- assertEquals("anId", page.getId());
- assertEquals("aTitle", page.getTitle());
- assertNotNull(page.getPageTimings());
- assertEquals("my comment", page.getComment());
- assertEquals("additional info", page.getAdditional().get("_add"));
+ assertEquals(EXPECTED_STARTED, page.startedDateTime());
+ assertEquals("anId", page.id());
+ assertEquals("aTitle", page.title());
+ assertNotNull(page.pageTimings());
+ assertEquals("my comment", page.comment());
+ assertEquals("additional info", page.additional().get("_add"));
page = map(UNKNOWN_PROPERTY, HarPage.class);
assertNotNull(page);
@@ -35,8 +36,12 @@ void testMapping() {
@Test
void testPageTimingsNull() {
HarPage page = new HarPage();
- page.setPageTimings(null);
- assertNotNull(page.getPageTimings());
+ assertNotNull(page.pageTimings());
+ }
+
+ @Test
+ void testNullability() {
+ testNullability(new HarPage());
}
@Test
diff --git a/src/test/java/de/sstoehr/harreader/model/HarPageTimingTest.java b/src/test/java/de/sstoehr/harreader/model/HarPageTimingTest.java
index 11b3b54..abef1ef 100644
--- a/src/test/java/de/sstoehr/harreader/model/HarPageTimingTest.java
+++ b/src/test/java/de/sstoehr/harreader/model/HarPageTimingTest.java
@@ -14,42 +14,42 @@ class HarPageTimingTest extends AbstractMapperTest {
@Test
void testOnContentLoad() {
HarPageTiming pageTiming = new HarPageTiming();
- assertEquals(EXPECTED_DEFAULT_DURATION, pageTiming.getOnContentLoad());
+ assertEquals(EXPECTED_DEFAULT_DURATION, pageTiming.onContentLoad());
- pageTiming.setOnContentLoad(1234);
- assertEquals(1234, (int) pageTiming.getOnContentLoad());
-
- pageTiming.setOnContentLoad(null);
- assertEquals(EXPECTED_DEFAULT_DURATION, pageTiming.getOnContentLoad());
+ pageTiming = new HarPageTiming(1234, null, null, null);
+ assertEquals(1234, (int) pageTiming.onContentLoad());
}
@Test
void testOnLoad() {
HarPageTiming pageTiming = new HarPageTiming();
- assertEquals(EXPECTED_DEFAULT_DURATION, pageTiming.getOnLoad());
-
- pageTiming.setOnLoad(1234);
- assertEquals(1234, (int) pageTiming.getOnLoad());
+ assertEquals(EXPECTED_DEFAULT_DURATION, pageTiming.onLoad());
- pageTiming.setOnLoad(null);
- assertEquals(EXPECTED_DEFAULT_DURATION, pageTiming.getOnLoad());
+ pageTiming = new HarPageTiming(null, 1234, null, null);
+ assertEquals(1234, (int) pageTiming.onLoad());
}
@Override
+ @Test
void testMapping() {
HarPageTiming pageTiming = map("{\"onContentLoad\": 1234, \"onLoad\": 5678, \"comment\": \"My comment\",\"_unknown\":\"unknown\"}", HarPageTiming.class);
- assertEquals(1234, (int) pageTiming.getOnContentLoad());
- assertEquals(5678, (int) pageTiming.getOnLoad());
- assertEquals("My comment", pageTiming.getComment());
+ assertEquals(1234, (int) pageTiming.onContentLoad());
+ assertEquals(5678, (int) pageTiming.onLoad());
+ assertEquals("My comment", pageTiming.comment());
- assertNotNull(pageTiming.getAdditional());
- assertEquals("unknown", pageTiming.getAdditional().get("_unknown"));
+ assertNotNull(pageTiming.additional());
+ assertEquals("unknown", pageTiming.additional().get("_unknown"));
pageTiming = map(UNKNOWN_PROPERTY, HarPageTiming.class);
assertNotNull(pageTiming);
}
+ @Test
+ void testNullability() {
+ testNullability(new HarPageTiming());
+ }
+
@Test
void equalsContract() {
EqualsVerifier.simple().forClass(HarPageTiming.class).verify();
diff --git a/src/test/java/de/sstoehr/harreader/model/HarPostDataParamTest.java b/src/test/java/de/sstoehr/harreader/model/HarPostDataParamTest.java
index 6789938..f52ca43 100644
--- a/src/test/java/de/sstoehr/harreader/model/HarPostDataParamTest.java
+++ b/src/test/java/de/sstoehr/harreader/model/HarPostDataParamTest.java
@@ -10,22 +10,28 @@
class HarPostDataParamTest extends AbstractMapperTest {
@Override
+ @Test
void testMapping() {
HarPostDataParam postDataParam = map("{\"name\": \"aName\", \"value\": \"aValue\", \"fileName\": \"aFilename\", \"contentType\": \"aContentType\", \"comment\": \"My comment\",\"_unknown\":\"unknown\"}", HarPostDataParam.class);
- assertEquals("aName", postDataParam.getName());
- assertEquals("aValue", postDataParam.getValue());
- assertEquals("aFilename", postDataParam.getFileName());
- assertEquals("aContentType", postDataParam.getContentType());
- assertEquals("My comment", postDataParam.getComment());
+ assertEquals("aName", postDataParam.name());
+ assertEquals("aValue", postDataParam.value());
+ assertEquals("aFilename", postDataParam.fileName());
+ assertEquals("aContentType", postDataParam.contentType());
+ assertEquals("My comment", postDataParam.comment());
- assertNotNull(postDataParam.getAdditional());
- assertEquals("unknown", postDataParam.getAdditional().get("_unknown"));
+ assertNotNull(postDataParam.additional());
+ assertEquals("unknown", postDataParam.additional().get("_unknown"));
postDataParam = map(UNKNOWN_PROPERTY, HarPostDataParam.class);
assertNotNull(postDataParam);
}
+ @Test
+ void testNullability() {
+ testNullability(new HarPostDataParam());
+ }
+
@Test
void equalsContract() {
EqualsVerifier.simple().forClass(HarPostDataParam.class).verify();
diff --git a/src/test/java/de/sstoehr/harreader/model/HarPostDataTest.java b/src/test/java/de/sstoehr/harreader/model/HarPostDataTest.java
index 8198b0e..cb99ef6 100644
--- a/src/test/java/de/sstoehr/harreader/model/HarPostDataTest.java
+++ b/src/test/java/de/sstoehr/harreader/model/HarPostDataTest.java
@@ -18,13 +18,13 @@ public class HarPostDataTest extends AbstractMapperTest {
public void testMapping() {
HarPostData postData = map("{\"mimeType\": \"aMimeType\", \"params\": [], \"text\":\"aText\", \"comment\": \"My comment\",\"_unknown\":\"unknown\"}", HarPostData.class);
- assertEquals("aMimeType", postData.getMimeType());
- assertEquals(EXPECTED_LIST, postData.getParams());
- assertEquals("aText", postData.getText());
- assertEquals("My comment", postData.getComment());
+ assertEquals("aMimeType", postData.mimeType());
+ assertEquals(EXPECTED_LIST, postData.params());
+ assertEquals("aText", postData.text());
+ assertEquals("My comment", postData.comment());
- assertNotNull(postData.getAdditional());
- assertEquals("unknown", postData.getAdditional().get("_unknown"));
+ assertNotNull(postData.additional());
+ assertEquals("unknown", postData.additional().get("_unknown"));
postData = map(UNKNOWN_PROPERTY, HarPostData.class);
assertNotNull(postData);
@@ -33,8 +33,12 @@ public void testMapping() {
@Test
public void testParams() {
HarPostData postData = new HarPostData();
- postData.setParams(null);
- assertNotNull(postData.getParams());
+ assertNotNull(postData.params());
+ }
+
+ @Test
+ void testNullability() {
+ testNullability(new HarPostData());
}
@Test
diff --git a/src/test/java/de/sstoehr/harreader/model/HarQueryParamTest.java b/src/test/java/de/sstoehr/harreader/model/HarQueryParamTest.java
index 55fc292..332bd82 100644
--- a/src/test/java/de/sstoehr/harreader/model/HarQueryParamTest.java
+++ b/src/test/java/de/sstoehr/harreader/model/HarQueryParamTest.java
@@ -10,15 +10,21 @@
class HarQueryParamTest extends AbstractMapperTest {
@Override
+ @Test
void testMapping() {
HarQueryParam queryParam = map("{\"name\": \"aName\", \"value\":\"aValue\", \"comment\": \"My comment\",\"_unknown\":\"unknown\"}", HarQueryParam.class);
- assertEquals("aName", queryParam.getName());
- assertEquals("aValue", queryParam.getValue());
- assertEquals("My comment", queryParam.getComment());
+ assertEquals("aName", queryParam.name());
+ assertEquals("aValue", queryParam.value());
+ assertEquals("My comment", queryParam.comment());
+
+ assertNotNull(queryParam.additional());
+ assertEquals("unknown", queryParam.additional().get("_unknown"));
+ }
- assertNotNull(queryParam.getAdditional());
- assertEquals("unknown", queryParam.getAdditional().get("_unknown"));
+ @Test
+ void testNullability() {
+ testNullability(new HarQueryParam());
}
@Test
diff --git a/src/test/java/de/sstoehr/harreader/model/HarRequestTest.java b/src/test/java/de/sstoehr/harreader/model/HarRequestTest.java
index befc6b3..27968ac 100644
--- a/src/test/java/de/sstoehr/harreader/model/HarRequestTest.java
+++ b/src/test/java/de/sstoehr/harreader/model/HarRequestTest.java
@@ -1,15 +1,15 @@
package de.sstoehr.harreader.model;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-
import org.junit.jupiter.api.Test;
import nl.jqno.equalsverifier.EqualsVerifier;
+import static org.junit.jupiter.api.Assertions.*;
+
class HarRequestTest extends AbstractMapperTest {
@Override
+ @Test
void testMapping() {
HarRequest request = map("{\"method\": \"GET\",\"url\": "
+ "\"http://www.sebastianstoehr.de/\",\"httpVersion\": "
@@ -18,76 +18,83 @@ void testMapping() {
+ "\"_add\": \"additional info\"}", HarRequest.class);
assertNotNull(request);
- assertEquals(HttpMethod.GET, request.getMethod());
- assertEquals("GET", request.getRawMethod());
- assertEquals("http://www.sebastianstoehr.de/", request.getUrl());
- assertEquals("HTTP/1.1", request.getHttpVersion());
- assertNotNull(request.getCookies());
- assertNotNull(request.getHeaders());
- assertNotNull(request.getQueryString());
- assertNotNull(request.getPostData());
- assertEquals(676L, (long) request.getHeadersSize());
- assertEquals(-1L, (long) request.getBodySize());
- assertEquals("my comment", request.getComment());
- assertEquals("additional info", request.getAdditional().get("_add"));
+ assertEquals(HttpMethod.GET, request.httpMethod());
+ assertEquals("GET", request.method());
+ assertEquals("http://www.sebastianstoehr.de/", request.url());
+ assertEquals("HTTP/1.1", request.httpVersion());
+ assertNotNull(request.cookies());
+ assertNotNull(request.headers());
+ assertNotNull(request.queryString());
+ assertNotNull(request.postData());
+ assertEquals(676L, (long) request.headersSize());
+ assertEquals(-1L, (long) request.bodySize());
+ assertEquals("my comment", request.comment());
+ assertEquals("additional info", request.additional().get("_add"));
}
@Test
void testCookies() {
HarRequest request = new HarRequest();
- request.setCookies(null);
- assertNotNull(request.getCookies());
+ assertNotNull(request.cookies());
}
@Test
void testHeaders() {
HarRequest request = new HarRequest();
- request.setHeaders(null);
- assertNotNull(request.getHeaders());
+ assertNotNull(request.headers());
}
@Test
void testQueryString() {
HarRequest request = new HarRequest();
- request.setQueryString(null);
- assertNotNull(request.getQueryString());
+ assertNotNull(request.queryString());
}
@Test
void testPostData() {
HarRequest request = new HarRequest();
- request.setPostData(null);
- assertNotNull(request.getPostData());
+ assertNotNull(request.postData());
}
@Test
void testHeadersSize() {
HarRequest request = new HarRequest();
- request.setHeadersSize(null);
- assertEquals(-1L, (long) request.getHeadersSize());
+ assertEquals(-1L, (long) request.headersSize());
}
@Test
void testBodySize() {
HarRequest request = new HarRequest();
- request.setBodySize(null);
- assertEquals(-1L, (long) request.getBodySize());
+ assertEquals(-1L, (long) request.bodySize());
}
@Test
void testUnknownMethod() {
- HarRequest request = new HarRequest();
- request.setMethod(HttpMethod.POST);
- assertEquals("POST", request.getRawMethod());
- assertEquals(HttpMethod.POST, request.getMethod());
+ HarRequest request = new HarRequest("POST", null, null, null, null, null, null, null,
+ null, null, null);
+ assertEquals("POST", request.method());
+ assertEquals(HttpMethod.POST, request.httpMethod());
}
@Test
void testUnknownMethodRaw() {
- HarRequest request = new HarRequest();
- request.setRawMethod("NOT_PART_OF_ENUM");
- assertEquals("NOT_PART_OF_ENUM", request.getRawMethod());
- assertEquals(HttpMethod.UNKNOWN, request.getMethod());
+ HarRequest request = new HarRequest("NOT_PART_OF_ENUM", null, null, null, null, null, null, null,
+ null, null, null);
+ assertEquals("NOT_PART_OF_ENUM", request.method());
+ assertEquals(HttpMethod.UNKNOWN, request.httpMethod());
+ }
+
+ @Test
+ void testNullMethodRaw() {
+ HarRequest request = new HarRequest(null, null, null, null, null, null, null, null,
+ null, null, null);
+ assertNull(request.method());
+ assertEquals(HttpMethod.UNKNOWN, request.httpMethod());
+ }
+
+ @Test
+ void testNullability() {
+ testNullability(new HarRequest());
}
@Test
diff --git a/src/test/java/de/sstoehr/harreader/model/HarResponseTest.java b/src/test/java/de/sstoehr/harreader/model/HarResponseTest.java
index 3908781..2128df7 100644
--- a/src/test/java/de/sstoehr/harreader/model/HarResponseTest.java
+++ b/src/test/java/de/sstoehr/harreader/model/HarResponseTest.java
@@ -10,83 +10,82 @@
class HarResponseTest extends AbstractMapperTest {
@Override
+ @Test
void testMapping() {
HarResponse response = map("{\"status\": 200,\"statusText\": \"OK\",\"httpVersion\": \"HTTP/1.1\","
+ "\"cookies\": [],\"headers\": [],\"content\": {},\"redirectURL\": \"redirectUrl\",\"headersSize\": 318,"
+ "\"bodySize\": 16997,\"comment\": \"My comment\", \"_add\": \"additional info\"}", HarResponse.class);
assertNotNull(response);
- assertEquals(200, response.getStatus());
- assertEquals("OK", response.getStatusText());
- assertEquals("HTTP/1.1", response.getHttpVersion());
- assertNotNull(response.getCookies());
- assertNotNull(response.getHeaders());
- assertNotNull(response.getContent());
- assertEquals("redirectUrl", response.getRedirectURL());
- assertEquals(318L, (long) response.getHeadersSize());
- assertEquals(16997L, (long) response.getBodySize());
- assertEquals("My comment", response.getComment());
- assertEquals("additional info", response.getAdditional().get("_add"));
+ assertEquals(200, response.status());
+ assertEquals("OK", response.statusText());
+ assertEquals("HTTP/1.1", response.httpVersion());
+ assertNotNull(response.cookies());
+ assertNotNull(response.headers());
+ assertNotNull(response.content());
+ assertEquals("redirectUrl", response.redirectURL());
+ assertEquals(318L, (long) response.headersSize());
+ assertEquals(16997L, (long) response.bodySize());
+ assertEquals("My comment", response.comment());
+ assertEquals("additional info", response.additional().get("_add"));
}
@Test
void testStatus() {
HarResponse response = new HarResponse();
- assertEquals(0, response.getStatus());
- assertEquals(0, response.getRawStatus());
+ assertEquals(0, response.status());
+ assertEquals(HttpStatus.UNKNOWN_HTTP_STATUS, response.httpStatus());
}
@Test
- void testUnknownStatus() {
- HarResponse response = new HarResponse();
- response.setStatus(600);
+ void testKnownStatus() {
+ HarResponse response = new HarResponse(404, null, null, null, null, null, null, null, null, null, null);
- assertEquals(0, response.getStatus()); // old behaviour, falling back to UNKNOWN_STATUS_CODE
- assertEquals(600, response.getRawStatus());
+ assertEquals(404, response.status());
+ assertEquals(HttpStatus.NOT_FOUND, response.httpStatus());
}
@Test
- void testUnknownStatusRaw() {
- HarResponse response = new HarResponse();
- response.setRawStatus(600);
+ void testUnknownStatus() {
+ HarResponse response = new HarResponse(600, null, null, null, null, null, null, null, null, null, null);
- assertEquals(0, response.getStatus()); // old behaviour, falling back to UNKNOWN_STATUS_CODE
- assertEquals(600, response.getRawStatus());
+ assertEquals(600, response.status());
+ assertEquals(HttpStatus.UNKNOWN_HTTP_STATUS, response.httpStatus());
}
@Test
void testCookies() {
HarResponse response = new HarResponse();
- response.setCookies(null);
- assertNotNull(response.getCookies());
+ assertNotNull(response.cookies());
}
@Test
void testHeaders() {
HarResponse response = new HarResponse();
- response.setHeaders(null);
- assertNotNull(response.getHeaders());
+ assertNotNull(response.headers());
}
@Test
void testContent() {
HarResponse response = new HarResponse();
- response.setContent(null);
- assertNotNull(response.getContent());
+ assertNotNull(response.content());
}
@Test
void testHeadersSize() {
HarResponse response = new HarResponse();
- response.setHeadersSize(null);
- assertEquals(-1L, (long) response.getHeadersSize());
+ assertEquals(-1L, (long) response.headersSize());
}
@Test
void testBodySize() {
HarResponse response = new HarResponse();
- response.setBodySize(null);
- assertEquals(-1L, (long) response.getBodySize());
+ assertEquals(-1L, (long) response.bodySize());
+ }
+
+ @Test
+ void testNullability() {
+ testNullability(new HarResponse());
}
@Test
diff --git a/src/test/java/de/sstoehr/harreader/model/HarTest.java b/src/test/java/de/sstoehr/harreader/model/HarTest.java
index d2cbe5d..28b20e3 100644
--- a/src/test/java/de/sstoehr/harreader/model/HarTest.java
+++ b/src/test/java/de/sstoehr/harreader/model/HarTest.java
@@ -6,19 +6,19 @@
import nl.jqno.equalsverifier.EqualsVerifier;
-class HarTest extends AbstractMapperTest{
+class HarTest extends AbstractMapperTest {
@Test
void testLogNull() {
- Har har = new Har();
- har.setLog(null);
- assertNotNull(har.getLog());
+ Har har = new Har(null);
+ assertNotNull(har.log());
}
@Override
+ @Test
void testMapping() {
Har har = map("{\"log\": {}}", Har.class);
- assertNotNull(har.getLog());
+ assertNotNull(har.log());
har = map(UNKNOWN_PROPERTY, Har.class);
assertNotNull(har);
diff --git a/src/test/java/de/sstoehr/harreader/model/HarTimingTest.java b/src/test/java/de/sstoehr/harreader/model/HarTimingTest.java
index c88f55e..4b07fdb 100644
--- a/src/test/java/de/sstoehr/harreader/model/HarTimingTest.java
+++ b/src/test/java/de/sstoehr/harreader/model/HarTimingTest.java
@@ -1,59 +1,78 @@
package de.sstoehr.harreader.model;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-
import org.junit.jupiter.api.Test;
import nl.jqno.equalsverifier.EqualsVerifier;
+import static org.junit.jupiter.api.Assertions.*;
+
class HarTimingTest extends AbstractMapperTest {
@Override
+ @Test
void testMapping() {
HarTiming timing = map("{\"blocked\": 3804,\"dns\": 23,\"connect\": 5,\"send\": 9,\"wait\": 5209,"
+ "\"receive\": 79, \"ssl\": 123, \"comment\": \"my comment\",\"_unknown\":\"unknown\"}", HarTiming.class);
assertNotNull(timing);
- assertEquals(3804, (int) timing.getBlocked());
- assertEquals(23, (int) timing.getDns());
- assertEquals(5, (int) timing.getConnect());
- assertEquals(9, (int) timing.getSend());
- assertEquals(5209, (int) timing.getWait());
- assertEquals(79, (int) timing.getReceive());
- assertEquals(123, (int) timing.getSsl());
- assertEquals("my comment", timing.getComment());
+ assertEquals(3804, (int) timing.blocked());
+ assertEquals(23, (int) timing.dns());
+ assertEquals(5, (int) timing.connect());
+ assertEquals(9, (int) timing.send());
+ assertEquals(5209, (int) timing.waitTime());
+ assertEquals(79, (int) timing.receive());
+ assertEquals(123, (int) timing.ssl());
+ assertEquals("my comment", timing.comment());
- assertNotNull(timing.getAdditional());
- assertEquals("unknown", timing.getAdditional().get("_unknown"));
+ assertNotNull(timing.additional());
+ assertEquals("unknown", timing.additional().get("_unknown"));
}
@Test
void testBlocked() {
HarTiming timing = new HarTiming();
- timing.setBlocked(null);
- assertEquals(-1, (int) timing.getBlocked());
+ assertEquals(-1, (int) timing.blocked());
}
@Test
void testDns() {
HarTiming timing = new HarTiming();
- timing.setDns(null);
- assertEquals(-1, (int) timing.getDns());
+ assertEquals(-1, (int) timing.dns());
}
@Test
void testConnect() {
HarTiming timing = new HarTiming();
- timing.setConnect(null);
- assertEquals(-1, (int) timing.getConnect());
+ assertEquals(-1, (int) timing.connect());
}
@Test
void testSsl() {
HarTiming timing = new HarTiming();
- timing.setSsl(null);
- assertEquals(-1, (int) timing.getSsl());
+ assertEquals(-1, (int) timing.ssl());
+ }
+
+ @Test
+ void testSend() {
+ HarTiming timing = new HarTiming();
+ assertNull(timing.send());
+ }
+
+ @Test
+ void testWait() {
+ HarTiming timing = new HarTiming();
+ assertNull(timing.waitTime());
+ }
+
+ @Test
+ void testReceive() {
+ HarTiming timing = new HarTiming();
+ assertNull(timing.receive());
+ }
+
+ @Test
+ void testNullability() {
+ testNullability(new HarTiming());
}
@Test