diff --git a/pom.xml b/pom.xml index e3b3dc89..efe3daae 100644 --- a/pom.xml +++ b/pom.xml @@ -49,5 +49,11 @@ 4.11 test + + org.springframework + spring-test + 3.1.3.RELEASE + test + diff --git a/src/test/java/com/couchbase/spring/cache/CouchbaseCacheManagerTest.java b/src/test/java/com/couchbase/spring/cache/CouchbaseCacheManagerTest.java index 8f300f7f..e71ecea9 100644 --- a/src/test/java/com/couchbase/spring/cache/CouchbaseCacheManagerTest.java +++ b/src/test/java/com/couchbase/spring/cache/CouchbaseCacheManagerTest.java @@ -23,39 +23,28 @@ package com.couchbase.spring.cache; import com.couchbase.client.CouchbaseClient; -import java.net.URI; -import java.util.ArrayList; -import java.util.Collection; +import com.couchbase.spring.config.TestApplicationConfig; import java.util.HashMap; import static org.junit.Assert.*; -import org.junit.BeforeClass; import org.junit.Test; -import org.springframework.cache.Cache; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * Verifies the correct functionality of the CouchbaseCacheManager. */ +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = TestApplicationConfig.class) public class CouchbaseCacheManagerTest { /** * Contains a reference to the actual CouchbaseClient. */ - private static CouchbaseClient client; + @Autowired + private CouchbaseClient client; - /** - * Setup a CouchbaseClient before the tests run. - * - * @throws Exception - */ - @BeforeClass - public static void setupCouchbase() throws Exception { - ArrayList baseList = new ArrayList(); - baseList.add(URI.create("http://127.0.0.1:8091/pools")); - String bucketName = "default"; - String pwd = ""; - - client = new CouchbaseClient(baseList, bucketName, pwd); - } /** * Tests the main functionality of the manager: loading the caches. diff --git a/src/test/java/com/couchbase/spring/cache/CouchbaseCacheTest.java b/src/test/java/com/couchbase/spring/cache/CouchbaseCacheTest.java index 38d79c6c..6e09ea1a 100644 --- a/src/test/java/com/couchbase/spring/cache/CouchbaseCacheTest.java +++ b/src/test/java/com/couchbase/spring/cache/CouchbaseCacheTest.java @@ -23,43 +23,33 @@ package com.couchbase.spring.cache; import com.couchbase.client.CouchbaseClient; -import java.net.URI; -import java.util.ArrayList; +import com.couchbase.spring.config.TestApplicationConfig; import static org.junit.Assert.*; -import org.junit.BeforeClass; import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.Cache.ValueWrapper; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * Tests the CouchbaseCache class and verifies its functionality. */ +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = TestApplicationConfig.class) public class CouchbaseCacheTest { /** * Contains a reference to the actual CouchbaseClient. */ - private static CouchbaseClient client; + @Autowired + private CouchbaseClient client; /** * Simple name of the cache bucket to create. */ private String cacheName = "test"; - /** - * Setup a CouchbaseClient before the tests run. - * - * @throws Exception - */ - @BeforeClass - public static void setupCouchbase() throws Exception { - ArrayList baseList = new ArrayList(); - baseList.add(URI.create("http://127.0.0.1:8091/pools")); - String bucketName = "default"; - String pwd = ""; - - client = new CouchbaseClient(baseList, bucketName, pwd); - } - /** * Tests the basic Cache construction functionality. */ diff --git a/src/test/java/com/couchbase/spring/config/TestApplicationConfig.java b/src/test/java/com/couchbase/spring/config/TestApplicationConfig.java new file mode 100644 index 00000000..11f8fca4 --- /dev/null +++ b/src/test/java/com/couchbase/spring/config/TestApplicationConfig.java @@ -0,0 +1,43 @@ +/** + * Copyright (C) 2009-2012 Couchbase, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALING + * IN THE SOFTWARE. + */ + +package com.couchbase.spring.config; + +import com.couchbase.client.CouchbaseClient; +import java.io.IOException; +import java.net.URI; +import java.util.Arrays; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class TestApplicationConfig { + + @Bean + public CouchbaseClient couchbaseClient() throws IOException { + return new CouchbaseClient( + Arrays.asList(URI.create("http://127.0.0.1:8091/pools")), + "default", + "" + ); + } +}