Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[JBIDE-23029] impl'd requirements for connection, project, service (#…
…1609)

* impl'd requirements for connection, project, service
* allow UI assertions to specify connection and project
  • Loading branch information
adietish authored and rhopp committed Oct 25, 2016
1 parent eccff33 commit 677cd68
Show file tree
Hide file tree
Showing 46 changed files with 1,676 additions and 303 deletions.
21 changes: 14 additions & 7 deletions plugins/org.jboss.tools.openshift.reddeer/META-INF/MANIFEST.MF
Expand Up @@ -4,19 +4,27 @@ Bundle-Name: RedDeer API for OpenShift UI Tests
Bundle-SymbolicName: org.jboss.tools.openshift.reddeer
Bundle-Version: 4.4.2.qualifier
Bundle-Activator: org.jboss.tools.openshift.reddeer.Activator
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.jgit,
org.junit;bundle-version="4.8.2",
org.apache.commons.compress,
Require-Bundle:
org.jboss.tools.openshift.ui;bundle-version="3.3.0",
org.jboss.tools.common.core;bundle-version="3.8.1",
org.jboss.tools.openshift.common.core;bundle-version="3.3.0",
org.apache.commons.lang;bundle-version="2.6.0",
org.jboss.reddeer.jface;bundle-version="[1.0.0,2.0.0)",
org.jboss.reddeer.swt;bundle-version="[1.0.0,2.0.0)",
org.jboss.reddeer.eclipse;bundle-version="[1.0.0,2.0.0)",
org.jboss.reddeer.workbench;bundle-version="[1.0.0,2.0.0)",
org.jboss.reddeer.uiforms;bundle-version="[1.0.0,2.0.0)",
org.jboss.reddeer.common;bundle-version="[1.0.0,2.0.0)",
org.jboss.reddeer.core;bundle-version="[1.0.0,2.0.0)"
org.jboss.reddeer.core;bundle-version="[1.0.0,2.0.0)",
org.jboss.reddeer.junit;bundle-version="1.1.0",
org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.jgit,
org.junit;bundle-version="4.8.2",
org.apache.commons.compress,
org.apache.commons.lang;bundle-version="2.6.0",
org.jboss.tools.openshift.core;bundle-version="3.3.0",
org.jboss.tools.openshift.client;bundle-version="3.3.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-ActivationPolicy: lazy
Eclipse-BundleShape: jar
Expand All @@ -40,4 +48,3 @@ Export-Package: org.jboss.tools.openshift.reddeer.condition,
org.jboss.tools.openshift.reddeer.wizard.page.v2,
org.jboss.tools.openshift.reddeer.wizard.v2,
org.jboss.tools.openshift.reddeer.wizard.v3
Import-Package: org.jboss.reddeer.junit.requirement
Expand Up @@ -55,6 +55,9 @@ public boolean test() {
return false;
}

