KeeperContainerServiceImpl extends AbstractConsoleService<KeepercontainerTblDao> implements KeeperContainerService { @Override public void addKeeperContainer(final KeeperContainerCreateInfo createInfo) { KeepercontainerTbl proto = dao.createLocal(); if(keeperContainerAlreadyExists(createInfo)) { throw new IllegalArgumentException("Keeper Container with IP: " + createInfo.getKeepercontainerIp() + " already exists"); } if (!checkIpAndPort(createInfo.getKeepercontainerIp(), createInfo.getKeepercontainerPort())) { throw new IllegalArgumentException(String.format("Keeper container with ip:%s, port:%d is unhealthy", createInfo.getKeepercontainerIp(), createInfo.getKeepercontainerPort())); } DcTbl dcTbl = dcService.find(createInfo.getDcName()); if(dcTbl == null) { throw new IllegalArgumentException("DC name does not exist"); } OrganizationTbl org; if(createInfo.getKeepercontainerOrgId() == 0) { org = new OrganizationTbl().setId(0L); } else { org = organizationService.getOrganizationTblByCMSOrganiztionId(createInfo.getKeepercontainerOrgId()); if (org == null) { throw new IllegalArgumentException("Org Id does not exist in database"); } } proto.setKeepercontainerDc(dcTbl.getId()) .setKeepercontainerIp(createInfo.getKeepercontainerIp()) .setKeepercontainerPort(createInfo.getKeepercontainerPort()) .setKeepercontainerOrgId(org.getId()) .setKeepercontainerActive(createInfo.isActive()); queryHandler.handleInsert(new DalQuery<Integer>() { @Override public Integer doQuery() throws DalException { return dao.insert(proto); } }); }  @Override KeepercontainerTbl find(final long id); @Override List<KeepercontainerTbl> findAllByDcName(final String dcName); @Override List<KeepercontainerTbl> findAllActiveByDcName(String dcName); @Override List<KeepercontainerTbl> findKeeperCount(String dcName); @Override List<KeepercontainerTbl> findBestKeeperContainersByDcCluster(String dcName, String clusterName); @Override void addKeeperContainer(final KeeperContainerCreateInfo createInfo); @Override List<KeeperContainerCreateInfo> getDcAllKeeperContainers(String dc); @Override void updateKeeperContainer(KeeperContainerCreateInfo createInfo); @Override List<KeeperContainerInfoModel> findAllInfos();  }
@Test(expected = IllegalArgumentException.class) public void testAddKeeperContainer() { KeeperContainerCreateInfo createInfo = new KeeperContainerCreateInfo(); keeperContainerService.addKeeperContainer(createInfo); }
@Test(expected = IllegalArgumentException.class) public void testAddKeeperContainer3() { KeeperContainerCreateInfo createInfo = new KeeperContainerCreateInfo() .setDcName(dcNames[0]).setKeepercontainerIp("127.0.0.1") .setKeepercontainerPort(9090).setKeepercontainerOrgId(3L); keeperContainerService.addKeeperContainer(createInfo); try { keeperContainerService.addKeeperContainer(createInfo); } catch (Exception e) { Assert.assertEquals("Keeper Container with IP: " + createInfo.getKeepercontainerIp() + " already exists", e.getMessage()); throw e; } }