/** *** */ private B2BRegistrationModel createB2BRegistrationModel() { final B2BRegistrationModel b2BRegistration = new B2BRegistrationModel(); b2BRegistration.setTitle(titleModel); final CountryModel country = new CountryModel(); country.setIsocode("US"); country.setActive(Boolean.TRUE); b2BRegistration.setCompanyAddressCountry(country); return b2BRegistration; }
@Test public void testPerform() { attachments = Arrays.asList(customer, b2BRegistrationModel); Mockito.doAnswer( new Answer<Object>() { @Override public Object answer(final InvocationOnMock invocation) { customers = new LinkedList<>(); return null; } }) .when(modelService) .remove(customer); Mockito.doAnswer( new Answer<Object>() { @Override public Object answer(final InvocationOnMock invocation) { customers = new ArrayList<CustomerModel>(); customers.add(b2BCustomer); return null; } }) .when(modelService) .save(b2BCustomer); Mockito.doAnswer( new Answer<Object>() { @Override public Object answer(final InvocationOnMock invocation) { attachments = new LinkedList<ItemModel>(); attachments = Arrays.asList(createB2BCustomerModel(customers.get(0)), b2BRegistrationModel); return null; } }) .when(workflowAttachmentService) .addItems(any(WorkflowModel.class), any(attachments.getClass())); workflowAttachmentService.addItems(workflowActionModel.getWorkflow(), attachments); when(userService.getUserForUID(b2BRegistrationModel.getEmail(), CustomerModel.class)) .thenReturn(customer); final List<ItemModel> customerAsList = new LinkedList<ItemModel>(); customerAsList.add(customer); when(workflowAttachmentService.getAttachmentsForAction( workflowActionModel, CustomerModel.class.getName())) .thenReturn(customerAsList); final List<ItemModel> b2BRegistrationModelAsList = new LinkedList<ItemModel>(); b2BRegistrationModelAsList.add(b2BRegistrationModel); when(workflowAttachmentService.getAttachmentsForAction( workflowActionModel, B2BRegistrationModel.class.getName())) .thenReturn(b2BRegistrationModelAsList); when(modelService.create(B2BCustomerModel.class)).thenReturn(b2BCustomer); final WorkflowModel workflowModel = new WorkflowModel(); workflowModel.setActions(Arrays.asList(workflowActionModel)); workflowActionModel.setWorkflow(workflowModel); final WorkflowDecisionModel decision = registrationApprovedAutomatedWorkflowTemplateJob.perform(workflowActionModel); assertEquals("The right decision shoule be returned", decision, workflowDecisionModel); assertTrue( "B2BCustomer should have been created", attachments.get(0) instanceof B2BCustomerModel); assertEquals( "B2BCustomer should have been assigned a B2BUnit", ((B2BCustomerModel) attachments.get(0)).getDefaultB2BUnit().getName(), b2bUnitModel.getName()); assertTrue( "b2BRegistrationModel should still be in workflow attachment", attachments.get(1).getClass().getName().endsWith("B2BRegistrationModel")); }