Example usage for org.springframework.ide.eclipse.boot.dash.cloudfoundry CloudAppDashElement getRunState

List of usage examples for org.springframework.ide.eclipse.boot.dash.cloudfoundry CloudAppDashElement getRunState

Introduction

In this page you can find the example usage for org.springframework.ide.eclipse.boot.dash.cloudfoundry CloudAppDashElement getRunState.

Prototype

@Override
    public RunState getRunState() 

Source Link

Usage

From source file:org.springframework.ide.eclipse.boot.dash.test.CloudFoundryBootDashModelIntegrationTest.java

/**
 * Test that tests a bunch of things.//from   w ww. ja v  a2s .c om
 * TODO: It isn't good practice to create 'test everything' tests...
 * but we do it anyway because ramping up a test that deploys an app takes about 90 seconds...
 * Maybe we can factor this better somehow so we have separate tests, but only deploy app once?
 */
@Test
public void testDeployAppAndDeleteAndStuff() throws Exception {
    harness.createCfTarget(CfTestTargetParams.fromEnv());
    final CloudFoundryBootDashModel model = harness.getCfTargetModel();

    final BootProjectDashElement project = harness
            .getElementFor(projects.createBootProject("to-deploy", withStarters("actuator", "web")));
    final String appName = appHarness.randomAppName();

    harness.answerDeploymentPrompt(ui, appName, appName);
    model.add(ImmutableList.<Object>of(project), ui);

    //The resulting deploy is asynchronous
    new ACondition("wait for app '" + appName + "'to appear", APP_IS_VISIBLE_TIMEOUT) {
        public boolean test() throws Exception {
            assertNotNull(model.getApplication(appName));
            return true;
        }
    };

    new ACondition("wait for app '" + appName + "'to be RUNNING", APP_DEPLOY_TIMEOUT) {
        public boolean test() throws Exception {
            CloudAppDashElement element = model.getApplication(appName);
            assertEquals(RunState.RUNNING, element.getRunState());
            return true;
        }
    };

    //Try to get request mappings
    new ACondition("wait for request mappings", FETCH_REQUEST_MAPPINGS_TIMEOUT) {
        public boolean test() throws Exception {
            CloudAppDashElement element = model.getApplication(appName);
            List<RequestMapping> mappings = element.getLiveRequestMappings();
            assertNotNull(mappings); //Why is the test sometimes failing here?
            assertTrue(!mappings.isEmpty()); //Even though this is an 'empty' app should have some mappings,
                                             // for example an 'error' page.
            return true;
        }
    };

    //Try to delete the app...
    reset(ui);
    when(ui.confirmOperation(eq("Deleting Elements"), anyString())).thenReturn(true);

    CloudAppDashElement app = model.getApplication(appName);
    app.getCloudModel().delete(ImmutableList.<BootDashElement>of(app), ui);

    new ACondition("wait for app to be deleted", APP_DELETE_TIMEOUT) {

        @Override
        public boolean test() throws Exception {
            assertNull(model.getApplication(appName));
            return true;
        }
    };
}

From source file:org.springframework.ide.eclipse.boot.dash.test.CloudFoundryBootDashModelIntegrationTest.java

@Test
public void testDeployAppIntoDebugMode() throws Exception {
    harness.createCfTarget(CfTestTargetParams.fromEnv());
    final CloudFoundryBootDashModel model = harness.getCfTargetModel();

    final BootProjectDashElement project = harness
            .getElementFor(projects.createBootProject("to-deploy", withStarters("actuator", "web")));
    final String appName = appHarness.randomAppName();

    harness.answerDeploymentPrompt(ui, appName, appName);
    model.performDeployment(ImmutableSet.of(project.getProject()), ui, RunState.DEBUGGING);

    new ACondition("wait for app '" + appName + "'to be DEBUGGING", APP_DEPLOY_TIMEOUT) {
        public boolean test() throws Exception {
            CloudAppDashElement element = model.getApplication(appName);
            assertEquals(RunState.DEBUGGING, element.getRunState());
            return true;
        }/*from   w w  w  . j a v  a2s . c  o m*/
    };

}

