Moving tests to spring-test with autowiring.

This commit is contained in:
Michael Nitschinger
2012-12-17 14:23:00 +01:00
parent 2fa7345ccb
commit daa22767a1
4 changed files with 67 additions and 39 deletions

View File

@@ -49,5 +49,11 @@
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>3.1.3.RELEASE</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@@ -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<URI> baseList = new ArrayList<URI>();
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.

View File

@@ -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<URI> baseList = new ArrayList<URI>();
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.
*/

View File

@@ -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",
""
);
}
}