Search in sources :

Example 11 with OpenShiftToolsException

use of org.jboss.tools.openshift.reddeer.exception.OpenShiftToolsException in project jbosstools-openshift by jbosstools.

the class OpenShiftCommandLineToolsRequirement method downloadAndExtractOpenShiftClient.

private File downloadAndExtractOpenShiftClient(String url) {
    LOGGER.info("Creating directory binaries");
    File outputDirectory = new File(CLIENT_TOOLS_DESTINATION);
    FileHelper.createDirectory(outputDirectory);
    String fileName = downloadArchive(url);
    String extractedDirectory = extractArchive(fileName, outputDirectory);
    if (StringUtils.isEmpty(extractedDirectory) || !(new File(extractedDirectory).exists())) {
        throw new OpenShiftToolsException("Cannot extract archive " + fileName + ". " + "Archive does not extract into a single root folder");
    }
    return new File(extractedDirectory, OCBinaryFile.get().getName());
}
Also used : File(java.io.File) OpenShiftToolsException(org.jboss.tools.openshift.reddeer.exception.OpenShiftToolsException)

Example 12 with OpenShiftToolsException

use of org.jboss.tools.openshift.reddeer.exception.OpenShiftToolsException in project jbosstools-openshift by jbosstools.

the class ConnectionUtils method getConnection.

/**
 * Returns a connection for the given connection server and username
 * @param connectionUrlString
 * @return
 *
 * @see ConnectionURL
 */
