Search in sources :

Example 1 with StubResourceLoader

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);
    }
}
Also used : StubResourceLoader(org.springframework.cloud.deployer.resource.StubResourceLoader) Test(org.junit.Test)

Example 2 with StubResourceLoader

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);
}
Also used : StubResourceLoader(org.springframework.cloud.deployer.resource.StubResourceLoader) URI(java.net.URI) Test(org.junit.Test)

Example 3 with StubResourceLoader

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"));
}
Also used : StubResourceLoader(org.springframework.cloud.deployer.resource.StubResourceLoader) Properties(java.util.Properties) Test(org.junit.Test)

Example 4 with StubResourceLoader

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"));
}
Also used : StubResourceLoader(org.springframework.cloud.deployer.resource.StubResourceLoader) ResourceLoader(org.springframework.core.io.ResourceLoader) StubResourceLoader(org.springframework.cloud.deployer.resource.StubResourceLoader) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 StubResourceLoader (org.springframework.cloud.deployer.resource.StubResourceLoader)4 URI (java.net.URI)1 HashMap (java.util.HashMap)1 Properties (java.util.Properties)1 ResourceLoader (org.springframework.core.io.ResourceLoader)1