@Test public void testNoMatchingActionTemplate() { final WorkflowActionModel actionOne = Mockito.mock(WorkflowActionModel.class); Mockito.when(actionOne.getTemplate()).thenReturn(new WorkflowActionTemplateModel()); final WorkflowActionModel actionTwo = Mockito.mock(WorkflowActionModel.class); Mockito.when(actionTwo.getTemplate()).thenReturn(new WorkflowActionTemplateModel()); final WorkflowModel workFlow = Mockito.mock(WorkflowModel.class); Mockito.when(workFlow.getActions()).thenReturn(Arrays.asList(actionOne, actionTwo)); final WorkflowDecisionTemplateModel decisionTemplate = Mockito.mock(WorkflowDecisionTemplateModel.class); Mockito.when(decisionTemplate.getActionTemplate()) .thenReturn(new WorkflowActionTemplateModel()); Assert.assertSame(decision, factory.create(workFlow, decisionTemplate)); Mockito.verify(decision).setToActions(Collections.EMPTY_LIST); }
/** Creates some attachments and assigns them to the test workflow. */ @Test public void testAttachments() { final CatalogVersionModel testCv = catalogVersionService.getCatalogVersion("DefaultTestCatalog", "Online"); assertNotNull(testCv); final PK workflowPk = testWorkflow.getPk(); // create product attachment final ProductModel product = modelService.create(ProductModel.class); product.setCode("abc"); product.setCatalogVersion(testCv); modelService.save(product); assertNotNull("Product not null", product); final WorkflowItemAttachmentModel attachProduct = createAttachment("productTest", product, testWorkflow); assertNotNull("Attachment not null", attachProduct); // create category attachment final CategoryModel category = modelService.create(CategoryModel.class); category.setCode("abc"); category.setCatalogVersion(testCv); assertNotNull("Category not null", category); final WorkflowItemAttachmentModel attachCategory = createAttachment("categoryTest", category, testWorkflow); assertNotNull("Attachment not null", attachCategory); final WorkflowActionModel action1 = getAction(ACTIONCODES.ACTION1.name()); action1.setAttachments( Arrays.asList(new WorkflowItemAttachmentModel[] {attachProduct, attachCategory})); clearCache(); // check attachments final WorkflowModel found = modelService.get(workflowPk); assertEquals("Excpected number of attachments", 2, found.getAttachments().size()); final WorkflowActionModel foundAction = getAction(ACTIONCODES.ACTION1.name()); assertEquals( "Excpected number of attachments of action 1", 2, foundAction.getAttachments().size()); }
@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")); }