Beispiel #1
0
  @SuppressWarnings("unchecked")
  @Test
  public void testAppendUserStateConstraint() throws Exception {
    CustomerDAO dao = new CustomerDAO();

    SearchConstraint sc =
        new SearchConstraint(
            ICustomerService.PROP_USERS_IN_STATE,
            SearchConstraintOperator.CONSTRAINT_EQUALS,
            "val3");
    String got = dao.appendUserStateConstraint(sc);
    String expected =
        CustomerDAO.SQL_CUSTOMER_QUERY_USER_CONSTRAINT + "= E'val3' and uc.user_count > 0) ";
    assertEquals("Wrong constraint added.", expected, got);
  }
Beispiel #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());
  }