Search in sources :

Example 21 with RedDeerException

use of org.eclipse.reddeer.common.exception.RedDeerException in project jbosstools-openshift by jbosstools.

the class OpenShiftServiceRequirement method waitForUI.

/**
 * Waits for the service and replication controller to appear in the UI,
 * possibly refreshes the project. This shouldnt be required but turns out
 * that the UI takes extensive amount of time to notice the new resources.
 * We therefore make sure they are present in UI before considering this
 * requirement as fullfilled and possibly refresh the project (in ui) to
 * force it to appear. This shouldnt be necessary, I consider this as workaround.
 *
 * @param projectName
 * @param serviceName
 */
private void waitForUI(final String serviceName, final String projectName) {
    // wait for service to appear in UI
    new WaitUntil(new AbstractWaitCondition() {

        @Override
        public boolean test() {
            OpenShiftExplorerView explorer = new OpenShiftExplorerView();
            explorer.open();
            OpenShift3Connection os3Connection = explorer.getOpenShift3Connection(connection);
            assertThat(os3Connection, not(nullValue()));
            OpenShiftProject os3Project = os3Connection.getProject(projectName);
            assertThat(os3Project, not(nullValue()));
            boolean serviceExists = false;
            try {
                serviceExists = os3Project.getService(serviceName) != null;
            } catch (RedDeerException e) {
                // catched intentionnally
                System.err.println(e);
            }
            /*
						 * WORKAROUND: UI takes extensive amount of time to notice resource changes
						 * -> refresh tree to force it to see changes
						 */
            if (!serviceExists) {
                os3Project.refresh();
            }
            return serviceExists;
        }
    }, TimePeriod.VERY_LONG);
    // wait for replication controller to appear in UI
    List<IReplicationController> rcs = connection.getResources(ResourceKind.REPLICATION_CONTROLLER, service.getNamespaceName());
    IReplicationController serviceRc = ResourceUtils.getReplicationControllerFor(service, rcs);
    assertThat(serviceRc, not(nullValue()));
    new WaitUntil(new OpenShiftResourceExists(Resource.DEPLOYMENT, containsString(serviceRc.getName()), ResourceState.UNSPECIFIED, projectName, connection), TimePeriod.VERY_LONG);
}
Also used : RedDeerException(org.eclipse.reddeer.common.exception.RedDeerException) OpenShiftProject(org.jboss.tools.openshift.reddeer.view.resources.OpenShiftProject) WaitUntil(org.eclipse.reddeer.common.wait.WaitUntil) AbstractWaitCondition(org.eclipse.reddeer.common.condition.AbstractWaitCondition) OpenShiftExplorerView(org.jboss.tools.openshift.reddeer.view.OpenShiftExplorerView) IReplicationController(com.openshift.restclient.model.IReplicationController) OpenShiftResourceExists(org.jboss.tools.openshift.reddeer.condition.OpenShiftResourceExists) OpenShift3Connection(org.jboss.tools.openshift.reddeer.view.resources.OpenShift3Connection)

Example 22 with RedDeerException

use of org.eclipse.reddeer.common.exception.RedDeerException in project jbosstools-openshift by jbosstools.

the class TestUtils method getProjectAbsolutePath.

/**
 * Provide resource absolute path in project directory
 * @param path - resource relative path
 * @return resource absolute path
 */
public static String getProjectAbsolutePath(String... path) {
    // Construct path
    StringBuilder builder = new StringBuilder();
    for (String fragment : path) {
        builder.append("/" + fragment);
    }
    String filePath = System.getProperty("user.dir");
    File file = new File(filePath + builder.toString());
    if (!file.exists()) {
        throw new RedDeerException("Resource file does not exists within project path " + filePath + builder.toString());
    }
    return file.getAbsolutePath();
}
Also used : RedDeerException(org.eclipse.reddeer.common.exception.RedDeerException) File(java.io.File)

Example 23 with RedDeerException

use of org.eclipse.reddeer.common.exception.RedDeerException in project jbosstools-openshift by jbosstools.

the class OpenShiftServiceRequirement method fulfill.

