use of com.orm.androrm.impl.Branch in project androrm by androrm.
the class ManyToManyFieldTest method testSet.
public void testSet() {
Product p = new Product();
p.setName("test product");
p.save(getContext());
Brand b = new Brand();
b.setName("Copcal");
b.save(getContext());
Branch b1 = new Branch();
b1.setName("test branch");
b1.setBrand(b);
b1.addProduct(p);
b1.addProduct(p);
b1.save(getContext());
Branch b2 = Model.objects(getContext(), Branch.class).get(b1.getId());
assertEquals(1, b2.getProducts(getContext()).count());
assertTrue(b2.getProducts(getContext()).contains(p));
}
use of com.orm.androrm.impl.Branch in project androrm by androrm.
the class OneToManyFieldTest method testReset.
public void testReset() {
Brand b = new Brand();
b.setName("Copcal");
b.save(getContext());
Branch b1 = new Branch();
b1.setName("test1");
b1.setBrand(b);
b1.save(getContext());
Branch b2 = new Branch();
b2.setName("test2");
b2.setBrand(b);
b2.save(getContext());
Product p = new Product();
p.addBranches(Arrays.asList(new Branch[] { b1, b2 }));
p.save(getContext());
assertEquals(2, p.getBranches(getContext()).count());
p.delete(getContext());
assertEquals(0, p.getBranches(getContext()).count());
}
use of com.orm.androrm.impl.Branch in project androrm by androrm.
the class OneToManyFieldTest method testCount.
public void testCount() {
Brand b = new Brand();
b.setName("Copcal");
b.save(getContext());
Branch b1 = new Branch();
b1.setName("test1");
b1.setBrand(b);
b1.save(getContext());
Branch b2 = new Branch();
b2.setName("test2");
b2.setBrand(b);
b2.save(getContext());
b = Brand.objects(getContext()).get(b.getId());
assertEquals(2, b.branchCount(getContext()));
}
use of com.orm.androrm.impl.Branch 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.Branch in project androrm by androrm.
the class FieldResulutionTest method testOneToManyResolutionLastField.
public void testOneToManyResolutionLastField() {
List<Branch> branches = new ArrayList<Branch>();
branches.add(mB1);
branches.add(mB2);
Filter filter = new Filter();
filter.in("mProducts__mBranches", branches);
QuerySet<Supplier> suppliers = Supplier.objects(getContext()).filter(filter);
assertEquals(1, suppliers.count());
assertTrue(suppliers.contains(mS1));
branches.remove(0);
filter = new Filter();
filter.in("mProducts__mBranches", branches);
suppliers = Supplier.objects(getContext()).filter(filter);
assertEquals(0, suppliers.count());
}
Aggregations