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 componentSingleConstructor() { this.context = new AnnotationConfigApplicationContext(BaseConfiguration.class, SingleConstructorComponent.class); assertThat(this.context.getBean(SingleConstructorComponent.class).autowiredName, is("foo")); }
private static void assertLastEvent(int[] event, long sequence, DummyEventHandler<int[]>... eh1) { for (DummyEventHandler<int[]> eh : eh1) { assertThat(eh.lastEvent, is(event)); assertThat(eh.lastSequence, is(sequence)); } }
@Test public void testSpr12701() throws Exception { ResolvableType resolvableType = ResolvableType.forClassWithGenerics(Callable.class, String.class); Type type = resolvableType.getType(); assertThat(type, is(instanceOf(ParameterizedType.class))); assertThat(((ParameterizedType) type).getRawType(), is(equalTo(Callable.class))); assertThat(((ParameterizedType) type).getActualTypeArguments().length, is(equalTo(1))); assertThat(((ParameterizedType) type).getActualTypeArguments()[0], is(equalTo(String.class))); }
private Map<Object, Object> listToMap(List<Object> list) { assertThat(list.size() % 2, is(0)); Map<Object, Object> res = new HashMap<>(); for (int i = 0; i < list.size(); i += 2) { res.put(list.get(i), list.get(i + 1)); } return res; }
@Test public void implicitTxManager() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); ctx.register(ImplicitTxManagerConfig.class); ctx.refresh(); FooRepository fooRepository = ctx.getBean(FooRepository.class); fooRepository.findAll(); CallCountingTransactionManager txManager = ctx.getBean(CallCountingTransactionManager.class); assertThat(txManager.begun, equalTo(1)); assertThat(txManager.commits, equalTo(1)); assertThat(txManager.rollbacks, equalTo(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 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 shouldSupportNullFieldType() throws Exception { String[] codes = resolver.resolveMessageCodes("errorCode", "objectName", "field", null); assertThat(codes, is(equalTo(new String[] { "errorCode.objectName.field", "errorCode.field", "errorCode" }))); }
@Test public void componentTwoConstructorsNoHint() { this.context = new AnnotationConfigApplicationContext(BaseConfiguration.class, TwoConstructorsComponent.class); assertThat(this.context.getBean(TwoConstructorsComponent.class).name, is("fallback")); }
@Test public void send() throws Exception { this.session.handleFrame(SockJsFrame.openFrame().getContent()); this.session.sendMessage(new TextMessage("foo")); assertThat(this.session.sentMessage, equalTo(new TextMessage("[\"foo\"]"))); }
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())); } }
private static void assertShutoownCalls(int startCalls, DummyEventHandler<int[]>... handlers) { for (DummyEventHandler<int[]> handler : handlers) { assertThat(handler.shutdownCalls, is(startCalls)); } } }
@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 @SuppressWarnings("rawtypes") public void getObjectType() { assertThat(factory.getObjectType(), is(equalTo((Class) DateTimeFormatter.class))); }
@Test public void shouldNotifyOfBatchProcessorLifecycle() throws Exception { new Thread(batchEventProcessor).start(); startLatch.await(); batchEventProcessor.halt(); shutdownLatch.await(); assertThat(Integer.valueOf(handler.startCounter), is(Integer.valueOf(1))); assertThat(Integer.valueOf(handler.shutdownCounter), is(Integer.valueOf(1))); }
@Test public void handleFrameClose() throws Exception { this.session.handleFrame(SockJsFrame.openFrame().getContent()); this.session.handleFrame(SockJsFrame.closeFrame(1007, "").getContent()); assertThat(this.session.isOpen(), equalTo(false)); assertThat(this.session.disconnectStatus, equalTo(new CloseStatus(1007, ""))); verify(this.handler).afterConnectionEstablished(this.session); verifyNoMoreInteractions(this.handler); }
private static void assertResponseEntityExist(Response httpResponse) { ReplicationListResponse entity = (ReplicationListResponse) httpResponse.getEntity(); assertThat(entity, is(notNullValue())); ReplicationInstanceResponse replicationResponse = entity.getResponseList().get(0); assertThat(replicationResponse.getResponseEntity(), is(notNullValue())); }
@Test public void withOptionArgsOnly() { CommandLinePropertySource<?> ps = new SimpleCommandLinePropertySource("--o1=v1", "--o2"); assertThat(ps.containsProperty("o1"), is(true)); assertThat(ps.containsProperty("o2"), is(true)); assertThat(ps.containsProperty("o3"), is(false)); assertThat(ps.getProperty("o1"), equalTo("v1")); assertThat(ps.getProperty("o2"), equalTo("")); assertThat(ps.getProperty("o3"), nullValue()); }
@Test public void shouldSupportMalformedIndexField() throws Exception { String[] codes = resolver.resolveMessageCodes("errorCode", "objectName", "field[", TestBean.class); assertThat(codes, is(equalTo(new String[] { "errorCode.objectName.field[", "errorCode.field[", "errorCode.org.springframework.tests.sample.beans.TestBean", "errorCode" }))); }