From source file:org.springframework.ide.eclipse.boot.dash.test.CloudFoundryBootDashModelIntegrationTest.java

@Test
public void testEnvVarsSetOnFirstDeploy() throws Exception {
    CloudFoundryBootDashModel target = harness.createCfTarget(CfTestTargetParams.fromEnv());
    final CloudFoundryBootDashModel model = harness.getCfTargetModel();

    IProject project = projects.createBootProject("to-deploy", withStarters("actuator", "web"));

    final String appName = appHarness.randomAppName();

    Map<String, String> env = new HashMap<>();
    env.put("FOO", "something");
    harness.answerDeploymentPrompt(ui, appName, appName, env);

    model.performDeployment(ImmutableSet.of(project), ui, RunState.RUNNING);

    new ACondition("wait for app '" + appName + "'to be RUNNING", APP_DEPLOY_TIMEOUT) {
        public boolean test() throws Exception {
            CloudAppDashElement element = model.getApplication(appName);
            assertEquals(RunState.RUNNING, element.getRunState());
            return true;
        }//ww  w.ja  va2  s.  com
    };

    Map<String, String> actualEnv = harness.fetchEnvironment(target, appName);

    assertEquals("something", actualEnv.get("FOO"));
}

From source file:org.springframework.ide.eclipse.boot.dash.test.CloudFoundryBootDashModelIntegrationTest.java

@Test
public void testServicesBoundOnFirstDeploy() throws Exception {
    CloudFoundryBootDashModel target = harness.createCfTarget(CfTestTargetParams.fromEnv());
    final CloudFoundryBootDashModel model = harness.getCfTargetModel();

    IProject project = projects.createBootProject("to-deploy", withStarters("actuator", "web"));

    List<String> bindServices = ImmutableList.of(services.createTestService(), services.createTestService());
    ACondition.waitFor("services exist " + bindServices, 30_000, () -> {
        Set<String> services = client.getServices().stream().map(CFServiceInstance::getName)
                .collect(Collectors.toSet());
        System.out.println("services = " + services);
        assertTrue(services.containsAll(bindServices));
    });/*from  w  w  w  .  j  a v  a 2  s.  c o  m*/

    final String appName = appHarness.randomAppName();

    harness.answerDeploymentPrompt(ui, appName, appName, bindServices);

    model.performDeployment(ImmutableSet.of(project), ui, RunState.RUNNING);

    new ACondition("wait for app '" + appName + "'to be RUNNING", APP_DEPLOY_TIMEOUT) {
        public boolean test() throws Exception {
            CloudAppDashElement element = model.getApplication(appName);
            assertEquals(RunState.RUNNING, element.getRunState());
            return true;
        }
    };

    Set<String> actualServices = client.getBoundServicesSet(appName).block();

    assertEquals(ImmutableSet.copyOf(bindServices), actualServices);
}

From source file:org.springframework.ide.eclipse.boot.dash.test.CloudFoundryBootDashModelIntegrationTest.java

@Test
public void testDeployManifestWithAbsolutePathAttribute() throws Exception {
    CFClientParams targetParams = CfTestTargetParams.fromEnv();
    IProject project = projects.createProject("to-deploy");

    CloudFoundryBootDashModel model = harness.createCfTarget(targetParams);

    waitForJobsToComplete();/*from ww w  . j  a  v a 2 s.co  m*/

    File zipFile = getTestZip("testapp");
    final String appName = appHarness.randomAppName();
    IFile manifestFile = createFile(project, "manifest.yml", "applications:\n" + "- name: " + appName + "\n"
            + "  path: " + zipFile.getAbsolutePath() + "\n" + "  buildpack: staticfile_buildpack");
    harness.answerDeploymentPrompt(ui, manifestFile);
    model.performDeployment(ImmutableSet.of(project), ui, RunState.RUNNING);

    ACondition.waitFor("app to appear", APP_IS_VISIBLE_TIMEOUT, () -> {
        assertNotNull(model.getApplication(appName));
    });

    CloudAppDashElement app = model.getApplication(appName);

    ACondition.waitFor("app to be running", APP_DEPLOY_TIMEOUT, () -> {
        assertEquals(RunState.RUNNING, app.getRunState());
        String url = pathJoin(app.getUrl(), "test.txt");
        assertEquals(url, "some content here\n", IOUtils.toString(new URL(url)));
    });

    verify(ui).promptApplicationDeploymentProperties(any());
    verifyNoMoreInteractions(ui);
}

