@SuppressWarnings("unchecked") @Test void testCreateEntity() throws URISyntaxException { String entityTypeId = "MyEntityTypeId"; String entityId = "MyId"; Map<String, Object> entityMap = mock(Map.class); Entity entity = mock(Entity.class); when(entity.getIdValue()).thenReturn(entityId); when(dataServiceV3.create(entityTypeId, entityMap)).thenReturn(entity); ResponseEntity responseEntity = entityController.createEntity(entityTypeId, entityMap); ResponseEntity<Object> expectedResponseEntity = ResponseEntity.created(new URI("http: assertEquals(expectedResponseEntity, responseEntity); }
@Transactional @PostMapping("/{entityTypeId}") public ResponseEntity createEntity( @PathVariable("entityTypeId") String entityTypeId, @RequestBody Map<String, Object> entityMap) { Entity entity = dataServiceV3.create(entityTypeId, entityMap); URI location = ServletUriComponentsBuilder.fromCurrentRequestUri() .replacePath(API_ENTITY_PATH) .pathSegment(entityTypeId, entity.getIdValue().toString()) .build() .toUri(); return ResponseEntity.created(location).build(); }
EntityController extends ApiController { @Transactional @PostMapping("/{entityTypeId}") public ResponseEntity createEntity( @PathVariable("entityTypeId") String entityTypeId, @RequestBody Map<String, Object> entityMap) { Entity entity = dataServiceV3.create(entityTypeId, entityMap); URI location = ServletUriComponentsBuilder.fromCurrentRequestUri() .replacePath(API_ENTITY_PATH) .pathSegment(entityTypeId, entity.getIdValue().toString()) .build() .toUri(); return ResponseEntity.created(location).build(); } }
EntityController extends ApiController { @Transactional @PostMapping("/{entityTypeId}") public ResponseEntity createEntity( @PathVariable("entityTypeId") String entityTypeId, @RequestBody Map<String, Object> entityMap) { Entity entity = dataServiceV3.create(entityTypeId, entityMap); URI location = ServletUriComponentsBuilder.fromCurrentRequestUri() .replacePath(API_ENTITY_PATH) .pathSegment(entityTypeId, entity.getIdValue().toString()) .build() .toUri(); return ResponseEntity.created(location).build(); } EntityController(DataServiceV3 dataServiceV3, EntityMapper entityMapper); }
EntityController extends ApiController { @Transactional @PostMapping("/{entityTypeId}") public ResponseEntity createEntity( @PathVariable("entityTypeId") String entityTypeId, @RequestBody Map<String, Object> entityMap) { Entity entity = dataServiceV3.create(entityTypeId, entityMap); URI location = ServletUriComponentsBuilder.fromCurrentRequestUri() .replacePath(API_ENTITY_PATH) .pathSegment(entityTypeId, entity.getIdValue().toString()) .build() .toUri(); return ResponseEntity.created(location).build(); } EntityController(DataServiceV3 dataServiceV3, EntityMapper entityMapper); @Transactional @PostMapping("/{entityTypeId}") ResponseEntity createEntity(
      @PathVariable("entityTypeId") String entityTypeId,
      @RequestBody Map<String, Object> entityMap); @Transactional(readOnly = true) @GetMapping("/{entityTypeId}/{entityId}") EntityResponse getEntity(@Valid ReadEntityRequest entityRequest); @Transactional(readOnly = true) @GetMapping("/{entityTypeId}/{entityId}/{fieldId}") EntitiesResponse getReferencedEntities(@Valid ReadSubresourceRequest entitiesRequest); @Transactional @PutMapping("/{entityTypeId}/{entityId}") @ResponseStatus(HttpStatus.NO_CONTENT) void updateEntity(
      @PathVariable("entityTypeId") String entityTypeId,
      @PathVariable("entityId") String entityId,
      @RequestBody Map<String, Object> entityMap); @Transactional @PatchMapping("/{entityTypeId}/{entityId}") @ResponseStatus(HttpStatus.NO_CONTENT) void updatePartialEntity(
      @PathVariable("entityTypeId") String entityTypeId,
      @PathVariable("entityId") String entityId,
      @RequestBody Map<String, Object> entityMap); @Transactional @DeleteMapping("/{entityTypeId}/{entityId}") @ResponseStatus(HttpStatus.NO_CONTENT) void deleteEntity(@Valid DeleteEntityRequest deleteRequest); @DeleteMapping("/{entityTypeId}") @ResponseStatus(HttpStatus.NO_CONTENT) void deleteEntities(@Valid DeleteEntitiesRequest deleteRequest); @Transactional(readOnly = true) @GetMapping("/{entityTypeId}") EntitiesResponse getEntities(@Valid ReadEntitiesRequest entitiesRequest); }
EntityController extends ApiController { @Transactional @PostMapping("/{entityTypeId}") public ResponseEntity createEntity( @PathVariable("entityTypeId") String entityTypeId, @RequestBody Map<String, Object> entityMap) { Entity entity = dataServiceV3.create(entityTypeId, entityMap); URI location = ServletUriComponentsBuilder.fromCurrentRequestUri() .replacePath(API_ENTITY_PATH) .pathSegment(entityTypeId, entity.getIdValue().toString()) .build() .toUri(); return ResponseEntity.created(location).build(); } EntityController(DataServiceV3 dataServiceV3, EntityMapper entityMapper); @Transactional @PostMapping("/{entityTypeId}") ResponseEntity createEntity(
      @PathVariable("entityTypeId") String entityTypeId,
      @RequestBody Map<String, Object> entityMap); @Transactional(readOnly = true) @GetMapping("/{entityTypeId}/{entityId}") EntityResponse getEntity(@Valid ReadEntityRequest entityRequest); @Transactional(readOnly = true) @GetMapping("/{entityTypeId}/{entityId}/{fieldId}") EntitiesResponse getReferencedEntities(@Valid ReadSubresourceRequest entitiesRequest); @Transactional @PutMapping("/{entityTypeId}/{entityId}") @ResponseStatus(HttpStatus.NO_CONTENT) void updateEntity(
      @PathVariable("entityTypeId") String entityTypeId,
      @PathVariable("entityId") String entityId,
      @RequestBody Map<String, Object> entityMap); @Transactional @PatchMapping("/{entityTypeId}/{entityId}") @ResponseStatus(HttpStatus.NO_CONTENT) void updatePartialEntity(
      @PathVariable("entityTypeId") String entityTypeId,
      @PathVariable("entityId") String entityId,
      @RequestBody Map<String, Object> entityMap); @Transactional @DeleteMapping("/{entityTypeId}/{entityId}") @ResponseStatus(HttpStatus.NO_CONTENT) void deleteEntity(@Valid DeleteEntityRequest deleteRequest); @DeleteMapping("/{entityTypeId}") @ResponseStatus(HttpStatus.NO_CONTENT) void deleteEntities(@Valid DeleteEntitiesRequest deleteRequest); @Transactional(readOnly = true) @GetMapping("/{entityTypeId}") EntitiesResponse getEntities(@Valid ReadEntitiesRequest entitiesRequest); static final String API_ENTITY_PATH; }