From c8b2e178db48272035153301bf592d6d5b531455 Mon Sep 17 00:00:00 2001 From: Christoph Lorenz Date: Thu, 5 Dec 2024 15:55:51 +0100 Subject: [PATCH] Fixed delete endpoint for EntityRelations --- .../relation/EntityRelationController.java | 14 ++----- .../EntityRelationControllerTest.java | 39 +++++++++++++++++++ 2 files changed, 42 insertions(+), 11 deletions(-) create mode 100644 metasvc-server/webapp/src/test/java/io/github/dbmdz/metadata/server/controller/identifiable/entity/relation/EntityRelationControllerTest.java diff --git a/metasvc-server/webapp/src/main/java/io/github/dbmdz/metadata/server/controller/identifiable/entity/relation/EntityRelationController.java b/metasvc-server/webapp/src/main/java/io/github/dbmdz/metadata/server/controller/identifiable/entity/relation/EntityRelationController.java index 40bc28dd6..95995e342 100644 --- a/metasvc-server/webapp/src/main/java/io/github/dbmdz/metadata/server/controller/identifiable/entity/relation/EntityRelationController.java +++ b/metasvc-server/webapp/src/main/java/io/github/dbmdz/metadata/server/controller/identifiable/entity/relation/EntityRelationController.java @@ -6,10 +6,8 @@ import de.digitalcollections.model.list.filtering.Filtering; import de.digitalcollections.model.list.paging.PageRequest; import de.digitalcollections.model.list.paging.PageResponse; -import io.github.dbmdz.metadata.server.business.api.service.exceptions.ConflictException; import io.github.dbmdz.metadata.server.business.api.service.exceptions.ServiceException; import io.github.dbmdz.metadata.server.business.api.service.identifiable.entity.relation.EntityToEntityRelationService; -import io.github.dbmdz.metadata.server.controller.ParameterHelper; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; @@ -107,18 +105,12 @@ List saveEntityRelationsForSubject( @Operation(summary = "Delete an entity relation") @DeleteMapping( - value = - "/v6/entities/{subjectuuid: " - + ParameterHelper.UUID_PATTERN - + "}/{predicate}/{objectuuid: " - + ParameterHelper.UUID_PATTERN - + "}", + value = "/v6/entities/relations/{subjectuuid}/{predicate}/{objectuuid}", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity deleteByUuid( + public ResponseEntity deleteByUuidsAndPredicate( @Parameter(description = "UUID of the subject") @PathVariable("subjectuuid") UUID subjectUuid, @Parameter(description = "predicate") @PathVariable("predicate") String predicate, - @Parameter(description = "UUID of the object") @PathVariable("objectuuid") UUID objectUuid) - throws ConflictException, ServiceException { + @Parameter(description = "UUID of the object") @PathVariable("objectuuid") UUID objectUuid) { EntityRelation example = EntityRelation.builder() .subject(Entity.builder().uuid(subjectUuid).build()) diff --git a/metasvc-server/webapp/src/test/java/io/github/dbmdz/metadata/server/controller/identifiable/entity/relation/EntityRelationControllerTest.java b/metasvc-server/webapp/src/test/java/io/github/dbmdz/metadata/server/controller/identifiable/entity/relation/EntityRelationControllerTest.java new file mode 100644 index 000000000..ab7910136 --- /dev/null +++ b/metasvc-server/webapp/src/test/java/io/github/dbmdz/metadata/server/controller/identifiable/entity/relation/EntityRelationControllerTest.java @@ -0,0 +1,39 @@ +package io.github.dbmdz.metadata.server.controller.identifiable.entity.relation; + +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; + +import de.digitalcollections.model.identifiable.entity.Entity; +import de.digitalcollections.model.identifiable.entity.relation.EntityRelation; +import io.github.dbmdz.metadata.server.business.api.service.identifiable.entity.relation.EntityToEntityRelationService; +import io.github.dbmdz.metadata.server.controller.BaseControllerTest; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; + +@WebMvcTest(EntityRelationController.class) +@DisplayName("The EntityRelation controller") +class EntityRelationControllerTest extends BaseControllerTest { + + @MockBean private EntityToEntityRelationService entityRelationService; + + @DisplayName("can delete an EntityRelation") + @ParameterizedTest + @ValueSource( + strings = { + "/v6/entities/relations/8fe24c2a-ee3d-4f3f-bc4b-c78b6c132afd/is_realized_with/d2206b4c-910f-4dbe-b496-c0a5c0449ee7" + }) + public void listOfRelatedEntities(String path) throws Exception { + EntityRelation expectedEntityRelationToDelete = + EntityRelation.builder() + .subject(Entity.builder().uuid("8fe24c2a-ee3d-4f3f-bc4b-c78b6c132afd").build()) + .predicate("is_realized_with") + .object(Entity.builder().uuid("d2206b4c-910f-4dbe-b496-c0a5c0449ee7").build()) + .build(); + when(entityRelationService.delete(eq(expectedEntityRelationToDelete))).thenReturn(1); + + testDeleteSuccessful(path); + } +}