@Test public void performActionWithFullFormWithNonExistingCoordinators() throws Exception { final String name = "org name here"; final long id = 1L; String newName = "NEW org name here"; final DomainGroup newGroup = new DomainGroup(); final Person coordinatorMock = context.mock(Person.class); final HashMap<String, Serializable> formData = new HashMap<String, Serializable>(); formData.put("id", Long.toString(id)); formData.put("name", newName); formData.put("memberbershipcriteria", "someattrib=something"); Set<Person> requestedCoordinators = new HashSet<Person>(); final Person requestedCoordinator = new Person("aperson", "A", "Simple", "Person", "A"); requestedCoordinators.add(requestedCoordinator); formData.put("coordinators", (Serializable) requestedCoordinators); context.checking(new Expectations() { { oneOf(personMapperMock).findByAccountId(with(requestedCoordinator.getAccountId())); will(returnValue(null)); oneOf(factoryMock).getCreatePersonAction(personMapperMock, updaterMock); will(returnValue(personCreatorMock)); oneOf(persistStrategyMock).get(with(any(TaskHandlerActionContext.class)), with(any(HashMap.class))); will(returnValue(newGroup)); oneOf(personCreatorMock).execute(with(any(TaskHandlerActionContext.class))); will(returnValue(coordinatorMock)); oneOf(persistStrategyMock).persist(with(any(TaskHandlerActionContext.class)), with(any(HashMap.class)), with(any(DomainGroup.class))); oneOf(updaterMock).setProperties(with(any(Object.class)), with(any(HashMap.class))); } }); TaskHandlerActionContext<PrincipalActionContext> taskHandlerActionContext = TestContextCreator .createTaskHandlerContextWithPrincipal(formData, null); sut.execute(taskHandlerActionContext); context.assertIsSatisfied(); }
@Override public Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) throws ExecutionException { try { Map<String, Serializable> fields = (Map<String, Serializable>) inActionContext.getActionContext() .getParams(); Map<String, Serializable> newFields = new HashMap<String, Serializable>(); for (String key : fields.keySet()) { if (fields.get(key) instanceof Set) { Set<Person> verifiedPersons = reformatSet(inActionContext, (Set<Person>) fields.get(key)); newFields.put(key, (Serializable) verifiedPersons); } else { newFields.put(key, fields.get(key)); } } T resource = persistenceStrategy.get(inActionContext, newFields); updater.setProperties(resource, newFields); persistenceStrategy.persist(inActionContext, newFields, resource); return (Serializable) resource; } catch (Exception e) { if (e instanceof ValidationException) { ValidationException ve = (ValidationException) e; Set<Entry<String, String>> errors = ve.getErrors().entrySet(); StringBuffer b = new StringBuffer(); for (Entry<String, String> entry : errors) { b.append(entry.getKey() + ":" + entry.getValue() + " "); } log.error(b.toString()); } throw new ExecutionException(e); } }
PersistResourceExecution implements TaskHandlerExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) throws ExecutionException { try { Map<String, Serializable> fields = (Map<String, Serializable>) inActionContext.getActionContext() .getParams(); Map<String, Serializable> newFields = new HashMap<String, Serializable>(); for (String key : fields.keySet()) { if (fields.get(key) instanceof Set) { Set<Person> verifiedPersons = reformatSet(inActionContext, (Set<Person>) fields.get(key)); newFields.put(key, (Serializable) verifiedPersons); } else { newFields.put(key, fields.get(key)); } } T resource = persistenceStrategy.get(inActionContext, newFields); updater.setProperties(resource, newFields); persistenceStrategy.persist(inActionContext, newFields, resource); return (Serializable) resource; } catch (Exception e) { if (e instanceof ValidationException) { ValidationException ve = (ValidationException) e; Set<Entry<String, String>> errors = ve.getErrors().entrySet(); StringBuffer b = new StringBuffer(); for (Entry<String, String> entry : errors) { b.append(entry.getKey() + ":" + entry.getValue() + " "); } log.error(b.toString()); } throw new ExecutionException(e); } } }
PersistResourceExecution implements TaskHandlerExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) throws ExecutionException { try { Map<String, Serializable> fields = (Map<String, Serializable>) inActionContext.getActionContext() .getParams(); Map<String, Serializable> newFields = new HashMap<String, Serializable>(); for (String key : fields.keySet()) { if (fields.get(key) instanceof Set) { Set<Person> verifiedPersons = reformatSet(inActionContext, (Set<Person>) fields.get(key)); newFields.put(key, (Serializable) verifiedPersons); } else { newFields.put(key, fields.get(key)); } } T resource = persistenceStrategy.get(inActionContext, newFields); updater.setProperties(resource, newFields); persistenceStrategy.persist(inActionContext, newFields, resource); return (Serializable) resource; } catch (Exception e) { if (e instanceof ValidationException) { ValidationException ve = (ValidationException) e; Set<Entry<String, String>> errors = ve.getErrors().entrySet(); StringBuffer b = new StringBuffer(); for (Entry<String, String> entry : errors) { b.append(entry.getKey() + ":" + entry.getValue() + " "); } log.error(b.toString()); } throw new ExecutionException(e); } } @SuppressWarnings("unchecked")  PersistResourceExecution(final PersonMapper inPersonMapper, final CreatePersonActionFactory inFactory,
            final UpdaterStrategy inUpdater, final ResourcePersistenceStrategy inPersistenceStrategy); }
