/** * Throws a {@link BeanDefinitionParsingException} detailing the error * that has occurred. * @param problem the source of the error */ @Override public void fatal(Problem problem) { throw new BeanDefinitionParsingException(problem); }
@Test public void configurationClassesMayNotBeFinal() { @Configuration final class Config { } BeanDefinition configBeanDef = rootBeanDefinition(Config.class).getBeanDefinition(); DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); beanFactory.registerBeanDefinition("config", configBeanDef); try { ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor(); pp.postProcessBeanFactory(beanFactory); fail("expected exception"); } catch (BeanDefinitionParsingException ex) { assertTrue(ex.getMessage(), ex.getMessage().contains("Remove the final modifier")); } }
@Test public void complexCircularImportIsDetected() throws Exception { boolean threw = false; try { newParser().parse(loadAsConfigurationSource(X.class), "X"); } catch (BeanDefinitionParsingException ex) { assertTrue("Wrong message. Got: " + ex.getMessage(), ex.getMessage().contains( "Illegal attempt by @Configuration class 'AbstractCircularImportDetectionTests.Z2' " + "to import class 'AbstractCircularImportDetectionTests.Z'")); threw = true; } assertTrue(threw); }
/** * Throws a {@link BeanDefinitionParsingException} detailing the error * that has occurred. * @param problem the source of the error */ @Override public void error(Problem problem) { throw new BeanDefinitionParsingException(problem); }
@Test public void simpleCircularImportIsDetected() throws Exception { boolean threw = false; try { newParser().parse(loadAsConfigurationSource(A.class), "A"); } catch (BeanDefinitionParsingException ex) { assertTrue("Wrong message. Got: " + ex.getMessage(), ex.getMessage().contains( "Illegal attempt by @Configuration class 'AbstractCircularImportDetectionTests.B' " + "to import class 'AbstractCircularImportDetectionTests.A'")); threw = true; } assertTrue(threw); }
/** * Throws a {@link BeanDefinitionParsingException} detailing the error * that has occurred. * @param problem the source of the error */ @Override public void error(Problem problem) { throw new BeanDefinitionParsingException(problem); }
@Test public void pre32SchemaAreNotSupported() throws Exception { try { new InMemoryXmlApplicationContext( "<user-service id='us'>" + " <user name='bob' password='bobspassword' authorities='ROLE_A' />" + "</user-service>", "3.0.3", null); fail("Expected BeanDefinitionParsingException"); } catch (BeanDefinitionParsingException expected) { assertThat(expected.getMessage().contains( "You cannot use a spring-security-2.0.xsd")); } }
/** * Throws a {@link BeanDefinitionParsingException} detailing the error * that has occurred. * @param problem the source of the error */ @Override public void fatal(Problem problem) { throw new BeanDefinitionParsingException(problem); }
@Test public void testUnreachableStepInFlow() { try { new ClassPathXmlApplicationContext( "org/springframework/batch/core/configuration/xml/JobParserUnreachableStepInFlowTests-context.xml"); fail("Error expected"); } catch (BeanDefinitionParsingException e) { assertTrue(e.getMessage().contains("The element [s4] is unreachable")); } }
@Override public void fatal(Problem problem) { throw new BeanDefinitionParsingException(problem); }
@Test public void testOneFlowInSplit() { try { new ClassPathXmlApplicationContext("/org/springframework/batch/core/jsr/configuration/xml/invalid-split-context.xml"); } catch (BeanDefinitionParsingException bdpe) { assertTrue(bdpe.getMessage().contains("A <split/> must contain at least two 'flow' elements.")); return; } fail("Expected exception was not thrown"); }
/** * Define a Spring XML namespace definition to use. * @param definition the namespace definition */ public void xmlns(Map<String, String> definition) { if (!definition.isEmpty()) { for (Map.Entry<String,String> entry : definition.entrySet()) { String namespace = entry.getKey(); String uri = entry.getValue(); if (uri == null) { throw new IllegalArgumentException("Namespace definition must supply a non-null URI"); } NamespaceHandler namespaceHandler = this.groovyDslXmlBeanDefinitionReader.getNamespaceHandlerResolver().resolve(uri); if (namespaceHandler == null) { throw new BeanDefinitionParsingException(new Problem("No namespace handler found for URI: " + uri, new Location(new DescriptiveResource(("Groovy"))))); } this.namespaces.put(namespace, uri); } } }
@Test public void testUnreachableStep() { try { new ClassPathXmlApplicationContext( "org/springframework/batch/core/configuration/xml/JobParserUnreachableStepTests-context.xml"); fail("Error expected"); } catch (BeanDefinitionParsingException e) { assertTrue(e.getMessage().contains("The element [s2] is unreachable")); } }
/** * Define a Spring XML namespace definition to use. * @param definition the namespace definition */ public void xmlns(Map<String, String> definition) { if (!definition.isEmpty()) { for (Map.Entry<String,String> entry : definition.entrySet()) { String namespace = entry.getKey(); String uri = entry.getValue(); if (uri == null) { throw new IllegalArgumentException("Namespace definition must supply a non-null URI"); } NamespaceHandler namespaceHandler = this.groovyDslXmlBeanDefinitionReader.getNamespaceHandlerResolver().resolve(uri); if (namespaceHandler == null) { throw new BeanDefinitionParsingException(new Problem("No namespace handler found for URI: " + uri, new Location(new DescriptiveResource(("Groovy"))))); } this.namespaces.put(namespace, uri); } } }
@Test public void testWrongSchemaInRoot() { try { new ClassPathXmlApplicationContext( "org/springframework/batch/core/configuration/xml/JobParserWrongSchemaInRootTests-context.xml"); fail("Error expected"); } catch (BeanDefinitionParsingException e) { String message = e.getMessage(); assertTrue("Wrong message: "+message, message.startsWith("Configuration problem: You are using a version of the spring-batch XSD")); } catch (BeanDefinitionStoreException e) { // Probably the internet is not available and the schema validation failed. fail("Wrong exception when schema didn't match: " + e.getMessage()); } }
throw new BeanDefinitionParsingException(new Problem("Error evaluating Groovy script: " + ex.getMessage(), new Location(encodedResource.getResource()), null, ex));
@Test public void loadBalancerRefFailWithLoadBalancer() { try { new ClassPathXmlApplicationContext("ChannelWithLoadBalancerRef-fail-config.xml", this.getClass()).close(); } catch (BeanDefinitionParsingException e) { assertThat(e.getMessage(), Matchers.containsString("'load-balancer' and 'load-balancer-ref' are mutually exclusive")); } }
throw new BeanDefinitionParsingException(new Problem("Error evaluating Groovy script: " + ex.getMessage(), new Location(encodedResource.getResource()), null, ex));
@Test public void testInt2971HeaderMapperAndMappedHeadersExclusivity() { try { new ClassPathXmlApplicationContext("AmqpInboundGatewayParserTests-headerMapper-fail-context.xml", this.getClass()).close(); } catch (BeanDefinitionParsingException e) { assertTrue(e.getMessage().startsWith("Configuration problem: The 'header-mapper' attribute " + "is mutually exclusive with 'mapped-request-headers' or 'mapped-reply-headers'")); } }
/** * Throws a {@link BeanDefinitionParsingException} detailing the error * that has occurred. * @param problem the source of the error */ public void fatal(Problem problem) { throw new BeanDefinitionParsingException(problem); }