Skip to content

Commit

Permalink
Added tests for issue #100 and #104
Browse files Browse the repository at this point in the history
  • Loading branch information
tzaeschke committed May 26, 2017
1 parent 4ed0b34 commit 2348bd4
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 58 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@
<exclude>**/test/jdo/Test_038_SchemaAutoCreate.java</exclude>
<exclude>**/test/jdo/Test_039_SchemaEvolBug.java</exclude>
<exclude>**/test/jdo/Test_160_SchemaBug.java</exclude>
<exclude>**/test/jdo/Test_173_QueryIssue99_100_104.java</exclude>
</excludes>
</configuration>
</plugin>
Expand Down
2 changes: 2 additions & 0 deletions src/org/zoodb/internal/query/QueryParserV3.java
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,8 @@ private QueryTerm parseTerm(boolean negate) {
}
} else {
if (!(String.class.isAssignableFrom(lhsType) ||
//TODO allow char type!
// (!(Character.class.isAssignableFrom(lhsType)) && token().str.length() == 1) ||
Collection.class.isAssignableFrom(lhsType) ||
Map.class.isAssignableFrom(lhsType))) {
throw tokenParsingError(
Expand Down
2 changes: 1 addition & 1 deletion tst/org/zoodb/test/api/TestSuper.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public String toString() {
s.append(" ID=");
s.append(_id);
s.append(" RAW=");
s.append(_rawData);
s.append(Arrays.toString(_rawData));
s.append(" DUMMY=");
s.append(_dummy);
s.append(" CHILD=");
Expand Down
57 changes: 0 additions & 57 deletions tst/org/zoodb/test/jdo/Test_173_QueryIssue99.java

This file was deleted.

127 changes: 127 additions & 0 deletions tst/org/zoodb/test/jdo/Test_173_QueryIssue99_100_104.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
package org.zoodb.test.jdo;

import static org.junit.Assert.assertTrue;

import java.util.Collection;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;

import org.junit.Before;
import org.junit.Test;
import org.zoodb.jdo.ZooJdoHelper;
import org.zoodb.jdo.ZooJdoProperties;
import org.zoodb.test.testutil.TestTools;

public class Test_173_QueryIssue99_100_104 {

@Before
public void setUp() {
TestTools.removeDb();
TestTools.createDb();
}

@SuppressWarnings("unchecked")
@Test
public void testIssue99() {
ZooJdoProperties props = TestTools.getProps();
props.setZooAutoCreateSchema(true);
PersistenceManager pm = TestTools.openPM(props);

final String str = "abcdefghijklmnopqrstuvwxyz";
pm.currentTransaction().begin();
for (char c : str.toCharArray()) {
TestClass i = new TestClass();
i.setChar(c);
pm.makePersistent(i);
}
pm.currentTransaction().commit();

pm.currentTransaction().begin();
ZooJdoHelper.createIndex(pm, TestClass.class, "_char", true/*isUnique*/);
pm.currentTransaction().commit();

pm.currentTransaction().begin();
Query q = pm.newQuery(TestClass.class);
q.declareParameters("Character ch1, Character ch2");
q.setFilter("_char == ch1 || _char == ch2");
Collection<TestClass> rslt = (Collection<TestClass>) q.execute('a', 'z');
assertTrue(rslt.iterator().hasNext());
q.closeAll();
pm.currentTransaction().commit();

TestTools.closePM();
}

@SuppressWarnings("unchecked")
@Test
public void testIssue100() {
ZooJdoProperties props = TestTools.getProps();
props.setZooAutoCreateSchema(true);
PersistenceManager pm = TestTools.openPM(props);

final String str = "abcdefghijklmnopqrstuvwxyz";
pm.currentTransaction().begin();
for (char c : str.toCharArray()) {
TestClass i = new TestClass();
i.setChar(c);
i.setString( new String(new char[] { c, '9' }) );
pm.makePersistent(i);
}
pm.currentTransaction().commit();

pm.currentTransaction().begin();
ZooJdoHelper.createIndex(pm, TestClass.class, "_string", true/*isUnique*/);
pm.currentTransaction().commit();

pm.currentTransaction().begin();
Query q = pm.newQuery(TestClass.class);
q.declareParameters("String ssp");
q.setFilter("ssp != null && _string == ssp");
Collection<TestClass> rslt = (Collection<TestClass>) q.execute("z9");
q.closeAll();
pm.currentTransaction().commit();

pm.currentTransaction().begin();
q = pm.newQuery(TestClass.class);
q.setFilter(":ssp != null && _string == :ssp");
rslt = (Collection<TestClass>) q.execute("z9");
assertTrue(rslt.iterator().hasNext());
q.closeAll();
pm.currentTransaction().commit();

TestTools.closePM();
}

@SuppressWarnings("unchecked")
@Test
public void testIssue104() {
ZooJdoProperties props = TestTools.getProps();
props.setZooAutoCreateSchema(true);
PersistenceManager pm = TestTools.openPM(props);

final String str = "abcdefghijklmnopqrstuvwxyz";
pm.currentTransaction().begin();
for (char c : str.toCharArray()) {
TestClass i = new TestClass();
i.setChar(c);
pm.makePersistent(i);
}
pm.currentTransaction().commit();

pm.currentTransaction().begin();
ZooJdoHelper.createIndex(pm, TestClass.class, "_char", true/*isUnique*/);
pm.currentTransaction().commit();

pm.currentTransaction().begin();
Query q = pm.newQuery(TestClass.class);
q.setFilter("_char == 'a' || _char == 'z'");
Collection<TestClass> rslt = (Collection<TestClass>) q.execute();
assertTrue(rslt.iterator().hasNext());
q.closeAll();
pm.currentTransaction().commit();

TestTools.closePM();
}

}

0 comments on commit 2348bd4

Please sign in to comment.