use of com.orm.androrm.impl.Product in project androrm by androrm.
the class FieldResulutionTest method testOneToManyResolutionOnlyField.
public void testOneToManyResolutionOnlyField() {
List<Branch> branches = new ArrayList<Branch>();
branches.add(mB1);
branches.add(mB2);
Filter filter = new Filter();
filter.in("mBranches", branches);
QuerySet<Product> products = Product.objects(getContext()).filter(filter);
assertEquals(1, products.count());
assertTrue(products.contains(mP1));
branches.remove(0);
filter = new Filter();
filter.in("mBranches", branches);
products = Product.objects(getContext()).filter(filter);
assertEquals(0, products.count());
}
use of com.orm.androrm.impl.Product in project androrm by androrm.
the class FieldResulutionTest method testManyToManyFieldResolutionLastField.
public void testManyToManyFieldResolutionLastField() {
List<Supplier> suppliers = new ArrayList<Supplier>();
suppliers.add(mS1);
Filter filter = new Filter();
filter.in("mBranches__mSuppliers", suppliers);
QuerySet<Product> products = Product.objects(getContext()).filter(filter);
assertEquals(1, products.count());
assertTrue(products.contains(mP1));
suppliers.clear();
filter = new Filter();
filter.in("mBranches__mSuppliers", suppliers);
products = Product.objects(getContext()).filter(filter);
assertEquals(0, products.count());
}
use of com.orm.androrm.impl.Product in project androrm by androrm.
the class TableDefinitionTest method testForeignKeyField.
public void testForeignKeyField() {
TableDefinition def = new TableDefinition("foo");
ForeignKeyField<Product> fk = new ForeignKeyField<Product>(Product.class);
def.addField("product", fk);
assertEquals("CREATE TABLE IF NOT EXISTS `foo` (" + "`product` integer," + "FOREIGN KEY (`product`) " + "REFERENCES `product` (`mId`) " + "ON DELETE CASCADE);", def.toString());
}
use of com.orm.androrm.impl.Product in project androrm by androrm.
the class ForeignKeyFieldTest method testSetAndGet.
public void testSetAndGet() {
Product p = new Product();
p.setName("test product");
ForeignKeyField<Product> fk = new ForeignKeyField<Product>(Product.class);
fk.set(p);
assertEquals(p.getName(), fk.get(getContext()).getName());
p.save(getContext());
fk = new ForeignKeyField<Product>(Product.class);
fk.set(p.getId());
assertEquals(p.getName(), fk.get(getContext()).getName());
}
use of com.orm.androrm.impl.Product in project androrm by androrm.
the class ManyToManyFieldTest method testAddAllAndGet.
public void testAddAllAndGet() {
Product p1 = new Product();
p1.setName("test1");
p1.save(getContext());
Product p2 = new Product();
p2.setName("test2");
p2.save(getContext());
Brand b = new Brand();
b.setName("Copcal");
b.save(getContext());
Supplier s = new Supplier();
s.setName("ACME");
s.setBrand(b);
s.addProducts(Arrays.asList(new Product[] { p1, p2 }));
s.save(getContext());
s = Supplier.objects(getContext()).get(s.getId());
QuerySet<Product> products = s.getProducts(getContext());
assertEquals(2, products.count());
assertTrue(products.contains(p1));
assertTrue(products.contains(p2));
}
Aggregations