Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JBIDE-25194 OpenShift IO Integration test #1615

Merged
merged 1 commit into from Nov 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -20,7 +20,10 @@ Require-Bundle: org.eclipse.ui.ide,
org.jboss.tools.openshift.common.ui,
org.jboss.tools.openshift.core,
org.jboss.tools.openshift.ui,
org.eclipse.linuxtools.docker.reddeer
org.jboss.tools.openshift.io.core,
org.jboss.tools.openshift.io.ui,
org.eclipse.linuxtools.docker.reddeer,
org.eclipse.reddeer.common
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Eclipse-BundleShape: jar
Bundle-Localization: plugin
Expand Down
4 changes: 2 additions & 2 deletions itests/org.jboss.tools.openshift.ui.bot.test/README.md
Expand Up @@ -11,13 +11,13 @@ There are three suites for OpenShift 3 tests (full suite (OpenShift3BotTests), s
2. Select desired suite (e.g. OpenShift3BotTests, OpenShift3SmokeBotTests, OpenShift3StableBotTests) and in its context menu select _Run As_ - _Run Configurations..._
3. In Run Configurations shell double click on RedDeer Test and a new RedDeer test run configuration for your suite is created
4. Select tab Argument and fill in following properties **with credentials** to VM arguments:
`-Dopenshift.server= -Dopenshift.username= -Dopenshift.password= -Dsecurestorage.password= -Dusage_reporting_enabled=false -Dopenshift.authmethod=basic`
`-Dopenshift.server= -Dopenshift.username= -Dopenshift.password= -Dsecurestorage.password= -Dusage_reporting_enabled=false -Dopenshift.authmethod=basic -Dopenshift.io.username= -Dopenshift.io.password=`
for OpenShift tests is used basic authentication method with username/password by default.
5. Confirm changes and run test suite.

#### Running OS tests from command line
For execution of OpenShift tests from command line you need to have installed maven. At first you need to build jbosstools-openshift repo with maven and disabled tests, e.g. `mvn clean install -DskipTests=true -DskipITests=true`. Then run in _org.jboss.tools.openshift.ui.bot.test_ plugin following command **with filled credentials and OpenShift server** with basic authentication. By default it is used OpenShift3StableBotTests tests suite. User can switch to different suite class by using profiles: `-Psmoke` (OpenShift3SmokeBotTests) or `-Pfull` (OpenShift3BotTests).
`mvn clean verify -PITests -Dopenshift.username= -Dopenshift.password= -Dsecurestorage.password= -Dopenshift.server= `
`mvn clean verify -PITests -Dopenshift.username= -Dopenshift.password= -Dsecurestorage.password= -Dopenshift.server= -Dopenshift.io.username= -Dopenshift.io.password=`

Or you can run ITests from jbosstools-openshift root folder with profile ITests, e.g. `mvn clean verify -PITests -Dopenshift.username= -Dopenshift.password= -Dsecurestorage.password= -Dopenshift.server= `.

Expand Down
Expand Up @@ -31,7 +31,7 @@
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl} -consoleLog"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.jboss.tools.openshift.ui.bot.test"/>
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Dopenshift.server=&lt;OpenShift_Instance_Address&gt; -Dopenshift.username=&lt;username&gt; -Dopenshift.password=&lt;password&gt; -Dsecurestorage.password=&lt;Secure_Storage_Password&gt; -Dopenshift.authmethod=basic -Dusage_reporting_enabled=false"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Dopenshift.server=&lt;OpenShift_Instance_Address&gt; -Dopenshift.username=&lt;username&gt; -Dopenshift.password=&lt;password&gt; -Dsecurestorage.password=&lt;Secure_Storage_Password&gt; -Dopenshift.authmethod=basic -Dusage_reporting_enabled=false -Dopenshift.io.username=&lt;OpenShift.io username&gt; -Dopenshift.io.password=&lt;OpenShift.io password&gt;"/>
<stringAttribute key="pde.version" value="3.3"/>
<stringAttribute key="product" value="com.jboss.devstudio.core.product"/>
<stringAttribute key="rd.launch.property.rd.captureScreenshot" value="true"/>
Expand Down
4 changes: 3 additions & 1 deletion itests/org.jboss.tools.openshift.ui.bot.test/pom.xml
Expand Up @@ -14,7 +14,7 @@