// TODO: this FLAWED: it assumes that all pods that it finds within a
// project are the pods for the application that a test wants to wait
// for
for (OpenShiftResource resource: pods) {
if (!resource.getName().contains("build") &&
!resource.getName().contains("deploy")) {
Expand Down
Expand Up @@ -11,6 +11,7 @@
package org.jboss.tools.openshift.reddeer.condition;

import org.jboss.reddeer.common.condition.AbstractWaitCondition;
import org.jboss.tools.openshift.core.connection.Connection;
import org.jboss.tools.openshift.reddeer.utils.DatastoreOS3;
import org.jboss.tools.openshift.reddeer.view.OpenShiftExplorerView;
import org.jboss.tools.openshift.reddeer.view.resources.OpenShift3Connection;
Expand All @@ -30,12 +31,20 @@ public class OpenShiftProjectExists extends AbstractWaitCondition {
* @param projectDisplayedName project displayed name
*/
public OpenShiftProjectExists(String projectName) {
this(projectName, null);
}

public OpenShiftProjectExists(String projectName, Connection connection) {
this.projectName = projectName;

OpenShiftExplorerView explorer = new OpenShiftExplorerView();
connection = explorer.getOpenShift3Connection();
if (connection == null) {
this.connection = explorer.getOpenShift3Connection();
} else {
this.connection = explorer.getOpenShift3Connection(connection);
}
}

/**
* Creates condition OpenShift project exists for a project defined in {@link DatastoreOS3} as first one.
*/
Expand Down
Expand Up @@ -12,13 +12,15 @@

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.hamcrest.Matcher;
import org.jboss.reddeer.common.condition.AbstractWaitCondition;
import org.jboss.reddeer.core.exception.CoreLayerException;
import org.jboss.reddeer.core.matcher.WithTextMatcher;
import org.jboss.tools.openshift.reddeer.enums.Resource;
import org.jboss.tools.openshift.reddeer.enums.ResourceState;
import org.jboss.tools.openshift.reddeer.view.OpenShiftExplorerView;
import org.jboss.tools.openshift.reddeer.view.resources.OpenShift3Connection;
import org.jboss.tools.openshift.reddeer.view.resources.OpenShiftProject;
import org.jboss.tools.openshift.reddeer.view.resources.OpenShiftResource;

Expand All @@ -28,22 +30,22 @@
* @author mlabuda@redhat.com
*
*/
public class ResourceExists extends AbstractWaitCondition {
public class OpenShiftResourceExists extends AbstractWaitCondition {

private OpenShiftExplorerView explorer;
private final OpenShiftExplorerView explorer;
private OpenShiftProject project;
private Matcher resourceNameMatcher;
private ResourceState resourceState;
private Resource resource;
private final Matcher<String> resourceNameMatcher;
private final ResourceState resourceState;
private final Resource resource;

/**
* Creates new ResourceExists to wait for existence of any resource of specified type for
* default connection and project.
*
* @param resource resource type
*/
public ResourceExists(Resource resource) {
this(resource, (Matcher) null, ResourceState.UNSPECIFIED);
public OpenShiftResourceExists(Resource resource) {
this(resource, (Matcher<String>) null, ResourceState.UNSPECIFIED);
}

/**
Expand All @@ -53,7 +55,7 @@ public ResourceExists(Resource resource) {
* @param resource resource type
* @param resourceName resource name
*/
public ResourceExists(Resource resource, String resourceName) {
public OpenShiftResourceExists(Resource resource, String resourceName) {
this(resource, new WithTextMatcher(resourceName), ResourceState.UNSPECIFIED);
}

Expand All @@ -66,18 +68,22 @@ public ResourceExists(Resource resource, String resourceName) {
* @param resourceName resource name
* @param resourceState state of a resource
*/
public ResourceExists(Resource resource, String resourceName, ResourceState resourceState) {
this(resource, new WithTextMatcher(resourceName), resourceState);
public OpenShiftResourceExists(Resource resource, String resourceName, ResourceState resourceState) {
this(resource, new WithTextMatcher(resourceName), resourceState, null);
}

public OpenShiftResourceExists(Resource resource, String resourceName, ResourceState resourceState, String projectName) {
this(resource, new WithTextMatcher(resourceName), resourceState, projectName);
}

/**
* Creates new ResourceExists to wait for existence of a resource of specified type
* matching specified resource name matcher for default connection and project.
*
* @param resource resource type
* @param nameMatcher resource name matcher
*/
public ResourceExists(Resource resource, Matcher nameMatcher) {
public OpenShiftResourceExists(Resource resource, Matcher<String> nameMatcher) {
this(resource, nameMatcher, ResourceState.UNSPECIFIED);
}

Expand All @@ -90,34 +96,34 @@ public ResourceExists(Resource resource, Matcher nameMatcher) {
* @param nameMatcher resource name matcher
* @param resourceState state of a resource
*/
public ResourceExists(Resource resource, Matcher nameMatcher, ResourceState resourceState) {
explorer = new OpenShiftExplorerView();
project = explorer.getOpenShift3Connection().getProject();
resourceNameMatcher = nameMatcher;
public OpenShiftResourceExists(Resource resource, Matcher<String> nameMatcher, ResourceState resourceState) {
this(resource, nameMatcher, resourceState, null);
}

public OpenShiftResourceExists(Resource resource, Matcher<String> nameMatcher, ResourceState resourceState, String projectName) {
this.explorer = new OpenShiftExplorerView();
this.project = getProjectOrDefault(projectName, explorer);
this.resourceNameMatcher = nameMatcher;
this.resourceState = resourceState;
this.resource = resource;
}

@Override
private OpenShiftProject getProjectOrDefault(String projectName, OpenShiftExplorerView explorer) {
if (StringUtils.isEmpty(projectName)) {
return explorer.getOpenShift3Connection().getProject();
} else {
return explorer.getOpenShift3Connection().getProject(projectName);
}
}

@Override
public boolean test() {
// workaround for disposed widget
if (project.getTreeItem().isDisposed()) {
project = explorer.getOpenShift3Connection().getProject();
this.project = explorer.getOpenShift3Connection().getProject(project.getName());
}

List<OpenShiftResource> resources;
try {
resources = project.getOpenShiftResources(resource);
} catch (CoreLayerException ex) {
// In case widget is still disposed... what the heck?!
explorer.getOpenShift3Connection().refresh();
resources = explorer.getOpenShift3Connection().getProject().getOpenShiftResources(resource);
}

if (resources.isEmpty()) {
return false;
}


List<OpenShiftResource> resources = getResources();
for (OpenShiftResource rsrc: resources) {
if (resourceNameMatcher == null) {
return true;
Expand All @@ -132,6 +138,19 @@ public boolean test() {
return false;
}

private List<OpenShiftResource> getResources() {
List<OpenShiftResource> resources;
try {
resources = project.getOpenShiftResources(resource);
} catch (CoreLayerException ex) {
// In case widget is still disposed... what the heck?!
OpenShift3Connection connection = explorer.getOpenShift3Connection();
connection.refresh();
resources = connection.getProject(project.getName()).getOpenShiftResources(resource);
}
return resources;
}

@Override
public String description() {
String matcherDescription = resourceNameMatcher == null ? "" : " matching resource name matcher " +
Expand Down
Expand Up @@ -10,8 +10,9 @@
******************************************************************************/
package org.jboss.tools.openshift.reddeer.condition;

import java.util.List;
import static org.junit.Assert.assertNotNull;

import org.apache.commons.lang.StringUtils;
import org.jboss.reddeer.common.condition.AbstractWaitCondition;
import org.jboss.tools.openshift.reddeer.enums.Resource;
import org.jboss.tools.openshift.reddeer.view.OpenShiftExplorerView;
Expand All @@ -31,21 +32,18 @@
*/
public class PodsAreDeployed extends AbstractWaitCondition {

private OpenShiftResource replicationController;
private String podAmountValue;
private final OpenShiftResource replicationController;
private final String podAmountValue;

/**
* Constructor to wait for a specific amount of pods to be running
* @param projectName name of project with a replication controller
* @param resourceName name of replication controller
* @param replicationControllerName name of replication controller
* @param desiredAmountOfPods desired amount of running pods
*/
public PodsAreDeployed(String projectName, String resourceName, int desiredAmountOfPods) {
OpenShiftExplorerView explorer = new OpenShiftExplorerView();
explorer.open();
replicationController = explorer.getOpenShift3Connection().getProject(projectName).
getOpenShiftResource(Resource.DEPLOYMENT, resourceName);
podAmountValue = desiredAmountOfPods + " current / " + desiredAmountOfPods + " desired";
public PodsAreDeployed(OpenShiftProject project, String replicationControllerName, int desiredAmountOfPods) {
assertNotNull(this.replicationController = project.getOpenShiftResource(Resource.DEPLOYMENT, replicationControllerName));
this.podAmountValue = desiredAmountOfPods + " current / " + desiredAmountOfPods + " desired";
}

@Override
Expand All @@ -54,27 +52,45 @@ public boolean test() {
return replicationController.getPropertyValue("Misc", "Replicas").trim().equals(
podAmountValue);
}
public static int getNumberOfCurrentReplicas() {
return Integer.valueOf(getReplicasInfo().split(" ")[0]).intValue();

public static int getNumberOfCurrentReplicas(String project, String replicationControllerName) {
return getReplicas(getReplicasInfo(project, replicationControllerName));
}

public static int getNumberOfDesiredReplicas() {
return Integer.valueOf(getReplicasInfo().split(" ")[3]).intValue();

public static int getNumberOfCurrentReplicas(OpenShiftProject project, String replicationControllerName) {
return getReplicas(getReplicasInfo(project, replicationControllerName));
}

public static int getNumberOfCurrentReplicas(String server, String username, String project, String replicationControllerName) {
return getReplicas(getReplicasInfo(server, username, project, replicationControllerName));
}

public static String getReplicasInfo(String server, String username, String project, String replicationControllerName) {
return getReplicasInfo(new OpenShiftExplorerView().getOpenShift3Connection(server, username).getProject(project), replicationControllerName);
}

public static String getReplicasInfo(String project, String replicationControllerName) {
return getReplicasInfo(new OpenShiftExplorerView().getOpenShift3Connection().getProject(project), replicationControllerName);
}

private static int getReplicas(String replicaInfo) {
if (StringUtils.isEmpty(replicaInfo)) {
return -1;
}

return Integer.valueOf(replicaInfo.split(" ")[0]);
}

public static String getReplicasInfo() {
OpenShiftExplorerView explorer = new OpenShiftExplorerView();
OpenShiftProject project = explorer.getOpenShift3Connection().getProject();
OpenShiftResource replicationController = null;
List<OpenShiftResource> rsrcs = project.getOpenShiftResources(Resource.DEPLOYMENT);
for (OpenShiftResource resource: rsrcs) {
if (resource.getName().contains("-" + rsrcs.size())) {
replicationController = resource;
break;
}
public static String getReplicasInfo(OpenShiftProject project, String replicationControllerName) {
if (project == null
|| StringUtils.isEmpty(replicationControllerName)) {
return null;
}

OpenShiftResource replicationController = project.getOpenShiftResource(Resource.DEPLOYMENT, replicationControllerName);
if (replicationController == null) {
return null;
}

return replicationController.getPropertyValue("Misc", "Replicas").trim();
}
}
@@ -0,0 +1,60 @@
/*******************************************************************************
* Copyright (c) 2016 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.condition.core;

import static org.junit.Assert.assertNotNull;

import org.jboss.reddeer.common.condition.AbstractWaitCondition;
import org.jboss.tools.openshift.core.connection.Connection;

import com.openshift.restclient.OpenShiftException;

/**
* Wait condition to wait for existence of a resource of a given kind and name
* in the given project. The condition operates on the client-lib, not on the
* UI.
*
* @author adietish@redhat.com
*
*/
public class NamedResourceExist extends AbstractWaitCondition {

private final String kind;
protected final String name;
private String project;
protected Connection connection;

public NamedResourceExist(String kind, String name, String project, Connection connection) {
assertNotNull(kind);
assertNotNull(name);
assertNotNull(connection);

this.kind = kind;
this.name = name;
this.project = project;
this.connection = connection;
}

@Override
public boolean test() {
try {
connection.getResource(kind, project, name);
return true;
} catch(OpenShiftException e) {
return false;
}
}

@Override
public String description() {
return kind + " named " + name + " in project " + project + " gets available.";
}
}

0 comments on commit 677cd68

Please sign in to comment.