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 new file mode 100644 index 0000000000..cd9992b748 --- /dev/null +++ b/spring-integration-mongodb/src/test/java/org/springframework/integration/mongodb/rules/MongodbAvailable.java @@ -0,0 +1,31 @@ +/* + * Copyright 2002-2011 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.mongodb.rules; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * @author Oleg Zhurakousky + * + */ +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.METHOD}) +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 new file mode 100644 index 0000000000..77d82f198c --- /dev/null +++ b/spring-integration-mongodb/src/test/java/org/springframework/integration/mongodb/rules/MongodbAvailableRule.java @@ -0,0 +1,51 @@ +/* + * Copyright 2002-2011 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.mongodb.rules; + +import org.junit.rules.MethodRule; +import org.junit.runners.model.FrameworkMethod; +import org.junit.runners.model.Statement; + +import com.mongodb.Mongo; + +/** + * @author Oleg Zhurakousky + * + */ +public final class MongodbAvailableRule implements MethodRule{ + + public Statement apply(final Statement base, final FrameworkMethod method, Object target) { + return new Statement(){ + + @Override + public void evaluate() throws Throwable { + 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."); + 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 new file mode 100644 index 0000000000..2ed1972ab3 --- /dev/null +++ b/spring-integration-mongodb/src/test/java/org/springframework/integration/mongodb/rules/MongodbAvailableTests.java @@ -0,0 +1,27 @@ +/* + * Copyright 2002-2011 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.mongodb.rules; + +import org.junit.Rule; + +/** + * @author Oleg Zhurakousky + * + */ +public class MongodbAvailableTests { + @Rule + public MongodbAvailableRule redisAvailableRule = new MongodbAvailableRule(); +}