Example usage for org.springframework.ide.eclipse.boot.dash.test CfTestTargetParams fromEnv

List of usage examples for org.springframework.ide.eclipse.boot.dash.test CfTestTargetParams fromEnv

Introduction

In this page you can find the example usage for org.springframework.ide.eclipse.boot.dash.test CfTestTargetParams fromEnv.

Prototype

public static CFClientParams fromEnv() 

Source Link

Usage

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

@Test
public void testCreateCfTargetAndForgetPassword() throws Exception {
    CFClientParams targetParams = CfTestTargetParams.fromEnv();
    clientFactory.defSpace(targetParams.getOrgName(), targetParams.getSpaceName());

    {/*w ww .jav  a 2 s . c  o m*/
        CloudFoundryBootDashModel target = harness.createCfTarget(targetParams,
                StoreCredentialsMode.STORE_NOTHING);

        assertNotNull(target);
        assertNotNull(target.getRunTarget().getTargetProperties().getCredentials().getPassword());
        assertEquals(1, harness.getCfRunTargetModels().size());

        SecuredCredentialsStore store = harness.getCredentialsStore();
        assertFalse(store.isUnlocked()); // should not have gotten unlocked.
    }

    harness.reload();

    {
        CloudFoundryBootDashModel target = harness.getCfTargetModel();

        waitForJobsToComplete();

        assertEquals(StoreCredentialsMode.STORE_NOTHING,
                target.getRunTarget().getTargetProperties().getStoreCredentials());
        assertNotNull(target);
        assertNull(target.getRunTarget().getTargetProperties().getCredentials());
        assertFalse(target.isConnected()); // no auto connect if no creds are stored.
        { //check secure store is clean
            SecuredCredentialsStore store = harness.getCredentialsStore();
            assertFalse(store.isUnlocked()); // should not have gotten unlocked.
            String storedCred = store.getCredentials(harness.secureStoreKey(target));
            assertNull(storedCred);
        }
        { //check private store is clean
            IPropertyStore store = harness.getPrivateStore();
            String storedCred = store.get(harness.privateStoreKey(target));
            assertNull(storedCred);
        }

        verifyZeroInteractions(ui);

        //When we connect... the user should get prompted for password
        harness.answerPasswordPrompt(ui, (d) -> {
            d.getPasswordVar().setValue(targetParams.getCredentials().getPassword());
            d.performOk();
        });

        harness.sectionSelection.setValue(target);
        IAction connectAction = actions.getToggleTargetConnectionAction();
        connectAction.run();

        ACondition.waitFor("connected to target", 5_000, () -> {
            assertTrue(target.isConnected());
        });

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

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

@Test
public void testCreateCfTargetAndStoreToken() throws Exception {

    {/*  w  ww  . j a v a2  s  .c o  m*/
        CFClientParams targetParams = CfTestTargetParams.fromEnv();
        MockCFSpace space = clientFactory.defSpace(targetParams.getOrgName(), targetParams.getSpaceName());
        space.defApp("foo");
        clientFactory.defSpace(targetParams.getOrgName(), targetParams.getSpaceName());

        CloudFoundryBootDashModel target = harness.createCfTarget(targetParams,
                StoreCredentialsMode.STORE_TOKEN);
        assertNotNull(target);
        assertTrue(target.isConnected());
        assertEquals(MockCloudFoundryClientFactory.FAKE_REFRESH_TOKEN,
                target.getRunTarget().getTargetProperties().getCredentials().getRefreshToken());
        assertEquals(1, harness.getCfRunTargetModels().size());
    }

    harness.reload();

    {
        CloudFoundryBootDashModel target = harness.getCfTargetModel();

        { //secure store shouldn't have been accessed (i.e. avoid opening it and popping password)
            SecuredCredentialsStore store = harness.getCredentialsStore();
            assertFalse(store.isUnlocked());
            String key = harness.secureStoreKey(target);
            String storedCred = store.getCredentials(key);
            assertNull(storedCred);
        }
        {
            IPropertyStore store = harness.getPrivateStore();
            String key = harness.privateStoreKey(target);
            String storedCred = store.get(key);
            assertEquals(MockCloudFoundryClientFactory.FAKE_REFRESH_TOKEN, storedCred);
        }

        assertNotNull(target);
        assertEquals(MockCloudFoundryClientFactory.FAKE_REFRESH_TOKEN,
                target.getRunTarget().getTargetProperties().getCredentials().getRefreshToken());
        assertEquals(StoreCredentialsMode.STORE_TOKEN,
                target.getRunTarget().getTargetProperties().getStoreCredentials());

        waitForJobsToComplete();
        assertTrue(target.isConnected()); //should auto connect.
        verifyZeroInteractions(ui); //should not prompt for password (but used stored token).
    }
}

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

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

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

    space.defApp("foo");
    space.defApp("bar");

    final CloudFoundryBootDashModel target = harness.createCfTarget(targetParams);

    new ACondition("wait for apps to appear", 3000) {
        @Override//from w  w  w  . j  a v a 2 s . com
        public boolean test() throws Exception {
            ImmutableSet<String> appNames = getNames(target.getApplications().getValues());
            assertEquals(ImmutableSet.of("foo", "bar"), appNames);
            return true;
        }
    };
}

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

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

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

    space.defApp("foo");
    space.defApp("bar");

    final CloudFoundryBootDashModel target = harness.createCfTarget(targetParams);

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

    space.defApp("anotherfoo");
    space.defApp("anotherbar");
    target.refresh(ui);/*from  w w w .ja v a2s .  co  m*/

    waitForApps(target, "foo", "bar", "anotherfoo", "anotherbar");
}

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);/*w  w  w  .  j a v  a2 s.co  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 testRefreshAppsHealthCheck() throws Exception {
    CFClientParams targetParams = CfTestTargetParams.fromEnv();

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

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

    final CloudFoundryBootDashModel target = harness.createCfTarget(targetParams);

    waitForApps(target, "foo");

    CloudAppDashElement appElement = harness.getCfTargetModel().getApplication("foo");
    assertEquals(HealthChecks.HC_PORT, appElement.getHealthCheck());

    foo.setHealthCheck(HealthChecks.HC_NONE);

    target.refresh(ui);// w  w  w  . jav a2  s  .c o  m

    new ACondition("wait for app health check", 3000) {
        @Override
        public boolean test() throws Exception {
            ImmutableSet<String> appNames = getNames(target.getApplications().getValues());
            assertEquals(ImmutableSet.of("foo"), appNames);

            CloudAppDashElement appElement = harness.getCfTargetModel().getApplication("foo");
            assertEquals(HealthChecks.HC_NONE, appElement.getHealthCheck());

            return true;
        }
    };
}

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

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

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

    space.defApp("foo");
    space.defService("elephantsql");
    space.defService("cleardb");

    final CloudFoundryBootDashModel target = harness.createCfTarget(targetParams);

    waitForApps(target, "foo");
    waitForServices(target, "elephantsql", "cleardb");
    waitForElements(target, "foo", "elephantsql", "cleardb");

    space.defService("rabbit");

    target.refresh(ui);//from  w  ww .  java2 s .  co  m
    waitForServices(target, "elephantsql", "cleardb", "rabbit");
    waitForElements(target, "foo", "elephantsql", "cleardb", "rabbit");
}

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

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

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

    space.defApp("foo");
    space.defApp("bar");
    space.defService("a-sql");
    space.defService("z-rabbit");

    final CloudFoundryBootDashModel target = harness.createCfTarget(targetParams);
    assertTrue(target.isConnected());// www  . j a v  a2 s  . com

    debugListener("applications", target.getApplications());
    debugListener("services", target.getServices());
    debugListener("all", target.getElements());

    new ACondition("wait for elements to appear", 3000) {
        @Override
        public boolean test() throws Exception {
            ImmutableSet<String> appNames = getNames(target.getApplications().getValues());
            ImmutableSet<String> serviceNames = getNames(target.getServices().getValues());
            ImmutableSet<String> allNames = getNames(target.getElements().getValues());
            assertEquals(ImmutableSet.of("foo", "bar"), appNames);
            assertEquals(ImmutableSet.of("a-sql", "z-rabbit"), serviceNames);
            assertEquals(ImmutableSet.of("foo", "bar", "a-sql", "z-rabbit"), allNames);
            return true;
        }
    };

    //Also test we sort this stuff in the right order.

    ArrayList<BootDashElement> elements = new ArrayList<>(target.getElements().getValues());
    Collections.sort(elements, target.getElementComparator());
    assertNames(elements,
            //first apps... alphabetic
            "bar", "foo",
            //then services... alphabetic
            "a-sql", "z-rabbit");

    //For https://www.pivotaltracker.com/story/show/114408475
    // Apps and services should disappear when target is disconnected

    IAction toggleConnection = actions.getToggleTargetConnectionAction();
    harness.sectionSelection.setValue(target);
    toggleConnection.run();

    new ACondition("wait for elements to disappear", 10000) {
        @Override
        public boolean test() throws Exception {
            assertFalse(target.isConnected());
            ImmutableSet<String> appNames = getNames(target.getApplications().getValues());
            ImmutableSet<String> serviceNames = getNames(target.getServices().getValues());
            ImmutableSet<String> allNames = getNames(target.getElements().getValues());
            assertEquals(ImmutableSet.of(), appNames);
            assertEquals(ImmutableSet.of(), serviceNames);
            assertEquals(ImmutableSet.of(), allNames);
            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;
        }// ww w  . j  a v  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 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);
    {// w ww.  j a v a2 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);
    }
}