PersistResourceExecution implements TaskHandlerExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) throws ExecutionException { try { Map<String, Serializable> fields = (Map<String, Serializable>) inActionContext.getActionContext() .getParams(); Map<String, Serializable> newFields = new HashMap<String, Serializable>(); for (String key : fields.keySet()) { if (fields.get(key) instanceof Set) { Set<Person> verifiedPersons = reformatSet(inActionContext, (Set<Person>) fields.get(key)); newFields.put(key, (Serializable) verifiedPersons); } else { newFields.put(key, fields.get(key)); } } T resource = persistenceStrategy.get(inActionContext, newFields); updater.setProperties(resource, newFields); persistenceStrategy.persist(inActionContext, newFields, resource); return (Serializable) resource; } catch (Exception e) { if (e instanceof ValidationException) { ValidationException ve = (ValidationException) e; Set<Entry<String, String>> errors = ve.getErrors().entrySet(); StringBuffer b = new StringBuffer(); for (Entry<String, String> entry : errors) { b.append(entry.getKey() + ":" + entry.getValue() + " "); } log.error(b.toString()); } throw new ExecutionException(e); } } @SuppressWarnings("unchecked")  PersistResourceExecution(final PersonMapper inPersonMapper, final CreatePersonActionFactory inFactory,
            final UpdaterStrategy inUpdater, final ResourcePersistenceStrategy inPersistenceStrategy); @Override Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext); }
PersistResourceExecution implements TaskHandlerExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) throws ExecutionException { try { Map<String, Serializable> fields = (Map<String, Serializable>) inActionContext.getActionContext() .getParams(); Map<String, Serializable> newFields = new HashMap<String, Serializable>(); for (String key : fields.keySet()) { if (fields.get(key) instanceof Set) { Set<Person> verifiedPersons = reformatSet(inActionContext, (Set<Person>) fields.get(key)); newFields.put(key, (Serializable) verifiedPersons); } else { newFields.put(key, fields.get(key)); } } T resource = persistenceStrategy.get(inActionContext, newFields); updater.setProperties(resource, newFields); persistenceStrategy.persist(inActionContext, newFields, resource); return (Serializable) resource; } catch (Exception e) { if (e instanceof ValidationException) { ValidationException ve = (ValidationException) e; Set<Entry<String, String>> errors = ve.getErrors().entrySet(); StringBuffer b = new StringBuffer(); for (Entry<String, String> entry : errors) { b.append(entry.getKey() + ":" + entry.getValue() + " "); } log.error(b.toString()); } throw new ExecutionException(e); } } @SuppressWarnings("unchecked")  PersistResourceExecution(final PersonMapper inPersonMapper, final CreatePersonActionFactory inFactory,
            final UpdaterStrategy inUpdater, final ResourcePersistenceStrategy inPersistenceStrategy); @Override Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext);  }