Example usage for org.springframework.ide.eclipse.boot.dash.cloudfoundry CloudFoundryBootDashModel getApplication

List of usage examples for org.springframework.ide.eclipse.boot.dash.cloudfoundry CloudFoundryBootDashModel getApplication

Introduction

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

Prototype

private CloudAppDashElement getApplication(IProject project) 

Source Link

Usage

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

/**
 * Test that tests a bunch of things./* www. j  a v a  2s  .  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  ava 2  s .  com*/
    };

}

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;
        }/*from   ww w . ja  va  2 s  .  c o  m*/
    };

    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));
    });//w  ww  .j a  va  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   w w w .  ja  v  a2s.  com*/

    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 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;
        }/*ww w  .j  a  va2 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 appToProjectBindingsPersisted() throws Exception {
    final String appName = "foo";
    String projectName = "to-deploy";
    CFClientParams targetParams = CfTestTargetParams.fromEnv();
    clientFactory.defSpace(targetParams.getOrgName(), targetParams.getSpaceName());
    final IProject project = projects.createBootProject(projectName, withStarters("actuator", "web"));

    harness.createCfTarget(targetParams);
    {//from w w  w .j a  va  2  s .  c o  m
        final CloudFoundryBootDashModel model = harness.getCfTargetModel();

        deployApp(model, appName, project);

        CloudAppDashElement appByProject = getApplication(model, project);
        CloudAppDashElement appByName = model.getApplication(appName);
        assertNotNull(appByProject);
        assertEquals(appByProject, appByName);
    }

    harness.reload();
    {
        final CloudFoundryBootDashModel model = harness.getCfTargetModel();
        waitForApps(model, appName);
        CloudAppDashElement appByName = model.getApplication(appName);
        CloudAppDashElement appByProject = getApplication(model, project);
        assertNotNull(appByProject);
        assertEquals(appByProject, appByName);
    }
}

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

@Test
public void appToProjectBindingChangedAfterProjectRename() throws Exception {
    final String appName = "foo";
    String projectName = "to-deploy";
    CFClientParams targetParams = CfTestTargetParams.fromEnv();
    MockCFSpace space = clientFactory.defSpace(targetParams.getOrgName(), targetParams.getSpaceName());
    space.defApp(appName);/* w  ww .  j  a  v  a 2s .  c  o  m*/
    final IProject project = projects.createProject(projectName);

    final CloudFoundryBootDashModel target = harness.createCfTarget(targetParams);
    waitForApps(target, appName);
    CloudAppDashElement app = target.getApplication(appName);
    app.setProject(project);

    assertAppToProjectBinding(target, project, appName);

    ElementStateListener elementStateListener = mock(ElementStateListener.class);
    target.addElementStateListener(elementStateListener);

    final IProject newProject = projects.rename(project, projectName + "-RENAMED");
    // resource listeners called synchronously by eclipse so we don't need ACondition

    assertAppToProjectBinding(target, newProject, appName);

    //state change event should have been fired (to update label of element in view)
    verify(elementStateListener).stateChanged(same(app));
}

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

@Test
public void appToProjectBindingForgottenAfterDelete() throws Exception {
    final String appName = "foo";
    String projectName = "to-deploy";
    CFClientParams targetParams = CfTestTargetParams.fromEnv();
    MockCFSpace space = clientFactory.defSpace(targetParams.getOrgName(), targetParams.getSpaceName());
    space.defApp(appName);//from w w  w.j a  v a  2s .  c om
    final IProject project = projects.createProject(projectName);

    final CloudFoundryBootDashModel target = harness.createCfTarget(targetParams);
    waitForApps(target, appName);
    CloudAppDashElement app = target.getApplication(appName);
    app.setProject(project);

    assertAppToProjectBinding(target, project, appName);

    ElementStateListener elementStateListener = mock(ElementStateListener.class);
    target.addElementStateListener(elementStateListener);

    project.delete(true, new NullProgressMonitor());

    assertNull(app.getProject(true));
    verify(elementStateListener).stateChanged(same(app));
}

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

@Test
public void runstateBecomesUnknownWhenStartOperationFails() throws Exception {
    final String appName = "foo";
    String projectName = "to-deploy";
    CFClientParams targetParams = CfTestTargetParams.fromEnv();
    MockCFSpace space = clientFactory.defSpace(targetParams.getOrgName(), targetParams.getSpaceName());
    MockCFApplication app = space.defApp(appName);
    final IProject project = projects.createProject(projectName);

    final CloudFoundryBootDashModel target = harness.createCfTarget(targetParams);
    waitForApps(target, appName);/*from   w  ww  . ja  v a 2 s  . com*/
    CloudAppDashElement appElement = target.getApplication(appName);
    appElement.setProject(project);

    //The state refressh is asynch so until state becomes 'INACTIVE' it will be unknown.
    waitForState(appElement, RunState.INACTIVE, 3000);
    IAction restartAction = actions.getRestartOnlyApplicationAction();

    RunStateHistory runstateHistory = new RunStateHistory();

    appElement.getBaseRunStateExp().addListener(runstateHistory);
    doThrow(IOException.class).when(app).start(any());

    System.out.println("restarting application...");
    harness.selection.setElements(appElement);
    restartAction.run();

    waitForState(appElement, RunState.UNKNOWN, 3000);

    runstateHistory.assertHistoryContains(RunState.INACTIVE, RunState.STARTING);
    runstateHistory.assertLast(RunState.UNKNOWN);
}