@Before public void setUp() throws Exception { loadBalancer = new LoadBalancer(); loadBalancer.setAccountId(1000); loadBalancer.setName("integration testing"); loadBalancer.setPort(80); loadBalancer.setProtocol(LoadBalancerProtocol.POP3); Set<Node> nodes = new HashSet<Node>(); Node node = new Node(); node.setIpAddress("2.2.2.2"); node.setPort(80); node.setCondition(NodeCondition.ENABLED); nodes.add(node); loadBalancer.setNodes(nodes); UserPages userPages = new UserPages(); userPages.setErrorpage("aError"); userPages.setLoadbalancer(loadBalancer); loadBalancer.setUserPages(userPages); loadBalancer = createLoadBalancerInActiveStatus(loadBalancer); accessList = new AccessList(); accessList.setIpAddress("new ip"); accessList.setType(AccessListType.ALLOW); }
@Test(expected = BadRequestException.class) public void shouldThrowExceptionWhenAccessListLimitExceeded() throws Exception { LoadBalancer newLoadBalancer = new LoadBalancer(); newLoadBalancer.setId(loadBalancer.getId()); newLoadBalancer.setAccountId(loadBalancer.getAccountId()); accessList.setLoadbalancer(loadBalancer); for (int i = 0; i < 101; i++) { accessList = new AccessList(); accessList.setIpAddress("new ip " + i); accessList.setType(AccessListType.ALLOW); newLoadBalancer.addAccessList(accessList); } accessListService.updateAccessList(newLoadBalancer); }
@Test(expected = BadRequestException.class) public void shouldThrowExceptionWhenDuplicateAccessLists() throws Exception { LoadBalancer newLoadBalancer = new LoadBalancer(); newLoadBalancer.setId(loadBalancer.getId()); newLoadBalancer.setAccountId(loadBalancer.getAccountId()); accessList.setLoadbalancer(loadBalancer); newLoadBalancer.addAccessList(accessList); accessListService.updateAccessList(newLoadBalancer); loadBalancerService.setStatus(loadBalancer, LoadBalancerStatus.ACTIVE); newLoadBalancer.addAccessList(accessList); accessListService.updateAccessList(newLoadBalancer); }
@Test public void shouldAddNewAccessListLoadBalancerWhenOperationSucceeds() throws Exception { List<AccessList> accessListsBefore = accessListService.getAccessListByAccountIdLoadBalancerId( loadBalancer.getAccountId(), loadBalancer.getId()); LoadBalancer newLoadBalancer = new LoadBalancer(); newLoadBalancer.setId(loadBalancer.getId()); newLoadBalancer.setAccountId(loadBalancer.getAccountId()); accessList.setLoadbalancer(loadBalancer); newLoadBalancer.addAccessList(accessList); accessListService.updateAccessList(newLoadBalancer); List<AccessList> accessListsAfter = accessListService.getAccessListByAccountIdLoadBalancerId( loadBalancer.getAccountId(), loadBalancer.getId()); Assert.assertEquals(accessListsBefore.size() + 1, accessListsAfter.size()); }