@Test public void onlyOneInterceptorIsAvailable() { Map<String, JCacheInterceptor> interceptors = ctx.getBeansOfType(JCacheInterceptor.class); assertEquals("Only one interceptor should be defined", 1, interceptors.size()); JCacheInterceptor interceptor = interceptors.values().iterator().next(); assertEquals("Custom interceptor not defined", TestCacheInterceptor.class, interceptor.getClass()); }
@Test public void onlyOneInterceptorIsAvailable() { Map<String, CacheInterceptor> interceptors = this.ctx.getBeansOfType(CacheInterceptor.class); assertEquals("Only one interceptor should be defined", 1, interceptors.size()); CacheInterceptor interceptor = interceptors.values().iterator().next(); assertEquals("Custom interceptor not defined", TestCacheInterceptor.class, interceptor.getClass()); }
private int getExitCodeFromMappedException(ConfigurableApplicationContext context, Throwable exception) { if (context == null || !context.isActive()) { return 0; } ExitCodeGenerators generators = new ExitCodeGenerators(); Collection<ExitCodeExceptionMapper> beans = context .getBeansOfType(ExitCodeExceptionMapper.class).values(); generators.addAll(exception, beans); return generators.getExitCode(); }
SmsConfigProperties.smsProduct, SmsConfigProperties.smsDomain); Collection<MessageListener> messageListeners = event.getApplicationContext() .getBeansOfType(MessageListener.class).values(); if (messageListeners.isEmpty()) { return;
@Test public void transactionalEventListenerRegisteredProperly() { assertTrue(this.context.containsBean(TransactionManagementConfigUtils .TRANSACTIONAL_EVENT_LISTENER_FACTORY_BEAN_NAME)); assertEquals(1, this.context.getBeansOfType(TransactionalEventListenerFactory.class).size()); }
@Test @SuppressWarnings("resource") public void testJobElement() throws Exception { ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext( "org/springframework/batch/core/configuration/xml/AutoRegisteringJobScopeForJobElementTests-context.xml"); Map<String, JobScope> beans = ctx.getBeansOfType(JobScope.class); assertTrue("JobScope not defined properly", beans.size() == 1); }
@Test @SuppressWarnings("resource") public void testStepElement() throws Exception { ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext( "org/springframework/batch/core/configuration/xml/AutoRegisteringJobScopeForStepElementTests-context.xml"); Map<String, JobScope> beans = ctx.getBeansOfType(JobScope.class); assertTrue("JobScope not defined properly", beans.size() == 1); }
@Test public void credentialsAreClearedByDefault() throws Exception { ConfigurableApplicationContext appContext = this.spring.context(CONTEXT) .getContext(); ProviderManager pm = (ProviderManager) appContext .getBeansOfType(ProviderManager.class).values().toArray()[0]; assertThat(pm.isEraseCredentialsAfterAuthentication()).isTrue(); }
@Test @SuppressWarnings("resource") public void testStepElement() throws Exception { ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext("org/springframework/batch/core/configuration/xml/AutoRegisteringStepScopeForStepElementTests-context.xml"); Map<String, StepScope> beans = ctx.getBeansOfType(StepScope.class); assertTrue("StepScope not defined properly", beans.size() == 1); }
@Test @SuppressWarnings("resource") public void testJobElement() throws Exception { ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext("org/springframework/batch/core/configuration/xml/AutoRegisteringStepScopeForJobElementTests-context.xml"); Map<String, StepScope> beans = ctx.getBeansOfType(StepScope.class); assertTrue("StepScope not defined properly", beans.size() == 1); }
@Test public void clearCredentialsPropertyIsRespected() throws Exception { ConfigurableApplicationContext appContext = this.spring.context("<authentication-manager erase-credentials='false'/>") .getContext(); ProviderManager pm = (ProviderManager) appContext .getBeansOfType(ProviderManager.class).values().toArray()[0]; assertThat(pm.isEraseCredentialsAfterAuthentication()).isFalse(); }
@Test public void eventsArePublishedByDefault() throws Exception { ConfigurableApplicationContext appContext = this.spring.context(CONTEXT) .getContext(); AuthListener listener = new AuthListener(); appContext.addApplicationListener(listener); ProviderManager pm = (ProviderManager) appContext .getBeansOfType(ProviderManager.class).values().toArray()[0]; Object eventPublisher = FieldUtils.getFieldValue(pm, "eventPublisher"); assertThat(eventPublisher).isNotNull(); assertThat(eventPublisher instanceof DefaultAuthenticationEventPublisher).isTrue(); pm.authenticate(new UsernamePasswordAuthenticationToken("bob", "bobspassword")); assertThat(listener.events).hasSize(1); }
@Test @SuppressWarnings("resource") public void testStepParserBeanName() throws Exception { ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext( "org/springframework/batch/core/configuration/xml/StepParserBeanNameTests-context.xml"); Map<String, Step> beans = ctx.getBeansOfType(Step.class); assertTrue("'s1' bean not found", beans.containsKey("s1")); Step s1 = (Step) ctx.getBean("s1"); assertEquals("wrong name", "s1", s1.getName()); }
@Test @SuppressWarnings("resource") public void testStepParserCompletionPolicy() throws Exception { ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext( "org/springframework/batch/core/configuration/xml/StepParserCompletionPolicyTests-context.xml"); Map<String, Step> beans = ctx.getBeansOfType(Step.class); assertTrue("'s1' bean not found", beans.containsKey("s1")); Step s1 = (Step) ctx.getBean("s1"); CompletionPolicy completionPolicy = getCompletionPolicy(s1); assertTrue(completionPolicy instanceof DummyCompletionPolicy); }
@Test // SEC-1225 public void providersAreRegisteredAsTopLevelBeans() throws Exception { ConfigurableApplicationContext context = this.spring.context(CONTEXT) .getContext(); assertThat(context.getBeansOfType(AuthenticationProvider.class)).hasSize(1); }
@Test @SuppressWarnings("resource") public void testTaskletStepAttributes() throws Exception { ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext( "org/springframework/batch/core/configuration/xml/StepParserTaskletAttributesTests-context.xml"); @SuppressWarnings({ "rawtypes" }) Map<String, StepParserStepFactoryBean> beans = ctx.getBeansOfType(StepParserStepFactoryBean.class); String factoryName = (String) beans.keySet().toArray()[0]; @SuppressWarnings("unchecked") StepParserStepFactoryBean<Object, Object> factory = beans.get(factoryName); TaskletStep bean = (TaskletStep) factory.getObject(); assertEquals("wrong start-limit:", 25, bean.getStartLimit()); Object throttleLimit = ReflectionTestUtils.getField(factory, "throttleLimit"); assertEquals(new Integer(10), throttleLimit); }
@Test @SuppressWarnings("resource") public void testStepParserCommitInterval() throws Exception { ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext( "org/springframework/batch/core/configuration/xml/StepParserCommitIntervalTests-context.xml"); Map<String, Step> beans = ctx.getBeansOfType(Step.class); assertTrue("'s1' bean not found", beans.containsKey("s1")); Step s1 = (Step) ctx.getBean("s1"); CompletionPolicy completionPolicy = getCompletionPolicy(s1); assertTrue(completionPolicy instanceof SimpleCompletionPolicy); assertEquals(25, ReflectionTestUtils.getField(completionPolicy, "chunkSize")); }
@Test public void testInlineHandlersWithStepScope() throws Exception { context = new ClassPathXmlApplicationContext( "org/springframework/batch/core/configuration/xml/InlineItemHandlerWithStepScopeParserTests-context.xml"); StepSynchronizationManager.register(new StepExecution("step", new JobExecution(123L))); @SuppressWarnings({ "rawtypes" }) Map<String,ItemReader> readers = context.getBeansOfType(ItemReader.class); // Should be 2 each (proxy and target) for the two readers in the steps defined assertEquals(4, readers.size()); }
@Test public void testNoHistoryAwareMessageHandler() { ConfigurableApplicationContext ac = new ClassPathXmlApplicationContext("messageHistoryWithoutHistoryWriter.xml", MessageHistoryIntegrationTests.class); Map<String, ConsumerEndpointFactoryBean> cefBeans = ac.getBeansOfType(ConsumerEndpointFactoryBean.class); for (ConsumerEndpointFactoryBean cefBean : cefBeans.values()) { DirectFieldAccessor bridgeAccessor = new DirectFieldAccessor(cefBean); String handlerClassName = bridgeAccessor.getPropertyValue("handler").getClass().getName(); assertFalse("org.springframework.integration.config.MessageHistoryWritingMessageHandler" .equals(handlerClassName)); } ac.close(); }
@Test public void testJpaExecutorBeanIdNaming() throws Exception { JpaExecutor jpaExecutor1 = this.context.getBean("jpaInboundChannelAdapter1.jpaExecutor", JpaExecutor.class); JpaExecutor jpaExecutor2 = this.context.getBean("jpaInboundChannelAdapter2.jpaExecutor", JpaExecutor.class); assertNotNull(jpaExecutor1); assertNotNull(jpaExecutor2); assertNotSame(jpaExecutor1, jpaExecutor2); assertEquals(5, this.context.getBeansOfType(JpaExecutor.class).size()); JpaExecutor jpaExecutorWithoutId0 = this.context.getBean("org.springframework.integration.config.SourcePollingChannelAdapterFactoryBean#0.jpaExecutor", JpaExecutor.class); JpaExecutor jpaExecutorWithoutId1 = this.context.getBean("org.springframework.integration.config.SourcePollingChannelAdapterFactoryBean#1.jpaExecutor", JpaExecutor.class); assertNotNull(jpaExecutorWithoutId0); assertNotNull(jpaExecutorWithoutId1); assertNotSame(jpaExecutorWithoutId0, jpaExecutorWithoutId1); }