@Test @SuppressWarnings("resource") public void testWithProperties() { Properties properties = new Properties(); properties.put("prop1key", "prop1val"); JsrXmlApplicationContext applicationContext = new JsrXmlApplicationContext(properties); BeanDefinition beanDefinition = applicationContext.getBeanDefinition(JOB_PARAMETERS_BEAN_DEFINITION_NAME); Properties storedProperties = (Properties) beanDefinition.getConstructorArgumentValues().getGenericArgumentValue(Properties.class).getValue(); assertNotNull("Properties should not be null", storedProperties); assertFalse("Properties not be empty", storedProperties.isEmpty()); assertEquals("prop1val", storedProperties.getProperty("prop1key")); } }
@Test @SuppressWarnings("resource") public void testGetJobParameters() { Properties jobParameters = new Properties(); jobParameters.setProperty("jobParameter1", "jobParameter1Value"); jobParameters.setProperty("jobParameter2", "jobParameter2Value"); JsrXmlApplicationContext applicationContext = new JsrXmlApplicationContext(jobParameters); applicationContext.setValidating(false); applicationContext.load(new ClassPathResource("jsrBaseContext.xml"), new ClassPathResource("/META-INF/batch.xml"), new ClassPathResource("/META-INF/batch-jobs/jsrPropertyPreparseTestJob.xml")); applicationContext.refresh(); BeanDefinition beanDefinition = applicationContext.getBeanDefinition(JOB_PARAMETERS_BEAN_DEFINITION_NAME); Properties processedJobParameters = (Properties) beanDefinition.getConstructorArgumentValues().getGenericArgumentValue(Properties.class).getValue(); assertNotNull(processedJobParameters); assertTrue("Wrong number of job parameters", processedJobParameters.size() == 2); assertEquals("jobParameter1Value", processedJobParameters.getProperty("jobParameter1")); assertEquals("jobParameter2Value", processedJobParameters.getProperty("jobParameter2")); }
@Test @SuppressWarnings("resource") public void testNullProperties() { JsrXmlApplicationContext applicationContext = new JsrXmlApplicationContext(null); BeanDefinition beanDefinition = applicationContext.getBeanDefinition(JOB_PARAMETERS_BEAN_DEFINITION_NAME); Properties properties = (Properties) beanDefinition.getConstructorArgumentValues().getGenericArgumentValue(Properties.class).getValue(); assertNotNull("Properties should not be null", properties); assertTrue("Properties should be empty", properties.isEmpty()); }
@Test @SuppressWarnings("resource") public void testGenerationOfSpringBeanDefinitionsForMultipleReferences() { JsrXmlApplicationContext applicationContext = new JsrXmlApplicationContext(new Properties()); applicationContext.setValidating(false); applicationContext.load(new ClassPathResource("jsrBaseContext.xml"), new ClassPathResource("/META-INF/batch-jobs/jsrSpringInstanceTests.xml")); applicationContext.refresh(); assertTrue("exitStatusSettingStepListener bean definition not found", applicationContext.containsBeanDefinition("exitStatusSettingStepListener")); assertTrue("scopedTarget.exitStatusSettingStepListener bean definition not found", applicationContext.containsBeanDefinition("scopedTarget.exitStatusSettingStepListener")); BeanDefinition exitStatusSettingStepListenerBeanDefinition = applicationContext.getBeanDefinition("scopedTarget.exitStatusSettingStepListener"); assertTrue("step".equals(exitStatusSettingStepListenerBeanDefinition.getScope())); assertTrue("Should not contain bean definition for exitStatusSettingStepListener1", !applicationContext.containsBeanDefinition("exitStatusSettingStepListener1")); assertTrue("Should not contain bean definition for exitStatusSettingStepListener2", !applicationContext.containsBeanDefinition("exitStatusSettingStepListener2")); assertTrue("Should not contain bean definition for exitStatusSettingStepListener3", !applicationContext.containsBeanDefinition("exitStatusSettingStepListener3")); assertTrue("Should not contain bean definition for testBatchlet1", !applicationContext.containsBeanDefinition("testBatchlet1")); assertTrue("Should not contain bean definition for testBatchlet2", !applicationContext.containsBeanDefinition("testBatchlet2")); assertTrue("testBatchlet bean definition not found", applicationContext.containsBeanDefinition("testBatchlet")); BeanDefinition testBatchletBeanDefinition = applicationContext.getBeanDefinition("testBatchlet"); assertTrue("singleton".equals(testBatchletBeanDefinition.getScope())); }