List of usage examples for org.springframework.ide.eclipse.boot.dash.model AbstractBootDashModel addModelStateListener
public void addModelStateListener(BootDashModel.ModelStateListener l)
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 av a 2 s .c o m 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()); }
From source file:org.springframework.ide.eclipse.boot.dash.test.CloudFoundryBootDashModelMockingTest.java
@Test public void customizeTargetLabelDialog() throws Exception { EditTemplateDialogModel dialog;//from w w w . j ava 2s . c o m clientFactory.defSpace("my-org", "foo"); clientFactory.defSpace("your-org", "bar"); String apiUrl = "http://api.some-cloud.com"; String username = "freddy"; String password = "whocares"; 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)); ModelStateListener modelStateListener = mock(ModelStateListener.class); fooSpace.addModelStateListener(modelStateListener); barSpace.addModelStateListener(modelStateListener); // Check initial state of the dialog when no custom labels have yet been set at all: dialog = CustomizeTargetLabelDialogModel.create(fooSpace); assertTrue(dialog.applyToAll.getValue()); assertEquals("%o : %s - [%a]", dialog.template.getValue()); //Check performOk only changes the one label when 'apply to all' is disabled. dialog.applyToAll.setValue(false); dialog.template.setValue("CHANGED %s -> %o"); dialog.performOk(); verify(modelStateListener).stateChanged(same(fooSpace)); verify(modelStateListener, never()).stateChanged(same(barSpace)); assertEquals("CHANGED foo -> my-org", fooSpace.getDisplayName()); assertEquals("your-org : bar - [http://api.some-cloud.com]", barSpace.getDisplayName()); //Opening the dialog now should have 'apply to all' disabled to avoid accidentally overwriting // existing individually customized labels... dialog = CustomizeTargetLabelDialogModel.create(fooSpace); assertFalse(dialog.applyToAll.getValue()); assertEquals("CHANGED %s -> %o", dialog.template.getValue()); //Also if we open the dialog on the other element!!! dialog = CustomizeTargetLabelDialogModel.create(barSpace); assertFalse(dialog.applyToAll.getValue()); assertEquals("%o : %s - [%a]", dialog.template.getValue()); //Selecting 'apply to all' should set the template on the type and erase custom templates on the // individual targets. dialog.applyToAll.setValue(true); dialog.template.setValue("DIFFERENT %s -> %o"); dialog.performOk(); assertEquals("DIFFERENT %s -> %o", harness.getCfTargetType().getNameTemplate()); for (BootDashModel target : harness.getCfRunTargetModels()) { assertFalse(target.hasCustomNameTemplate()); assertEquals("DIFFERENT %s -> %o", target.getNameTemplate()); } assertEquals("DIFFERENT foo -> my-org", fooSpace.getDisplayName()); assertEquals("DIFFERENT bar -> your-org", barSpace.getDisplayName()); }