@Test
public void testHttpSubscription() throws Exception {

    RequestContext requestContext = new RequestContext.Builder().build();
    // Create a subscription
    DefaultResourceState subscriptionState = new DefaultResourceState();
    subscriptionState.putProperty("path", "/testApp/memory/data/*");
    subscriptionState.putProperty("destination", "http://localhost:8080/testApp/memory/notifications/");
    ResourceState createdSubscription = this.client.create(requestContext, "/testApp/subscriptions", subscriptionState);
    assertThat(createdSubscription).isNotNull();
    assertThat(createdSubscription.getProperty("path")).isEqualTo("/testApp/memory/data/*");
    assertThat(createdSubscription.getProperty("destination")).isEqualTo("http://localhost:8080/testApp/memory/notifications/");
    // Create an item that is subscribed to
    DefaultResourceState bobState = new DefaultResourceState();
    bobState.putProperty("name", "Bob McWhirter");
    ResourceState createdBob = this.client.create(requestContext, "/testApp/memory/data", bobState);
    String bobId = createdBob.id();
    assertThat(bobId).isNotEmpty();
    // Give subscription time to deliver
    Thread.sleep(1000);
    assertThat(createdBob.uri().toString()).isEqualTo("/testApp/memory/data/" + bobId);
    // Check that subscription fired, creating target
    ResourceState notifiedBob = this.client.read(requestContext, "/testApp/memory/notifications/" + bobId);
    assertThat(notifiedBob).isNotNull();
    assertThat(notifiedBob.id()).isEqualTo(bobId);
    assertThat(notifiedBob.uri().toString()).isEqualTo("/testApp/memory/notifications/" + bobId);
    assertThat(notifiedBob.getPropertyNames()).hasSize(1);
    assertThat(notifiedBob.getProperty("name")).isEqualTo("Bob McWhirter");
    // Delete a subscribed thing
    this.client.delete(requestContext, createdBob.uri().toString());
    // Give it time to propagate
    Thread.sleep(1000);
    // ensure delete was notified to subscriber
    try {
        this.client.read(requestContext, notifiedBob.uri().toString());
        fail("Should have thrown ResourceNotFoundException");
    } catch (ResourceNotFoundException e) {
        // expected and correct
    }
    // Delete the subscription
    ResourceState deletedSubscription = this.client.delete(requestContext, createdSubscription.uri().toString());
    assertThat(deletedSubscription).isNotNull();
    // Ensure that further notifications do not occur.
    DefaultResourceState kenState = new DefaultResourceState();
    kenState.putProperty("name", "Ken Finnigan");
    ResourceState createdKen = this.client.create(requestContext, "/testApp/memory/data", kenState);
    String kenId = createdKen.id();
    assertThat(kenId).isNotEmpty();
    Thread.sleep(2000);
    try {
        this.client.read(requestContext, "/testApp/memory/notifications/" + kenId);
        fail("should have thrown ResourceNotFoundException");
    } catch (ResourceNotFoundException e) {
        // expected and corret
    }
}