@Override
    public String lock(final Path file) throws BackgroundException {
        try {
            return new LocksApi(new BrickApiClient(session))
                .postLocksPath(StringUtils.removeStart(file.getAbsolute(), String.valueOf(Path.DELIMITER)),
                    new LocksPathBody().exclusive(true).allowAccessByAnyUser(true)).getToken();
        }
        catch(ApiException e) {
            throw new BrickExceptionMappingService().map("Failure to write attributes of {0}", e, file);
        }
    }
@Test
    public void testLock() throws Exception {
        final TransferStatus status = new TransferStatus();
        final Local local = new Local(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());
        final byte[] content = RandomUtils.nextBytes(128);
        final OutputStream out = local.getOutputStream(false);
        IOUtils.write(content, out);
        out.close();
        status.setLength(content.length);
        final Path test = new Path(new DefaultHomeFinderService(session).find(), new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
        final BrickUploadFeature upload = new BrickUploadFeature(session, new BrickWriteFeature(session));
        upload.upload(test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED),
            new DisabledStreamListener(), status, new DisabledConnectionCallback());
        assertTrue(new BrickFindFeature(session).find(test));
        final BrickLockFeature feature = new BrickLockFeature(session);
        final String lockid = feature.lock(test);
        assertNotNull(lockid);
        try {
            feature.lock(test);
            fail();
        }
        catch(LockedException e) {
            // Expected
        }
        feature.unlock(test, lockid);
        new BrickDeleteFeature(session).delete(Collections.singletonMap(test, new TransferStatus().withLockId(lockid)), new DisabledPasswordCallback(), new Delete.DisabledCallback());
    }