Search in sources :

Example 6 with Product

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;
}
Also used : Brand(com.orm.androrm.impl.Brand) Branch(com.orm.androrm.impl.Branch) ArrayList(java.util.ArrayList) Model(com.orm.androrm.Model) Product(com.orm.androrm.impl.Product) Supplier(com.orm.androrm.impl.Supplier) DatabaseAdapter(com.orm.androrm.DatabaseAdapter)

Example 7 with Product

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));
}
Also used : Brand(com.orm.androrm.impl.Brand) Branch(com.orm.androrm.impl.Branch) Product(com.orm.androrm.impl.Product)

Example 8 with Product

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));
}
Also used : Brand(com.orm.androrm.impl.Brand) Product(com.orm.androrm.impl.Product) Supplier(com.orm.androrm.impl.Supplier)

Example 9 with Product

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());
}
Also used : ForeignKeyField(com.orm.androrm.field.ForeignKeyField) TableDefinition(com.orm.androrm.TableDefinition) Product(com.orm.androrm.impl.Product)

Example 10 with Product

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());
}
Also used : Brand(com.orm.androrm.impl.Brand) Branch(com.orm.androrm.impl.Branch) Product(com.orm.androrm.impl.Product)

Aggregations

Product (com.orm.androrm.impl.Product)17 Brand (com.orm.androrm.impl.Brand)7 Supplier (com.orm.androrm.impl.Supplier)6 Filter (com.orm.androrm.Filter)5 ForeignKeyField (com.orm.androrm.field.ForeignKeyField)5 Branch (com.orm.androrm.impl.Branch)4 ArrayList (java.util.ArrayList)4 Rule (com.orm.androrm.Rule)2 TableDefinition (com.orm.androrm.TableDefinition)2 InStatement (com.orm.androrm.statement.InStatement)2 LikeStatement (com.orm.androrm.statement.LikeStatement)2 Statement (com.orm.androrm.statement.Statement)2 DatabaseAdapter (com.orm.androrm.DatabaseAdapter)1 Model (com.orm.androrm.Model)1