return new TestSuite(ResolverCacheTest.class);
}
public void testCache()
{
ResolverCache cache = new ResolverCache();
cache.setNewCache("test", 1000);
assertTrue("Initial cache not empty", cache.getSize() == 0);
XRD xrd = new XRD();
Service atAuthService = new Service();
atAuthService.addMediaType(Tags.CONTENT_TYPE_XRDS + ";trust=none");
atAuthService.addType(Tags.SERVICE_AUTH_RES);
atAuthService.addURI("http://gcs.epok.net/xri/resolve?ns=at");
xrd.addService(atAuthService);
XRD xrd1 = new XRD();
Service dummyService = new Service();
dummyService.addMediaType(Tags.CONTENT_TYPE_XRDS + ";trust=none");
dummyService.addType(Tags.SERVICE_AUTH_RES);
dummyService.addURI("http://www.example.com/xri/resolve?id=1");
xrd1.addService(dummyService);
try {
GCSAuthority auth = new GCSAuthority("@");
cache.put(auth.toString(), false, false, xrd.toString().getBytes("UTF-8"), 1000);
assertTrue("Initial cache incorrect", cache.getSize() == 1);
cache.put(
AuthorityPath.buildAuthorityPath("@!a!b!foo").toString(), false, false, xrd1.toString().getBytes("UTF-8"), 1000);
assertTrue("Cache size incorrect", cache.getSize() == 2);
cache.put(
AuthorityPath.buildAuthorityPath("@!a!b!foo").toString(), false, false, xrd1.toString().getBytes("UTF-8"), 1000);
assertTrue("Cache stores duplicate element?", cache.getSize() == 2);
byte[] val =
cache.get(AuthorityPath.buildAuthorityPath("@!a!b!foo").toString(), false, false);
assertTrue("Cached value not found", val != null);
val =
cache.get(AuthorityPath.buildAuthorityPath("@!a!b!woo").toString(), false, false);
assertTrue("Cached value should not have been found", val == null);
}
catch (UnsupportedEncodingException e) {
assertTrue("Unexpected exception" + e, false);
}