@Test public void aBeanWithAValidAnnotationReturnsAConfigProperty() throws ConfigBuilderException { List<HandlerConfigProperty> properties = configPropertyParser.getConfigProperties(ConfigBeanWithAValidAnnotation.class); assertEquals(1, properties.size()); HandlerConfigProperty p = properties.get(0); assertEquals( p.getName(), "myProperty"); assertEquals( p.getDescription(), "My Property Description"); assertFalse(p.getValidationPattern().isPresent()); assertFalse(p.getDefaultValue().isPresent()); }
@Test public void testConfigSettersWhichHavePrimitiveArgumentAreDescribedUsingTheEquivalentWrapperType() throws ConfigBuilderException { List<HandlerConfigProperty> properties = configPropertyParser.getConfigProperties(ConfigBeanWithASetterWithPrimitiveTypeParameter.class); assertEquals(1, properties.size()); HandlerConfigProperty p = properties.get(0); assertTrue( p.isMandatory()); }
@Test public void primitiveTypedPropertiesGetDefaultValidation() throws ConfigBuilderException { Map<String, HandlerConfigProperty> m = configPropertyParser.getConfigPropertiesByName(ConfigBeanWithPrimitiveTypedProperties.class); assertEquals("^[-+]?\\d+$", m.get("integerProperty").getValidationPattern().get().pattern()); assertEquals("^[-+]?\\d+$", m.get("longProperty").getValidationPattern().get().pattern()); assertEquals("^[-+]?\\d+$", m.get("shortProperty").getValidationPattern().get().pattern()); assertEquals("^[-+]?[0-9]*\\.?[0-9]+(?:[eE][-+]?[0-9]+)?$", m.get("floatProperty").getValidationPattern().get().pattern()); assertEquals("^[-+]?[0-9]*\\.?[0-9]+(?:[eE][-+]?[0-9]+)?$", m.get("doubleProperty").getValidationPattern().get().pattern()); assertEquals("(?i)^true|false$", m.get("booleanProperty").getValidationPattern().get().pattern()); assertEquals("^\\S$", m.get("charProperty").getValidationPattern().get().pattern()); }
@Test public void defaultValuesCanBeConvertedToSimpleTypes() throws ConfigBuilderException { Map<String, HandlerConfigProperty> m = configPropertyParser.getConfigPropertiesByName(ConfigBeanWithPrimitiveTypedProperties.class); assertEquals(7, m.size()); assertEquals(1, m.get("integerProperty").getDefaultValue().get()); assertEquals(1000000L, m.get("longProperty").getDefaultValue().get()); assertEquals(1.23d, m.get("doubleProperty").getDefaultValue().get()); assertEquals(2.34f, m.get("floatProperty").getDefaultValue().get()); assertEquals(true, m.get("booleanProperty").getDefaultValue().get()); assertEquals('C', m.get("charProperty").getDefaultValue().get()); assertEquals((short)9, m.get("shortProperty").getDefaultValue().get()); }
@Test public void enumFieldsCanBeParsed() throws ConfigBuilderException { List<HandlerConfigProperty> properties = configPropertyParser.getConfigProperties(ConfigBeanWithEnumTypes.class); assertEquals(1, properties.size()); HandlerConfigProperty p = properties.get(0); assertEquals( p.getJavaType(), Scope.class); }
@Test public void aPropertyCanBeConfiguredNotMandatory() throws ConfigBuilderException { List<HandlerConfigProperty> properties = configPropertyParser.getConfigProperties(ConfigBeanPropertyCanBeConfiguredNotMandatory.class); assertEquals(1, properties.size()); HandlerConfigProperty p = properties.get(0); assertFalse( p.isMandatory()); }
@Test public void testAValidationPatternCanBeSetWithoutADefaultValue() throws ConfigBuilderException { List<HandlerConfigProperty> properties = configPropertyParser.getConfigProperties(ConfigBeanWithValidationPatternAndNoDefaultValue.class); HandlerConfigProperty p = properties.get(0); assertEquals("test.*", p.getValidationPattern().get().pattern()); }
@Test public void aPropertyIsMandatoryByDefault() throws ConfigBuilderException { List<HandlerConfigProperty> properties = configPropertyParser.getConfigProperties(ConfigBeanWithAValidAnnotation.class); assertEquals(1, properties.size()); HandlerConfigProperty p = properties.get(0); assertTrue( p.isMandatory()); }