Skip to content

Commit

Permalink
Adding getServerRuntime in RuntimePref page
Browse files Browse the repository at this point in the history
 - fixes #1711

Signed-off-by: Ondrej Dockal <odockal@redhat.com>
  • Loading branch information
odockal authored and rawagner committed Mar 19, 2018
1 parent 9a18c81 commit 8b70be5
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 3 deletions.
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017 Red Hat, Inc and others.
* Copyright (c) 2018 Red Hat, Inc and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand All @@ -12,6 +12,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import org.eclipse.reddeer.common.logging.Logger;
import org.eclipse.reddeer.common.wait.TimePeriod;
Expand Down Expand Up @@ -71,6 +72,47 @@ public List<Runtime> getServerRuntimes(){
return runtimes;
}

/**
* Returns server runtime based on passed name and type
* @param name string parameters representing name of the runtime
* @param type string type of runtime
* @return runtime object fulfilling conditions of equality
*/
public Runtime getServerRuntime(String name, String type) {
return getServerRuntime(new Runtime(name, type));
}

/**
* Returns server runtime based on passed runtime
* @param runtime runtime object to find
* @return runtime object if equals to passed parameter, null if there is none or
* throws an exception if there are more than one runtime found
*/
public Runtime getServerRuntime(Runtime runtime) {
List<Runtime> resultRuntimes = getServerRuntimes()
.stream()
.filter((run) -> run.equals(runtime))
.collect(Collectors.toList());
return resultRuntimes.isEmpty() ? null : resultRuntimes.get(0);
}

/**
* Returns server runtime based on its name.
* @param name string name parameter
* @return runtime object if equals to passed parameter, null if there is none or
* throws an exception if there are more than one runtime found
*/
public Runtime getServerRuntime(String name) {
List<Runtime> resultRuntimes = getServerRuntimes()
.stream()
.filter((runtime) -> runtime.getName().equals(name))
.collect(Collectors.toList());
if (resultRuntimes.size() > 1) {
throw new EclipseLayerException("There are more than one runtime fulfilling conditions. Result is ambiguous.");
}
return resultRuntimes.isEmpty() ? null : resultRuntimes.get(0);
}

/**
* Removes a given runtime.
*
Expand Down Expand Up @@ -115,7 +157,7 @@ private RuntimePreferencePage selectRuntime(String name){
return this;
}
}
throw new EclipseLayerException("Unable to find runtime "+name);
throw new EclipseLayerException("Unable to find runtime " + name);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions tests/org.eclipse.reddeer.eclipse.test/plugin.xml
Expand Up @@ -17,6 +17,8 @@
<moduleType types="PHP" versions="1.0"/>
<moduleType types="wst.web" versions="1.0"/>
</runtimeType>
<runtimeType id="org.eclipse.reddeer.eclipse.test.wst.server.testserverruntime2" name="Test runtime 2" description="Second testing runtime" facetRuntimeComponent="org.eclipse.wst.server.http.runtime" facetRuntimeVersion="1.0" class="org.eclipse.reddeer.eclipse.test.wst.server.ui.TestServerRuntime2">
</runtimeType>
</extension>
<extension point="org.eclipse.wst.server.core.serverTypes">
<serverType
Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017 Red Hat, Inc and others.
* Copyright (c) 2018 Red Hat, Inc and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand All @@ -13,9 +13,11 @@
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;

import java.util.List;

import org.eclipse.reddeer.eclipse.exception.EclipseLayerException;
import org.eclipse.reddeer.eclipse.wst.server.ui.Runtime;
import org.eclipse.reddeer.eclipse.wst.server.ui.RuntimePreferencePage;
import org.eclipse.reddeer.eclipse.wst.server.ui.wizard.NewRuntimeWizardDialog;
Expand All @@ -33,6 +35,8 @@ public class RuntimePreferencePageTest {

private static final String SERVER_NAME = TestServerRuntime.NAME;

private static final String SERVER_NAME_2 = TestServerRuntime2.NAME;

private static final String SERVER_PATH = "Basic";

private WorkbenchPreferenceDialog preferencesDialog;
Expand Down Expand Up @@ -111,4 +115,39 @@ public void editRuntime(){

assertFalse(new PushButton(RuntimePreferencePage.EDIT_BUTTON_NAME).isEnabled());
}

@Test
public void getServerRuntime() {
NewRuntimeWizardDialog wizardDialog = preferencePage.addRuntime();
NewRuntimeWizardPage wizardPage = new NewRuntimeWizardPage(wizardDialog);
wizardPage.selectType(SERVER_PATH, SERVER_NAME);
wizardDialog.finish();

wizardDialog = preferencePage.addRuntime();
wizardPage = new NewRuntimeWizardPage(wizardDialog);
wizardPage.selectType(SERVER_PATH, SERVER_NAME_2);
wizardDialog.finish();

wizardDialog = preferencePage.addRuntime();
wizardPage = new NewRuntimeWizardPage(wizardDialog);
wizardPage.selectType(SERVER_PATH, SERVER_NAME_2);
wizardDialog.finish();

List<Runtime> runtimes = preferencePage.getServerRuntimes();
assertThat(runtimes.size(), is(3));

Runtime runtime1 = preferencePage.getServerRuntime(SERVER_NAME, SERVER_NAME);
assertThat(runtime1, is(new Runtime(SERVER_NAME, SERVER_NAME)));

Runtime runtime2 = preferencePage.getServerRuntime(new Runtime(SERVER_NAME_2, SERVER_NAME_2));
assertThat(runtime2, is(new Runtime(SERVER_NAME_2, SERVER_NAME_2)));

Runtime runtime3 = null;
try {
runtime3 = preferencePage.getServerRuntime(SERVER_NAME_2);
} catch (EclipseLayerException exc) {
fail(exc.getMessage());
}
assertThat(runtime3, is(new Runtime(SERVER_NAME_2, SERVER_NAME_2)));
}
}
@@ -0,0 +1,36 @@
/*******************************************************************************
* Copyright (c) 2018 Red Hat, Inc and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat Inc. - initial API and implementation
*******************************************************************************/
package org.eclipse.reddeer.eclipse.test.wst.server.ui;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.wst.server.core.model.RuntimeDelegate;

public class TestServerRuntime2 extends RuntimeDelegate {

public static final String ID = "org.eclipse.reddeer.eclipse.test.wst.server.testserverruntime";

public static final String CATEGORY = "Basic";

public static final String NAME = "Test runtime 2";

public static final String TYPE = "Test runtime 2";

public IStatus validate() {
return Status.OK_STATUS;
}

public void setDefaults(IProgressMonitor monitor) {
getRuntimeWorkingCopy().setLocation(new Path(""));
}
}

0 comments on commit 8b70be5

Please sign in to comment.