HttpSubscription implements Subscription { public HttpSubscription(HttpClient httpClient, String path, URI destination, ResourceCodec codec, SecurityContext securityContext) { this.id = UUID.randomUUID().toString(); this.httpClient = httpClient; this.resourcePath = new ResourcePath(path); this.destination = destination; this.codec = codec; this.securityContext = securityContext; } HttpSubscription(HttpClient httpClient, String path, URI destination, ResourceCodec codec, SecurityContext securityContext); @Override String id(); URI destination(); @Override ResourcePath resourcePath(); @Override boolean isSecure(); @Override SecurityContext securityContext(); @Override void sendAuthzError(ResourceState errorState, Resource resource, int status); @Override void resourceCreated(ResourceResponse resourceResponse); @Override void resourceUpdated(ResourceResponse resourceResponse); @Override void resourceDeleted(ResourceResponse resourceResponse);  }
@Test public void testHttpSubscription() throws Exception { RequestContext requestContext = new RequestContext.Builder().build(); DefaultResourceState subscriptionState = new DefaultResourceState(); subscriptionState.putProperty("path", "/testApp/memory/data/*"); subscriptionState.putProperty("destination", "http: 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: 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(); Thread.sleep(1000); assertThat(createdBob.uri().toString()).isEqualTo("/testApp/memory/data/" + bobId); 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"); this.client.delete(requestContext, createdBob.uri().toString()); Thread.sleep(1000); try { this.client.read(requestContext, notifiedBob.uri().toString()); fail("Should have thrown ResourceNotFoundException"); } catch (ResourceNotFoundException e) { } ResourceState deletedSubscription = this.client.delete(requestContext, createdSubscription.uri().toString()); assertThat(deletedSubscription).isNotNull(); 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) { } }