From c71412d6d512e70ce5fd3947c7d3ed50a1870a69 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Thu, 6 Mar 2008 20:20:10 +0000 Subject: [PATCH] Added tests for MailTargetAdapterParser. Also, adjusted ApplicationEvent adapter tests to have an explicit context.stop() call rather than relying on context.close() for the stop event (after 2.5.2 upgrade). --- .../ApplicationEventSourceAdapterTests.java | 9 +-- .../config/MailTargetAdapterParserTests.java | 55 +++++++++++++++++++ .../config/mailTargetAdapterParserTests.xml | 27 +++++++++ 3 files changed, 87 insertions(+), 4 deletions(-) create mode 100644 spring-integration-adapters/src/test/java/org/springframework/integration/adapter/mail/config/MailTargetAdapterParserTests.java create mode 100644 spring-integration-adapters/src/test/java/org/springframework/integration/adapter/mail/config/mailTargetAdapterParserTests.xml diff --git a/spring-integration-adapters/src/test/java/org/springframework/integration/adapter/event/ApplicationEventSourceAdapterTests.java b/spring-integration-adapters/src/test/java/org/springframework/integration/adapter/event/ApplicationEventSourceAdapterTests.java index 16af096948..c561ee8a4c 100644 --- a/spring-integration-adapters/src/test/java/org/springframework/integration/adapter/event/ApplicationEventSourceAdapterTests.java +++ b/spring-integration-adapters/src/test/java/org/springframework/integration/adapter/event/ApplicationEventSourceAdapterTests.java @@ -86,14 +86,15 @@ public class ApplicationEventSourceAdapterTests { context.start(); Message startedEventMessage = channel.receive(0); assertNotNull(startedEventMessage); - assertEquals(ContextStartedEvent.class, startedEventMessage.getPayload().getClass()); + assertEquals(ContextStartedEvent.class, startedEventMessage.getPayload().getClass()); + context.stop(); + Message stoppedEventMessage = channel.receive(0); + assertNotNull(stoppedEventMessage); + assertEquals(ContextStoppedEvent.class, stoppedEventMessage.getPayload().getClass()); context.close(); Message closedEventMessage = channel.receive(0); assertNotNull(closedEventMessage); assertEquals(ContextClosedEvent.class, closedEventMessage.getPayload().getClass()); - Message stoppedEventMessage = channel.receive(0); - assertNotNull(stoppedEventMessage); - assertEquals(ContextStoppedEvent.class, stoppedEventMessage.getPayload().getClass()); } diff --git a/spring-integration-adapters/src/test/java/org/springframework/integration/adapter/mail/config/MailTargetAdapterParserTests.java b/spring-integration-adapters/src/test/java/org/springframework/integration/adapter/mail/config/MailTargetAdapterParserTests.java new file mode 100644 index 0000000000..dcb4367220 --- /dev/null +++ b/spring-integration-adapters/src/test/java/org/springframework/integration/adapter/mail/config/MailTargetAdapterParserTests.java @@ -0,0 +1,55 @@ +/* + * Copyright 2002-2007 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.integration.adapter.mail.config; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.springframework.integration.adapter.mail.MailTargetAdapter; +import org.springframework.integration.endpoint.DefaultMessageEndpoint; +import org.springframework.integration.handler.MessageHandler; + +/** + * @author Mark Fisher + */ +public class MailTargetAdapterParserTests { + + @Test + public void testAdapterWithMailSenderReference() { + ApplicationContext context = new ClassPathXmlApplicationContext( + "mailTargetAdapterParserTests.xml", this.getClass()); + DefaultMessageEndpoint endpoint = (DefaultMessageEndpoint) context.getBean("adapterWithMailSenderReference"); + MessageHandler handler = endpoint.getHandler(); + assertNotNull(handler); + assertTrue(handler instanceof MailTargetAdapter); + } + + @Test + public void testAdapterWithHostProperty() { + ApplicationContext context = new ClassPathXmlApplicationContext( + "mailTargetAdapterParserTests.xml", this.getClass()); + DefaultMessageEndpoint endpoint = (DefaultMessageEndpoint) context.getBean("adapterWithHostProperty"); + MessageHandler handler = endpoint.getHandler(); + assertNotNull(handler); + assertTrue(handler instanceof MailTargetAdapter); + } + +} diff --git a/spring-integration-adapters/src/test/java/org/springframework/integration/adapter/mail/config/mailTargetAdapterParserTests.xml b/spring-integration-adapters/src/test/java/org/springframework/integration/adapter/mail/config/mailTargetAdapterParserTests.xml new file mode 100644 index 0000000000..0699350033 --- /dev/null +++ b/spring-integration-adapters/src/test/java/org/springframework/integration/adapter/mail/config/mailTargetAdapterParserTests.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file