TSK-44 implement Holgers comments - assert only Exception type, not message; rename attachment id prefix and helper method

This commit is contained in:
BerndBreier 2018-01-08 11:15:47 +01:00 committed by Holger Hagen
parent 8b26f7564d
commit a6f95fcd55
4 changed files with 41 additions and 42 deletions

View File

@ -46,7 +46,7 @@ public class TaskServiceImpl implements TaskService {
private static final Logger LOGGER = LoggerFactory.getLogger(TaskServiceImpl.class); private static final Logger LOGGER = LoggerFactory.getLogger(TaskServiceImpl.class);
private static final String ID_PREFIX_OBJECT_REFERENCE = "ORI"; private static final String ID_PREFIX_OBJECT_REFERENCE = "ORI";
private static final String ID_PREFIX_ATTACHMENT = "ATT"; private static final String ID_PREFIX_ATTACHMENT = "TAI";
private static final String ID_PREFIX_TASK = "TKI"; private static final String ID_PREFIX_TASK = "TKI";
private static final String ID_PREFIX_BUSINESS_PROCESS = "BPI"; private static final String ID_PREFIX_BUSINESS_PROCESS = "BPI";
private TaskanaEngine taskanaEngine; private TaskanaEngine taskanaEngine;
@ -177,7 +177,7 @@ public class TaskServiceImpl implements TaskService {
this.classificationService.getClassification(classification.getKey(), this.classificationService.getClassification(classification.getKey(),
classification.getDomain()); classification.getDomain());
validatePrimaryObjectReference(task.getPrimaryObjRef(), "Task"); validateObjectReference(task.getPrimaryObjRef(), "primary ObjectReference", "Task");
validateAttachments(task); validateAttachments(task);
standardSettings(task); standardSettings(task);
this.taskMapper.insert(task); this.taskMapper.insert(task);
@ -431,24 +431,24 @@ public class TaskServiceImpl implements TaskService {
task.setPrimaryObjRef(objRef); task.setPrimaryObjRef(objRef);
} }
private void validatePrimaryObjectReference(ObjectReference primObjRef, String objName) private void validateObjectReference(ObjectReference objRef, String objRefType, String objName)
throws InvalidArgumentException { throws InvalidArgumentException {
// check that all values in the primary ObjectReference are set correctly // check that all values in the ObjectReference are set correctly
if (primObjRef == null) { if (objRef == null) {
throw new InvalidArgumentException("primary ObjectReference of " + objName + " must not be null"); throw new InvalidArgumentException(objRefType + " of " + objName + " must not be null");
} else if (primObjRef.getCompany() == null || primObjRef.getCompany().length() == 0) { } else if (objRef.getCompany() == null || objRef.getCompany().length() == 0) {
throw new InvalidArgumentException( throw new InvalidArgumentException(
"Company of primary ObjectReference of " + objName + " must not be empty"); "Company of " + objRefType + " of " + objName + " must not be empty");
} else if (primObjRef.getSystem() == null || primObjRef.getSystem().length() == 0) { } else if (objRef.getSystem() == null || objRef.getSystem().length() == 0) {
throw new InvalidArgumentException( throw new InvalidArgumentException(
"System of primary ObjectReference of " + objName + " must not be empty"); "System of " + objRefType + " of " + objName + " must not be empty");
} else if (primObjRef.getSystemInstance() == null || primObjRef.getSystemInstance().length() == 0) { } else if (objRef.getSystemInstance() == null || objRef.getSystemInstance().length() == 0) {
throw new InvalidArgumentException( throw new InvalidArgumentException(
"SystemInstance of primary ObjectReference of " + objName + " must not be empty"); "SystemInstance of " + objRefType + " of " + objName + " must not be empty");
} else if (primObjRef.getType() == null || primObjRef.getType().length() == 0) { } else if (objRef.getType() == null || objRef.getType().length() == 0) {
throw new InvalidArgumentException("Type of primary ObjectReference of " + objName + " must not be empty"); throw new InvalidArgumentException("Type of " + objRefType + " of " + objName + " must not be empty");
} else if (primObjRef.getValue() == null || primObjRef.getValue().length() == 0) { } else if (objRef.getValue() == null || objRef.getValue().length() == 0) {
throw new InvalidArgumentException("Value of primary ObjectReference of " + objName + " must not be empty"); throw new InvalidArgumentException("Value of" + objRefType + " of " + objName + " must not be empty");
} }
} }
@ -460,7 +460,7 @@ public class TaskServiceImpl implements TaskService {
for (Attachment attachment : attachments) { for (Attachment attachment : attachments) {
ObjectReference objRef = attachment.getObjectReference(); ObjectReference objRef = attachment.getObjectReference();
validatePrimaryObjectReference(objRef, "Attachment"); validateObjectReference(objRef, "ObjectReference", "Attachment");
if (attachment.getClassification() == null) { if (attachment.getClassification() == null) {
throw new InvalidArgumentException("Classification of attachment " + attachment + " must not be null"); throw new InvalidArgumentException("Classification of attachment " + attachment + " must not be null");
} }
@ -470,7 +470,7 @@ public class TaskServiceImpl implements TaskService {
private void standardUpdateActions(TaskImpl oldTaskImpl, TaskImpl newTaskImpl) private void standardUpdateActions(TaskImpl oldTaskImpl, TaskImpl newTaskImpl)
throws InvalidArgumentException, ConcurrencyException { throws InvalidArgumentException, ConcurrencyException {
validatePrimaryObjectReference(newTaskImpl.getPrimaryObjRef(), "Task"); validateObjectReference(newTaskImpl.getPrimaryObjRef(), "primary ObjectReference", "Task");
if (oldTaskImpl.getModified() != null && !oldTaskImpl.getModified().equals(newTaskImpl.getModified()) if (oldTaskImpl.getModified() != null && !oldTaskImpl.getModified().equals(newTaskImpl.getModified())
|| oldTaskImpl.getClaimed() != null && !oldTaskImpl.getClaimed().equals(newTaskImpl.getClaimed()) || oldTaskImpl.getClaimed() != null && !oldTaskImpl.getClaimed().equals(newTaskImpl.getClaimed())
|| oldTaskImpl.getState() != null && !oldTaskImpl.getState().equals(newTaskImpl.getState())) { || oldTaskImpl.getState() != null && !oldTaskImpl.getState().equals(newTaskImpl.getState())) {

View File

@ -141,4 +141,4 @@ CREATE TABLE ATTACHMENT(
RECEIVED TIMESTAMP NULL, RECEIVED TIMESTAMP NULL,
CUSTOM_ATTRIBUTES BLOB NULL, CUSTOM_ATTRIBUTES BLOB NULL,
PRIMARY KEY (ID) PRIMARY KEY (ID)
); );

View File

@ -86,8 +86,8 @@ public class CreateTaskAccTest extends AbstractAccTest {
Task createdTask = taskService.createTask(newTask); Task createdTask = taskService.createTask(newTask);
assertNotNull(createdTask); assertNotNull(createdTask);
// assertNotNull(createdTask.getAttachments()); assertNotNull(createdTask.getAttachments());
// assertEquals(1, createdTask.getAttachments().size()); assertEquals(1, createdTask.getAttachments().size());
} }
@WithAccessId( @WithAccessId(
@ -114,9 +114,8 @@ public class CreateTaskAccTest extends AbstractAccTest {
Task createdTask = taskService.createTask(newTask); Task createdTask = taskService.createTask(newTask);
assertNotNull(createdTask); assertNotNull(createdTask);
// assertNotNull(createdTask.getAttachments()); assertNotNull(createdTask.getAttachments());
// assertEquals(2, createdTask.getAttachments().size()); assertEquals(2, createdTask.getAttachments().size());
// further assertions
} }
@WithAccessId( @WithAccessId(
@ -136,7 +135,7 @@ public class CreateTaskAccTest extends AbstractAccTest {
try { try {
createdTask = taskService.createTask(newTask); createdTask = taskService.createTask(newTask);
} catch (InvalidArgumentException ex) { } catch (InvalidArgumentException ex) {
assertEquals("primary ObjectReference of Attachment must not be null", ex.getMessage()); // nothing to do
} }
newTask = makeNewTask(taskService); newTask = makeNewTask(taskService);
@ -146,7 +145,7 @@ public class CreateTaskAccTest extends AbstractAccTest {
try { try {
createdTask = taskService.createTask(newTask); createdTask = taskService.createTask(newTask);
} catch (InvalidArgumentException ex) { } catch (InvalidArgumentException ex) {
assertEquals("Value of primary ObjectReference of Attachment must not be empty", ex.getMessage()); // nothing to do
} }
newTask = makeNewTask(taskService); newTask = makeNewTask(taskService);
@ -157,7 +156,7 @@ public class CreateTaskAccTest extends AbstractAccTest {
try { try {
createdTask = taskService.createTask(newTask); createdTask = taskService.createTask(newTask);
} catch (InvalidArgumentException ex) { } catch (InvalidArgumentException ex) {
assertEquals("Type of primary ObjectReference of Attachment must not be empty", ex.getMessage()); // nothing to do
} }
newTask = makeNewTask(taskService); newTask = makeNewTask(taskService);
newTask.addAttachment(createAttachment("DOKTYP_DEFAULT", newTask.addAttachment(createAttachment("DOKTYP_DEFAULT",
@ -167,7 +166,7 @@ public class CreateTaskAccTest extends AbstractAccTest {
try { try {
createdTask = taskService.createTask(newTask); createdTask = taskService.createTask(newTask);
} catch (InvalidArgumentException ex) { } catch (InvalidArgumentException ex) {
assertEquals("SystemInstance of primary ObjectReference of Attachment must not be empty", ex.getMessage()); // nothing to do
} }
newTask = makeNewTask(taskService); newTask = makeNewTask(taskService);
newTask.addAttachment(createAttachment("DOKTYP_DEFAULT", newTask.addAttachment(createAttachment("DOKTYP_DEFAULT",
@ -177,7 +176,7 @@ public class CreateTaskAccTest extends AbstractAccTest {
try { try {
createdTask = taskService.createTask(newTask); createdTask = taskService.createTask(newTask);
} catch (InvalidArgumentException ex) { } catch (InvalidArgumentException ex) {
assertEquals("System of primary ObjectReference of Attachment must not be empty", ex.getMessage()); // nothing to do
} }
newTask = makeNewTask(taskService); newTask = makeNewTask(taskService);
newTask.addAttachment(createAttachment("DOKTYP_DEFAULT", newTask.addAttachment(createAttachment("DOKTYP_DEFAULT",
@ -187,7 +186,7 @@ public class CreateTaskAccTest extends AbstractAccTest {
try { try {
createdTask = taskService.createTask(newTask); createdTask = taskService.createTask(newTask);
} catch (InvalidArgumentException ex) { } catch (InvalidArgumentException ex) {
assertEquals("Company of primary ObjectReference of Attachment must not be empty", ex.getMessage()); // nothing to do
} }
} }
@ -311,7 +310,7 @@ public class CreateTaskAccTest extends AbstractAccTest {
try { try {
createdTask = taskService.createTask(newTask); createdTask = taskService.createTask(newTask);
} catch (InvalidArgumentException ex) { } catch (InvalidArgumentException ex) {
assertEquals("primary ObjectReference of Task must not be null", ex.getMessage()); // nothing to do
} }
// Exception // Exception
@ -323,7 +322,7 @@ public class CreateTaskAccTest extends AbstractAccTest {
try { try {
createdTask = taskService.createTask(newTask); createdTask = taskService.createTask(newTask);
} catch (InvalidArgumentException ex) { } catch (InvalidArgumentException ex) {
assertEquals("Value of primary ObjectReference of Task must not be empty", ex.getMessage()); // nothing to do
} }
// Exception // Exception
@ -336,7 +335,7 @@ public class CreateTaskAccTest extends AbstractAccTest {
try { try {
createdTask = taskService.createTask(newTask); createdTask = taskService.createTask(newTask);
} catch (InvalidArgumentException ex) { } catch (InvalidArgumentException ex) {
assertEquals("Type of primary ObjectReference of Task must not be empty", ex.getMessage()); // nothing to do
} }
// Exception // Exception
@ -349,7 +348,7 @@ public class CreateTaskAccTest extends AbstractAccTest {
try { try {
createdTask = taskService.createTask(newTask); createdTask = taskService.createTask(newTask);
} catch (InvalidArgumentException ex) { } catch (InvalidArgumentException ex) {
assertEquals("SystemInstance of primary ObjectReference of Task must not be empty", ex.getMessage()); // nothing to do
} }
// Exception // Exception
@ -362,7 +361,7 @@ public class CreateTaskAccTest extends AbstractAccTest {
try { try {
createdTask = taskService.createTask(newTask); createdTask = taskService.createTask(newTask);
} catch (InvalidArgumentException ex) { } catch (InvalidArgumentException ex) {
assertEquals("System of primary ObjectReference of Task must not be empty", ex.getMessage()); // nothing to do
} }
// Exception // Exception
@ -375,7 +374,7 @@ public class CreateTaskAccTest extends AbstractAccTest {
try { try {
createdTask = taskService.createTask(newTask); createdTask = taskService.createTask(newTask);
} catch (InvalidArgumentException ex) { } catch (InvalidArgumentException ex) {
assertEquals("Company of primary ObjectReference of Task must not be empty", ex.getMessage()); // nothing to do
} }
// Exception // Exception

View File

@ -74,39 +74,39 @@ public class UpdateTaskAccTest extends AbstractAccTest {
try { try {
updatedTask = taskService.updateTask(task); updatedTask = taskService.updateTask(task);
} catch (InvalidArgumentException ex) { } catch (InvalidArgumentException ex) {
assertEquals("primary ObjectReference of Task must not be null", ex.getMessage()); // nothing to do
} }
task.setPrimaryObjRef(createObjectReference("COMPANY_A", "SYSTEM_A", "INSTANCE_A", "VNR", null)); task.setPrimaryObjRef(createObjectReference("COMPANY_A", "SYSTEM_A", "INSTANCE_A", "VNR", null));
try { try {
updatedTask = taskService.updateTask(task); updatedTask = taskService.updateTask(task);
} catch (InvalidArgumentException ex) { } catch (InvalidArgumentException ex) {
assertEquals("Value of primary ObjectReference of Task must not be empty", ex.getMessage()); // nothing to do
} }
task.setPrimaryObjRef(createObjectReference("COMPANY_A", "SYSTEM_A", "INSTANCE_A", null, "1234567")); task.setPrimaryObjRef(createObjectReference("COMPANY_A", "SYSTEM_A", "INSTANCE_A", null, "1234567"));
try { try {
updatedTask = taskService.updateTask(task); updatedTask = taskService.updateTask(task);
} catch (InvalidArgumentException ex) { } catch (InvalidArgumentException ex) {
assertEquals("Type of primary ObjectReference of Task must not be empty", ex.getMessage()); // nothing to do
} }
task.setPrimaryObjRef(createObjectReference("COMPANY_A", "SYSTEM_A", null, "VNR", "1234567")); task.setPrimaryObjRef(createObjectReference("COMPANY_A", "SYSTEM_A", null, "VNR", "1234567"));
try { try {
updatedTask = taskService.updateTask(task); updatedTask = taskService.updateTask(task);
} catch (InvalidArgumentException ex) { } catch (InvalidArgumentException ex) {
assertEquals("SystemInstance of primary ObjectReference of Task must not be empty", ex.getMessage()); // nothing to do
} }
task.setPrimaryObjRef(createObjectReference("COMPANY_A", null, "INSTANCE_A", "VNR", "1234567")); task.setPrimaryObjRef(createObjectReference("COMPANY_A", null, "INSTANCE_A", "VNR", "1234567"));
try { try {
updatedTask = taskService.updateTask(task); updatedTask = taskService.updateTask(task);
} catch (InvalidArgumentException ex) { } catch (InvalidArgumentException ex) {
assertEquals("System of primary ObjectReference of Task must not be empty", ex.getMessage()); // nothing to do
} }
task.setPrimaryObjRef(createObjectReference(null, "SYSTEM_A", "INSTANCE_A", "VNR", "1234567")); task.setPrimaryObjRef(createObjectReference(null, "SYSTEM_A", "INSTANCE_A", "VNR", "1234567"));
try { try {
updatedTask = taskService.updateTask(task); updatedTask = taskService.updateTask(task);
} catch (InvalidArgumentException ex) { } catch (InvalidArgumentException ex) {
assertEquals("Company of primary ObjectReference of Task must not be empty", ex.getMessage()); // nothing to do
} }
} }