From 591cdab94f77ab3c5e921f7f74608f8b99257b9e Mon Sep 17 00:00:00 2001 From: David T Webb Date: Tue, 11 Feb 2014 17:25:57 -0500 Subject: [PATCH] DATACASS-85 - WIP Fixed integration test to comply with new EntityMetadataVerifier. --- .../composites/NotificationPK.java | 36 +++++++++++++++++-- .../test/integration/composites/PostPK.java | 34 +++++++++++++++++- .../integration/composites/TimelinePK.java | 34 +++++++++++++++++- ...raCompositePrimaryKeyIntegrationTests.java | 35 +++++++++++++++++- 4 files changed, 134 insertions(+), 5 deletions(-) diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/NotificationPK.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/NotificationPK.java index be92429b7..b45498558 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/NotificationPK.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/NotificationPK.java @@ -15,12 +15,13 @@ */ package org.springframework.data.cassandra.test.integration.composites; +import java.io.Serializable; import java.util.Date; import org.springframework.cassandra.core.PrimaryKeyType; +import org.springframework.data.cassandra.mapping.CassandraType; import org.springframework.data.cassandra.mapping.PrimaryKeyClass; import org.springframework.data.cassandra.mapping.PrimaryKeyColumn; -import org.springframework.data.cassandra.mapping.CassandraType; import com.datastax.driver.core.DataType; @@ -33,7 +34,7 @@ import com.datastax.driver.core.DataType; * @author Alex Shvid */ @PrimaryKeyClass -public class NotificationPK { +public class NotificationPK implements Serializable { /* * Row ID @@ -64,4 +65,35 @@ public class NotificationPK { this.time = time; } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((time == null) ? 0 : time.hashCode()); + result = prime * result + ((username == null) ? 0 : username.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + NotificationPK other = (NotificationPK) obj; + if (time == null) { + if (other.time != null) + return false; + } else if (!time.equals(other.time)) + return false; + if (username == null) { + if (other.username != null) + return false; + } else if (!username.equals(other.username)) + return false; + return true; + } + } diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/PostPK.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/PostPK.java index b353e0097..40f1d3b2e 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/PostPK.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/PostPK.java @@ -15,6 +15,7 @@ */ package org.springframework.data.cassandra.test.integration.composites; +import java.io.Serializable; import java.util.Date; import org.springframework.cassandra.core.PrimaryKeyType; @@ -32,7 +33,7 @@ import org.springframework.data.cassandra.mapping.PrimaryKeyColumn; */ @PrimaryKeyClass -public class PostPK { +public class PostPK implements Serializable { @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED) private String author; @@ -56,4 +57,35 @@ public class PostPK { this.time = time; } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((author == null) ? 0 : author.hashCode()); + result = prime * result + ((time == null) ? 0 : time.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + PostPK other = (PostPK) obj; + if (author == null) { + if (other.author != null) + return false; + } else if (!author.equals(other.author)) + return false; + if (time == null) { + if (other.time != null) + return false; + } else if (!time.equals(other.time)) + return false; + return true; + } + } diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/TimelinePK.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/TimelinePK.java index ae6e296bb..e05bfecaa 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/TimelinePK.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/TimelinePK.java @@ -15,6 +15,7 @@ */ package org.springframework.data.cassandra.test.integration.composites; +import java.io.Serializable; import java.util.Date; import org.springframework.cassandra.core.PrimaryKeyType; @@ -32,7 +33,7 @@ import org.springframework.data.cassandra.mapping.PrimaryKeyColumn; */ @PrimaryKeyClass -public class TimelinePK { +public class TimelinePK implements Serializable { /* * Row ID @@ -62,4 +63,35 @@ public class TimelinePK { this.time = time; } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((time == null) ? 0 : time.hashCode()); + result = prime * result + ((username == null) ? 0 : username.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + TimelinePK other = (TimelinePK) obj; + if (time == null) { + if (other.time != null) + return false; + } else if (!time.equals(other.time)) + return false; + if (username == null) { + if (other.username != null) + return false; + } else if (!username.equals(other.username)) + return false; + return true; + } + } diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/CassandraCompositePrimaryKeyIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/CassandraCompositePrimaryKeyIntegrationTests.java index 32ca22f1c..1d1dfe03b 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/CassandraCompositePrimaryKeyIntegrationTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/CassandraCompositePrimaryKeyIntegrationTests.java @@ -18,6 +18,7 @@ package org.springframework.data.cassandra.test.integration.mapping; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import java.io.Serializable; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Arrays; @@ -56,13 +57,45 @@ public class CassandraCompositePrimaryKeyIntegrationTests { private static final CassandraSimpleTypeHolder SIMPLE_TYPE_HOLDER = new CassandraSimpleTypeHolder(); @PrimaryKeyClass - static class Key { + static class Key implements Serializable { @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED) String z; @PrimaryKeyColumn(ordinal = 1, type = PrimaryKeyType.CLUSTERED) String a; + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((a == null) ? 0 : a.hashCode()); + result = prime * result + ((z == null) ? 0 : z.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Key other = (Key) obj; + if (a == null) { + if (other.a != null) + return false; + } else if (!a.equals(other.a)) + return false; + if (z == null) { + if (other.z != null) + return false; + } else if (!z.equals(other.z)) + return false; + return true; + } + } @Table