Search in sources :

Example 1 with Product

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

the class FilterTest method testIs.

public void testIs() {
    Filter f = new Filter();
    f.is("product__name", "foo");
    List<Rule> filters = f.getRules();
    Rule filter = filters.get(0);
    Statement s = filter.getStatement();
    Set<String> keys = s.getKeys();
    assertEquals("product__name", filter.getKey());
    assertTrue(keys.contains("name"));
    assertEquals("name = 'foo'", s.toString());
    Product p = new Product();
    p.setName("test product");
    p.save(getContext());
    f = new Filter();
    f.is("supplier__product", p);
    filters = f.getRules();
    filter = filters.get(0);
    s = filter.getStatement();
    keys = s.getKeys();
    assertEquals("supplier__product", filter.getKey());
    assertTrue(keys.contains("product"));
    assertEquals("product = '" + p.getId() + "'", s.toString());
}
Also used : Filter(com.orm.androrm.Filter) InStatement(com.orm.androrm.statement.InStatement) Statement(com.orm.androrm.statement.Statement) LikeStatement(com.orm.androrm.statement.LikeStatement) Product(com.orm.androrm.impl.Product) Rule(com.orm.androrm.Rule)

Example 2 with Product

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

the class FilterTest method testIn.

public void testIn() {
    Filter set = new Filter();
    List<Integer> values = new ArrayList<Integer>();
    values.add(3);
    values.add(5);
    set.in("product__id", values);
    List<Rule> filters = set.getRules();
    Rule filter = filters.get(0);
    Statement s = filter.getStatement();
    Set<String> keys = s.getKeys();
    assertEquals("product__id", filter.getKey());
    assertTrue(keys.contains("id"));
    assertTrue(s instanceof InStatement);
    assertEquals("id IN ('3','5')", s.toString());
    List<Product> products = new ArrayList<Product>();
    Product p1 = new Product();
    p1.setName("test 1");
    p1.save(getContext());
    Product p2 = new Product();
    p2.setName("test 2");
    p2.save(getContext());
    products.add(p1);
    products.add(p2);
    set = new Filter();
    set.in("supplier__product", products);
    filters = set.getRules();
    filter = filters.get(0);
    s = filter.getStatement();
    keys = s.getKeys();
    assertEquals("supplier__product", filter.getKey());
    assertTrue(keys.contains("product"));
    assertTrue(s instanceof InStatement);
    assertEquals("product IN ('" + p1.getId() + "','" + p2.getId() + "')", s.toString());
}
Also used : InStatement(com.orm.androrm.statement.InStatement) Filter(com.orm.androrm.Filter) InStatement(com.orm.androrm.statement.InStatement) Statement(com.orm.androrm.statement.Statement) LikeStatement(com.orm.androrm.statement.LikeStatement) ArrayList(java.util.ArrayList) Product(com.orm.androrm.impl.Product) Rule(com.orm.androrm.Rule)

Example 3 with Product

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

the class ForeignKeyFieldTest method testReset.

public void testReset() {
    Product p = new Product();
    p.setName("test product");
    p.save(getContext());
    ForeignKeyField<Product> fk = new ForeignKeyField<Product>(Product.class);
    fk.set(p);
    fk.reset();
    assertNull(fk.get(getContext()));
    fk.set(p.getId());
    fk.reset();
    assertNull(fk.get(getContext()));
}
Also used : ForeignKeyField(com.orm.androrm.field.ForeignKeyField) Product(com.orm.androrm.impl.Product)

Example 4 with Product

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

the class ForeignKeyFieldTest method testIsPersisted.

public void testIsPersisted() {
    ForeignKeyField<Product> fk = new ForeignKeyField<Product>(Product.class);
    Product p = new Product();
    assertFalse(fk.isPersisted());
    fk.set(p);
    assertFalse(fk.isPersisted());
    p.save(getContext());
    assertTrue(fk.isPersisted());
}
Also used : ForeignKeyField(com.orm.androrm.field.ForeignKeyField) Product(com.orm.androrm.impl.Product)

Example 5 with Product

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

the class FieldResulutionTest method testManyToManyFieldResolutionInBetween.

public void testManyToManyFieldResolutionInBetween() {
    Filter filter = new Filter();
    filter.is("mBranches__mSuppliers__mName", "ACME");
    QuerySet<Product> products = Product.objects(getContext()).filter(filter);
    assertEquals(1, products.count());
    assertTrue(products.contains(mP1));
    filter = new Filter();
    filter.is("mBranches__mSuppliers__mName", "fail");
    products = Product.objects(getContext()).filter(filter);
    assertEquals(0, products.count());
}
Also used : Filter(com.orm.androrm.Filter) 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