TASK-1278: Extended Test Coverage of Assembler Classes
This commit is contained in:
parent
8832876b93
commit
d07459fe26
|
@ -38,12 +38,13 @@ public class TaskImpl extends TaskSummaryImpl implements Task {
|
|||
attachments = copyFrom.attachments.stream().map(Attachment::copy).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public CallbackState getCallbackState() {
|
||||
return callbackState;
|
||||
public String getClassificationId() {
|
||||
return classificationSummary == null ? null : classificationSummary.getId();
|
||||
}
|
||||
|
||||
public void setCallbackState(CallbackState callbackState) {
|
||||
this.callbackState = callbackState;
|
||||
@Override
|
||||
public TaskImpl copy() {
|
||||
return new TaskImpl(this);
|
||||
}
|
||||
|
||||
public String getClassificationKey() {
|
||||
|
@ -81,6 +82,14 @@ public class TaskImpl extends TaskSummaryImpl implements Task {
|
|||
this.customAttributes = customAttributes;
|
||||
}
|
||||
|
||||
public CallbackState getCallbackState() {
|
||||
return callbackState;
|
||||
}
|
||||
|
||||
public void setCallbackState(CallbackState callbackState) {
|
||||
this.callbackState = callbackState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getCallbackInfo() {
|
||||
if (callbackInfo == null) {
|
||||
|
@ -263,11 +272,6 @@ public class TaskImpl extends TaskSummaryImpl implements Task {
|
|||
((ClassificationSummaryImpl) this.classificationSummary).setCategory(classificationCategory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskImpl copy() {
|
||||
return new TaskImpl(this);
|
||||
}
|
||||
|
||||
protected boolean canEqual(Object other) {
|
||||
return (other instanceof TaskImpl);
|
||||
}
|
||||
|
@ -388,8 +392,4 @@ public class TaskImpl extends TaskSummaryImpl implements Task {
|
|||
+ custom16
|
||||
+ "]";
|
||||
}
|
||||
|
||||
public String getClassificationId() {
|
||||
return classificationSummary == null ? null : classificationSummary.getId();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -314,9 +314,6 @@ public class TaskSummaryImpl implements TaskSummary {
|
|||
|
||||
@Override
|
||||
public List<AttachmentSummary> getAttachmentSummaries() {
|
||||
if (attachmentSummaries == null) {
|
||||
attachmentSummaries = new ArrayList<>();
|
||||
}
|
||||
return attachmentSummaries;
|
||||
}
|
||||
|
||||
|
|
|
@ -175,16 +175,6 @@
|
|||
</rules>
|
||||
</token>
|
||||
</tokens>
|
||||
<groups>
|
||||
<group>
|
||||
<type>GETTERS_AND_SETTERS</type>
|
||||
<order>KEEP</order>
|
||||
</group>
|
||||
<group>
|
||||
<type>OVERRIDDEN_METHODS</type>
|
||||
<order>KEEP</order>
|
||||
</group>
|
||||
</groups>
|
||||
<rules>
|
||||
<section>
|
||||
<rule>
|
||||
|
@ -430,320 +420,7 @@
|
|||
<option name="TAB_SIZE" value="2" />
|
||||
</indentOptions>
|
||||
<arrangement>
|
||||
<rules>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>xmlns:android</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>xmlns:.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:id</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>style</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:.*Style</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:layout_width</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:layout_height</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:layout_weight</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:layout_margin</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:layout_marginTop</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:layout_marginBottom</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:layout_marginStart</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:layout_marginEnd</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:layout_marginLeft</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:layout_marginRight</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:layout_.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:padding</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:paddingTop</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:paddingBottom</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:paddingStart</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:paddingEnd</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:paddingLeft</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:paddingRight</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*</NAME>
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*</NAME>
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res-auto</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*</NAME>
|
||||
<XML_NAMESPACE>http://schemas.android.com/tools</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*</NAME>
|
||||
<XML_NAMESPACE>.*</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
</rules>
|
||||
<rules />
|
||||
</arrangement>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="protobuf">
|
||||
|
|
|
@ -9,7 +9,7 @@ import org.springframework.stereotype.Component;
|
|||
|
||||
import pro.taskana.classification.api.ClassificationService;
|
||||
import pro.taskana.classification.api.models.ClassificationSummary;
|
||||
import pro.taskana.classification.internal.models.ClassificationImpl;
|
||||
import pro.taskana.classification.internal.models.ClassificationSummaryImpl;
|
||||
import pro.taskana.classification.rest.models.ClassificationSummaryRepresentationModel;
|
||||
import pro.taskana.common.rest.Mapping;
|
||||
import pro.taskana.common.rest.assembler.TaskanaPagingAssembler;
|
||||
|
@ -60,10 +60,10 @@ public class ClassificationSummaryRepresentationModelAssembler
|
|||
}
|
||||
|
||||
public ClassificationSummary toEntityModel(ClassificationSummaryRepresentationModel repModel) {
|
||||
ClassificationImpl classification =
|
||||
(ClassificationImpl)
|
||||
ClassificationSummaryImpl classification =
|
||||
(ClassificationSummaryImpl)
|
||||
classificationService.newClassification(
|
||||
repModel.getKey(), repModel.getDomain(), repModel.getType());
|
||||
repModel.getKey(), repModel.getDomain(), repModel.getType()).asSummary();
|
||||
classification.setId(repModel.getClassificationId());
|
||||
classification.setApplicationEntryPoint(repModel.getApplicationEntryPoint());
|
||||
classification.setCategory(repModel.getCategory());
|
||||
|
|
|
@ -8,7 +8,6 @@ import pro.taskana.classification.api.models.Classification;
|
|||
public class ClassificationRepresentationModel extends ClassificationSummaryRepresentationModel {
|
||||
|
||||
private Boolean isValidInDomain;
|
||||
|
||||
private Instant created; // ISO-8601
|
||||
private Instant modified; // ISO-8601
|
||||
private String description;
|
||||
|
|
|
@ -7,7 +7,7 @@ import java.util.function.Function;
|
|||
import java.util.stream.Collectors;
|
||||
|
||||
public enum TaskanaPagedModelKeys {
|
||||
ACCESSITEMS("accessItems"),
|
||||
ACCESS_ITEMS("accessItems"),
|
||||
CLASSIFICATIONS("classifications"),
|
||||
DISTRIBUTION_TARGETS("distributionTargets"),
|
||||
TASKS("tasks"),
|
||||
|
|
|
@ -49,7 +49,7 @@ public class AttachmentRepresentationModelAssembler
|
|||
return repModel;
|
||||
}
|
||||
|
||||
public AttachmentImpl toEntityModel(AttachmentRepresentationModel attachmentRepresentationModel) {
|
||||
public Attachment toEntityModel(AttachmentRepresentationModel attachmentRepresentationModel) {
|
||||
AttachmentImpl attachment = (AttachmentImpl) taskService.newAttachment();
|
||||
attachment.setId(attachmentRepresentationModel.getAttachmentId());
|
||||
attachment.setTaskId(attachmentRepresentationModel.getTaskId());
|
||||
|
|
|
@ -8,7 +8,7 @@ import org.springframework.stereotype.Component;
|
|||
import pro.taskana.classification.rest.assembler.ClassificationSummaryRepresentationModelAssembler;
|
||||
import pro.taskana.task.api.TaskService;
|
||||
import pro.taskana.task.api.models.AttachmentSummary;
|
||||
import pro.taskana.task.internal.models.AttachmentImpl;
|
||||
import pro.taskana.task.internal.models.AttachmentSummaryImpl;
|
||||
import pro.taskana.task.rest.models.AttachmentSummaryRepresentationModel;
|
||||
|
||||
/** EntityModel assembler for {@link AttachmentSummaryRepresentationModel}. */
|
||||
|
@ -45,7 +45,8 @@ public class AttachmentSummaryRepresentationModelAssembler
|
|||
}
|
||||
|
||||
public AttachmentSummary toEntityModel(AttachmentSummaryRepresentationModel repModel) {
|
||||
AttachmentImpl attachment = (AttachmentImpl) taskService.newAttachment();
|
||||
AttachmentSummaryImpl attachment =
|
||||
(AttachmentSummaryImpl) taskService.newAttachment().asSummary();
|
||||
attachment.setId(repModel.getAttachmentId());
|
||||
attachment.setTaskId(repModel.getTaskId());
|
||||
attachment.setCreated(repModel.getCreated());
|
||||
|
|
|
@ -19,7 +19,7 @@ import pro.taskana.common.rest.models.TaskanaPagedModelKeys;
|
|||
import pro.taskana.resource.rest.PageLinks;
|
||||
import pro.taskana.task.api.TaskService;
|
||||
import pro.taskana.task.api.models.TaskSummary;
|
||||
import pro.taskana.task.internal.models.TaskImpl;
|
||||
import pro.taskana.task.internal.models.TaskSummaryImpl;
|
||||
import pro.taskana.task.rest.models.TaskSummaryRepresentationModel;
|
||||
import pro.taskana.workbasket.rest.assembler.WorkbasketSummaryRepresentationModelAssembler;
|
||||
|
||||
|
@ -100,7 +100,7 @@ public class TaskSummaryRepresentationModelAssembler
|
|||
}
|
||||
|
||||
public TaskSummary toEntityModel(TaskSummaryRepresentationModel repModel) {
|
||||
TaskImpl taskSummary = (TaskImpl) taskService.newTask();
|
||||
TaskSummaryImpl taskSummary = (TaskSummaryImpl) taskService.newTask().asSummary();
|
||||
taskSummary.setId(repModel.getTaskId());
|
||||
taskSummary.setExternalId(repModel.getExternalId());
|
||||
taskSummary.setCreated(repModel.getCreated());
|
||||
|
|
|
@ -7,13 +7,11 @@ import java.util.List;
|
|||
import java.util.Map.Entry;
|
||||
|
||||
import pro.taskana.task.api.models.Task;
|
||||
import pro.taskana.task.rest.assembler.AttachmentRepresentationModelAssembler;
|
||||
|
||||
/** EntityModel class for {@link Task}. */
|
||||
@JsonIgnoreProperties("attachmentSummaries")
|
||||
public class TaskRepresentationModel extends TaskSummaryRepresentationModel {
|
||||
|
||||
protected AttachmentRepresentationModelAssembler attachmentAssembler;
|
||||
// All objects have to be serializable
|
||||
private List<CustomAttribute> customAttributes = Collections.emptyList();
|
||||
private List<CustomAttribute> callbackInfo = Collections.emptyList();
|
||||
|
|
|
@ -41,10 +41,11 @@ import pro.taskana.workbasket.api.exceptions.WorkbasketNotFoundException;
|
|||
import pro.taskana.workbasket.api.models.Workbasket;
|
||||
import pro.taskana.workbasket.api.models.WorkbasketAccessItem;
|
||||
import pro.taskana.workbasket.api.models.WorkbasketSummary;
|
||||
import pro.taskana.workbasket.internal.models.WorkbasketAccessItemImpl;
|
||||
import pro.taskana.workbasket.internal.models.WorkbasketImpl;
|
||||
import pro.taskana.workbasket.rest.assembler.WorkbasketAccessItemRepresentationModelAssembler;
|
||||
import pro.taskana.workbasket.rest.assembler.WorkbasketDefinitionRepresentationModelAssembler;
|
||||
import pro.taskana.workbasket.rest.assembler.WorkbasketRepresentationModelAssembler;
|
||||
import pro.taskana.workbasket.rest.models.WorkbasketAccessItemRepresentationModel;
|
||||
import pro.taskana.workbasket.rest.models.WorkbasketDefinitionRepresentationModel;
|
||||
import pro.taskana.workbasket.rest.models.WorkbasketRepresentationModel;
|
||||
|
||||
|
@ -59,6 +60,7 @@ public class WorkbasketDefinitionController {
|
|||
private final WorkbasketService workbasketService;
|
||||
private final WorkbasketDefinitionRepresentationModelAssembler workbasketDefinitionAssembler;
|
||||
private final WorkbasketRepresentationModelAssembler workbasketAssembler;
|
||||
private final WorkbasketAccessItemRepresentationModelAssembler accessItemAssembler;
|
||||
private final ObjectMapper mapper;
|
||||
|
||||
@Autowired
|
||||
|
@ -66,10 +68,12 @@ public class WorkbasketDefinitionController {
|
|||
WorkbasketService workbasketService,
|
||||
WorkbasketDefinitionRepresentationModelAssembler workbasketDefinitionAssembler,
|
||||
WorkbasketRepresentationModelAssembler workbasketAssembler,
|
||||
WorkbasketAccessItemRepresentationModelAssembler accessItemAssembler,
|
||||
ObjectMapper mapper) {
|
||||
this.workbasketService = workbasketService;
|
||||
this.workbasketDefinitionAssembler = workbasketDefinitionAssembler;
|
||||
this.workbasketAssembler = workbasketAssembler;
|
||||
this.accessItemAssembler = accessItemAssembler;
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
|
@ -149,7 +153,7 @@ public class WorkbasketDefinitionController {
|
|||
// STEP 1: update or create workbaskets from the import
|
||||
for (WorkbasketDefinitionRepresentationModel definition : definitions.getContent()) {
|
||||
Workbasket importedWb =
|
||||
workbasketDefinitionAssembler.toEntityModel(definition.getWorkbasket());
|
||||
workbasketAssembler.toEntityModel(definition.getWorkbasket());
|
||||
String newId;
|
||||
WorkbasketImpl wbWithoutId = (WorkbasketImpl) removeId(importedWb);
|
||||
if (systemIds.containsKey(logicalId(importedWb))) {
|
||||
|
@ -182,9 +186,10 @@ public class WorkbasketDefinitionController {
|
|||
for (WorkbasketAccessItem accessItem : workbasketService.getWorkbasketAccessItems(newId)) {
|
||||
workbasketService.deleteWorkbasketAccessItem(accessItem.getId());
|
||||
}
|
||||
for (WorkbasketAccessItemImpl authorization : definition.getAuthorizations()) {
|
||||
for (WorkbasketAccessItemRepresentationModel authorization : definition.getAuthorizations()) {
|
||||
authorization.setWorkbasketId(newId);
|
||||
workbasketService.createWorkbasketAccessItem(authorization);
|
||||
workbasketService.createWorkbasketAccessItem(
|
||||
accessItemAssembler.toEntityModel(authorization));
|
||||
}
|
||||
idConversion.put(importedWb.getId(), newId);
|
||||
}
|
||||
|
@ -218,7 +223,7 @@ public class WorkbasketDefinitionController {
|
|||
private Workbasket removeId(Workbasket importedWb) {
|
||||
WorkbasketRepresentationModel wbRes = workbasketAssembler.toModel(importedWb);
|
||||
wbRes.setWorkbasketId(null);
|
||||
return workbasketDefinitionAssembler.toEntityModel(wbRes);
|
||||
return workbasketAssembler.toEntityModel(wbRes);
|
||||
}
|
||||
|
||||
private void checkForDuplicates(Collection<WorkbasketDefinitionRepresentationModel> definitions) {
|
||||
|
@ -226,7 +231,7 @@ public class WorkbasketDefinitionController {
|
|||
Set<String> duplicates = new HashSet<>();
|
||||
for (WorkbasketDefinitionRepresentationModel definition : definitions) {
|
||||
String identifier =
|
||||
logicalId(workbasketDefinitionAssembler.toEntityModel(definition.getWorkbasket()));
|
||||
logicalId(workbasketAssembler.toEntityModel(definition.getWorkbasket()));
|
||||
if (identifiers.contains(identifier)) {
|
||||
duplicates.add(identifier);
|
||||
} else {
|
||||
|
|
|
@ -2,19 +2,19 @@ package pro.taskana.workbasket.rest.assembler;
|
|||
|
||||
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;
|
||||
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;
|
||||
import static pro.taskana.common.rest.models.TaskanaPagedModelKeys.ACCESSITEMS;
|
||||
import static pro.taskana.common.rest.models.TaskanaPagedModelKeys.ACCESS_ITEMS;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.hateoas.PagedModel.PageMetadata;
|
||||
import org.springframework.hateoas.server.RepresentationModelAssembler;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import pro.taskana.common.api.exceptions.NotAuthorizedException;
|
||||
import pro.taskana.common.rest.Mapping;
|
||||
import pro.taskana.common.rest.assembler.TaskanaPagingAssembler;
|
||||
import pro.taskana.common.rest.models.TaskanaPagedModel;
|
||||
import pro.taskana.common.rest.models.TaskanaPagedModelKeys;
|
||||
import pro.taskana.resource.rest.PageLinks;
|
||||
import pro.taskana.workbasket.api.WorkbasketService;
|
||||
import pro.taskana.workbasket.api.exceptions.WorkbasketNotFoundException;
|
||||
|
@ -29,22 +29,21 @@ import pro.taskana.workbasket.rest.models.WorkbasketAccessItemRepresentationMode
|
|||
*/
|
||||
@Component
|
||||
public class WorkbasketAccessItemRepresentationModelAssembler
|
||||
implements RepresentationModelAssembler<
|
||||
implements TaskanaPagingAssembler<
|
||||
WorkbasketAccessItem, WorkbasketAccessItemRepresentationModel> {
|
||||
|
||||
private final WorkbasketService workbasketService;
|
||||
|
||||
@Autowired
|
||||
public WorkbasketAccessItemRepresentationModelAssembler(
|
||||
WorkbasketService workbasketService) {
|
||||
public WorkbasketAccessItemRepresentationModelAssembler(WorkbasketService workbasketService) {
|
||||
this.workbasketService = workbasketService;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public WorkbasketAccessItemRepresentationModel toModel(@NonNull WorkbasketAccessItem wbAccItem) {
|
||||
WorkbasketAccessItemRepresentationModel repModel
|
||||
= new WorkbasketAccessItemRepresentationModel();
|
||||
WorkbasketAccessItemRepresentationModel repModel =
|
||||
new WorkbasketAccessItemRepresentationModel();
|
||||
repModel.setAccessId(wbAccItem.getAccessId());
|
||||
repModel.setWorkbasketId(wbAccItem.getWorkbasketId());
|
||||
repModel.setWorkbasketKey(wbAccItem.getWorkbasketKey());
|
||||
|
@ -70,8 +69,7 @@ public class WorkbasketAccessItemRepresentationModelAssembler
|
|||
return repModel;
|
||||
}
|
||||
|
||||
public WorkbasketAccessItem toEntityModel(
|
||||
WorkbasketAccessItemRepresentationModel repModel) {
|
||||
public WorkbasketAccessItem toEntityModel(WorkbasketAccessItemRepresentationModel repModel) {
|
||||
WorkbasketAccessItemImpl wbAccItemModel =
|
||||
(WorkbasketAccessItemImpl)
|
||||
workbasketService.newWorkbasketAccessItem(
|
||||
|
@ -118,11 +116,11 @@ public class WorkbasketAccessItemRepresentationModelAssembler
|
|||
@PageLinks(Mapping.URL_WORKBASKET_ACCESS_ITEMS)
|
||||
public TaskanaPagedModel<WorkbasketAccessItemRepresentationModel> toPageModel(
|
||||
List<WorkbasketAccessItem> workbasketAccessItems, PageMetadata pageMetadata) {
|
||||
return workbasketAccessItems.stream()
|
||||
.map(this::toModel)
|
||||
.collect(
|
||||
Collectors.collectingAndThen(
|
||||
Collectors.toList(),
|
||||
list -> new TaskanaPagedModel<>(ACCESSITEMS, list, pageMetadata)));
|
||||
return TaskanaPagingAssembler.super.toPageModel(workbasketAccessItems, pageMetadata);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskanaPagedModelKeys getProperty() {
|
||||
return ACCESS_ITEMS;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package pro.taskana.workbasket.rest.assembler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -17,11 +17,9 @@ import pro.taskana.workbasket.api.exceptions.WorkbasketNotFoundException;
|
|||
import pro.taskana.workbasket.api.models.Workbasket;
|
||||
import pro.taskana.workbasket.api.models.WorkbasketAccessItem;
|
||||
import pro.taskana.workbasket.api.models.WorkbasketSummary;
|
||||
import pro.taskana.workbasket.internal.models.WorkbasketAccessItemImpl;
|
||||
import pro.taskana.workbasket.internal.models.WorkbasketImpl;
|
||||
import pro.taskana.workbasket.rest.models.WorkbasketAccessItemRepresentationModel;
|
||||
import pro.taskana.workbasket.rest.models.WorkbasketDefinitionRepresentationModel;
|
||||
import pro.taskana.workbasket.rest.models.WorkbasketRepresentationModel;
|
||||
import pro.taskana.workbasket.rest.models.WorkbasketRepresentationModelWithoutLinks;
|
||||
|
||||
/**
|
||||
* Transforms {@link Workbasket} into a {@link WorkbasketDefinitionRepresentationModel} containing
|
||||
|
@ -32,42 +30,28 @@ public class WorkbasketDefinitionRepresentationModelAssembler
|
|||
implements TaskanaPagingAssembler<Workbasket, WorkbasketDefinitionRepresentationModel> {
|
||||
|
||||
private final WorkbasketService workbasketService;
|
||||
private final WorkbasketAccessItemRepresentationModelAssembler accessItemAssembler;
|
||||
private final WorkbasketRepresentationModelAssembler workbasketAssembler;
|
||||
|
||||
@Autowired
|
||||
public WorkbasketDefinitionRepresentationModelAssembler(WorkbasketService workbasketService) {
|
||||
public WorkbasketDefinitionRepresentationModelAssembler(
|
||||
WorkbasketService workbasketService,
|
||||
WorkbasketAccessItemRepresentationModelAssembler accessItemAssembler,
|
||||
WorkbasketRepresentationModelAssembler workbasketAssembler) {
|
||||
this.workbasketService = workbasketService;
|
||||
this.accessItemAssembler = accessItemAssembler;
|
||||
this.workbasketAssembler = workbasketAssembler;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public WorkbasketDefinitionRepresentationModel toModel(@NonNull Workbasket workbasket) {
|
||||
WorkbasketRepresentationModelWithoutLinks basket =
|
||||
new WorkbasketRepresentationModelWithoutLinks();
|
||||
|
||||
basket.setKey(workbasket.getKey());
|
||||
basket.setModified(workbasket.getModified());
|
||||
basket.setCreated(workbasket.getModified());
|
||||
basket.setWorkbasketId(workbasket.getId());
|
||||
basket.setDescription(workbasket.getDescription());
|
||||
basket.setDomain(workbasket.getDomain());
|
||||
basket.setName(workbasket.getName());
|
||||
basket.setType(workbasket.getType());
|
||||
basket.setOwner(workbasket.getOwner());
|
||||
basket.setCustom1(workbasket.getCustom1());
|
||||
basket.setCustom2(workbasket.getCustom2());
|
||||
basket.setCustom3(workbasket.getCustom3());
|
||||
basket.setCustom4(workbasket.getCustom4());
|
||||
basket.setOrgLevel1(workbasket.getOrgLevel1());
|
||||
basket.setOrgLevel2(workbasket.getOrgLevel2());
|
||||
basket.setOrgLevel3(workbasket.getOrgLevel3());
|
||||
basket.setOrgLevel4(workbasket.getOrgLevel4());
|
||||
|
||||
List<WorkbasketAccessItemImpl> authorizations = new ArrayList<>();
|
||||
WorkbasketRepresentationModel basket = workbasketAssembler.toModel(workbasket);
|
||||
Collection<WorkbasketAccessItemRepresentationModel> authorizations;
|
||||
Set<String> distroTargets;
|
||||
try {
|
||||
for (WorkbasketAccessItem accessItem :
|
||||
workbasketService.getWorkbasketAccessItems(basket.getWorkbasketId())) {
|
||||
authorizations.add((WorkbasketAccessItemImpl) accessItem);
|
||||
}
|
||||
List<WorkbasketAccessItem> workbasketAccessItems =
|
||||
workbasketService.getWorkbasketAccessItems(basket.getWorkbasketId());
|
||||
authorizations = accessItemAssembler.toCollectionModel(workbasketAccessItems).getContent();
|
||||
distroTargets =
|
||||
workbasketService.getDistributionTargets(workbasket.getId()).stream()
|
||||
.map(WorkbasketSummary::getId)
|
||||
|
@ -85,28 +69,6 @@ public class WorkbasketDefinitionRepresentationModelAssembler
|
|||
return repModel;
|
||||
}
|
||||
|
||||
public Workbasket toEntityModel(WorkbasketRepresentationModel repModel) {
|
||||
WorkbasketImpl workbasket =
|
||||
(WorkbasketImpl) workbasketService.newWorkbasket(repModel.getKey(), repModel.getDomain());
|
||||
workbasket.setId(repModel.getWorkbasketId());
|
||||
workbasket.setName(repModel.getName());
|
||||
workbasket.setType(repModel.getType());
|
||||
workbasket.setDescription(repModel.getDescription());
|
||||
workbasket.setOwner(repModel.getOwner());
|
||||
workbasket.setMarkedForDeletion(repModel.getMarkedForDeletion());
|
||||
workbasket.setCustom1(repModel.getCustom1());
|
||||
workbasket.setCustom2(repModel.getCustom2());
|
||||
workbasket.setCustom3(repModel.getCustom3());
|
||||
workbasket.setCustom4(repModel.getCustom4());
|
||||
workbasket.setOrgLevel1(repModel.getOrgLevel1());
|
||||
workbasket.setOrgLevel2(repModel.getOrgLevel2());
|
||||
workbasket.setOrgLevel3(repModel.getOrgLevel3());
|
||||
workbasket.setOrgLevel4(repModel.getOrgLevel4());
|
||||
workbasket.setCreated(repModel.getCreated());
|
||||
workbasket.setModified(repModel.getModified());
|
||||
return workbasket;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskanaPagedModelKeys getProperty() {
|
||||
return TaskanaPagedModelKeys.WORKBASKET_DEFINITIONS;
|
||||
|
|
|
@ -17,7 +17,7 @@ import pro.taskana.common.rest.models.TaskanaPagedModelKeys;
|
|||
import pro.taskana.resource.rest.PageLinks;
|
||||
import pro.taskana.workbasket.api.WorkbasketService;
|
||||
import pro.taskana.workbasket.api.models.WorkbasketSummary;
|
||||
import pro.taskana.workbasket.internal.models.WorkbasketImpl;
|
||||
import pro.taskana.workbasket.internal.models.WorkbasketSummaryImpl;
|
||||
import pro.taskana.workbasket.rest.models.WorkbasketSummaryRepresentationModel;
|
||||
|
||||
/** EntityModel assembler for {@link WorkbasketSummaryRepresentationModel}. */
|
||||
|
@ -59,8 +59,9 @@ public class WorkbasketSummaryRepresentationModelAssembler
|
|||
}
|
||||
|
||||
public WorkbasketSummary toEntityModel(WorkbasketSummaryRepresentationModel repModel) {
|
||||
WorkbasketImpl workbasket =
|
||||
(WorkbasketImpl) workbasketService.newWorkbasket(repModel.getKey(), repModel.getDomain());
|
||||
WorkbasketSummaryImpl workbasket =
|
||||
(WorkbasketSummaryImpl)
|
||||
workbasketService.newWorkbasket(repModel.getKey(), repModel.getDomain()).asSummary();
|
||||
workbasket.setId(repModel.getWorkbasketId());
|
||||
workbasket.setName(repModel.getName());
|
||||
workbasket.setType(repModel.getType());
|
||||
|
|
|
@ -4,9 +4,7 @@ import org.springframework.hateoas.RepresentationModel;
|
|||
|
||||
import pro.taskana.workbasket.api.models.WorkbasketAccessItem;
|
||||
|
||||
/**
|
||||
* EntityModel class for {@link WorkbasketAccessItem}.
|
||||
*/
|
||||
/** EntityModel class for {@link WorkbasketAccessItem}. */
|
||||
public class WorkbasketAccessItemRepresentationModel
|
||||
extends RepresentationModel<WorkbasketAccessItemRepresentationModel> {
|
||||
|
||||
|
@ -208,5 +206,4 @@ public class WorkbasketAccessItemRepresentationModel
|
|||
public void setPermCustom12(boolean permCustom12) {
|
||||
this.permCustom12 = permCustom12;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
package pro.taskana.workbasket.rest.models;
|
||||
|
||||
import java.util.List;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
import org.springframework.hateoas.RepresentationModel;
|
||||
|
||||
import pro.taskana.workbasket.internal.models.WorkbasketAccessItemImpl;
|
||||
|
||||
/** this class represents a workbasket including its distro targets and authorisations. */
|
||||
public class WorkbasketDefinitionRepresentationModel
|
||||
extends RepresentationModel<WorkbasketDefinitionRepresentationModel> {
|
||||
|
||||
@JsonIgnoreProperties("_links")
|
||||
private WorkbasketRepresentationModel workbasket;
|
||||
private Collection<WorkbasketAccessItemRepresentationModel> authorizations;
|
||||
private Set<String> distributionTargets;
|
||||
private List<WorkbasketAccessItemImpl> authorizations;
|
||||
private WorkbasketRepresentationModelWithoutLinks workbasket;
|
||||
|
||||
public Set<String> getDistributionTargets() {
|
||||
return distributionTargets;
|
||||
|
@ -22,19 +22,20 @@ public class WorkbasketDefinitionRepresentationModel
|
|||
this.distributionTargets = distributionTargets;
|
||||
}
|
||||
|
||||
public List<WorkbasketAccessItemImpl> getAuthorizations() {
|
||||
public Collection<WorkbasketAccessItemRepresentationModel> getAuthorizations() {
|
||||
return authorizations;
|
||||
}
|
||||
|
||||
public void setAuthorizations(List<WorkbasketAccessItemImpl> authorizations) {
|
||||
public void setAuthorizations(
|
||||
Collection<WorkbasketAccessItemRepresentationModel> authorizations) {
|
||||
this.authorizations = authorizations;
|
||||
}
|
||||
|
||||
public WorkbasketRepresentationModelWithoutLinks getWorkbasket() {
|
||||
public WorkbasketRepresentationModel getWorkbasket() {
|
||||
return workbasket;
|
||||
}
|
||||
|
||||
public void setWorkbasket(WorkbasketRepresentationModelWithoutLinks workbasket) {
|
||||
public void setWorkbasket(WorkbasketRepresentationModel workbasket) {
|
||||
this.workbasket = workbasket;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
package pro.taskana.workbasket.rest.models;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
|
||||
import pro.taskana.workbasket.api.models.Workbasket;
|
||||
|
||||
/**
|
||||
* EntityModel class for {@link Workbasket} but without links property.
|
||||
*/
|
||||
@JsonIgnoreProperties(value = {"links"})
|
||||
public class WorkbasketRepresentationModelWithoutLinks extends WorkbasketRepresentationModel {
|
||||
|
||||
}
|
|
@ -1,148 +0,0 @@
|
|||
package pro.taskana.classification.rest.assembler;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.time.Instant;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import pro.taskana.classification.api.ClassificationService;
|
||||
import pro.taskana.classification.api.models.Classification;
|
||||
import pro.taskana.classification.internal.models.ClassificationImpl;
|
||||
import pro.taskana.classification.rest.models.ClassificationRepresentationModel;
|
||||
import pro.taskana.common.rest.Mapping;
|
||||
import pro.taskana.common.rest.TaskanaSpringBootTest;
|
||||
|
||||
/** Test for {@link ClassificationRepresentationModelAssembler}. */
|
||||
@TaskanaSpringBootTest
|
||||
class ClassificationAssemblerTest {
|
||||
|
||||
@Autowired ClassificationRepresentationModelAssembler classificationRepresentationModelAssembler;
|
||||
|
||||
@Autowired ClassificationService classificationService;
|
||||
|
||||
@Test
|
||||
void classificationToResource() {
|
||||
// given
|
||||
ClassificationImpl classification =
|
||||
(ClassificationImpl) classificationService.newClassification("KEY_A", "DOMAIN_A", "A");
|
||||
classification.setId("1");
|
||||
classification.setCategory("ABC");
|
||||
classification.setName("Classification 1");
|
||||
classification.setIsValidInDomain(true);
|
||||
classification.setCustom1("Custom1");
|
||||
classification.setCustom2("Custom2");
|
||||
classification.setCustom3("Custom3");
|
||||
classification.setCustom4("Custom4");
|
||||
classification.setCustom5("Custom5");
|
||||
classification.setCustom6("Custom6");
|
||||
classification.setCustom7("Custom7");
|
||||
classification.setCustom8("Custom8");
|
||||
classification.setParentId("2");
|
||||
classification.setParentKey("parentKey");
|
||||
classification.setPriority(2);
|
||||
classification.setApplicationEntryPoint("12");
|
||||
classification.setServiceLevel("P1D");
|
||||
classification.setDescription("Test");
|
||||
classification.setCreated(Instant.parse("2010-01-01T12:00:00Z"));
|
||||
classification.setModified(Instant.parse("2011-11-11T11:00:00Z"));
|
||||
// when
|
||||
ClassificationRepresentationModel classificationRepresentationModel =
|
||||
classificationRepresentationModelAssembler.toModel(classification);
|
||||
// then
|
||||
testEquality(classification, classificationRepresentationModel);
|
||||
testLinks(classificationRepresentationModel);
|
||||
}
|
||||
|
||||
@Test
|
||||
void resourceToClassification() {
|
||||
ClassificationImpl classification =
|
||||
(ClassificationImpl) classificationService.newClassification("KEY_B", "DOMAIN_B", "AB");
|
||||
|
||||
// given
|
||||
classification.setId("1");
|
||||
classification.setApplicationEntryPoint("Test");
|
||||
classification.setCategory("ABC");
|
||||
classification.setCreated(Instant.parse("2010-01-01T12:00:00Z"));
|
||||
classification.setModified(Instant.parse("2011-11-11T11:00:00Z"));
|
||||
classification.setCustom1("Custom1");
|
||||
classification.setCustom2("Custom2");
|
||||
classification.setCustom3("Custom3");
|
||||
classification.setCustom4("Custom4");
|
||||
classification.setCustom5("Custom5");
|
||||
classification.setCustom6("Custom6");
|
||||
classification.setCustom7("Custom7");
|
||||
classification.setCustom8("Custom8");
|
||||
classification.setParentId("2");
|
||||
classification.setParentKey("parentKey");
|
||||
classification.setPriority(2);
|
||||
classification.setApplicationEntryPoint("12");
|
||||
classification.setServiceLevel("P1D");
|
||||
classification.setDescription("Test");
|
||||
classification.setIsValidInDomain(true);
|
||||
|
||||
ClassificationRepresentationModel classificationRepresentationModel =
|
||||
classificationRepresentationModelAssembler.toModel(classification);
|
||||
|
||||
// when
|
||||
classification =
|
||||
(ClassificationImpl)
|
||||
classificationRepresentationModelAssembler
|
||||
.toEntityModel(classificationRepresentationModel);
|
||||
// then
|
||||
testEquality(classification, classificationRepresentationModel);
|
||||
}
|
||||
|
||||
private void testLinks(ClassificationRepresentationModel resource) {
|
||||
assertThat(resource.getLinks()).hasSize(1);
|
||||
assertThat(Mapping.URL_CLASSIFICATIONS_ID.replaceAll("\\{.*}", resource.getClassificationId()))
|
||||
.isEqualTo(resource.getRequiredLink("self").getHref());
|
||||
}
|
||||
|
||||
private void testEquality(
|
||||
Classification classification,
|
||||
ClassificationRepresentationModel classificationRepresentationModel) {
|
||||
assertThat(classification.getApplicationEntryPoint())
|
||||
.isEqualTo(classificationRepresentationModel.getApplicationEntryPoint());
|
||||
assertThat(classification.getKey()).isEqualTo(classificationRepresentationModel.getKey());
|
||||
assertThat(classification.getDomain()).isEqualTo(classificationRepresentationModel.getDomain());
|
||||
assertThat(classification.getId())
|
||||
.isEqualTo(classificationRepresentationModel.getClassificationId());
|
||||
assertThat(classification.getDescription())
|
||||
.isEqualTo(classificationRepresentationModel.getDescription());
|
||||
assertThat(classification.getName()).isEqualTo(classificationRepresentationModel.getName());
|
||||
assertThat(classification.getServiceLevel())
|
||||
.isEqualTo(classificationRepresentationModel.getServiceLevel());
|
||||
assertThat(classification.getCategory())
|
||||
.isEqualTo(classificationRepresentationModel.getCategory());
|
||||
assertThat(classification.getCustom1())
|
||||
.isEqualTo(classificationRepresentationModel.getCustom1());
|
||||
assertThat(classification.getCustom2())
|
||||
.isEqualTo(classificationRepresentationModel.getCustom2());
|
||||
assertThat(classification.getCustom3())
|
||||
.isEqualTo(classificationRepresentationModel.getCustom3());
|
||||
assertThat(classification.getCustom4())
|
||||
.isEqualTo(classificationRepresentationModel.getCustom4());
|
||||
assertThat(classification.getCustom5())
|
||||
.isEqualTo(classificationRepresentationModel.getCustom5());
|
||||
assertThat(classification.getCustom6())
|
||||
.isEqualTo(classificationRepresentationModel.getCustom6());
|
||||
assertThat(classification.getCustom7())
|
||||
.isEqualTo(classificationRepresentationModel.getCustom7());
|
||||
assertThat(classification.getCustom8())
|
||||
.isEqualTo(classificationRepresentationModel.getCustom8());
|
||||
assertThat(classification.getParentId())
|
||||
.isEqualTo(classificationRepresentationModel.getParentId());
|
||||
assertThat(classification.getParentKey())
|
||||
.isEqualTo(classificationRepresentationModel.getParentKey());
|
||||
assertThat(classification.getType()).isEqualTo(classificationRepresentationModel.getType());
|
||||
assertThat(classification.getPriority())
|
||||
.isEqualTo(classificationRepresentationModel.getPriority());
|
||||
assertThat(classification.getIsValidInDomain())
|
||||
.isEqualTo(classificationRepresentationModel.getIsValidInDomain());
|
||||
assertThat(classification.getCreated())
|
||||
.isEqualTo(classificationRepresentationModel.getCreated());
|
||||
assertThat(classification.getModified())
|
||||
.isEqualTo(classificationRepresentationModel.getModified());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,147 @@
|
|||
package pro.taskana.classification.rest.assembler;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.time.Instant;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import pro.taskana.classification.api.ClassificationService;
|
||||
import pro.taskana.classification.api.models.Classification;
|
||||
import pro.taskana.classification.internal.models.ClassificationImpl;
|
||||
import pro.taskana.classification.rest.models.ClassificationRepresentationModel;
|
||||
import pro.taskana.common.rest.Mapping;
|
||||
import pro.taskana.common.rest.TaskanaSpringBootTest;
|
||||
|
||||
/** Test for {@link ClassificationRepresentationModelAssembler}. */
|
||||
@TaskanaSpringBootTest
|
||||
class ClassificationRepresentationModelAssemblerTest {
|
||||
|
||||
private final ClassificationRepresentationModelAssembler assembler;
|
||||
|
||||
private final ClassificationService classificationService;
|
||||
|
||||
@Autowired
|
||||
ClassificationRepresentationModelAssemblerTest(
|
||||
ClassificationRepresentationModelAssembler assembler,
|
||||
ClassificationService classificationService) {
|
||||
this.assembler = assembler;
|
||||
this.classificationService = classificationService;
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_ReturnRepresentationModel_When_ConvertingEntityToRepresentationModel() {
|
||||
// given
|
||||
ClassificationImpl classification =
|
||||
(ClassificationImpl) classificationService.newClassification("KEY_A", "DOMAIN_A", "A");
|
||||
classification.setId("1");
|
||||
classification.setCategory("ABC");
|
||||
classification.setName("Classification 1");
|
||||
classification.setIsValidInDomain(true);
|
||||
classification.setCustom1("Custom1");
|
||||
classification.setCustom2("Custom2");
|
||||
classification.setCustom3("Custom3");
|
||||
classification.setCustom4("Custom4");
|
||||
classification.setCustom5("Custom5");
|
||||
classification.setCustom6("Custom6");
|
||||
classification.setCustom7("Custom7");
|
||||
classification.setCustom8("Custom8");
|
||||
classification.setParentId("2");
|
||||
classification.setParentKey("parentKey");
|
||||
classification.setPriority(2);
|
||||
classification.setApplicationEntryPoint("12");
|
||||
classification.setServiceLevel("P1D");
|
||||
classification.setDescription("Test");
|
||||
classification.setCreated(Instant.parse("2010-01-01T12:00:00Z"));
|
||||
classification.setModified(Instant.parse("2011-11-11T11:00:00Z"));
|
||||
// when
|
||||
ClassificationRepresentationModel repModel = assembler.toModel(classification);
|
||||
// then
|
||||
testEquality(classification, repModel);
|
||||
testLinks(repModel);
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_ReturnEntity_When_ConvertingRepresentationModelToEntity() {
|
||||
// given
|
||||
ClassificationRepresentationModel repModel = new ClassificationRepresentationModel();
|
||||
repModel.setKey("KEY_B");
|
||||
repModel.setName("name");
|
||||
repModel.setDomain("DOMAIN_B");
|
||||
repModel.setType("AB");
|
||||
repModel.setClassificationId("1");
|
||||
repModel.setApplicationEntryPoint("Test");
|
||||
repModel.setCategory("ABC");
|
||||
repModel.setCreated(Instant.parse("2010-01-01T12:00:00Z"));
|
||||
repModel.setModified(Instant.parse("2011-11-11T11:00:00Z"));
|
||||
repModel.setCustom1("Custom1");
|
||||
repModel.setCustom2("Custom2");
|
||||
repModel.setCustom3("Custom3");
|
||||
repModel.setCustom4("Custom4");
|
||||
repModel.setCustom5("Custom5");
|
||||
repModel.setCustom6("Custom6");
|
||||
repModel.setCustom7("Custom7");
|
||||
repModel.setCustom8("Custom8");
|
||||
repModel.setParentId("2");
|
||||
repModel.setParentKey("parentKey");
|
||||
repModel.setPriority(2);
|
||||
repModel.setApplicationEntryPoint("12");
|
||||
repModel.setServiceLevel("P1D");
|
||||
repModel.setDescription("Test");
|
||||
repModel.setIsValidInDomain(true);
|
||||
// when
|
||||
Classification classification = assembler.toEntityModel(repModel);
|
||||
// then
|
||||
testEquality(classification, repModel);
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_Equal_When_ComparingEntityWithConvertedEntity() {
|
||||
ClassificationImpl classification =
|
||||
(ClassificationImpl) classificationService.newClassification("KEY_A", "DOMAIN_A", "A");
|
||||
classification.setId("1");
|
||||
classification.setCategory("ABC");
|
||||
classification.setName("Classification 1");
|
||||
classification.setIsValidInDomain(true);
|
||||
classification.setCustom1("Custom1");
|
||||
classification.setCustom2("Custom2");
|
||||
classification.setCustom3("Custom3");
|
||||
classification.setCustom4("Custom4");
|
||||
classification.setCustom5("Custom5");
|
||||
classification.setCustom6("Custom6");
|
||||
classification.setCustom7("Custom7");
|
||||
classification.setCustom8("Custom8");
|
||||
classification.setParentId("2");
|
||||
classification.setParentKey("parentKey");
|
||||
classification.setPriority(2);
|
||||
classification.setApplicationEntryPoint("12");
|
||||
classification.setServiceLevel("P1D");
|
||||
classification.setDescription("Test");
|
||||
classification.setCreated(Instant.parse("2010-01-01T12:00:00Z"));
|
||||
classification.setModified(Instant.parse("2011-11-11T11:00:00Z"));
|
||||
// when
|
||||
ClassificationRepresentationModel repModel = assembler.toModel(classification);
|
||||
Classification secondClassification = assembler.toEntityModel(repModel);
|
||||
// then
|
||||
assertThat(classification)
|
||||
.hasNoNullFieldsOrProperties()
|
||||
.isNotSameAs(secondClassification)
|
||||
.isEqualTo(secondClassification);
|
||||
}
|
||||
|
||||
private void testLinks(ClassificationRepresentationModel repModel) {
|
||||
assertThat(repModel.getLinks()).hasSize(1);
|
||||
assertThat(Mapping.URL_CLASSIFICATIONS_ID.replaceAll("\\{.*}", repModel.getClassificationId()))
|
||||
.isEqualTo(repModel.getRequiredLink("self").getHref());
|
||||
}
|
||||
|
||||
private static void testEquality(
|
||||
Classification entity, ClassificationRepresentationModel repModel) {
|
||||
ClassificationSummaryRepresentationModelAssemblerTest.testEquality(entity, repModel);
|
||||
|
||||
assertThat(entity.getIsValidInDomain()).isEqualTo(repModel.getIsValidInDomain());
|
||||
assertThat(entity.getCreated()).isEqualTo(repModel.getCreated());
|
||||
assertThat(entity.getModified()).isEqualTo(repModel.getModified());
|
||||
assertThat(entity.getDescription()).isEqualTo(repModel.getDescription());
|
||||
}
|
||||
}
|
|
@ -1,109 +0,0 @@
|
|||
package pro.taskana.classification.rest.assembler;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.time.Instant;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import pro.taskana.classification.api.ClassificationService;
|
||||
import pro.taskana.classification.api.models.ClassificationSummary;
|
||||
import pro.taskana.classification.internal.models.ClassificationImpl;
|
||||
import pro.taskana.classification.rest.models.ClassificationSummaryRepresentationModel;
|
||||
import pro.taskana.common.rest.TaskanaSpringBootTest;
|
||||
|
||||
/** Test for {@link ClassificationSummaryRepresentationModelAssembler}. */
|
||||
@TaskanaSpringBootTest
|
||||
class ClassificationSummaryAssemblerTest {
|
||||
@Autowired
|
||||
ClassificationSummaryRepresentationModelAssembler
|
||||
classificationSummaryRepresentationModelAssembler;
|
||||
|
||||
@Autowired private ClassificationService classificationService;
|
||||
|
||||
@Test
|
||||
void testModelToResource() {
|
||||
// given
|
||||
ClassificationImpl classification =
|
||||
(ClassificationImpl) classificationService.newClassification("DOMAIN_A", "1", "A");
|
||||
classification.setId("1");
|
||||
classification.setCategory("ABC");
|
||||
classification.setName("Classification 1");
|
||||
classification.setIsValidInDomain(true);
|
||||
classification.setCustom1("Custom1");
|
||||
classification.setCustom2("Custom2");
|
||||
classification.setCustom3("Custom3");
|
||||
classification.setCustom4("Custom4");
|
||||
classification.setCustom5("Custom5");
|
||||
classification.setCustom6("Custom6");
|
||||
classification.setCustom7("Custom7");
|
||||
classification.setCustom8("Custom8");
|
||||
classification.setParentId("2");
|
||||
classification.setPriority(2);
|
||||
classification.setApplicationEntryPoint("12");
|
||||
classification.setServiceLevel("P1D");
|
||||
classification.setDescription("Test");
|
||||
classification.setCreated(Instant.parse("2010-01-01T12:00:00Z"));
|
||||
classification.setModified(Instant.parse("2011-11-11T11:00:00Z"));
|
||||
ClassificationSummary classificationSummary = classification.asSummary();
|
||||
// when
|
||||
ClassificationSummaryRepresentationModel resource =
|
||||
classificationSummaryRepresentationModelAssembler.toModel(classification);
|
||||
// then
|
||||
testEquality(classificationSummary, resource);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testResourceToModel() {
|
||||
// given
|
||||
ClassificationSummaryRepresentationModel resource =
|
||||
new ClassificationSummaryRepresentationModel();
|
||||
resource.setCategory("EFG");
|
||||
resource.setClassificationId("2");
|
||||
resource.setCustom1("custom1");
|
||||
resource.setCustom2("custom2");
|
||||
resource.setCustom3("custom3");
|
||||
resource.setCustom4("custom4");
|
||||
resource.setCustom5("custom5");
|
||||
resource.setCustom6("custom6");
|
||||
resource.setCustom7("custom7");
|
||||
resource.setCustom8("custom8");
|
||||
resource.setDomain("domain1");
|
||||
resource.setKey("key");
|
||||
resource.setName("classSummary");
|
||||
resource.setParentId("ID2");
|
||||
resource.setParentKey("key2");
|
||||
resource.setPriority(1);
|
||||
resource.setType("A");
|
||||
// when
|
||||
ClassificationSummary classificationSummary =
|
||||
classificationSummaryRepresentationModelAssembler.toEntityModel(resource);
|
||||
// then
|
||||
testEquality(classificationSummary, resource);
|
||||
}
|
||||
|
||||
private void testEquality(
|
||||
ClassificationSummary classificationSummary,
|
||||
ClassificationSummaryRepresentationModel resource) {
|
||||
assertThat(resource.getKey()).isEqualTo(classificationSummary.getKey());
|
||||
assertThat(resource.getDomain()).isEqualTo(classificationSummary.getDomain());
|
||||
assertThat(resource.getClassificationId()).isEqualTo(classificationSummary.getId());
|
||||
assertThat(resource.getName()).isEqualTo(classificationSummary.getName());
|
||||
assertThat(resource.getCategory()).isEqualTo(classificationSummary.getCategory());
|
||||
assertThat(resource.getCustom1()).isEqualTo(classificationSummary.getCustom1());
|
||||
assertThat(resource.getCustom2()).isEqualTo(classificationSummary.getCustom2());
|
||||
assertThat(resource.getCustom3()).isEqualTo(classificationSummary.getCustom3());
|
||||
assertThat(resource.getCustom4()).isEqualTo(classificationSummary.getCustom4());
|
||||
assertThat(resource.getCustom5()).isEqualTo(classificationSummary.getCustom5());
|
||||
assertThat(resource.getCustom6()).isEqualTo(classificationSummary.getCustom6());
|
||||
assertThat(resource.getCustom7()).isEqualTo(classificationSummary.getCustom7());
|
||||
assertThat(resource.getCustom8()).isEqualTo(classificationSummary.getCustom8());
|
||||
assertThat(resource.getParentId()).isEqualTo(classificationSummary.getParentId());
|
||||
assertThat(resource.getParentKey()).isEqualTo(classificationSummary.getParentKey());
|
||||
assertThat(resource.getType()).isEqualTo(classificationSummary.getType());
|
||||
assertThat(resource.getPriority()).isEqualTo(classificationSummary.getPriority());
|
||||
assertThat(resource.getApplicationEntryPoint())
|
||||
.isEqualTo(classificationSummary.getApplicationEntryPoint());
|
||||
assertThat(resource.getServiceLevel()).isEqualTo(classificationSummary.getServiceLevel());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,147 @@
|
|||
package pro.taskana.classification.rest.assembler;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import pro.taskana.classification.api.ClassificationService;
|
||||
import pro.taskana.classification.api.models.ClassificationSummary;
|
||||
import pro.taskana.classification.internal.models.ClassificationSummaryImpl;
|
||||
import pro.taskana.classification.rest.models.ClassificationSummaryRepresentationModel;
|
||||
import pro.taskana.common.rest.TaskanaSpringBootTest;
|
||||
|
||||
/** Test for {@link ClassificationSummaryRepresentationModelAssembler}. */
|
||||
@TaskanaSpringBootTest
|
||||
class ClassificationSummaryRepresentationModelAssemblerTest {
|
||||
|
||||
private final ClassificationSummaryRepresentationModelAssembler assembler;
|
||||
|
||||
private final ClassificationService classificationService;
|
||||
|
||||
@Autowired
|
||||
ClassificationSummaryRepresentationModelAssemblerTest(
|
||||
ClassificationSummaryRepresentationModelAssembler assembler,
|
||||
ClassificationService classificationService) {
|
||||
this.assembler = assembler;
|
||||
this.classificationService = classificationService;
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_ReturnRepresentationModel_When_ConvertingEntityToRepresentationModel() {
|
||||
// given
|
||||
ClassificationSummaryImpl classification =
|
||||
(ClassificationSummaryImpl)
|
||||
classificationService.newClassification("DOMAIN_A", "1", "A").asSummary();
|
||||
classification.setId("1");
|
||||
classification.setCategory("ABC");
|
||||
classification.setName("Classification 1");
|
||||
classification.setCustom1("Custom1");
|
||||
classification.setCustom2("Custom2");
|
||||
classification.setCustom3("Custom3");
|
||||
classification.setCustom4("Custom4");
|
||||
classification.setCustom5("Custom5");
|
||||
classification.setCustom6("Custom6");
|
||||
classification.setCustom7("Custom7");
|
||||
classification.setCustom8("Custom8");
|
||||
classification.setParentId("2");
|
||||
classification.setParentKey("parentKey");
|
||||
classification.setPriority(2);
|
||||
classification.setApplicationEntryPoint("12");
|
||||
classification.setServiceLevel("P1D");
|
||||
// when
|
||||
ClassificationSummaryRepresentationModel repModel = assembler.toModel(classification);
|
||||
// then
|
||||
testEquality(classification, repModel);
|
||||
testLinks(repModel);
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_ReturnEntity_When_ConvertingRepresentationModelToEntity() {
|
||||
// given
|
||||
ClassificationSummaryRepresentationModel repModel =
|
||||
new ClassificationSummaryRepresentationModel();
|
||||
repModel.setCategory("EFG");
|
||||
repModel.setClassificationId("2");
|
||||
repModel.setCustom1("custom1");
|
||||
repModel.setCustom2("custom2");
|
||||
repModel.setCustom3("custom3");
|
||||
repModel.setCustom4("custom4");
|
||||
repModel.setCustom5("custom5");
|
||||
repModel.setCustom6("custom6");
|
||||
repModel.setCustom7("custom7");
|
||||
repModel.setCustom8("custom8");
|
||||
repModel.setDomain("domain1");
|
||||
repModel.setKey("key");
|
||||
repModel.setName("classSummary");
|
||||
repModel.setParentId("ID2");
|
||||
repModel.setParentKey("key2");
|
||||
repModel.setPriority(1);
|
||||
repModel.setType("A");
|
||||
repModel.setApplicationEntryPoint("applicationEntryPoint");
|
||||
repModel.setServiceLevel("ServiceLevel");
|
||||
// when
|
||||
ClassificationSummary classificationSummary = assembler.toEntityModel(repModel);
|
||||
// then
|
||||
testEquality(classificationSummary, repModel);
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_Equal_When_ComparingEntityWithConvertedEntity() {
|
||||
// given
|
||||
ClassificationSummaryImpl classification =
|
||||
(ClassificationSummaryImpl)
|
||||
classificationService.newClassification("DOMAIN_A", "1", "A").asSummary();
|
||||
classification.setId("1");
|
||||
classification.setCategory("ABC");
|
||||
classification.setName("Classification 1");
|
||||
classification.setCustom1("Custom1");
|
||||
classification.setCustom2("Custom2");
|
||||
classification.setCustom3("Custom3");
|
||||
classification.setCustom4("Custom4");
|
||||
classification.setCustom5("Custom5");
|
||||
classification.setCustom6("Custom6");
|
||||
classification.setCustom7("Custom7");
|
||||
classification.setCustom8("Custom8");
|
||||
classification.setParentId("2");
|
||||
classification.setParentKey("parentKey");
|
||||
classification.setPriority(2);
|
||||
classification.setApplicationEntryPoint("12");
|
||||
classification.setServiceLevel("P1D");
|
||||
// when
|
||||
ClassificationSummaryRepresentationModel repModel = assembler.toModel(classification);
|
||||
ClassificationSummary secondClassification = assembler.toEntityModel(repModel);
|
||||
// then
|
||||
assertThat(classification)
|
||||
.hasNoNullFieldsOrProperties()
|
||||
.isNotSameAs(secondClassification)
|
||||
.isEqualTo(secondClassification);
|
||||
}
|
||||
|
||||
static void testEquality(
|
||||
ClassificationSummary entity, ClassificationSummaryRepresentationModel repModel) {
|
||||
assertThat(entity).hasNoNullFieldsOrProperties();
|
||||
assertThat(repModel).hasNoNullFieldsOrProperties();
|
||||
assertThat(entity.getId()).isEqualTo(repModel.getClassificationId());
|
||||
assertThat(entity.getKey()).isEqualTo(repModel.getKey());
|
||||
assertThat(entity.getApplicationEntryPoint()).isEqualTo(repModel.getApplicationEntryPoint());
|
||||
assertThat(entity.getCategory()).isEqualTo(repModel.getCategory());
|
||||
assertThat(entity.getDomain()).isEqualTo(repModel.getDomain());
|
||||
assertThat(entity.getName()).isEqualTo(repModel.getName());
|
||||
assertThat(entity.getParentId()).isEqualTo(repModel.getParentId());
|
||||
assertThat(entity.getParentKey()).isEqualTo(repModel.getParentKey());
|
||||
assertThat(entity.getPriority()).isEqualTo(repModel.getPriority());
|
||||
assertThat(entity.getServiceLevel()).isEqualTo(repModel.getServiceLevel());
|
||||
assertThat(entity.getType()).isEqualTo(repModel.getType());
|
||||
assertThat(entity.getCustom1()).isEqualTo(repModel.getCustom1());
|
||||
assertThat(entity.getCustom2()).isEqualTo(repModel.getCustom2());
|
||||
assertThat(entity.getCustom3()).isEqualTo(repModel.getCustom3());
|
||||
assertThat(entity.getCustom4()).isEqualTo(repModel.getCustom4());
|
||||
assertThat(entity.getCustom5()).isEqualTo(repModel.getCustom5());
|
||||
assertThat(entity.getCustom6()).isEqualTo(repModel.getCustom6());
|
||||
assertThat(entity.getCustom7()).isEqualTo(repModel.getCustom7());
|
||||
assertThat(entity.getCustom8()).isEqualTo(repModel.getCustom8());
|
||||
}
|
||||
|
||||
private void testLinks(ClassificationSummaryRepresentationModel repModel) {}
|
||||
}
|
|
@ -25,7 +25,7 @@ import pro.taskana.common.rest.models.TaskanaPagedModelKeys;
|
|||
/** Generate REST Documentatioon for the WorkbasketController. */
|
||||
class WorkbasketControllerRestDocumentation extends BaseRestDocumentation {
|
||||
|
||||
public static final String PROPERTY_NAME = TaskanaPagedModelKeys.ACCESSITEMS.getPropertyName();
|
||||
public static final String PROPERTY_NAME = TaskanaPagedModelKeys.ACCESS_ITEMS.getPropertyName();
|
||||
// HashMaps to store the field descriptions centrally for multiple uses
|
||||
private final HashMap<String, String> workbasketFieldDescriptionsMap = new HashMap<>();
|
||||
private final HashMap<String, String> accessItemFieldDescriptionsMap = new HashMap<>();
|
||||
|
|
|
@ -563,7 +563,7 @@ class TaskControllerIntTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
void should_ChangeValueOfModified_When_UpdatingTask() throws IOException {
|
||||
void should_ChangeValueOfModified_When_UpdatingTask() {
|
||||
|
||||
ResponseEntity<TaskRepresentationModel> responseGet =
|
||||
template.exchange(
|
||||
|
|
|
@ -0,0 +1,119 @@
|
|||
package pro.taskana.task.rest.assembler;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Collections;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import pro.taskana.classification.api.ClassificationService;
|
||||
import pro.taskana.classification.api.models.ClassificationSummary;
|
||||
import pro.taskana.classification.rest.models.ClassificationSummaryRepresentationModel;
|
||||
import pro.taskana.common.rest.TaskanaSpringBootTest;
|
||||
import pro.taskana.task.api.TaskService;
|
||||
import pro.taskana.task.api.models.Attachment;
|
||||
import pro.taskana.task.api.models.ObjectReference;
|
||||
import pro.taskana.task.internal.models.AttachmentImpl;
|
||||
import pro.taskana.task.rest.models.AttachmentRepresentationModel;
|
||||
|
||||
/** Test for {@link AttachmentRepresentationModelAssembler}. */
|
||||
@TaskanaSpringBootTest
|
||||
class AttachmentRepresentationModelAssemblerTest {
|
||||
|
||||
private final AttachmentRepresentationModelAssembler assembler;
|
||||
private final ClassificationService classService;
|
||||
private final TaskService taskService;
|
||||
|
||||
@Autowired
|
||||
AttachmentRepresentationModelAssemblerTest(
|
||||
AttachmentRepresentationModelAssembler assembler,
|
||||
ClassificationService classService,
|
||||
TaskService taskService) {
|
||||
this.assembler = assembler;
|
||||
this.classService = classService;
|
||||
this.taskService = taskService;
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_ReturnEntity_When_ConvertingRepresentationModelToEntity() {
|
||||
ObjectReference reference = new ObjectReference();
|
||||
reference.setId("abc");
|
||||
ClassificationSummaryRepresentationModel summary =
|
||||
new ClassificationSummaryRepresentationModel();
|
||||
summary.setKey("keyabc");
|
||||
summary.setDomain("DOMAIN_A");
|
||||
summary.setType("MANUAL");
|
||||
AttachmentRepresentationModel repModel = new AttachmentRepresentationModel();
|
||||
repModel.setCustomAttributes(Collections.singletonMap("abc", "def"));
|
||||
repModel.setClassificationSummary(summary);
|
||||
repModel.setAttachmentId("id");
|
||||
repModel.setTaskId("taskId");
|
||||
repModel.setChannel("channel");
|
||||
repModel.setCreated(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
repModel.setModified(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
repModel.setObjectReference(reference);
|
||||
repModel.setReceived(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
|
||||
Attachment attachment = assembler.toEntityModel(repModel);
|
||||
|
||||
testEquality(attachment, repModel);
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_ReturnRepresentationModel_When_ConvertingEntityToRepresentationModel() {
|
||||
AttachmentImpl attachment = (AttachmentImpl) taskService.newAttachment();
|
||||
ObjectReference reference = new ObjectReference();
|
||||
ClassificationSummary summary =
|
||||
classService.newClassification("ckey", "cdomain", "MANUAL").asSummary();
|
||||
reference.setId("abc");
|
||||
attachment.setCustomAttributes(Collections.singletonMap("abc", "def"));
|
||||
attachment.setClassificationSummary(summary);
|
||||
attachment.setId("id");
|
||||
attachment.setTaskId("taskId");
|
||||
attachment.setChannel("channel");
|
||||
attachment.setCreated(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
attachment.setModified(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
attachment.setObjectReference(reference);
|
||||
attachment.setReceived(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
|
||||
AttachmentRepresentationModel repModel = assembler.toModel(attachment);
|
||||
|
||||
testEquality(attachment, repModel);
|
||||
testLinks(repModel);
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_Equal_When_ComparingEntityWithConvertedEntity() {
|
||||
AttachmentImpl attachment = (AttachmentImpl) taskService.newAttachment();
|
||||
ObjectReference reference = new ObjectReference();
|
||||
ClassificationSummary summary =
|
||||
classService.newClassification("ckey", "cdomain", "MANUAL").asSummary();
|
||||
reference.setId("abc");
|
||||
attachment.setCustomAttributes(Collections.singletonMap("abc", "def"));
|
||||
attachment.setClassificationSummary(summary);
|
||||
attachment.setId("id");
|
||||
attachment.setTaskId("taskId");
|
||||
attachment.setChannel("channel");
|
||||
attachment.setCreated(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
attachment.setModified(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
attachment.setObjectReference(reference);
|
||||
attachment.setReceived(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
|
||||
AttachmentRepresentationModel repModel = assembler.toModel(attachment);
|
||||
Attachment attachment2 = assembler.toEntityModel(repModel);
|
||||
|
||||
assertThat(attachment)
|
||||
.hasNoNullFieldsOrProperties()
|
||||
.isNotSameAs(attachment2)
|
||||
.isEqualTo(attachment2);
|
||||
}
|
||||
|
||||
void testEquality(Attachment attachment, AttachmentRepresentationModel repModel) {
|
||||
AttachmentSummaryRepresentationModelAssemblerTest.testEquality(attachment, repModel);
|
||||
|
||||
assertThat(attachment.getCustomAttributes()).isEqualTo(repModel.getCustomAttributes());
|
||||
}
|
||||
|
||||
void testLinks(AttachmentRepresentationModel repModel) {}
|
||||
}
|
|
@ -0,0 +1,126 @@
|
|||
package pro.taskana.task.rest.assembler;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.time.Instant;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import pro.taskana.classification.api.ClassificationService;
|
||||
import pro.taskana.classification.api.models.ClassificationSummary;
|
||||
import pro.taskana.classification.rest.models.ClassificationSummaryRepresentationModel;
|
||||
import pro.taskana.common.rest.TaskanaSpringBootTest;
|
||||
import pro.taskana.task.api.TaskService;
|
||||
import pro.taskana.task.api.models.AttachmentSummary;
|
||||
import pro.taskana.task.api.models.ObjectReference;
|
||||
import pro.taskana.task.internal.models.AttachmentSummaryImpl;
|
||||
import pro.taskana.task.rest.models.AttachmentSummaryRepresentationModel;
|
||||
|
||||
/** Test for {@link AttachmentSummaryRepresentationModelAssembler}. */
|
||||
@TaskanaSpringBootTest
|
||||
class AttachmentSummaryRepresentationModelAssemblerTest {
|
||||
|
||||
private final AttachmentSummaryRepresentationModelAssembler assembler;
|
||||
private final ClassificationService classService;
|
||||
private final TaskService taskService;
|
||||
|
||||
@Autowired
|
||||
AttachmentSummaryRepresentationModelAssemblerTest(
|
||||
AttachmentSummaryRepresentationModelAssembler assembler,
|
||||
ClassificationService classService,
|
||||
TaskService taskService) {
|
||||
this.assembler = assembler;
|
||||
this.classService = classService;
|
||||
this.taskService = taskService;
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_ReturnEntity_When_ConvertingRepresentationModelToEntity() {
|
||||
ObjectReference reference = new ObjectReference();
|
||||
reference.setId("abc");
|
||||
ClassificationSummaryRepresentationModel summary =
|
||||
new ClassificationSummaryRepresentationModel();
|
||||
summary.setKey("keyabc");
|
||||
summary.setDomain("DOMAIN_A");
|
||||
summary.setType("MANUAL");
|
||||
AttachmentSummaryRepresentationModel repModel = new AttachmentSummaryRepresentationModel();
|
||||
repModel.setClassificationSummary(summary);
|
||||
repModel.setAttachmentId("id");
|
||||
repModel.setTaskId("taskId");
|
||||
repModel.setChannel("channel");
|
||||
repModel.setCreated(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
repModel.setModified(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
repModel.setObjectReference(reference);
|
||||
repModel.setReceived(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
|
||||
AttachmentSummary attachment = assembler.toEntityModel(repModel);
|
||||
|
||||
testEquality(attachment, repModel);
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_ReturnRepresentationModel_When_ConvertingEntityToRepresentationModel() {
|
||||
AttachmentSummaryImpl attachment =
|
||||
(AttachmentSummaryImpl) taskService.newAttachment().asSummary();
|
||||
ObjectReference reference = new ObjectReference();
|
||||
ClassificationSummary summary =
|
||||
classService.newClassification("ckey", "cdomain", "MANUAL").asSummary();
|
||||
reference.setId("abc");
|
||||
attachment.setClassificationSummary(summary);
|
||||
attachment.setId("id");
|
||||
attachment.setTaskId("taskId");
|
||||
attachment.setChannel("channel");
|
||||
attachment.setCreated(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
attachment.setModified(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
attachment.setObjectReference(reference);
|
||||
attachment.setReceived(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
|
||||
AttachmentSummaryRepresentationModel repModel = assembler.toModel(attachment);
|
||||
|
||||
testEquality(attachment, repModel);
|
||||
testLinks(repModel);
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_Equal_When_ComparingEntityWithConvertedEntity() {
|
||||
AttachmentSummaryImpl attachment =
|
||||
(AttachmentSummaryImpl) taskService.newAttachment().asSummary();
|
||||
ObjectReference reference = new ObjectReference();
|
||||
ClassificationSummary summary =
|
||||
classService.newClassification("ckey", "cdomain", "MANUAL").asSummary();
|
||||
reference.setId("abc");
|
||||
attachment.setClassificationSummary(summary);
|
||||
attachment.setId("id");
|
||||
attachment.setTaskId("taskId");
|
||||
attachment.setChannel("channel");
|
||||
attachment.setCreated(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
attachment.setModified(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
attachment.setObjectReference(reference);
|
||||
attachment.setReceived(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
|
||||
AttachmentSummaryRepresentationModel repModel = assembler.toModel(attachment);
|
||||
AttachmentSummary attachment2 = assembler.toEntityModel(repModel);
|
||||
|
||||
assertThat(attachment)
|
||||
.hasNoNullFieldsOrProperties()
|
||||
.isNotSameAs(attachment2)
|
||||
.isEqualTo(attachment2);
|
||||
}
|
||||
|
||||
static void testEquality(
|
||||
AttachmentSummary attachment, AttachmentSummaryRepresentationModel repModel) {
|
||||
assertThat(attachment).hasNoNullFieldsOrProperties();
|
||||
assertThat(repModel).hasNoNullFieldsOrProperties();
|
||||
assertThat(attachment.getId()).isEqualTo(repModel.getAttachmentId());
|
||||
assertThat(attachment.getTaskId()).isEqualTo(repModel.getTaskId());
|
||||
assertThat(attachment.getCreated()).isEqualTo(repModel.getCreated());
|
||||
assertThat(attachment.getModified()).isEqualTo(repModel.getModified());
|
||||
assertThat(attachment.getReceived()).isEqualTo(repModel.getReceived());
|
||||
assertThat(attachment.getClassificationSummary().getId())
|
||||
.isEqualTo(repModel.getClassificationSummary().getClassificationId());
|
||||
assertThat(attachment.getObjectReference()).isEqualTo(repModel.getObjectReference());
|
||||
assertThat(attachment.getChannel()).isEqualTo(repModel.getChannel());
|
||||
}
|
||||
|
||||
private void testLinks(AttachmentSummaryRepresentationModel repModel) {}
|
||||
}
|
|
@ -12,65 +12,83 @@ import pro.taskana.task.api.models.TaskComment;
|
|||
import pro.taskana.task.internal.models.TaskCommentImpl;
|
||||
import pro.taskana.task.rest.models.TaskCommentRepresentationModel;
|
||||
|
||||
/**
|
||||
* Test for {@link TaskCommentRepresentationModelAssembler}.
|
||||
*/
|
||||
/** Test for {@link TaskCommentRepresentationModelAssembler}. */
|
||||
@TaskanaSpringBootTest
|
||||
class TaskCommentRepresentationModelAssemblerTest {
|
||||
|
||||
private final TaskCommentRepresentationModelAssembler taskCommentRepresentationModelAssembler;
|
||||
private final TaskCommentRepresentationModelAssembler assembler;
|
||||
private final TaskService taskService;
|
||||
|
||||
@Autowired
|
||||
TaskCommentRepresentationModelAssemblerTest(
|
||||
TaskCommentRepresentationModelAssembler taskCommentRepresentationModelAssembler,
|
||||
TaskService taskService) {
|
||||
this.taskCommentRepresentationModelAssembler = taskCommentRepresentationModelAssembler;
|
||||
TaskCommentRepresentationModelAssembler assembler, TaskService taskService) {
|
||||
this.assembler = assembler;
|
||||
this.taskService = taskService;
|
||||
}
|
||||
|
||||
@Test
|
||||
void taskCommentModelToResource() {
|
||||
void should_ReturnRepresentationModel_When_ConvertingEntityToRepresentationModel() {
|
||||
|
||||
TaskCommentImpl taskComment =
|
||||
(TaskCommentImpl) taskService.newTaskComment("TKI:000000000000000000000000000000000000");
|
||||
|
||||
taskComment.setId("taskCommentId");
|
||||
taskComment.setCreator("user_1_1");
|
||||
taskComment.setTextField("this is a task comment");
|
||||
taskComment.setCreated(Instant.parse("2010-01-01T12:00:00Z"));
|
||||
taskComment.setModified(Instant.parse("2011-11-11T11:00:00Z"));
|
||||
|
||||
TaskCommentRepresentationModel taskCommentRepresentationModel =
|
||||
taskCommentRepresentationModelAssembler.toModel(taskComment);
|
||||
TaskCommentRepresentationModel repModel = assembler.toModel(taskComment);
|
||||
|
||||
testEquality(taskComment, taskCommentRepresentationModel);
|
||||
testEquality(taskComment, repModel);
|
||||
testLinks(repModel);
|
||||
}
|
||||
|
||||
@Test
|
||||
void taskCommentResourceToModel() {
|
||||
void should_ReturnEntity_When_ConvertingRepresentationModelToEntity() {
|
||||
|
||||
TaskCommentRepresentationModel taskCommentRepresentationModel =
|
||||
new TaskCommentRepresentationModel();
|
||||
taskCommentRepresentationModel.setTaskId("TKI:000000000000000000000000000000000000");
|
||||
taskCommentRepresentationModel.setTaskCommentId("TCI:000000000000000000000000000000000000");
|
||||
taskCommentRepresentationModel.setCreator("user_1_1");
|
||||
taskCommentRepresentationModel.setCreated(Instant.parse("2010-01-01T12:00:00Z"));
|
||||
taskCommentRepresentationModel.setModified(Instant.parse("2011-11-11T11:00:00Z"));
|
||||
TaskCommentRepresentationModel repModel = new TaskCommentRepresentationModel();
|
||||
repModel.setTaskId("TKI:000000000000000000000000000000000000");
|
||||
repModel.setTaskCommentId("TCI:000000000000000000000000000000000000");
|
||||
repModel.setCreator("user_1_1");
|
||||
repModel.setCreated(Instant.parse("2010-01-01T12:00:00Z"));
|
||||
repModel.setModified(Instant.parse("2011-11-11T11:00:00Z"));
|
||||
repModel.setTextField("textField");
|
||||
|
||||
TaskComment taskComment =
|
||||
taskCommentRepresentationModelAssembler.toEntityModel(taskCommentRepresentationModel);
|
||||
TaskComment taskComment = assembler.toEntityModel(repModel);
|
||||
|
||||
testEquality(taskComment, taskCommentRepresentationModel);
|
||||
testEquality(taskComment, repModel);
|
||||
}
|
||||
|
||||
private void testEquality(
|
||||
TaskComment taskComment, TaskCommentRepresentationModel taskCommentRepresentationModel) {
|
||||
@Test
|
||||
void should_Equal_When_ComparingEntityWithConvertedEntity() {
|
||||
TaskCommentImpl taskComment =
|
||||
(TaskCommentImpl) taskService.newTaskComment("TKI:000000000000000000000000000000000000");
|
||||
taskComment.setId("taskCommentId");
|
||||
taskComment.setCreator("user_1_1");
|
||||
taskComment.setTextField("this is a task comment");
|
||||
taskComment.setCreated(Instant.parse("2010-01-01T12:00:00Z"));
|
||||
taskComment.setModified(Instant.parse("2011-11-11T11:00:00Z"));
|
||||
|
||||
assertThat(taskComment.getTaskId()).isEqualTo(taskCommentRepresentationModel.getTaskId());
|
||||
assertThat(taskComment.getId()).isEqualTo(taskCommentRepresentationModel.getTaskCommentId());
|
||||
assertThat(taskComment.getCreator()).isEqualTo(taskCommentRepresentationModel.getCreator());
|
||||
assertThat(taskComment.getTextField()).isEqualTo(taskCommentRepresentationModel.getTextField());
|
||||
assertThat(taskComment.getCreated()).isEqualTo(taskCommentRepresentationModel.getCreated());
|
||||
assertThat(taskComment.getModified()).isEqualTo(taskCommentRepresentationModel.getModified());
|
||||
TaskCommentRepresentationModel repModel = assembler.toModel(taskComment);
|
||||
TaskComment taskComment2 = assembler.toEntityModel(repModel);
|
||||
|
||||
assertThat(taskComment)
|
||||
.hasNoNullFieldsOrProperties()
|
||||
.isNotSameAs(taskComment2)
|
||||
.isEqualTo(taskComment2);
|
||||
}
|
||||
|
||||
private void testEquality(TaskComment taskComment, TaskCommentRepresentationModel repModel) {
|
||||
assertThat(taskComment).hasNoNullFieldsOrProperties();
|
||||
assertThat(repModel).hasNoNullFieldsOrProperties();
|
||||
assertThat(taskComment.getId()).isEqualTo(repModel.getTaskCommentId());
|
||||
assertThat(taskComment.getTaskId()).isEqualTo(repModel.getTaskId());
|
||||
assertThat(taskComment.getTextField()).isEqualTo(repModel.getTextField());
|
||||
assertThat(taskComment.getCreator()).isEqualTo(repModel.getCreator());
|
||||
assertThat(taskComment.getCreated()).isEqualTo(repModel.getCreated());
|
||||
assertThat(taskComment.getModified()).isEqualTo(repModel.getModified());
|
||||
}
|
||||
|
||||
private void testLinks(TaskCommentRepresentationModel repModel) {}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ import org.junit.jupiter.api.Test;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import pro.taskana.classification.api.ClassificationService;
|
||||
import pro.taskana.classification.api.models.Classification;
|
||||
import pro.taskana.classification.api.models.ClassificationSummary;
|
||||
import pro.taskana.classification.rest.models.ClassificationSummaryRepresentationModel;
|
||||
import pro.taskana.common.api.exceptions.InvalidArgumentException;
|
||||
import pro.taskana.common.rest.Mapping;
|
||||
|
@ -26,6 +26,7 @@ import pro.taskana.task.rest.models.AttachmentRepresentationModel;
|
|||
import pro.taskana.task.rest.models.TaskRepresentationModel;
|
||||
import pro.taskana.workbasket.api.WorkbasketService;
|
||||
import pro.taskana.workbasket.api.models.Workbasket;
|
||||
import pro.taskana.workbasket.api.models.WorkbasketSummary;
|
||||
import pro.taskana.workbasket.rest.models.WorkbasketSummaryRepresentationModel;
|
||||
|
||||
/** Test for {@link TaskRepresentationModelAssembler}. */
|
||||
|
@ -35,22 +36,23 @@ class TaskRepresentationModelAssemberTest {
|
|||
TaskService taskService;
|
||||
WorkbasketService workbasketService;
|
||||
ClassificationService classificationService;
|
||||
TaskRepresentationModelAssembler taskRepresentationModelAssembler;
|
||||
TaskRepresentationModelAssembler assembler;
|
||||
|
||||
@Autowired
|
||||
TaskRepresentationModelAssemberTest(
|
||||
TaskService taskService,
|
||||
WorkbasketService workbasketService,
|
||||
ClassificationService classificationService,
|
||||
TaskRepresentationModelAssembler taskRepresentationModelAssembler) {
|
||||
TaskRepresentationModelAssembler assembler) {
|
||||
this.taskService = taskService;
|
||||
this.workbasketService = workbasketService;
|
||||
this.classificationService = classificationService;
|
||||
this.taskRepresentationModelAssembler = taskRepresentationModelAssembler;
|
||||
this.assembler = assembler;
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSimpleResourceToModel() throws InvalidArgumentException {
|
||||
void should_ReturnEntity_When_ConvertingRepresentationModelToEntity()
|
||||
throws InvalidArgumentException {
|
||||
// given
|
||||
ObjectReference primaryObjRef = new ObjectReference();
|
||||
primaryObjRef.setId("abc");
|
||||
|
@ -62,68 +64,70 @@ class TaskRepresentationModelAssemberTest {
|
|||
classificationSummary.setKey("keyabc");
|
||||
classificationSummary.setDomain("DOMAIN_A");
|
||||
classificationSummary.setType("MANUAL");
|
||||
AttachmentRepresentationModel attachement = new AttachmentRepresentationModel();
|
||||
attachement.setClassificationSummary(classificationSummary);
|
||||
attachement.setAttachmentId("attachementId");
|
||||
TaskRepresentationModel resource = new TaskRepresentationModel();
|
||||
resource.setTaskId("taskId");
|
||||
resource.setExternalId("externalId");
|
||||
resource.setCreated(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
resource.setClaimed(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
resource.setCompleted(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
resource.setModified(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
resource.setPlanned(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
resource.setDue(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
resource.setName("name");
|
||||
resource.setCreator("creator");
|
||||
resource.setDescription("desc");
|
||||
resource.setNote("note");
|
||||
resource.setPriority(123);
|
||||
resource.setState(TaskState.READY);
|
||||
resource.setClassificationSummary(classificationSummary);
|
||||
resource.setWorkbasketSummary(workbasketResource);
|
||||
resource.setBusinessProcessId("businessProcessId");
|
||||
resource.setParentBusinessProcessId("parentBusinessProcessId");
|
||||
resource.setOwner("owner");
|
||||
resource.setPrimaryObjRef(primaryObjRef);
|
||||
resource.setRead(true);
|
||||
resource.setTransferred(true);
|
||||
resource.setCustomAttributes(
|
||||
AttachmentRepresentationModel attachment = new AttachmentRepresentationModel();
|
||||
attachment.setClassificationSummary(classificationSummary);
|
||||
attachment.setAttachmentId("attachmentId");
|
||||
TaskRepresentationModel repModel = new TaskRepresentationModel();
|
||||
repModel.setTaskId("taskId");
|
||||
repModel.setExternalId("externalId");
|
||||
repModel.setCreated(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
repModel.setClaimed(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
repModel.setCompleted(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
repModel.setModified(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
repModel.setPlanned(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
repModel.setDue(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
repModel.setName("name");
|
||||
repModel.setCreator("creator");
|
||||
repModel.setDescription("desc");
|
||||
repModel.setNote("note");
|
||||
repModel.setPriority(123);
|
||||
repModel.setState(TaskState.READY);
|
||||
repModel.setClassificationSummary(classificationSummary);
|
||||
repModel.setWorkbasketSummary(workbasketResource);
|
||||
repModel.setBusinessProcessId("businessProcessId");
|
||||
repModel.setParentBusinessProcessId("parentBusinessProcessId");
|
||||
repModel.setOwner("owner");
|
||||
repModel.setPrimaryObjRef(primaryObjRef);
|
||||
repModel.setRead(true);
|
||||
repModel.setTransferred(true);
|
||||
repModel.setCustomAttributes(
|
||||
Collections.singletonList(TaskRepresentationModel.CustomAttribute.of("abc", "def")));
|
||||
resource.setCallbackInfo(
|
||||
repModel.setCallbackInfo(
|
||||
Collections.singletonList(TaskRepresentationModel.CustomAttribute.of("ghi", "jkl")));
|
||||
resource.setAttachments(Collections.singletonList(attachement));
|
||||
resource.setCustom1("custom1");
|
||||
resource.setCustom2("custom2");
|
||||
resource.setCustom3("custom3");
|
||||
resource.setCustom4("custom4");
|
||||
resource.setCustom5("custom5");
|
||||
resource.setCustom6("custom6");
|
||||
resource.setCustom7("custom7");
|
||||
resource.setCustom8("custom8");
|
||||
resource.setCustom9("custom9");
|
||||
resource.setCustom10("custom10");
|
||||
resource.setCustom11("custom11");
|
||||
resource.setCustom12("custom12");
|
||||
resource.setCustom13("custom13");
|
||||
resource.setCustom14("custom14");
|
||||
resource.setCustom15("custom15");
|
||||
repModel.setAttachments(Collections.singletonList(attachment));
|
||||
repModel.setCustom1("custom1");
|
||||
repModel.setCustom2("custom2");
|
||||
repModel.setCustom3("custom3");
|
||||
repModel.setCustom4("custom4");
|
||||
repModel.setCustom5("custom5");
|
||||
repModel.setCustom6("custom6");
|
||||
repModel.setCustom7("custom7");
|
||||
repModel.setCustom8("custom8");
|
||||
repModel.setCustom9("custom9");
|
||||
repModel.setCustom10("custom10");
|
||||
repModel.setCustom11("custom11");
|
||||
repModel.setCustom12("custom12");
|
||||
repModel.setCustom13("custom13");
|
||||
repModel.setCustom14("custom14");
|
||||
repModel.setCustom15("custom15");
|
||||
repModel.setCustom16("custom16");
|
||||
// when
|
||||
Task task = taskRepresentationModelAssembler.toEntityModel(resource);
|
||||
Task task = assembler.toEntityModel(repModel);
|
||||
// then
|
||||
testEquality(task, resource);
|
||||
testEquality(task, repModel);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testModelToResource() throws InvalidArgumentException {
|
||||
void should_ReturnRepresentationModel_When_ConvertingEntityToRepresentationModel()
|
||||
throws InvalidArgumentException {
|
||||
// given
|
||||
ObjectReference primaryObjRef = new ObjectReference();
|
||||
primaryObjRef.setId("abc");
|
||||
final Workbasket workbasket = workbasketService.newWorkbasket("key", "domain");
|
||||
Classification classification =
|
||||
classificationService.newClassification("ckey", "cdomain", "MANUAL");
|
||||
ClassificationSummary classification =
|
||||
classificationService.newClassification("ckey", "cdomain", "MANUAL").asSummary();
|
||||
AttachmentImpl attachment = (AttachmentImpl) taskService.newAttachment();
|
||||
attachment.setClassificationSummary(classification.asSummary());
|
||||
attachment.setClassificationSummary(classification);
|
||||
attachment.setId("attachmentId");
|
||||
TaskImpl task = (TaskImpl) taskService.newTask();
|
||||
task.setId("taskId");
|
||||
|
@ -166,88 +170,107 @@ class TaskRepresentationModelAssemberTest {
|
|||
task.setCustom13("custom13");
|
||||
task.setCustom14("custom14");
|
||||
task.setCustom15("custom15");
|
||||
task.setCustom16("custom16");
|
||||
// when
|
||||
TaskRepresentationModel resource = taskRepresentationModelAssembler.toModel(task);
|
||||
TaskRepresentationModel repModel = assembler.toModel(task);
|
||||
// then
|
||||
testEquality(task, resource);
|
||||
testLinks(resource);
|
||||
testEquality(task, repModel);
|
||||
testLinks(repModel);
|
||||
}
|
||||
|
||||
void testEquality(Task task, TaskRepresentationModel resource) throws InvalidArgumentException {
|
||||
assertThat(resource.getTaskId()).isEqualTo(task.getId());
|
||||
assertThat(resource.getExternalId()).isEqualTo(task.getExternalId());
|
||||
assertThat(resource.getCreated())
|
||||
.isEqualTo(task.getCreated() == null ? null : task.getCreated().toString());
|
||||
assertThat(resource.getClaimed())
|
||||
.isEqualTo(task.getClaimed() == null ? null : task.getClaimed().toString());
|
||||
assertThat(resource.getCompleted())
|
||||
.isEqualTo(task.getCompleted() == null ? null : task.getCompleted().toString());
|
||||
assertThat(resource.getModified())
|
||||
.isEqualTo(task.getModified() == null ? null : task.getModified().toString());
|
||||
assertThat(resource.getPlanned())
|
||||
.isEqualTo(task.getPlanned() == null ? null : task.getPlanned().toString());
|
||||
assertThat(resource.getDue())
|
||||
.isEqualTo(task.getDue() == null ? null : task.getDue().toString());
|
||||
assertThat(resource.getName()).isEqualTo(task.getName());
|
||||
assertThat(resource.getCreator()).isEqualTo(task.getCreator());
|
||||
assertThat(resource.getDescription()).isEqualTo(task.getDescription());
|
||||
assertThat(resource.getNote()).isEqualTo(task.getNote());
|
||||
assertThat(resource.getPriority()).isEqualTo(task.getPriority());
|
||||
assertThat(resource.getState()).isEqualTo(task.getState());
|
||||
assertThat(resource.getClassificationSummary().getClassificationId())
|
||||
.isEqualTo(task.getClassificationSummary().getId());
|
||||
assertThat(resource.getWorkbasketSummary().getWorkbasketId())
|
||||
.isEqualTo(task.getWorkbasketSummary().getId());
|
||||
assertThat(resource.getBusinessProcessId()).isEqualTo(task.getBusinessProcessId());
|
||||
assertThat(resource.getParentBusinessProcessId()).isEqualTo(task.getParentBusinessProcessId());
|
||||
assertThat(resource.getOwner()).isEqualTo(task.getOwner());
|
||||
assertThat(resource.getPrimaryObjRef()).isEqualTo(task.getPrimaryObjRef());
|
||||
assertThat(resource.isRead()).isEqualTo(task.isRead());
|
||||
assertThat(resource.isTransferred()).isEqualTo(task.isTransferred());
|
||||
testEquality(task.getCustomAttributes(), resource.getCustomAttributes());
|
||||
testEquality(task.getCallbackInfo(), resource.getCallbackInfo());
|
||||
testEqualityAttachements(task.getAttachments(), resource.getAttachments());
|
||||
assertThat(resource.getCustom1()).isEqualTo(task.getCustomAttribute("1"));
|
||||
assertThat(resource.getCustom2()).isEqualTo(task.getCustomAttribute("2"));
|
||||
assertThat(resource.getCustom3()).isEqualTo(task.getCustomAttribute("3"));
|
||||
assertThat(resource.getCustom4()).isEqualTo(task.getCustomAttribute("4"));
|
||||
assertThat(resource.getCustom5()).isEqualTo(task.getCustomAttribute("5"));
|
||||
assertThat(resource.getCustom6()).isEqualTo(task.getCustomAttribute("6"));
|
||||
assertThat(resource.getCustom7()).isEqualTo(task.getCustomAttribute("7"));
|
||||
assertThat(resource.getCustom8()).isEqualTo(task.getCustomAttribute("8"));
|
||||
assertThat(resource.getCustom9()).isEqualTo(task.getCustomAttribute("9"));
|
||||
assertThat(resource.getCustom10()).isEqualTo(task.getCustomAttribute("10"));
|
||||
assertThat(resource.getCustom11()).isEqualTo(task.getCustomAttribute("11"));
|
||||
assertThat(resource.getCustom12()).isEqualTo(task.getCustomAttribute("12"));
|
||||
assertThat(resource.getCustom13()).isEqualTo(task.getCustomAttribute("13"));
|
||||
assertThat(resource.getCustom14()).isEqualTo(task.getCustomAttribute("14"));
|
||||
assertThat(resource.getCustom15()).isEqualTo(task.getCustomAttribute("15"));
|
||||
assertThat(resource.getCustom16()).isEqualTo(task.getCustomAttribute("16"));
|
||||
@Test
|
||||
void should_Equal_When_ComparingEntityWithConvertedEntity() {
|
||||
// given
|
||||
ObjectReference primaryObjRef = new ObjectReference();
|
||||
primaryObjRef.setId("abc");
|
||||
final WorkbasketSummary workbasket =
|
||||
workbasketService.newWorkbasket("key", "domain").asSummary();
|
||||
ClassificationSummary classification =
|
||||
classificationService.newClassification("ckey", "cdomain", "MANUAL").asSummary();
|
||||
AttachmentImpl attachment = (AttachmentImpl) taskService.newAttachment();
|
||||
attachment.setClassificationSummary(classification);
|
||||
attachment.setId("attachmentId");
|
||||
TaskImpl task = (TaskImpl) taskService.newTask();
|
||||
task.setId("taskId");
|
||||
task.setExternalId("externalId");
|
||||
task.setCreated(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
task.setClaimed(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
task.setCompleted(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
task.setModified(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
task.setPlanned(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
task.setDue(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
task.setName("name");
|
||||
task.setCreator("creator");
|
||||
task.setDescription("desc");
|
||||
task.setNote("note");
|
||||
task.setPriority(123);
|
||||
task.setState(TaskState.READY);
|
||||
task.setClassificationSummary(classification);
|
||||
task.setWorkbasketSummary(workbasket);
|
||||
task.setBusinessProcessId("businessProcessId");
|
||||
task.setParentBusinessProcessId("parentBusinessProcessId");
|
||||
task.setOwner("owner");
|
||||
task.setPrimaryObjRef(primaryObjRef);
|
||||
task.setRead(true);
|
||||
task.setTransferred(true);
|
||||
task.setCustomAttributes(Collections.singletonMap("abc", "def"));
|
||||
task.setCallbackInfo(Collections.singletonMap("ghi", "jkl"));
|
||||
task.setAttachments(Collections.singletonList(attachment));
|
||||
task.setCustom1("custom1");
|
||||
task.setCustom2("custom2");
|
||||
task.setCustom3("custom3");
|
||||
task.setCustom4("custom4");
|
||||
task.setCustom5("custom5");
|
||||
task.setCustom6("custom6");
|
||||
task.setCustom7("custom7");
|
||||
task.setCustom8("custom8");
|
||||
task.setCustom9("custom9");
|
||||
task.setCustom10("custom10");
|
||||
task.setCustom11("custom11");
|
||||
task.setCustom12("custom12");
|
||||
task.setCustom13("custom13");
|
||||
task.setCustom14("custom14");
|
||||
task.setCustom15("custom15");
|
||||
task.setCustom16("custom16");
|
||||
// when
|
||||
TaskRepresentationModel repModel = assembler.toModel(task);
|
||||
Task task2 = assembler.toEntityModel(repModel);
|
||||
// then
|
||||
assertThat(task).hasNoNullFieldsOrProperties().isNotSameAs(task2).isEqualTo(task2);
|
||||
}
|
||||
|
||||
private void testEquality(
|
||||
private void testEquality(Task task, TaskRepresentationModel repModel)
|
||||
throws InvalidArgumentException {
|
||||
TaskSummaryRepresentationModelAssemblerTest.testEquality(task, repModel);
|
||||
|
||||
testEqualityCustomAttributes(task.getCustomAttributes(), repModel.getCustomAttributes());
|
||||
testEqualityCustomAttributes(task.getCallbackInfo(), repModel.getCallbackInfo());
|
||||
testEqualityAttachments(task.getAttachments(), repModel.getAttachments());
|
||||
}
|
||||
|
||||
private void testEqualityCustomAttributes(
|
||||
Map<String, String> customAttributes,
|
||||
List<TaskRepresentationModel.CustomAttribute> resourceAttributes) {
|
||||
assertThat(resourceAttributes).hasSize(customAttributes.size());
|
||||
resourceAttributes.forEach(
|
||||
List<TaskRepresentationModel.CustomAttribute> repModelAttributes) {
|
||||
assertThat(repModelAttributes).hasSize(customAttributes.size());
|
||||
repModelAttributes.forEach(
|
||||
attribute ->
|
||||
assertThat(attribute.getValue()).isEqualTo(customAttributes.get(attribute.getKey())));
|
||||
}
|
||||
|
||||
private void testEqualityAttachements(
|
||||
List<Attachment> attachments, List<AttachmentRepresentationModel> resources) {
|
||||
private void testEqualityAttachments(
|
||||
List<Attachment> attachments, List<AttachmentRepresentationModel> repModels) {
|
||||
String[] objects = attachments.stream().map(Attachment::getId).toArray(String[]::new);
|
||||
|
||||
// Anything else should be be tested in AttachementResourceAssemblerTest
|
||||
assertThat(resources)
|
||||
// Anything else should be be tested in AttachmentResourceAssemblerTest
|
||||
assertThat(repModels)
|
||||
.hasSize(attachments.size())
|
||||
.extracting(AttachmentRepresentationModel::getAttachmentId)
|
||||
.containsOnly(objects);
|
||||
.containsOnlyOnce(objects);
|
||||
}
|
||||
|
||||
private void testLinks(TaskRepresentationModel resource) {
|
||||
assertThat(resource.getLinks()).hasSize(1);
|
||||
assertThat(resource.getRequiredLink("self").getHref())
|
||||
.isEqualTo(Mapping.URL_TASKS_ID.replaceAll("\\{.*}", resource.getTaskId()));
|
||||
private void testLinks(TaskRepresentationModel repModel) {
|
||||
assertThat(repModel.getLinks()).hasSize(1);
|
||||
assertThat(repModel.getRequiredLink("self").getHref())
|
||||
.isEqualTo(Mapping.URL_TASKS_ID.replaceAll("\\{.*}", repModel.getTaskId()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,159 +0,0 @@
|
|||
package pro.taskana.task.rest.assembler;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import org.junit.Assert;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import pro.taskana.classification.api.ClassificationService;
|
||||
import pro.taskana.classification.api.models.Classification;
|
||||
import pro.taskana.common.rest.TaskanaSpringBootTest;
|
||||
import pro.taskana.task.api.TaskService;
|
||||
import pro.taskana.task.api.TaskState;
|
||||
import pro.taskana.task.api.models.AttachmentSummary;
|
||||
import pro.taskana.task.api.models.ObjectReference;
|
||||
import pro.taskana.task.internal.models.AttachmentImpl;
|
||||
import pro.taskana.task.internal.models.TaskImpl;
|
||||
import pro.taskana.task.internal.models.TaskSummaryImpl;
|
||||
import pro.taskana.task.rest.models.AttachmentSummaryRepresentationModel;
|
||||
import pro.taskana.task.rest.models.TaskSummaryRepresentationModel;
|
||||
import pro.taskana.workbasket.api.WorkbasketService;
|
||||
import pro.taskana.workbasket.api.models.Workbasket;
|
||||
|
||||
@TaskanaSpringBootTest
|
||||
class TaskSummaryAssemblerTest {
|
||||
|
||||
TaskService taskService;
|
||||
TaskSummaryRepresentationModelAssembler taskSummaryRepresentationModelAssembler;
|
||||
WorkbasketService workbasketService;
|
||||
ClassificationService classificationService;
|
||||
|
||||
@Autowired
|
||||
TaskSummaryAssemblerTest(TaskService taskService,
|
||||
TaskSummaryRepresentationModelAssembler taskSummaryRepresentationModelAssembler,
|
||||
WorkbasketService workbasketService, ClassificationService classificationService) {
|
||||
this.taskService = taskService;
|
||||
this.taskSummaryRepresentationModelAssembler = taskSummaryRepresentationModelAssembler;
|
||||
this.workbasketService = workbasketService;
|
||||
this.classificationService = classificationService;
|
||||
}
|
||||
|
||||
@Test
|
||||
void taskSummaryToResource() {
|
||||
ObjectReference primaryObjRef = new ObjectReference();
|
||||
primaryObjRef.setId("abc");
|
||||
Classification classification =
|
||||
this.classificationService.newClassification("ckey", "cdomain", "MANUAL");
|
||||
AttachmentImpl attachment = (AttachmentImpl) this.taskService.newAttachment();
|
||||
attachment.setClassificationSummary(classification.asSummary());
|
||||
attachment.setId("attachmentId");
|
||||
TaskImpl task = (TaskImpl) this.taskService.newTask();
|
||||
task.setId("taskId");
|
||||
task.setExternalId("externalId");
|
||||
task.setCreated(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
task.setClaimed(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
task.setCompleted(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
task.setModified(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
task.setPlanned(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
task.setDue(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
task.setName("name");
|
||||
task.setCreator("creator");
|
||||
task.setDescription("desc");
|
||||
task.setNote("note");
|
||||
task.setPriority(123);
|
||||
task.setState(TaskState.READY);
|
||||
task.setClassificationSummary(classification);
|
||||
Workbasket workbasket = this.workbasketService.newWorkbasket("key", "domain");
|
||||
task.setWorkbasketSummary(workbasket.asSummary());
|
||||
task.setBusinessProcessId("businessProcessId");
|
||||
task.setParentBusinessProcessId("parentBusinessProcessId");
|
||||
task.setOwner("owner");
|
||||
task.setPrimaryObjRef(primaryObjRef);
|
||||
task.setRead(true);
|
||||
task.setTransferred(true);
|
||||
task.setCustomAttributes(Collections.singletonMap("abc", "def"));
|
||||
task.setCallbackInfo(Collections.singletonMap("ghi", "jkl"));
|
||||
task.setAttachments(Collections.singletonList(attachment));
|
||||
task.setCustom1("custom1");
|
||||
task.setCustom2("custom2");
|
||||
task.setCustom3("custom3");
|
||||
task.setCustom4("custom4");
|
||||
task.setCustom5("custom5");
|
||||
task.setCustom6("custom6");
|
||||
task.setCustom7("custom7");
|
||||
task.setCustom8("custom8");
|
||||
task.setCustom9("custom9");
|
||||
task.setCustom10("custom10");
|
||||
task.setCustom11("custom11");
|
||||
task.setCustom12("custom12");
|
||||
task.setCustom13("custom13");
|
||||
task.setCustom14("custom14");
|
||||
task.setCustom15("custom15");
|
||||
TaskSummaryImpl taskSummary = (TaskSummaryImpl) task.asSummary();
|
||||
TaskSummaryRepresentationModel resource =
|
||||
this.taskSummaryRepresentationModelAssembler.toModel(taskSummary);
|
||||
this.testEquality(taskSummary, resource);
|
||||
}
|
||||
|
||||
void testEquality(TaskSummaryImpl taskSummary, TaskSummaryRepresentationModel resource) {
|
||||
Assert.assertEquals(taskSummary.getId(), resource.getTaskId());
|
||||
Assert.assertEquals(taskSummary.getExternalId(), resource.getExternalId());
|
||||
Assert.assertEquals(taskSummary.getCreated(), resource.getCreated());
|
||||
Assert.assertEquals(taskSummary.getClaimed(), resource.getClaimed());
|
||||
Assert.assertEquals(taskSummary.getCompleted(), resource.getCompleted());
|
||||
Assert.assertEquals(taskSummary.getModified(), resource.getModified());
|
||||
Assert.assertEquals(taskSummary.getPlanned(), resource.getPlanned());
|
||||
Assert.assertEquals(taskSummary.getDescription(), resource.getDescription());
|
||||
Assert.assertEquals(taskSummary.getName(), resource.getName());
|
||||
Assert.assertEquals(taskSummary.getCreator(), resource.getCreator());
|
||||
Assert.assertEquals(taskSummary.getNote(), resource.getNote());
|
||||
Assert.assertEquals(taskSummary.getPriority(), resource.getPriority());
|
||||
Assert.assertEquals(taskSummary.getState(), resource.getState());
|
||||
Assert.assertEquals(
|
||||
taskSummary.getClassificationSummary().getId(),
|
||||
resource.getClassificationSummary().getClassificationId());
|
||||
Assert.assertEquals(
|
||||
taskSummary.getWorkbasketSummary().getId(),
|
||||
resource.getWorkbasketSummary().getWorkbasketId());
|
||||
Assert.assertEquals(taskSummary.getBusinessProcessId(), resource.getBusinessProcessId());
|
||||
Assert.assertEquals(
|
||||
taskSummary.getParentBusinessProcessId(), resource.getParentBusinessProcessId());
|
||||
Assert.assertEquals(taskSummary.getOwner(), resource.getOwner());
|
||||
Assert.assertEquals(taskSummary.getPrimaryObjRef(), resource.getPrimaryObjRef());
|
||||
Assert.assertEquals(taskSummary.isRead(), resource.isRead());
|
||||
Assert.assertEquals(taskSummary.isTransferred(), resource.isTransferred());
|
||||
Assert.assertEquals(taskSummary.getCustom1(), resource.getCustom1());
|
||||
Assert.assertEquals(taskSummary.getCustom2(), resource.getCustom2());
|
||||
Assert.assertEquals(taskSummary.getCustom3(), resource.getCustom3());
|
||||
Assert.assertEquals(taskSummary.getCustom4(), resource.getCustom4());
|
||||
Assert.assertEquals(taskSummary.getCustom5(), resource.getCustom5());
|
||||
Assert.assertEquals(taskSummary.getCustom6(), resource.getCustom6());
|
||||
Assert.assertEquals(taskSummary.getCustom7(), resource.getCustom7());
|
||||
Assert.assertEquals(taskSummary.getCustom8(), resource.getCustom8());
|
||||
Assert.assertEquals(taskSummary.getCustom9(), resource.getCustom9());
|
||||
Assert.assertEquals(taskSummary.getCustom10(), resource.getCustom10());
|
||||
Assert.assertEquals(taskSummary.getCustom11(), resource.getCustom11());
|
||||
Assert.assertEquals(taskSummary.getCustom12(), resource.getCustom12());
|
||||
Assert.assertEquals(taskSummary.getCustom13(), resource.getCustom13());
|
||||
Assert.assertEquals(taskSummary.getCustom14(), resource.getCustom14());
|
||||
Assert.assertEquals(taskSummary.getCustom15(), resource.getCustom15());
|
||||
Assert.assertEquals(taskSummary.getCustom16(), resource.getCustom16());
|
||||
|
||||
this.testEqualityAttachments(
|
||||
taskSummary.getAttachmentSummaries(), resource.getAttachmentSummaries());
|
||||
}
|
||||
|
||||
private void testEqualityAttachments(
|
||||
List<AttachmentSummary> attachmentSummaries,
|
||||
List<AttachmentSummaryRepresentationModel> resources) {
|
||||
Assert.assertEquals(attachmentSummaries.size(), resources.size());
|
||||
|
||||
for (int i = 0; i < resources.size(); ++i) {
|
||||
AttachmentSummaryRepresentationModel resource = resources.get(i);
|
||||
AttachmentSummary attachmentSummary = attachmentSummaries.get(i);
|
||||
Assert.assertEquals(attachmentSummary.getId(), resource.getAttachmentId());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,294 @@
|
|||
package pro.taskana.task.rest.assembler;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import pro.taskana.classification.api.ClassificationService;
|
||||
import pro.taskana.classification.api.models.ClassificationSummary;
|
||||
import pro.taskana.classification.rest.models.ClassificationSummaryRepresentationModel;
|
||||
import pro.taskana.common.api.exceptions.InvalidArgumentException;
|
||||
import pro.taskana.common.rest.TaskanaSpringBootTest;
|
||||
import pro.taskana.task.api.TaskService;
|
||||
import pro.taskana.task.api.TaskState;
|
||||
import pro.taskana.task.api.models.AttachmentSummary;
|
||||
import pro.taskana.task.api.models.ObjectReference;
|
||||
import pro.taskana.task.api.models.TaskSummary;
|
||||
import pro.taskana.task.internal.models.AttachmentSummaryImpl;
|
||||
import pro.taskana.task.internal.models.TaskSummaryImpl;
|
||||
import pro.taskana.task.rest.models.AttachmentRepresentationModel;
|
||||
import pro.taskana.task.rest.models.AttachmentSummaryRepresentationModel;
|
||||
import pro.taskana.task.rest.models.TaskRepresentationModel;
|
||||
import pro.taskana.task.rest.models.TaskSummaryRepresentationModel;
|
||||
import pro.taskana.workbasket.api.WorkbasketService;
|
||||
import pro.taskana.workbasket.api.models.WorkbasketSummary;
|
||||
import pro.taskana.workbasket.rest.models.WorkbasketSummaryRepresentationModel;
|
||||
|
||||
@TaskanaSpringBootTest
|
||||
class TaskSummaryRepresentationModelAssemblerTest {
|
||||
|
||||
private final TaskService taskService;
|
||||
private final WorkbasketService workbasketService;
|
||||
private final ClassificationService classificationService;
|
||||
private final TaskSummaryRepresentationModelAssembler assembler;
|
||||
|
||||
@Autowired
|
||||
TaskSummaryRepresentationModelAssemblerTest(
|
||||
TaskService taskService,
|
||||
TaskSummaryRepresentationModelAssembler assembler,
|
||||
WorkbasketService workbasketService,
|
||||
ClassificationService classificationService) {
|
||||
this.taskService = taskService;
|
||||
this.assembler = assembler;
|
||||
this.workbasketService = workbasketService;
|
||||
this.classificationService = classificationService;
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_ReturnRepresentationModel_When_ConvertingEntityToRepresentationModel()
|
||||
throws InvalidArgumentException {
|
||||
ObjectReference primaryObjRef = new ObjectReference();
|
||||
primaryObjRef.setId("abc");
|
||||
ClassificationSummary classification =
|
||||
this.classificationService.newClassification("ckey", "cdomain", "MANUAL").asSummary();
|
||||
AttachmentSummaryImpl attachment =
|
||||
(AttachmentSummaryImpl) this.taskService.newAttachment().asSummary();
|
||||
attachment.setClassificationSummary(classification);
|
||||
attachment.setId("attachmentId");
|
||||
final WorkbasketSummary workbasket =
|
||||
this.workbasketService.newWorkbasket("key", "domain").asSummary();
|
||||
TaskSummaryImpl task = (TaskSummaryImpl) this.taskService.newTask().asSummary();
|
||||
task.setAttachmentSummaries(Collections.singletonList(attachment));
|
||||
task.setClassificationSummary(classification);
|
||||
task.setWorkbasketSummary(workbasket);
|
||||
task.setId("taskId");
|
||||
task.setExternalId("externalId");
|
||||
task.setCreated(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
task.setClaimed(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
task.setCompleted(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
task.setModified(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
task.setPlanned(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
task.setDue(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
task.setName("name");
|
||||
task.setCreator("creator");
|
||||
task.setDescription("desc");
|
||||
task.setNote("note");
|
||||
task.setPriority(123);
|
||||
task.setState(TaskState.READY);
|
||||
task.setBusinessProcessId("businessProcessId");
|
||||
task.setParentBusinessProcessId("parentBusinessProcessId");
|
||||
task.setOwner("owner");
|
||||
task.setPrimaryObjRef(primaryObjRef);
|
||||
task.setRead(true);
|
||||
task.setTransferred(true);
|
||||
task.setCustom1("custom1");
|
||||
task.setCustom2("custom2");
|
||||
task.setCustom3("custom3");
|
||||
task.setCustom4("custom4");
|
||||
task.setCustom5("custom5");
|
||||
task.setCustom6("custom6");
|
||||
task.setCustom7("custom7");
|
||||
task.setCustom8("custom8");
|
||||
task.setCustom9("custom9");
|
||||
task.setCustom10("custom10");
|
||||
task.setCustom11("custom11");
|
||||
task.setCustom12("custom12");
|
||||
task.setCustom13("custom13");
|
||||
task.setCustom14("custom14");
|
||||
task.setCustom15("custom15");
|
||||
task.setCustom16("custom16");
|
||||
|
||||
TaskSummaryRepresentationModel repModel = assembler.toModel(task);
|
||||
|
||||
testEquality(task, repModel);
|
||||
testLinks(repModel);
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_ReturnEntity_When_ConvertingRepresentationModelToEntity()
|
||||
throws InvalidArgumentException {
|
||||
ObjectReference primaryObjRef = new ObjectReference();
|
||||
primaryObjRef.setId("abc");
|
||||
WorkbasketSummaryRepresentationModel workbasketResource =
|
||||
new WorkbasketSummaryRepresentationModel();
|
||||
workbasketResource.setWorkbasketId("workbasketId");
|
||||
ClassificationSummaryRepresentationModel classificationSummary =
|
||||
new ClassificationSummaryRepresentationModel();
|
||||
classificationSummary.setKey("keyabc");
|
||||
classificationSummary.setDomain("DOMAIN_A");
|
||||
classificationSummary.setType("MANUAL");
|
||||
AttachmentRepresentationModel attachment = new AttachmentRepresentationModel();
|
||||
attachment.setClassificationSummary(classificationSummary);
|
||||
attachment.setAttachmentId("attachmentId");
|
||||
TaskSummaryRepresentationModel repModel = new TaskRepresentationModel();
|
||||
repModel.setAttachmentSummaries(Collections.singletonList(attachment));
|
||||
repModel.setClassificationSummary(classificationSummary);
|
||||
repModel.setWorkbasketSummary(workbasketResource);
|
||||
repModel.setPrimaryObjRef(primaryObjRef);
|
||||
repModel.setTaskId("taskId");
|
||||
repModel.setExternalId("externalId");
|
||||
repModel.setCreated(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
repModel.setClaimed(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
repModel.setCompleted(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
repModel.setModified(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
repModel.setPlanned(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
repModel.setDue(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
repModel.setName("name");
|
||||
repModel.setCreator("creator");
|
||||
repModel.setDescription("desc");
|
||||
repModel.setNote("note");
|
||||
repModel.setPriority(123);
|
||||
repModel.setState(TaskState.READY);
|
||||
repModel.setBusinessProcessId("businessProcessId");
|
||||
repModel.setParentBusinessProcessId("parentBusinessProcessId");
|
||||
repModel.setOwner("owner");
|
||||
repModel.setRead(true);
|
||||
repModel.setTransferred(true);
|
||||
repModel.setCustom1("custom1");
|
||||
repModel.setCustom2("custom2");
|
||||
repModel.setCustom3("custom3");
|
||||
repModel.setCustom4("custom4");
|
||||
repModel.setCustom5("custom5");
|
||||
repModel.setCustom6("custom6");
|
||||
repModel.setCustom7("custom7");
|
||||
repModel.setCustom8("custom8");
|
||||
repModel.setCustom9("custom9");
|
||||
repModel.setCustom10("custom10");
|
||||
repModel.setCustom11("custom11");
|
||||
repModel.setCustom12("custom12");
|
||||
repModel.setCustom13("custom13");
|
||||
repModel.setCustom14("custom14");
|
||||
repModel.setCustom15("custom15");
|
||||
repModel.setCustom16("custom16");
|
||||
// when
|
||||
TaskSummary task = assembler.toEntityModel(repModel);
|
||||
// then
|
||||
testEquality(task, repModel);
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_Equal_When_ComparingEntityWithConvertedEntity() {
|
||||
// given
|
||||
ObjectReference primaryObjRef = new ObjectReference();
|
||||
primaryObjRef.setId("abc");
|
||||
final WorkbasketSummary workbasket =
|
||||
workbasketService.newWorkbasket("key", "domain").asSummary();
|
||||
ClassificationSummary classification =
|
||||
classificationService.newClassification("ckey", "cdomain", "MANUAL").asSummary();
|
||||
AttachmentSummaryImpl attachment =
|
||||
(AttachmentSummaryImpl) taskService.newAttachment().asSummary();
|
||||
attachment.setClassificationSummary(classification);
|
||||
attachment.setId("attachmentId");
|
||||
TaskSummaryImpl task = (TaskSummaryImpl) taskService.newTask().asSummary();
|
||||
task.setId("taskId");
|
||||
task.setExternalId("externalId");
|
||||
task.setCreated(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
task.setClaimed(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
task.setCompleted(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
task.setModified(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
task.setPlanned(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
task.setDue(Instant.parse("2019-09-13T08:44:17.588Z"));
|
||||
task.setName("name");
|
||||
task.setCreator("creator");
|
||||
task.setDescription("desc");
|
||||
task.setNote("note");
|
||||
task.setPriority(123);
|
||||
task.setState(TaskState.READY);
|
||||
task.setClassificationSummary(classification);
|
||||
task.setWorkbasketSummary(workbasket);
|
||||
task.setBusinessProcessId("businessProcessId");
|
||||
task.setParentBusinessProcessId("parentBusinessProcessId");
|
||||
task.setOwner("owner");
|
||||
task.setPrimaryObjRef(primaryObjRef);
|
||||
task.setRead(true);
|
||||
task.setTransferred(true);
|
||||
task.setCustom1("custom1");
|
||||
task.setCustom2("custom2");
|
||||
task.setCustom3("custom3");
|
||||
task.setCustom4("custom4");
|
||||
task.setCustom5("custom5");
|
||||
task.setCustom6("custom6");
|
||||
task.setCustom7("custom7");
|
||||
task.setCustom8("custom8");
|
||||
task.setCustom9("custom9");
|
||||
task.setCustom10("custom10");
|
||||
task.setCustom11("custom11");
|
||||
task.setCustom12("custom12");
|
||||
task.setCustom13("custom13");
|
||||
task.setCustom14("custom14");
|
||||
task.setCustom15("custom15");
|
||||
task.setCustom16("custom16");
|
||||
// when
|
||||
TaskSummaryRepresentationModel repModel = assembler.toModel(task);
|
||||
TaskSummary task2 = assembler.toEntityModel(repModel);
|
||||
// then
|
||||
assertThat(task).hasNoNullFieldsOrProperties().isNotSameAs(task2).isEqualTo(task2);
|
||||
}
|
||||
|
||||
static void testEquality(TaskSummary taskSummary, TaskSummaryRepresentationModel repModel)
|
||||
throws InvalidArgumentException {
|
||||
assertThat(taskSummary).hasNoNullFieldsOrProperties();
|
||||
assertThat(repModel).hasNoNullFieldsOrProperties();
|
||||
assertThat(taskSummary.getId()).isEqualTo(repModel.getTaskId());
|
||||
assertThat(taskSummary.getExternalId()).isEqualTo(repModel.getExternalId());
|
||||
assertThat(taskSummary.getCreated()).isEqualTo(repModel.getCreated());
|
||||
assertThat(taskSummary.getClaimed()).isEqualTo(repModel.getClaimed());
|
||||
assertThat(taskSummary.getCompleted()).isEqualTo(repModel.getCompleted());
|
||||
assertThat(taskSummary.getModified()).isEqualTo(repModel.getModified());
|
||||
assertThat(taskSummary.getPlanned()).isEqualTo(repModel.getPlanned());
|
||||
assertThat(taskSummary.getDue()).isEqualTo(repModel.getDue());
|
||||
assertThat(taskSummary.getName()).isEqualTo(repModel.getName());
|
||||
assertThat(taskSummary.getCreator()).isEqualTo(repModel.getCreator());
|
||||
assertThat(taskSummary.getNote()).isEqualTo(repModel.getNote());
|
||||
assertThat(taskSummary.getDescription()).isEqualTo(repModel.getDescription());
|
||||
assertThat(taskSummary.getPriority()).isEqualTo(repModel.getPriority());
|
||||
assertThat(taskSummary.getState()).isEqualTo(repModel.getState());
|
||||
assertThat(taskSummary.getClassificationSummary().getId())
|
||||
.isEqualTo(repModel.getClassificationSummary().getClassificationId());
|
||||
assertThat(taskSummary.getWorkbasketSummary().getId())
|
||||
.isEqualTo(repModel.getWorkbasketSummary().getWorkbasketId());
|
||||
assertThat(taskSummary.getBusinessProcessId()).isEqualTo(repModel.getBusinessProcessId());
|
||||
assertThat(taskSummary.getParentBusinessProcessId())
|
||||
.isEqualTo(repModel.getParentBusinessProcessId());
|
||||
assertThat(taskSummary.getOwner()).isEqualTo(repModel.getOwner());
|
||||
assertThat(taskSummary.getPrimaryObjRef()).isEqualTo(repModel.getPrimaryObjRef());
|
||||
assertThat(taskSummary.isRead()).isEqualTo(repModel.isRead());
|
||||
assertThat(taskSummary.isTransferred()).isEqualTo(repModel.isTransferred());
|
||||
assertThat(taskSummary.getCustomAttribute("1")).isEqualTo(repModel.getCustom1());
|
||||
assertThat(taskSummary.getCustomAttribute("2")).isEqualTo(repModel.getCustom2());
|
||||
assertThat(taskSummary.getCustomAttribute("3")).isEqualTo(repModel.getCustom3());
|
||||
assertThat(taskSummary.getCustomAttribute("4")).isEqualTo(repModel.getCustom4());
|
||||
assertThat(taskSummary.getCustomAttribute("5")).isEqualTo(repModel.getCustom5());
|
||||
assertThat(taskSummary.getCustomAttribute("6")).isEqualTo(repModel.getCustom6());
|
||||
assertThat(taskSummary.getCustomAttribute("7")).isEqualTo(repModel.getCustom7());
|
||||
assertThat(taskSummary.getCustomAttribute("8")).isEqualTo(repModel.getCustom8());
|
||||
assertThat(taskSummary.getCustomAttribute("9")).isEqualTo(repModel.getCustom9());
|
||||
assertThat(taskSummary.getCustomAttribute("10")).isEqualTo(repModel.getCustom10());
|
||||
assertThat(taskSummary.getCustomAttribute("11")).isEqualTo(repModel.getCustom11());
|
||||
assertThat(taskSummary.getCustomAttribute("12")).isEqualTo(repModel.getCustom12());
|
||||
assertThat(taskSummary.getCustomAttribute("13")).isEqualTo(repModel.getCustom13());
|
||||
assertThat(taskSummary.getCustomAttribute("14")).isEqualTo(repModel.getCustom14());
|
||||
assertThat(taskSummary.getCustomAttribute("15")).isEqualTo(repModel.getCustom15());
|
||||
assertThat(taskSummary.getCustomAttribute("16")).isEqualTo(repModel.getCustom16());
|
||||
testEqualityAttachments(
|
||||
taskSummary.getAttachmentSummaries(), repModel.getAttachmentSummaries());
|
||||
}
|
||||
|
||||
private static void testEqualityAttachments(
|
||||
List<AttachmentSummary> attachmentSummaries,
|
||||
List<AttachmentSummaryRepresentationModel> resources) {
|
||||
assertThat(attachmentSummaries.size()).isEqualTo(resources.size());
|
||||
|
||||
for (int i = 0; i < resources.size(); ++i) {
|
||||
AttachmentSummaryRepresentationModel resource = resources.get(i);
|
||||
AttachmentSummary attachmentSummary = attachmentSummaries.get(i);
|
||||
assertThat(attachmentSummary.getId()).isEqualTo(resource.getAttachmentId());
|
||||
}
|
||||
}
|
||||
|
||||
private void testLinks(TaskSummaryRepresentationModel repModel) {}
|
||||
}
|
|
@ -15,16 +15,25 @@ import pro.taskana.workbasket.rest.models.WorkbasketAccessItemRepresentationMode
|
|||
@TaskanaSpringBootTest
|
||||
class WorkbasketAccessItemRepresentationModelAssemblerTest {
|
||||
|
||||
@Autowired
|
||||
WorkbasketAccessItemRepresentationModelAssembler workbasketAccessItemRepresentationModelAssembler;
|
||||
private final WorkbasketAccessItemRepresentationModelAssembler assembler;
|
||||
private final WorkbasketService workbasketService;
|
||||
|
||||
@Autowired WorkbasketService workbasketService;
|
||||
@Autowired
|
||||
WorkbasketAccessItemRepresentationModelAssemblerTest(
|
||||
WorkbasketAccessItemRepresentationModelAssembler assembler,
|
||||
WorkbasketService workbasketService) {
|
||||
this.assembler = assembler;
|
||||
this.workbasketService = workbasketService;
|
||||
}
|
||||
|
||||
@Test
|
||||
void workBasketAccessItemToResourcePropertiesEqual() {
|
||||
void should_ReturnRepresentationModel_When_ConvertingEntityToRepresentationModel() {
|
||||
// given
|
||||
WorkbasketAccessItem accessItem = workbasketService.newWorkbasketAccessItem("1", "2");
|
||||
((WorkbasketAccessItemImpl) accessItem).setWorkbasketKey("workbasketKey");
|
||||
WorkbasketAccessItemImpl accessItem =
|
||||
(WorkbasketAccessItemImpl) workbasketService.newWorkbasketAccessItem("1", "2");
|
||||
accessItem.setId("id");
|
||||
accessItem.setAccessName("accessName");
|
||||
accessItem.setWorkbasketKey("workbasketKey");
|
||||
accessItem.setPermDistribute(false);
|
||||
accessItem.setPermOpen(true);
|
||||
accessItem.setPermAppend(false);
|
||||
|
@ -43,67 +52,107 @@ class WorkbasketAccessItemRepresentationModelAssemblerTest {
|
|||
accessItem.setPermCustom11(true);
|
||||
accessItem.setPermCustom12(true);
|
||||
// when
|
||||
WorkbasketAccessItemRepresentationModel resource =
|
||||
workbasketAccessItemRepresentationModelAssembler.toModel(accessItem);
|
||||
WorkbasketAccessItemRepresentationModel repModel = assembler.toModel(accessItem);
|
||||
// then
|
||||
testEquality(accessItem, resource);
|
||||
testEquality(accessItem, repModel);
|
||||
testLinks(repModel);
|
||||
}
|
||||
|
||||
@Test
|
||||
void workBasketAccessItemToModelPropertiesEqual() {
|
||||
void should_Equal_When_ComparingEntityWithConvertedEntity() {
|
||||
// given
|
||||
WorkbasketAccessItemRepresentationModel resource =
|
||||
new WorkbasketAccessItemRepresentationModel();
|
||||
resource.setAccessId("10");
|
||||
resource.setWorkbasketKey("workbasketKey");
|
||||
resource.setAccessItemId("120");
|
||||
resource.setWorkbasketId("1");
|
||||
resource.setPermRead(true);
|
||||
resource.setPermAppend(false);
|
||||
resource.setPermDistribute(false);
|
||||
resource.setPermOpen(false);
|
||||
resource.setPermTransfer(true);
|
||||
resource.setPermCustom1(false);
|
||||
resource.setPermCustom2(false);
|
||||
resource.setPermCustom3(false);
|
||||
resource.setPermCustom4(false);
|
||||
resource.setPermCustom5(true);
|
||||
resource.setPermCustom6(false);
|
||||
resource.setPermCustom7(false);
|
||||
resource.setPermCustom8(false);
|
||||
resource.setPermCustom9(false);
|
||||
resource.setPermCustom10(false);
|
||||
resource.setPermCustom11(true);
|
||||
resource.setPermCustom12(false);
|
||||
WorkbasketAccessItemImpl accessItem =
|
||||
(WorkbasketAccessItemImpl) workbasketService.newWorkbasketAccessItem("1", "2");
|
||||
accessItem.setId("accessItemId");
|
||||
accessItem.setWorkbasketKey("workbasketKey");
|
||||
accessItem.setPermDistribute(false);
|
||||
accessItem.setAccessName("accessName");
|
||||
accessItem.setPermOpen(true);
|
||||
accessItem.setPermAppend(false);
|
||||
accessItem.setPermRead(false);
|
||||
accessItem.setPermTransfer(true);
|
||||
accessItem.setPermCustom1(false);
|
||||
accessItem.setPermCustom2(false);
|
||||
accessItem.setPermCustom3(true);
|
||||
accessItem.setPermCustom4(true);
|
||||
accessItem.setPermCustom5(true);
|
||||
accessItem.setPermCustom6(true);
|
||||
accessItem.setPermCustom7(true);
|
||||
accessItem.setPermCustom8(true);
|
||||
accessItem.setPermCustom9(true);
|
||||
accessItem.setPermCustom10(true);
|
||||
accessItem.setPermCustom11(true);
|
||||
accessItem.setPermCustom12(true);
|
||||
// when
|
||||
WorkbasketAccessItem accessItem =
|
||||
workbasketAccessItemRepresentationModelAssembler.toEntityModel(resource);
|
||||
WorkbasketAccessItemRepresentationModel repModel = assembler.toModel(accessItem);
|
||||
WorkbasketAccessItem accessItem2 = assembler.toEntityModel(repModel);
|
||||
// then
|
||||
testEquality(accessItem, resource);
|
||||
assertThat(accessItem)
|
||||
.hasNoNullFieldsOrProperties()
|
||||
.isNotSameAs(accessItem2)
|
||||
.isEqualTo(accessItem2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_ReturnEntity_When_ConvertingRepresentationModelToEntity() {
|
||||
// given
|
||||
WorkbasketAccessItemRepresentationModel repModel =
|
||||
new WorkbasketAccessItemRepresentationModel();
|
||||
repModel.setAccessId("10");
|
||||
repModel.setWorkbasketKey("workbasketKey");
|
||||
repModel.setAccessItemId("120");
|
||||
repModel.setWorkbasketId("1");
|
||||
repModel.setAccessName("accessName");
|
||||
repModel.setPermRead(true);
|
||||
repModel.setPermAppend(false);
|
||||
repModel.setPermDistribute(false);
|
||||
repModel.setPermOpen(false);
|
||||
repModel.setPermTransfer(true);
|
||||
repModel.setPermCustom1(false);
|
||||
repModel.setPermCustom2(false);
|
||||
repModel.setPermCustom3(false);
|
||||
repModel.setPermCustom4(false);
|
||||
repModel.setPermCustom5(true);
|
||||
repModel.setPermCustom6(false);
|
||||
repModel.setPermCustom7(false);
|
||||
repModel.setPermCustom8(false);
|
||||
repModel.setPermCustom9(false);
|
||||
repModel.setPermCustom10(false);
|
||||
repModel.setPermCustom11(true);
|
||||
repModel.setPermCustom12(false);
|
||||
// when
|
||||
WorkbasketAccessItem accessItem = assembler.toEntityModel(repModel);
|
||||
// then
|
||||
testEquality(accessItem, repModel);
|
||||
}
|
||||
|
||||
private void testEquality(
|
||||
WorkbasketAccessItem accessItem, WorkbasketAccessItemRepresentationModel resource) {
|
||||
assertThat(resource.getAccessId()).isEqualTo(accessItem.getAccessId());
|
||||
assertThat(resource.getWorkbasketKey()).isEqualTo(accessItem.getWorkbasketKey());
|
||||
assertThat(resource.getAccessItemId()).isEqualTo(accessItem.getId());
|
||||
assertThat(resource.getWorkbasketId()).isEqualTo(accessItem.getWorkbasketId());
|
||||
assertThat(resource.isPermAppend()).isEqualTo(accessItem.isPermAppend());
|
||||
assertThat(resource.isPermCustom1()).isEqualTo(accessItem.isPermCustom1());
|
||||
assertThat(resource.isPermCustom2()).isEqualTo(accessItem.isPermCustom2());
|
||||
assertThat(resource.isPermCustom3()).isEqualTo(accessItem.isPermCustom3());
|
||||
assertThat(resource.isPermCustom4()).isEqualTo(accessItem.isPermCustom4());
|
||||
assertThat(resource.isPermCustom5()).isEqualTo(accessItem.isPermCustom5());
|
||||
assertThat(resource.isPermCustom6()).isEqualTo(accessItem.isPermCustom6());
|
||||
assertThat(resource.isPermCustom7()).isEqualTo(accessItem.isPermCustom7());
|
||||
assertThat(resource.isPermCustom8()).isEqualTo(accessItem.isPermCustom8());
|
||||
assertThat(resource.isPermCustom9()).isEqualTo(accessItem.isPermCustom9());
|
||||
assertThat(resource.isPermCustom10()).isEqualTo(accessItem.isPermCustom10());
|
||||
assertThat(resource.isPermCustom11()).isEqualTo(accessItem.isPermCustom11());
|
||||
assertThat(resource.isPermCustom12()).isEqualTo(accessItem.isPermCustom12());
|
||||
assertThat(resource.isPermDistribute()).isEqualTo(accessItem.isPermDistribute());
|
||||
assertThat(resource.isPermRead()).isEqualTo(accessItem.isPermRead());
|
||||
assertThat(resource.isPermOpen()).isEqualTo(accessItem.isPermOpen());
|
||||
assertThat(resource.isPermTransfer()).isEqualTo(accessItem.isPermTransfer());
|
||||
WorkbasketAccessItem accessItem, WorkbasketAccessItemRepresentationModel repModel) {
|
||||
assertThat(accessItem).hasNoNullFieldsOrProperties();
|
||||
assertThat(repModel).hasNoNullFieldsOrProperties();
|
||||
assertThat(repModel.getAccessItemId()).isEqualTo(accessItem.getId());
|
||||
assertThat(repModel.getWorkbasketId()).isEqualTo(accessItem.getWorkbasketId());
|
||||
assertThat(repModel.getWorkbasketKey()).isEqualTo(accessItem.getWorkbasketKey());
|
||||
assertThat(repModel.getAccessId()).isEqualTo(accessItem.getAccessId());
|
||||
assertThat(repModel.getAccessName()).isEqualTo(accessItem.getAccessName());
|
||||
assertThat(repModel.isPermRead()).isEqualTo(accessItem.isPermRead());
|
||||
assertThat(repModel.isPermOpen()).isEqualTo(accessItem.isPermOpen());
|
||||
assertThat(repModel.isPermAppend()).isEqualTo(accessItem.isPermAppend());
|
||||
assertThat(repModel.isPermTransfer()).isEqualTo(accessItem.isPermTransfer());
|
||||
assertThat(repModel.isPermDistribute()).isEqualTo(accessItem.isPermDistribute());
|
||||
assertThat(repModel.isPermCustom1()).isEqualTo(accessItem.isPermCustom1());
|
||||
assertThat(repModel.isPermCustom2()).isEqualTo(accessItem.isPermCustom2());
|
||||
assertThat(repModel.isPermCustom3()).isEqualTo(accessItem.isPermCustom3());
|
||||
assertThat(repModel.isPermCustom4()).isEqualTo(accessItem.isPermCustom4());
|
||||
assertThat(repModel.isPermCustom5()).isEqualTo(accessItem.isPermCustom5());
|
||||
assertThat(repModel.isPermCustom6()).isEqualTo(accessItem.isPermCustom6());
|
||||
assertThat(repModel.isPermCustom7()).isEqualTo(accessItem.isPermCustom7());
|
||||
assertThat(repModel.isPermCustom8()).isEqualTo(accessItem.isPermCustom8());
|
||||
assertThat(repModel.isPermCustom9()).isEqualTo(accessItem.isPermCustom9());
|
||||
assertThat(repModel.isPermCustom10()).isEqualTo(accessItem.isPermCustom10());
|
||||
assertThat(repModel.isPermCustom11()).isEqualTo(accessItem.isPermCustom11());
|
||||
assertThat(repModel.isPermCustom12()).isEqualTo(accessItem.isPermCustom12());
|
||||
}
|
||||
|
||||
private void testLinks(WorkbasketAccessItemRepresentationModel repModel) {}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
package pro.taskana.workbasket.rest.assembler;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.times;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InOrder;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.mock.mockito.SpyBean;
|
||||
|
||||
import pro.taskana.common.api.exceptions.NotAuthorizedException;
|
||||
import pro.taskana.common.rest.TaskanaSpringBootTest;
|
||||
import pro.taskana.workbasket.api.WorkbasketService;
|
||||
import pro.taskana.workbasket.api.exceptions.WorkbasketNotFoundException;
|
||||
import pro.taskana.workbasket.api.models.WorkbasketAccessItem;
|
||||
import pro.taskana.workbasket.api.models.WorkbasketSummary;
|
||||
import pro.taskana.workbasket.internal.models.WorkbasketImpl;
|
||||
import pro.taskana.workbasket.rest.models.WorkbasketDefinitionRepresentationModel;
|
||||
|
||||
/** Test for {@link WorkbasketDefinitionRepresentationModelAssembler}. */
|
||||
@TaskanaSpringBootTest
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class WorkbasketDefinitionRepresentationModelAssemblerTest {
|
||||
|
||||
private final WorkbasketDefinitionRepresentationModelAssembler assembler;
|
||||
@SpyBean private WorkbasketService workbasketService;
|
||||
@SpyBean private WorkbasketAccessItemRepresentationModelAssembler accessItemAssembler;
|
||||
@SpyBean private WorkbasketRepresentationModelAssembler workbasketAssembler;
|
||||
|
||||
@Autowired
|
||||
WorkbasketDefinitionRepresentationModelAssemblerTest(
|
||||
WorkbasketDefinitionRepresentationModelAssembler assembler) {
|
||||
this.assembler = assembler;
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_ReturnDefinitionEntity_When_ConvertingWorkbasketToDefinition()
|
||||
throws NotAuthorizedException, WorkbasketNotFoundException {
|
||||
WorkbasketImpl workbasket = (WorkbasketImpl) workbasketService.newWorkbasket("1", "DOMAIN_A");
|
||||
String id = "ID1";
|
||||
workbasket.setId(id);
|
||||
List<WorkbasketAccessItem> workbasketAccessItems =
|
||||
Arrays.asList(
|
||||
workbasketService.newWorkbasketAccessItem(id, "a"),
|
||||
workbasketService.newWorkbasketAccessItem(id, "b"));
|
||||
|
||||
WorkbasketImpl target1 = (WorkbasketImpl) workbasketService.newWorkbasket("2", "DOMAIN_A");
|
||||
WorkbasketImpl target2 = (WorkbasketImpl) workbasketService.newWorkbasket("3", "DOMAIN_A");
|
||||
target1.setId("target1");
|
||||
target2.setId("target2");
|
||||
List<WorkbasketSummary> workbasketSummaries = Arrays.asList(target1, target2);
|
||||
|
||||
Mockito.doReturn(workbasketAccessItems).when(workbasketService).getWorkbasketAccessItems(id);
|
||||
Mockito.doReturn(workbasketSummaries).when(workbasketService).getDistributionTargets(id);
|
||||
|
||||
Object[] mocks = {workbasketService, workbasketAssembler, accessItemAssembler};
|
||||
Mockito.clearInvocations(mocks);
|
||||
|
||||
WorkbasketDefinitionRepresentationModel repModel = assembler.toModel(workbasket);
|
||||
|
||||
assertThat(repModel).isNotNull();
|
||||
// workbasketAssembler does the conversion. Thus no further testing needed.
|
||||
assertThat(repModel.getWorkbasket()).isNotNull();
|
||||
// accessItemAssembler does the conversion. Thus no further testing needed.
|
||||
assertThat(repModel.getAuthorizations()).hasSize(2);
|
||||
assertThat(repModel.getDistributionTargets()).containsOnlyOnce("target1", "target2");
|
||||
InOrder inOrder = Mockito.inOrder(mocks);
|
||||
inOrder.verify(workbasketAssembler).toModel(workbasket);
|
||||
inOrder.verify(workbasketService).getWorkbasketAccessItems(id);
|
||||
inOrder.verify(accessItemAssembler).toCollectionModel(workbasketAccessItems);
|
||||
inOrder.verify(accessItemAssembler, times(2)).toModel(any());
|
||||
inOrder.verify(workbasketService).getDistributionTargets(id);
|
||||
inOrder.verifyNoMoreInteractions();
|
||||
Mockito.verifyNoMoreInteractions(mocks);
|
||||
}
|
||||
}
|
|
@ -30,10 +30,10 @@ class WorkbasketRepresentationModelAssemblerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
void workbasketToResource() {
|
||||
void should_ReturnRepresentationModel_When_ConvertingEntityToRepresentationModel() {
|
||||
// given
|
||||
Workbasket workbasket = workbasketService.newWorkbasket("1", "DOMAIN_A");
|
||||
((WorkbasketImpl) workbasket).setId("ID");
|
||||
WorkbasketImpl workbasket = (WorkbasketImpl) workbasketService.newWorkbasket("1", "DOMAIN_A");
|
||||
workbasket.setId("ID");
|
||||
workbasket.setType(WorkbasketType.PERSONAL);
|
||||
workbasket.setName("Testbasket");
|
||||
workbasket.setOrgLevel1("Org1");
|
||||
|
@ -46,44 +46,18 @@ class WorkbasketRepresentationModelAssemblerTest {
|
|||
workbasket.setCustom3("3");
|
||||
workbasket.setCustom4("4");
|
||||
workbasket.setOwner("Lars");
|
||||
((WorkbasketImpl) workbasket).setCreated(Instant.parse("2010-01-01T12:00:00Z"));
|
||||
((WorkbasketImpl) workbasket).setModified(Instant.parse("2010-01-01T12:00:00Z"));
|
||||
workbasket.setCreated(Instant.parse("2010-01-01T12:00:00Z"));
|
||||
workbasket.setModified(Instant.parse("2010-01-01T12:00:00Z"));
|
||||
// when
|
||||
WorkbasketRepresentationModel resource =
|
||||
WorkbasketRepresentationModel repModel =
|
||||
workbasketRepresentationModelAssembler.toModel(workbasket);
|
||||
// then
|
||||
testEquality(workbasket, resource);
|
||||
verifyLinks(resource);
|
||||
testEquality(workbasket, repModel);
|
||||
testLinks(repModel);
|
||||
}
|
||||
|
||||
@Test
|
||||
void resourceWithoutCreated() {
|
||||
// given
|
||||
WorkbasketRepresentationModel resource = new WorkbasketRepresentationModel();
|
||||
resource.setWorkbasketId("1");
|
||||
resource.setModified(Instant.parse("2010-01-01T12:00:00Z"));
|
||||
resource.setType(WorkbasketType.PERSONAL);
|
||||
// when
|
||||
Workbasket workbasket = workbasketRepresentationModelAssembler.toEntityModel(resource);
|
||||
// then
|
||||
testEquality(workbasket, resource);
|
||||
}
|
||||
|
||||
@Test
|
||||
void resourceWithoutModified() {
|
||||
// given
|
||||
WorkbasketRepresentationModel resource = new WorkbasketRepresentationModel();
|
||||
resource.setWorkbasketId("1");
|
||||
resource.setCreated(Instant.parse("2010-01-01T12:00:00Z"));
|
||||
resource.setType(WorkbasketType.PERSONAL);
|
||||
// when
|
||||
Workbasket workbasket = workbasketRepresentationModelAssembler.toEntityModel(resource);
|
||||
// then
|
||||
testEquality(workbasket, resource);
|
||||
}
|
||||
|
||||
@Test
|
||||
void resourceToWorkbasket() {
|
||||
void should_ReturnEntity_When_ConvertingRepresentationModelToEntity() {
|
||||
// given
|
||||
WorkbasketRepresentationModel workbasketRepresentationModel =
|
||||
new WorkbasketRepresentationModel();
|
||||
|
@ -111,7 +85,36 @@ class WorkbasketRepresentationModelAssemblerTest {
|
|||
testEquality(workbasket, workbasketRepresentationModel);
|
||||
}
|
||||
|
||||
private void verifyLinks(WorkbasketRepresentationModel workbasket) {
|
||||
@Test
|
||||
void should_Equal_When_ComparingEntityWithConvertedEntity() {
|
||||
WorkbasketImpl workbasket = (WorkbasketImpl) workbasketService.newWorkbasket("1", "DOMAIN_A");
|
||||
workbasket.setId("ID");
|
||||
workbasket.setType(WorkbasketType.PERSONAL);
|
||||
workbasket.setName("Testbasket");
|
||||
workbasket.setOrgLevel1("Org1");
|
||||
workbasket.setOrgLevel2("Org2");
|
||||
workbasket.setOrgLevel3("Org3");
|
||||
workbasket.setOrgLevel4("Org4");
|
||||
workbasket.setDescription("A test workbasket");
|
||||
workbasket.setCustom1("1");
|
||||
workbasket.setCustom2("2");
|
||||
workbasket.setCustom3("3");
|
||||
workbasket.setCustom4("4");
|
||||
workbasket.setOwner("Lars");
|
||||
workbasket.setCreated(Instant.parse("2010-01-01T12:00:00Z"));
|
||||
workbasket.setModified(Instant.parse("2010-01-01T12:00:00Z"));
|
||||
// when
|
||||
WorkbasketRepresentationModel repModel =
|
||||
workbasketRepresentationModelAssembler.toModel(workbasket);
|
||||
Workbasket workbasket2 = workbasketRepresentationModelAssembler.toEntityModel(repModel);
|
||||
|
||||
assertThat(workbasket)
|
||||
.hasNoNullFieldsOrProperties()
|
||||
.isNotSameAs(workbasket2)
|
||||
.isEqualTo(workbasket2);
|
||||
}
|
||||
|
||||
private void testLinks(WorkbasketRepresentationModel workbasket) {
|
||||
assertThat(workbasket.getLinks()).hasSize(5);
|
||||
assertThat(workbasket.getRequiredLink("self").getHref())
|
||||
.isEqualTo(Mapping.URL_WORKBASKET_ID.replaceAll("\\{.*}", workbasket.getWorkbasketId()));
|
||||
|
@ -127,27 +130,10 @@ class WorkbasketRepresentationModelAssemblerTest {
|
|||
"\\{.*}", workbasket.getWorkbasketId()));
|
||||
}
|
||||
|
||||
private void testEquality(
|
||||
Workbasket workbasket, WorkbasketRepresentationModel workbasketRepresentationModel) {
|
||||
assertThat(workbasketRepresentationModel.getWorkbasketId()).isEqualTo(workbasket.getId());
|
||||
assertThat(workbasketRepresentationModel.getKey()).isEqualTo(workbasket.getKey());
|
||||
assertThat(workbasketRepresentationModel.getCreated())
|
||||
.isEqualTo(workbasket.getCreated());
|
||||
assertThat(workbasketRepresentationModel.getModified())
|
||||
.isEqualTo(workbasket.getModified());
|
||||
assertThat(workbasketRepresentationModel.getName()).isEqualTo(workbasket.getName());
|
||||
assertThat(workbasketRepresentationModel.getDescription())
|
||||
.isEqualTo(workbasket.getDescription());
|
||||
assertThat(workbasketRepresentationModel.getOwner()).isEqualTo(workbasket.getOwner());
|
||||
assertThat(workbasketRepresentationModel.getDomain()).isEqualTo(workbasket.getDomain());
|
||||
assertThat(workbasketRepresentationModel.getType()).isEqualTo(workbasket.getType());
|
||||
assertThat(workbasketRepresentationModel.getCustom1()).isEqualTo(workbasket.getCustom1());
|
||||
assertThat(workbasketRepresentationModel.getCustom2()).isEqualTo(workbasket.getCustom2());
|
||||
assertThat(workbasketRepresentationModel.getCustom3()).isEqualTo(workbasket.getCustom3());
|
||||
assertThat(workbasketRepresentationModel.getCustom4()).isEqualTo(workbasket.getCustom4());
|
||||
assertThat(workbasketRepresentationModel.getOrgLevel1()).isEqualTo(workbasket.getOrgLevel1());
|
||||
assertThat(workbasketRepresentationModel.getOrgLevel2()).isEqualTo(workbasket.getOrgLevel2());
|
||||
assertThat(workbasketRepresentationModel.getOrgLevel3()).isEqualTo(workbasket.getOrgLevel3());
|
||||
assertThat(workbasketRepresentationModel.getOrgLevel4()).isEqualTo(workbasket.getOrgLevel4());
|
||||
private void testEquality(Workbasket workbasket, WorkbasketRepresentationModel repModel) {
|
||||
WorkbasketSummaryRepresentationModelAssemblerTest.testEquality(workbasket, repModel);
|
||||
|
||||
assertThat(repModel.getCreated()).isEqualTo(workbasket.getCreated());
|
||||
assertThat(repModel.getModified()).isEqualTo(workbasket.getModified());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,77 +0,0 @@
|
|||
package pro.taskana.workbasket.rest.assembler;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import pro.taskana.common.rest.TaskanaSpringBootTest;
|
||||
import pro.taskana.workbasket.api.WorkbasketService;
|
||||
import pro.taskana.workbasket.api.WorkbasketType;
|
||||
import pro.taskana.workbasket.internal.models.WorkbasketSummaryImpl;
|
||||
import pro.taskana.workbasket.rest.models.WorkbasketSummaryRepresentationModel;
|
||||
|
||||
/**
|
||||
* Test for {@link WorkbasketSummaryRepresentationModelAssembler}.
|
||||
*/
|
||||
@TaskanaSpringBootTest
|
||||
class WorkbasketSummaryAssemblerTest {
|
||||
|
||||
@Autowired
|
||||
WorkbasketSummaryRepresentationModelAssembler
|
||||
workbasketSummaryRepresentationModelAssembler;
|
||||
@Autowired
|
||||
WorkbasketService workbasketService;
|
||||
|
||||
@Test
|
||||
void workbasketSummaryToResource() {
|
||||
// given
|
||||
WorkbasketSummaryImpl workbasketSummary =
|
||||
(WorkbasketSummaryImpl) workbasketService.newWorkbasket("1", "DOMAIN_A").asSummary();
|
||||
workbasketSummary.setDescription("WorkbasketSummaryImplTes");
|
||||
workbasketSummary.setId("1");
|
||||
workbasketSummary.setName("WorkbasketSummary");
|
||||
workbasketSummary.setCustom1("custom1");
|
||||
workbasketSummary.setCustom2("custom2");
|
||||
workbasketSummary.setCustom3("custom3");
|
||||
workbasketSummary.setCustom4("custom4");
|
||||
workbasketSummary.setOrgLevel1("Org1");
|
||||
workbasketSummary.setOrgLevel2("Org2");
|
||||
workbasketSummary.setOrgLevel3("Org3");
|
||||
workbasketSummary.setOrgLevel4("Org4");
|
||||
workbasketSummary.setOwner("Lars");
|
||||
workbasketSummary.setType(WorkbasketType.PERSONAL);
|
||||
// when
|
||||
WorkbasketSummaryRepresentationModel workbasketSummaryRepresentationModel =
|
||||
workbasketSummaryRepresentationModelAssembler.toModel(workbasketSummary);
|
||||
// then
|
||||
Assert.assertEquals(
|
||||
workbasketSummary.getDescription(), workbasketSummaryRepresentationModel.getDescription());
|
||||
Assert.assertEquals(
|
||||
workbasketSummary.getDomain(), workbasketSummaryRepresentationModel.getDomain());
|
||||
Assert.assertEquals(
|
||||
workbasketSummary.getId(), workbasketSummaryRepresentationModel.getWorkbasketId());
|
||||
Assert.assertEquals(workbasketSummary.getKey(), workbasketSummaryRepresentationModel.getKey());
|
||||
Assert.assertEquals(
|
||||
workbasketSummary.getName(), workbasketSummaryRepresentationModel.getName());
|
||||
Assert.assertEquals(
|
||||
workbasketSummary.getCustom1(), workbasketSummaryRepresentationModel.getCustom1());
|
||||
Assert.assertEquals(
|
||||
workbasketSummary.getCustom2(), workbasketSummaryRepresentationModel.getCustom2());
|
||||
Assert.assertEquals(
|
||||
workbasketSummary.getCustom3(), workbasketSummaryRepresentationModel.getCustom3());
|
||||
Assert.assertEquals(
|
||||
workbasketSummary.getCustom4(), workbasketSummaryRepresentationModel.getCustom4());
|
||||
Assert.assertEquals(
|
||||
workbasketSummary.getOrgLevel1(), workbasketSummaryRepresentationModel.getOrgLevel1());
|
||||
Assert.assertEquals(
|
||||
workbasketSummary.getOrgLevel2(), workbasketSummaryRepresentationModel.getOrgLevel2());
|
||||
Assert.assertEquals(
|
||||
workbasketSummary.getOrgLevel3(), workbasketSummaryRepresentationModel.getOrgLevel3());
|
||||
Assert.assertEquals(
|
||||
workbasketSummary.getOrgLevel4(), workbasketSummaryRepresentationModel.getOrgLevel4());
|
||||
Assert.assertEquals(
|
||||
workbasketSummary.getOwner(), workbasketSummaryRepresentationModel.getOwner());
|
||||
Assert.assertEquals(
|
||||
workbasketSummary.getType(), workbasketSummaryRepresentationModel.getType());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,130 @@
|
|||
package pro.taskana.workbasket.rest.assembler;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import pro.taskana.common.rest.TaskanaSpringBootTest;
|
||||
import pro.taskana.workbasket.api.WorkbasketService;
|
||||
import pro.taskana.workbasket.api.WorkbasketType;
|
||||
import pro.taskana.workbasket.api.models.WorkbasketSummary;
|
||||
import pro.taskana.workbasket.internal.models.WorkbasketSummaryImpl;
|
||||
import pro.taskana.workbasket.rest.models.WorkbasketSummaryRepresentationModel;
|
||||
|
||||
/** Test for {@link WorkbasketSummaryRepresentationModelAssembler}. */
|
||||
@TaskanaSpringBootTest
|
||||
class WorkbasketSummaryRepresentationModelAssemblerTest {
|
||||
|
||||
private final WorkbasketSummaryRepresentationModelAssembler assembler;
|
||||
|
||||
private final WorkbasketService workbasketService;
|
||||
|
||||
@Autowired
|
||||
WorkbasketSummaryRepresentationModelAssemblerTest(
|
||||
WorkbasketSummaryRepresentationModelAssembler assembler,
|
||||
WorkbasketService workbasketService) {
|
||||
this.assembler = assembler;
|
||||
this.workbasketService = workbasketService;
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_ReturnRepresentationModel_When_ConvertingEntityToRepresentationModel() {
|
||||
// given
|
||||
WorkbasketSummaryImpl workbasketSummary =
|
||||
(WorkbasketSummaryImpl) workbasketService.newWorkbasket("1", "DOMAIN_A").asSummary();
|
||||
workbasketSummary.setDescription("WorkbasketSummaryImplTes");
|
||||
workbasketSummary.setId("1");
|
||||
workbasketSummary.setName("WorkbasketSummary");
|
||||
workbasketSummary.setCustom1("custom1");
|
||||
workbasketSummary.setCustom2("custom2");
|
||||
workbasketSummary.setCustom3("custom3");
|
||||
workbasketSummary.setCustom4("custom4");
|
||||
workbasketSummary.setOrgLevel1("Org1");
|
||||
workbasketSummary.setOrgLevel2("Org2");
|
||||
workbasketSummary.setOrgLevel3("Org3");
|
||||
workbasketSummary.setOrgLevel4("Org4");
|
||||
workbasketSummary.setOwner("Lars");
|
||||
workbasketSummary.setType(WorkbasketType.PERSONAL);
|
||||
// when
|
||||
WorkbasketSummaryRepresentationModel repModel = assembler.toModel(workbasketSummary);
|
||||
// then
|
||||
testEquality(workbasketSummary, repModel);
|
||||
testLinks(repModel);
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_ReturnEntity_When_ConvertingRepresentationModelToEntity() {
|
||||
WorkbasketSummaryRepresentationModel repModel = new WorkbasketSummaryRepresentationModel();
|
||||
repModel.setWorkbasketId("1");
|
||||
repModel.setCustom1("Custom1");
|
||||
repModel.setCustom2("Custom2");
|
||||
repModel.setCustom3("Custom3");
|
||||
repModel.setCustom4("Custom4");
|
||||
repModel.setDescription("Test Ressource");
|
||||
repModel.setDomain("DOMAIN_A");
|
||||
repModel.setKey("1");
|
||||
repModel.setName("Ressource");
|
||||
repModel.setOrgLevel1("Org1");
|
||||
repModel.setOrgLevel2("Org2");
|
||||
repModel.setOrgLevel3("Org3");
|
||||
repModel.setOrgLevel4("Org4");
|
||||
repModel.setOwner("Lars");
|
||||
repModel.setType(WorkbasketType.PERSONAL);
|
||||
// when
|
||||
WorkbasketSummary workbasket = assembler.toEntityModel(repModel);
|
||||
// then
|
||||
testEquality(workbasket, repModel);
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_Equal_When_ComparingEntityWithConvertedEntity() {
|
||||
WorkbasketSummaryImpl workbasketSummary =
|
||||
(WorkbasketSummaryImpl) workbasketService.newWorkbasket("1", "DOMAIN_A").asSummary();
|
||||
workbasketSummary.setDescription("WorkbasketSummaryImplTes");
|
||||
workbasketSummary.setId("1");
|
||||
workbasketSummary.setName("WorkbasketSummary");
|
||||
workbasketSummary.setCustom1("custom1");
|
||||
workbasketSummary.setCustom2("custom2");
|
||||
workbasketSummary.setCustom3("custom3");
|
||||
workbasketSummary.setCustom4("custom4");
|
||||
workbasketSummary.setOrgLevel1("Org1");
|
||||
workbasketSummary.setOrgLevel2("Org2");
|
||||
workbasketSummary.setOrgLevel3("Org3");
|
||||
workbasketSummary.setOrgLevel4("Org4");
|
||||
workbasketSummary.setOwner("Lars");
|
||||
workbasketSummary.setType(WorkbasketType.PERSONAL);
|
||||
|
||||
WorkbasketSummaryRepresentationModel repModel = assembler.toModel(workbasketSummary);
|
||||
WorkbasketSummary workbasketSummary2 = assembler.toEntityModel(repModel);
|
||||
|
||||
assertThat(workbasketSummary)
|
||||
.hasNoNullFieldsOrProperties()
|
||||
.isNotSameAs(workbasketSummary2)
|
||||
.isEqualTo(workbasketSummary2);
|
||||
}
|
||||
|
||||
static void testEquality(
|
||||
WorkbasketSummary summary, WorkbasketSummaryRepresentationModel repModel) {
|
||||
assertThat(summary).hasNoNullFieldsOrProperties();
|
||||
assertThat(repModel).hasNoNullFieldsOrProperties();
|
||||
Assert.assertEquals(summary.getDescription(), repModel.getDescription());
|
||||
Assert.assertEquals(summary.getDomain(), repModel.getDomain());
|
||||
Assert.assertEquals(summary.getId(), repModel.getWorkbasketId());
|
||||
Assert.assertEquals(summary.getKey(), repModel.getKey());
|
||||
Assert.assertEquals(summary.getName(), repModel.getName());
|
||||
Assert.assertEquals(summary.getCustom1(), repModel.getCustom1());
|
||||
Assert.assertEquals(summary.getCustom2(), repModel.getCustom2());
|
||||
Assert.assertEquals(summary.getCustom3(), repModel.getCustom3());
|
||||
Assert.assertEquals(summary.getCustom4(), repModel.getCustom4());
|
||||
Assert.assertEquals(summary.getOrgLevel1(), repModel.getOrgLevel1());
|
||||
Assert.assertEquals(summary.getOrgLevel2(), repModel.getOrgLevel2());
|
||||
Assert.assertEquals(summary.getOrgLevel3(), repModel.getOrgLevel3());
|
||||
Assert.assertEquals(summary.getOrgLevel4(), repModel.getOrgLevel4());
|
||||
Assert.assertEquals(summary.getOwner(), repModel.getOwner());
|
||||
Assert.assertEquals(summary.getType(), repModel.getType());
|
||||
}
|
||||
|
||||
private void testLinks(WorkbasketSummaryRepresentationModel repModel) {}
|
||||
}
|
Loading…
Reference in New Issue