@Override
public void fulfill() {
    this.connection = ConnectionUtils.getConnectionOrDefault(serviceSpec.connectionURL());
    assertNotNull(NLS.bind("No connection for {0} exists", serviceSpec.connectionURL()), connection);
    final String projectName = TestUtils.getValueOrDefault(serviceSpec.project(), DatastoreOS3.TEST_PROJECT);
    assertTrue(NLS.bind("No project {0} exists on server {1}", projectName, connection.getHost()), OpenShift3NativeResourceUtils.hasProject(projectName, connection));
    final String serviceName = serviceSpec.service();
    final String templateName = serviceSpec.template();
    IResourceFactory factory = new ClientBuilder(connection.getHost()).build().getResourceFactory();
    try {
        // try if template comes from a URL
        URL url = new URL(templateName);
        template = factory.create(url.openStream());
    } catch (MalformedURLException ex) {
        // template is not a URL, try a path to local file instead
        if (new File(templateName).exists()) {
            try {
                template = factory.create(new FileInputStream(templateName));
            } catch (FileNotFoundException e) {
                throw new RedDeerException("Unable to read local template", e);
            }
        } else {
            // it is not an external template
            template = connection.getResource(ResourceKind.TEMPLATE, OpenShiftResources.OPENSHIFT_PROJECT, templateName);
        }
    } catch (IOException ex) {
        throw new RedDeerException("Unable to read template from URL", ex);
    }
    assertNotNull(template);
    this.service = getOrCreateService(projectName, serviceName, template);
    if (serviceSpec.waitForBuild()) {
        waitForResources(serviceName, projectName, service);
        waitForUI(serviceName, projectName);
    }
}
Also used : RedDeerException(org.eclipse.reddeer.common.exception.RedDeerException) MalformedURLException(java.net.MalformedURLException) FileNotFoundException(java.io.FileNotFoundException) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) IOException(java.io.IOException) IResourceFactory(com.openshift.restclient.IResourceFactory) File(java.io.File) URL(java.net.URL) ConnectionURL(org.jboss.tools.openshift.common.core.connection.ConnectionURL) FileInputStream(java.io.FileInputStream) ClientBuilder(com.openshift.restclient.ClientBuilder)

Example 24 with RedDeerException

use of org.eclipse.reddeer.common.exception.RedDeerException in project jbosstools-openshift by jbosstools.

the class CDKServerEditorAbstractTest method addCDKServer.

public void addCDKServer() {
    NewCDKServerWizard dialog = CDKTestUtils.openNewServerWizardDialog();
    try {
        setupServerWizardPage(dialog);
        new WaitUntil(new ControlIsEnabled(new FinishButton()), TimePeriod.MEDIUM, false);
        dialog.finish(TimePeriod.MEDIUM);
    } catch (RedDeerException coreExc) {
        new CancelButton().click();
        throw new CDKServerException("Exception occured in CDK server wizard, wizard was canceled", coreExc);
    }
}
Also used : RedDeerException(org.eclipse.reddeer.common.exception.RedDeerException) FinishButton(org.eclipse.reddeer.swt.impl.button.FinishButton) ControlIsEnabled(org.eclipse.reddeer.swt.condition.ControlIsEnabled) CancelButton(org.eclipse.reddeer.swt.impl.button.CancelButton) CDKServerException(org.jboss.tools.cdk.reddeer.server.exception.CDKServerException) NewCDKServerWizard(org.jboss.tools.cdk.reddeer.server.ui.wizard.NewCDKServerWizard) WaitUntil(org.eclipse.reddeer.common.wait.WaitUntil)

Example 25 with RedDeerException

use of org.eclipse.reddeer.common.exception.RedDeerException in project jbosstools-openshift by jbosstools.

the class CDKAbstractTest method getProjectAbsolutePath.

/**
 * Provide resource absolute path in project directory
 * @param path - resource relative path
 * @return resource absolute path
 */
public static String getProjectAbsolutePath(String... path) {
    // Construct path
    StringBuilder builder = new StringBuilder();
    for (String fragment : path) {
        builder.append("/" + fragment);
    }
    String filePath = "";
    filePath = System.getProperty("user.dir");
    File file = new File(filePath + builder.toString());
    if (!file.exists()) {
        throw new RedDeerException("Resource file does not exists within project path " + filePath + builder.toString());
    }
    return file.getAbsolutePath();
}
Also used : RedDeerException(org.eclipse.reddeer.common.exception.RedDeerException) File(java.io.File)

Aggregations

RedDeerException (org.eclipse.reddeer.common.exception.RedDeerException)34 WaitUntil (org.eclipse.reddeer.common.wait.WaitUntil)12 WaitWhile (org.eclipse.reddeer.common.wait.WaitWhile)11 Test (org.junit.Test)11 ShellIsAvailable (org.eclipse.reddeer.swt.condition.ShellIsAvailable)10 DefaultShell (org.eclipse.reddeer.swt.impl.shell.DefaultShell)10 JobIsRunning (org.eclipse.reddeer.workbench.core.condition.JobIsRunning)7 AbstractTest (org.jboss.tools.openshift.ui.bot.test.application.v3.basic.AbstractTest)7 ControlIsEnabled (org.eclipse.reddeer.swt.condition.ControlIsEnabled)6 FinishButton (org.eclipse.reddeer.swt.impl.button.FinishButton)6 OpenShiftExplorerView (org.jboss.tools.openshift.reddeer.view.OpenShiftExplorerView)6 PushButton (org.eclipse.reddeer.swt.impl.button.PushButton)5 TextEditor (org.eclipse.reddeer.workbench.impl.editor.TextEditor)5 PackageExplorerPart (org.eclipse.reddeer.eclipse.jdt.ui.packageview.PackageExplorerPart)4 OkButton (org.eclipse.reddeer.swt.impl.button.OkButton)4 ContextMenuItem (org.eclipse.reddeer.swt.impl.menu.ContextMenuItem)4 LabeledText (org.eclipse.reddeer.swt.impl.text.LabeledText)4 File (java.io.File)3 LabeledCombo (org.eclipse.reddeer.swt.impl.combo.LabeledCombo)3 DefaultStyledText (org.eclipse.reddeer.swt.impl.styledtext.DefaultStyledText)3