From source file:org.springframework.ide.eclipse.boot.dash.test.CloudFoundryBootDashModelMockingTest.java

@Test
public void testRefreshAppsRunState() throws Exception {
    CFClientParams targetParams = CfTestTargetParams.fromEnv();

    MockCFSpace space = clientFactory.defSpace(targetParams.getOrgName(), targetParams.getSpaceName());

    final MockCFApplication foo = space.defApp("foo");
    space.defApp("bar");

    final CloudFoundryBootDashModel target = harness.createCfTarget(targetParams);

    waitForApps(target, "foo", "bar");

    foo.start(CancelationTokens.NULL);/*from   w w w .  j  a  v  a2 s . c o m*/

    target.refresh(ui);

    new ACondition("wait for app states", 3000) {
        @Override
        public boolean test() throws Exception {
            ImmutableSet<String> appNames = getNames(target.getApplications().getValues());
            assertEquals(ImmutableSet.of("foo", "bar"), appNames);
            CloudAppDashElement appElement = harness.getCfTargetModel().getApplication("foo");
            assertEquals(RunState.RUNNING, appElement.getRunState());

            appElement = harness.getCfTargetModel().getApplication("bar");
            assertEquals(RunState.INACTIVE, appElement.getRunState());

            return true;
        }
    };
}

From source file:org.springframework.ide.eclipse.boot.dash.test.CloudFoundryBootDashModelMockingTest.java

@Test
public void testEnvVarsSetOnFirstDeploy() throws Exception {
    CFClientParams targetParams = CfTestTargetParams.fromEnv();
    clientFactory.defSpace(targetParams.getOrgName(), targetParams.getSpaceName());
    CloudFoundryBootDashModel target = harness.createCfTarget(targetParams);
    final CloudFoundryBootDashModel model = harness.getCfTargetModel();

    IProject project = projects.createBootProject("to-deploy", withStarters("actuator", "web"));

    final String appName = appHarness.randomAppName();

    Map<String, String> env = new HashMap<>();
    env.put("FOO", "something");
    harness.answerDeploymentPrompt(ui, appName, appName, env);

    model.performDeployment(ImmutableSet.of(project), ui, RunState.RUNNING);

    new ACondition("wait for app '" + appName + "'to be RUNNING", 30000) { //why so long? JDT searching for main type.
        public boolean test() throws Exception {
            CloudAppDashElement element = model.getApplication(appName);
            assertEquals(RunState.RUNNING, element.getRunState());
            return true;
        }/*from   w  ww  . j av a 2 s.  c  om*/
    };

    Map<String, String> actualEnv = harness.fetchEnvironment(target, appName);

    assertEquals("something", actualEnv.get("FOO"));
}

From source file:org.springframework.ide.eclipse.boot.dash.test.CloudFoundryBootDashModelMockingTest.java

@Test
public void stopCancelsDeploy() throws Exception {
    CFClientParams targetParams = CfTestTargetParams.fromEnv();
    clientFactory.defSpace(targetParams.getOrgName(), targetParams.getSpaceName());
    CloudFoundryBootDashModel model = harness.createCfTarget(targetParams);

    IProject project = projects.createBootProject("to-deploy", withStarters("actuator", "web"));

    final String appName = appHarness.randomAppName();

    clientFactory.setAppStartDelay(TimeUnit.MINUTES, 2);
    harness.answerDeploymentPrompt(ui, appName, appName);
    model.performDeployment(ImmutableSet.of(project), ui, RunState.RUNNING);
    waitForApps(model, appName);/*w  w  w.  j a v a 2 s .  c o  m*/

    CloudAppDashElement app = model.getApplication(appName);

    waitForState(app, RunState.STARTING, 3000);

    ACondition.waitFor("stop hammering", 20000, () -> {
        app.stopAsync(ui);
        assertEquals(RunState.INACTIVE, app.getRunState());
    });

    //TODO: can we check that deployment related jobs are really canceled/finished somehow?
    //   can we check that they didn't pop errors?
}

