public void testSetProperties() throws Exception { Destination destination = new Destination(); PropertyUtils.setProperty(destination, "props.key", "value"); assertEquals("value", destination.getProps().getProperty("key")); PropertyUtils.setProperty(destination, "subDestination.props.key", "value"); assertEquals("value", destination.getSubDestination().getProps().getProperty("key")); PropertyUtils.setProperty(destination, "anInteger", "10"); assertEquals(10, destination.getAnInteger()); PropertyUtils.setProperty(destination, "subDestination.anInteger", "20"); assertEquals(20, destination.getSubDestination().getAnInteger()); PropertyUtils.setProperty(destination, "aBoolean", "true"); assertEquals(true, destination.isABoolean()); PropertyUtils.setProperty(destination, "aWriteOnlyInt", "20"); PrivateDestination privateDestination = new PrivateDestination(); try { PropertyUtils.setProperty(privateDestination, "subDestination.props.key", "value"); fail("it is not possible to set the 'subDestination' property, PropertyException should have been thrown"); } catch (PropertyException ex) { assertEquals("cannot set property 'subDestination.props.key' - 'subDestination' is null and cannot be auto-filled", ex.getMessage()); } }
public void testSetProperties() throws Exception { Destination destination = new Destination(); PropertyUtils.setProperty(destination, "props.key", "value"); assertEquals("value", destination.getProps().getProperty("key")); PropertyUtils.setProperty(destination, "subDestination.props.key", "value"); assertEquals("value", destination.getSubDestination().getProps().getProperty("key")); PropertyUtils.setProperty(destination, "anInteger", "10"); assertEquals(10, destination.getAnInteger()); PropertyUtils.setProperty(destination, "subDestination.anInteger", "20"); assertEquals(20, destination.getSubDestination().getAnInteger()); PropertyUtils.setProperty(destination, "aBoolean", "true"); assertEquals(true, destination.isABoolean()); PropertyUtils.setProperty(destination, "aWriteOnlyInt", "20"); PrivateDestination privateDestination = new PrivateDestination(); try { PropertyUtils.setProperty(privateDestination, "subDestination.props.key", "value"); fail("it is not possible to set the 'subDestination' property, PropertyException should have been thrown"); } catch (PropertyException ex) { assertEquals("cannot set property 'subDestination.props.key' - 'subDestination' is null and cannot be auto-filled", ex.getMessage()); } }
public void testSetPrimitiveTypes() throws Exception { Destination destination = new Destination(); PropertyUtils.setProperty(destination, "aString", "this is my string"); PropertyUtils.setProperty(destination, "aBoolean", "true"); PropertyUtils.setProperty(destination, "aByte", "100"); PropertyUtils.setProperty(destination, "aShort", "20000"); PropertyUtils.setProperty(destination, "anInteger", "300000"); PropertyUtils.setProperty(destination, "aLong", "4000000"); PropertyUtils.setProperty(destination, "aFloat", "3.14"); PropertyUtils.setProperty(destination, "aDouble", "0.654987"); assertEquals("this is my string", destination.getAString()); assertEquals(true, destination.isABoolean()); assertEquals(100, destination.getAByte()); assertEquals(20000, destination.getAShort()); assertEquals(300000, destination.getAnInteger()); assertEquals(4000000, destination.getALong()); assertEquals(3.14f, destination.getAFloat(), 0.01f); assertEquals(0.654987, destination.getADouble(), 0.000001); }
public void testSetPrimitiveTypes() throws Exception { Destination destination = new Destination(); PropertyUtils.setProperty(destination, "aString", "this is my string"); PropertyUtils.setProperty(destination, "aBoolean", "true"); PropertyUtils.setProperty(destination, "aByte", "100"); PropertyUtils.setProperty(destination, "aShort", "20000"); PropertyUtils.setProperty(destination, "anInteger", "300000"); PropertyUtils.setProperty(destination, "aLong", "4000000"); PropertyUtils.setProperty(destination, "aFloat", "3.14"); PropertyUtils.setProperty(destination, "aDouble", "0.654987"); assertEquals("this is my string", destination.getAString()); assertEquals(true, destination.isABoolean()); assertEquals(100, destination.getAByte()); assertEquals(20000, destination.getAShort()); assertEquals(300000, destination.getAnInteger()); assertEquals(4000000, destination.getALong()); assertEquals(3.14f, destination.getAFloat(), 0.01f); assertEquals(0.654987, destination.getADouble(), 0.000001); }