<properties>
<systemProperties>
-Dtest.configurations.dir=${configurations.dir} -Dopenshift.server=${openshift.server} -Dopenshift.username=${openshift.username} -Dopenshift.password=${openshift.password} -Dopenshift.token=${openshift.token} -Dgithub.username=${github.username} -Dgithub.password=${github.password} -Dopenshift.authmethod=${openshift.authmethod} -Dsecurestorage.password=${securestorage.password} -Dusage_reporting_enabled=false
-Dtest.configurations.dir=${configurations.dir} -Dopenshift.server=${openshift.server} -Dopenshift.username=${openshift.username} -Dopenshift.password=${openshift.password} -Dopenshift.token=${openshift.token} -Dopenshift.authmethod=${openshift.authmethod} -Dsecurestorage.password=${securestorage.password} -Dusage_reporting_enabled=false -Dopenshift.io.username=${openshift.io.username} -Dopenshift.io.password=${openshift.io.password}
</systemProperties>
<test.class>org.jboss.tools.openshift.ui.bot.test.OpenShift3StableBotTests</test.class>
<surefire.timeout>7200</surefire.timeout>
Expand All @@ -23,6 +23,8 @@
<openshift.password></openshift.password>
<openshift.token></openshift.token>
<openshift.authmethod>basic</openshift.authmethod>
<openshift.io.username></openshift.io.username>
<openshift.io.password></openshift.io.password>
<github.username></github.username>
<github.password></github.password>
<securestorage.password></securestorage.password>
Expand Down
Expand Up @@ -47,6 +47,7 @@
import org.jboss.tools.openshift.ui.bot.test.connection.v3.RemoveConnectionTest;
import org.jboss.tools.openshift.ui.bot.test.connection.v3.StoreConnectionTest;
import org.jboss.tools.openshift.ui.bot.test.integration.docker.DeployDockerImageTest;
import org.jboss.tools.openshift.ui.bot.test.integration.openshift.io.GetOpenShiftIOTokenTest;
import org.jboss.tools.openshift.ui.bot.test.project.CreateNewProjectTest;
import org.jboss.tools.openshift.ui.bot.test.project.DeleteProjectTest;
import org.jboss.tools.openshift.ui.bot.test.project.LinkToCreateNewProjectTest;
Expand Down Expand Up @@ -121,6 +122,9 @@
PublishChangesTest.class,
DebuggingEAPAppTest.class,
NodeJSAppDebugTest.class,

