use of org.springframework.cloud.deployer.resource.StubResourceLoader in project spring-cloud-deployer by spring-cloud.
the class UriRegistryPopulatorTests method populateRegistry.
@Test
public void populateRegistry() throws Exception {
String localUri = "local://local";
UriRegistryPopulator populator = new UriRegistryPopulator();
StubResourceLoader resourceLoader = new StubResourceLoader(new PropertiesResource(uris));
populator.setResourceLoader(resourceLoader);
UriRegistry registry = new InMemoryUriRegistry();
populator.populateRegistry(true, registry, localUri);
assertTrue(resourceLoader.getRequestedLocations().contains(localUri));
assertThat(resourceLoader.getRequestedLocations().size(), is(1));
assertThat(registry.findAll().size(), is(this.uris.size()));
for (String key : this.uris.stringPropertyNames()) {
assertThat(registry.find(key).toString(), is(this.uris.getProperty(key)));
}
boolean thrown = false;
try {
registry.find("not present");
} catch (IllegalArgumentException e) {
thrown = true;
} finally {
assertTrue(thrown);
}
}
use of org.springframework.cloud.deployer.resource.StubResourceLoader in project spring-cloud-deployer by spring-cloud.
the class UriRegistryPopulatorTests method populateRegistryWithOverwrites.
@Test
public void populateRegistryWithOverwrites() throws Exception {
String localUri = "local://local";
UriRegistryPopulator populator = new UriRegistryPopulator();
PropertiesResource propertiesResource = new PropertiesResource(uris);
StubResourceLoader resourceLoader = new StubResourceLoader(propertiesResource);
populator.setResourceLoader(resourceLoader);
UriRegistry registry = new InMemoryUriRegistry();
Map<String, URI> registered = populator.populateRegistry(true, registry, localUri);
assertTrue(registered.size() == 3);
// Perform overwrites on the existing keys
Map<String, URI> registeredWithNoOverwrites = populator.populateRegistry(false, registry, localUri);
assertTrue(registeredWithNoOverwrites.size() == 0);
propertiesResource.addNewProperty("another", "maven://somegroup:someartifact:jar:exec:1.0.0");
Map<String, URI> newlyRegisteredWithNoOverwrites = populator.populateRegistry(false, registry, localUri);
assertTrue(newlyRegisteredWithNoOverwrites.size() == 1);
propertiesResource.addNewProperty("yet-another", "file:///tmp/yet-another.jar");
Map<String, URI> newlyRegisteredWithOverwrites = populator.populateRegistry(true, registry, localUri);
assertTrue(newlyRegisteredWithOverwrites.size() == 5);
}
use of org.springframework.cloud.deployer.resource.StubResourceLoader in project spring-cloud-deployer by spring-cloud.
the class UriRegistryPopulatorTests method populateRegistryInvalidUri.
@Test
public void populateRegistryInvalidUri() throws Exception {
String localUri = "local://local";
Properties props = new Properties();
props.setProperty("test", "file:///bar-1.2.3.jar");
UriRegistryPopulator populator = new UriRegistryPopulator();
StubResourceLoader resourceLoader = new StubResourceLoader(new PropertiesResource(props));
populator.setResourceLoader(resourceLoader);
UriRegistry registry = new InMemoryUriRegistry();
populator.populateRegistry(true, registry, localUri);
assertTrue(resourceLoader.getRequestedLocations().contains(localUri));
assertThat(resourceLoader.getRequestedLocations().size(), is(1));
assertThat(registry.findAll().size(), is(1));
assertThat(registry.find("test").toString(), is("file:///bar-1.2.3.jar"));
populator.populateRegistry(true, registry, localUri);
props.setProperty("test", "invalid");
populator.populateRegistry(true, registry, localUri);
assertThat(registry.find("test").toString(), is("file:///bar-1.2.3.jar"));
}
use of org.springframework.cloud.deployer.resource.StubResourceLoader in project spring-cloud-deployer by spring-cloud.
the class DelegatingResourceLoaderTests method test.
@Test
public void test() {
NullResource one = new NullResource("one");
NullResource two = new NullResource("two");
NullResource three = new NullResource("three");
assertNotEquals(one, two);
assertNotEquals(two, three);
Map<String, ResourceLoader> map = new HashMap<>();
map.put("one", new StubResourceLoader(one));
map.put("two", new StubResourceLoader(two));
map.put("three", new StubResourceLoader(three));
DelegatingResourceLoader resourceLoader = new DelegatingResourceLoader(map);
assertEquals(one, resourceLoader.getResource("one://one"));
assertEquals(two, resourceLoader.getResource("two://two"));
assertEquals(three, resourceLoader.getResource("three://three"));
}
Aggregations