diff --git a/spring-integration-mongodb/src/test/java/org/springframework/integration/mongodb/rules/MongodbAvailable.java b/spring-integration-mongodb/src/test/java/org/springframework/integration/mongodb/rules/MongodbAvailable.java index cd9992b748..ec02a79473 100644 --- a/spring-integration-mongodb/src/test/java/org/springframework/integration/mongodb/rules/MongodbAvailable.java +++ b/spring-integration-mongodb/src/test/java/org/springframework/integration/mongodb/rules/MongodbAvailable.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.integration.mongodb.rules; import java.lang.annotation.ElementType; @@ -21,11 +22,13 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** + * Annotation used for any test method that requires a running MongoDb process. + * * @author Oleg Zhurakousky - * + * @since 2.1 */ @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD}) -public @interface MongodbAvailable { +public @interface MongoDbAvailable { } diff --git a/spring-integration-mongodb/src/test/java/org/springframework/integration/mongodb/rules/MongodbAvailableRule.java b/spring-integration-mongodb/src/test/java/org/springframework/integration/mongodb/rules/MongodbAvailableRule.java index 77d82f198c..a9fbad119e 100644 --- a/spring-integration-mongodb/src/test/java/org/springframework/integration/mongodb/rules/MongodbAvailableRule.java +++ b/spring-integration-mongodb/src/test/java/org/springframework/integration/mongodb/rules/MongodbAvailableRule.java @@ -13,8 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.integration.mongodb.rules; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + import org.junit.rules.MethodRule; import org.junit.runners.model.FrameworkMethod; import org.junit.runners.model.Statement; @@ -22,30 +26,34 @@ import org.junit.runners.model.Statement; import com.mongodb.Mongo; /** + * A {@link MethodRule} implementation that checks for a running MongoDB process. + * * @author Oleg Zhurakousky - * + * @since 2.1 */ -public final class MongodbAvailableRule implements MethodRule{ +public final class MongoDbAvailableRule implements MethodRule { - public Statement apply(final Statement base, final FrameworkMethod method, Object target) { - return new Statement(){ + private final Log logger = LogFactory.getLog(this.getClass()); + public Statement apply(final Statement base, final FrameworkMethod method, final Object target) { + return new Statement() { @Override public void evaluate() throws Throwable { - MongodbAvailable redisAvailable = method.getAnnotation(MongodbAvailable.class); - if (redisAvailable != null){ + MongoDbAvailable redisAvailable = method.getAnnotation(MongoDbAvailable.class); + if (redisAvailable != null) { try { Mongo mongo = new Mongo(); mongo.getDatabaseNames(); - } catch (Exception e) { - System.out.println("Mongodb is not available. Skipping the test."); + } + catch (Exception e) { + logger.warn("MongoDb is not available. Skipping the test: " + + target.getClass().getSimpleName() + "." + method.getName() + "()"); return; } } base.evaluate(); - } + } }; - } } diff --git a/spring-integration-mongodb/src/test/java/org/springframework/integration/mongodb/rules/MongodbAvailableTests.java b/spring-integration-mongodb/src/test/java/org/springframework/integration/mongodb/rules/MongodbAvailableTests.java index 2ed1972ab3..9844d78f29 100644 --- a/spring-integration-mongodb/src/test/java/org/springframework/integration/mongodb/rules/MongodbAvailableTests.java +++ b/spring-integration-mongodb/src/test/java/org/springframework/integration/mongodb/rules/MongodbAvailableTests.java @@ -13,15 +13,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.integration.mongodb.rules; import org.junit.Rule; /** + * Convenience base class that enables unit test methods to rely upon the {@link MongoDbAvailable} annotation. + * * @author Oleg Zhurakousky - * + * @since 2.1 */ -public class MongodbAvailableTests { +public abstract class MongoDbAvailableTests { + @Rule - public MongodbAvailableRule redisAvailableRule = new MongodbAvailableRule(); + public MongoDbAvailableRule redisAvailableRule = new MongoDbAvailableRule(); + } diff --git a/spring-integration-mongodb/src/test/java/org/springframework/integration/mongodb/store/MongoClaimCheckIntegrationTests.java b/spring-integration-mongodb/src/test/java/org/springframework/integration/mongodb/store/MongoClaimCheckIntegrationTests.java index 58fad5b203..3266fb94ab 100644 --- a/spring-integration-mongodb/src/test/java/org/springframework/integration/mongodb/store/MongoClaimCheckIntegrationTests.java +++ b/spring-integration-mongodb/src/test/java/org/springframework/integration/mongodb/store/MongoClaimCheckIntegrationTests.java @@ -20,8 +20,8 @@ import org.junit.Test; import org.springframework.data.mongodb.MongoDbFactory; import org.springframework.data.mongodb.core.SimpleMongoDbFactory; import org.springframework.integration.Message; -import org.springframework.integration.mongodb.rules.MongodbAvailable; -import org.springframework.integration.mongodb.rules.MongodbAvailableTests; +import org.springframework.integration.mongodb.rules.MongoDbAvailable; +import org.springframework.integration.mongodb.rules.MongoDbAvailableTests; import org.springframework.integration.support.MessageBuilder; import org.springframework.integration.transformer.ClaimCheckInTransformer; import org.springframework.integration.transformer.ClaimCheckOutTransformer; @@ -33,10 +33,10 @@ import static org.junit.Assert.assertEquals; /** * @author Mark Fisher */ -public class MongoClaimCheckIntegrationTests extends MongodbAvailableTests{ +public class MongoClaimCheckIntegrationTests extends MongoDbAvailableTests{ @Test - @MongodbAvailable + @MongoDbAvailable public void stringPayload() throws Exception { MongoDbFactory mongoDbFactory = new SimpleMongoDbFactory(new Mongo(), "test"); MongoMessageStore messageStore = new MongoMessageStore(mongoDbFactory); @@ -55,7 +55,7 @@ public class MongoClaimCheckIntegrationTests extends MongodbAvailableTests{ } @Test - @MongodbAvailable + @MongoDbAvailable public void objectPayload() throws Exception { MongoDbFactory mongoDbFactory = new SimpleMongoDbFactory(new Mongo(), "test"); MongoMessageStore messageStore = new MongoMessageStore(mongoDbFactory); diff --git a/spring-integration-mongodb/src/test/java/org/springframework/integration/mongodb/store/MongoMessageStoreTests.java b/spring-integration-mongodb/src/test/java/org/springframework/integration/mongodb/store/MongoMessageStoreTests.java index 4ccf3f5799..c609142ccb 100644 --- a/spring-integration-mongodb/src/test/java/org/springframework/integration/mongodb/store/MongoMessageStoreTests.java +++ b/spring-integration-mongodb/src/test/java/org/springframework/integration/mongodb/store/MongoMessageStoreTests.java @@ -21,8 +21,8 @@ import org.junit.Test; import org.springframework.data.mongodb.MongoDbFactory; import org.springframework.data.mongodb.core.SimpleMongoDbFactory; import org.springframework.integration.Message; -import org.springframework.integration.mongodb.rules.MongodbAvailable; -import org.springframework.integration.mongodb.rules.MongodbAvailableTests; +import org.springframework.integration.mongodb.rules.MongoDbAvailable; +import org.springframework.integration.mongodb.rules.MongoDbAvailableTests; import org.springframework.integration.support.MessageBuilder; import com.mongodb.Mongo; @@ -33,10 +33,10 @@ import static org.junit.Assert.assertNotNull; * @author Mark Fisher * @author Oleg Zhurakousky */ -public class MongoMessageStoreTests extends MongodbAvailableTests{ +public class MongoMessageStoreTests extends MongoDbAvailableTests{ @Test - @MongodbAvailable + @MongoDbAvailable public void addGetWithStringPayload() throws Exception { MongoDbFactory mongoDbFactory = new SimpleMongoDbFactory(new Mongo(), "test"); MongoMessageStore store = new MongoMessageStore(mongoDbFactory); @@ -50,7 +50,7 @@ public class MongoMessageStoreTests extends MongodbAvailableTests{ @Test - @MongodbAvailable + @MongoDbAvailable public void addGetWithObjectDefaultConstructorPayload() throws Exception { MongoDbFactory mongoDbFactory = new SimpleMongoDbFactory(new Mongo(), "test"); MongoMessageStore store = new MongoMessageStore(mongoDbFactory);