Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TSK-1824: Refactor createTask tests that involve Attachments; Throw exception in REST if taskId of an Attachment is incorrect #1876

Closed
wants to merge 2 commits into from

Conversation

ryzheboka
Copy link
Contributor

https://sonarcloud.io/summary/new_code?id=ryzheboka_taskana&branch=TSK-1824


For the submitter:

Verified by the reviewer:

  • Commit message format → TSK-XXX: Your commit message.
  • Submitter's update to documentation is sufficient
  • SonarCloud analysis meets our standards
  • Update of the current release notes reflects changes
  • PR fulfills the ticket
  • Edge cases and unwanted side effects are tested
  • Readability

@ryzheboka ryzheboka changed the title Refactor createTask tests that involve Attachments; Throw exception in REST if TaskId of attachment is incorrect Refactor createTask tests that involve Attachments; Throw exception in REST if taskId of an Attachment is incorrect Mar 29, 2022
@ryzheboka ryzheboka force-pushed the TSK-1824 branch 2 times, most recently from e926b52 to c0128e0 Compare March 31, 2022 11:20
@ryzheboka ryzheboka force-pushed the TSK-1824 branch 2 times, most recently from 1398726 to fcd311f Compare April 12, 2022 13:00
@mustaphazorgati mustaphazorgati changed the title Refactor createTask tests that involve Attachments; Throw exception in REST if taskId of an Attachment is incorrect TSK-1824: Refactor createTask tests that involve Attachments; Throw exception in REST if taskId of an Attachment is incorrect Jul 12, 2022
@ryzheboka ryzheboka force-pushed the TSK-1824 branch 2 times, most recently from d7af34b to cdf4ed4 Compare July 19, 2022 08:49
Comment on lines 148 to 149
assertThatThrownBy(() -> taskService.createTask(task))
.isInstanceOf(InvalidArgumentException.class);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that the original tests did not verify the message of the IllegalArgumentException, but I am undecided whether we should verify the message of those Exceptions. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will verify the message

Comment on lines 85 to 96
@WithAccessId(user = "user-1-1")
@Test
void should_SetTaskIdOfAttachmentCorrectly_WhenCopyingAttachment() throws Exception {
Attachment copiedAttachment =
taskService.getTask(defaultTaskWithAttachment.getId()).getAttachments().get(0).copy();
Task taskToCreate = taskService.newTask(defaultWorkbasketSummary.getId());
taskToCreate.setClassificationKey(defaultClassificationSummary.getKey());
taskToCreate.setPrimaryObjRef(defaultObjectReference);
taskToCreate.addAttachment(copiedAttachment);
Task result = taskService.createTask(taskToCreate);

assertThat(result.getAttachments().get(0).getTaskId()).isEqualTo(result.getId());
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not test TSK-1824 since the copiedAttachment does not contain a different taskId.
Please don't copy the Attachment. Just reuse the Attachment from the defaultTaskWithAttachment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok :)

@Test
void should_SetTaskIdOfAttachmentCorrectly_WhenCopyingAttachment() throws Exception {
Attachment copiedAttachment =
taskService.getTask(defaultTaskWithAttachment.getId()).getAttachments().get(0).copy();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
taskService.getTask(defaultTaskWithAttachment.getId()).getAttachments().get(0).copy();
defaultTaskWithAttachment.getAttachments().get(0).copy();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok :)

Comment on lines +57 to +81
defaultClassificationSummary =
defaultTestClassification()
.serviceLevel("P2D")
.buildAndStoreAsSummary(classificationService);
defaultWorkbasketSummary = defaultTestWorkbasket().buildAndStoreAsSummary(workbasketService);

WorkbasketAccessItemBuilder.newWorkbasketAccessItem()
.workbasketId(defaultWorkbasketSummary.getId())
.accessId("user-1-1")
.permission(WorkbasketPermission.OPEN)
.permission(WorkbasketPermission.READ)
.permission(WorkbasketPermission.APPEND)
.buildAndStore(workbasketService);
defaultObjectReference = defaultTestObjectReference().build();
defaultAttachment =
TaskAttachmentBuilder.newAttachment()
.classificationSummary(defaultClassificationSummary)
.objectReference(defaultObjectReference)
.build();
defaultTaskWithAttachment =
TaskBuilder.newTask()
.primaryObjRef(defaultObjectReference)
.workbasketSummary(defaultWorkbasketSummary)
.classificationSummary(defaultClassificationSummary)
.attachments(defaultAttachment)
.buildAndStore(taskService, "user-1-1");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please be consistent and static import all test-api classes :)

btw: should we make that a guideline?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will include this in the guidelines :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about static imports of DefaultTestEntities instead of all test-api classes?

@ryzheboka ryzheboka force-pushed the TSK-1824 branch 5 times, most recently from 93faaef to f7cd50f Compare August 23, 2022 10:46
@ryzheboka
Copy link
Contributor Author

Closed by #2355

@ryzheboka ryzheboka closed this Sep 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants