diff --git a/tests/org.jboss.tools.cdk.ui.bot.test/launchers/CDKAllTestsSuite.launch b/tests/org.jboss.tools.cdk.ui.bot.test/launchers/CDKAllTestsSuite.launch index 9492d0882f..7374918778 100644 --- a/tests/org.jboss.tools.cdk.ui.bot.test/launchers/CDKAllTestsSuite.launch +++ b/tests/org.jboss.tools.cdk.ui.bot.test/launchers/CDKAllTestsSuite.launch @@ -33,7 +33,7 @@ - + diff --git a/tests/org.jboss.tools.cdk.ui.bot.test/pom.xml b/tests/org.jboss.tools.cdk.ui.bot.test/pom.xml index f3ef588c1a..9c836cb9bb 100644 --- a/tests/org.jboss.tools.cdk.ui.bot.test/pom.xml +++ b/tests/org.jboss.tools.cdk.ui.bot.test/pom.xml @@ -14,9 +14,11 @@ eclipse-test-plugin true - ${integrationTestsSystemProperties} -Dvagrantfile.path=${vagrantfile.path} -Ddevelopers.username=${developers.username} -Ddevelopers.password=${developers.password} + ${integrationTestsSystemProperties} -Dvagrantfile.path=${vagrantfile.path} -Ddevelopers.username=${developers.username} -Ddevelopers.password=${developers.password} -Dminishift.path=${minishift.path} -Dminishift.hypervisor=${minishift.hypervisor} + + diff --git a/tests/org.jboss.tools.cdk.ui.bot.test/src/org/jboss/tools/cdk/ui/bot/test/CDK3DevstudioIntegrationTest.java b/tests/org.jboss.tools.cdk.ui.bot.test/src/org/jboss/tools/cdk/ui/bot/test/CDK3DevstudioIntegrationTest.java new file mode 100644 index 0000000000..7a0f5e437d --- /dev/null +++ b/tests/org.jboss.tools.cdk.ui.bot.test/src/org/jboss/tools/cdk/ui/bot/test/CDK3DevstudioIntegrationTest.java @@ -0,0 +1,245 @@ +/******************************************************************************* + * Copyright (c) 2017 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is 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.jboss.tools.cdk.ui.bot.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import org.jboss.reddeer.common.exception.RedDeerException; +import org.jboss.reddeer.common.exception.WaitTimeoutExpiredException; +import org.jboss.reddeer.common.logging.Logger; +import org.jboss.reddeer.common.wait.TimePeriod; +import org.jboss.reddeer.common.wait.WaitUntil; +import org.jboss.reddeer.common.wait.WaitWhile; +import org.jboss.reddeer.core.condition.JobIsRunning; +import org.jboss.reddeer.core.condition.ShellWithTextIsAvailable; +import org.jboss.reddeer.eclipse.exception.EclipseLayerException; +import org.jboss.reddeer.eclipse.wst.server.ui.view.Server; +import org.jboss.reddeer.eclipse.wst.server.ui.view.ServersView; +import org.jboss.reddeer.eclipse.wst.server.ui.view.ServersViewEnums.ServerState; +import org.jboss.reddeer.eclipse.wst.server.ui.wizard.NewServerWizardDialog; +import org.jboss.reddeer.eclipse.wst.server.ui.wizard.NewServerWizardPage; +import org.jboss.reddeer.jface.exception.JFaceLayerException; +import org.jboss.reddeer.jface.viewer.handler.TreeViewerHandler; +import org.jboss.reddeer.junit.runner.RedDeerSuite; +import org.jboss.reddeer.swt.condition.WidgetIsEnabled; +import org.jboss.reddeer.swt.impl.button.FinishButton; +import org.jboss.tools.cdk.reddeer.requirements.DisableSecureStorageRequirement.DisableSecureStorage; +import org.jboss.tools.cdk.reddeer.ui.CDEServer; +import org.jboss.tools.cdk.reddeer.ui.wizard.NewCDK3ServerContainerWizardPage; +import org.jboss.tools.docker.reddeer.ui.DockerExplorerView; +import org.jboss.tools.docker.reddeer.ui.resources.DockerConnection; +import org.jboss.tools.openshift.reddeer.view.OpenShiftExplorerView; +import org.jboss.tools.openshift.reddeer.view.resources.OpenShift3Connection; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * Testing CDK3 server adapter with minishift using vm driver passed via system property + * @author odockal + * + */ +@RunWith(RedDeerSuite.class) +@DisableSecureStorage +public class CDK3DevstudioIntegrationTest extends CDKDevstudioAbstractTest { + + private static final String SERVER_NAME = "Red Hat Container Development Kit 3 (Tech Preview)"; //$NON-NLS-1$ + + private static final String SERVER_ADAPTER = "Container Development Environment 3"; //$NON-NLS-1$ + + private static final String SERVER_TYPE = "Red Hat JBoss Middleware"; //$NON-NLS-1$ + + private static final String SERVER_HOST = "localhost"; //$NON-NLS-1$ + + private static final String OPENSHIFT_USER_NAME = "developer"; //$NON-NLS-1$ + + private static final String OPENSHIFT_PROJECT_NAME = "My Project"; //$NON-NLS-1$ + + private static final String DOCKER_DAEMON_CONNECTION = SERVER_ADAPTER; + + private static final String MINISHIFT_HYPERVISOR; + + private static final String MINISHIFT_PATH; + + private static Logger log = Logger.getLogger(CDK3DevstudioIntegrationTest.class); + + private TreeViewerHandler treeViewerHandler = TreeViewerHandler.getInstance(); + + static { + MINISHIFT_PATH = getSystemProperty("minishift.path"); //$NON-NLS-1$ + MINISHIFT_HYPERVISOR = getSystemProperty("hypervisor"); //$NON-NLS-1$ + } + + private static void checkMinishiftParams() { + if (MINISHIFT_PATH == null) { + throw new RedDeerException("Minishift binary path was not specified"); //$NON-NLS-1$ + } + log.info("Minishift binary file is " + MINISHIFT_PATH); //$NON-NLS-1$ + if (MINISHIFT_HYPERVISOR == null) { + log.info("Default hypervisor will be set"); //$NON-NLS-1$ + } else { + log.info(MINISHIFT_HYPERVISOR + " is set as hypervisor"); //$NON-NLS-1$ + } + } + + @Override + protected Server getCDEServer() { + return this.server; + } + + @Override + protected ServersView getServersView() { + return this.serversView; + } + + @Override + protected void setServersView(ServersView view) { + this.serversView = view; + } + + @Override + protected void setCDEServer(Server server) { + this.server = (CDEServer)server; + + } + + @Override + protected String getServerAdapter() { + return SERVER_ADAPTER; + } + + @BeforeClass + public static void setup() { + checkMinishiftParams(); + log.info("Adding new Container Development Environment server adapter"); //$NON-NLS-1$ + addNewCDEServer(); + } + + private static void addNewCDEServer() { + // call new server dialog from servers view + ServersView view = new ServersView(); + view.open(); + NewServerWizardDialog dialog = view.newServer(); + NewServerWizardPage page = new NewServerWizardPage(); + + new WaitWhile(new JobIsRunning(), TimePeriod.NORMAL, false); + // set first dialog page + page.selectType(SERVER_TYPE, SERVER_NAME); + page.setHostName(SERVER_HOST); + page.setName(SERVER_ADAPTER); + dialog.next(); + + // set second new server dialog page + NewCDK3ServerContainerWizardPage containerPage = new NewCDK3ServerContainerWizardPage(); + log.info("Setting credentials"); //$NON-NLS-1$ + containerPage.setCredentials(USERNAME, PASSWORD); + if (MINISHIFT_HYPERVISOR != null && !MINISHIFT_HYPERVISOR.isEmpty()) { + log.info("Setting hypervisor"); //$NON-NLS-1$ + containerPage.setHypevisor(MINISHIFT_HYPERVISOR); + } + log.info("Setting minishift binary file folder"); //$NON-NLS-1$ + containerPage.setMinishiftBinary(MINISHIFT_PATH); + new WaitUntil(new WidgetIsEnabled(new FinishButton()), TimePeriod.NORMAL); + log.info("Finishing Add new server dialog"); //$NON-NLS-1$ + if (!(new FinishButton().isEnabled())) { + log.error("Finish button was not enabled"); //$NON-NLS-1$ + } + dialog.finish(); + } + + @AfterClass + public static void tearDownEnvironment() { + log.info("Deleting Container Development Environment server adapter"); //$NON-NLS-1$ + ServersView servers = new ServersView(); + servers.open(); + try { + servers.getServer(SERVER_ADAPTER).delete(true); + } catch (EclipseLayerException exc) { + log.error(exc.getMessage()); + exc.printStackTrace(); + } + removeAccessRedHatCredentials(); + } + + @Test + public void testCDEStop() { + startServerAdapter(); + getCDEServer().stop(); + assertEquals(ServerState.STOPPED, getCDEServer().getLabel().getState()); + } + + @Test + public void testCDERestart() { + startServerAdapter(); + getCDEServer().restart(); + assertEquals(ServerState.STARTED, getCDEServer().getLabel().getState()); + } + + @Test + public void testOpenShiftConnection() { + startServerAdapter(); + OpenShiftExplorerView osExplorer = new OpenShiftExplorerView(); + osExplorer.open(); + try { + OpenShift3Connection connection = osExplorer.getOpenShift3Connection(null, OPENSHIFT_USER_NAME); + // usually, when server adapter is not started, openshift connection after refresh should cause + // problem occurs dialog + connection.refresh(); + try { + new WaitUntil(new ShellWithTextIsAvailable("Problem occurred"), TimePeriod.getCustom(30)); //$NON-NLS-1$ + fail("Problem dialog occured when refreshing OpenShift connection"); //$NON-NLS-1$ + } catch (WaitTimeoutExpiredException ex) { + // no dialog appeared, which is ok + log.debug("Expected WaitTimeoutExpiredException occured"); //$NON-NLS-1$ + ex.printStackTrace(); + } + try { + this.treeViewerHandler.getTreeItem(connection.getTreeItem(), OPENSHIFT_PROJECT_NAME); + } catch (JFaceLayerException ex) { + ex.printStackTrace(); + fail("Could not find deployed sample OpenShift project"); //$NON-NLS-1$ + } + } catch (RedDeerException ex) { + ex.printStackTrace(); + fail("Could not open OpenShift connection for " + OPENSHIFT_USER_NAME + //$NON-NLS-1$ + " ended with exception: " + ex.getMessage()); //$NON-NLS-1$ + } + } + + @Test + public void testDockerDaemonConnection() { + startServerAdapter(); + DockerExplorerView dockerExplorer = new DockerExplorerView(); + dockerExplorer.open(); + DockerConnection connection = dockerExplorer.getDockerConnectionByName(DOCKER_DAEMON_CONNECTION); + if (connection == null) { + fail("Could not find Docker connection " + DOCKER_DAEMON_CONNECTION); //$NON-NLS-1$ + } + connection.select(); + connection.enableConnection(); + connection.refresh(); + new WaitWhile(new JobIsRunning(), TimePeriod.getCustom(30)); + try { + assertTrue("Docker connection does not contain any images", connection.getImagesNames().size() > 0); //$NON-NLS-1$ + } catch (WaitTimeoutExpiredException ex) { + ex.printStackTrace(); + fail("WaitTimeoutExpiredException occurs when expanding" //$NON-NLS-1$ + + " Docker connection " + DOCKER_DAEMON_CONNECTION); //$NON-NLS-1$ + } catch (JFaceLayerException jFaceExc) { + jFaceExc.printStackTrace(); + fail(jFaceExc.getMessage()); + } + } + +} diff --git a/tests/org.jboss.tools.cdk.ui.bot.test/src/org/jboss/tools/cdk/ui/bot/test/CDKAllTestsSuite.java b/tests/org.jboss.tools.cdk.ui.bot.test/src/org/jboss/tools/cdk/ui/bot/test/CDKAllTestsSuite.java index 76b8dfbe37..2faab6326e 100644 --- a/tests/org.jboss.tools.cdk.ui.bot.test/src/org/jboss/tools/cdk/ui/bot/test/CDKAllTestsSuite.java +++ b/tests/org.jboss.tools.cdk.ui.bot.test/src/org/jboss/tools/cdk/ui/bot/test/CDKAllTestsSuite.java @@ -16,7 +16,8 @@ @RunWith(RedDeerSuite.class) @Suite.SuiteClasses({ - CDKDevstudioBaseTest.class + CDKDevstudioIntegrationTest.class, + CDK3DevstudioIntegrationTest.class }) /** * @author ondrej dockal diff --git a/tests/org.jboss.tools.cdk.ui.bot.test/src/org/jboss/tools/cdk/ui/bot/test/CDKDevstudioAbstractTest.java b/tests/org.jboss.tools.cdk.ui.bot.test/src/org/jboss/tools/cdk/ui/bot/test/CDKDevstudioAbstractTest.java new file mode 100644 index 0000000000..f404fbbaef --- /dev/null +++ b/tests/org.jboss.tools.cdk.ui.bot.test/src/org/jboss/tools/cdk/ui/bot/test/CDKDevstudioAbstractTest.java @@ -0,0 +1,185 @@ +/******************************************************************************* + * Copyright (c) 2017 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is 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.jboss.tools.cdk.ui.bot.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.jboss.reddeer.common.exception.RedDeerException; +import org.jboss.reddeer.common.exception.WaitTimeoutExpiredException; +import org.jboss.reddeer.common.logging.Logger; +import org.jboss.reddeer.common.wait.TimePeriod; +import org.jboss.reddeer.common.wait.WaitUntil; +import org.jboss.reddeer.common.wait.WaitWhile; +import org.jboss.reddeer.core.condition.JobIsRunning; +import org.jboss.reddeer.core.condition.WidgetIsFound; +import org.jboss.reddeer.core.matcher.ClassMatcher; +import org.jboss.reddeer.core.matcher.WithMnemonicTextMatcher; +import org.jboss.reddeer.core.matcher.WithTextMatcher; +import org.jboss.reddeer.eclipse.wst.server.ui.view.Server; +import org.jboss.reddeer.eclipse.wst.server.ui.view.ServersView; +import org.jboss.reddeer.eclipse.wst.server.ui.view.ServersViewEnums.ServerState; +import org.jboss.reddeer.eclipse.wst.server.ui.view.ServersViewException; +import org.jboss.reddeer.jface.exception.JFaceLayerException; +import org.jboss.reddeer.jface.viewer.handler.TreeViewerHandler; +import org.jboss.reddeer.swt.api.TreeItem; +import org.jboss.reddeer.swt.impl.button.PushButton; +import org.jboss.reddeer.swt.impl.clabel.DefaultCLabel; +import org.jboss.reddeer.swt.impl.tree.DefaultTree; +import org.jboss.reddeer.workbench.ui.dialogs.WorkbenchPreferenceDialog; +import org.jboss.tools.cdk.reddeer.preferences.OpenShift3SSLCertificatePreferencePage; +import org.jboss.tools.cdk.reddeer.ui.CDEServersView; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; + +public abstract class CDKDevstudioAbstractTest { + + protected ServersView serversView; + + protected Server server; + + private static final Logger log = Logger.getLogger(CDKDevstudioAbstractTest.class); + + protected static final String USERNAME; + + protected static final String PASSWORD; + + private static final String CREDENTIALS_DOMAIN = "access.redhat.com"; //$NON-NLS-1$ + + static { + USERNAME = getSystemProperty("developers.username"); //$NON-NLS-1$ + PASSWORD = getSystemProperty("developers.password"); //$NON-NLS-1$ + } + + protected static String getSystemProperty(String systemProperty) { + String property = System.getProperty(systemProperty); + if (!(property == null || property.equals("") || property.startsWith("${"))) { //$NON-NLS-1$ //$NON-NLS-2$ + return property; + } + return null; + } + + protected abstract Server getCDEServer(); + + protected abstract ServersView getServersView(); + + protected abstract void setServersView(ServersView view); + + protected abstract void setCDEServer(Server server); + + protected abstract String getServerAdapter(); + + private static void checkCredentials() { + if (USERNAME == null || PASSWORD== null) { + throw new RedDeerException("Credentials for Red Hat Developers were not set properly"); //$NON-NLS-1$ + } + log.info("Red Hat Developers username " + USERNAME + " and given password are set"); //$NON-NLS-1$ //$NON-NLS-2$ + } + + @BeforeClass + public static void setUpEnvironemnt() { + log.info("Checking given program arguments"); //$NON-NLS-1$ + checkCredentials(); + new WaitWhile(new JobIsRunning(), TimePeriod.LONG, false); + } + + @Before + public void setUpServers() { + log.info("Open Servers view tab"); //$NON-NLS-1$ + setServersView(new CDEServersView()); + getServersView().open(); + log.info("Getting server object from Servers View with name: " + getServerAdapter()); //$NON-NLS-1$ + setCDEServer(getServersView().getServer(getServerAdapter())); + new WaitUntil(new JobIsRunning(), TimePeriod.NORMAL, false); + } + + @After + public void tearDownServers() { + if (getCDEServer().getLabel().getState() == ServerState.STARTED) { + getCDEServer().stop(); + } + // remove SSL Certificate to be added at next server start at method annotated with before + deleteCertificates(); + setCDEServer(null); + getServersView().close(); + } + + protected void startServerAdapter() { + log.info("Starting server adapter"); //$NON-NLS-1$ + try { + getCDEServer().start(); + } catch (ServersViewException e) { + log.error(e.getMessage()); + e.printStackTrace(); + } + printCertificates(); + checkAvailableServers(); + assertEquals(ServerState.STARTED, getCDEServer().getLabel().getState()); + } + + private void checkAvailableServers() { + for (Server serverItem : getServersView().getServers()) { + String serverName = serverItem.getLabel().getName(); + log.info(serverName); + } + assertTrue(getCDEServer().getLabel().getName().contains(getServerAdapter())); + } + + private static void printCertificates() { + WorkbenchPreferenceDialog dialog = new WorkbenchPreferenceDialog(); + dialog.open(); + + OpenShift3SSLCertificatePreferencePage preferencePage = new OpenShift3SSLCertificatePreferencePage(); + dialog.select(preferencePage); + preferencePage.printCertificates(); + dialog.ok(); + } + + private static void deleteCertificates() { + WorkbenchPreferenceDialog dialog = new WorkbenchPreferenceDialog(); + dialog.open(); + + OpenShift3SSLCertificatePreferencePage preferencePage = new OpenShift3SSLCertificatePreferencePage(); + dialog.select(preferencePage); + preferencePage.deleteAll(); + preferencePage.apply(); + dialog.ok(); + } + + // removes access redhat com credentials used for first cdk run + protected static void removeAccessRedHatCredentials() { + WorkbenchPreferenceDialog dialog = new WorkbenchPreferenceDialog(); + dialog.open(); + + dialog.select("JBoss Tools", "Credentials"); //$NON-NLS-1$ //$NON-NLS-2$ + try { + new WaitUntil(new WidgetIsFound( + new ClassMatcher(org.eclipse.swt.custom.CLabel.class), + new WithMnemonicTextMatcher("Credentials")), TimePeriod.NORMAL); //$NON-NLS-1$ + new DefaultCLabel("Credentials"); //$NON-NLS-1$ + DefaultTree tree = new DefaultTree(1); + TreeItem item = TreeViewerHandler.getInstance().getTreeItem(tree, new String[]{CREDENTIALS_DOMAIN, USERNAME}); + item.select(); + new PushButton(new WithTextMatcher("Remove User")).click(); //$NON-NLS-1$ + new WaitUntil(new JobIsRunning(), TimePeriod.NORMAL, false); + } catch (WaitTimeoutExpiredException exc) { + log.error("JBoss Tools - Credentials preferences page has timed out"); //$NON-NLS-1$ + exc.printStackTrace(); + } catch (JFaceLayerException exc) { + log.error("JBoss Tools - Credentials does not contain required username to be deleted"); //$NON-NLS-1$ + exc.printStackTrace(); + } finally { + dialog.ok(); + } + } + +} diff --git a/tests/org.jboss.tools.cdk.ui.bot.test/src/org/jboss/tools/cdk/ui/bot/test/CDKDevstudioBaseTest.java b/tests/org.jboss.tools.cdk.ui.bot.test/src/org/jboss/tools/cdk/ui/bot/test/CDKDevstudioIntegrationTest.java similarity index 52% rename from tests/org.jboss.tools.cdk.ui.bot.test/src/org/jboss/tools/cdk/ui/bot/test/CDKDevstudioBaseTest.java rename to tests/org.jboss.tools.cdk.ui.bot.test/src/org/jboss/tools/cdk/ui/bot/test/CDKDevstudioIntegrationTest.java index 49ecd1dc86..b3f92f069e 100644 --- a/tests/org.jboss.tools.cdk.ui.bot.test/src/org/jboss/tools/cdk/ui/bot/test/CDKDevstudioBaseTest.java +++ b/tests/org.jboss.tools.cdk.ui.bot.test/src/org/jboss/tools/cdk/ui/bot/test/CDKDevstudioIntegrationTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2016 Red Hat, Inc. + * Copyright (c) 2017 Red Hat, Inc. * Distributed under license by Red Hat, Inc. All rights reserved. * This program is made available under the terms of the * Eclipse Public License v1.0 which accompanies this distribution, @@ -23,32 +23,27 @@ import org.jboss.reddeer.core.condition.JobIsRunning; import org.jboss.reddeer.core.condition.ShellWithTextIsAvailable; import org.jboss.reddeer.eclipse.exception.EclipseLayerException; -import org.jboss.reddeer.eclipse.ui.console.ConsoleView; import org.jboss.reddeer.eclipse.wst.server.ui.view.Server; import org.jboss.reddeer.eclipse.wst.server.ui.view.ServersView; import org.jboss.reddeer.eclipse.wst.server.ui.view.ServersViewEnums.ServerState; -import org.jboss.reddeer.eclipse.wst.server.ui.view.ServersViewException; import org.jboss.reddeer.eclipse.wst.server.ui.wizard.NewServerWizardDialog; import org.jboss.reddeer.eclipse.wst.server.ui.wizard.NewServerWizardPage; import org.jboss.reddeer.jface.exception.JFaceLayerException; import org.jboss.reddeer.jface.viewer.handler.TreeViewerHandler; +import org.jboss.reddeer.junit.runner.RedDeerSuite; import org.jboss.reddeer.swt.condition.WidgetIsEnabled; import org.jboss.reddeer.swt.impl.button.FinishButton; -import org.jboss.reddeer.workbench.ui.dialogs.WorkbenchPreferenceDialog; -import org.jboss.tools.cdk.reddeer.preferences.OpenShift3SSLCertificatePreferencePage; import org.jboss.tools.cdk.reddeer.requirements.DisableSecureStorageRequirement.DisableSecureStorage; import org.jboss.tools.cdk.reddeer.ui.CDEServer; -import org.jboss.tools.cdk.reddeer.ui.CDEServersView; -import org.jboss.tools.cdk.reddeer.ui.wizard.NewServerContainerWizardPage; +import org.jboss.tools.cdk.reddeer.ui.wizard.NewCDKServerContainerWizardPage; import org.jboss.tools.docker.reddeer.ui.DockerExplorerView; import org.jboss.tools.docker.reddeer.ui.resources.DockerConnection; import org.jboss.tools.openshift.reddeer.view.OpenShiftExplorerView; import org.jboss.tools.openshift.reddeer.view.resources.OpenShift3Connection; -import org.junit.After; import org.junit.AfterClass; -import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.runner.RunWith; /** @@ -57,80 +52,104 @@ * @author odockal * */ +@RunWith(RedDeerSuite.class) @DisableSecureStorage -public class CDKDevstudioBaseTest { - - private CDEServersView serversView; +public class CDKDevstudioIntegrationTest extends CDKDevstudioAbstractTest { - private CDEServer server; + private static final String VAGRANTFILE_PATH; - private TreeViewerHandler treeViewerHandler = TreeViewerHandler.getInstance(); + private static final String SERVER_NAME = "Red Hat Container Development Kit"; //$NON-NLS-1$ - private static final String SERVER_NAME = "Red Hat Container Development Kit"; + private static final String SERVER_ADAPTER = "Container Development Environment"; //$NON-NLS-1$ - private static final String SERVER_ADAPTER = "Container Development Environment"; + private static final String SERVER_TYPE = "Red Hat JBoss Middleware"; //$NON-NLS-1$ - private static final String SERVER_TYPE = "Red Hat JBoss Middleware"; + private static final String SERVER_HOST = "localhost"; //$NON-NLS-1$ - private static final String OPENSHIFT_USER_NAME = "openshift-dev"; + private static final String OPENSHIFT_USER_NAME = "openshift-dev"; //$NON-NLS-1$ - private static final String OPENSHIFT_SERVER = "https://10.1.2.2:8443"; + private static final String OPENSHIFT_PROJECT_NAME = "OpenShift sample project"; //$NON-NLS-1$ private static final String DOCKER_DAEMON_CONNECTION = SERVER_ADAPTER; - private static final Logger log = Logger.getLogger(CDKDevstudioBaseTest.class); - - private static String USERNAME; - - private static String PASSWORD; - - // TODO: add validation of vagrant path - private static String VAGRANTFILE_PATH; + private static Logger log = Logger.getLogger(CDK3DevstudioIntegrationTest.class); + private TreeViewerHandler treeViewerHandler = TreeViewerHandler.getInstance(); + static { - String username = System.getProperty("developers.username"); - if (!(username == null || username.equals("") || username.startsWith("${"))){ - USERNAME = username; - } else { - USERNAME = null; - } - String password = System.getProperty("developers.password"); - if (!(password == null || password.equals("") || password.startsWith("${"))){ - PASSWORD = password; - } else { - PASSWORD = null; - } - String vagrantfile = System.getProperty("vagrantfile.path"); - if (!(vagrantfile == null || vagrantfile.equals("") || vagrantfile.startsWith("${"))){ - VAGRANTFILE_PATH = vagrantfile; - } else { - VAGRANTFILE_PATH = null; - } + VAGRANTFILE_PATH = getSystemProperty("vagrantfile.path"); //$NON-NLS-1$ } - private static void checkCredentials() { - if (USERNAME == null || PASSWORD== null) { - throw new RedDeerException("Credentials for Red Hat Developers were not set properly"); - } - log.info("Red Hat Developers username " + USERNAME + " and given password are set"); + private static void checkVagrantfilePath() { if (VAGRANTFILE_PATH == null) { - throw new RedDeerException("Path Vagrantfile path was not specified"); + throw new RedDeerException("Path Vagrantfile path was not specified"); //$NON-NLS-1$ } - log.info("Vagrantfile path is set to " + VAGRANTFILE_PATH); + log.info("Vagrantfile path is set to " + VAGRANTFILE_PATH); //$NON-NLS-1$ + } + + @Override + protected Server getCDEServer() { + return this.server; + } + + @Override + protected ServersView getServersView() { + return this.serversView; + } + + @Override + protected void setServersView(ServersView view) { + this.serversView = view; + } + + @Override + protected void setCDEServer(Server server) { + this.server = (CDEServer)server; + } + + @Override + protected String getServerAdapter() { + return SERVER_ADAPTER; } @BeforeClass - public static void setUpEnvironemnt() { - log.info("Checking given program arguments"); - checkCredentials(); - new WaitWhile(new JobIsRunning(), TimePeriod.LONG, false); - log.info("Adding new Container Development Environment server adapter"); + public static void setup() { + checkVagrantfilePath(); + log.info("Adding new Container Development Environment server adapter"); //$NON-NLS-1$ addNewCDEServer(); } + private static void addNewCDEServer() { + // call new server dialog from servers view + ServersView view = new ServersView(); + view.open(); + NewServerWizardDialog dialog = view.newServer(); + NewServerWizardPage page = new NewServerWizardPage(); + + new WaitWhile(new JobIsRunning(), TimePeriod.NORMAL, false); + // set first dialog page + page.selectType(SERVER_TYPE, SERVER_NAME); + page.setHostName(SERVER_HOST); + dialog.next(); + + // set second new server dialog page + NewCDKServerContainerWizardPage containerPage = new NewCDKServerContainerWizardPage(); + log.info("Setting credentials"); //$NON-NLS-1$ + containerPage.setCredentials(CDKDevstudioAbstractTest.USERNAME, PASSWORD); + // set cdk 2.x fields + log.info("Setting vagrant file folder"); //$NON-NLS-1$ + containerPage.setFolder(VAGRANTFILE_PATH); + new WaitUntil(new WidgetIsEnabled(new FinishButton()), TimePeriod.NORMAL); + log.info("Finishing Add new server dialog"); //$NON-NLS-1$ + if (!(new FinishButton().isEnabled())) { + log.error("Finish button was not enabled"); //$NON-NLS-1$ + } + dialog.finish(); + } + @AfterClass public static void tearDownEnvironment() { - log.info("Deleting Container Development Environment server adapter"); + log.info("Deleting Container Development Environment server adapter"); //$NON-NLS-1$ ServersView servers = new ServersView(); servers.open(); try { @@ -138,55 +157,22 @@ public static void tearDownEnvironment() { } catch (EclipseLayerException exc) { log.error(exc.getMessage()); exc.printStackTrace(); - } - } - - @Before - public void setUpServers() { - log.info("Open Servers view tab"); - serversView = new CDEServersView(); - serversView.open(); - log.info("Getting server object from Servers View with name: " + SERVER_ADAPTER); - server = (CDEServer)serversView.getServer(SERVER_ADAPTER); - new WaitUntil(new JobIsRunning(), TimePeriod.NORMAL, false); - } - - @After - public void tearDownServers() { - if (server.getLabel().getState() == ServerState.STARTED) { - server.stop(); - } - // remove SSL Certificate to be added at next server start at method annotated with before - deleteCertificates(); - server = null; - serversView.close(); - } - - private void startServerAdapter() { - log.info("Starting server adapter"); - try { - server.start(); - } catch (ServersViewException e) { - log.error(e.getMessage()); - e.printStackTrace(); } - printCertificates(); - checkAvailableServers(); - assertEquals(ServerState.STARTED, server.getLabel().getState()); + removeAccessRedHatCredentials(); } @Test public void testCDEStop() { startServerAdapter(); - server.stop(); - assertEquals(ServerState.STOPPED, server.getLabel().getState()); + getCDEServer().stop(); + assertEquals(ServerState.STOPPED, getCDEServer().getLabel().getState()); } @Test public void testCDERestart() { startServerAdapter(); - server.restart(); - assertEquals(ServerState.STARTED, server.getLabel().getState()); + getCDEServer().restart(); + assertEquals(ServerState.STARTED, getCDEServer().getLabel().getState()); } @Test @@ -200,23 +186,23 @@ public void testOpenShiftConnection() { // problem occurs dialog connection.refresh(); try { - new WaitUntil(new ShellWithTextIsAvailable("Problem occurred"), TimePeriod.getCustom(30)); - fail("Problem dialog occured when refreshing OpenShift connection"); + new WaitUntil(new ShellWithTextIsAvailable("Problem occurred"), TimePeriod.getCustom(30)); //$NON-NLS-1$ + fail("Problem dialog occured when refreshing OpenShift connection"); //$NON-NLS-1$ } catch (WaitTimeoutExpiredException ex) { // no dialog appeared, which is ok - log.info("Expected WaitTimeoutExpiredException occured"); + log.debug("Expected WaitTimeoutExpiredException occured"); //$NON-NLS-1$ ex.printStackTrace(); } try { - treeViewerHandler.getTreeItem(connection.getTreeItem(), "OpenShift sample project"); + this.treeViewerHandler.getTreeItem(connection.getTreeItem(), OPENSHIFT_PROJECT_NAME); } catch (JFaceLayerException ex) { ex.printStackTrace(); - fail("Could not find deployed sample OpenShift project"); + fail("Could not find deployed sample OpenShift project"); //$NON-NLS-1$ } } catch (RedDeerException ex) { ex.printStackTrace(); - fail("Could not open OpenShift connection for " + OPENSHIFT_USER_NAME + - " ended with exception: " + ex.getMessage()); + fail("Could not open OpenShift connection for " + OPENSHIFT_USER_NAME + //$NON-NLS-1$ + " ended with exception: " + ex.getMessage()); //$NON-NLS-1$ } } @@ -227,82 +213,22 @@ public void testDockerDaemonConnection() { dockerExplorer.open(); DockerConnection connection = dockerExplorer.getDockerConnectionByName(DOCKER_DAEMON_CONNECTION); if (connection == null) { - fail("Could not find Docker connection " + DOCKER_DAEMON_CONNECTION); + fail("Could not find Docker connection " + DOCKER_DAEMON_CONNECTION); //$NON-NLS-1$ } connection.select(); connection.enableConnection(); connection.refresh(); new WaitWhile(new JobIsRunning(), TimePeriod.getCustom(30)); try { - assertTrue("Docker connection does not contain any images", connection.getImagesNames().size() > 0); + assertTrue("Docker connection does not contain any images", connection.getImagesNames().size() > 0); //$NON-NLS-1$ } catch (WaitTimeoutExpiredException ex) { ex.printStackTrace(); - fail("WaitTimeoutExpiredException occurs when expanding" - + " Docker connection " + DOCKER_DAEMON_CONNECTION); + fail("WaitTimeoutExpiredException occurs when expanding" //$NON-NLS-1$ + + " Docker connection " + DOCKER_DAEMON_CONNECTION); //$NON-NLS-1$ } catch (JFaceLayerException jFaceExc) { jFaceExc.printStackTrace(); fail(jFaceExc.getMessage()); } - } - - private static void addNewCDEServer() { - ServersView view = new ServersView(); - view.open(); - NewServerWizardDialog dialog = view.newServer(); - NewServerWizardPage page = new NewServerWizardPage(); - - new WaitWhile(new JobIsRunning(), TimePeriod.NORMAL, false); - page.selectType(SERVER_TYPE, SERVER_NAME); - page.setHostName("localhost"); - dialog.next(); - - NewServerContainerWizardPage containerPage = new NewServerContainerWizardPage(); - log.info("Setting credentials"); - containerPage.setCredentials(USERNAME, PASSWORD); - log.info("Setting vagrant file folder"); - containerPage.setFolder(VAGRANTFILE_PATH); - new WaitUntil(new WidgetIsEnabled(new FinishButton()), TimePeriod.NORMAL); - log.info("Finishing Add new server dialog"); - if (!(new FinishButton().isEnabled())){ - log.error("Finish button was not enabled"); - } - dialog.finish(); - } - - private void checkAvailableServers() { - for (Server server : serversView.getServers()) { - String serverName = server.getLabel().getName(); - log.info(serverName); - } - assertTrue(server.getLabel().getName().contains(SERVER_ADAPTER)); - } - - // TODO: Log active Console/Terminal-Console information - private void logConsoleOutput() { - ConsoleView console = new ConsoleView(); - console.open(); - log.info(console.getConsoleText()); - } - - private void printCertificates() { - WorkbenchPreferenceDialog dialog = new WorkbenchPreferenceDialog(); - dialog.open(); - - OpenShift3SSLCertificatePreferencePage preferencePage = new OpenShift3SSLCertificatePreferencePage(); - dialog.select(preferencePage); - preferencePage.printCertificates(); - dialog.ok(); - } - - private void deleteCertificates() { - WorkbenchPreferenceDialog dialog = new WorkbenchPreferenceDialog(); - dialog.open(); - - OpenShift3SSLCertificatePreferencePage preferencePage = new OpenShift3SSLCertificatePreferencePage(); - dialog.select(preferencePage); - preferencePage.deleteAll(); - preferencePage.apply(); - dialog.ok(); } } diff --git a/tests/org.jboss.tools.cdk.ui.bot.test/src/org/jboss/tools/cdk/ui/bot/test/CDKSmokeTestsSuite.java b/tests/org.jboss.tools.cdk.ui.bot.test/src/org/jboss/tools/cdk/ui/bot/test/CDKSmokeTestsSuite.java index 45fd53bb5b..7625945ab6 100644 --- a/tests/org.jboss.tools.cdk.ui.bot.test/src/org/jboss/tools/cdk/ui/bot/test/CDKSmokeTestsSuite.java +++ b/tests/org.jboss.tools.cdk.ui.bot.test/src/org/jboss/tools/cdk/ui/bot/test/CDKSmokeTestsSuite.java @@ -16,7 +16,8 @@ @RunWith(RedDeerSuite.class) @Suite.SuiteClasses({ - CDKDevstudioBaseTest.class + CDKDevstudioIntegrationTest.class, + CDK3DevstudioIntegrationTest.class }) /** * @author ondrej dockal