@Test public void createDomainExceptionTest() throws PacManException { when(domainRepository.existsById(anyString())).thenReturn(true); assertThatThrownBy(() -> domainService.createDomain(getDomainDetailsRequest(), "user123")) .isInstanceOf(PacManException.class); }
@Override public String createDomain(final CreateUpdateDomain createUpdateDomain, final String userId) throws PacManException { boolean isDomainExits = domainRepository.existsById(createUpdateDomain.getName()); if(!isDomainExits) { Date currentDate = new Date(); Domain domain = new Domain(); domain.setDomainName(createUpdateDomain.getName()); domain.setDomainDesc(createUpdateDomain.getDesc()); domain.setConfig(createUpdateDomain.getConfig()); domain.setModifiedDate(currentDate); domain.setCreatedDate(currentDate); domain.setUserId(userId); domainRepository.save(domain); return AdminConstants.DOMAIN_CREATION_SUCCESS; } else { throw new PacManException(AdminConstants.DOMAIN_NAME_EXITS); } }
DomainServiceImpl implements DomainService, Constants { @Override public String createDomain(final CreateUpdateDomain createUpdateDomain, final String userId) throws PacManException { boolean isDomainExits = domainRepository.existsById(createUpdateDomain.getName()); if(!isDomainExits) { Date currentDate = new Date(); Domain domain = new Domain(); domain.setDomainName(createUpdateDomain.getName()); domain.setDomainDesc(createUpdateDomain.getDesc()); domain.setConfig(createUpdateDomain.getConfig()); domain.setModifiedDate(currentDate); domain.setCreatedDate(currentDate); domain.setUserId(userId); domainRepository.save(domain); return AdminConstants.DOMAIN_CREATION_SUCCESS; } else { throw new PacManException(AdminConstants.DOMAIN_NAME_EXITS); } } }
DomainServiceImpl implements DomainService, Constants { @Override public String createDomain(final CreateUpdateDomain createUpdateDomain, final String userId) throws PacManException { boolean isDomainExits = domainRepository.existsById(createUpdateDomain.getName()); if(!isDomainExits) { Date currentDate = new Date(); Domain domain = new Domain(); domain.setDomainName(createUpdateDomain.getName()); domain.setDomainDesc(createUpdateDomain.getDesc()); domain.setConfig(createUpdateDomain.getConfig()); domain.setModifiedDate(currentDate); domain.setCreatedDate(currentDate); domain.setUserId(userId); domainRepository.save(domain); return AdminConstants.DOMAIN_CREATION_SUCCESS; } else { throw new PacManException(AdminConstants.DOMAIN_NAME_EXITS); } }  }
DomainServiceImpl implements DomainService, Constants { @Override public String createDomain(final CreateUpdateDomain createUpdateDomain, final String userId) throws PacManException { boolean isDomainExits = domainRepository.existsById(createUpdateDomain.getName()); if(!isDomainExits) { Date currentDate = new Date(); Domain domain = new Domain(); domain.setDomainName(createUpdateDomain.getName()); domain.setDomainDesc(createUpdateDomain.getDesc()); domain.setConfig(createUpdateDomain.getConfig()); domain.setModifiedDate(currentDate); domain.setCreatedDate(currentDate); domain.setUserId(userId); domainRepository.save(domain); return AdminConstants.DOMAIN_CREATION_SUCCESS; } else { throw new PacManException(AdminConstants.DOMAIN_NAME_EXITS); } }  @Override Collection<String> getAllDomainNames(); @Override List<Domain> getAllDomains(); @Override Domain getDomainByName(final String domainName); @Override Page<Object[]> getAllDomainDetails(final String searchTerm, final int page, final int size); @Override String createDomain(final CreateUpdateDomain createUpdateDomain, final String userId); @Override String updateDomain(final CreateUpdateDomain createUpdateDomain, final String userId); }
DomainServiceImpl implements DomainService, Constants { @Override public String createDomain(final CreateUpdateDomain createUpdateDomain, final String userId) throws PacManException { boolean isDomainExits = domainRepository.existsById(createUpdateDomain.getName()); if(!isDomainExits) { Date currentDate = new Date(); Domain domain = new Domain(); domain.setDomainName(createUpdateDomain.getName()); domain.setDomainDesc(createUpdateDomain.getDesc()); domain.setConfig(createUpdateDomain.getConfig()); domain.setModifiedDate(currentDate); domain.setCreatedDate(currentDate); domain.setUserId(userId); domainRepository.save(domain); return AdminConstants.DOMAIN_CREATION_SUCCESS; } else { throw new PacManException(AdminConstants.DOMAIN_NAME_EXITS); } }  @Override Collection<String> getAllDomainNames(); @Override List<Domain> getAllDomains(); @Override Domain getDomainByName(final String domainName); @Override Page<Object[]> getAllDomainDetails(final String searchTerm, final int page, final int size); @Override String createDomain(final CreateUpdateDomain createUpdateDomain, final String userId); @Override String updateDomain(final CreateUpdateDomain createUpdateDomain, final String userId);  }