import java.net.Socket;
import java.util.ArrayList;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.testng.Assert;
import com.huawei.support.cache.ICassCache;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:applicationContext.xml")
public class TestCassCache
{
@Autowired
@Qualifier("cassCache")
private ICassCache cache;
@Test
public void testRemove() throws Exception
{
cache.remove("support.navigation..getProductLineNodes");
cache.remove("support.navigation.getProductLineNodes");
}
// 向缓存中存放数据
@Test
public void testPut() throws Exception
{
cache.put("key123", "name1", "stringValue");
}
// 向缓存中存放数据时出错
@Test
public void testPut2()
{
try
{
cache.put(null, null, null);
}
catch (Exception e)
{
Assert.assertTrue(true);
}
}
// 向缓存中存放数据时出错
@Test
public void testPut3()
{
ArrayList<Socket> obj = new ArrayList<Socket>();
// Socket不可序列化
obj.add(new Socket());
try
{
cache.put("key123", "name1", obj);
}
catch (Exception e)
{
Assert.assertTrue(true);
}
}
// 从缓存中取数据
@Test
public void testGet() throws Exception
{
cache.get("key123", "name1");
}
// 从缓存中取数据(不存在出错)
@Test
public void testGet2()
{
try
{
cache.get("key1234", "name1");
}
catch (Exception e)
{
Assert.assertTrue(true);
}
}
// 从缓存中取数据(出错)
@Test
public void testGet3()
{
try
{
cache.get(null, null);
}
catch (Exception e)
{
Assert.assertTrue(true);
}
}
// 从缓存中删除数据(不存在出错)
@Test
public void testRemove2()
{
try
{
cache.remove("key1234", "name12");
}
catch (Exception e)
{
Assert.assertTrue(true);
}
}
// 从缓存中删除数据(出错)
@Test
public void testRemove3()
{
try
{
cache.remove(null);
}
catch (Exception e)
{
Assert.assertTrue(true);
}
}
// 从缓存中删除数据(出错)
@Test
public void testRemove4()
{
try
{
cache.remove(null, null);
}
catch (Exception e)
{
Assert.assertTrue(true);
}
}
}
import java.util.ArrayList;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.testng.Assert;
import com.huawei.support.cache.ICassCache;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:applicationContext.xml")
public class TestCassCache
{
@Autowired
@Qualifier("cassCache")
private ICassCache cache;
@Test
public void testRemove() throws Exception
{
cache.remove("support.navigation..getProductLineNodes");
cache.remove("support.navigation.getProductLineNodes");
}
// 向缓存中存放数据
@Test
public void testPut() throws Exception
{
cache.put("key123", "name1", "stringValue");
}
// 向缓存中存放数据时出错
@Test
public void testPut2()
{
try
{
cache.put(null, null, null);
}
catch (Exception e)
{
Assert.assertTrue(true);
}
}
// 向缓存中存放数据时出错
@Test
public void testPut3()
{
ArrayList<Socket> obj = new ArrayList<Socket>();
// Socket不可序列化
obj.add(new Socket());
try
{
cache.put("key123", "name1", obj);
}
catch (Exception e)
{
Assert.assertTrue(true);
}
}
// 从缓存中取数据
@Test
public void testGet() throws Exception
{
cache.get("key123", "name1");
}
// 从缓存中取数据(不存在出错)
@Test
public void testGet2()
{
try
{
cache.get("key1234", "name1");
}
catch (Exception e)
{
Assert.assertTrue(true);
}
}
// 从缓存中取数据(出错)
@Test
public void testGet3()
{
try
{
cache.get(null, null);
}
catch (Exception e)
{
Assert.assertTrue(true);
}
}
// 从缓存中删除数据(不存在出错)
@Test
public void testRemove2()
{
try
{
cache.remove("key1234", "name12");
}
catch (Exception e)
{
Assert.assertTrue(true);
}
}
// 从缓存中删除数据(出错)
@Test
public void testRemove3()
{
try
{
cache.remove(null);
}
catch (Exception e)
{
Assert.assertTrue(true);
}
}
// 从缓存中删除数据(出错)
@Test
public void testRemove4()
{
try
{
cache.remove(null, null);
}
catch (Exception e)
{
Assert.assertTrue(true);
}
}
}