use of com.googlecode.lanterna.gui2.Window in project tests by datanucleus.
the class JDOQLContainerTest method testBulkFetchUsingJoinTableWithOrdering.
/**
* Tests use of bulk-fetch on collection via JoinTable.
*/
public void testBulkFetchUsingJoinTableWithOrdering() {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
// Create some data
tx.begin();
House house1 = new House(101, "Downing Street");
Window win1 = new Window(400, 300, house1);
Window win2 = new Window(200, 300, house1);
Window win3 = new Window(400, 300, house1);
house1.addWindow(win1);
house1.addWindow(win2);
house1.addWindow(win3);
House house2 = new House(102, "Downing Street");
Window win4 = new Window(600, 300, house2);
Window win5 = new Window(500, 300, house2);
house2.addWindow(win4);
house2.addWindow(win5);
pm.makePersistent(house1);
pm.makePersistent(house2);
pm.flush();
// Query the data with bulk-fetch enabled
// Note : this doesn't actually check how many SQL were issued just that it passes
Query q = pm.newQuery("SELECT FROM " + House.class.getName() + " WHERE number == 101 ORDER BY street");
q.addExtension("datanucleus.rdbms.query.multivaluedFetch", "exists");
q.getFetchPlan().setGroup("all");
List<House> results = (List<House>) q.execute();
assertEquals(1, results.size());
House house = results.get(0);
assertEquals("Downing Street", house.getStreet());
assertEquals(3, house.getWindows().size());
tx.rollback();
} catch (Exception e) {
LOG.error("Exception thrown during test", e);
fail("Exception thrown while performing test : " + e.getMessage());
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
clean(House.class);
clean(Window.class);
}
}
use of com.googlecode.lanterna.gui2.Window in project tests by datanucleus.
the class RelationshipTest method test1toNBidirJoin.
/**
* Test case for 1-N bidir join table relationship.
*/
public void test1toNBidirJoin() throws Exception {
try {
Object houseId = null;
Object[] windowIds = null;
Object[] deletedWindowIds = null;
PersistenceManager pm = pmf.getPersistenceManager();
pm.setProperty(PropertyNames.PROPERTY_MANAGE_RELATIONSHIPS, "" + manageRelationships);
Transaction tx = pm.currentTransaction();
try {
tx.begin();
// Create some data
House house = new House(16, "Coronation Street");
Window w1 = new Window(2000, 1500, house);
Window w2 = new Window(1000, 1500, house);
Window w3 = new Window(4000, 1000, house);
house.addWindow(w1);
house.addWindow(w2);
house.addWindow(w3);
pm.makePersistent(house);
houseId = JDOHelper.getObjectId(house);
windowIds = new Object[3];
windowIds[0] = JDOHelper.getObjectId(w1);
windowIds[1] = JDOHelper.getObjectId(w2);
windowIds[2] = JDOHelper.getObjectId(w3);
tx.commit();
} catch (Exception e) {
LOG.error("Exception in test", e);
fail("Exception thrown while creating 1-N bidirectional Join Table relationship data : " + e.getMessage());
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
// Test the retrieval of objects by id
pm = pmf.getPersistenceManager();
pm.setProperty(PropertyNames.PROPERTY_MANAGE_RELATIONSHIPS, "" + manageRelationships);
tx = pm.currentTransaction();
try {
tx.begin();
// Check the House
House house = (House) pm.getObjectById(houseId);
assertTrue("House was not retrieved via getObjectById", house != null);
assertTrue("House obtained by getObjectById was incorrect : has wrong street/number", house.getStreet().equals("Coronation Street") && house.getNumber() == 16);
assertTrue("House obtained by getObjectById was incorrect : has null collection of windows", house.getWindows() != null);
assertTrue("House obtained by getObjectById was incorrect : has incorrect number of windows : was " + house.getNumberOfWindows() + " but should be 3", house.getNumberOfWindows() == 3);
// Check a Window
Window window = (Window) pm.getObjectById(windowIds[0]);
assertTrue("Window was not retrieved via getObjectById", window != null);
assertTrue("Window obtained by getObjectById was incorrect : has wrong width/height", window.getWidth() == 2000 && window.getHeight() == 1500);
assertTrue("Window obtained by getObjectById was incorrect : has null house", window.getHouse() != null);
assertTrue("Window obtained by getObjectById was incorrect : has incorrect House", JDOHelper.getObjectId(window.getHouse()).equals(houseId));
tx.commit();
} catch (Exception e) {
LOG.error("Exception in test", e);
fail("Exception thrown while creating 1-N bidirectional Join Table relationship data : " + e.getMessage());
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
// Test add/remove of windows
pm = pmf.getPersistenceManager();
pm.setProperty(PropertyNames.PROPERTY_MANAGE_RELATIONSHIPS, "" + manageRelationships);
tx = pm.currentTransaction();
try {
tx.begin();
// Retrieve the House
House house = (House) pm.getObjectById(houseId);
// Remove 2 windows and replace them with a much larger one
Window w1 = (Window) pm.getObjectById(windowIds[0]);
Window w3 = (Window) pm.getObjectById(windowIds[2]);
house.removeWindow(w1);
house.removeWindow(w3);
w1.setHouse(null);
w3.setHouse(null);
Window w4 = new Window(6000, 1000, house);
house.addWindow(w4);
tx.commit();
deletedWindowIds = new Object[2];
deletedWindowIds[0] = windowIds[0];
deletedWindowIds[1] = windowIds[2];
Object windowId2 = windowIds[1];
windowIds = new Object[2];
windowIds[0] = windowId2;
windowIds[1] = JDOHelper.getObjectId(w4);
} catch (Exception e) {
LOG.error("Exception in test", e);
fail("Exception thrown while updating 1-N bidirectional Join Table relationship data : " + e.getMessage());
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
pm = pmf.getPersistenceManager();
pm.setProperty(PropertyNames.PROPERTY_MANAGE_RELATIONSHIPS, "" + manageRelationships);
tx = pm.currentTransaction();
try {
tx.begin();
// Check the House
House house = (House) pm.getObjectById(houseId);
assertTrue("House was not retrieved via getObjectById", house != null);
assertTrue("House obtained by getObjectById was incorrect : has wrong street/number", house.getStreet().equals("Coronation Street") && house.getNumber() == 16);
assertTrue("House obtained by getObjectById was incorrect : has null collection of windows", house.getWindows() != null);
assertTrue("House obtained by getObjectById was incorrect : has incorrect number of windows : was " + house.getNumberOfWindows() + " but should be 2", house.getNumberOfWindows() == 2);
// Check the Windows
Window w1 = (Window) pm.getObjectById(deletedWindowIds[0]);
assertTrue("Window was not retrieved via getObjectById", w1 != null);
assertTrue("Window obtained by getObjectById was incorrect : has wrong width/height", w1.getWidth() == 2000 && w1.getHeight() == 1500);
assertTrue("Window obtained by getObjectById was incorrect : has house but should be null", w1.getHouse() == null);
Window w2 = (Window) pm.getObjectById(deletedWindowIds[1]);
assertTrue("Window was not retrieved via getObjectById", w2 != null);
assertTrue("Window obtained by getObjectById was incorrect : has wrong width/height", w2.getWidth() == 4000 && w2.getHeight() == 1000);
assertTrue("Window obtained by getObjectById was incorrect : has house but should be null", w1.getHouse() == null);
Window w3 = (Window) pm.getObjectById(windowIds[0]);
assertTrue("Window was not retrieved via getObjectById", w3 != null);
assertTrue("Window obtained by getObjectById was incorrect : has wrong width/height", w3.getWidth() == 1000 && w3.getHeight() == 1500);
assertTrue("Window obtained by getObjectById was incorrect : has null house", w3.getHouse() != null);
assertTrue("Window obtained by getObjectById was incorrect : has incorrect House", JDOHelper.getObjectId(w3.getHouse()).equals(houseId));
Window w4 = (Window) pm.getObjectById(windowIds[1]);
assertTrue("Window was not retrieved via getObjectById", w4 != null);
assertTrue("Window obtained by getObjectById was incorrect : has wrong width/height", w4.getWidth() == 6000 && w4.getHeight() == 1000);
assertTrue("Window obtained by getObjectById was incorrect : has null house", w4.getHouse() != null);
assertTrue("Window obtained by getObjectById was incorrect : has incorrect House", JDOHelper.getObjectId(w4.getHouse()).equals(houseId));
tx.commit();
} catch (Exception e) {
LOG.error("Exception in test", e);
fail("Exception thrown while creating 1-N bidirectional Join Table relationship data : " + e.getMessage());
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
// Perform a query on the N side with the 1 side in the fetch group
pm = pmf.getPersistenceManager();
pm.setProperty(PropertyNames.PROPERTY_MANAGE_RELATIONSHIPS, "" + manageRelationships);
tx = pm.currentTransaction();
try {
tx.begin();
// Fetch all fields (including FK to House)
pm.getFetchPlan().addGroup(FetchPlan.ALL);
Query query = pm.newQuery(Window.class);
query.setFilter("width == 6000");
List results = (List) query.execute();
assertEquals(results.size(), 1);
tx.commit();
} catch (Exception e) {
LOG.error("Exception in test", e);
fail("Exception thrown while querying class at N side using fetch plan to include 1 side : " + e.getMessage());
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
// Perform a query on the N side of the relation referring to the 1 side in the query
pm = pmf.getPersistenceManager();
pm.setProperty(PropertyNames.PROPERTY_MANAGE_RELATIONSHIPS, "" + manageRelationships);
tx = pm.currentTransaction();
try {
tx.begin();
Query query = pm.newQuery(Window.class);
query.setFilter("house.street == \"Coronation Street\"");
List results = (List) query.execute();
assertEquals(results.size(), 2);
tx.commit();
} catch (Exception e) {
LOG.error("Exception in test", e);
fail("Exception thrown while querying class at N side of relation : " + e.getMessage());
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
// Persist data from the "N" end.
pm = pmf.getPersistenceManager();
pm.setProperty(PropertyNames.PROPERTY_MANAGE_RELATIONSHIPS, "" + manageRelationships);
tx = pm.currentTransaction();
try {
tx.begin();
// Create some data
House house = new House(25, "Albert Road");
Window w1 = new Window(600, 300, house);
Window w2 = new Window(800, 300, house);
Window w3 = new Window(900, 200, house);
house.addWindow(w1);
house.addWindow(w2);
house.addWindow(w3);
pm.makePersistent(w1);
houseId = JDOHelper.getObjectId(house);
windowIds = new Object[3];
windowIds[0] = JDOHelper.getObjectId(w1);
windowIds[1] = JDOHelper.getObjectId(w2);
windowIds[2] = JDOHelper.getObjectId(w3);
tx.commit();
} catch (Exception e) {
LOG.error("Exception in test", e);
fail("Exception thrown while creating 1-N bidirectional Join Table relationship data from the N side : " + e.getMessage());
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
// Retrieve the objects
pm = pmf.getPersistenceManager();
pm.setProperty(PropertyNames.PROPERTY_MANAGE_RELATIONSHIPS, "" + manageRelationships);
tx = pm.currentTransaction();
try {
tx.begin();
// Check the House
House house = (House) pm.getObjectById(houseId);
assertTrue("House was not retrieved via getObjectById", house != null);
assertTrue("House obtained by getObjectById was incorrect : has wrong street/number", house.getStreet().equals("Albert Road") && house.getNumber() == 25);
assertTrue("House obtained by getObjectById was incorrect : has null collection of windows", house.getWindows() != null);
assertTrue("House obtained by getObjectById was incorrect : has incorrect number of windows : was " + house.getNumberOfWindows() + " but should be 3", house.getNumberOfWindows() == 3);
tx.commit();
} catch (Exception e) {
LOG.error("Exception in test", e);
fail("Exception thrown while creating 1-N bidirectional Join Table relationship data : " + e.getMessage());
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
} finally {
// Clean out our data
clean(House.class);
clean(Window.class);
}
}
use of com.googlecode.lanterna.gui2.Window in project tests by datanucleus.
the class JPQLQueryTest method testInnerJoinOneToManyBiJoinTableOwner.
/**
* Test for Inner Join 1-N bidirectional JoinTable relation from the owner side.
*/
public void testInnerJoinOneToManyBiJoinTableOwner() {
try {
EntityManager em = getEM();
EntityTransaction tx = em.getTransaction();
try {
tx.begin();
House house = new House(101, "Coronation Street");
Window window = new Window(200, 400, house);
house.getWindows().add(window);
em.persist(house);
em.flush();
List result = em.createQuery("SELECT H FROM " + House.class.getName() + " H INNER JOIN H.windows W").getResultList();
assertEquals(1, result.size());
tx.rollback();
} finally {
if (tx.isActive()) {
tx.rollback();
}
em.close();
}
} finally {
clean(House.class);
clean(Window.class);
}
}
use of com.googlecode.lanterna.gui2.Window in project narchy by automenta.
the class ConsoleGUI method start.
@Override
public void start(@Nullable SurfaceBase parent) {
synchronized (this) {
super.start(parent);
// thr.start();
try {
screen = new TerminalScreen(term);
screen.startScreen();
gui = new MultiWindowTextGUI(MyStupidGUIThread::new, screen);
// TODO try to avoid wrapping it in Window
window = new BasicWindow();
window.setPosition(new TerminalPosition(0, 0));
TerminalSize size = term.getTerminalSize();
window.setSize(new TerminalSize(size.getColumns(), size.getRows()));
window.setHints(List.of(Window.Hint.FULL_SCREEN, Window.Hint.NO_DECORATIONS));
window.setTheme(DARK);
window.setEnableDirectionBasedMovements(true);
gui.addWindow(window);
gui.setActiveWindow(window);
gui.setEOFWhenNoWindows(true);
init(window);
TextGUIThread guiThread = gui.getGUIThread();
updates = root().onUpdate((s) -> {
try {
guiThread.processEventsAndUpdate();
} catch (IOException e) {
e.printStackTrace();
}
});
} catch (IOException e) {
e.printStackTrace();
}
}
}
use of com.googlecode.lanterna.gui2.Window in project tests by datanucleus.
the class JDOQLContainerTest method testBulkFetchUsingJoinTable.
/**
* Tests use of bulk-fetch on collection via JoinTable.
*/
public void testBulkFetchUsingJoinTable() {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
// Create some data
tx.begin();
House house1 = new House(101, "Downing Street");
Window win1 = new Window(400, 300, house1);
Window win2 = new Window(200, 300, house1);
Window win3 = new Window(400, 300, house1);
house1.addWindow(win1);
house1.addWindow(win2);
house1.addWindow(win3);
House house2 = new House(102, "Downing Street");
Window win4 = new Window(600, 300, house2);
Window win5 = new Window(500, 300, house2);
house2.addWindow(win4);
house2.addWindow(win5);
pm.makePersistent(house1);
pm.makePersistent(house2);
pm.flush();
// Query the data with bulk-fetch enabled
// Note : this doesn't actually check how many SQL were issued just that it passes
Query q = pm.newQuery("SELECT FROM " + House.class.getName() + " WHERE number == 101");
q.addExtension("datanucleus.rdbms.query.multivaluedFetch", "exists");
q.getFetchPlan().setGroup("all");
List<House> results = (List<House>) q.execute();
assertEquals(1, results.size());
House house = results.get(0);
assertEquals("Downing Street", house.getStreet());
assertEquals(3, house.getWindows().size());
tx.rollback();
} catch (Exception e) {
LOG.error("Exception thrown during test", e);
fail("Exception thrown while performing test : " + e.getMessage());
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
clean(House.class);
clean(Window.class);
}
}
Aggregations