SpringBeanService { public void addBeanDefinition(File configFile, Project project, Object jaxbElement) { Source xsltSource; Source xmlSource; try { xsltSource = new StreamSource(new ClassPathResource("transform/add-bean.xsl").getInputStream()); xsltSource.setSystemId("add-bean"); String source = FileUtils.readToString(new FileInputStream(configFile)); xmlSource = new StringSource(source); Transformer transformer = transformerFactory.newTransformer(xsltSource); transformer.setParameter("bean_content", getXmlContent(jaxbElement) .replaceAll("(?m)^(.)", getTabs(1, project.getSettings().getTabSize()) + "$1")); StringResult result = new StringResult(); transformer.transform(xmlSource, result); FileUtils.writeToFile(format(postProcess(source, result.toString()), project.getSettings().getTabSize()), configFile); 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 testAddBeanDefinition() throws Exception { SchemaModel xsdSchema1 = new SchemaModelBuilder().withId("1").withLocation("l1").build(); SchemaModel xsdSchema2 = new SchemaModelBuilder().withId("2").withLocation("l2").build(); SchemaRepositoryModel schemaRepository = new SchemaRepositoryModelBuilder().withId("x").addSchemaReference("1").addSchemaReference("2").build(); SpringBean springBean = new SpringBean(); springBean.setId("listener"); springBean.setClazz(WebSocketPushEventsListener.class.getName()); File tempFile = createTempContextFile("citrus-context-add"); springBeanConfigService.addBeanDefinition(tempFile, project, xsdSchema1); springBeanConfigService.addBeanDefinition(tempFile, project, xsdSchema2); springBeanConfigService.addBeanDefinition(tempFile, project, schemaRepository); springBeanConfigService.addBeanDefinition(tempFile, project, springBean); String result = FileUtils.readToString(new FileInputStream(tempFile)); Assert.assertTrue(result.contains("<citrus:schema id=\"1\" location=\"l1\"/>"), "Failed to validate " + result); Assert.assertTrue(result.contains("<citrus:schema id=\"2\" location=\"l2\"/>"), "Failed to validate " + result); Assert.assertTrue(result.contains("<citrus:schema-repository id=\"x\">"), "Failed to validate " + result); Assert.assertTrue(result.contains("<bean class=\"" + WebSocketPushEventsListener.class.getName() + "\" id=\"listener\"/>"), "Failed to validate " + result); }
@Test public void testAddBeanDefinitionNamespace() throws Exception { JmsEndpointModel jmsEndpoint = new JmsEndpointModel(); jmsEndpoint.setId("jmsEndpoint"); jmsEndpoint.setDestinationName("jms.inbound.queue"); File tempFile = createTempContextFile("citrus-context-add"); springBeanConfigService.addBeanDefinition(tempFile, project, jmsEndpoint); String result = FileUtils.readToString(new FileInputStream(tempFile)); Assert.assertTrue(result.contains("<citrus-jms:endpoint id=\"jmsEndpoint\" destination-name=\"jms.inbound.queue\"/>"), "Failed to validate " + result); Assert.assertTrue(result.contains("xmlns:citrus-jms=\"http: }