/*
* Copyright 2009-2016 Tilmann Zaeschke. All rights reserved.
*
* This file is part of ZooDB.
*
* ZooDB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ZooDB 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ZooDB. If not, see <http://www.gnu.org/licenses/>.
*
* See the README and COPYING files for further information.
*/
package org.zoodb.test.jdo;
import static org.junit.Assert.fail;
import javax.jdo.PersistenceManager;
import javax.jdo.Query;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.zoodb.test.testutil.TestTools;
/**
* Tests for query setResult().
*
* @author ztilmann
*
*/
public class Test_121_QueryResultProcessing {
@BeforeClass
public static void setUp() {
TestTools.removeDb();
TestTools.createDb();
TestTools.defineSchema(TestClass.class);
}
@Before
public void before() {
PersistenceManager pm = TestTools.openPM();
pm.currentTransaction().begin();
pm.newQuery(TestClass.class).deletePersistentAll();
TestClass tc1 = new TestClass();
tc1.setData(1, false, 'c', (byte)127, (short)32001, 1234567890L, "xyz", new byte[]{1,2},
-1.1f, 35);
pm.makePersistent(tc1);
tc1 = new TestClass();
tc1.setData(12, false, 'd', (byte)126, (short)32002, 1234567890L, "xyz", new byte[]{1,2},
-0.1f, 34);
pm.makePersistent(tc1);
tc1 = new TestClass();
tc1.setData(123, false, 'e', (byte)125, (short)32003, 1234567890L, "xyz", new byte[]{1,2},
0.1f, 3.0);
pm.makePersistent(tc1);
tc1 = new TestClass();
tc1.setData(1234, false, 'f', (byte)124, (short)32004, 1234567890L, "xyz", new byte[]{1,2},
1.1f, -0.01);
pm.makePersistent(tc1);
tc1 = new TestClass();
tc1.setData(12345, false, 'g', (byte)123, (short)32005, 1234567890L, "xyz", new byte[]{1,2},
11.1f, -35);
pm.makePersistent(tc1);
pm.currentTransaction().commit();
TestTools.closePM();;
}
@After
public void afterTest() {
TestTools.closePM();
}
@AfterClass
public static void tearDown() {
TestTools.removeDb();
}
@Test
public void testFailuresSetResult() {
PersistenceManager pm = TestTools.openPM();
pm.currentTransaction().begin();
// select [unique] [ <result> ] [into <result-class-name>]
// [from <candidate-class-name> [exclude subclasses] ]
// [where <filter>]
// [variables <variable -list> ]
// [parameters <parameter-list>]
// [imports <import-list>]
// [group by <grouping-clause> ]
// [order by <ordering-clause>]
// [range <from-range> ,<to-range>]
String start = "_int > 1 ";
System.err.println("TODO implement query variables");
checkFails(pm, start + "variables xyz");
System.err.println("TODO implement query imports");
checkFails(pm, start + "imports xyz");
System.err.println("TODO implement query group");
checkFails(pm, start + "group by xyz");
}
private void checkFails(PersistenceManager pm, String s) {
try {
Query q = pm.newQuery(TestClass.class, s);
q.compile();
fail();
} catch (UnsupportedOperationException e) {
//good, we got an JDOUSerException()
}
}
}