Example usage for org.springframework.core.io Resource getFile

List of usage examples for org.springframework.core.io Resource getFile

Introduction

In this page you can find the example usage for org.springframework.core.io Resource getFile.

Prototype

File getFile() throws IOException;

Source Link

Document

Return a File handle for this resource.

Usage

From source file:org.springframework.cloud.dataflow.server.service.impl.validation.DefaultValidationService.java

private static Archive resolveAsArchive(Resource app) throws IOException {
    Assert.notNull(app, "The resource specified for the app must not be null");
    File moduleFile = app.getFile();
    return moduleFile.isDirectory() ? new ExplodedArchive(moduleFile) : new JarFileArchive(moduleFile);
}

From source file:org.springframework.cloud.deployer.spi.cloudfoundry.CloudFoundryAppDeployerTests.java

@SuppressWarnings("unchecked")
@Test//from  w w  w  .  j  ava 2s.  c o  m
public void deploy() throws IOException {
    Resource resource = new FileSystemResource("src/test/resources/demo-0.0.1-SNAPSHOT.jar");

    given(this.applicationNameGenerator.generateAppName("test-application")).willReturn("test-application-id");

    givenRequestGetApplication("test-application-id", Mono.error(new IllegalArgumentException()),
            Mono.just(ApplicationDetail.builder().diskQuota(0).id("test-application-id").instances(1)
                    .memoryLimit(0).name("test-application").requestedState("RUNNING").runningInstances(0)
                    .stack("test-stack").build()));

    givenRequestPushApplication(PushApplicationManifestRequest.builder()
            .manifest(ApplicationManifest.builder().path(resource.getFile().toPath())
                    .buildpack(deploymentProperties.getBuildpack()).disk(1024)
                    .environmentVariables(defaultEnvironmentVariables()).instances(1).memory(1024)
                    .name("test-application-id").service("test-service-2").service("test-service-1").build())
            .stagingTimeout(this.deploymentProperties.getStagingTimeout())
            .startupTimeout(this.deploymentProperties.getStartupTimeout()).build(), Mono.empty());

    String deploymentId = this.deployer.deploy(new AppDeploymentRequest(
            new AppDefinition("test-application", Collections.emptyMap()), resource, Collections.EMPTY_MAP));

    assertThat(deploymentId, equalTo("test-application-id"));
}

From source file:org.springframework.cloud.deployer.spi.cloudfoundry.CloudFoundryAppDeployerTests.java

@SuppressWarnings("unchecked")
@Test/*from  w  ww  . j  ava 2s . c  o  m*/
public void deployWithServiceParameters() throws IOException {
    Resource resource = new FileSystemResource("src/test/resources/demo-0.0.1-SNAPSHOT.jar");

    given(this.applicationNameGenerator.generateAppName("test-application")).willReturn("test-application-id");
    given(this.services.bind(any(BindServiceInstanceRequest.class))).willReturn(Mono.empty());
    given(this.applications.start(any(StartApplicationRequest.class))).willReturn(Mono.empty());

    givenRequestGetApplication("test-application-id", Mono.error(new IllegalArgumentException()),
            Mono.just(ApplicationDetail.builder().diskQuota(0).id("test-application-id").instances(1)
                    .memoryLimit(0).name("test-application").requestedState("RUNNING").runningInstances(0)
                    .stack("test-stack").build()));

    givenRequestPushApplication(PushApplicationManifestRequest.builder()
            .manifest(ApplicationManifest.builder().path(resource.getFile().toPath())
                    .buildpack(deploymentProperties.getBuildpack()).disk(1024)
                    .environmentVariables(defaultEnvironmentVariables()).instances(1).memory(1024)
                    .name("test-application-id").service("test-service-2").service("test-service-1").build())
            .stagingTimeout(this.deploymentProperties.getStagingTimeout())
            .startupTimeout(this.deploymentProperties.getStartupTimeout()).build(), Mono.empty());

    String deploymentId = this.deployer
            .deploy(new AppDeploymentRequest(new AppDefinition("test-application", Collections.emptyMap()),
                    resource, Collections.singletonMap(SERVICES_PROPERTY_KEY, "'test-service-3 foo:bar'")));

    assertThat(deploymentId, equalTo("test-application-id"));
}

