@Test public void primitiveLookupByName() { ApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class); boolean b = ctx.getBean("b", boolean.class); assertThat(b, equalTo(true)); int i = ctx.getBean("i", int.class); assertThat(i, equalTo(42)); }
@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 shouldImplementEqualsProperly() { final Collection<ConfigEntry> entries = new ArrayList<>(); entries.add(E1); assertThat(config, is(equalTo(config))); assertThat(config, is(equalTo(new Config(config.entries())))); assertThat(config, is(not(equalTo(new Config(entries))))); assertThat(config, is(not(equalTo((Object) "this")))); }
@Test public void testMultiClasses() { Class expectedClass1 = TestZuulFilter.class; Class expectedClass2 = TestZuulFilter2.class; when(configuration.getStringArray(eq("zuul.filters.classes"))).thenReturn(new String[]{"com.netflix.zuul.init.TestZuulFilter", "com.netflix.zuul.init2.TestZuulFilter2"}); when(configuration.getStringArray(eq("zuul.filters.packages"))).thenReturn(new String[0]); String[] classNames = module.findClassNames(configuration); assertThat(classNames.length, equalTo(2)); assertThat(classNames[0], equalTo(expectedClass1.getCanonicalName())); assertThat(classNames[1], equalTo(expectedClass2.getCanonicalName())); }
@Test public void testQueryCount() { expect() .statusCode(Status.OK.getStatusCode()) .body("count", equalTo(2)) .when() .get(HISTORIC_REPORT_COUNT_URL); verify(historicCaseInstanceReport).count(); verifyNoMoreInteractions(historicCaseInstanceReport); }
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")))); }
@Test void invalidExpressionEvaluationType() { String methodName = "nonBooleanOrStringExpression"; IllegalStateException exception = assertThrows(IllegalStateException.class, () -> condition.evaluateExecutionCondition(buildExtensionContext(methodName))); Method method = ReflectionUtils.findMethod(getClass(), methodName); assertThat(exception.getMessage(), is(equalTo("@DisabledIf(\"#{6 * 7}\") on " + method + " must evaluate to a String or a Boolean, not java.lang.Integer"))); }
private void testTransportUrl(String scheme, String expectedScheme, TransportType transportType) throws Exception { SockJsUrlInfo info = new SockJsUrlInfo(new URI(scheme + "://example.com")); String serverId = info.getServerId(); String sessionId = info.getSessionId(); String transport = transportType.toString().toLowerCase(); URI expected = new URI(expectedScheme + "://example.com/" + serverId + "/" + sessionId + "/" + transport); assertThat(info.getTransportUrl(transportType), equalTo(expected)); }
@Test public void propertyCountsWithNonStandardWriteMethod() throws IntrospectionException { class ExtendedTestBean extends TestBean { @SuppressWarnings("unused") public ExtendedTestBean setFoo(String s) { return this; } } BeanInfo bi = Introspector.getBeanInfo(ExtendedTestBean.class); BeanInfo ebi = new ExtendedBeanInfo(bi); boolean found = false; for (PropertyDescriptor pd : ebi.getPropertyDescriptors()) { if (pd.getName().equals("foo")) { found = true; } } assertThat(found, is(true)); assertThat(ebi.getPropertyDescriptors().length, equalTo(bi.getPropertyDescriptors().length+1)); }
@Test public void testMultiPackages() { Class expectedClass1 = TestZuulFilter.class; Class expectedClass2 = TestZuulFilter2.class; when(configuration.getStringArray(eq("zuul.filters.classes"))).thenReturn(new String[0]); when(configuration.getStringArray(eq("zuul.filters.packages"))).thenReturn(new String[]{"com.netflix.zuul.init", "com.netflix.zuul.init2"}); String[] classNames = module.findClassNames(configuration); assertThat(classNames.length, equalTo(2)); assertThat(classNames[0], equalTo(expectedClass1.getCanonicalName())); assertThat(classNames[1], equalTo(expectedClass2.getCanonicalName())); } }
@Test public void testMissingAuthorization() { String message = "not authorized"; when(historicCaseInstanceReport.list()).thenThrow(new AuthorizationException(message)); given() .then().expect() .statusCode(Status.FORBIDDEN.getStatusCode()) .contentType(ContentType.JSON) .body("type", equalTo(AuthorizationException.class.getSimpleName())) .body("message", equalTo(message)) .when().get(HISTORIC_REPORT_URL); }
@Test public void beanMethodOverloadingWithoutInheritance() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); ctx.register(ConfigWithOverloading.class); ctx.setAllowBeanDefinitionOverriding(false); ctx.refresh(); assertThat(ctx.getBean(String.class), equalTo("regular")); }
@Test public void testTransformUserEntityHappyCase() { UserEntity userEntity = userEntityJsonMapper.transformUserEntity(JSON_RESPONSE_USER_DETAILS); assertThat(userEntity.getUserId(), is(1)); assertThat(userEntity.getFullname(), is(equalTo("Simon Hill"))); assertThat(userEntity.getEmail(), is(equalTo("jcooper@babbleset.edu"))); }
@Test void unsupportedStringEvaluationValue() { String methodName = "stringExpressionThatIsNeitherTrueNorFalse"; IllegalStateException exception = assertThrows(IllegalStateException.class, () -> condition.evaluateExecutionCondition(buildExtensionContext(methodName))); Method method = ReflectionUtils.findMethod(getClass(), methodName); assertThat(exception.getMessage(), is(equalTo("@DisabledIf(\"#{'enigma'}\") on " + method + " must evaluate to \"true\" or \"false\", not \"enigma\""))); }
@Test public void findsBeansByTypeIfNotInstantiated() { AnnotationConfigApplicationContext bf = new AnnotationConfigApplicationContext(); bf.registerBeanDefinition("fooConfig", new RootBeanDefinition(FooConfig.class)); bf.getBeanFactory().addBeanPostProcessor(new PredictingBPP()); bf.refresh(); 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(1, equalTo(aiBeans.size())); assertThat("&foo", equalTo(aiBeans.keySet().iterator().next())); }
@Test public void testDefaultFilterLocations() { when(configuration.getStringArray(eq("zuul.filters.locations"))).thenReturn("inbound,outbound,endpoint".split(",")); String[] filterLocations = module.findFilterLocations(configuration); assertThat(filterLocations.length, equalTo(3)); assertThat(filterLocations[1], equalTo("outbound")); }
@Test public void testQueryCount() { expect() .statusCode(Status.OK.getStatusCode()) .body("count", equalTo(2)) .when() .get(HISTORIC_DETAIL_COUNT_RESOURCE_URL); verify(mockedQuery).count(); }
@Test @SuppressWarnings("resource") public void valueFieldsAreProcessedWhenPlaceholderConfigurerIsSegregated() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); ctx.register(ConfigWithValueField.class); ctx.register(ConfigWithPlaceholderConfigurer.class); System.setProperty("test.name", "foo"); ctx.refresh(); System.clearProperty("test.name"); TestBean testBean = ctx.getBean(TestBean.class); assertThat(testBean.getName(), equalTo("foo")); }
@Test public void testFileContent() { File fileToWrite = createDummyFile(); String fileContent = "content\n"; fileManager.writeToFile(fileToWrite, fileContent); String expectedContent = fileManager.readFileContent(fileToWrite); assertThat(expectedContent, is(equalTo(fileContent))); }