Пример #1
0
  @SuppressWarnings("unchecked")
  @Test
  public void testAppendDomainConstraint() throws Exception {
    CustomerDAO dao = new CustomerDAO();

    // list
    List<String> list = new LinkedList<String>();
    list.add("domain0");
    list.add("domain1");
    SearchConstraint sc =
        new SearchConstraint("TEST_PROP", SearchConstraintOperator.CONSTRAINT_IN_LIST, list);
    String got = dao.appendDomainConstraint(sc);
    String expected =
        CustomerDAO.SQL_CUSTOMER_QUERY_DOMAIN_CONSTRAINT + "in (E'domain0',E'domain1'))";
    assertEquals("Wrong constraint added.", expected, got);

    // equal
    sc = new SearchConstraint("TEST_PROP", SearchConstraintOperator.CONSTRAINT_EQUALS, "domain3");
    got = dao.appendDomainConstraint(sc);
    expected = CustomerDAO.SQL_CUSTOMER_QUERY_DOMAIN_CONSTRAINT + "= E'domain3')";
    assertEquals("Wrong constraint added.", expected, got);
  }
Пример #2
0
  @SuppressWarnings("unchecked")
  @Test
  public void testAppendConstraints() throws Exception {
    CustomerDAO dao =
        EasyMock.createMockBuilder(CustomerDAO.class)
            .addMockedMethod("appendDomainConstraint")
            .addMockedMethod("appendCloudServiceGuidConstraint")
            .addMockedMethod("appendCustomerPrefixConstraint")
            .addMockedMethod("appendUserStateConstraint")
            .createStrictMock();
    List<SearchConstraint> constraints = new LinkedList<SearchConstraint>();

    // domain constraint
    SearchConstraint sc =
        new SearchConstraint(
            ICustomerService.PROP_DOMAINS, SearchConstraintOperator.CONSTRAINT_EQUALS, "blah");
    constraints.add(sc);
    EasyMock.expect(dao.appendDomainConstraint(EasyMock.eq(sc))).andReturn("a");

    // cloud service guid
    sc =
        new SearchConstraint(
            ICustomerService.PROP_CLOUD_SERVICE_GUID,
            SearchConstraintOperator.CONSTRAINT_EQUALS,
            "blah");
    constraints.add(sc);
    EasyMock.expect(dao.appendCloudServiceGuidConstraint(EasyMock.eq(sc))).andReturn("b");
    sc =
        new SearchConstraint(
            ICustomerService.PROP_CLOUD_SERVICE_ANY_GUID,
            SearchConstraintOperator.CONSTRAINT_EQUALS,
            "blah");
    constraints.add(sc);
    EasyMock.expect(dao.appendCloudServiceGuidConstraint(EasyMock.eq(sc))).andReturn("c");

    // customer prefix
    sc =
        new SearchConstraint(
            ICustomerService.PROP_CUST_CAPABILITY_PREFIX,
            SearchConstraintOperator.CONSTRAINT_EQUALS,
            "blah");
    constraints.add(sc);
    dao.appendCustomerPrefixConstraint(EasyMock.eq(sc), EasyMock.isA(StringBuffer.class));
    EasyMock.expectLastCall();

    // users in state
    sc =
        new SearchConstraint(
            ICustomerService.PROP_USERS_IN_STATE,
            SearchConstraintOperator.CONSTRAINT_EQUALS,
            "blah");
    constraints.add(sc);
    EasyMock.expect(dao.appendUserStateConstraint(EasyMock.eq(sc))).andReturn("d");

    // users NOT in state
    sc =
        new SearchConstraint(
            ICustomerService.PROP_NO_USERS_IN_STATE,
            SearchConstraintOperator.CONSTRAINT_EQUALS,
            "blah");
    constraints.add(sc);
    EasyMock.expect(dao.appendUserStateConstraint(EasyMock.eq(sc))).andReturn("e");

    StringBuilder whereClause = new StringBuilder();
    EasyMock.replay(dao);
    dao.appendConstraints(constraints, whereClause);
    EasyMock.verify(dao);

    String expected = " and (a) and (b) and (c) and (not )";
    assertEquals("Wrong where clause returned.", expected, whereClause.toString());
  }