From source file:org.springframework.cloud.deployer.spi.cloudfoundry.CloudFoundryAppDeployerTests.java

@SuppressWarnings("unchecked")
@Test/*from   w ww  . j a  va  2 s .c o  m*/
public void deployWithAdditionalProperties() throws IOException {
    Resource resource = new FileSystemResource("src/test/resources/demo-0.0.1-SNAPSHOT.jar");

    given(this.applicationNameGenerator.generateAppName("test-application")).willReturn("test-application-id");

    givenRequestGetApplication("test-application-id", Mono.error(new IllegalArgumentException()),
            Mono.just(ApplicationDetail.builder().diskQuota(0).id("test-application-id").instances(1)
                    .memoryLimit(0).name("test-application").requestedState("RUNNING").runningInstances(0)
                    .stack("test-stack").build()));

    Map<String, String> environmentVariables = new HashMap<>();
    environmentVariables.put("test-key-1", "test-value-1");
    addGuidAndIndex(environmentVariables);

    givenRequestPushApplication(PushApplicationManifestRequest.builder()
            .manifest(ApplicationManifest.builder().path(resource.getFile().toPath())
                    .buildpack(deploymentProperties.getBuildpack()).disk(1024)
                    .environmentVariables(environmentVariables).instances(1).memory(1024)
                    .name("test-application-id").service("test-service-2").service("test-service-1").build())
            .stagingTimeout(this.deploymentProperties.getStagingTimeout())
            .startupTimeout(this.deploymentProperties.getStartupTimeout()).build(), Mono.empty());

    String deploymentId = this.deployer.deploy(new AppDeploymentRequest(
            new AppDefinition("test-application", Collections.singletonMap("test-key-1", "test-value-1")),
            resource,
            FluentMap.<String, String>builder().entry("test-key-2", "test-value-2")
                    .entry(CloudFoundryDeploymentProperties.USE_SPRING_APPLICATION_JSON_KEY,
                            String.valueOf(false))
                    .build()));

    assertThat(deploymentId, equalTo("test-application-id"));
}

From source file:org.springframework.cloud.deployer.spi.cloudfoundry.CloudFoundryAppDeployerTests.java

@SuppressWarnings("unchecked")
@Test//  ww  w  .  j  av a 2 s.  c  o m
public void deployWithAdditionalPropertiesInSpringApplicationJson() throws IOException {
    Resource resource = new FileSystemResource("src/test/resources/demo-0.0.1-SNAPSHOT.jar");

    given(this.applicationNameGenerator.generateAppName("test-application")).willReturn("test-application-id");

    givenRequestGetApplication("test-application-id", Mono.error(new IllegalArgumentException()),
            Mono.just(ApplicationDetail.builder().diskQuota(0).id("test-application-id").instances(1)
                    .memoryLimit(0).name("test-application").requestedState("RUNNING").runningInstances(0)
                    .stack("test-stack").build()));

    Map<String, String> environmentVariables = new HashMap<>();
    environmentVariables.put("SPRING_APPLICATION_JSON", "{\"test-key-1\":\"test-value-1\"}");
    addGuidAndIndex(environmentVariables);

    givenRequestPushApplication(PushApplicationManifestRequest.builder()
            .manifest(ApplicationManifest.builder().path(resource.getFile().toPath())
                    .buildpack(deploymentProperties.getBuildpack()).disk(1024)
                    .environmentVariables(environmentVariables).instances(1).memory(1024)
                    .name("test-application-id").service("test-service-2").service("test-service-1").build())
            .stagingTimeout(this.deploymentProperties.getStagingTimeout())
            .startupTimeout(this.deploymentProperties.getStartupTimeout()).build(), Mono.empty());

    String deploymentId = this.deployer.deploy(new AppDeploymentRequest(
            new AppDefinition("test-application", Collections.singletonMap("test-key-1", "test-value-1")),
            resource, Collections.singletonMap("test-key-2", "test-value-2")));

    assertThat(deploymentId, equalTo("test-application-id"));
}