From source file:org.springframework.ide.eclipse.boot.dash.test.CloudFoundryBootDashModelMockingTest.java

@Test
public void acceptDeployOfExistingApp() throws Exception {
    CFClientParams targetParams = CfTestTargetParams.fromEnv();
    MockCFSpace space = clientFactory.defSpace(targetParams.getOrgName(), targetParams.getSpaceName());
    IProject project = projects.createBootProject("to-deploy", withStarters("actuator", "web"));
    final String appName = "foo";
    MockCFApplication deployedApp = space.defApp(appName);

    CloudFoundryBootDashModel model = harness.createCfTarget(targetParams);
    waitForApps(model, appName);//from   ww  w .ja  v  a  2 s  .  c o m
    CloudAppDashElement app = model.getApplication(appName);
    app.setProject(null);
    assertNull(app.getProject());

    assertEquals(RunState.INACTIVE, app.getRunState());

    harness.answerDeploymentPrompt(ui, appName, appName);
    Mockito.doReturn(true).when(ui).confirmOperation(same("Replace Existing Application"), any());
    model.performDeployment(ImmutableSet.of(project), ui, RunState.RUNNING);

    System.out.println(app.getRunState());
    waitForJobsToComplete();
    System.out.println(app.getRunState());
    assertEquals(project, app.getProject());
    assertEquals(1, deployedApp.getPushCount());

    verify(ui).confirmOperation(any(), any());
}

From source file:org.springframework.ide.eclipse.boot.dash.test.CloudFoundryBootDashModelMockingTest.java

@Test
public void manifestDiffDialogChooseUseManfifest() throws Exception {
    //Setup initial state for our test
    final String appName = "foo";
    CFClientParams targetParams = CfTestTargetParams.fromEnv();
    MockCFSpace space = clientFactory.defSpace(targetParams.getOrgName(), targetParams.getSpaceName());

    IProject project = projects.createBootProject("to-deploy", withStarters("web", "actuator"));
    IFile manifest = createFile(project, "manifest.yml",
            "applications:\n" + "- name: " + appName + "\n" + "  memory: 1111M\n");

    harness.answerDeploymentPrompt(ui, manifest);

    CloudFoundryBootDashModel model = harness.createCfTarget(targetParams);
    model.performDeployment(ImmutableSet.of(project), ui, RunState.RUNNING);

    waitForApps(model, appName);//from  w  ww  .j a  v  a  2  s  . c  o  m
    CloudAppDashElement app = model.getApplication(appName);
    waitForState(app, RunState.RUNNING, APP_DEPLOY_TIMEOUT);

    {
        MockCFApplication appInCloud = space.getApplication(appName);
        assertEquals(1111, appInCloud.getMemory());
        Mockito.reset(ui);

        //// real test begins here

        appInCloud.setMemory(2222);
    }

    harness.answerManifestDiffDialog(ui, (ManifestDiffDialogModel dialog) -> {
        //??? code to check what's in the dialog???
        return ManifestDiffDialogModel.Result.USE_MANIFEST;
    });

    app.restart(RunState.RUNNING, ui);

    waitForJobsToComplete();
    {
        MockCFApplication appInCloud = space.getApplication(appName);
        assertEquals(2, appInCloud.getPushCount());
        assertEquals(RunState.RUNNING, app.getRunState());
        assertEquals(1111, appInCloud.getMemory());
        assertEquals(1111, (int) app.getMemory());
    }
}