Ejemplo n.º 1
0
  @Test
  public void testMailRoutingPolicyUpdateAndGetDomainsByPolicy() throws Exception {
    int custId = createCustomer("testMailRoutingPolicyUpdateAndGetDomainsByPolicy");
    int defPolicyId =
        createMailRoutingPolicy(
            custId, "testMailRoutingPolicyUpdateAndGetDomainsByPolicyDefPolicy", true);
    int policyId =
        createMailRoutingPolicy(custId, "testMailRoutingPolicyUpdateAndGetDomainsByPolicy", false);
    List<String> custDomains = createCustomerDomains(custId, defPolicyId);
    CustomerDomainDAO dao = createDao();
    Connection conn = null;
    try {
      conn = getDBConnection();
      List<CustomerDomain> domains = dao.getDomainsForMailRoutingPolicy(234232, conn);
      assertEquals("Wrong number of domains returned from random policy id.", 0, domains.size());

      domains = dao.getDomainsForMailRoutingPolicy(policyId, conn);
      assertEquals("Wrong number of domains returned for policy " + policyId, 0, domains.size());

      dao.updateMailRoutingPolicy(custId, custDomains.get(0), policyId, conn);

      domains = dao.getDomainsForMailRoutingPolicy(policyId, conn);
      assertEquals("Wrong number of domains returned.", 1, domains.size());
      assertEquals(
          "Wrong domain name returned.", custDomains.get(0), domains.get(0).getDomainName());

      // verify domain removal from policy
      dao.updateMailRoutingPolicy(custId, custDomains.get(0), null, conn);
      domains = dao.getDomainsForMailRoutingPolicy(policyId, conn);
      assertEquals("Wrong number of domains returned after id was removed.", 0, domains.size());

      for (String dom : custDomains) {
        dao.updateMailRoutingPolicy(custId, dom, policyId, conn);
      }
      domains = dao.getDomainsForMailRoutingPolicy(policyId, conn);
      assertEquals(
          "Wrong number of domains returned after id was set back.",
          custDomains.size(),
          domains.size());
      for (String dom : custDomains) {
        checkDomainList(domains, dom);
      }
    } finally {
      if (conn != null) {
        conn.close();
      }
    }
  }
Ejemplo n.º 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();
      }
    }
  }
Ejemplo n.º 3
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();
      }
    }
  }