From source file:org.springframework.cloud.deployer.spi.cloudfoundry.CloudFoundryAppDeployerTests.java

@SuppressWarnings("unchecked")
@Test//from   w  w  w  . j  av a  2s.co  m
public void deployWithApplicationDeploymentProperties() throws IOException {
    Resource resource = new FileSystemResource("src/test/resources/demo-0.0.1-SNAPSHOT.jar");

    given(this.applicationNameGenerator.generateAppName("test-application")).willReturn("test-application-id");

    givenRequestGetApplication("test-application-id", Mono.error(new IllegalArgumentException()),
            Mono.just(ApplicationDetail.builder().diskQuota(0).id("test-application-id").instances(1)
                    .memoryLimit(0).name("test-application").requestedState("RUNNING").runningInstances(0)
                    .stack("test-stack").build()));

    givenRequestPushApplication(PushApplicationManifestRequest.builder()
            .manifest(ApplicationManifest.builder().path(resource.getFile().toPath())
                    .buildpack("test-buildpack").disk(0).environmentVariables(defaultEnvironmentVariables())
                    .healthCheckType(ApplicationHealthCheck.NONE).instances(0).memory(0)
                    .name("test-application-id").noRoute(false).host("test-host").domain("test-domain")
                    .routePath("/test-route-path").service("test-service-2").service("test-service-1").build())
            .stagingTimeout(this.deploymentProperties.getStagingTimeout())
            .startupTimeout(this.deploymentProperties.getStartupTimeout()).build(), Mono.empty());

    String deploymentId = this.deployer.deploy(new AppDeploymentRequest(
            new AppDefinition("test-application", Collections.emptyMap()), resource,
            FluentMap.<String, String>builder().entry(BUILDPACK_PROPERTY_KEY, "test-buildpack")
                    .entry(AppDeployer.DISK_PROPERTY_KEY, "0").entry(DOMAIN_PROPERTY, "test-domain")
                    .entry(HEALTHCHECK_PROPERTY_KEY, "none").entry(HOST_PROPERTY, "test-host")
                    .entry(COUNT_PROPERTY_KEY, "0").entry(AppDeployer.MEMORY_PROPERTY_KEY, "0")
                    .entry(NO_ROUTE_PROPERTY, "false").entry(ROUTE_PATH_PROPERTY, "/test-route-path").build()));

    assertThat(deploymentId, equalTo("test-application-id"));
}

From source file:org.springframework.cloud.deployer.spi.cloudfoundry.CloudFoundryAppDeployerTests.java

