diff --git a/pom.xml b/pom.xml
index c8d09ff41..03615141d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -101,6 +101,7 @@
1.11.0
7.4
+ 3.15.3
@@ -168,6 +169,13 @@
tomcat-embed-el
provided
+
+
+ nl.jqno.equalsverifier
+ equalsverifier
+ ${equalsverifier.version}
+ test
+
diff --git a/powerauth-java-server/pom.xml b/powerauth-java-server/pom.xml
index ab9bf262b..566f0f53c 100644
--- a/powerauth-java-server/pom.xml
+++ b/powerauth-java-server/pom.xml
@@ -166,6 +166,11 @@
h2
test
+
+
+ nl.jqno.equalsverifier
+ equalsverifier
+
diff --git a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/entity/ActivationHistoryEntity.java b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/entity/ActivationHistoryEntity.java
index 618567dae..8afc5a091 100644
--- a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/entity/ActivationHistoryEntity.java
+++ b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/entity/ActivationHistoryEntity.java
@@ -202,22 +202,27 @@ public void setActivationName(final String activationName) {
}
@Override
- public int hashCode() {
- return Objects.hash(id);
- }
-
- @Override
- public boolean equals(Object obj) {
- if (null == obj) {
+ public boolean equals(final Object o) {
+ if (null == o) {
return false;
- } else if (this == obj) {
+ } else if (this == o) {
return true;
- } else if (!this.getClass().equals(ProxyUtils.getUserClass(obj))) {
+ } else if (!this.getClass().equals(ProxyUtils.getUserClass(o))) {
return false;
} else {
- final ActivationHistoryEntity that = (ActivationHistoryEntity) obj;
- return null != this.getId() && this.getId().equals(that.getId());
+ final ActivationHistoryEntity that = (ActivationHistoryEntity) o;
+ return Objects.equals(getActivationId(), that.getActivationId()) && Objects.equals(getTimestampCreated(), that.getTimestampCreated());
}
}
+ @Override
+ public int hashCode() {
+ return Objects.hash(getActivationId(), timestampCreated);
+ }
+
+ // TODO (racansky, 2023-11-08) remove when activation equals and hashCode implemented correctly
+ private String getActivationId() {
+ return getActivation() == null ? null : getActivation().getActivationId();
+ }
+
}
diff --git a/powerauth-java-server/src/test/java/io/getlime/security/powerauth/app/server/database/model/entity/ActivationHistoryEntityTest.java b/powerauth-java-server/src/test/java/io/getlime/security/powerauth/app/server/database/model/entity/ActivationHistoryEntityTest.java
new file mode 100644
index 000000000..1c5c97f29
--- /dev/null
+++ b/powerauth-java-server/src/test/java/io/getlime/security/powerauth/app/server/database/model/entity/ActivationHistoryEntityTest.java
@@ -0,0 +1,62 @@
+/*
+ * PowerAuth Server and related software components
+ * Copyright (C) 2023 Wultra s.r.o.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published
+ * by the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+package io.getlime.security.powerauth.app.server.database.model.entity;
+
+import lombok.extern.slf4j.Slf4j;
+import nl.jqno.equalsverifier.EqualsVerifier;
+import nl.jqno.equalsverifier.Warning;
+import org.junit.jupiter.api.Test;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * Test for {@link ActivationHistoryEntity}.
+ *
+ * @author Lubos Racansky, lubos.racansky@wultra.com
+ */
+@Slf4j
+class ActivationHistoryEntityTest {
+
+ @Test
+ void testEqualsContract() {
+ final ApplicationEntity application1 = new ApplicationEntity();
+ application1.setId("app1");
+ final ApplicationEntity application2 = new ApplicationEntity();
+ application2.setId("app2");
+
+ final ApplicationVersionEntity applicationVersion1 = new ApplicationVersionEntity();
+ applicationVersion1.setId("v1");
+ final ApplicationVersionEntity applicationVersion2 = new ApplicationVersionEntity();
+ applicationVersion2.setId("v2");
+
+ final ActivationHistoryEntity activationHistory1 = new ActivationHistoryEntity();
+ activationHistory1.setTimestampCreated(new Date(1));
+ final ActivationHistoryEntity activationHistory2 = new ActivationHistoryEntity();
+ activationHistory2.setTimestampCreated(new Date(2));
+
+ EqualsVerifier.forClass(ActivationHistoryEntity.class)
+ .withOnlyTheseFields("activation", "timestampCreated")
+ // TODO (racansky, 2023-11-09) equals and hashCode is using getActivation().getActivationId() but still getting false positive; https://jqno.nl/equalsverifier/manual/jpa-entities/
+ .suppress(Warning.JPA_GETTER)
+ .withPrefabValues(ApplicationEntity.class, application1, application2)
+ .withPrefabValues(ApplicationVersionEntity.class, applicationVersion1, applicationVersion2)
+ .withPrefabValues(List.class, List.of(activationHistory1), List.of(activationHistory2))
+ .verify();
+ }
+}