@Test
public void skipPersistDocument() throws Throwable {

    this.host.startFactory(new NoUpdateOnPutService());
    this.host.waitForServiceAvailable(NoUpdateOnPutService.FACTORY_LINK);
    String servicePath = UriUtils.buildUriPath(NoUpdateOnPutService.FACTORY_LINK, "foo");
    NoUpdateOnPutService.State initialBody = new NoUpdateOnPutService.State();
    initialBody.name = "init";
    initialBody.documentSelfLink = servicePath;
    Operation initialPost = Operation.createPost(this.host, NoUpdateOnPutService.FACTORY_LINK).setBody(initialBody);
    NoUpdateOnPutService.State postResult = this.sender.sendAndWait(initialPost, NoUpdateOnPutService.State.class);
    long initialVersion = postResult.documentVersion;
    // register subscription
    URI subscriptionUri = UriUtils.buildSubscriptionUri(this.host, servicePath);
    Operation createSubscriptionOp = Operation.createPost(subscriptionUri).setReferer(this.host.getPublicUri());
    AtomicBoolean isSubscriptionCalled = new AtomicBoolean(false);
    this.host.startSubscriptionService(createSubscriptionOp, subscriptionOp -> {
        isSubscriptionCalled.set(true);
        subscriptionOp.complete();
    });
    // perform PUT multiple times and verify always it keeps initial state when GET is performed
    for (int i = 0; i < 100; i++) {
        String newName = "modified-" + i;
        NoUpdateOnPutService.State putBody = new NoUpdateOnPutService.State();
        putBody.name = newName;
        Operation put = Operation.createPut(this.host, servicePath).setBody(putBody);
        Operation putResponseOp = this.sender.sendAndWait(put);
        assertEquals(Operation.STATUS_CODE_OK, putResponseOp.getStatusCode());
        assertTrue(putResponseOp.hasBody());
        NoUpdateOnPutService.State putResponseBody = putResponseOp.getBody(NoUpdateOnPutService.State.class);
        assertEquals("response of put should be the one specified in request", newName, putResponseBody.name);
        NoUpdateOnPutService.State getBody = this.sender.sendAndWait(Operation.createGet(this.host, servicePath),
                NoUpdateOnPutService.State.class);
        assertEquals("document should not be updated", "init", getBody.name);
        assertEquals("document should not be updated", initialVersion, getBody.documentVersion);
        assertFalse("subscription should not be called for non modification", isSubscriptionCalled.get());
    }
}