@SuppressWarnings("unchecked")
@Test/*  www  .  java2  s . c  o  m*/
public void deployWithInvalidRoutePathProperty() throws IOException {
    Resource resource = new FileSystemResource("src/test/resources/demo-0.0.1-SNAPSHOT.jar");

    given(this.applicationNameGenerator.generateAppName("test-application")).willReturn("test-application-id");

    givenRequestGetApplication("test-application-id", Mono.error(new IllegalArgumentException()),
            Mono.just(ApplicationDetail.builder().diskQuota(0).id("test-application-id").instances(1)
                    .memoryLimit(0).name("test-application").requestedState("RUNNING").runningInstances(0)
                    .stack("test-stack").build()));

    givenRequestPushApplication(PushApplicationManifestRequest.builder()
            .manifest(ApplicationManifest.builder().path(resource.getFile().toPath())
                    .buildpack("test-buildpack").disk(0).environmentVariables(defaultEnvironmentVariables())
                    .healthCheckType(ApplicationHealthCheck.NONE).instances(0).memory(0)
                    .name("test-application-id").noRoute(false).host("test-host").domain("test-domain")
                    .routePath("/test-route-path").service("test-service-2").service("test-service-1").build())
            .stagingTimeout(this.deploymentProperties.getStagingTimeout())
            .startupTimeout(this.deploymentProperties.getStartupTimeout()).build(), Mono.empty());
    try {
        String deploymentId = this.deployer.deploy(new AppDeploymentRequest(
                new AppDefinition("test-application", Collections.emptyMap()), resource,
                FluentMap.<String, String>builder().entry(BUILDPACK_PROPERTY_KEY, "test-buildpack")
                        .entry(AppDeployer.DISK_PROPERTY_KEY, "0").entry(DOMAIN_PROPERTY, "test-domain")
                        .entry(HEALTHCHECK_PROPERTY_KEY, "none").entry(HOST_PROPERTY, "test-host")
                        .entry(COUNT_PROPERTY_KEY, "0").entry(AppDeployer.MEMORY_PROPERTY_KEY, "0")
                        .entry(NO_ROUTE_PROPERTY, "false").entry(ROUTE_PATH_PROPERTY, "test-route-path")
                        .build()));
        fail("Illegal Argument exception is expected.");
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage(),
                equalTo("Cloud Foundry routes must start with \"/\". Route passed = [test-route-path]."));
    }
}

From source file:org.springframework.cloud.deployer.spi.cloudfoundry.CloudFoundryAppDeployerTests.java

@SuppressWarnings("unchecked")
@Test/*from ww  w.ja va  2s.c o m*/
public void deployWithCustomDeploymentProperties() throws IOException {
    Resource resource = new FileSystemResource("src/test/resources/demo-0.0.1-SNAPSHOT.jar");

    given(this.applicationNameGenerator.generateAppName("test-application")).willReturn("test-application-id");

    givenRequestGetApplication("test-application-id", Mono.error(new IllegalArgumentException()),
            Mono.just(ApplicationDetail.builder().diskQuota(0).id("test-application-id").instances(1)
                    .memoryLimit(0).name("test-application").requestedState("RUNNING").runningInstances(0)
                    .stack("test-stack").build()));

    this.deploymentProperties.setBuildpack("test-buildpack");
    this.deploymentProperties.setDisk("0");
    this.deploymentProperties.setDomain("test-domain");
    this.deploymentProperties.setHealthCheck(ApplicationHealthCheck.NONE);
    this.deploymentProperties.setHost("test-host");
    this.deploymentProperties.setInstances(0);
    this.deploymentProperties.setMemory("0");

    givenRequestPushApplication(PushApplicationManifestRequest.builder()
            .manifest(ApplicationManifest.builder().path(resource.getFile().toPath())
                    .buildpack("test-buildpack").disk(0).domain("test-domain")
                    .environmentVariables(defaultEnvironmentVariables())
                    .healthCheckType(ApplicationHealthCheck.NONE).host("test-host").instances(0).memory(0)
                    .name("test-application-id").service("test-service-2").service("test-service-1").build())
            .stagingTimeout(this.deploymentProperties.getStagingTimeout())
            .startupTimeout(this.deploymentProperties.getStartupTimeout()).build(), Mono.empty());

    String deploymentId = this.deployer.deploy(new AppDeploymentRequest(
            new AppDefinition("test-application", Collections.emptyMap()), resource, Collections.emptyMap()));

    assertThat(deploymentId, equalTo("test-application-id"));
}

From source file:org.springframework.cloud.deployer.spi.cloudfoundry.CloudFoundryAppDeployerTests.java

