SpringBeanService { public void removeBeanDefinition(File configFile, Project project, String id) { Source xsltSource; Source xmlSource; try { xsltSource = new StreamSource(new ClassPathResource("transform/delete-bean.xsl").getInputStream()); xsltSource.setSystemId("delete-bean"); List<File> configFiles = new ArrayList<>(); configFiles.add(configFile); configFiles.addAll(getConfigImports(configFile, project)); for (File file : configFiles) { String source = FileUtils.readToString(new FileInputStream(configFile)); xmlSource = new StringSource(source); Transformer transformer = transformerFactory.newTransformer(xsltSource); transformer.setParameter("bean_id", id); StringResult result = new StringResult(); transformer.transform(xmlSource, result); FileUtils.writeToFile(format(postProcess(source, result.toString()), project.getSettings().getTabSize()), file); return; } } catch (IOException e) { throw new ApplicationRuntimeException(UNABLE_TO_READ_TRANSFORMATION_SOURCE, e); } catch (TransformerException e) { throw new ApplicationRuntimeException(FAILED_TO_UPDATE_BEAN_DEFINITION, e); } }  List<File> getConfigImports(File configFile, Project project); T getBeanDefinition(File configFile, Project project, String id, Class<T> type); List<T> getBeanDefinitions(File configFile, Project project, Class<T> type); List<T> getBeanDefinitions(File configFile, Project project, Class<T> type, Map<String, String> attributes); List<String> getBeanNames(File configFile, Project project, String beanType); void addBeanDefinition(File configFile, Project project, Object jaxbElement); void removeBeanDefinition(File configFile, Project project, String id); void removeBeanDefinitions(File configFile, Project project, Class<?> type); void removeBeanDefinitions(File configFile, Project project, Class<?> type, String attributeName, String attributeValue); void updateBeanDefinition(File configFile, Project project, String id, Object jaxbElement); void updateBeanDefinitions(File configFile, Project project, Class<?> type, Object jaxbElement); void updateBeanDefinitions(File configFile, Project project, Class<?> type, Object jaxbElement, String attributeName, String attributeValue); void setSpringBeanMarshaller(SpringBeanMarshaller springBeanMarshaller); static final String FAILED_TO_UPDATE_BEAN_DEFINITION; static final String UNABLE_TO_READ_TRANSFORMATION_SOURCE; }
@Test public void testRemoveBeanDefinition() throws Exception { File tempFile = createTempContextFile("citrus-context-remove"); springBeanConfigService.removeBeanDefinition(tempFile, project, "deleteMe"); springBeanConfigService.removeBeanDefinition(tempFile, project, "deleteMeName"); springBeanConfigService.removeBeanDefinition(tempFile, project, "helloSchema"); String result = FileUtils.readToString(new FileInputStream(tempFile)); Assert.assertTrue(result.contains("id=\"preserveMe\""), "Failed to validate " + result); Assert.assertTrue(result.contains("name=\"preserveMeName\""), "Failed to validate " + result); Assert.assertFalse(result.contains("<bean id=\"deleteMe\""), "Failed to validate " + result); Assert.assertTrue(result.contains("<bean name=\"deleteMeName\""), "Failed to validate " + result); Assert.assertTrue(result.contains("<property name=\"deleteMe\" value=\"some\"/>"), "Failed to validate " + result); }