public static Connection getConnection(String username, String server) {
    try {
        String url = UrlUtils.getUrlFor(username, server);
        ConnectionURL connectionUrl = ConnectionURL.forURL(url);
        return ConnectionsRegistrySingleton.getInstance().getByUrl(connectionUrl, Connection.class);
    } catch (UnsupportedEncodingException | MalformedURLException e) {
        throw new OpenShiftToolsException(NLS.bind("Could not lookup connection to server {0}: {1}", server, e));
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) ConnectionURL(org.jboss.tools.openshift.common.core.connection.ConnectionURL) UnsupportedEncodingException(java.io.UnsupportedEncodingException) OpenShiftToolsException(org.jboss.tools.openshift.reddeer.exception.OpenShiftToolsException)

Example 13 with OpenShiftToolsException

use of org.jboss.tools.openshift.reddeer.exception.OpenShiftToolsException in project jbosstools-openshift by jbosstools.

the class FileHelper method unzipFile.

public static void unzipFile(File zipArchive, File outputDirectory) {
    ZipFile zipfile = null;
    try {
        zipfile = new ZipFile(zipArchive);
    } catch (IOException ex) {
        throw new OpenShiftToolsException("Exception occured while processing zip file.\n" + ex.getMessage());
    }
    String extractedDirectory = StringUtils.chomp(zipArchive.getName(), ".zip");
    Enumeration<? extends ZipEntry> entries = zipfile.entries();
    while (entries.hasMoreElements()) {
        ZipEntry entry = (ZipEntry) entries.nextElement();
        unzipEntry(zipfile, entry, new File(outputDirectory, extractedDirectory));
    }
}
Also used : ZipFile(java.util.zip.ZipFile) ZipEntry(java.util.zip.ZipEntry) IOException(java.io.IOException) File(java.io.File) ZipFile(java.util.zip.ZipFile) OpenShiftToolsException(org.jboss.tools.openshift.reddeer.exception.OpenShiftToolsException)

Example 14 with OpenShiftToolsException

use of org.jboss.tools.openshift.reddeer.exception.OpenShiftToolsException in project jbosstools-openshift by jbosstools.

the class OpenShift3ConnectionWizard method discover.

/**
 * Overwriting of URL requires user confirmation, Message Dialog is shown. If
 * url is not filled in, no dialog pops up and url is generated automatically.
 * If it is not possible to get proper registry url (ie. adapter is stopped),
 * then Error dialog is thrown.
 */
public void discover() {
    Button discover = getDiscoveryButton();
    discover.click();
    try {
        new WaitUntil(new ShellIsAvailable(OpenShiftLabel.Shell.REGISTRY_URL_NOT_FOUND), TimePeriod.DEFAULT);
        // Error dialog appeared, exception will be thrown
        log.error("Unable to discover a registry URL");
        throw new OpenShiftToolsException(OpenShiftLabel.Shell.REGISTRY_URL_NOT_FOUND);
    } catch (WaitTimeoutExpiredException exc) {
    // Error dialog was not thrown
    }
    try {
        confirmMessageDialog();
    } catch (WaitTimeoutExpiredException exc) {
        // Confirmation dialog did not appear, only spotted reason so far is that
        // it would be replacing the same URL.
        log.info("Discover action did not invoke any dialog");
    }
}
Also used : ShellIsAvailable(org.eclipse.reddeer.swt.condition.ShellIsAvailable) PushButton(org.eclipse.reddeer.swt.impl.button.PushButton) FinishButton(org.eclipse.reddeer.swt.impl.button.FinishButton) CancelButton(org.eclipse.reddeer.swt.impl.button.CancelButton) OkButton(org.eclipse.reddeer.swt.impl.button.OkButton) Button(org.eclipse.reddeer.swt.api.Button) WaitTimeoutExpiredException(org.eclipse.reddeer.common.exception.WaitTimeoutExpiredException) WaitUntil(org.eclipse.reddeer.common.wait.WaitUntil) OpenShiftToolsException(org.jboss.tools.openshift.reddeer.exception.OpenShiftToolsException)

Example 15 with OpenShiftToolsException

use of org.jboss.tools.openshift.reddeer.exception.OpenShiftToolsException in project jbosstools-openshift by jbosstools.

the class CDKImageRegistryUrlDiscoveryFailureTest method testRegistryUrlNotFoundDialog.

/**
 * Covers JBIDE-25049
 */
@Test
public void testRegistryUrlNotFoundDialog() {
    String shellTitle = OpenShiftLabel.Shell.REGISTRY_URL_NOT_FOUND;
    wizard.getImageRegistryUrl().setText("");
    wizard.finish();
    stopServerAdapter();
    wizard = connection.editConnection();
    switchOffPasswordSaving();
    try {
        wizard.discover();
        fail("Expected OpenshiftToolsException was not thrown, possibly no dialog is shown.");
    } catch (OpenShiftToolsException osExc) {
        // os exception was thrown with specific message
        assertTrue("Registry URL not found dialog did not appear.", osExc.getMessage().contains(shellTitle));
        // error dialog is still there
        new WaitUntil(new ShellIsAvailable(shellTitle), TimePeriod.SHORT);
        new DefaultShell(shellTitle);
        new OkButton().click();
    }
    wizard.cancel();
}
Also used : ShellIsAvailable(org.eclipse.reddeer.swt.condition.ShellIsAvailable) OkButton(org.eclipse.reddeer.swt.impl.button.OkButton) DefaultShell(org.eclipse.reddeer.swt.impl.shell.DefaultShell) WaitUntil(org.eclipse.reddeer.common.wait.WaitUntil) OpenShiftToolsException(org.jboss.tools.openshift.reddeer.exception.OpenShiftToolsException) Test(org.junit.Test)

Aggregations

OpenShiftToolsException (org.jboss.tools.openshift.reddeer.exception.OpenShiftToolsException)16 File (java.io.File)7 IOException (java.io.IOException)4 MalformedURLException (java.net.MalformedURLException)3 WaitUntil (org.eclipse.reddeer.common.wait.WaitUntil)3 ShellIsAvailable (org.eclipse.reddeer.swt.condition.ShellIsAvailable)3 ServerAdapter (org.jboss.tools.openshift.reddeer.view.resources.ServerAdapter)3 FileOutputStream (java.io.FileOutputStream)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ZipFile (java.util.zip.ZipFile)2 WaitTimeoutExpiredException (org.eclipse.reddeer.common.exception.WaitTimeoutExpiredException)2 WaitWhile (org.eclipse.reddeer.common.wait.WaitWhile)2 ProjectExplorer (org.eclipse.reddeer.eclipse.ui.navigator.resources.ProjectExplorer)2 OkButton (org.eclipse.reddeer.swt.impl.button.OkButton)2 DefaultShell (org.eclipse.reddeer.swt.impl.shell.DefaultShell)2 JobIsRunning (org.eclipse.reddeer.workbench.core.condition.JobIsRunning)2 ConnectionURL (org.jboss.tools.openshift.common.core.connection.ConnectionURL)2 After (org.junit.After)2 BufferedInputStream (java.io.BufferedInputStream)1 BufferedOutputStream (java.io.BufferedOutputStream)1