Search in sources :

Example 1 with UpdatePolicy

use of org.javamoney.moneta.spi.LoaderService.UpdatePolicy in project jsr354-ri by JavaMoney.

the class LoaderConfigurator method initResource.

private void initResource(String name, Map<String, String> allProps) throws MalformedURLException {
    Map<String, String> props = mapProperties(allProps, name);
    UpdatePolicy updatePolicy = UpdatePolicy.valueOf(props.get(TYPE));
    String fallbackRes = props.get("resource");
    if (Objects.isNull(fallbackRes)) {
        throw new IllegalArgumentException(LOAD + name + ".resource (classpath resource) required.");
    }
    String resourcesString = props.get("urls");
    boolean startRemote = Boolean.valueOf(props.get("startRemote"));
    String[] resources;
    if (Objects.isNull(resourcesString)) {
        LOG.info("No update URLs configured for: " + name);
        resources = new String[0];
    } else {
        resources = resourcesString.split(",");
    }
    URI[] urls = createURIs(resources);
    LoadDataInformation loadDataInformation = new LoadDataInformationBuilder().withResourceId(name).withUpdatePolicy(updatePolicy).withProperties(props).withBackupResource(getClassLoaderLocation(fallbackRes)).withResourceLocations(urls).withStartRemote(startRemote).build();
    this.loaderService.registerData(loadDataInformation);
}
Also used : LoadDataInformation(org.javamoney.moneta.spi.LoadDataInformation) UpdatePolicy(org.javamoney.moneta.spi.LoaderService.UpdatePolicy) LoadDataInformationBuilder(org.javamoney.moneta.spi.LoadDataInformationBuilder) URI(java.net.URI)

Example 2 with UpdatePolicy

use of org.javamoney.moneta.spi.LoaderService.UpdatePolicy in project jsr354-ri by JavaMoney.

the class LoadDataInformationBuilderTest method shouldCreateLoadDataInformationWithOutBackupResource.

@Test
public void shouldCreateLoadDataInformationWithOutBackupResource() throws URISyntaxException {
    String resourceId = "resourceId";
    UpdatePolicy updatePolicy = UpdatePolicy.LAZY;
    Map<String, String> properties = new HashMap<>();
    LoaderListener loaderListener = new LoaderListener() {

        @Override
        public void newDataLoaded(String resourceId, InputStream is) {
        }
    };
    URI[] resourceLocations = new URI[] { new URI("localhost") };
    LoadDataInformation loadInformation = new LoadDataInformationBuilder().withResourceId(resourceId).withUpdatePolicy(updatePolicy).withProperties(properties).withLoaderListener(loaderListener).withResourceLocations(resourceLocations).build();
    assertEquals(loadInformation.getResourceId(), resourceId);
    assertEquals(loadInformation.getUpdatePolicy(), updatePolicy);
    assertEquals(loadInformation.getProperties(), properties);
    assertNull(loadInformation.getBackupResource());
    assertEquals(loadInformation.getResourceLocations(), resourceLocations);
    assertFalse(loadInformation.isStartRemote());
}
Also used : LoaderListener(org.javamoney.moneta.spi.LoaderService.LoaderListener) UpdatePolicy(org.javamoney.moneta.spi.LoaderService.UpdatePolicy) HashMap(java.util.HashMap) InputStream(java.io.InputStream) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 3 with UpdatePolicy

use of org.javamoney.moneta.spi.LoaderService.UpdatePolicy in project jsr354-ri by JavaMoney.

the class LoadDataInformationBuilderTest method shouldReturnsErrorWhenResourceLocationsWasNotInformed.

@Test(expectedExceptions = IllegalStateException.class)
public void shouldReturnsErrorWhenResourceLocationsWasNotInformed() throws URISyntaxException {
    String resourceId = "resourceId";
    UpdatePolicy updatePolicy = UpdatePolicy.LAZY;
    Map<String, String> properties = new HashMap<>();
    LoaderListener loaderListener = new LoaderListener() {

        @Override
        public void newDataLoaded(String resourceId, InputStream is) {
        }
    };
    new LoadDataInformationBuilder().withResourceId(resourceId).withUpdatePolicy(updatePolicy).withProperties(properties).withLoaderListener(loaderListener).build();
}
Also used : LoaderListener(org.javamoney.moneta.spi.LoaderService.LoaderListener) UpdatePolicy(org.javamoney.moneta.spi.LoaderService.UpdatePolicy) HashMap(java.util.HashMap) InputStream(java.io.InputStream) Test(org.testng.annotations.Test)

