use of org.jpox.samples.models.fitness.Gym in project tests by datanucleus.
the class JDOQLContainerTest method testNotContainsValuesInMapFieldsInverse.
/**
* Tests NOT contains in Map.values
*/
public void testNotContainsValuesInMapFieldsInverse() {
try {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
// Create some data
tx.begin();
Gym gym = new Gym();
gym.setLocation("downtown");
Gym gym2 = new Gym();
gym2.setLocation("village");
Wardrobe wardrobe1 = new Wardrobe();
wardrobe1.setModel("1 door");
Wardrobe wardrobe2 = new Wardrobe();
wardrobe2.setModel("2 doors");
Wardrobe wardrobe3 = new Wardrobe();
wardrobe3.setModel("3 doors");
gym.getWardrobesInverse().put(wardrobe2.getModel(), wardrobe2);
gym.getWardrobesInverse().put(wardrobe3.getModel(), wardrobe3);
gym2.getWardrobesInverse().put(wardrobe1.getModel(), wardrobe1);
pm.makePersistent(gym);
pm.makePersistent(gym2);
Cloth whiteShirt = new Cloth();
whiteShirt.setName("white shirt");
Cloth blackShirt = new Cloth();
blackShirt.setName("black shirt");
Cloth skirt = new Cloth();
skirt.setName("skirt");
wardrobe3.getClothes().add(whiteShirt);
wardrobe3.getClothes().add(skirt);
wardrobe2.getClothes().add(blackShirt);
pm.flush();
// Query the data
Query q = pm.newQuery("SELECT FROM org.jpox.samples.models.fitness.Gym " + "WHERE !this.wardrobesInverse.containsValue(wrd) " + "PARAMETERS org.jpox.samples.models.fitness.Wardrobe wrd");
List results = (List) q.execute(wardrobe3);
assertEquals(1, results.size());
assertEquals("village", ((Gym) results.get(0)).getLocation());
// two !contains
q = pm.newQuery("SELECT FROM org.jpox.samples.models.fitness.Gym " + "WHERE !this.wardrobesInverse.containsValue(wrd) && !this.wardrobesInverse.containsValue(wrd2) " + "PARAMETERS org.jpox.samples.models.fitness.Wardrobe wrd,org.jpox.samples.models.fitness.Wardrobe wrd2");
results = (List) q.execute(wardrobe3, wardrobe2);
assertEquals(1, results.size());
assertEquals("village", ((Gym) results.get(0)).getLocation());
// two !contains and one contains
q = pm.newQuery("SELECT FROM org.jpox.samples.models.fitness.Gym " + "WHERE !this.wardrobesInverse.containsValue(wrd) && !this.wardrobesInverse.containsValue(wrd2) && this.wardrobesInverse.containsValue(wrd1) " + "PARAMETERS org.jpox.samples.models.fitness.Wardrobe wrd,org.jpox.samples.models.fitness.Wardrobe wrd2,org.jpox.samples.models.fitness.Wardrobe wrd1");
results = (List) q.execute(wardrobe3, wardrobe2, wardrobe1);
assertEquals(1, results.size());
assertEquals("village", ((Gym) results.get(0)).getLocation());
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();
}
} finally {
// Clean out our data
FitnessHelper.cleanFitnessData(pmf);
}
}
use of org.jpox.samples.models.fitness.Gym in project tests by datanucleus.
the class JDOQLContainerTest method testQueryUsesContainsKeyOnceOnOneUnboundVariableImplicitVariables.
/**
* Test for the Map.containsKey() method.
*/
public void testQueryUsesContainsKeyOnceOnOneUnboundVariableImplicitVariables() {
try {
Gym gym1 = new Gym();
gym1.setName("Cinema");
gym1.setLocation("First floor");
Wardrobe w1 = new Wardrobe();
Wardrobe w2 = new Wardrobe();
Wardrobe w3 = new Wardrobe();
Wardrobe w4 = new Wardrobe();
w1.setModel("2 door");
w2.setModel("3 door");
w3.setModel("4 door");
w4.setModel("5 door");
gym1.getWardrobes2().put(w1, w1.getModel());
gym1.getWardrobes2().put(w2, w2.getModel());
gym1.getWardrobes2().put(w3, w3.getModel());
gym1.getWardrobes2().put(w4, w4.getModel());
Gym gym2 = new Gym();
gym2.setName("Shopping");
gym2.setLocation("Second floor");
gym2.getWardrobes2().put(w1, w1.getModel());
gym2.getWardrobes2().put(w2, w2.getModel());
Cloth c1 = new Cloth();
c1.setName("green shirt");
Cloth c2 = new Cloth();
c2.setName("red shirt");
Cloth c3 = new Cloth();
c3.setName("blue shirt");
GymEquipment ge1 = new GymEquipment();
ge1.setName("Weight");
GymEquipment ge2 = new GymEquipment();
ge2.setName("Yoga");
GymEquipment ge3 = new GymEquipment();
ge3.setName("Pilates");
GymEquipment ge4 = new GymEquipment();
ge4.setName("Abdominal");
gym1.getEquipments2().put(ge1, ge1.getName());
gym1.getEquipments2().put(ge2, ge2.getName());
gym2.getEquipments2().put(ge3, ge3.getName());
gym2.getEquipments2().put(ge4, ge4.getName());
gym1.getPartners2().put(gym2, gym2.getName());
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
pm.makePersistent(gym1);
pm.makePersistent(gym2);
tx.commit();
tx.begin();
Query q = pm.newQuery(Gym.class);
q.setFilter("wardrobes2.containsKey(w1) && w1.model == \"4 door\"");
Collection c = (Collection) q.execute();
assertEquals(1, c.size());
q = pm.newQuery(Gym.class);
q.setFilter("wardrobes2.containsKey(w1) && (w1.model == \"2 door\" || w1.model == \"3 door\")");
c = (Collection) q.execute();
assertEquals(2, c.size());
q = pm.newQuery(Gym.class);
q.setFilter("wardrobes2.containsKey(w1) && (w1.model == \"4 door\" || w1.model == \"5 door\")");
c = (Collection) q.execute();
assertEquals(1, c.size());
try {
q = pm.newQuery(Gym.class);
q.setFilter("equipments2.containsKey(e) && g.equipments2.containsKey(e) && e.name =='Yoga'");
c = (Collection) q.execute();
fail("expected JDOUserException");
} catch (JDOUserException e) {
// expected
}
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
} finally {
// Clean out our data
FitnessHelper.cleanFitnessData(pmf);
}
}
use of org.jpox.samples.models.fitness.Gym in project tests by datanucleus.
the class JDOQLContainerTest method testNotContainsEntryInMapFieldsInverse.
/**
* Tests NOT contains in Map.entry
*/
public void testNotContainsEntryInMapFieldsInverse() {
try {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
// Create some data
tx.begin();
Gym gym = new Gym();
gym.setLocation("downtown");
Gym gym2 = new Gym();
gym2.setLocation("village");
Wardrobe wardrobe1 = new Wardrobe();
wardrobe1.setModel("1 door");
Wardrobe wardrobe2 = new Wardrobe();
wardrobe2.setModel("2 doors");
Wardrobe wardrobe3 = new Wardrobe();
wardrobe3.setModel("3 doors");
gym.getWardrobesInverse().put(wardrobe2.getModel(), wardrobe2);
gym.getWardrobesInverse().put(wardrobe3.getModel(), wardrobe3);
gym2.getWardrobesInverse().put(wardrobe1.getModel(), wardrobe1);
pm.makePersistent(gym);
pm.makePersistent(gym2);
Cloth whiteShirt = new Cloth();
whiteShirt.setName("white shirt");
Cloth blackShirt = new Cloth();
blackShirt.setName("black shirt");
Cloth skirt = new Cloth();
skirt.setName("skirt");
wardrobe3.getClothes().add(whiteShirt);
wardrobe3.getClothes().add(skirt);
wardrobe2.getClothes().add(blackShirt);
tx.commit();
// Query the data
tx.begin();
Query q = pm.newQuery("SELECT FROM org.jpox.samples.models.fitness.Gym " + "WHERE !this.wardrobesInverse.containsEntry(wrd.model,wrd) " + "PARAMETERS org.jpox.samples.models.fitness.Wardrobe wrd");
List results = (List) q.execute(wardrobe3);
assertEquals(1, results.size());
assertEquals("village", ((Gym) results.get(0)).getLocation());
// two !contains
q = pm.newQuery("SELECT FROM org.jpox.samples.models.fitness.Gym " + "WHERE !this.wardrobesInverse.containsEntry(wrd.model,wrd) && !this.wardrobesInverse.containsEntry(wrd2.model,wrd2) " + "PARAMETERS org.jpox.samples.models.fitness.Wardrobe wrd,org.jpox.samples.models.fitness.Wardrobe wrd2");
results = (List) q.execute(wardrobe3, wardrobe2);
assertEquals(1, results.size());
assertEquals("village", ((Gym) results.get(0)).getLocation());
// two !contains and one contains
q = pm.newQuery("SELECT FROM org.jpox.samples.models.fitness.Gym " + "WHERE !this.wardrobesInverse.containsEntry(wrd.model,wrd) && !this.wardrobesInverse.containsEntry(wrd2.model,wrd2) && this.wardrobesInverse.containsEntry(wrd1.model,wrd1) " + "PARAMETERS org.jpox.samples.models.fitness.Wardrobe wrd,org.jpox.samples.models.fitness.Wardrobe wrd2,org.jpox.samples.models.fitness.Wardrobe wrd1");
results = (List) q.execute(wardrobe3, wardrobe2, wardrobe1);
assertEquals(1, results.size());
assertEquals("village", ((Gym) results.get(0)).getLocation());
tx.commit();
} 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();
}
} finally {
// Clean out our data
FitnessHelper.cleanFitnessData(pmf);
}
}
use of org.jpox.samples.models.fitness.Gym in project tests by datanucleus.
the class JDOQLContainerTest method testQueryUsesContainsValueOnceOnOneUnboundVariableInverse.
/**
* Test for the Map.containsValue() method.
*/
public void testQueryUsesContainsValueOnceOnOneUnboundVariableInverse() {
try {
Gym gym1 = new Gym();
gym1.setName("Cinema");
gym1.setLocation("First floor");
Wardrobe w1 = new Wardrobe();
Wardrobe w2 = new Wardrobe();
w1.setModel("2 door");
w2.setModel("3 door");
w1.setGym(gym1);
w2.setGym(gym1);
gym1.getWardrobesInverse().put(w1.getModel(), w1);
gym1.getWardrobesInverse().put(w2.getModel(), w2);
GymEquipment ge1 = new GymEquipment();
ge1.setName("Weight");
GymEquipment ge2 = new GymEquipment();
ge2.setName("Yoga");
ge1.setGym(gym1);
ge2.setGym(gym1);
gym1.getEquipmentsInverse().put(ge1.getName(), ge1);
gym1.getEquipmentsInverse().put(ge2.getName(), ge2);
Gym gym2 = new Gym();
gym2.setName("Shopping");
gym2.setLocation("Second floor");
Wardrobe w3 = new Wardrobe();
Wardrobe w4 = new Wardrobe();
w3.setModel("4 door");
w4.setModel("5 door");
w3.setGym(gym2);
w4.setGym(gym2);
gym2.getWardrobesInverse().put(w3.getModel(), w3);
gym2.getWardrobesInverse().put(w4.getModel(), w4);
GymEquipment ge3 = new GymEquipment();
ge3.setName("Pilates");
GymEquipment ge4 = new GymEquipment();
ge4.setName("Abdominal");
ge3.setGym(gym2);
ge4.setGym(gym2);
gym2.getEquipmentsInverse().put(ge3.getName(), ge3);
gym2.getEquipmentsInverse().put(ge4.getName(), ge4);
gym2.setGym(gym1);
gym1.getPartnersInverse().put(gym2.getName(), gym2);
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
pm.makePersistent(gym1);
pm.makePersistent(gym2);
pm.flush();
assertEquals(2, gym1.getWardrobesInverse().size());
assertEquals(2, gym1.getEquipmentsInverse().size());
tx.commit();
tx.begin();
Collection c = (Collection) pm.newQuery(Gym.class).execute();
assertEquals(2, c.size());
Gym g = (Gym) c.iterator().next();
assertEquals(2, g.getWardrobesInverse().size());
assertEquals(2, g.getEquipmentsInverse().size());
g = (Gym) c.iterator().next();
assertEquals(2, g.getWardrobesInverse().size());
assertEquals(2, g.getEquipmentsInverse().size());
tx.commit();
tx.begin();
Query q = pm.newQuery(Gym.class);
q.setFilter("wardrobesInverse.containsValue(w1) && w1.model == \"4 door\"");
q.declareVariables("Wardrobe w1");
c = (Collection) q.execute();
assertEquals(1, c.size());
q = pm.newQuery(Gym.class);
q.setFilter("wardrobesInverse.containsValue(w1) && (w1.model == \"2 door\" || w1.model == \"3 door\")");
q.declareVariables("Wardrobe w1");
c = (Collection) q.execute();
assertEquals(1, c.size());
q = pm.newQuery(Gym.class);
q.setFilter("wardrobesInverse.containsValue(w1) && (w1.model == \"4 door\" || w1.model == \"5 door\")");
q.declareVariables("Wardrobe w1");
c = (Collection) q.execute();
assertEquals(1, c.size());
q = pm.newQuery(Gym.class);
q.setFilter("equipmentsInverse.containsValue(e) && g.equipmentsInverse.containsValue(e) && e.name =='Yoga'");
q.declareVariables("GymEquipment e; Gym g");
c = (Collection) q.execute();
assertEquals(1, c.size());
assertEquals("Cinema", ((Gym) c.iterator().next()).getName());
q = pm.newQuery(Gym.class);
q.setFilter("equipmentsInverse.containsValue(e) && g.equipmentsInverse.containsValue(e) && e.name =='Pilates'");
q.declareVariables("GymEquipment e; Gym g");
c = (Collection) q.execute();
assertEquals(1, c.size());
assertEquals("Shopping", ((Gym) c.iterator().next()).getName());
q = pm.newQuery(Gym.class);
q.setFilter("partnersInverse.containsValue(g) && (g.equipmentsInverse.containsValue(e) && e.name =='Pilates')");
q.declareVariables("GymEquipment e; Gym g");
c = (Collection) q.execute();
assertEquals(1, c.size());
assertEquals("Cinema", ((Gym) c.iterator().next()).getName());
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
} finally {
// Clean out our data
FitnessHelper.cleanFitnessData(pmf);
}
}
use of org.jpox.samples.models.fitness.Gym in project tests by datanucleus.
the class JDOQLContainerTest method testQueryContainsKeyOnCharacter.
/**
* Test for the Map.containsKey(Character) method.
*/
public void testQueryContainsKeyOnCharacter() {
try {
Gym gym1 = new Gym();
gym1.setName("Cinema");
gym1.setLocation("First floor");
gym1.getCodes().put(new Character('a'), new String("aaaaa"));
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
pm.makePersistent(gym1);
tx.commit();
tx.begin();
Query q = pm.newQuery(Gym.class);
q.setFilter("codes.containsKey('a')");
Collection c = (Collection) q.execute();
assertEquals(1, c.size());
q = pm.newQuery(Gym.class);
q.setFilter("codes.containsKey('b')");
c = (Collection) q.execute();
assertEquals(0, c.size());
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
} finally {
// Clean out our data
FitnessHelper.cleanFitnessData(pmf);
}
}
Aggregations