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

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

Introduction

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

Prototype

@Override
    public ObservableSet<BootDashElement> getElements() 

Source Link

Usage

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());//from w w w.j av  a  2 s .c o m

    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

protected void waitForElements(final CloudFoundryBootDashModel target, final String... names) throws Exception {
    new ACondition("wait for elements to appear", 3000) {
        @Override//from  w  ww  .  ja va2 s.c  om
        public boolean test() throws Exception {
            ImmutableSet<String> elements = getNames(target.getElements().getValues());
            assertEquals(ImmutableSet.copyOf(names), elements);
            return true;
        }
    };
}