List of usage examples for org.springframework.ide.eclipse.boot.dash.cloudfoundry.client CFCredentials fromPassword
@Deprecated public static CFCredentials fromPassword(String password)
From source file:org.springframework.ide.eclipse.boot.dash.cloudfoundry.CloudFoundryTargetWizardModel.java
/** * Create target properties based on current input values in the wizard. * <p>// w ww . jav a2 s.com * Note that there are two slightly different ways to produce these properties. * <p> * a) to create a intermediate client just to fetch orgs and spaces. * <p> * b) the final properties used to create the client after space is selected and the user * clicks 'finish' button. */ private CloudFoundryTargetProperties createTargetProperties(boolean toFetchSpaces) throws CannotAccessPropertyException { CloudFoundryTargetProperties targetProps = new CloudFoundryTargetProperties(runTargetType, context); if (!toFetchSpaces) { //Take care: when fetching spaces the space may not be known yet, so neither is the id String id = CloudFoundryTargetProperties.getId(this.getUsername(), this.getUrl(), this.getOrganizationName(), this.getSpaceName()); targetProps.put(TargetProperties.RUN_TARGET_ID, id); } targetProps.setUrl(url.getValue()); targetProps.setSelfSigned(selfsigned.getValue()); targetProps.setSkipSslValidation(skipSslValidation.getValue()); targetProps.setUserName(userName.getValue()); if (toFetchSpaces) { targetProps.setStoreCredentials(StoreCredentialsMode.STORE_NOTHING); targetProps.setCredentials(CFCredentials.fromLogin(method.getValue(), password.getValue())); } else { //use credentials of a style that is consistent with the 'store mode'. if (method.getValue() == LoginMethod.TEMPORARY_CODE && storeCredentials.getValue() == StoreCredentialsMode.STORE_PASSWORD) { //The one token shouldn't be stored since its meaningless. Silently downgrade storemode to store storeCredentials.setValue(StoreCredentialsMode.STORE_NOTHING); } StoreCredentialsMode mode = storeCredentials.getValue(); targetProps.setStoreCredentials(storeCredentials.getValue()); switch (mode) { case STORE_NOTHING: case STORE_TOKEN: Assert.isTrue(refreshToken != null); targetProps.setCredentials(CFCredentials.fromRefreshToken(refreshToken)); break; case STORE_PASSWORD: targetProps.setCredentials(CFCredentials.fromPassword(password.getValue())); break; default: throw new IllegalStateException("BUG: Missing switch case?"); } } targetProps.setSpace(space.getValue()); return targetProps; }
From source file:org.springframework.ide.eclipse.boot.dash.test.CloudFoundryBootDashModelMockingTest.java
@Test public void testDeployActionsSorted() throws Exception { //Generate some random 'space' names. String orgName = "CloudRunAMock"; String[] spaceNames = new String[6]; for (int i = 0; i < spaceNames.length; i++) { spaceNames[i] = RandomStringUtils.randomAlphabetic(10).toLowerCase(); }/* ww w.ja v a 2 s .com*/ //Define the spaces in the 'mock' cloud: for (String spaceName : spaceNames) { //Since this is just a mock client we creating, the params don't matter all that much at all. clientFactory.defSpace(orgName, spaceName); } //Create targets in the boot dash that connect to these spaces: for (String spaceName : spaceNames) { CFClientParams params = new CFClientParams("http://api.run.cloud.mock.com", "some-user", CFCredentials.fromPassword("his-password"), false, orgName, spaceName, false); harness.createCfTarget(params); } { ImmutableList<IAction> deployActions = actions.getDebugOnTargetActions(); assertEquals(spaceNames.length, deployActions.size()); assertSorted(deployActions); } { ImmutableList<IAction> deployActions = actions.getRunOnTargetActions(); assertEquals(spaceNames.length, deployActions.size()); assertSorted(deployActions); } }
From source file:org.springframework.ide.eclipse.boot.dash.test.CloudFoundryBootDashModelMockingTest.java
@Test public void appsManagerDefaultHost() throws Exception { MockCFSpace space = clientFactory.defSpace("my-org", "foo"); String apiUrl = "http://api.some-cloud.com"; String username = "freddy"; String password = "whocares"; CloudFoundryBootDashModel cfModel = harness.createCfTarget(new CFClientParams(apiUrl, username, CFCredentials.fromPassword(password), false, "my-org", "foo", false)); assertEquals("http://console.some-cloud.com", cfModel.getRunTarget().getAppsManagerHost()); assertEquals("http://console.some-cloud.com", cfModel.getRunTarget().getAppsManagerHostDefault()); assertEquals("http://console.some-cloud.com/organizations/" + space.getOrganization().getGuid() + "/spaces/" + space.getGuid(), cfModel.getRunTarget().getAppsManagerURL()); }
From source file:org.springframework.ide.eclipse.boot.dash.test.CloudFoundryBootDashModelMockingTest.java
@Test public void appsManagerCustomizedHost() throws Exception { MockCFSpace space = clientFactory.defSpace("my-org", "foo"); String apiUrl = "http://api.some-cloud.com"; String username = "freddy"; String password = "whocares"; CloudFoundryBootDashModel cfModel = harness.createCfTarget(new CFClientParams(apiUrl, username, CFCredentials.fromPassword(password), false, "my-org", "foo", false)); cfModel.getRunTarget().setAppsManagerHost("http://totallyDifferentHost.com"); assertEquals("http://totallyDifferentHost.com", cfModel.getRunTarget().getAppsManagerHost()); assertEquals("http://console.some-cloud.com", cfModel.getRunTarget().getAppsManagerHostDefault()); assertEquals("http://totallyDifferentHost.com/organizations/" + space.getOrganization().getGuid() + "/spaces/" + space.getGuid(), cfModel.getRunTarget().getAppsManagerURL()); }
From source file:org.springframework.ide.eclipse.boot.dash.test.CloudFoundryBootDashModelMockingTest.java
@Test public void templateDrivenTargetNames() 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"; 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)); //check the default rendering is like it used to be before introducing templates. assertEquals("my-org : foo - [http://api.some-cloud.com]", fooSpace.getDisplayName()); assertEquals("your-org : bar - [http://api.some-cloud.com]", barSpace.getDisplayName()); RunTargetType targetType = fooSpace.getRunTarget().getType(); //Let's try switching the order of org and space targetType.setNameTemplate("%s - %o @ %a"); assertEquals("foo - my-org @ http://api.some-cloud.com", fooSpace.getDisplayName()); assertEquals("bar - your-org @ http://api.some-cloud.com", barSpace.getDisplayName()); //Let's try adding 'username' into the label targetType.setNameTemplate("%u@%s"); assertEquals("freddy@foo", fooSpace.getDisplayName()); assertEquals("freddy@bar", barSpace.getDisplayName()); }
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());// w w w . ja v a2s .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()); }
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 av a 2 s.c om*/ 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()); }