Пример #1
0
  @Test
  public void testAddAndDeleteDomains() throws Exception {
    int custId = createCustomer("testAddDeleteDomain");
    int policyId = createMailRoutingPolicy(custId, "testAddAndDeleteDomains", false);
    List<String> custDomains = createCustomerDomains(custId, policyId);
    CustomerDomainDAO dao = createDao();
    Connection conn = null;
    try {
      conn = getDBConnection();

      List<CustomerDomain> domains = dao.getDomainsForCustomer(custId, conn);
      assertEquals("Wrong number of domains for customer.", custDomains.size(), domains.size());

      dao.addDomain(custId, "new_domain1", policyId, conn);
      dao.addDomain(custId, "new_domain2", policyId, conn);

      domains = dao.getDomainsForCustomer(custId, conn);
      assertEquals("Wrong number of domains for customer.", custDomains.size() + 2, domains.size());
      for (String dom : custDomains) {
        checkDomainList(domains, dom);
      }
      checkDomainList(domains, "new_domain1");
      checkDomainList(domains, "new_domain2");

      assertEquals(
          "Wrong # of domains deleted.",
          custDomains.size() + 2,
          dao.deleteByCustomerId(custId, conn));

      domains = dao.getDomainsForCustomer(custId, conn);
      assertEquals("Wrong number of domains for customer.", 0, domains.size());
    } finally {
      if (conn != null) {
        conn.close();
      }
    }
  }
Пример #2
0
  @Test
  public void testDeleteDomain() throws Exception {
    int custId = createCustomer("testDeleteDomain");
    int policyId = createMailRoutingPolicy(custId, "testMailRoutingPolicy", true);
    List<String> custDomains = createCustomerDomains(custId, policyId);
    CustomerDomainDAO dao = createDao();
    Connection conn = null;
    try {
      conn = getDBConnection();
      List<CustomerDomain> domains = dao.getDomainsForCustomer(custId, conn);
      assertEquals("Wrong number of domains returned.", custDomains.size(), domains.size());

      for (String dom : custDomains) {
        assertTrue("Failed to delete domain " + dom, dao.deleteDomain(custId, dom, conn));
      }

      domains = dao.getDomainsForCustomer(custId, conn);
      assertEquals("Wrong number of domains returned.", 0, domains.size());
    } finally {
      if (conn != null) {
        conn.close();
      }
    }
  }