@Test void testCreateAttribute() throws URISyntaxException { String entityTypeId = "MyEntityTypeId"; String attibuteId = "myAttributeId"; CreateAttributeRequest createAttributeRequest = CreateAttributeRequest.builder().setId(attibuteId).setName("updatedMyAttribute").build(); EntityType entityType = mock(EntityType.class); when(metadataApiService.findEntityType(entityTypeId)).thenReturn(entityType); Attribute newAttribute = mock(Attribute.class); when(attributeRequestMapper.toAttribute(createAttributeRequest, entityType)) .thenReturn(newAttribute); EntityType jobEntityType = mock(EntityType.class); when(jobEntityType.getId()).thenReturn("MyJobEntityTypeId"); MetadataUpsertJobExecution metadataUpsertJobExecution = mock(MetadataUpsertJobExecution.class); when(metadataUpsertJobExecution.getEntityType()).thenReturn(jobEntityType); when(metadataUpsertJobExecution.getIdentifier()).thenReturn("MyJobEntityId"); when(metadataApiService.updateEntityTypeAsync(entityType)) .thenReturn(metadataUpsertJobExecution); ResponseEntity<?> responseEntity = ResponseEntity.accepted() .location(new URI("http: .build(); assertEquals( responseEntity, metadataApiController.createAttribute(entityTypeId, createAttributeRequest)); verify(entityType).addAttribute(newAttribute); }
@Transactional @PostMapping("/{entityTypeId}/attributes") public ResponseEntity<Void> createAttribute( @PathVariable("entityTypeId") String entityTypeId, @Valid @RequestBody CreateAttributeRequest createAttributeRequest) { EntityType entityType = metadataApiService.findEntityType(entityTypeId); Attribute attribute = attributeRequestMapper.toAttribute(createAttributeRequest, entityType); entityType.addAttribute(attribute); JobExecution jobExecution = metadataApiService.updateEntityTypeAsync(entityType); return toLocationResponse(jobExecution); }
MetadataApiController extends ApiController { @Transactional @PostMapping("/{entityTypeId}/attributes") public ResponseEntity<Void> createAttribute( @PathVariable("entityTypeId") String entityTypeId, @Valid @RequestBody CreateAttributeRequest createAttributeRequest) { EntityType entityType = metadataApiService.findEntityType(entityTypeId); Attribute attribute = attributeRequestMapper.toAttribute(createAttributeRequest, entityType); entityType.addAttribute(attribute); JobExecution jobExecution = metadataApiService.updateEntityTypeAsync(entityType); return toLocationResponse(jobExecution); } }
MetadataApiController extends ApiController { @Transactional @PostMapping("/{entityTypeId}/attributes") public ResponseEntity<Void> createAttribute( @PathVariable("entityTypeId") String entityTypeId, @Valid @RequestBody CreateAttributeRequest createAttributeRequest) { EntityType entityType = metadataApiService.findEntityType(entityTypeId); Attribute attribute = attributeRequestMapper.toAttribute(createAttributeRequest, entityType); entityType.addAttribute(attribute); JobExecution jobExecution = metadataApiService.updateEntityTypeAsync(entityType); return toLocationResponse(jobExecution); } MetadataApiController(
      MetadataApiService metadataApiService,
      EntityTypeResponseMapper entityTypeResponseMapper,
      EntityTypeRequestMapper entityTypeRequestMapper,
      AttributeResponseMapper attributeResponseMapper,
      AttributeRequestMapper attributeRequestMapper); }
MetadataApiController extends ApiController { @Transactional @PostMapping("/{entityTypeId}/attributes") public ResponseEntity<Void> createAttribute( @PathVariable("entityTypeId") String entityTypeId, @Valid @RequestBody CreateAttributeRequest createAttributeRequest) { EntityType entityType = metadataApiService.findEntityType(entityTypeId); Attribute attribute = attributeRequestMapper.toAttribute(createAttributeRequest, entityType); entityType.addAttribute(attribute); JobExecution jobExecution = metadataApiService.updateEntityTypeAsync(entityType); return toLocationResponse(jobExecution); } MetadataApiController(
      MetadataApiService metadataApiService,
      EntityTypeResponseMapper entityTypeResponseMapper,
      EntityTypeRequestMapper entityTypeRequestMapper,
      AttributeResponseMapper attributeResponseMapper,
      AttributeRequestMapper attributeRequestMapper); @Transactional(readOnly = true) @GetMapping EntityTypesResponse getEntityTypes(@Valid ReadEntityTypesRequest entitiesRequest); @Transactional(readOnly = true) @GetMapping("/{entityTypeId}") EntityTypeResponse getEntityType(
      @PathVariable("entityTypeId") String entityTypeId,
      @Valid ReadEntityTypeRequest readEntityTypeRequest); @Transactional(readOnly = true) @GetMapping("/{entityTypeId}/attributes/{attributeId}") AttributeResponse getAttribute(
      @PathVariable("entityTypeId") String entityTypeId,
      @PathVariable("attributeId") String attributeId); @Transactional @PostMapping ResponseEntity<Void> createEntityType(
      @Valid @RequestBody CreateEntityTypeRequest createEntityTypeRequest); @Transactional(readOnly = true) @GetMapping("/{entityTypeId}/attributes") AttributesResponse getAttributes(
      @PathVariable("entityTypeId") String entityTypeId,
      @Valid ReadAttributesRequest readAttributesRequest); @Transactional @PostMapping("/{entityTypeId}/attributes") ResponseEntity<Void> createAttribute(
      @PathVariable("entityTypeId") String entityTypeId,
      @Valid @RequestBody CreateAttributeRequest createAttributeRequest); @Transactional @DeleteMapping("/{entityTypeId}/attributes/{attributeId}") ResponseEntity<Void> deleteAttribute(
      @PathVariable("entityTypeId") String entityTypeId,
      @PathVariable("attributeId") String attributeId); @Transactional @DeleteMapping("/{entityTypeId}/attributes") ResponseEntity<Void> deleteAttributes(
      @PathVariable("entityTypeId") String entityTypeId,
      @Valid DeleteAttributesRequest deleteAttributesRequest); @Transactional @PutMapping("/{entityTypeId}") ResponseEntity<Void> updateEntityType(
      @PathVariable("entityTypeId") String entityTypeId,
      @Valid @RequestBody CreateEntityTypeRequest createEntityTypeRequest); @Transactional @PutMapping("/{entityTypeId}/attributes/{attributeId}") ResponseEntity<Void> updateAttribute(
      @PathVariable("entityTypeId") String entityTypeId,
      @PathVariable("attributeId") String attributeId,
      @Valid @RequestBody CreateAttributeRequest createAttributeRequest); @Transactional @PatchMapping("/{entityTypeId}/attributes/{attributeId}") ResponseEntity<Void> updatePartialAttribute(
      @PathVariable("entityTypeId") String entityTypeId,
      @PathVariable("attributeId") String attributeId,
      @RequestBody Map<String, Object> attributeValues); @Transactional @PatchMapping("/{entityTypeId}") ResponseEntity<Void> updatePartialEntityType(
      @PathVariable("entityTypeId") String entityTypeId,
      @RequestBody Map<String, Object> entityTypeValues); @Transactional @DeleteMapping("/{entityTypeId}") ResponseEntity<Void> deleteEntityType(@PathVariable("entityTypeId") String entityTypeId); @Transactional @DeleteMapping ResponseEntity<Void> deleteEntityTypes(
      @Valid DeleteEntityTypesRequest deleteEntityTypesRequest); }
MetadataApiController extends ApiController { @Transactional @PostMapping("/{entityTypeId}/attributes") public ResponseEntity<Void> createAttribute( @PathVariable("entityTypeId") String entityTypeId, @Valid @RequestBody CreateAttributeRequest createAttributeRequest) { EntityType entityType = metadataApiService.findEntityType(entityTypeId); Attribute attribute = attributeRequestMapper.toAttribute(createAttributeRequest, entityType); entityType.addAttribute(attribute); JobExecution jobExecution = metadataApiService.updateEntityTypeAsync(entityType); return toLocationResponse(jobExecution); } MetadataApiController(
      MetadataApiService metadataApiService,
      EntityTypeResponseMapper entityTypeResponseMapper,
      EntityTypeRequestMapper entityTypeRequestMapper,
      AttributeResponseMapper attributeResponseMapper,
      AttributeRequestMapper attributeRequestMapper); @Transactional(readOnly = true) @GetMapping EntityTypesResponse getEntityTypes(@Valid ReadEntityTypesRequest entitiesRequest); @Transactional(readOnly = true) @GetMapping("/{entityTypeId}") EntityTypeResponse getEntityType(
      @PathVariable("entityTypeId") String entityTypeId,
      @Valid ReadEntityTypeRequest readEntityTypeRequest); @Transactional(readOnly = true) @GetMapping("/{entityTypeId}/attributes/{attributeId}") AttributeResponse getAttribute(
      @PathVariable("entityTypeId") String entityTypeId,
      @PathVariable("attributeId") String attributeId); @Transactional @PostMapping ResponseEntity<Void> createEntityType(
      @Valid @RequestBody CreateEntityTypeRequest createEntityTypeRequest); @Transactional(readOnly = true) @GetMapping("/{entityTypeId}/attributes") AttributesResponse getAttributes(
      @PathVariable("entityTypeId") String entityTypeId,
      @Valid ReadAttributesRequest readAttributesRequest); @Transactional @PostMapping("/{entityTypeId}/attributes") ResponseEntity<Void> createAttribute(
      @PathVariable("entityTypeId") String entityTypeId,
      @Valid @RequestBody CreateAttributeRequest createAttributeRequest); @Transactional @DeleteMapping("/{entityTypeId}/attributes/{attributeId}") ResponseEntity<Void> deleteAttribute(
      @PathVariable("entityTypeId") String entityTypeId,
      @PathVariable("attributeId") String attributeId); @Transactional @DeleteMapping("/{entityTypeId}/attributes") ResponseEntity<Void> deleteAttributes(
      @PathVariable("entityTypeId") String entityTypeId,
      @Valid DeleteAttributesRequest deleteAttributesRequest); @Transactional @PutMapping("/{entityTypeId}") ResponseEntity<Void> updateEntityType(
      @PathVariable("entityTypeId") String entityTypeId,
      @Valid @RequestBody CreateEntityTypeRequest createEntityTypeRequest); @Transactional @PutMapping("/{entityTypeId}/attributes/{attributeId}") ResponseEntity<Void> updateAttribute(
      @PathVariable("entityTypeId") String entityTypeId,
      @PathVariable("attributeId") String attributeId,
      @Valid @RequestBody CreateAttributeRequest createAttributeRequest); @Transactional @PatchMapping("/{entityTypeId}/attributes/{attributeId}") ResponseEntity<Void> updatePartialAttribute(
      @PathVariable("entityTypeId") String entityTypeId,
      @PathVariable("attributeId") String attributeId,
      @RequestBody Map<String, Object> attributeValues); @Transactional @PatchMapping("/{entityTypeId}") ResponseEntity<Void> updatePartialEntityType(
      @PathVariable("entityTypeId") String entityTypeId,
      @RequestBody Map<String, Object> entityTypeValues); @Transactional @DeleteMapping("/{entityTypeId}") ResponseEntity<Void> deleteEntityType(@PathVariable("entityTypeId") String entityTypeId); @Transactional @DeleteMapping ResponseEntity<Void> deleteEntityTypes(
      @Valid DeleteEntityTypesRequest deleteEntityTypesRequest);  }