private static void verifyResponseOkWithEntity(InstanceInfo original, EurekaHttpResponse<InstanceInfo> httpResponse) { assertThat(httpResponse.getStatusCode(), is(equalTo(200))); assertThat(httpResponse.getEntity(), is(notNullValue())); assertThat(EurekaEntityComparators.equal(httpResponse.getEntity(), original), is(true)); }
@Test public void shouldCompareInterfaces() throws Exception { Comparator<Object> comparator = new InstanceComparator<>(I1.class, I2.class); assertThat(comparator.compare(c1, c1), is(0)); assertThat(comparator.compare(c1, c2), is(0)); assertThat(comparator.compare(c2, c1), is(0)); assertThat(comparator.compare(c1, c3), is(-1)); assertThat(comparator.compare(c3, c1), is(1)); assertThat(comparator.compare(c3, c4), is(0)); }
private void assertBeanPropertyValueOf(String propertyName, String expected, DefaultListableBeanFactory factory) { BeanDefinition bean = factory.getBeanDefinition(expected); PropertyValue value = bean.getPropertyValues().getPropertyValue(propertyName); assertThat(value, is(notNullValue())); assertThat(value.getValue().toString(), is(expected)); }
@Test public void testCreateCloudDataStore() { given(mockUserCache.isExpired()).willReturn(true); given(mockUserCache.isCached(FAKE_USER_ID)).willReturn(false); UserDataStore userDataStore = userDataStoreFactory.create(FAKE_USER_ID); assertThat(userDataStore, is(notNullValue())); assertThat(userDataStore, is(instanceOf(CloudUserDataStore.class))); verify(mockUserCache).isExpired(); } }
private void testInfoUrl(String scheme, String expectedScheme) throws Exception { SockJsUrlInfo info = new SockJsUrlInfo(new URI(scheme + "://example.com")); Assert.assertThat(info.getInfoUrl(), is(equalTo(new URI(expectedScheme + "://example.com/info")))); }
public void testContainsUserDetailsFragment() { Fragment userDetailsFragment = userDetailsActivity.getFragmentManager().findFragmentById(R.id.fragmentContainer); assertThat(userDetailsFragment, is(notNullValue())); }
private static void verifyResponseOkWithEntity(Applications original, EurekaHttpResponse<Applications> httpResponse) { assertThat(httpResponse.getStatusCode(), is(equalTo(200))); assertThat(httpResponse.getEntity(), is(notNullValue())); assertThat(EurekaEntityComparators.equal(httpResponse.getEntity(), original), is(true)); }
@Test public void shouldDefaultToAscending() throws Exception { InvertibleComparator<Integer> invertibleComparator = new InvertibleComparator<>(comparator); assertThat(invertibleComparator.isAscending(), is(true)); assertThat(invertibleComparator.compare(1, 2), is(-1)); }
@Test public void testCreateDiskDataStore() { given(mockUserCache.isCached(FAKE_USER_ID)).willReturn(true); given(mockUserCache.isExpired()).willReturn(false); UserDataStore userDataStore = userDataStoreFactory.create(FAKE_USER_ID); assertThat(userDataStore, is(notNullValue())); assertThat(userDataStore, is(instanceOf(DiskUserDataStore.class))); verify(mockUserCache).isCached(FAKE_USER_ID); verify(mockUserCache).isExpired(); }
public void expectTransientErrors(int count) throws InterruptedException { for (int i = 0; i < count; i++) { ProcessingResult task = transientErrorTasks.poll(5, TimeUnit.SECONDS); assertThat(task, is(notNullValue())); } }
@Test public void testBasicAuthentication() throws Exception { InstanceInfo instance = InstanceInfoGenerator.takeOne(); when(requestHandler.register(instance)).thenReturn(EurekaHttpResponse.status(204)); EurekaHttpResponse<Void> httpResponse = getEurekaClientWithBasicAuthentication("myuser", "mypassword").register(instance); assertThat(httpResponse.getStatusCode(), is(equalTo(204))); assertThat(observedHttpRequests.get(0).getHeaders().containsKey(HttpHeaders.AUTHORIZATION), is(true)); }
@Test public void shouldInvert() throws Exception { InvertibleComparator<Integer> invertibleComparator = new InvertibleComparator<>(comparator); assertThat(invertibleComparator.isAscending(), is(true)); assertThat(invertibleComparator.compare(1, 2), is(-1)); invertibleComparator.invertOrder(); assertThat(invertibleComparator.isAscending(), is(false)); assertThat(invertibleComparator.compare(1, 2), is(1)); }
public void expectPermanentErrors(int count) throws InterruptedException { for (int i = 0; i < count; i++) { ProcessingResult task = permanentErrorTasks.poll(5, TimeUnit.SECONDS); assertThat(task, is(notNullValue())); } } }
@Test public void shouldInvokeAwareMethodsInImportBeanDefinitionRegistrar() { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class); context.getBean(MessageSource.class); assertThat(SampleRegistrar.beanFactory, is(context.getBeanFactory())); assertThat(SampleRegistrar.classLoader, is(context.getBeanFactory().getBeanClassLoader())); assertThat(SampleRegistrar.resourceLoader, is(notNullValue())); assertThat(SampleRegistrar.environment, is(context.getEnvironment())); }
@Test public void containsConstant() { assertThat(ObjectUtils.containsConstant(Tropes.values(), "FOO"), is(true)); assertThat(ObjectUtils.containsConstant(Tropes.values(), "foo"), is(true)); assertThat(ObjectUtils.containsConstant(Tropes.values(), "BaR"), is(true)); assertThat(ObjectUtils.containsConstant(Tropes.values(), "bar"), is(true)); assertThat(ObjectUtils.containsConstant(Tropes.values(), "BAZ"), is(true)); assertThat(ObjectUtils.containsConstant(Tropes.values(), "baz"), is(true)); assertThat(ObjectUtils.containsConstant(Tropes.values(), "BOGUS"), is(false)); assertThat(ObjectUtils.containsConstant(Tropes.values(), "FOO", true), is(true)); assertThat(ObjectUtils.containsConstant(Tropes.values(), "foo", true), is(false)); }
public void expectSuccesses(int count) throws InterruptedException { for (int i = 0; i < count; i++) { ProcessingResult task = completedTasks.poll(5, TimeUnit.SECONDS); assertThat(task, is(notNullValue())); } }
@Test public void findsBeansByTypeIfNotInstantiated() { assertThat(bf.isTypeMatch("&foo", FactoryBean.class), is(true)); @SuppressWarnings("rawtypes") Map<String, FactoryBean> fbBeans = bf.getBeansOfType(FactoryBean.class); assertThat(1, equalTo(fbBeans.size())); assertThat("&foo", equalTo(fbBeans.keySet().iterator().next())); Map<String, AnInterface> aiBeans = bf.getBeansOfType(AnInterface.class); assertThat(aiBeans.size(), is(1)); assertThat(aiBeans.keySet(), hasItem("&foo")); }
@Test public void withLocationAndExplicitNameAndExplicitClassLoader() throws IOException { PropertySource<?> ps = new ResourcePropertySource("ps1", PROPERTIES_LOCATION, getClass().getClassLoader()); assertEquals("bar", ps.getProperty("foo")); assertThat(ps.getName(), is("ps1")); }
private void runTestAndVerifyHierarchies(Class<? extends FooTestCase> testClass, boolean isFooContextActive, boolean isBarContextActive, boolean isBazContextActive) { JUnitCore jUnitCore = new JUnitCore(); Result result = jUnitCore.run(testClass); assertTrue("all tests passed", result.wasSuccessful()); assertThat(ContextHierarchyDirtiesContextTests.context, notNullValue()); ConfigurableApplicationContext bazContext = (ConfigurableApplicationContext) ContextHierarchyDirtiesContextTests.context; assertEquals("baz", ContextHierarchyDirtiesContextTests.baz); assertThat("bazContext#isActive()", bazContext.isActive(), is(isBazContextActive)); ConfigurableApplicationContext barContext = (ConfigurableApplicationContext) bazContext.getParent(); assertThat(barContext, notNullValue()); assertEquals("bar", ContextHierarchyDirtiesContextTests.bar); assertThat("barContext#isActive()", barContext.isActive(), is(isBarContextActive)); ConfigurableApplicationContext fooContext = (ConfigurableApplicationContext) barContext.getParent(); assertThat(fooContext, notNullValue()); assertEquals("foo", ContextHierarchyDirtiesContextTests.foo); assertThat("fooContext#isActive()", fooContext.isActive(), is(isFooContextActive)); }
@Test public void buildContextHierarchyMapForTestClassHierarchyWithMultiLevelContextHierarchies() { Map<String, List<ContextConfigurationAttributes>> map = buildContextHierarchyMap(TestClass3WithMultiLevelContextHierarchy.class); assertThat(map.size(), is(3)); assertThat(map.keySet(), hasItems("alpha", "beta", "gamma")); List<ContextConfigurationAttributes> alphaConfig = map.get("alpha"); assertThat(alphaConfig.size(), is(3)); assertThat(alphaConfig.get(0).getLocations()[0], is("1-A.xml")); assertThat(alphaConfig.get(1).getLocations()[0], is("2-A.xml")); assertThat(alphaConfig.get(2).getLocations()[0], is("3-A.xml")); List<ContextConfigurationAttributes> betaConfig = map.get("beta"); assertThat(betaConfig.size(), is(3)); assertThat(betaConfig.get(0).getLocations()[0], is("1-B.xml")); assertThat(betaConfig.get(1).getLocations()[0], is("2-B.xml")); assertThat(betaConfig.get(2).getLocations()[0], is("3-B.xml")); List<ContextConfigurationAttributes> gammaConfig = map.get("gamma"); assertThat(gammaConfig.size(), is(1)); assertThat(gammaConfig.get(0).getLocations()[0], is("3-C.xml")); }