//OpenShift.io
GetOpenShiftIOTokenTest.class
})
public class OpenShift3BotTests extends AbstractBotTests{

Expand Down
@@ -0,0 +1,113 @@
/*******************************************************************************
* Copyright (c) 2007-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 v 1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*
* Contributor:
* Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.openshift.ui.bot.test.integration.openshift.io;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import org.eclipse.reddeer.common.wait.TimePeriod;
import org.eclipse.reddeer.common.wait.WaitUntil;
import org.eclipse.reddeer.common.wait.WaitWhile;
import org.eclipse.reddeer.core.exception.CoreLayerException;
import org.eclipse.reddeer.eclipse.equinox.security.ui.storage.StoragePreferencePage;
import org.eclipse.reddeer.junit.runner.RedDeerSuite;
import org.eclipse.reddeer.swt.impl.browser.InternalBrowser;
import org.eclipse.reddeer.swt.impl.button.OkButton;
import org.eclipse.reddeer.swt.impl.shell.DefaultShell;
import org.eclipse.reddeer.swt.impl.toolbar.DefaultToolItem;
import org.eclipse.reddeer.swt.impl.tree.DefaultTree;
import org.eclipse.reddeer.swt.impl.tree.DefaultTreeItem;
import org.eclipse.reddeer.workbench.core.condition.JobIsRunning;
import org.eclipse.reddeer.workbench.impl.shell.WorkbenchShell;
import org.eclipse.reddeer.workbench.ui.dialogs.WorkbenchPreferenceDialog;
import org.jboss.tools.openshift.reddeer.condition.BrowserContainsText;
import org.jboss.tools.openshift.reddeer.preference.page.OpenShifIOPreferencePage;
import org.jboss.tools.openshift.reddeer.utils.DatastoreOS3;
import org.jboss.tools.openshift.reddeer.utils.SecureStorage;
import org.jboss.tools.openshift.reddeer.utils.SystemProperties;
import org.junit.AfterClass;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
*
* @author jkopriva@redhat.com
*/
@RunWith(RedDeerSuite.class)
public class GetOpenShiftIOTokenTest {

@Test
public void testGetToken() {
new DefaultToolItem(new WorkbenchShell(), "Connect to OpenShift.io").click();
DefaultShell browser = new DefaultShell();
InternalBrowser internalBrowser = new InternalBrowser(browser);

new WaitWhile(new JobIsRunning(), TimePeriod.LONG);
new WaitUntil(new BrowserContainsText("OpenShift.io Developer Preview"), TimePeriod.LONG);

internalBrowser.execute(String.format("document.getElementById(\"username\").value=\"%s\"", DatastoreOS3.OPENSHIFT_IO_USERNAME));
internalBrowser.execute(String.format("document.getElementById(\"password\").value=\"%s\"", DatastoreOS3.OPENSHIFT_IO_PASSWORD));
internalBrowser.execute("document.getElementById(\"password\").parentElement.parentElement.parentElement.submit()");

new WaitWhile(new JobIsRunning(), TimePeriod.LONG);

try {
new DefaultShell("OpenShift.io");
} catch (CoreLayerException ex) {
//Secure storage has been triggered
SecureStorage.handleSecureStoragePasswordAndHint(SystemProperties.SECURE_STORAGE_PASSWORD);
new DefaultShell("OpenShift.io");
}
new OkButton().click();

checkAccountInProperties();
checkPluginInSecureStorage();

}

private void checkPluginInSecureStorage() {
WorkbenchPreferenceDialog preferences = new WorkbenchPreferenceDialog();
preferences.open();
StoragePreferencePage storagePreferencePage = new StoragePreferencePage(preferences);
preferences.select(storagePreferencePage);
storagePreferencePage.selectContentTab();
DefaultTreeItem account = new DefaultTreeItem(new DefaultTree(storagePreferencePage, 1), "[Default Secure Storage]","org.jboss.tools.openshift.io.core", "accounts", "OpenShift.io", DatastoreOS3.OPENSHIFT_IO_USERNAME);
account.select();
assertNotNull("Account does not exists in secure storage", account);
preferences.ok();
}

private void checkAccountInProperties() {
WorkbenchPreferenceDialog preferences = new WorkbenchPreferenceDialog();
preferences.open();
OpenShifIOPreferencePage page = new OpenShifIOPreferencePage(preferences);
preferences.select(page);
assertTrue("Account is not configured!",page.existsOpenShiftIOAccount());
preferences.ok();
}

@AfterClass
public static void cleanUp() {
removeAccountFromOpenShiftIOPreferencePage();
}

private static void removeAccountFromOpenShiftIOPreferencePage() {
WorkbenchPreferenceDialog preferences = new WorkbenchPreferenceDialog();
preferences.open();
OpenShifIOPreferencePage page = new OpenShifIOPreferencePage(preferences);
preferences.select(page);
if (page.existsOpenShiftIOAccount()) {
page.remove();
}
preferences.ok();
}

}
@@ -0,0 +1,39 @@
/*******************************************************************************
* Copyright (c) 2007-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 v 1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*
* Contributor:
* Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.openshift.reddeer.preference.page;

import org.eclipse.reddeer.core.reference.ReferencedComposite;
import org.eclipse.reddeer.jface.preference.PreferencePage;
import org.eclipse.reddeer.swt.impl.button.PushButton;

/**
* OpenShift.io preference page its used for showing information about OpenShift.io account.
* @author jkopriva@redhat.com
*/
public class OpenShifIOPreferencePage extends PreferencePage {

public OpenShifIOPreferencePage(ReferencedComposite composite) {
super(composite, "JBoss Tools", "OpenShift.io");
}

/**
* Remove OpenShift.io account.
*/
public OpenShifIOPreferencePage remove() {
new PushButton(this, "Remove").click();
return this;
}

public boolean existsOpenShiftIOAccount() {
return new PushButton(this, "Remove").isEnabled();
}

}
Expand Up @@ -12,6 +12,8 @@

import static org.jboss.tools.openshift.reddeer.utils.SystemProperties.KEY_SERVER;
import static org.jboss.tools.openshift.reddeer.utils.SystemProperties.KEY_USERNAME;
import static org.jboss.tools.openshift.reddeer.utils.SystemProperties.KEY_OPENSHIFT_IO_USERNAME;
import static org.jboss.tools.openshift.reddeer.utils.SystemProperties.KEY_OPENSHIFT_IO_PASSWORD;
import static org.jboss.tools.openshift.reddeer.utils.SystemProperties.getRequiredProperty;
import static org.junit.Assert.assertTrue;

Expand Down Expand Up @@ -62,6 +64,10 @@ public class DatastoreOS3 {
public static final String GIT_USERNAME = System.getProperty("github.username", "openshift-tools-testing-account");
public static final String GIT_PASSWORD = System.getProperty("github.password");

//OpenShift IO credentials
public static String OPENSHIFT_IO_USERNAME = System.getProperty(KEY_OPENSHIFT_IO_USERNAME);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MINOR Rename this field "OPENSHIFT_IO_USERNAME" to match the regular expression '^[a-z][a-zA-Z0-9]*$'. rule
MINOR Make this "public static OPENSHIFT_IO_USERNAME" field final rule
MINOR Make OPENSHIFT_IO_USERNAME a static final constant or non-public and provide accessors if needed. rule

public static String OPENSHIFT_IO_PASSWORD = System.getProperty(KEY_OPENSHIFT_IO_PASSWORD);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MINOR Rename this field "OPENSHIFT_IO_PASSWORD" to match the regular expression '^[a-z][a-zA-Z0-9]*$'. rule
MINOR Make this "public static OPENSHIFT_IO_PASSWORD" field final rule
MINOR Make OPENSHIFT_IO_PASSWORD a static final constant or non-public and provide accessors if needed. rule


public static String PROJECT1 = "project-name01-" + System.currentTimeMillis();
public static String PROJECT1_DISPLAYED_NAME = "displayedName-" + System.currentTimeMillis();
public static String PROJECT2 = "project-name02-" + System.currentTimeMillis();
Expand Down
Expand Up @@ -88,18 +88,7 @@ private static void triggerSecureStorageOfPasswordInConnectionDialog(String user

TestUtils.acceptSSLCertificate();

boolean firstStorage = provideSecureStoragePassword(SystemProperties.SECURE_STORAGE_PASSWORD);

if (firstStorage) {
// Did "Password hint needed" shell appear? Get rid of it.
try {
new DefaultShell(OpenShiftLabel.Shell.PASSWORD_HINT_NEEDED);
new NoButton().click();
} catch (CoreLayerException ex) {
// do nothing
LOGGER.debug("Password hint did not appear. Skipping.");
}
}
handleSecureStoragePasswordAndHint(SystemProperties.SECURE_STORAGE_PASSWORD);
// Remove password if it is stored
} else if (new CheckBox(1).isChecked() && !storePassword) {
new CheckBox(1).click();
Expand All @@ -108,6 +97,21 @@ private static void triggerSecureStorageOfPasswordInConnectionDialog(String user

new WaitWhile(new JobIsRunning());
}

public static void handleSecureStoragePasswordAndHint(String secureStoragePassword) {
boolean firstStorage = provideSecureStoragePassword(secureStoragePassword);

if (firstStorage) {
// Did "Password hint needed" shell appear? Get rid of it.
try {
new DefaultShell(OpenShiftLabel.Shell.PASSWORD_HINT_NEEDED);
new NoButton().click();
} catch (CoreLayerException ex) {
// do nothing
LOGGER.debug("Password hint did not appear. Skipping.");
}
}
}

private static boolean provideSecureStoragePassword(String password) {
try {
Expand Down
Expand Up @@ -27,6 +27,8 @@ public class SystemProperties {
public static final String KEY_USERNAME = "openshift.username";
public static final String KEY_PASSWORD = "openshift.password";
private static final String KEY_SECURE_STORAGE_PASSWORD = "securestorage.password";
public static final String KEY_OPENSHIFT_IO_USERNAME = "openshift.io.username";
public static final String KEY_OPENSHIFT_IO_PASSWORD = "openshift.io.password";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BLOCKER 'PASSWORD' detected in this expression, review this potentially hardcoded credential. rule


// secure storage
public static final String SECURE_STORAGE_PASSWORD = getRequiredProperty(KEY_SECURE_STORAGE_PASSWORD,
Expand Down