Example 4 with UpdatePolicy

use of org.javamoney.moneta.spi.LoaderService.UpdatePolicy in project jsr354-ri by JavaMoney.

the class LoadDataInformationBuilderTest method shouldCreateLoadDataInformation.

@Test
public void shouldCreateLoadDataInformation() throws URISyntaxException {
    String resourceId = "resourceId";
    UpdatePolicy updatePolicy = UpdatePolicy.LAZY;
    Map<String, String> properties = new HashMap<>();
    LoaderListener loaderListener = new LoaderListener() {

        @Override
        public void newDataLoaded(String resourceId, InputStream is) {
        }
    };
    URI backupResource = new URI("localhost");
    URI[] resourceLocations = new URI[] { new URI("localhost") };
    LoadDataInformation loadInformation = new LoadDataInformationBuilder().withResourceId(resourceId).withUpdatePolicy(updatePolicy).withProperties(properties).withLoaderListener(loaderListener).withBackupResource(backupResource).withStartRemote(true).withResourceLocations(resourceLocations).build();
    assertEquals(loadInformation.getResourceId(), resourceId);
    assertEquals(loadInformation.getUpdatePolicy(), updatePolicy);
    assertEquals(loadInformation.getProperties(), properties);
    assertEquals(loadInformation.getBackupResource(), backupResource);
    assertEquals(loadInformation.getResourceLocations(), resourceLocations);
    assertTrue(loadInformation.isStartRemote());
}
Also used : LoaderListener(org.javamoney.moneta.spi.LoaderService.LoaderListener) UpdatePolicy(org.javamoney.moneta.spi.LoaderService.UpdatePolicy) HashMap(java.util.HashMap) InputStream(java.io.InputStream) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 5 with UpdatePolicy

use of org.javamoney.moneta.spi.LoaderService.UpdatePolicy in project jsr354-ri-bp by JavaMoney.

the class LoaderConfigurator method initResource.

private void initResource(String name, Map<String, String> allProps) throws MalformedURLException {
    Map<String, String> props = mapProperties(allProps, name);
    UpdatePolicy updatePolicy = UpdatePolicy.valueOf(props.get(TYPE));
    String fallbackRes = props.get("resource");
    if (fallbackRes == null) {
        throw new IllegalArgumentException(LOAD + name + ".resource (classpath resource) required.");
    }
    String resourcesString = props.get("urls");
    boolean startRemote = Boolean.parseBoolean(props.get("startRemote"));
    String[] resources;
    if (resourcesString == null) {
        LOG.log(Level.INFO, "No update URLs configured for: %s", name);
        resources = new String[0];
    } else {
        resources = resourcesString.split(",");
    }
    URI[] urls = createURIs(resources);
    LoadDataInformation loadDataInformation = new LoadDataInformationBuilder().withResourceId(name).withUpdatePolicy(updatePolicy).withProperties(props).withBackupResource(getClassLoaderLocation(fallbackRes)).withResourceLocations(urls).withStartRemote(startRemote).build();
    this.loaderService.registerData(loadDataInformation);
}
Also used : LoadDataInformation(org.javamoney.moneta.spi.LoadDataInformation) UpdatePolicy(org.javamoney.moneta.spi.LoaderService.UpdatePolicy) LoadDataInformationBuilder(org.javamoney.moneta.spi.LoadDataInformationBuilder) URI(java.net.URI)

Aggregations

UpdatePolicy (org.javamoney.moneta.spi.LoaderService.UpdatePolicy)9 URI (java.net.URI)8 InputStream (java.io.InputStream)6 HashMap (java.util.HashMap)6 LoaderListener (org.javamoney.moneta.spi.LoaderService.LoaderListener)6 Test (org.testng.annotations.Test)6 LoadDataInformationBuilder (org.javamoney.moneta.spi.LoadDataInformationBuilder)3 LoadDataInformation (org.javamoney.moneta.spi.LoadDataInformation)2 BeforeMethod (org.testng.annotations.BeforeMethod)1