/** * {@inheritDoc} */ @Override public AgentMappings saveAgentMappings(AgentMappings agentMappings) throws BusinessException { try { return ciManager.saveAgentMappings(agentMappings, true); } catch (JAXBException e) { throw new TechnicalException("Update the agent mappings.", ConfigurationInterfaceErrorCodeEnum.JAXB_MARSHALLING_OR_DEMARSHALLING_FAILED, e); } catch (IOException e) { throw new TechnicalException("Update the agent mappings.", ConfigurationInterfaceErrorCodeEnum.INPUT_OUTPUT_OPERATION_FAILED, e); } }
/** * Deletes the existing environment. * * @param environment * Environment to delete. * @throws IOException * If {@link IOException} occurs during delete. */ public void deleteEnvironment(Environment environment) throws IOException { String id = environment.getId(); Environment local = existingEnvironments.remove(id); if (null != local) { Files.deleteIfExists(pathResolver.getEnvironmentFilePath(local)); AgentMappings agentMappings = agentMappingsReference.get(); if (checkEnvironments(agentMappings)) { try { saveAgentMappings(agentMappings, false); } catch (Exception e) { log.error("Update of the agent mappings on the environment deletion failed.", e); } } } }
@Test(expectedExceptions = BusinessException.class) public void mappingsRevisionFails() throws Exception { AgentMappings mappings = new AgentMappings(); mappings.setRevision(0); manager.saveAgentMappings(mappings, false); } }
@Test public void mappings() throws Exception { AgentMappings mappings = manager.getAgentMappings(); List<AgentMapping> list = new ArrayList<>(); AgentMapping mapping = new AgentMapping("test", "test"); list.add(mapping); mappings.setMappings(list); manager.saveAgentMappings(mappings, false); assertThat(mappings.getRevision(), is(2)); }
@Test public void mappingsCheckEnvironments() throws Exception { AgentMappings mappings = manager.getAgentMappings(); List<AgentMapping> list = new ArrayList<>(); AgentMapping mapping = new AgentMapping("test", "test"); mapping.setEnvironmentId("non-existing-env-id"); list.add(mapping); mappings.setMappings(list); manager.saveAgentMappings(mappings, true); assertThat(mappings.getRevision(), is(2)); assertThat(mappings.getMappings(), is(empty())); }
@Test public void deleteEnvironmentUpdateMappings() throws Exception { Environment environment = new Environment(); environment.setName("test"); environment = manager.createEnvironment(environment); AgentMappings mappings = manager.getAgentMappings(); List<AgentMapping> list = new ArrayList<>(); AgentMapping mapping = new AgentMapping("test", "test"); mapping.setEnvironmentId(environment.getId()); list.add(mapping); mappings.setMappings(list); manager.saveAgentMappings(mappings, true); manager.deleteEnvironment(environment); assertThat(manager.getAgentMappings().getMappings(), is(empty())); } }