@Test
public void processBulkAction() throws IOException {

	IdmBulkActionDto exampleAction = findBulkAction(IdmIdentity.class, IdentityUsernameExportBulkAction.BULK_ACTION_NAME);
	
	assertNotNull(exampleAction);
	
	IdmIdentityDto identity = getHelper().createIdentity();
	IdmIdentityDto identity2 = getHelper().createIdentity();
	IdmIdentityDto identity3 = getHelper().createIdentity();
	
	exampleAction.setIdentifiers(Sets.newHashSet(identity.getId(), identity2.getId(), identity3.getId()));
	
	IdmBulkActionDto processAction = bulkActionManager.processAction(exampleAction);
	assertNotNull(processAction.getLongRunningTaskId());
	IdmLongRunningTaskFilter context = new IdmLongRunningTaskFilter();
	context.setIncludeItemCounts(true);
	IdmLongRunningTaskDto longRunningTask = longRunningTaskService.get(processAction.getLongRunningTaskId(), context);
	assertEquals(Long.valueOf(3), longRunningTask.getCount());
	assertEquals(Long.valueOf(3), longRunningTask.getSuccessItemCount());
	assertEquals(Long.valueOf(0), longRunningTask.getFailedItemCount());
	assertEquals(Long.valueOf(0), longRunningTask.getWarningItemCount());
	OperationResult result = longRunningTask.getResult();
	ResultModel model = result.getModel();
	assertNotNull(model);
	assertEquals(206, model.getStatusCode());
	assertEquals(CoreResultCode.LONG_RUNNING_TASK_PARTITIAL_DOWNLOAD.getCode(), model.getStatusEnum());
	Map<String, Object> parameters = model.getParameters();
	assertNotNull(parameters);
	Object object = parameters.get(AttachableEntity.PARAMETER_ATTACHMENT_ID);
	assertNotNull(object);
	UUID fromString = UUID.fromString(object.toString());
	assertNotNull(fromString);
	IdmAttachmentDto attachmentDto = attachmentManager.get(fromString);
	assertNotNull(attachmentDto);
	assertEquals(longRunningTask.getId(), attachmentDto.getOwnerId());
	IdmAttachmentDto attachmentForLongRunningTask = longRunningTaskManager.getAttachment(longRunningTask.getId(), attachmentDto.getId());
	assertNotNull(attachmentForLongRunningTask);
	assertEquals(attachmentDto.getId(), attachmentForLongRunningTask.getId());
	
	InputStream is = attachmentManager.getAttachmentData(attachmentDto.getId());
	try {
		String string = IOUtils.toString(is);
		assertTrue(string.contains(identity.getUsername()));
		assertTrue(string.contains(identity2.getUsername()));
		assertTrue(string.contains(identity3.getUsername()));

		assertTrue(string.contains(IdmIdentity_.username.getName().toUpperCase()));
		assertTrue(string.contains(IdmIdentity_.externalCode.getName().toUpperCase()));
		assertTrue(string.contains(IdmIdentity_.state.getName().toUpperCase()));
	} finally {
		IOUtils.closeQuietly(is);
	}
}