use of com.orm.androrm.impl.Product in project androrm by androrm.
the class FilterTest method testIs.
public void testIs() {
Filter f = new Filter();
f.is("product__name", "foo");
List<Rule> filters = f.getRules();
Rule filter = filters.get(0);
Statement s = filter.getStatement();
Set<String> keys = s.getKeys();
assertEquals("product__name", filter.getKey());
assertTrue(keys.contains("name"));
assertEquals("name = 'foo'", s.toString());
Product p = new Product();
p.setName("test product");
p.save(getContext());
f = new Filter();
f.is("supplier__product", p);
filters = f.getRules();
filter = filters.get(0);
s = filter.getStatement();
keys = s.getKeys();
assertEquals("supplier__product", filter.getKey());
assertTrue(keys.contains("product"));
assertEquals("product = '" + p.getId() + "'", s.toString());
}
use of com.orm.androrm.impl.Product in project androrm by androrm.
the class FilterTest method testIn.
public void testIn() {
Filter set = new Filter();
List<Integer> values = new ArrayList<Integer>();
values.add(3);
values.add(5);
set.in("product__id", values);
List<Rule> filters = set.getRules();
Rule filter = filters.get(0);
Statement s = filter.getStatement();
Set<String> keys = s.getKeys();
assertEquals("product__id", filter.getKey());
assertTrue(keys.contains("id"));
assertTrue(s instanceof InStatement);
assertEquals("id IN ('3','5')", s.toString());
List<Product> products = new ArrayList<Product>();
Product p1 = new Product();
p1.setName("test 1");
p1.save(getContext());
Product p2 = new Product();
p2.setName("test 2");
p2.save(getContext());
products.add(p1);
products.add(p2);
set = new Filter();
set.in("supplier__product", products);
filters = set.getRules();
filter = filters.get(0);
s = filter.getStatement();
keys = s.getKeys();
assertEquals("supplier__product", filter.getKey());
assertTrue(keys.contains("product"));
assertTrue(s instanceof InStatement);
assertEquals("product IN ('" + p1.getId() + "','" + p2.getId() + "')", s.toString());
}
use of com.orm.androrm.impl.Product in project androrm by androrm.
the class ForeignKeyFieldTest method testReset.
public void testReset() {
Product p = new Product();
p.setName("test product");
p.save(getContext());
ForeignKeyField<Product> fk = new ForeignKeyField<Product>(Product.class);
fk.set(p);
fk.reset();
assertNull(fk.get(getContext()));
fk.set(p.getId());
fk.reset();
assertNull(fk.get(getContext()));
}
use of com.orm.androrm.impl.Product in project androrm by androrm.
the class ForeignKeyFieldTest method testIsPersisted.
public void testIsPersisted() {
ForeignKeyField<Product> fk = new ForeignKeyField<Product>(Product.class);
Product p = new Product();
assertFalse(fk.isPersisted());
fk.set(p);
assertFalse(fk.isPersisted());
p.save(getContext());
assertTrue(fk.isPersisted());
}
use of com.orm.androrm.impl.Product in project androrm by androrm.
the class FieldResulutionTest method testManyToManyFieldResolutionInBetween.
public void testManyToManyFieldResolutionInBetween() {
Filter filter = new Filter();
filter.is("mBranches__mSuppliers__mName", "ACME");
QuerySet<Product> products = Product.objects(getContext()).filter(filter);
assertEquals(1, products.count());
assertTrue(products.contains(mP1));
filter = new Filter();
filter.is("mBranches__mSuppliers__mName", "fail");
products = Product.objects(getContext()).filter(filter);
assertEquals(0, products.count());
}
Aggregations