use of com.orm.androrm.impl.Product in project androrm by androrm.
the class FieldResulutionTest method setUp.
@Override
public void setUp() {
List<Class<? extends Model>> models = new ArrayList<Class<? extends Model>>();
models.add(Product.class);
models.add(Branch.class);
models.add(Supplier.class);
models.add(Brand.class);
DatabaseAdapter adapter = DatabaseAdapter.getInstance(getContext());
adapter.setModels(models);
Brand b = new Brand();
b.setName("Copcal");
b.save(getContext());
mB = b;
// ID 1
Branch b1 = new Branch();
b1.setName("Cashbuild Pretoria");
b1.setBrand(b);
b1.save(getContext());
mB1 = b1;
// ID 2
Branch b2 = new Branch();
b2.setName("Plumblink Pretoria");
b2.setBrand(b);
b2.save(getContext());
mB2 = b2;
// ID 3
Branch b3 = new Branch();
b3.setName("The third Branch");
b3.setBrand(b);
b3.save(getContext());
mB3 = b3;
// ID 1
Product p1 = new Product();
p1.setName("ofen");
p1.addBranch(b1);
p1.addBranch(b3);
p1.save(getContext());
mP1 = p1;
Supplier s1 = new Supplier();
s1.setName("ACME");
s1.setBrand(b);
s1.addProduct(p1);
s1.addBranch(b1);
s1.save(getContext());
mS1 = s1;
}
use of com.orm.androrm.impl.Product 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.Product in project androrm by androrm.
the class ManyToManyFieldTest method testAddAndGet.
public void testAddAndGet() {
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.addProduct(p1);
s.addProduct(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));
}
use of com.orm.androrm.impl.Product in project androrm by androrm.
the class TableDefinitionTest method testForeignKeyNotCascading.
public void testForeignKeyNotCascading() {
TableDefinition def = new TableDefinition("foo");
ForeignKeyField<Product> fk = new ForeignKeyField<Product>(Product.class);
fk.doNotCascade();
def.addField("product", fk);
assertEquals("CREATE TABLE IF NOT EXISTS `foo` (" + "`product` integer," + "FOREIGN KEY (`product`) " + "REFERENCES `product` (`mId`) " + "ON DELETE SET NULL);", def.toString());
}
use of com.orm.androrm.impl.Product 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());
}
Aggregations