Skip to content

Commit

Permalink
openshift properties view test improvement JBIDE-23885 (#1814)
Browse files Browse the repository at this point in the history
  • Loading branch information
theJNOVAK authored and rhopp committed May 5, 2017
1 parent ccd7d21 commit 9dffb39
Showing 1 changed file with 84 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,63 @@
******************************************************************************/
package org.jboss.tools.openshift.ui.bot.test.project;

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

import java.util.List;

import org.jboss.reddeer.core.exception.CoreLayerException;
import org.jboss.reddeer.eclipse.ui.views.properties.PropertiesView;
import org.jboss.reddeer.eclipse.ui.views.properties.PropertiesViewProperty;
import org.jboss.reddeer.junit.runner.RedDeerSuite;
import org.jboss.reddeer.swt.api.TreeItem;
import org.jboss.tools.openshift.reddeer.requirement.OpenShiftConnectionRequirement.RequiredBasicConnection;
import org.jboss.tools.openshift.reddeer.requirement.OpenShiftProjectRequirement.RequiredProject;
import org.jboss.tools.openshift.reddeer.requirement.OpenShiftServiceRequirement.RequiredService;
import org.jboss.tools.openshift.reddeer.requirement.OpenShiftResources;
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;
import org.jboss.tools.openshift.reddeer.view.resources.OpenShiftProject;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

@RequiredBasicConnection
@RequiredProject
@RequiredService(project=DatastoreOS3.TEST_PROJECT,
service = OpenShiftResources.NODEJS_SERVICE,
template = OpenShiftResources.NODEJS_TEMPLATE)
@RunWith(RedDeerSuite.class)
public class ProjectPropertiesTest {

@Test
public void testProjectProperties() {
private static final String[] BASIC_PROPERTIES =
{"Creation Timestamp", "Kind", "Name", "Namespace", "Resource Version"};
private static final String[] BASIC_TABS =
{"Details", "Builds", "Build Configs", "Deployments",
"Deployment Configs", "Image Streams", "Pods", "Routes", "Services"};

private PropertiesView propertiesView;
private OpenShiftProject project;

@Before
public void setUp() {
OpenShiftExplorerView explorer = new OpenShiftExplorerView();
explorer.open();

OpenShift3Connection connection = explorer.getOpenShift3Connection();
OpenShiftProject project = connection.getProject(DatastoreOS3.TEST_PROJECT);
project = connection.getProject(DatastoreOS3.TEST_PROJECT);
project.select();
project.openProperties();
project.selectTabbedProperty("Details");

PropertiesView propertiesView = new PropertiesView();
propertiesView = new PropertiesView();
}

@Test
public void testProjectNameProperties() {
project.selectTabbedProperty("Details");

String displayedName = propertiesView.getProperty("Annotations", "openshift.io/display-name").getPropertyValue();
String name = propertiesView.getProperty("Basic", "Name").getPropertyValue();
String namespace = propertiesView.getProperty("Basic", "Namespace").getPropertyValue();
Expand All @@ -49,5 +79,54 @@ public void testProjectProperties() {
assertTrue("Property namespace is not correct. Property is " + namespace
+ " but was expected " + DatastoreOS3.TEST_PROJECT, namespace.equals(DatastoreOS3.TEST_PROJECT));
}

@Test
public void testTabs() {
for (String tabName : BASIC_TABS) {
project.selectTabbedProperty(tabName);
assertBasicProperties();
assertAnnotationProperties();
}
}

private void assertBasicProperties() {
for (String propertyName : BASIC_PROPERTIES) {
assertPropertyNotEmpty("Basic", propertyName);
}
}

private void assertAnnotationProperties() {
for (TreeItem property : getCurrentAnnotationProperties()) {
assertPropertyNotEmpty(property.getPath());
}
}

/**
* Asserts that property with specified path exists and has a non-empty value.
* @param path path to property
*/
private void assertPropertyNotEmpty(String... path) {
String errorMessage = "Property " + path[path.length - 1] + " should be present";
try {
String propertyValue = propertiesView.getProperty(path).getPropertyValue();
assertNotNull(errorMessage, propertyValue);
} catch (CoreLayerException e) {
fail(errorMessage + System.lineSeparator() + e.getMessage());
}
}

private List<TreeItem> getCurrentAnnotationProperties() {
try {
PropertiesViewProperty annotationPropertiesRoot = propertiesView.getProperty("Annotations");
List<TreeItem> annotationProperties = annotationPropertiesRoot.getTreeItem().getItems();
assertTrue("There should be some annotation properties in the tab",
annotationProperties != null && annotationProperties.size() > 0);

return annotationProperties;
} catch (CoreLayerException e) {
fail(e.getMessage());
return null;
}
}

}

0 comments on commit 9dffb39

Please sign in to comment.