ConfigurationResourceManager implements LoggableResource { public Future<Optional<Buffer>> getRegisteredResource(String resourceUri){ return getValidatedRegisteredResource(resourceUri); } ConfigurationResourceManager(Vertx vertx, final ResourceStorage storage); Future<Optional<Buffer>> getRegisteredResource(String resourceUri); void registerResource(String resourceUri, String resourceSchema); void registerObserver(ConfigurationResourceObserver observer, String resourceUri); @Override void enableResourceLogging(boolean resourceLoggingEnabled); boolean handleConfigurationResource(final HttpServerRequest request); Map<String, List<ConfigurationResourceObserver>> getObservers(); static final String CONFIG_RESOURCE_CHANGED_ADDRESS; }
@Test public void testGetRegisteredResourceNotYetRegistered(TestContext context) { Async async = context.async(); MockResourceStorage storage = new MockResourceStorage(); configurationResourceManager = new ConfigurationResourceManager(vertx, storage); String resourceURI = "/gateleen/resources/person"; context.assertFalse(storage.getMockData().containsKey(resourceURI)); configurationResourceManager.getRegisteredResource(resourceURI).setHandler(event -> { context.assertTrue(event.succeeded()); context.assertFalse(event.result().isPresent()); async.complete(); }); }
@Test public void testGetRegisteredResource(TestContext context) { Async async = context.async(); MockResourceStorage storage = new MockResourceStorage(); configurationResourceManager = new ConfigurationResourceManager(vertx, storage); String resourceURI = "/gateleen/resources/person"; configurationResourceManager.registerResource(resourceURI, PERSON_SCHEMA); ConfigurationResourceObserver observer = Mockito.spy(new TestConfigurationResourceObserver()); configurationResourceManager.registerObserver(observer, resourceURI); PersonResourceRequest request = new PersonResourceRequest(HttpMethod.PUT, resourceURI, resourceURI, CONTENT_MATCHING_PERSON_SCHEMA, new DummyHttpServerResponse()); context.assertFalse(storage.getMockData().containsKey(resourceURI)); boolean handled = configurationResourceManager.handleConfigurationResource(request); context.assertTrue(handled, "PUT Request to configuration resource should be handled"); await().atMost(3, SECONDS).until( () -> storage.getMockData().get(resourceURI), equalTo(CONTENT_MATCHING_PERSON_SCHEMA)); configurationResourceManager.getRegisteredResource(resourceURI).setHandler(event -> { context.assertTrue(event.succeeded()); context.assertTrue(event.result().isPresent()); context.assertEquals(CONTENT_MATCHING_PERSON_SCHEMA, event.result().get().toString()); async.complete(); }); }