@Test public void should_add_date_of_birth_success() throws Exception { Customer customer = new Customer(); customer.setDateOfBirth("2014-5-15"); DateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd"); assertThat(dateFormatter.format(customer.getDateOfBirth()), is("2014-05-15")); assertThat(customer.getDateOfBirth(), isA(Date.class)); }
@Override public Result execute(InteractionContext ctx) throws InteractionException { assert (ctx != null); // retrieve from a database, etc. String id = ctx.getId(); Customer customer = daoHibernate.getCustomer(id); if (customer != null) { // Convert Customer object into Entity object EntityProperties addressFields = new EntityProperties(); addressFields.setProperty( new EntityProperty("postcode", customer.getAddress().getPostcode())); addressFields.setProperty( new EntityProperty("houseNumber", customer.getAddress().getHouseNumber())); EntityProperties props = new EntityProperties(); props.setProperty(new EntityProperty("name", customer.getName())); props.setProperty(new EntityProperty("address", addressFields)); props.setProperty(new EntityProperty("dateOfBirth", customer.getDateOfBirth())); Entity entity = new Entity("Customer", props); ctx.setResource(createEntityResource(entity)); return Result.SUCCESS; } else { return Result.FAILURE; } }