@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); }
@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); }
@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")); } }
@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"); }
@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")); } }
@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")); } }
@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()); } }
@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")); } }
@Test public void testAggregatorFailureIfMutuallyExclusivityPresent() { try { new ClassPathXmlApplicationContext("aggregatorParserFailTests.xml", this.getClass()).close(); } catch (BeanDefinitionParsingException e) { assertThat(e.getMessage(), containsString( "Exactly one of the 'release-strategy' or 'release-strategy-expression' attribute is allowed.")); } }
@Test public void testSelectorAndStore() throws Exception { try { bootStrap("selector-and-store"); fail("BeanDefinitionParsingException expected"); } catch (BeanDefinitionParsingException e) { assertThat(e.getMessage(), containsString("The 'selector' attribute is mutually exclusive with 'metadata-store', " + "'key-strategy', 'key-expression', 'value-strategy' or 'value-expression'")); } }
@Test public void testSelectorAndKeyStrategy() throws Exception { try { bootStrap("selector-and-key-strategy"); fail("BeanDefinitionParsingException expected"); } catch (BeanDefinitionParsingException e) { assertThat(e.getMessage(), containsString("The 'selector' attribute is mutually exclusive with 'metadata-store', " + "'key-strategy', 'key-expression', 'value-strategy' or 'value-expression'")); } }
@Test public void testSelectorAndKeyExpression() throws Exception { try { bootStrap("selector-and-key-expression"); fail("BeanDefinitionParsingException expected"); } catch (BeanDefinitionParsingException e) { assertThat(e.getMessage(), containsString("The 'selector' attribute is mutually exclusive with 'metadata-store', " + "'key-strategy', 'key-expression', 'value-strategy' or 'value-expression'")); } }
@Test public void testValueStrategyAndValueExpression() throws Exception { try { bootStrap("value-strategy-and-value-expression"); fail("BeanDefinitionParsingException expected"); } catch (BeanDefinitionParsingException e) { assertThat(e.getMessage(), containsString("The 'value-strategy' and 'value-expression' attributes are mutually exclusive")); } }
@Test public void testProcedureNameAndExpressionExclusivity() throws Exception { try { this.bootStrap("nameAndExpressionExclusivity"); fail("Expected a BeanDefinitionParsingException to be thrown."); } catch (BeanDefinitionParsingException e) { assertTrue(e.getMessage().contains("Exactly one of 'stored-procedure-name' or 'stored-procedure-name-expression' is required")); } }
@Test public void testWithoutEndpoint() throws Exception { try { bootStrap("without-endpoint"); fail("BeanDefinitionParsingException expected"); } catch (BeanDefinitionParsingException e) { assertThat(e.getMessage(), containsString("he 'endpoint' attribute is required")); } }
@Test public void testKeyStrategyAndKeyExpression() throws Exception { try { bootStrap("key-strategy-and-key-expression"); fail("BeanDefinitionParsingException expected"); } catch (BeanDefinitionParsingException e) { assertThat(e.getMessage(), containsString("The 'key-strategy' and 'key-expression' attributes are mutually exclusive")); } }
@Test public void testInt2755DetectDuplicateHandlerId() throws Exception { try { this.bootStrap("duplicate-handler-id"); fail("Expected a BeanDefinitionParsingException to be thrown."); } catch (BeanDefinitionParsingException e) { assertTrue(e.getMessage().contains("A bean definition is already registered for " + "beanName: 'foo$child.bar.handler' within the current <chain>.")); } }
@Test public void testReturnTypeAndScaleExclusivity() throws Exception { try { this.bootStrap("returnTypeAndScaleExclusivity"); fail("Expected a BeanDefinitionParsingException to be thrown."); } catch (BeanDefinitionParsingException e) { assertTrue(e.getMessage().contains("'returnType' and 'scale' attributes are mutually exclusive " + "for 'sql-parameter-definition' element.")); } }
@Test public void testTypeNameAndScaleExclusivity() throws Exception { try { this.bootStrap("typeNameAndScaleExclusivity"); fail("Expected a BeanDefinitionParsingException to be thrown."); } catch (BeanDefinitionParsingException e) { assertTrue(e.getMessage().contains("'type-name' and 'scale' attributes are mutually exclusive " + "for 'sql-parameter-definition' element.")); } }