@Test public void testSecure() throws MalformedURLException { CookieJar jar = new CookieJar(); Cookie cookie = new Cookie("myname", "myvalue"); cookie.setDomain(".10gen.com"); cookie.setPath("/"); cookie.setSecure(true); jar.addCookie(new URL("https://www.10gen.com"), cookie); assertSame(cookie, jar.getActiveCookies(new URL("https://10gen.com/")).get("myname")); assertSame(0, jar.getActiveCookies(new URL("http://10gen.com/")).size()); }
@Test public void testPath() throws MalformedURLException { CookieJar jar = new CookieJar(); Cookie cookie = new Cookie("myname", "myvalue"); cookie.setDomain(".10gen.com"); cookie.setPath("/subdir"); jar.addCookie(new URL("http://www.10gen.com/subdir"), cookie); assertSame( cookie, jar.getActiveCookies(new URL("http://10gen.com/subdir/moo/baa.html")).get("myname")); assertSame(0, jar.getActiveCookies(new URL("http://10gen.com/otherdir/")).size()); }
@Test public void testSimple() throws MalformedURLException { CookieJar jar = new CookieJar(); Cookie cookie = new Cookie("myname", "myvalue"); cookie.setDomain("10gen.com"); cookie.setPath("/"); jar.addCookie(new URL("http://10gen.com/"), cookie); // make sure it was actually saved assertSame(cookie, jar.getAll().get("myname")); // make sure it would resent to the same url assertSame(cookie, jar.getActiveCookies(new URL("http://10gen.com/")).get("myname")); // make sure it won't be sent elsewhere URL otherUrl = new URL("http://someotherhost.com/with/random/path"); assertEquals(0, jar.getActiveCookies(otherUrl).size()); }
public void shouldFindArtifact() { when(artifactFactory.createArtifact( coord.getGroupId(), coord.getArtifactId(), coord.getVersion(), "", coord.getFileType())) .thenReturn(goodArtifact); try { assertSame(locator.getAbsolutePathToArtifact(coord), A_PATH); } catch (Exception e) { fail("Should not have thrown an exception."); } }
@Test public void testInvalidDomain() throws MalformedURLException { CookieJar jar = new CookieJar(); Cookie cookie = new Cookie("myname", "myvalue"); cookie.setDomain(".10gen.com"); cookie.setPath("/subdir"); jar.addCookie(new URL("http://othersite.com/"), cookie); assertSame(0, jar.getAll().size()); }
// ------------------------------------------------------------------------- @Test public void testGetConfigByUid() { final SimpleExchange target = new SimpleExchange(); target.setName("Test"); when(_underlying.getConfig(eq(SimpleExchange.class), eq(UID))).thenReturn(target); Response test = _resource.get(OID.toString(), SimpleExchange.class.getName(), UID.getVersion(), "", ""); assertEquals(Status.OK.getStatusCode(), test.getStatus()); assertSame(target, test.getEntity()); }
@Test public final void shouldAlwaysReturnTheSameCache() { final Cache<Object, Object> testDefaultCache1 = this.applicationContext.getBean(DEFAULT_CACHE_NAME, Cache.class); final Cache<Object, Object> testDefaultCache2 = this.applicationContext.getBean(DEFAULT_CACHE_NAME, Cache.class); assertSame( "InfinispanDefaultCacheFactoryBean should always return the same cache instance when being " + "called repeatedly. However, the cache instances are not the same.", testDefaultCache1, testDefaultCache2); }
@Test public void lookupBound() throws Exception { registry.bind(KEY, VALUE); final String result = registry.lookup(KEY); assertSame("Unexpected value found", VALUE, result); }
public void testCompileFunction() { final InMemoryFunctionRepository functions = new InMemoryFunctionRepository(); final MockFunction alwaysValid = new MockFunction("always valid", null, null); final MockFunction validUntil = new MockFunction("valid until", null, 30L); final MockFunction validFrom = new MockFunction("valid from", 30L, null); final MockFunction validWithin = new MockFunction("valid within", 30L, 30L); functions.addFunction(alwaysValid); functions.addFunction(validUntil); functions.addFunction(validFrom); functions.addFunction(validWithin); final CachingFunctionRepositoryCompiler compiler = new CachingFunctionRepositoryCompiler(); final CompiledFunctionService context = new CompiledFunctionService(functions, compiler, new FunctionCompilationContext()); final Instant timestamp = Instant.now(); // Everything compiled once final CompiledFunctionRepository compiledFunctionsNow = context.compileFunctionRepository(timestamp); assertSame( alwaysValid, compiledFunctionsNow.getDefinition(alwaysValid.getUniqueId()).getFunctionDefinition()); assertSame( validUntil, compiledFunctionsNow.getDefinition(validUntil.getUniqueId()).getFunctionDefinition()); assertSame( validFrom, compiledFunctionsNow.getDefinition(validFrom.getUniqueId()).getFunctionDefinition()); assertSame( validWithin, compiledFunctionsNow.getDefinition(validWithin.getUniqueId()).getFunctionDefinition()); assertEquals(1, alwaysValid._compileCount.get()); assertEquals(1, validUntil._compileCount.get()); assertEquals(1, validFrom._compileCount.get()); assertEquals(1, validWithin._compileCount.get()); // All previously compiled ones still valid, so should use the "previous" cache final CompiledFunctionRepository compiledFunctionsAheadWithin = context.compileFunctionRepository(timestamp.plusMillis(29L)); assertSame(compiledFunctionsNow, compiledFunctionsAheadWithin); assertEquals(1, alwaysValid._compileCount.get()); assertEquals(1, validUntil._compileCount.get()); assertEquals(1, validFrom._compileCount.get()); assertEquals(1, validWithin._compileCount.get()); // All previously compiled ones still valid, so should use the "previous" cache final CompiledFunctionRepository compiledFunctionsAheadLimit = context.compileFunctionRepository(timestamp.plusMillis(30L)); assertSame(compiledFunctionsNow, compiledFunctionsAheadLimit); assertEquals(1, alwaysValid._compileCount.get()); assertEquals(1, validUntil._compileCount.get()); assertEquals(1, validFrom._compileCount.get()); assertEquals(1, validWithin._compileCount.get()); // Some functions to be recompiled, others from the "previous" cache final CompiledFunctionRepository compiledFunctionsAheadBeyond = context.compileFunctionRepository(timestamp.plusMillis(31L)); assertNotSame(compiledFunctionsNow, compiledFunctionsAheadBeyond); assertSame( compiledFunctionsNow.getDefinition(alwaysValid.getUniqueId()), compiledFunctionsAheadBeyond.getDefinition(alwaysValid.getUniqueId())); assertNotSame( compiledFunctionsNow.getDefinition(validUntil.getUniqueId()), compiledFunctionsAheadBeyond.getDefinition(validUntil.getUniqueId())); assertSame( compiledFunctionsNow.getDefinition(validFrom.getUniqueId()), compiledFunctionsAheadBeyond.getDefinition(validFrom.getUniqueId())); assertNotSame( compiledFunctionsNow.getDefinition(validWithin.getUniqueId()), compiledFunctionsAheadBeyond.getDefinition(validWithin.getUniqueId())); assertEquals(1, alwaysValid._compileCount.get()); assertEquals(2, validUntil._compileCount.get()); assertEquals(1, validFrom._compileCount.get()); assertEquals(2, validWithin._compileCount.get()); // All previously compiled functions, so should use the "ahead" cache final CompiledFunctionRepository compiledFunctionsBeforeWithin = context.compileFunctionRepository(timestamp.minusMillis(30L)); assertSame(compiledFunctionsNow, compiledFunctionsBeforeWithin); assertEquals(1, alwaysValid._compileCount.get()); assertEquals(2, validUntil._compileCount.get()); assertEquals(1, validFrom._compileCount.get()); assertEquals(2, validWithin._compileCount.get()); // Some functions to be recompiled, others from the "ahead" cache final CompiledFunctionRepository compiledFunctionsBeforeBeyond = context.compileFunctionRepository(timestamp.minusMillis(31L)); assertNotSame(compiledFunctionsNow, compiledFunctionsBeforeBeyond); assertSame( compiledFunctionsNow.getDefinition(alwaysValid.getUniqueId()), compiledFunctionsBeforeBeyond.getDefinition(alwaysValid.getUniqueId())); assertSame( compiledFunctionsNow.getDefinition(validUntil.getUniqueId()), compiledFunctionsBeforeBeyond.getDefinition(validUntil.getUniqueId())); assertNotSame( compiledFunctionsNow.getDefinition(validFrom.getUniqueId()), compiledFunctionsBeforeBeyond.getDefinition(validFrom.getUniqueId())); assertNotSame( compiledFunctionsNow.getDefinition(validWithin.getUniqueId()), compiledFunctionsBeforeBeyond.getDefinition(validWithin.getUniqueId())); assertEquals(1, alwaysValid._compileCount.get()); assertEquals(2, validUntil._compileCount.get()); assertEquals(2, validFrom._compileCount.get()); assertEquals(3, validWithin._compileCount.get()); }
public void test_withSearchType_same() { ExternalIdSearch base = ExternalIdSearch.of(ExternalIdSearchType.ALL, ExternalId.of("A", "B")); assertSame(base, base.withSearchType(ExternalIdSearchType.ALL)); }
public void test_ofCorrectedTo_Instant_null() { VersionCorrection test = VersionCorrection.ofCorrectedTo((InstantProvider) null); assertSame(VersionCorrection.LATEST, test); }
public void test_of_InstantInstant_nulls() { VersionCorrection test = VersionCorrection.of((InstantProvider) null, (InstantProvider) null); assertSame(VersionCorrection.LATEST, test); }
public void test_of_VersionCorrection_null() { VersionCorrection test = VersionCorrection.of((VersionCorrection) null); assertSame(VersionCorrection.LATEST, test); }
// ------------------------------------------------------------------------- public void test_of_VersionCorrection() { VersionCorrection base = VersionCorrection.of(INSTANT1, INSTANT2); VersionCorrection test = VersionCorrection.of(base); assertSame(base, test); }
// ------------------------------------------------------------------------- public void test_withLatestFixed_noNulls() { VersionCorrection test = VersionCorrection.of(INSTANT1, INSTANT2); assertSame(test, test.withLatestFixed(INSTANT3)); }
public void test_parse_latests() { VersionCorrection test = VersionCorrection.parse("VLATEST.CLATEST"); assertSame(VersionCorrection.LATEST, test); }