StudioWorkspaceResourceHandler implements WorkspaceResourceHandler { @Override public LockStatus getLockStatus(final Path filePath) throws ResourceNotFoundException { try { ResponseEntity<String> lockStatusResponse = doGet(filePath, GET_LOCK_STATUS); if (lockStatusResponse.hasBody()) { return LockStatus.valueOf(lockStatusResponse.getBody()); } } catch (Exception e) { handleResourceException(filePath, e); } return LockStatus.UNLOCKED; } @Inject  StudioWorkspaceResourceHandler(RestClient restClient); @Override void preOpen(final Path filePath); @Override void postClose(final Path filePath); @Override void delete(Path filePath); @Override void postDelete(final Path filePath); @Override void postSave(final Path filePath); @Override void preImport(); @Override void postImport(); @Override LockStatus getLockStatus(final Path filePath);  }
@Test public void should_getLockStatus_get_to_workspace_rest_api() throws Exception { server.request(by(uri("/workspace/" + URLEncoder.encode(filePath.toString(), "UTF-8") + "/lockStatus"))).response(LockStatus.LOCKED_BY_ME.name()); LockStatus lockStatus = studioWorkspaceResourceHandler.getLockStatus(filePath); assertThat(lockStatus).isEqualTo(LockStatus.LOCKED_BY_ME); }
@Test public void should_getLockStatus_return_UNLOCKED_as_default_value() throws Exception { server.request(by(uri("/workspace/" + URLEncoder.encode(filePath.toString(), "UTF-8") + "/lockStatus"))).response(status(HttpStatus.OK.value())); LockStatus lockStatus = studioWorkspaceResourceHandler.getLockStatus(filePath); assertThat(lockStatus).isEqualTo(LockStatus.UNLOCKED); }
@Test(expected = ResourceNotFoundException.class) public void should_getLockStatus_throw_a_ResourceNotFoundException_if_status_NOT_FOUND() throws Exception { server.request(by(uri("/workspace/" + URLEncoder.encode(filePath.toString(), "UTF-8") + "/lockStatus"))).response(status(HttpStatus.NOT_FOUND.value())); studioWorkspaceResourceHandler.getLockStatus(filePath); }