Search in sources :

Example 11 with Brand

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

Example 12 with Brand

use of com.orm.androrm.impl.Brand in project androrm by androrm.

the class ManyToManyFieldTest method testReset.

public void testReset() {
    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());
    assertEquals(2, s.getProducts(getContext()).count());
    s.delete(getContext());
    assertEquals(0, s.getProducts(getContext()).count());
}
Also used : Brand(com.orm.androrm.impl.Brand) Product(com.orm.androrm.impl.Product) Supplier(com.orm.androrm.impl.Supplier)

Example 13 with Brand

use of com.orm.androrm.impl.Brand in project androrm by androrm.

the class ManyToManyFieldTest method testCount.

public void testCount() {
    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 }));
    assertEquals(0, s.productCount(getContext()));
    s.save(getContext());
    s = Supplier.objects(getContext()).get(s.getId());
    assertEquals(2, s.productCount(getContext()));
}
Also used : Brand(com.orm.androrm.impl.Brand) Product(com.orm.androrm.impl.Product) Supplier(com.orm.androrm.impl.Supplier)

Aggregations

Brand (com.orm.androrm.impl.Brand)13 Branch (com.orm.androrm.impl.Branch)8 Product (com.orm.androrm.impl.Product)7 Supplier (com.orm.androrm.impl.Supplier)6 DatabaseAdapter (com.orm.androrm.DatabaseAdapter)2 Model (com.orm.androrm.Model)2 ArrayList (java.util.ArrayList)2