@SuppressWarnings("unchecked")
@Test/*from  www .ja v  a2 s  .c  om*/
public void deployWithMultipleRoutes() throws IOException {
    Resource resource = new FileSystemResource("src/test/resources/demo-0.0.1-SNAPSHOT.jar");

    given(this.applicationNameGenerator.generateAppName("test-application")).willReturn("test-application-id");

    givenRequestGetApplication("test-application-id", Mono.error(new IllegalArgumentException()),
            Mono.just(ApplicationDetail.builder().diskQuota(0).id("test-application-id").instances(1)
                    .memoryLimit(0).name("test-application").requestedState("RUNNING").runningInstances(0)
                    .stack("test-stack").build()));

    this.deploymentProperties.setBuildpack("test-buildpack");
    this.deploymentProperties.setDisk("0");
    this.deploymentProperties.setHealthCheck(ApplicationHealthCheck.NONE);
    this.deploymentProperties.setRoutes(Sets.newHashSet("route1.test-domain", "route2.test-domain"));
    this.deploymentProperties.setInstances(0);
    this.deploymentProperties.setMemory("0");

    givenRequestPushApplication(PushApplicationManifestRequest.builder()
            .manifest(ApplicationManifest.builder().path(resource.getFile().toPath())
                    .buildpack("test-buildpack").disk(0)
                    .routes(Sets.newHashSet(Route.builder().route("route1.test-domain").build(),
                            Route.builder().route("route2.test-domain").build()))
                    .environmentVariables(defaultEnvironmentVariables())
                    .healthCheckType(ApplicationHealthCheck.NONE).instances(0).memory(0)
                    .name("test-application-id").service("test-service-2").service("test-service-1").build())
            .stagingTimeout(this.deploymentProperties.getStagingTimeout())
            .startupTimeout(this.deploymentProperties.getStartupTimeout()).build(), Mono.empty());

    String deploymentId = this.deployer.deploy(new AppDeploymentRequest(
            new AppDefinition("test-application", Collections.emptyMap()), resource, Collections.emptyMap()));

    assertThat(deploymentId, equalTo("test-application-id"));
}

From source file:org.springframework.cloud.deployer.spi.cloudfoundry.CloudFoundryAppDeployerTests.java

@SuppressWarnings("unchecked")
@Test//from w ww.  j a  va 2  s .  c  o m
public void deployWithGroup() throws IOException {
    Resource resource = new FileSystemResource("src/test/resources/demo-0.0.1-SNAPSHOT.jar");

    given(this.applicationNameGenerator.generateAppName("test-group-test-application"))
            .willReturn("test-group-test-application-id");

    givenRequestGetApplication("test-group-test-application-id", Mono.error(new IllegalArgumentException()),
            Mono.just(ApplicationDetail.builder().diskQuota(0).id("test-group-test-application-id").instances(1)
                    .memoryLimit(0).name("test-group-test-application").requestedState("RUNNING")
                    .runningInstances(0).stack("test-stack").build()));

    givenRequestPushApplication(PushApplicationManifestRequest.builder().manifest(ApplicationManifest.builder()
            .path(resource.getFile().toPath()).buildpack(deploymentProperties.getBuildpack()).disk(1024)
            .environmentVariable("SPRING_CLOUD_APPLICATION_GROUP", "test-group")
            .environmentVariable("SPRING_APPLICATION_JSON", "{}")
            .environmentVariable("SPRING_APPLICATION_INDEX", "${vcap.application.instance_index}")
            .environmentVariable("SPRING_CLOUD_APPLICATION_GUID",
                    "${vcap.application.name}:${vcap.application.instance_index}")
            .instances(1).memory(1024).name("test-group-test-application-id").service("test-service-2")
            .service("test-service-1").build()).stagingTimeout(this.deploymentProperties.getStagingTimeout())
            .startupTimeout(this.deploymentProperties.getStartupTimeout()).build(), Mono.empty());

    String deploymentId = this.deployer
            .deploy(new AppDeploymentRequest(new AppDefinition("test-application", Collections.emptyMap()),
                    resource, Collections.singletonMap(GROUP_PROPERTY_KEY, "test-group")));

    assertThat(deploymentId, equalTo("test-group-test-application-id"));
}