@GET("childByKind") public List<Child> childByKind(Map<String, String> params) { List<Child> children = yawp(Child.class).where("kindOfChild", "=", params.get("kindOfChild")).list(); return children; }
@Test public void testWhereInWithEmptyList() { saveManyBasicObjects(1); List<BasicObject> objects = yawp(BasicObject.class).where("intValue", "in", Collections.emptyList()).list(); assertEquals(0, objects.size()); }
@Test public void testWhereInWithNullList() { saveManyBasicObjects(1); List<BasicObject> objects = yawp(BasicObject.class).where("intValue", "in", null).list(); assertEquals(0, objects.size()); }
@Test public void testAtomicRollback() { try { put(uri("/parents/atomic_rollback")); } catch (FakeException e) { } assertEquals(0, yawp(Parent.class).list().size()); }
@Test public void testCursor() { saveManyBasicObjects(3); QueryBuilder<BasicObject> q = yawp(BasicObject.class).order("intValue", "desc").limit(1); List<BasicObject> objects1 = q.list(); assertEquals(3, objects1.get(0).getIntValue()); List<BasicObject> objects2 = q.list(); assertEquals(2, objects2.get(0).getIntValue()); List<BasicObject> objects3 = yawp(BasicObject.class).cursor(q.getCursor()).order("intValue", "desc").limit(1).list(); assertEquals(1, objects3.get(0).getIntValue()); }
@Test public void testLimit() { saveManyBasicObjects(3); List<BasicObject> objects = yawp(BasicObject.class).order("intValue", "desc").limit(1).list(); assertEquals(1, objects.size()); assertEquals(3, objects.get(0).getIntValue()); }
@Test public void testQueryFromOptions() { saveManyBasicObjects(3); QueryOptions options = QueryOptions .parse("{where: ['stringValue', '=', 'xpto'], order: [{p: 'intValue', d: 'desc'}], limit: 2}"); List<BasicObject> objects = yawp(BasicObject.class).options(options).list(); assertEquals(2, objects.size()); assertEquals(3, objects.get(0).getIntValue()); assertEquals(2, objects.get(1).getIntValue()); }
@Test public void testWhereInWithEmptyListOrTrueExpression() { saveManyBasicObjects(3); BaseCondition emptyListCondition = c("intValue", "in", Collections.emptyList()); BaseCondition condition = or(emptyListCondition, c("stringValue", "=", "xpto")); List<BasicObject> objects = yawp(BasicObject.class).where(condition).list(); assertEquals(3, objects.size()); }
@Test public void testWhereInWithEmptyListAndFalseExpression() { saveManyBasicObjects(1); BaseCondition emptyListCondition = c("intValue", "in", Collections.emptyList()); BaseCondition condition = and(emptyListCondition, c("stringValue", "=", "otpx")); List<BasicObject> objects = yawp(BasicObject.class).where(condition).list(); assertEquals(0, objects.size()); }
@Test public void testWhereWithUnicode() { yawp.save(new BasicObject("\u00c1")); List<BasicObject> objects = yawp(BasicObject.class).where("stringValue", "=", "\u00c1").list(); assertEquals(1, objects.size()); assertEquals("\u00c1", objects.get(0).getStringValue()); }
@Test public void testWhere() { saveManyBasicObjects(3); yawp.save(new BasicObject("different")); List<BasicObject> objects = yawp(BasicObject.class).where("stringValue", "=", "xpto").list(); assertEquals(3, objects.size()); assertEquals(1, objects.get(0).getIntValue()); assertEquals(2, objects.get(1).getIntValue()); assertEquals(3, objects.get(2).getIntValue()); }
@PUT("touched") public List<Parent> touch() { List<Parent> parents = yawp(Parent.class).order("name").list(); for (Parent parent : parents) { parent.setName("touched " + parent.getName()); } return parents; }
@Test public void testTransactionRollback() { yawp.begin(); yawp.save(new BasicObject()); yawp.rollback(); assertEquals(0, yawp(BasicObject.class).list().size()); }
@Test public void testWhereWithOr() { saveManyBasicObjects(2); List<BasicObject> objects = yawp(BasicObject.class).where(or(c("intValue", "=", 1), c("intValue", "=", 2))).list(); assertEquals(2, objects.size()); sort(objects); assertEquals(2, objects.size()); assertEquals("xpto", objects.get(0).getStringValue()); assertEquals(1, objects.get(0).getIntValue()); assertEquals("xpto", objects.get(1).getStringValue()); assertEquals(2, objects.get(1).getIntValue()); }
@Test public void testFindByIdUsingWhereIn() { BasicObject object1 = new BasicObject("xpto1"); yawp.save(object1); BasicObject object2 = new BasicObject("xpto2"); yawp.save(object2); final List<IdRef<BasicObject>> ids = Arrays.asList(object1.getId(), object2.getId()); List<BasicObject> objects = yawp(BasicObject.class).where("id", "in", ids).order("stringValue").list(); assertEquals(2, objects.size()); assertEquals("xpto1", objects.get(0).getStringValue()); assertEquals("xpto2", objects.get(1).getStringValue()); }
@Test public void testWhereWithOrNot() { saveManyBasicObjects(3); List<BasicObject> objects = yawp(BasicObject.class).where(or(c("intValue", "=", 1), c("intValue", "=", 2)).not()).list(); assertEquals(1, objects.size()); assertEquals("xpto", objects.get(0).getStringValue()); assertEquals(3, objects.get(0).getIntValue()); }
@PUT("touched") public List<Child> touchCollection(IdRef<Parent> parentId) { List<Child> childs = yawp(Child.class).from(parentId).order("name").list(); for (Child child : childs) { child.setName("touched " + child.getName()); } return childs; }
@Test public void testAfterDestroy() { HookedObject objectToDelete = new HookedObject(); yawp.save(objectToDelete); yawp.destroy(objectToDelete.getId()); List<BasicObject> objects = yawp(BasicObject.class).where("stringValue", "=", "afterDestroy test: " + objectToDelete.getId()) .list(); assertEquals(1, objects.size()); }
@Test public void testBeforeDestroy() { HookedObject objectToDelete = new HookedObject("beforeDestroy test"); yawp.save(objectToDelete); yawp.destroy(objectToDelete.getId()); List<BasicObject> objects = yawp(BasicObject.class).where("stringValue", "=", "beforeDestroy test: " + objectToDelete.getId()) .list(); assertEquals(1, objects.size()); }
@Test public void testInOperator() { Parent parent1 = new Parent("xpto1"); yawp.save(parent1); Parent parent2 = new Parent("xpto2"); yawp.save(parent2); Parent parent3 = new Parent("xpto3"); yawp.save(parent3); List<IdRef<Parent>> inList = Arrays.asList(parent1.getId(), parent2.getId()); List<Parent> objects = yawp(Parent.class).where("id", "in", inList).list(); assertEquals(2, objects.size()); }