Skip to content
2 changes: 1 addition & 1 deletion selenium/che-selenium-core/bin/webdriver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ initVariables() {
PRODUCT_HOST=$(detectDockerInterfaceIp)
PRODUCT_PORT=8080

SUPPORTED_INFRASTRUCTURES=(docker openshift)
SUPPORTED_INFRASTRUCTURES=(docker openshift k8s osio)

unset DEBUG_OPTIONS
unset MAVEN_OPTIONS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ public interface TestGroup {
String DOCKER = "docker";
String GITHUB = "github";
String OSIO = "osio";
String K8S = "k8s";
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ public Map.Entry<String, String> apply(Map.Entry<String, String> entry) {
name = name.replace("__", "=");
name = name.replace('_', '.');
name = name.replace("=", "_");

// convert value of CHE_INFRASTRUCTURE to upper case to comply with Infrastructure
// enumeration;
if (name.equals("che.infrastructure")) {
return new AbstractMap.SimpleEntry<>(name, entry.getValue().toUpperCase());
}

return new AbstractMap.SimpleEntry<>(name, entry.getValue());
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (c) 2012-2018 Red Hat, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.selenium.core.constant;

import com.google.inject.Singleton;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

javadoc

/**
* Reflects values of environment variable CHE_INFRASTRUCTURE
*
* @author Dmytro Nochevnov
*/
@Singleton
public enum Infrastructure {
DOCKER,
OPENSHIFT,
K8S,
OSIO
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.eclipse.che.selenium.core.SeleniumWebDriver;
import org.eclipse.che.selenium.core.client.TestFactoryServiceClient;
import org.eclipse.che.selenium.core.client.TestWorkspaceServiceClient;
import org.eclipse.che.selenium.core.constant.Infrastructure;
import org.eclipse.che.selenium.core.entrance.Entrance;
import org.eclipse.che.selenium.core.provider.TestApiEndpointUrlProvider;
import org.eclipse.che.selenium.core.provider.TestDashboardUrlProvider;
Expand All @@ -60,7 +61,7 @@ public class TestFactoryInitializer {

@Inject
@Named("che.infrastructure")
private String infrastructure;
private Infrastructure infrastructure;

/**
* Initialize {@link TestFactory} base upon template.
Expand All @@ -69,9 +70,7 @@ public class TestFactoryInitializer {
*/
public TestFactoryBuilder fromTemplate(String template) throws Exception {
String name = NameGenerator.generate("factory", 6);
InputStream resource =
TestFactory.class.getResourceAsStream(
format("/templates/factory/%s/%s", infrastructure, template));
InputStream resource = TestFactory.class.getResourceAsStream(getTemplateDirectory(template));
if (resource == null) {
throw new IOException(format("Factory template '%s' not found", template));
}
Expand All @@ -85,6 +84,20 @@ public TestFactoryBuilder fromTemplate(String template) throws Exception {
return new TestFactoryBuilder(factoryDto);
}

private String getTemplateDirectory(String template) {
String templateDirectoryName;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can be simplified:

private String getTemplateDirectory(String template) {
    String templateDirectoryName = infrastructure.toString().toLowerCase();
    
    if (infrastructure == k8s){
      templateDirectoryName = k8s.toString().toLowerCase();
    }

    return format("/templates/factory/%s/%s", templateDirectoryName, template);

Copy link
Copy Markdown
Contributor

@dmytro-ndp dmytro-ndp Jul 11, 2018

Choose a reason for hiding this comment

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

Yes, it can, but case-statement is more preferable so as it's more obvious compare to if-statement, and it is more flexible

switch (infrastructure) {
case OSIO:
templateDirectoryName = Infrastructure.OPENSHIFT.toString().toLowerCase();
break;

default:
templateDirectoryName = infrastructure.toString().toLowerCase();
}

return String.format("/templates/factory/%s/%s", templateDirectoryName, template);
}

/** Initialize {@link TestFactory} base upon url. Can't be modified. */
public TestFactory fromUrl(String url) throws Exception {
HttpJsonRequest httpJsonRequest =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@
*/
package org.eclipse.che.selenium.core.utils;

import static java.lang.String.format;
import static java.util.Objects.requireNonNull;

import com.google.common.base.Charsets;
import com.google.common.io.Resources;
import com.google.gson.JsonSyntaxException;
import com.google.inject.Inject;
import java.io.IOException;
import java.net.URL;
import javax.inject.Inject;
import javax.inject.Named;
import org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto;
import org.eclipse.che.dto.server.DtoFactory;
import org.eclipse.che.selenium.core.constant.Infrastructure;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -38,26 +38,39 @@ public class WorkspaceDtoDeserializer {

@Inject
@Named("che.infrastructure")
private String infrastructure;
private Infrastructure infrastructure;

public WorkspaceConfigDto deserializeWorkspaceTemplate(String templateName) {
requireNonNull(templateName);

try {

URL url =
Resources.getResource(
WorkspaceDtoDeserializer.class,
format("/templates/workspace/%s/%s", infrastructure, templateName));
Resources.getResource(WorkspaceDtoDeserializer.class, getTemplateDirectory(templateName));
return DtoFactory.getInstance()
.createDtoFromJson(Resources.toString(url, Charsets.UTF_8), WorkspaceConfigDto.class);
} catch (IOException | IllegalArgumentException | JsonSyntaxException e) {
LOG.error(
"Fail to read workspace template {} for infrastructure {} because {} ",
templateName,
infrastructure,
getTemplateDirectory(templateName),
e.getMessage());
throw new RuntimeException(e.getLocalizedMessage(), e);
}
}

private String getTemplateDirectory(String template) {
String templateDirectoryName;
switch (infrastructure) {
case OSIO:
case K8S:
templateDirectoryName = Infrastructure.OPENSHIFT.toString().toLowerCase();
break;

default:
templateDirectoryName = infrastructure.toString().toLowerCase();
}

return String.format("/templates/workspace/%s/%s", templateDirectoryName, template);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package org.eclipse.che.selenium.core.utils;

import java.lang.reflect.Field;
import org.eclipse.che.selenium.core.constant.Infrastructure;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
Expand All @@ -24,7 +25,7 @@ public void setUp() throws Exception {
deserializer = new WorkspaceDtoDeserializer();
Field f1 = WorkspaceDtoDeserializer.class.getDeclaredField("infrastructure");
f1.setAccessible(true);
f1.set(deserializer, "supershift");
f1.set(deserializer, Infrastructure.OPENSHIFT);
}

@Test
Expand All @@ -36,7 +37,7 @@ public void shouldBeAbleToGetWorkspaceConfigFromResource() {
@Test(
expectedExceptions = RuntimeException.class,
expectedExceptionsMessageRegExp =
"resource /templates/workspace/supershift/some.json relative to org.eclipse.che.selenium.core.utils.WorkspaceDtoDeserializer not found."
"resource /templates/workspace/openshift/some.json relative to org.eclipse.che.selenium.core.utils.WorkspaceDtoDeserializer not found."
)
public void shouldFailIfResourceIsNotFound() {
deserializer.deserializeWorkspaceTemplate("some.json");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.eclipse.che.selenium.core.client.TestWorkspaceServiceClientFactory;
import org.eclipse.che.selenium.core.configuration.SeleniumTestConfiguration;
import org.eclipse.che.selenium.core.configuration.TestConfiguration;
import org.eclipse.che.selenium.core.constant.Infrastructure;
import org.eclipse.che.selenium.core.pageobject.PageObjectsInjector;
import org.eclipse.che.selenium.core.provider.CheTestApiEndpointUrlProvider;
import org.eclipse.che.selenium.core.provider.CheTestDashboardUrlProvider;
Expand Down Expand Up @@ -76,8 +77,6 @@
public class CheSeleniumSuiteModule extends AbstractModule {

public static final String AUXILIARY = "auxiliary";
public static final String DOCKER_INFRASTRUCTURE = "docker";
public static final String OPENSHIFT_INFRASTRUCTURE = "openshift";

private static final String CHE_MULTIUSER_VARIABLE = "CHE_MULTIUSER";
private static final String CHE_INFRASTRUCTURE_VARIABLE = "CHE_INFRASTRUCTURE";
Expand Down Expand Up @@ -132,19 +131,22 @@ public void configure() {
}

private void configureInfrastructureRelatedDependencies() {
String cheInfrastructure = System.getenv(CHE_INFRASTRUCTURE_VARIABLE);
if (cheInfrastructure == null || cheInfrastructure.isEmpty()) {
throw new RuntimeException(
format(
"Che infrastructure should be defined by environment variable '%s'.",
CHE_INFRASTRUCTURE_VARIABLE));
} else if (cheInfrastructure.equalsIgnoreCase(DOCKER_INFRASTRUCTURE)) {
install(new CheSeleniumDockerModule());
} else if (cheInfrastructure.equalsIgnoreCase(OPENSHIFT_INFRASTRUCTURE)) {
install(new CheSeleniumOpenshiftModule());
} else {
throw new RuntimeException(
format("Infrastructure '%s' hasn't been supported by tests.", cheInfrastructure));
final Infrastructure cheInfrastructure =
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please, restore configureInfrastructureRelatedDependencies() method and update its content according to your PR.

Infrastructure.valueOf(System.getenv(CHE_INFRASTRUCTURE_VARIABLE).toUpperCase());
switch (cheInfrastructure) {
case OPENSHIFT:
case K8S:
case OSIO:
install(new CheSeleniumOpenshiftModule());
break;

case DOCKER:
install(new CheSeleniumDockerModule());
break;

default:
throw new RuntimeException(
format("Infrastructure '%s' hasn't been supported by tests.", cheInfrastructure));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public void checkNameField() {
checkValidNames();
}

@Test(groups = TestGroup.OPENSHIFT)
@Test(groups = {TestGroup.OPENSHIFT, TestGroup.K8S})
public void checkOpenshiftStackButtons() {
checkStackButtons(
EXPECTED_OPENSHIFT_QUICK_START_STACKS,
Expand All @@ -327,7 +327,7 @@ public void checkDockerStackButtons() {
EXPECTED_DOCKER_QUICK_START_STACKS_REVERSE_ORDER);
}

@Test(groups = TestGroup.OPENSHIFT)
@Test(groups = {TestGroup.OPENSHIFT, TestGroup.K8S})
public void checkOpenshiftFiltersButton() {
checkFiltersButton(EXPECTED_OPENSHIFT_QUICK_START_STACKS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

@Test(groups = {TestGroup.OPENSHIFT, TestGroup.MULTIUSER})
@Test(groups = {TestGroup.OPENSHIFT, TestGroup.K8S, TestGroup.MULTIUSER})
public class RecreateUpdateStrategyTest {
@Inject CheTestAdminHttpJsonRequestFactory testUserHttpJsonRequestFactory;
@Inject CheTestSystemClient cheTestSystemClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void checkButtonsOnToolbarOnDocker() {

@Test(
priority = 1,
groups = {TestGroup.OPENSHIFT}
groups = {TestGroup.OPENSHIFT, TestGroup.K8S}
)
public void checkButtonsOnToolbarOnOpenshift() {
checkButtonsOnToolbar("Application is not available");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
*
* @author Dmytro Nochevnov
*/
@Test(groups = {TestGroup.OPENSHIFT, TestGroup.MULTIUSER})
@Test(groups = {TestGroup.OPENSHIFT, TestGroup.K8S, TestGroup.MULTIUSER})
public class LoginExistedUserWithOpenShiftOAuthTest {

private static final String WORKSPACE_NAME = NameGenerator.generate("workspace", 4);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
*
* @author Dmytro Nochevnov
*/
@Test(groups = {TestGroup.OPENSHIFT, TestGroup.MULTIUSER})
@Test(groups = {TestGroup.OPENSHIFT, TestGroup.K8S, TestGroup.MULTIUSER})
public class LoginNewUserWithOpenShiftOAuthTest {

private static final String WORKSPACE_NAME = NameGenerator.generate("workspace", 4);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"v":"4.0",
"workspace":{
"projects":[
{
"name":"Spring",
"attributes":{
"languageVersion":[
"1.6"
],
"language":[
"java"
]
},
"type":"maven",
"source":{
"location":"https://github.com/codenvy-templates/web-spring-java-simple.git",
"type":"git",
"parameters":{
"keepVcs":"false",
"branch":"3.1.0"
}
},
"modules":[

],
"path":"/Spring",
"mixins":[
"git"
],
"problems":[

]
}
],
"defaultEnv":"wss",
"name":"wss",
"environments":{
"wss":{
"machines":{
"dev-machine":{
"installers":[
"org.eclipse.che.terminal",
"org.eclipse.che.ws-agent"
],
"servers":{

},
"attributes":{
"memoryLimitBytes":"2147483648"
}
}
},
"recipe":{
"content":"eclipse/ubuntu_jdk8",
"type":"dockerimage"
}
}
}
}
}