Example usage for org.springframework.ide.eclipse.boot.dash.views CustmomizeTargetLabelAction isVisible

List of usage examples for org.springframework.ide.eclipse.boot.dash.views CustmomizeTargetLabelAction isVisible

Introduction

In this page you can find the example usage for org.springframework.ide.eclipse.boot.dash.views CustmomizeTargetLabelAction isVisible.

Prototype

public boolean isVisible() 

Source Link

Usage

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

@Test
public void customizeTargetLabelAction() throws Exception {
    clientFactory.defSpace("my-org", "foo");
    clientFactory.defSpace("your-org", "bar");

    String apiUrl = "http://api.some-cloud.com";
    String username = "freddy";
    String password = "whocares";
    LocalBootDashModel local = harness.getLocalModel();
    AbstractBootDashModel fooSpace = harness.createCfTarget(new CFClientParams(apiUrl, username,
            CFCredentials.fromPassword(password), false, "my-org", "foo", false));
    AbstractBootDashModel barSpace = harness.createCfTarget(new CFClientParams(apiUrl, username,
            CFCredentials.fromPassword(password), false, "your-org", "bar", false));
    CustmomizeTargetLabelAction action = actions.getCustomizeTargetLabelAction();

    //////////// not applicable for local targets:

    harness.sectionSelection.setValue(local);
    assertFalse(action.isEnabled());//from   w  w  w.  j a  v  a 2 s . c om
    assertFalse(action.isVisible());

    //////////// for cf targets //////////////////////////////////////////////////

    harness.sectionSelection.setValue(fooSpace);
    assertTrue(action.isEnabled());
    assertTrue(action.isVisible());

    ModelStateListener modelStateListener = mock(ModelStateListener.class);
    fooSpace.addModelStateListener(modelStateListener);
    barSpace.addModelStateListener(modelStateListener);

    doAnswer(editSetTemplate("%s - %o @ %a")).when(ui)
            .openEditTemplateDialog(any(EditTemplateDialogModel.class));

    action.run();

    //Changing the template should result in modelStateListener firing on all the affected models
    verify(modelStateListener).stateChanged(same(fooSpace));
    verify(modelStateListener).stateChanged(same(barSpace));

    assertEquals("foo - my-org @ http://api.some-cloud.com", fooSpace.getDisplayName());
    assertEquals("bar - your-org @ http://api.some-cloud.com", barSpace.getDisplayName());

    //Let's also try a user interaction that involves the 'Restore Defaults' button...

    reset(ui, modelStateListener);

    doAnswer(restoreDefaultTemplate()).when(ui).openEditTemplateDialog(any(EditTemplateDialogModel.class));

    action.run();

    verify(modelStateListener).stateChanged(same(fooSpace));
    verify(modelStateListener).stateChanged(same(barSpace));

    assertEquals("my-org : foo - [http://api.some-cloud.com]", fooSpace.getDisplayName());
    assertEquals("your-org : bar - [http://api.some-cloud.com]", barSpace.getDisplayName());
}