Upgrade to JUnit 4
Migrate existing tests to JUNit 4. Rename the model classes
TestAddress and TestPerson[2] so that they are not regarded
as test classes by the maven surefire plugin.
Change-Id: Id4dd2edaa507e89909dd97ee26628b6e8a1bdd04
Signed-off-by: Adrian Goerler <adrian.goerler@sap.com>
diff --git a/GwtOrm-AllTests.launch b/GwtOrm-AllTests.launch
index b9be32d..16cec19 100644
--- a/GwtOrm-AllTests.launch
+++ b/GwtOrm-AllTests.launch
@@ -9,7 +9,7 @@
<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value="=gwtorm"/>
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
-<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit3"/>
+<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/>
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.m2e.launchconfig.classpathProvider"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value=""/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="gwtorm"/>
diff --git a/pom.xml b/pom.xml
index e23ec21..28ae85a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -320,7 +320,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
- <version>3.8.1</version>
+ <version>4.0</version>
<scope>test</scope>
</dependency>
diff --git a/src/test/java/com/google/gwtorm/client/IntKeyTestCase.java b/src/test/java/com/google/gwtorm/client/IntKeyTestCase.java
index c0bbe25..2222500 100644
--- a/src/test/java/com/google/gwtorm/client/IntKeyTestCase.java
+++ b/src/test/java/com/google/gwtorm/client/IntKeyTestCase.java
@@ -15,11 +15,18 @@
package com.google.gwtorm.client;
import com.google.gwtorm.server.StandardKeyEncoder;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
import junit.framework.TestCase;
+import org.junit.Before;
+import org.junit.Test;
-public class IntKeyTestCase extends TestCase {
+
+public class IntKeyTestCase {
private abstract static class IntKeyImpl<T extends Key<?>> extends IntKey<T> {
@Column(id = 1)
int id;
@@ -65,22 +72,25 @@
}
}
- @Override
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
KeyUtil.setEncoderImpl(new StandardKeyEncoder());
}
+ @Test
public void testHashCodeWhenNull() {
final Parent p = new Parent(0);
assertEquals(0, p.hashCode());
}
+ @Test
public void testParentHashCode() {
final int id = 42;
final Parent p = new Parent(id);
assertEquals(id, p.hashCode());
}
+ @Test
public void testParentEquals() {
final int id = 42;
final Parent p1 = new Parent(id);
@@ -98,6 +108,7 @@
assertFalse(p1.equals(p3));
}
+ @Test
public void testChildHashCode() {
final int pId = 2;
final int cId = 8;
@@ -107,6 +118,7 @@
assertTrue(cId != c.hashCode());
}
+ @Test
public void testChildEquals() {
final int pId = 2;
final int cId = 8;
@@ -122,6 +134,7 @@
assertFalse(u.equals(c1));
}
+ @Test
public void testParentString() {
final Parent p1 = new Parent(1);
assertEquals("1", p1.toString());
@@ -131,6 +144,7 @@
assertEquals(p1, p2);
}
+ @Test
public void testChildString() {
final Child c1 = new Child(new Parent(1), 2);
assertEquals("1,2", c1.toString());
diff --git a/src/test/java/com/google/gwtorm/client/LongKeyTestCase.java b/src/test/java/com/google/gwtorm/client/LongKeyTestCase.java
index 46f04a0..be77f90 100644
--- a/src/test/java/com/google/gwtorm/client/LongKeyTestCase.java
+++ b/src/test/java/com/google/gwtorm/client/LongKeyTestCase.java
@@ -14,12 +14,18 @@
package com.google.gwtorm.client;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
import com.google.gwtorm.server.StandardKeyEncoder;
-import junit.framework.TestCase;
+import org.junit.Before;
+import org.junit.Test;
-public class LongKeyTestCase extends TestCase {
+public class LongKeyTestCase {
private abstract static class LongKeyImpl<T extends Key<?>> extends
LongKey<T> {
@Column(id = 1)
@@ -66,22 +72,25 @@
}
}
- @Override
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
KeyUtil.setEncoderImpl(new StandardKeyEncoder());
}
+ @Test
public void testHashCodeWhenNull() {
final Parent p = new Parent(0);
assertEquals(0, p.hashCode());
}
+ @Test
public void testParentHashCode() {
final long id = 21281821821821881L;
final Parent p = new Parent(id);
assertEquals((int) id, p.hashCode());
}
+ @Test
public void testParentEquals() {
final long id = 21281821821821881L;
final Parent p1 = new Parent(id);
@@ -99,6 +108,7 @@
assertFalse(p1.equals(p3));
}
+ @Test
public void testChildHashCode() {
final long pId = 21281821821821881L;
final long cId = 8;
@@ -108,6 +118,7 @@
assertTrue(cId != c.hashCode());
}
+ @Test
public void testChildEquals() {
final long pId = 21281821821821881L;
final long cId = 8;
@@ -123,6 +134,7 @@
assertFalse(u.equals(c1));
}
+ @Test
public void testParentString() {
final long pId = 21281821821821881L;
final Parent p1 = new Parent(pId);
@@ -133,6 +145,7 @@
assertEquals(p1, p2);
}
+ @Test
public void testChildString() {
final long pId = 21281821821821881L;
final long cId = 18218181281818888L;
diff --git a/src/test/java/com/google/gwtorm/client/StringKeyTestCase.java b/src/test/java/com/google/gwtorm/client/StringKeyTestCase.java
index 5922823..30d64a0 100644
--- a/src/test/java/com/google/gwtorm/client/StringKeyTestCase.java
+++ b/src/test/java/com/google/gwtorm/client/StringKeyTestCase.java
@@ -14,12 +14,18 @@
package com.google.gwtorm.client;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
import com.google.gwtorm.server.StandardKeyEncoder;
-import junit.framework.TestCase;
+import org.junit.Before;
+import org.junit.Test;
-public class StringKeyTestCase extends TestCase {
+public class StringKeyTestCase {
private abstract static class StringKeyImpl<T extends Key<?>> extends
StringKey<T> {
@Column(id = 1)
@@ -66,22 +72,25 @@
}
}
- @Override
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
KeyUtil.setEncoderImpl(new StandardKeyEncoder());
}
+ @Test
public void testHashCodeWhenNull() {
final Parent p = new Parent(null);
assertEquals(0, p.hashCode());
}
+ @Test
public void testParentHashCode() {
final String str = "foo";
final Parent p = new Parent(str);
assertEquals(str.hashCode(), p.hashCode());
}
+ @Test
public void testParentEquals() {
final String str = "foo";
final Parent p1 = new Parent(str);
@@ -99,6 +108,7 @@
assertFalse(p1.equals(p3));
}
+ @Test
public void testChildHashCode() {
final String pName = "foo";
final String cName = "bar";
@@ -108,6 +118,7 @@
assertTrue(cName.hashCode() != c.hashCode());
}
+ @Test
public void testChildEquals() {
final String pName = "foo";
final String cName = "bar";
@@ -123,6 +134,7 @@
assertFalse(u.equals(c1));
}
+ @Test
public void testParentString() {
final String pv = "foo,bar/ at %here";
final Parent p1 = new Parent(pv);
@@ -133,6 +145,7 @@
assertEquals(p1, p2);
}
+ @Test
public void testChildString() {
final String pv = "foo,bar/ at %here";
final String cv = "x";
diff --git a/src/test/java/com/google/gwtorm/data/TestAddress.java b/src/test/java/com/google/gwtorm/data/Address.java
similarity index 78%
rename from src/test/java/com/google/gwtorm/data/TestAddress.java
rename to src/test/java/com/google/gwtorm/data/Address.java
index d5e330f..a21479e 100644
--- a/src/test/java/com/google/gwtorm/data/TestAddress.java
+++ b/src/test/java/com/google/gwtorm/data/Address.java
@@ -17,19 +17,19 @@
import com.google.gwtorm.client.Column;
import com.google.gwtorm.client.StringKey;
-public class TestAddress {
- public static class Key extends StringKey<TestPerson.Key> {
+public class Address {
+ public static class Key extends StringKey<Person.Key> {
@Column(id = 1)
- protected TestPerson.Key owner;
+ protected Person.Key owner;
@Column(id = 2)
protected String name;
protected Key() {
- owner = new TestPerson.Key();
+ owner = new Person.Key();
}
- public Key(final TestPerson.Key owner, final String name) {
+ public Key(final Person.Key owner, final String name) {
this.owner = owner;
this.name = name;
}
@@ -40,7 +40,7 @@
}
@Override
- public TestPerson.Key getParentKey() {
+ public Person.Key getParentKey() {
return owner;
}
@@ -59,10 +59,10 @@
@Column(id = 3, notNull = false)
protected byte[] photo;
- protected TestAddress() {
+ protected Address() {
}
- public TestAddress(final TestAddress.Key city, final String where) {
+ public Address(final Address.Key city, final String where) {
this.city = city;
this.location = where;
}
@@ -75,7 +75,7 @@
return location;
}
- public TestAddress.Key key() {
+ public Address.Key key() {
return city;
}
}
diff --git a/src/test/java/com/google/gwtorm/data/AddressAccess.java b/src/test/java/com/google/gwtorm/data/AddressAccess.java
index 701058e..7a2b3d4 100644
--- a/src/test/java/com/google/gwtorm/data/AddressAccess.java
+++ b/src/test/java/com/google/gwtorm/data/AddressAccess.java
@@ -20,13 +20,13 @@
import com.google.gwtorm.server.Query;
import com.google.gwtorm.server.ResultSet;
-public interface AddressAccess extends Access<TestAddress, TestAddress.Key> {
+public interface AddressAccess extends Access<Address, Address.Key> {
@PrimaryKey("city")
- TestAddress byId(TestAddress.Key a) throws OrmException;
+ Address byId(Address.Key a) throws OrmException;
@Query()
- ResultSet<TestAddress> all() throws OrmException;
+ ResultSet<Address> all() throws OrmException;
@Query("WHERE city.owner = ?")
- ResultSet<TestAddress> byOwner(TestPerson.Key owner) throws OrmException;
+ ResultSet<Address> byOwner(Person.Key owner) throws OrmException;
}
diff --git a/src/test/java/com/google/gwtorm/data/TestPerson.java b/src/test/java/com/google/gwtorm/data/Person.java
similarity index 90%
rename from src/test/java/com/google/gwtorm/data/TestPerson.java
rename to src/test/java/com/google/gwtorm/data/Person.java
index bafeaf9..5839e11 100644
--- a/src/test/java/com/google/gwtorm/data/TestPerson.java
+++ b/src/test/java/com/google/gwtorm/data/Person.java
@@ -18,7 +18,7 @@
import com.google.gwtorm.client.StringKey;
-public class TestPerson {
+public class Person {
public static class Key extends StringKey<com.google.gwtorm.client.Key<?>> {
@Column(id = 1, length = 20)
protected String name;
@@ -50,10 +50,10 @@
@Column(id = 3)
protected boolean registered;
- protected TestPerson() {
+ protected Person() {
}
- public TestPerson(final Key key, final int age) {
+ public Person(final Key key, final int age) {
this.name = key;
this.age = age;
}
@@ -89,8 +89,8 @@
@Override
public boolean equals(Object other) {
- if (other instanceof TestPerson) {
- TestPerson p = (TestPerson) other;
+ if (other instanceof Person) {
+ Person p = (Person) other;
return name.equals(p.name) && age == p.age && registered == p.registered;
}
return false;
diff --git a/src/test/java/com/google/gwtorm/data/TestPerson2.java b/src/test/java/com/google/gwtorm/data/Person2.java
similarity index 92%
rename from src/test/java/com/google/gwtorm/data/TestPerson2.java
rename to src/test/java/com/google/gwtorm/data/Person2.java
index 7c780bf..ab363e7 100644
--- a/src/test/java/com/google/gwtorm/data/TestPerson2.java
+++ b/src/test/java/com/google/gwtorm/data/Person2.java
@@ -17,9 +17,9 @@
import com.google.gwtorm.client.Column;
-public class TestPerson2 {
+public class Person2 {
@Column(id = 1)
- protected TestPerson.Key name;
+ protected Person.Key name;
@Column(id = 2)
protected int age;
diff --git a/src/test/java/com/google/gwtorm/data/PersonAccess.java b/src/test/java/com/google/gwtorm/data/PersonAccess.java
index 2792c74..091af8e 100644
--- a/src/test/java/com/google/gwtorm/data/PersonAccess.java
+++ b/src/test/java/com/google/gwtorm/data/PersonAccess.java
@@ -20,29 +20,29 @@
import com.google.gwtorm.server.Query;
import com.google.gwtorm.server.ResultSet;
-public interface PersonAccess extends Access<TestPerson, TestPerson.Key> {
+public interface PersonAccess extends Access<Person, Person.Key> {
@PrimaryKey("name")
- TestPerson get(TestPerson.Key key) throws OrmException;
+ Person get(Person.Key key) throws OrmException;
@Query
- ResultSet<TestPerson> all() throws OrmException;
+ ResultSet<Person> all() throws OrmException;
@Query("WHERE age > ? ORDER BY age")
- ResultSet<TestPerson> olderThan(int age) throws OrmException;
+ ResultSet<Person> olderThan(int age) throws OrmException;
@Query("WHERE age > ? ORDER BY name DESC")
- ResultSet<TestPerson> olderThanDescByName(int age)
+ ResultSet<Person> olderThanDescByName(int age)
throws OrmException;
@Query("WHERE name = 'bob' LIMIT ?")
- ResultSet<TestPerson> firstNBob(int n) throws OrmException;
+ ResultSet<Person> firstNBob(int n) throws OrmException;
@Query("WHERE registered = false ORDER BY name")
- ResultSet<TestPerson> notRegistered() throws OrmException;
+ ResultSet<Person> notRegistered() throws OrmException;
@Query("ORDER BY age LIMIT 1")
- ResultSet<TestPerson> youngest() throws OrmException;
+ ResultSet<Person> youngest() throws OrmException;
@Query("ORDER BY age LIMIT ?")
- ResultSet<TestPerson> youngestN(int n) throws OrmException;
+ ResultSet<Person> youngestN(int n) throws OrmException;
}
diff --git a/src/test/java/com/google/gwtorm/data/PersonAccess2.java b/src/test/java/com/google/gwtorm/data/PersonAccess2.java
index 6acedce..46e12cd 100644
--- a/src/test/java/com/google/gwtorm/data/PersonAccess2.java
+++ b/src/test/java/com/google/gwtorm/data/PersonAccess2.java
@@ -18,7 +18,7 @@
import com.google.gwtorm.server.OrmException;
import com.google.gwtorm.server.PrimaryKey;
-public interface PersonAccess2 extends Access<TestPerson2, TestPerson.Key> {
+public interface PersonAccess2 extends Access<Person2, Person.Key> {
@PrimaryKey("name")
- TestPerson2 get(TestPerson.Key key) throws OrmException;
+ Person2 get(Person.Key key) throws OrmException;
}
diff --git a/src/test/java/com/google/gwtorm/nosql/IndexFunctionTest.java b/src/test/java/com/google/gwtorm/nosql/IndexFunctionTest.java
index 55eb4d1..5f9f432 100644
--- a/src/test/java/com/google/gwtorm/nosql/IndexFunctionTest.java
+++ b/src/test/java/com/google/gwtorm/nosql/IndexFunctionTest.java
@@ -14,174 +14,187 @@
package com.google.gwtorm.nosql;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import com.google.gwtorm.data.Person;
import com.google.gwtorm.data.PhoneBookDb;
-import com.google.gwtorm.data.TestPerson;
import com.google.gwtorm.schema.QueryModel;
import com.google.gwtorm.schema.RelationModel;
import com.google.gwtorm.schema.java.JavaSchemaModel;
import com.google.gwtorm.server.GeneratedClassLoader;
import com.google.gwtorm.server.OrmException;
-import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
@SuppressWarnings("unchecked")
-public class IndexFunctionTest extends TestCase {
+public class IndexFunctionTest {
private JavaSchemaModel schema;
private RelationModel people;
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() throws Exception {
schema = new JavaSchemaModel(PhoneBookDb.class);
people = schema.getRelation("people");
}
+ @Test
public void testPersonByName() throws Exception {
- IndexFunction<TestPerson> idx = index("testMyQuery", "WHERE name=?");
- assertEquals("testMyQuery", idx.getName());
+ IndexFunction<Person> idx = index("testMyQuery", "WHERE name=?");
+ Assert.assertEquals("testMyQuery", idx.getName());
IndexKeyBuilder b;
- TestPerson p;
+ Person p;
b = new IndexKeyBuilder();
- p = new TestPerson(new TestPerson.Key("bob"), 12);
+ p = new Person(new Person.Key("bob"), 12);
assertTrue(idx.includes(p));
idx.encode(b, p);
- assertEquals(new byte[] {'b', 'o', 'b'}, b);
+ assertEqualToBuilderResult(new byte[] {'b', 'o', 'b'}, b);
}
+ @Test
public void testPersonByNameAge() throws Exception {
- IndexFunction<TestPerson> idx = index("nameAge", "WHERE name=? AND age=?");
- assertEquals("nameAge", idx.getName());
+ IndexFunction<Person> idx = index("nameAge", "WHERE name=? AND age=?");
+ Assert.assertEquals("nameAge", idx.getName());
IndexKeyBuilder b;
- TestPerson p;
+ Person p;
b = new IndexKeyBuilder();
- p = new TestPerson(new TestPerson.Key("hm"), 42);
+ p = new Person(new Person.Key("hm"), 42);
assertTrue(idx.includes(p));
idx.encode(b, p);
- assertEquals(new byte[] {'h', 'm', 0x00, 0x01, 0x01, 42}, b);
+ assertEqualToBuilderResult(new byte[] {'h', 'm', 0x00, 0x01, 0x01, 42}, b);
- p = new TestPerson(new TestPerson.Key(null), 0);
+ p = new Person(new Person.Key(null), 0);
assertFalse(idx.includes(p));
b = new IndexKeyBuilder();
assertFalse(idx.includes(p));
}
+ @Test
public void testPersonByNameAge_OrderByName() throws Exception {
- IndexFunction<TestPerson> idx =
+ IndexFunction<Person> idx =
index("nameAge", "WHERE name=? AND age=? ORDER BY name");
- assertEquals("nameAge", idx.getName());
+ Assert.assertEquals("nameAge", idx.getName());
IndexKeyBuilder b;
- TestPerson p;
+ Person p;
b = new IndexKeyBuilder();
- p = new TestPerson(new TestPerson.Key("qy"), 42);
+ p = new Person(new Person.Key("qy"), 42);
assertTrue(idx.includes(p));
idx.encode(b, p);
- assertEquals(new byte[] {'q', 'y', 0x00, 0x01, 0x01, 42}, b);
+ assertEqualToBuilderResult(new byte[] {'q', 'y', 0x00, 0x01, 0x01, 42}, b);
}
+ @Test
public void testPersonByNameAge_OrderByRegistered() throws Exception {
- IndexFunction<TestPerson> idx =
+ IndexFunction<Person> idx =
index("nameAge", "WHERE name=? AND age=? ORDER BY registered");
- assertEquals("nameAge", idx.getName());
+ Assert.assertEquals("nameAge", idx.getName());
IndexKeyBuilder b;
- TestPerson p;
+ Person p;
b = new IndexKeyBuilder();
- p = new TestPerson(new TestPerson.Key("q"), 42);
+ p = new Person(new Person.Key("q"), 42);
p.register();
assertTrue(idx.includes(p));
idx.encode(b, p);
- assertEquals(new byte[] {'q', 0x00, 0x01, // name
+ assertEqualToBuilderResult(new byte[] {'q', 0x00, 0x01, // name
0x01, 42, 0x00, 0x01, // age
0x01, 0x01 // registered
}, b);
}
+ @Test
public void testPersonByNameRange_OrderByName() throws Exception {
- IndexFunction<TestPerson> idx =
+ IndexFunction<Person> idx =
index("nameSuggest", "WHERE name >= ? AND name <= ? ORDER BY name");
assertEquals("nameSuggest", idx.getName());
IndexKeyBuilder b;
- TestPerson p;
+ Person p;
b = new IndexKeyBuilder();
- p = new TestPerson(new TestPerson.Key("q"), 42);
+ p = new Person(new Person.Key("q"), 42);
assertTrue(idx.includes(p));
idx.encode(b, p);
- assertEquals(new byte[] {'q'}, b);
+ assertEqualToBuilderResult(new byte[] {'q'}, b);
}
+ @Test
public void testOnlyRegistered() throws Exception {
- IndexFunction<TestPerson> idx =
+ IndexFunction<Person> idx =
index("isregistered", "WHERE registered = true ORDER BY name");
assertEquals("isregistered", idx.getName());
IndexKeyBuilder b;
- TestPerson p;
+ Person p;
b = new IndexKeyBuilder();
- p = new TestPerson(new TestPerson.Key("q"), 42);
+ p = new Person(new Person.Key("q"), 42);
assertFalse(idx.includes(p));
p.register();
assertTrue(idx.includes(p));
idx.encode(b, p);
- assertEquals(new byte[] {'q'}, b);
+ assertEqualToBuilderResult(new byte[] {'q'}, b);
}
+ @Test
public void testOnlyAge42() throws Exception {
- IndexFunction<TestPerson> idx =
+ IndexFunction<Person> idx =
index("isOldEnough", "WHERE age = 42 ORDER BY name");
assertEquals("isOldEnough", idx.getName());
IndexKeyBuilder b;
- TestPerson p;
+ Person p;
b = new IndexKeyBuilder();
- p = new TestPerson(new TestPerson.Key("q"), 32);
+ p = new Person(new Person.Key("q"), 32);
assertFalse(idx.includes(p));
- p = new TestPerson(new TestPerson.Key("q"), 42);
+ p = new Person(new Person.Key("q"), 42);
assertTrue(idx.includes(p));
idx.encode(b, p);
- assertEquals(new byte[] {'q'}, b);
+ assertEqualToBuilderResult(new byte[] {'q'}, b);
}
+ @Test
public void testOnlyBob() throws Exception {
- IndexFunction<TestPerson> idx = index("isbob", "WHERE name.name = 'bob'");
+ IndexFunction<Person> idx = index("isbob", "WHERE name.name = 'bob'");
assertEquals("isbob", idx.getName());
IndexKeyBuilder b;
- TestPerson p;
+ Person p;
b = new IndexKeyBuilder();
- p = new TestPerson(new TestPerson.Key("q"), 42);
+ p = new Person(new Person.Key("q"), 42);
assertFalse(idx.includes(p));
- p = new TestPerson(new TestPerson.Key("bob"), 42);
+ p = new Person(new Person.Key("bob"), 42);
assertTrue(idx.includes(p));
idx.encode(b, p);
- assertEquals(new byte[] {}, b);
+ assertEqualToBuilderResult(new byte[] {}, b);
}
- private IndexFunction<TestPerson> index(String name, String query)
+ private IndexFunction<Person> index(String name, String query)
throws OrmException {
final QueryModel qm = new QueryModel(people, name, query);
- return new IndexFunctionGen(new GeneratedClassLoader(TestPerson.class
- .getClassLoader()), qm, TestPerson.class).create();
+ return new IndexFunctionGen(new GeneratedClassLoader(Person.class
+ .getClassLoader()), qm, Person.class).create();
}
- private static void assertEquals(byte[] exp, IndexKeyBuilder ic) {
+ private static void assertEqualToBuilderResult(byte[] exp, IndexKeyBuilder ic) {
assertEquals(toString(exp), toString(ic.toByteArray()));
}
diff --git a/src/test/java/com/google/gwtorm/nosql/IndexKeyBuilderTest.java b/src/test/java/com/google/gwtorm/nosql/IndexKeyBuilderTest.java
index e0f8028..e08059f 100644
--- a/src/test/java/com/google/gwtorm/nosql/IndexKeyBuilderTest.java
+++ b/src/test/java/com/google/gwtorm/nosql/IndexKeyBuilderTest.java
@@ -14,56 +14,65 @@
package com.google.gwtorm.nosql;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
-public class IndexKeyBuilderTest extends TestCase {
+import org.junit.Test;
+
+public class IndexKeyBuilderTest {
+
+ @Test
public void testInt() {
IndexKeyBuilder ib;
ib = new IndexKeyBuilder();
ib.add(0);
- assertEquals(new byte[] {0x00}, ib);
+ assertEqualToBuilderResult(new byte[] {0x00}, ib);
ib = new IndexKeyBuilder();
ib.add(1);
- assertEquals(new byte[] {0x01, 0x01}, ib);
+ assertEqualToBuilderResult(new byte[] {0x01, 0x01}, ib);
ib = new IndexKeyBuilder();
ib.add(256);
- assertEquals(new byte[] {0x02, 0x01, 0x00}, ib);
+ assertEqualToBuilderResult(new byte[] {0x02, 0x01, 0x00}, ib);
}
+ @Test
public void testDelimiter() {
IndexKeyBuilder ib = new IndexKeyBuilder();
ib.delimiter();
- assertEquals(new byte[] {0x00, 0x01}, ib);
+ assertEqualToBuilderResult(new byte[] {0x00, 0x01}, ib);
}
+ @Test
public void testStringASCII() {
IndexKeyBuilder ib = new IndexKeyBuilder();
ib.add("hi");
- assertEquals(new byte[] {'h', 'i'}, ib);
+ assertEqualToBuilderResult(new byte[] {'h', 'i'}, ib);
}
+ @Test
public void testStringNUL() {
IndexKeyBuilder ib = new IndexKeyBuilder();
ib.add("\0");
- assertEquals(new byte[] {0x00, (byte) 0xff}, ib);
+ assertEqualToBuilderResult(new byte[] {0x00, (byte) 0xff}, ib);
}
+ @Test
public void testStringFF() {
IndexKeyBuilder ib = new IndexKeyBuilder();
ib.add(new byte[] {(byte) 0xff});
- assertEquals(new byte[] {(byte) 0xff, 0x00}, ib);
+ assertEqualToBuilderResult(new byte[] {(byte) 0xff, 0x00}, ib);
}
+ @Test
public void testInfinity() {
IndexKeyBuilder ib = new IndexKeyBuilder();
ib.infinity();
- assertEquals(new byte[] {(byte) 0xff, (byte) 0xff}, ib);
+ assertEqualToBuilderResult(new byte[] {(byte) 0xff, (byte) 0xff}, ib);
}
- private static void assertEquals(byte[] exp, IndexKeyBuilder ic) {
+ private static void assertEqualToBuilderResult(byte[] exp, IndexKeyBuilder ic) {
assertEquals(toString(exp), toString(ic.toByteArray()));
}
diff --git a/src/test/java/com/google/gwtorm/nosql/NoSqlPhoneBookTest.java b/src/test/java/com/google/gwtorm/nosql/NoSqlPhoneBookTest.java
index 97f208a..71672e5 100644
--- a/src/test/java/com/google/gwtorm/nosql/NoSqlPhoneBookTest.java
+++ b/src/test/java/com/google/gwtorm/nosql/NoSqlPhoneBookTest.java
@@ -14,35 +14,40 @@
package com.google.gwtorm.nosql;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import com.google.gwtorm.data.Person;
import com.google.gwtorm.data.PersonAccess;
import com.google.gwtorm.data.PhoneBookDb;
-import com.google.gwtorm.data.TestPerson;
-import com.google.gwtorm.jdbc.JdbcExecutor;
-import com.google.gwtorm.jdbc.JdbcSchema;
import com.google.gwtorm.nosql.heap.MemoryDatabase;
import com.google.gwtorm.server.Access;
import com.google.gwtorm.server.OrmConcurrencyException;
import com.google.gwtorm.server.OrmException;
-import junit.framework.TestCase;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-public class NoSqlPhoneBookTest extends TestCase {
+public class NoSqlPhoneBookTest {
protected MemoryDatabase<PhoneBookDb> db;
private List<PhoneBookDb> openSchemas;
- @Override
+ @Before
public void setUp() throws Exception {
- super.setUp();
-
db = new MemoryDatabase<PhoneBookDb>(PhoneBookDb.class);
openSchemas = new ArrayList<PhoneBookDb>();
}
- @Override
+ @After
public void tearDown() throws Exception {
if (openSchemas != null) {
for (PhoneBookDb schema : openSchemas) {
@@ -50,7 +55,6 @@
}
openSchemas = null;
}
- super.tearDown();
}
protected PhoneBookDb open() throws OrmException {
@@ -61,10 +65,12 @@
return r;
}
+ @Test
public void testCreateDatabaseHandle() throws Exception {
assertNotNull(db);
}
+ @Test
public void testOpenSchema() throws Exception {
final PhoneBookDb schema1 = open();
assertNotNull(schema1);
@@ -74,6 +80,7 @@
assertNotSame(schema1, schema2);
}
+ @Test
public void testGetPeopleAccess() throws Exception {
final PhoneBookDb schema = open();
assertNotNull(schema.people());
@@ -81,6 +88,7 @@
assertEquals(1, schema.people().getRelationID());
}
+ @Test
public void testGetAddressAccess() throws Exception {
final PhoneBookDb schema = open();
assertNotNull(schema.addresses());
@@ -88,6 +96,7 @@
assertEquals(2, schema.addresses().getRelationID());
}
+ @Test
public void testGetAllRelations() throws Exception {
final PhoneBookDb schema = open();
Access<?, ?>[] all = schema.allRelations();
@@ -97,6 +106,7 @@
assertSame(schema.addresses(), all[1]);
}
+ @Test
public void testNextAddressId() throws Exception {
final PhoneBookDb schema = open();
final int a = schema.nextAddressId();
@@ -104,91 +114,100 @@
assertTrue(a != b);
}
+ @Test
public void testPersonPrimaryKey() throws Exception {
final PhoneBookDb schema = open();
- final TestPerson.Key key = new TestPerson.Key("Bob");
- final TestPerson bob = new TestPerson(key, 18);
+ final Person.Key key = new Person.Key("Bob");
+ final Person bob = new Person(key, 18);
assertSame(key, schema.people().primaryKey(bob));
}
+ @Test
public void testInsertOnePerson() throws Exception {
final PhoneBookDb schema = open();
- final TestPerson bob = new TestPerson(new TestPerson.Key("Bob"), 18);
+ final Person bob = new Person(new Person.Key("Bob"), 18);
schema.people().insert(Collections.singleton(bob));
- TestPerson copy = schema.people().all().toList().get(0);
+ Person copy = schema.people().all().toList().get(0);
assertNotSame(copy, bob);
assertEquals(bob.name(), copy.name());
}
+ @Test
public void testGetOnePerson() throws Exception {
final PhoneBookDb schema = open();
final PersonAccess sp = schema.people();
- final TestPerson p1 = new TestPerson(new TestPerson.Key("Bob"), 18);
+ final Person p1 = new Person(new Person.Key("Bob"), 18);
sp.insert(Collections.singleton(p1));
- final TestPerson p2 = sp.get(sp.primaryKey(p1));
+ final Person p2 = sp.get(sp.primaryKey(p1));
assertNotNull(p2);
assertNotSame(p1, p2);
assertEquals(sp.primaryKey(p1), sp.primaryKey(p2));
}
+ @Test
public void testGetAsyncOnePerson() throws Exception {
final PhoneBookDb schema = open();
final PersonAccess sp = schema.people();
- final TestPerson p1 = new TestPerson(new TestPerson.Key("Bob"), 18);
+ final Person p1 = new Person(new Person.Key("Bob"), 18);
sp.insert(Collections.singleton(p1));
- final TestPerson p2 = sp.getAsync(sp.primaryKey(p1)).get();
+ final Person p2 = sp.getAsync(sp.primaryKey(p1)).get();
assertNotNull(p2);
assertNotSame(p1, p2);
assertEquals(sp.primaryKey(p1), sp.primaryKey(p2));
}
+ @Test
public void testGetOnePersonIterator() throws Exception {
final PhoneBookDb schema = open();
final PersonAccess sp = schema.people();
- final TestPerson p1 = new TestPerson(new TestPerson.Key("Bob"), 18);
+ final Person p1 = new Person(new Person.Key("Bob"), 18);
sp.insert(Collections.singleton(p1));
- final List<TestPerson> list =
+ final List<Person> list =
sp.get(Collections.singleton(sp.primaryKey(p1))).toList();
assertNotNull(list);
assertEquals(1, list.size());
- final TestPerson p2 = list.get(0);
+ final Person p2 = list.get(0);
assertNotNull(p2);
assertNotSame(p1, p2);
assertEquals(sp.primaryKey(p1), sp.primaryKey(p2));
}
+ @Test
public void testInsertManyPeople() throws Exception {
final PhoneBookDb schema = open();
- final ArrayList<TestPerson> all = new ArrayList<TestPerson>();
- all.add(new TestPerson(new TestPerson.Key("Bob"), 18));
- all.add(new TestPerson(new TestPerson.Key("Mary"), 22));
- all.add(new TestPerson(new TestPerson.Key("Zak"), 33));
+ final ArrayList<Person> all = new ArrayList<Person>();
+ all.add(new Person(new Person.Key("Bob"), 18));
+ all.add(new Person(new Person.Key("Mary"), 22));
+ all.add(new Person(new Person.Key("Zak"), 33));
schema.people().insert(all);
}
+ @Test
public void testDeleteOnePerson() throws Exception {
final PhoneBookDb schema = open();
- final TestPerson bob = new TestPerson(new TestPerson.Key("Bob"), 18);
+ final Person bob = new Person(new Person.Key("Bob"), 18);
schema.people().insert(Collections.singleton(bob));
schema.people().delete(Collections.singleton(bob));
}
+ @Test
public void testUpdateOnePerson() throws Exception {
final PhoneBookDb schema = open();
- final TestPerson bob = new TestPerson(new TestPerson.Key("Bob"), 18);
+ final Person bob = new Person(new Person.Key("Bob"), 18);
schema.people().insert(Collections.singleton(bob));
bob.growOlder();
schema.people().update(Collections.singleton(bob));
}
+ @Test
public void testUpdateNoPerson() throws Exception {
final PhoneBookDb schema = open();
- final TestPerson bob = new TestPerson(new TestPerson.Key("Bob"), 18);
+ final Person bob = new Person(new Person.Key("Bob"), 18);
try {
schema.people().update(Collections.singleton(bob));
fail("Update of missing person succeeded");
@@ -197,12 +216,13 @@
}
}
+ @Test
public void testFetchOnePerson() throws Exception {
final PhoneBookDb schema = open();
- final TestPerson bob = new TestPerson(new TestPerson.Key("Bob"), 18);
+ final Person bob = new Person(new Person.Key("Bob"), 18);
schema.people().insert(Collections.singleton(bob));
- final List<TestPerson> all = schema.people().all().toList();
+ final List<Person> all = schema.people().all().toList();
assertNotNull(all);
assertEquals(1, all.size());
assertNotSame(bob, all.get(0));
@@ -211,13 +231,14 @@
assertEquals(bob.isRegistered(), all.get(0).isRegistered());
}
+ @Test
public void testFetchOnePersonByName() throws Exception {
final PhoneBookDb schema = open();
- final TestPerson bob1 = new TestPerson(new TestPerson.Key("Bob"), 18);
+ final Person bob1 = new Person(new Person.Key("Bob"), 18);
schema.people().insert(Collections.singleton(bob1));
- final TestPerson bob2 =
- schema.people().get(new TestPerson.Key(bob1.name()));
+ final Person bob2 =
+ schema.people().get(new Person.Key(bob1.name()));
assertNotNull(bob2);
assertNotSame(bob1, bob2);
assertEquals(bob1.name(), bob2.name());
@@ -225,23 +246,25 @@
assertEquals(bob1.isRegistered(), bob2.isRegistered());
}
+ @Test
public void testFetchByAge() throws Exception {
final PhoneBookDb schema = open();
- final ArrayList<TestPerson> all = new ArrayList<TestPerson>();
- all.add(new TestPerson(new TestPerson.Key("Bob"), 18));
- all.add(new TestPerson(new TestPerson.Key("Mary"), 22));
- all.add(new TestPerson(new TestPerson.Key("Zak"), 33));
+ final ArrayList<Person> all = new ArrayList<Person>();
+ all.add(new Person(new Person.Key("Bob"), 18));
+ all.add(new Person(new Person.Key("Mary"), 22));
+ all.add(new Person(new Person.Key("Zak"), 33));
schema.people().insert(all);
- final List<TestPerson> r = schema.people().olderThan(20).toList();
+ final List<Person> r = schema.people().olderThan(20).toList();
assertEquals(2, r.size());
assertEquals(all.get(1).name(), r.get(0).name());
assertEquals(all.get(2).name(), r.get(1).name());
}
+ @Test
public void testBooleanType() throws Exception {
final PhoneBookDb schema = open();
- final TestPerson bob = new TestPerson(new TestPerson.Key("Bob"), 18);
+ final Person bob = new Person(new Person.Key("Bob"), 18);
schema.people().insert(Collections.singleton(bob));
assertEquals(bob.isRegistered(), schema.people().all().toList().get(0)
diff --git a/src/test/java/com/google/gwtorm/protobuf/ProtobufEncoderTest.java b/src/test/java/com/google/gwtorm/protobuf/ProtobufEncoderTest.java
index f4cb241..1ac5632 100644
--- a/src/test/java/com/google/gwtorm/protobuf/ProtobufEncoderTest.java
+++ b/src/test/java/com/google/gwtorm/protobuf/ProtobufEncoderTest.java
@@ -14,13 +14,20 @@
package com.google.gwtorm.protobuf;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
import com.google.gwtorm.client.Column;
-import com.google.gwtorm.data.TestAddress;
-import com.google.gwtorm.data.TestPerson;
+import com.google.gwtorm.data.Address;
+import com.google.gwtorm.data.Person;
import com.google.protobuf.CodedInputStream;
import com.google.protobuf.CodedOutputStream;
-import junit.framework.TestCase;
+import org.junit.Test;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -32,7 +39,7 @@
import java.util.SortedSet;
import java.util.TreeSet;
-public class ProtobufEncoderTest extends TestCase {
+public class ProtobufEncoderTest {
private static final byte[] testingBin = new byte[] {
//
// name
@@ -47,12 +54,13 @@
};
@SuppressWarnings("cast")
+ @Test
public void testPerson() throws UnsupportedEncodingException {
- final ProtobufCodec<TestPerson> e = CodecFactory.encoder(TestPerson.class);
+ final ProtobufCodec<Person> e = CodecFactory.encoder(Person.class);
- TestPerson p = e.decode(testingBin);
+ Person p = e.decode(testingBin);
assertNotNull(p);
- assertTrue(p instanceof TestPerson);
+ assertTrue(p instanceof Person);
assertEquals("testing", p.name());
assertEquals(75, p.age());
assertTrue(p.isRegistered());
@@ -62,37 +70,40 @@
assertEquals(testingBin.length, e.sizeof(p));
}
+ @Test
public void testAddress() {
- final ProtobufCodec<TestAddress> e =
- CodecFactory.encoder(TestAddress.class);
- TestAddress a = e.decode(new byte[0]);
+ final ProtobufCodec<Address> e =
+ CodecFactory.encoder(Address.class);
+ Address a = e.decode(new byte[0]);
assertNotNull(a);
assertNull(a.location());
- TestPerson.Key k = new TestPerson.Key("bob");
- TestPerson p = new TestPerson(k, 42);
- TestAddress b = new TestAddress(new TestAddress.Key(k, "ny"), "ny");
+ Person.Key k = new Person.Key("bob");
+ Person p = new Person(k, 42);
+ Address b = new Address(new Address.Key(k, "ny"), "ny");
byte[] act = e.encodeToByteArray(b);
- TestAddress c = e.decode(act);
+ Address c = e.decode(act);
assertEquals(c.location(), b.location());
assertEquals(c.city(), b.city());
assertEquals(c.key(), b.key());
}
+ @Test
public void testDecodeEmptiesByteBuffer() {
- ProtobufCodec<TestPerson> e = CodecFactory.encoder(TestPerson.class);
+ ProtobufCodec<Person> e = CodecFactory.encoder(Person.class);
ByteBuffer buf = ByteBuffer.wrap(testingBin);
- TestPerson p = e.decode(buf);
+ Person p = e.decode(buf);
assertEquals(0, buf.remaining());
assertEquals(testingBin.length, buf.position());
}
+ @Test
public void testEncodeFillsByteBuffer() throws UnsupportedEncodingException {
- ProtobufCodec<TestPerson> e = CodecFactory.encoder(TestPerson.class);
+ ProtobufCodec<Person> e = CodecFactory.encoder(Person.class);
- TestPerson p = new TestPerson(new TestPerson.Key("testing"), 75);
+ Person p = new Person(new Person.Key("testing"), 75);
p.register();
int sz = e.sizeof(p);
@@ -110,11 +121,12 @@
assertEquals(asString(testingBin), asString(act));
}
+ @Test
public void testEncodeNonArrayByteBuffer()
throws UnsupportedEncodingException {
- ProtobufCodec<TestPerson> e = CodecFactory.encoder(TestPerson.class);
+ ProtobufCodec<Person> e = CodecFactory.encoder(Person.class);
- TestPerson p = new TestPerson(new TestPerson.Key("testing"), 75);
+ Person p = new Person(new Person.Key("testing"), 75);
p.register();
int sz = e.sizeof(p);
@@ -134,6 +146,7 @@
assertEquals(asString(testingBin), asString(act));
}
+ @Test
public void testStringList() throws UnsupportedEncodingException {
ProtobufCodec<StringList> e = CodecFactory.encoder(StringList.class);
@@ -153,6 +166,7 @@
}), asString(act));
}
+ @Test
public void testStringSet() throws UnsupportedEncodingException {
ProtobufCodec<StringSet> e = CodecFactory.encoder(StringSet.class);
@@ -172,20 +186,22 @@
}), asString(act));
}
+ @Test
public void testPersonList() {
ProtobufCodec<PersonList> e = CodecFactory.encoder(PersonList.class);
PersonList list = new PersonList();
- list.people = new ArrayList<TestPerson>();
- list.people.add(new TestPerson(new TestPerson.Key("larry"), 1 << 16));
- list.people.add(new TestPerson(new TestPerson.Key("curly"), 1));
- list.people.add(new TestPerson(new TestPerson.Key("moe"), -1));
+ list.people = new ArrayList<Person>();
+ list.people.add(new Person(new Person.Key("larry"), 1 << 16));
+ list.people.add(new Person(new Person.Key("curly"), 1));
+ list.people.add(new Person(new Person.Key("moe"), -1));
PersonList other = e.decode(e.encodeToByteArray(list));
assertNotNull(other.people);
assertEquals(list.people, other.people);
}
+ @Test
public void testCustomEncoderList() {
ProtobufCodec<ItemList> e = CodecFactory.encoder(ItemList.class);
@@ -199,6 +215,7 @@
assertEquals(2, other.list.size());
}
+ @Test
public void testEnumEncoder() throws UnsupportedEncodingException {
assertEquals(1, ThingWithEnum.Type.B.ordinal());
assertSame(ThingWithEnum.Type.B, ThingWithEnum.Type.values()[1]);
@@ -217,6 +234,7 @@
assertEquals(asString(exp), asString(act));
}
+ @Test
public void testEncodeToStream()throws IOException {
ProtobufCodec<ThingWithEnum> e = CodecFactory.encoder(ThingWithEnum.class);
@@ -231,8 +249,8 @@
byte[] exp2 = {0x02, 0x08, 0x01, '\n'};
ByteArrayInputStream in = new ByteArrayInputStream(exp2);
ThingWithEnum other = e.decodeWithSize(in);
- assertEquals('\n', in.read());
- assertEquals(-1, in.read());
+ assertTrue('\n' == in.read());
+ assertTrue(-1 == in.read());
assertNotNull(other.type);
assertSame(thing.type, other.type);
}
@@ -244,7 +262,7 @@
static class PersonList {
@Column(id = 5)
- public List<TestPerson> people;
+ public List<Person> people;
}
static class StringList {
diff --git a/src/test/java/com/google/gwtorm/schema/QueryParserTest.java b/src/test/java/com/google/gwtorm/schema/QueryParserTest.java
index 906f4ad..f117549 100644
--- a/src/test/java/com/google/gwtorm/schema/QueryParserTest.java
+++ b/src/test/java/com/google/gwtorm/schema/QueryParserTest.java
@@ -14,17 +14,21 @@
package com.google.gwtorm.schema;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
import com.google.gwtorm.server.OrmException;
-import junit.framework.TestCase;
-
import org.antlr.runtime.tree.Tree;
+import org.junit.Test;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collection;
-public class QueryParserTest extends TestCase {
+public class QueryParserTest {
private final class DummyColumn extends ColumnModel {
private String name;
@@ -97,10 +101,12 @@
assertEquals(QueryParser.PLACEHOLDER, c.getChild(1).getType());
}
+ @Test
public void testEmptyQuery() throws QueryParseException {
assertNull(parse(""));
}
+ @Test
public void testWhereNameEq() throws QueryParseException {
final Tree t = parse("WHERE name = ?");
assertNotNull(t);
@@ -110,6 +116,7 @@
assertGoodEQ(t.getChild(0), "name");
}
+ @Test
public void testWhereAAndBAndC() throws QueryParseException {
final Tree t = parse("WHERE a = ? AND b = ? AND c = ?");
assertNotNull(t);
@@ -124,6 +131,7 @@
assertGoodEQ(c.getChild(2), "c");
}
+ @Test
public void testOrderByA() throws QueryParseException {
final Tree t = parse("ORDER BY a");
assertNotNull(t);
@@ -138,6 +146,7 @@
assertEquals("a", a.getChild(0).getText());
}
+ @Test
public void testOrderByAB() throws QueryParseException {
final Tree t = parse("ORDER BY a DESC, b ASC");
assertNotNull(t);
@@ -161,6 +170,7 @@
}
}
+ @Test
public void testWhereAOrderByA() throws QueryParseException {
final Tree t = parse("WHERE a = ? ORDER BY a");
assertNotNull(t);
diff --git a/src/test/java/com/google/gwtorm/schema/UtilTestCase.java b/src/test/java/com/google/gwtorm/schema/UtilTestCase.java
index 8295e99..ddb928c 100644
--- a/src/test/java/com/google/gwtorm/schema/UtilTestCase.java
+++ b/src/test/java/com/google/gwtorm/schema/UtilTestCase.java
@@ -14,9 +14,12 @@
package com.google.gwtorm.schema;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
-public class UtilTestCase extends TestCase {
+import org.junit.Test;
+
+public class UtilTestCase {
+ @Test
public void testSqlFriendlyNames() {
assertEquals("a", Util.makeSqlFriendly("a"));
assertEquals("url", Util.makeSqlFriendly("url"));
diff --git a/src/test/java/com/google/gwtorm/schema/sql/DialectH2Test.java b/src/test/java/com/google/gwtorm/schema/sql/DialectH2Test.java
index 10f7a1c..aa5f847 100644
--- a/src/test/java/com/google/gwtorm/schema/sql/DialectH2Test.java
+++ b/src/test/java/com/google/gwtorm/schema/sql/DialectH2Test.java
@@ -14,10 +14,14 @@
package com.google.gwtorm.schema.sql;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
import com.google.gwtorm.data.PhoneBookDb;
import com.google.gwtorm.data.PhoneBookDb2;
-import com.google.gwtorm.data.TestAddress;
-import com.google.gwtorm.data.TestPerson;
+import com.google.gwtorm.data.Address;
+import com.google.gwtorm.data.Person;
import com.google.gwtorm.jdbc.Database;
import com.google.gwtorm.jdbc.JdbcExecutor;
import com.google.gwtorm.jdbc.JdbcSchema;
@@ -26,6 +30,10 @@
import junit.framework.TestCase;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
@@ -33,16 +41,15 @@
import java.util.Properties;
import java.util.Set;
-public class DialectH2Test extends TestCase {
+public class DialectH2Test {
private Connection db;
private JdbcExecutor executor;
private SqlDialect dialect;
private Database<PhoneBookDb> phoneBook;
private Database<PhoneBookDb2> phoneBook2;
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() throws Exception {
org.h2.Driver.load();
db = DriverManager.getConnection("jdbc:h2:mem:DialectH2Test");
executor = new JdbcExecutor(db);
@@ -57,8 +64,8 @@
new Database<PhoneBookDb2>(new SimpleDataSource(p), PhoneBookDb2.class);
}
- @Override
- protected void tearDown() {
+ @After
+ public void tearDown() {
if (executor != null) {
executor.close();
}
@@ -78,6 +85,7 @@
executor.execute(sql);
}
+ @Test
public void testListSequences() throws OrmException, SQLException {
assertTrue(dialect.listSequences(db).isEmpty());
@@ -90,7 +98,8 @@
assertFalse(s.contains("foo"));
}
- public void testListTables() throws OrmException,SQLException {
+ @Test
+ public void testListTables() throws OrmException, SQLException {
assertTrue(dialect.listTables(db).isEmpty());
execute("CREATE SEQUENCE cnt");
@@ -102,6 +111,7 @@
assertTrue(s.contains("foo"));
}
+ @Test
public void testUpgradeSchema() throws SQLException, OrmException {
final PhoneBookDb p = phoneBook.open();
try {
@@ -132,12 +142,12 @@
assertFalse(sequences.contains("cnt"));
assertFalse(tables.contains("foo"));
- final TestPerson.Key pk = new TestPerson.Key("Bob");
- final TestPerson bob = new TestPerson(pk, p.nextAddressId());
+ final Person.Key pk = new Person.Key("Bob");
+ final Person bob = new Person(pk, p.nextAddressId());
p.people().insert(Collections.singleton(bob));
- final TestAddress addr =
- new TestAddress(new TestAddress.Key(pk, "home"), "some place");
+ final Address addr =
+ new Address(new Address.Key(pk, "home"), "some place");
p.addresses().insert(Collections.singleton(addr));
} finally {
p.close();
diff --git a/src/test/java/com/google/gwtorm/schema/sql/DialectMySQLTest.java b/src/test/java/com/google/gwtorm/schema/sql/DialectMySQLTest.java
index f3d2e72..d3917f3 100644
--- a/src/test/java/com/google/gwtorm/schema/sql/DialectMySQLTest.java
+++ b/src/test/java/com/google/gwtorm/schema/sql/DialectMySQLTest.java
@@ -15,17 +15,23 @@
package com.google.gwtorm.schema.sql;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
import com.google.gwtorm.data.PhoneBookDb;
import com.google.gwtorm.data.PhoneBookDb2;
-import com.google.gwtorm.data.TestAddress;
-import com.google.gwtorm.data.TestPerson;
+import com.google.gwtorm.data.Address;
+import com.google.gwtorm.data.Person;
import com.google.gwtorm.jdbc.Database;
import com.google.gwtorm.jdbc.JdbcExecutor;
import com.google.gwtorm.jdbc.JdbcSchema;
import com.google.gwtorm.jdbc.SimpleDataSource;
import com.google.gwtorm.server.OrmException;
-import junit.framework.TestCase;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
import java.sql.Connection;
import java.sql.DriverManager;
@@ -34,16 +40,15 @@
import java.util.Properties;
import java.util.Set;
-public class DialectMySQLTest extends TestCase {
+public class DialectMySQLTest {
private Connection db;
private JdbcExecutor executor;
private SqlDialect dialect;
private Database<PhoneBookDb> phoneBook;
private Database<PhoneBookDb2> phoneBook2;
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() throws Exception {
Class.forName(com.mysql.jdbc.Driver.class.getName());
final String host = "localhost";
@@ -80,8 +85,8 @@
}
}
- @Override
- protected void tearDown() {
+ @After
+ public void tearDown() {
if (executor != null) {
executor.close();
}
@@ -101,6 +106,7 @@
executor.execute(sql);
}
+ @Test
public void testListSequences() throws OrmException, SQLException {
assertTrue(dialect.listSequences(db).isEmpty());
@@ -113,6 +119,7 @@
assertFalse(s.contains("foo"));
}
+ @Test
public void testListTables() throws OrmException, SQLException {
assertTrue(dialect.listTables(db).isEmpty());
@@ -125,6 +132,7 @@
assertTrue(s.contains("foo"));
}
+ @Test
public void testUpgradeSchema() throws SQLException, OrmException {
final PhoneBookDb p = phoneBook.open();
try {
@@ -155,12 +163,12 @@
assertFalse(sequences.contains("cnt"));
assertFalse(tables.contains("foo"));
- final TestPerson.Key pk = new TestPerson.Key("Bob");
- final TestPerson bob = new TestPerson(pk, p.nextAddressId());
+ final Person.Key pk = new Person.Key("Bob");
+ final Person bob = new Person(pk, p.nextAddressId());
p.people().insert(Collections.singleton(bob));
- final TestAddress addr =
- new TestAddress(new TestAddress.Key(pk, "home"), "some place");
+ final Address addr =
+ new Address(new Address.Key(pk, "home"), "some place");
p.addresses().insert(Collections.singleton(addr));
} finally {
p.close();
diff --git a/src/test/java/com/google/gwtorm/schema/sql/DialectPostgreSQLTest.java b/src/test/java/com/google/gwtorm/schema/sql/DialectPostgreSQLTest.java
index 043ea61..3d12e77 100644
--- a/src/test/java/com/google/gwtorm/schema/sql/DialectPostgreSQLTest.java
+++ b/src/test/java/com/google/gwtorm/schema/sql/DialectPostgreSQLTest.java
@@ -15,17 +15,23 @@
package com.google.gwtorm.schema.sql;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
import com.google.gwtorm.data.PhoneBookDb;
import com.google.gwtorm.data.PhoneBookDb2;
-import com.google.gwtorm.data.TestAddress;
-import com.google.gwtorm.data.TestPerson;
+import com.google.gwtorm.data.Address;
+import com.google.gwtorm.data.Person;
import com.google.gwtorm.jdbc.Database;
import com.google.gwtorm.jdbc.JdbcExecutor;
import com.google.gwtorm.jdbc.JdbcSchema;
import com.google.gwtorm.jdbc.SimpleDataSource;
import com.google.gwtorm.server.OrmException;
-import junit.framework.TestCase;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
import java.sql.Connection;
import java.sql.DriverManager;
@@ -34,16 +40,15 @@
import java.util.Properties;
import java.util.Set;
-public class DialectPostgreSQLTest extends TestCase {
+public class DialectPostgreSQLTest {
private Connection db;
private JdbcExecutor executor;
private SqlDialect dialect;
private Database<PhoneBookDb> phoneBook;
private Database<PhoneBookDb2> phoneBook2;
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() throws Exception {
Class.forName(org.postgresql.Driver.class.getName());
final String database = "gwtorm";
@@ -79,8 +84,8 @@
}
}
- @Override
- protected void tearDown() {
+ @After
+ public void tearDown() {
if (executor != null) {
executor.close();
}
@@ -100,6 +105,7 @@
executor.execute(sql);
}
+ @Test
public void testListSequences() throws OrmException, SQLException {
assertTrue(dialect.listSequences(db).isEmpty());
@@ -112,6 +118,7 @@
assertFalse(s.contains("foo"));
}
+ @Test
public void testListTables() throws OrmException, SQLException {
assertTrue(dialect.listTables(db).isEmpty());
@@ -124,6 +131,7 @@
assertTrue(s.contains("foo"));
}
+ @Test
public void testUpgradeSchema() throws SQLException, OrmException {
final PhoneBookDb p = phoneBook.open();
try {
@@ -154,12 +162,12 @@
assertFalse(sequences.contains("cnt"));
assertFalse(tables.contains("foo"));
- final TestPerson.Key pk = new TestPerson.Key("Bob");
- final TestPerson bob = new TestPerson(pk, p.nextAddressId());
+ final Person.Key pk = new Person.Key("Bob");
+ final Person bob = new Person(pk, p.nextAddressId());
p.people().insert(Collections.singleton(bob));
- final TestAddress addr =
- new TestAddress(new TestAddress.Key(pk, "home"), "some place");
+ final Address addr =
+ new Address(new Address.Key(pk, "home"), "some place");
p.addresses().insert(Collections.singleton(addr));
} finally {
p.close();
diff --git a/src/test/java/com/google/gwtorm/server/PhoneBookDbTestCase.java b/src/test/java/com/google/gwtorm/server/PhoneBookDbTestCase.java
index ba8e2d3..247a4a4 100644
--- a/src/test/java/com/google/gwtorm/server/PhoneBookDbTestCase.java
+++ b/src/test/java/com/google/gwtorm/server/PhoneBookDbTestCase.java
@@ -14,15 +14,25 @@
package com.google.gwtorm.server;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import com.google.gwtorm.data.Person;
import com.google.gwtorm.data.PersonAccess;
import com.google.gwtorm.data.PhoneBookDb;
-import com.google.gwtorm.data.TestPerson;
import com.google.gwtorm.jdbc.Database;
import com.google.gwtorm.jdbc.JdbcExecutor;
import com.google.gwtorm.jdbc.JdbcSchema;
import com.google.gwtorm.jdbc.SimpleDataSource;
-import junit.framework.TestCase;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
import java.sql.ResultSet;
import java.sql.SQLException;
@@ -32,15 +42,13 @@
import java.util.List;
import java.util.Properties;
-public class PhoneBookDbTestCase extends TestCase {
+public class PhoneBookDbTestCase {
private static int runCount;
protected Database<PhoneBookDb> db;
private List<PhoneBookDb> openSchemas;
- @Override
+ @Before
public void setUp() throws Exception {
- super.setUp();
-
final Properties p = new Properties();
p.setProperty("driver", org.h2.Driver.class.getName());
p.setProperty("url", "jdbc:h2:mem:PhoneBookDb" + (runCount++));
@@ -48,7 +56,7 @@
openSchemas = new ArrayList<PhoneBookDb>();
}
- @Override
+ @After
public void tearDown() throws Exception {
if (openSchemas != null) {
for (PhoneBookDb schema : openSchemas) {
@@ -56,7 +64,6 @@
}
openSchemas = null;
}
- super.tearDown();
}
protected PhoneBookDb open() throws OrmException {
@@ -82,10 +89,12 @@
return ((JdbcSchema) schema).getConnection().createStatement();
}
+ @Test
public void testCreateDatabaseHandle() throws Exception {
assertNotNull(db);
}
+ @Test
public void testOpenSchema() throws Exception {
final PhoneBookDb schema1 = open();
assertNotNull(schema1);
@@ -95,6 +104,7 @@
assertNotSame(schema1, schema2);
}
+ @Test
public void testGetPeopleAccess() throws Exception {
final PhoneBookDb schema = open();
assertNotNull(schema.people());
@@ -102,6 +112,7 @@
assertEquals(1, schema.people().getRelationID());
}
+ @Test
public void testGetAddressAccess() throws Exception {
final PhoneBookDb schema = open();
assertNotNull(schema.addresses());
@@ -109,6 +120,7 @@
assertEquals(2, schema.addresses().getRelationID());
}
+ @Test
public void testGetAllRelations() throws Exception {
final PhoneBookDb schema = open();
Access<?, ?>[] all = schema.allRelations();
@@ -118,6 +130,7 @@
assertSame(schema.addresses(), all[1]);
}
+ @Test
public void testCreateSchema() throws Exception {
final PhoneBookDb schema = open();
final JdbcExecutor e = new JdbcExecutor((JdbcSchema) schema);
@@ -128,6 +141,7 @@
}
}
+ @Test
public void testNextAddressId() throws Exception {
final PhoneBookDb schema = openAndCreate();
final int a = schema.nextAddressId();
@@ -135,16 +149,18 @@
assertTrue(a != b);
}
+ @Test
public void testPersonPrimaryKey() throws Exception {
final PhoneBookDb schema = openAndCreate();
- final TestPerson.Key key = new TestPerson.Key("Bob");
- final TestPerson bob = new TestPerson(key, 18);
+ final Person.Key key = new Person.Key("Bob");
+ final Person bob = new Person(key, 18);
assertSame(key, schema.people().primaryKey(bob));
}
+ @Test
public void testInsertOnePerson() throws Exception {
final PhoneBookDb schema = openAndCreate();
- final TestPerson bob = new TestPerson(new TestPerson.Key("Bob"), 18);
+ final Person bob = new Person(new Person.Key("Bob"), 18);
schema.people().insert(Collections.singleton(bob));
final Statement st = statement(schema);
@@ -157,53 +173,57 @@
st.close();
}
+ @Test
public void testGetOnePerson() throws Exception {
final PhoneBookDb schema = openAndCreate();
final PersonAccess sp = schema.people();
- final TestPerson p1 = new TestPerson(new TestPerson.Key("Bob"), 18);
+ final Person p1 = new Person(new Person.Key("Bob"), 18);
sp.insert(Collections.singleton(p1));
- final TestPerson p2 = sp.get(sp.primaryKey(p1));
+ final Person p2 = sp.get(sp.primaryKey(p1));
assertNotNull(p2);
assertNotSame(p1, p2);
assertEquals(sp.primaryKey(p1), sp.primaryKey(p2));
}
+ @Test
public void testGetAsyncOnePerson() throws Exception {
final PhoneBookDb schema = openAndCreate();
final PersonAccess sp = schema.people();
- final TestPerson p1 = new TestPerson(new TestPerson.Key("Bob"), 18);
+ final Person p1 = new Person(new Person.Key("Bob"), 18);
sp.insert(Collections.singleton(p1));
- final TestPerson p2 = sp.getAsync(sp.primaryKey(p1)).get();
+ final Person p2 = sp.getAsync(sp.primaryKey(p1)).get();
assertNotNull(p2);
assertNotSame(p1, p2);
assertEquals(sp.primaryKey(p1), sp.primaryKey(p2));
}
+ @Test
public void testGetOnePersonIterator() throws Exception {
final PhoneBookDb schema = openAndCreate();
final PersonAccess sp = schema.people();
- final TestPerson p1 = new TestPerson(new TestPerson.Key("Bob"), 18);
+ final Person p1 = new Person(new Person.Key("Bob"), 18);
sp.insert(Collections.singleton(p1));
- final List<TestPerson> list =
+ final List<Person> list =
sp.get(Collections.singleton(sp.primaryKey(p1))).toList();
assertNotNull(list);
assertEquals(1, list.size());
- final TestPerson p2 = list.get(0);
+ final Person p2 = list.get(0);
assertNotNull(p2);
assertNotSame(p1, p2);
assertEquals(sp.primaryKey(p1), sp.primaryKey(p2));
}
+ @Test
public void testInsertManyPeople() throws Exception {
final PhoneBookDb schema = openAndCreate();
- final ArrayList<TestPerson> all = new ArrayList<TestPerson>();
- all.add(new TestPerson(new TestPerson.Key("Bob"), 18));
- all.add(new TestPerson(new TestPerson.Key("Mary"), 22));
- all.add(new TestPerson(new TestPerson.Key("Zak"), 33));
+ final ArrayList<Person> all = new ArrayList<Person>();
+ all.add(new Person(new Person.Key("Bob"), 18));
+ all.add(new Person(new Person.Key("Mary"), 22));
+ all.add(new Person(new Person.Key("Zak"), 33));
schema.people().insert(all);
final Statement st = statement(schema);
@@ -219,9 +239,10 @@
st.close();
}
+ @Test
public void testDeleteOnePerson() throws Exception {
final PhoneBookDb schema = openAndCreate();
- final TestPerson bob = new TestPerson(new TestPerson.Key("Bob"), 18);
+ final Person bob = new Person(new Person.Key("Bob"), 18);
schema.people().insert(Collections.singleton(bob));
schema.people().delete(Collections.singleton(bob));
@@ -232,9 +253,10 @@
st.close();
}
+ @Test
public void testUpdateOnePerson() throws Exception {
final PhoneBookDb schema = openAndCreate();
- final TestPerson bob = new TestPerson(new TestPerson.Key("Bob"), 18);
+ final Person bob = new Person(new Person.Key("Bob"), 18);
schema.people().insert(Collections.singleton(bob));
bob.growOlder();
schema.people().update(Collections.singleton(bob));
@@ -249,9 +271,10 @@
st.close();
}
+ @Test
public void testUpdateNoPerson() throws Exception {
final PhoneBookDb schema = openAndCreate();
- final TestPerson bob = new TestPerson(new TestPerson.Key("Bob"), 18);
+ final Person bob = new Person(new Person.Key("Bob"), 18);
try {
schema.people().update(Collections.singleton(bob));
fail("Update of missing person succeeded");
@@ -260,12 +283,13 @@
}
}
+ @Test
public void testFetchOnePerson() throws Exception {
final PhoneBookDb schema = openAndCreate();
- final TestPerson bob = new TestPerson(new TestPerson.Key("Bob"), 18);
+ final Person bob = new Person(new Person.Key("Bob"), 18);
schema.people().insert(Collections.singleton(bob));
- final List<TestPerson> all = schema.people().all().toList();
+ final List<Person> all = schema.people().all().toList();
assertNotNull(all);
assertEquals(1, all.size());
assertNotSame(bob, all.get(0));
@@ -274,13 +298,14 @@
assertEquals(bob.isRegistered(), all.get(0).isRegistered());
}
+ @Test
public void testFetchOnePersonByName() throws Exception {
final PhoneBookDb schema = openAndCreate();
- final TestPerson bob1 = new TestPerson(new TestPerson.Key("Bob"), 18);
+ final Person bob1 = new Person(new Person.Key("Bob"), 18);
schema.people().insert(Collections.singleton(bob1));
- final TestPerson bob2 =
- schema.people().get(new TestPerson.Key(bob1.name()));
+ final Person bob2 =
+ schema.people().get(new Person.Key(bob1.name()));
assertNotNull(bob2);
assertNotSame(bob1, bob2);
assertEquals(bob1.name(), bob2.name());
@@ -288,38 +313,41 @@
assertEquals(bob1.isRegistered(), bob2.isRegistered());
}
+ @Test
public void testFetchByAge() throws Exception {
final PhoneBookDb schema = openAndCreate();
- final ArrayList<TestPerson> all = new ArrayList<TestPerson>();
- all.add(new TestPerson(new TestPerson.Key("Bob"), 18));
- all.add(new TestPerson(new TestPerson.Key("Mary"), 22));
- all.add(new TestPerson(new TestPerson.Key("Zak"), 33));
+ final ArrayList<Person> all = new ArrayList<Person>();
+ all.add(new Person(new Person.Key("Bob"), 18));
+ all.add(new Person(new Person.Key("Mary"), 22));
+ all.add(new Person(new Person.Key("Zak"), 33));
schema.people().insert(all);
- final List<TestPerson> r = schema.people().olderThan(20).toList();
+ final List<Person> r = schema.people().olderThan(20).toList();
assertEquals(2, r.size());
assertEquals(all.get(1).name(), r.get(0).name());
assertEquals(all.get(2).name(), r.get(1).name());
}
+ @Test
public void testFetchNotPerson() throws Exception {
final PhoneBookDb schema = openAndCreate();
- final ArrayList<TestPerson> all = new ArrayList<TestPerson>();
- all.add(new TestPerson(new TestPerson.Key("Bob"), 18));
- all.add(new TestPerson(new TestPerson.Key("Mary"), 22));
- all.add(new TestPerson(new TestPerson.Key("Zak"), 33));
+ final ArrayList<Person> all = new ArrayList<Person>();
+ all.add(new Person(new Person.Key("Bob"), 18));
+ all.add(new Person(new Person.Key("Mary"), 22));
+ all.add(new Person(new Person.Key("Zak"), 33));
schema.people().insert(all);
- final List<TestPerson> r =
+ final List<Person> r =
schema.people().olderThanDescByName(18).toList();
assertEquals(2, r.size());
assertEquals(all.get(2).name(), r.get(0).name());
assertEquals(all.get(1).name(), r.get(1).name());
}
+ @Test
public void testBooleanType() throws Exception {
final PhoneBookDb schema = openAndCreate();
- final TestPerson bob = new TestPerson(new TestPerson.Key("Bob"), 18);
+ final Person bob = new Person(new Person.Key("Bob"), 18);
schema.people().insert(Collections.singleton(bob));
final Statement st = statement(schema);
diff --git a/src/test/java/com/google/gwtorm/server/PrintCreateTablesTestCase.java b/src/test/java/com/google/gwtorm/server/PrintCreateTablesTestCase.java
index 544c185..66a13d2 100644
--- a/src/test/java/com/google/gwtorm/server/PrintCreateTablesTestCase.java
+++ b/src/test/java/com/google/gwtorm/server/PrintCreateTablesTestCase.java
@@ -18,9 +18,11 @@
import com.google.gwtorm.schema.java.JavaSchemaModel;
import com.google.gwtorm.schema.sql.DialectH2;
-import junit.framework.TestCase;
+import org.junit.Test;
-public class PrintCreateTablesTestCase extends TestCase {
+public class PrintCreateTablesTestCase {
+
+ @Test
public void testCreate() throws Exception {
final JavaSchemaModel m = new JavaSchemaModel(PhoneBookDb.class);
System.out.println(m.getCreateDatabaseSql(new DialectH2()));