Skip to content

Commit

Permalink
add Environment class to record more runtime env info
Browse files Browse the repository at this point in the history
  • Loading branch information
tascape committed Mar 27, 2016
1 parent 4c4eea9 commit 5687b2c
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 21 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.tascape.qa</groupId>
<artifactId>testharness</artifactId>
<version>1.1.2</version>
<version>1.1.3</version>
<packaging>jar</packaging>
<name>testharness</name>

Expand Down
5 changes: 2 additions & 3 deletions src/main/java/com/tascape/qa/th/TestRunnerJUnit4.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@
import com.tascape.qa.th.db.DbHandler;
import com.tascape.qa.th.db.TestCase;
import com.tascape.qa.th.db.TestResult;
import com.tascape.qa.th.driver.EntityDriver;
import com.tascape.qa.th.suite.AbstractSuite;
import com.tascape.qa.th.suite.Environment;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Map;
import java.util.concurrent.Callable;
import org.junit.runner.JUnitCore;
import org.junit.runner.Request;
Expand Down Expand Up @@ -92,7 +91,7 @@ private void injectTestEnvironment() throws Exception {
if (suiteClass == null || suiteClass.isEmpty()) {
return;
}
Map<String, ? extends EntityDriver> env = AbstractSuite.getEnvionment(suiteClass);
Environment env = AbstractSuite.getEnvionment(suiteClass);
if (env == null) {
AbstractSuite abstractSuite = AbstractSuite.class.cast(Class.forName(suiteClass).newInstance());
abstractSuite.setUp();
Expand Down
30 changes: 15 additions & 15 deletions src/main/java/com/tascape/qa/th/suite/AbstractSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,28 @@
public abstract class AbstractSuite {
private static final Logger LOG = LoggerFactory.getLogger(AbstractSuite.class);

private static final ThreadLocal<Map<String, Map<String, EntityDriver>>> ENVIRONMENTS
= new ThreadLocal<Map<String, Map<String, EntityDriver>>>() {
@Override
protected Map<String, Map<String, EntityDriver>> initialValue() {
return new HashMap<>();
}
};
private static final ThreadLocal<Map<String, Environment>> ENVIRONMENTS
= new ThreadLocal<Map<String, Environment>>() {
@Override
protected Map<String, Environment> initialValue() {
return new HashMap<>();
}
};

public static void putEnvionment(String suiteClass, Map<String, EntityDriver> drivers) {
ENVIRONMENTS.get().put(suiteClass, drivers);
public static void putEnvionment(String suiteClass, Environment env) {
ENVIRONMENTS.get().put(suiteClass, env);
}

public static Map<String, EntityDriver> getEnvionment(String suiteClass) {
Map<String, EntityDriver> drivers = ENVIRONMENTS.get().get(suiteClass);
return drivers;
public static Environment getEnvionment(String suiteClass) {
Environment env = ENVIRONMENTS.get().get(suiteClass);
return env;
}

private static final List<AbstractSuite> SUITES = new ArrayList<>();

private final List<Class<? extends AbstractTest>> testClasses = new ArrayList<>();

private final Map<String, EntityDriver> suiteEnvironment = new HashMap<>();
private final Environment suiteEnvironment = new Environment();

protected final SystemConfiguration SYSCONFIG = SystemConfiguration.getInstance();

Expand All @@ -73,13 +73,13 @@ public static List<AbstractSuite> getSuites() {
}

protected ExecutionResult executionResult;

public int getNumberOfEnvs() {
return 0;
}

public void setUp() throws Exception {
Map<String, EntityDriver> env = AbstractSuite.getEnvionment(this.getClass().getName());
Environment env = AbstractSuite.getEnvionment(this.getClass().getName());
if (env == null || env.isEmpty()) {
this.setUpEnvironment();
AbstractSuite.putEnvionment(this.getClass().getName(), this.suiteEnvironment);
Expand Down
36 changes: 36 additions & 0 deletions src/main/java/com/tascape/qa/th/suite/Environment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2016 tascape.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.tascape.qa.th.suite;

import com.tascape.qa.th.driver.EntityDriver;
import java.util.HashMap;

/**
*
* @author linsong wang
*/
public class Environment extends HashMap<String, EntityDriver> {

private String name = "";

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/tascape/qa/th/test/AbstractTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
import com.tascape.qa.th.AbstractTestResource;
import com.tascape.qa.th.db.TestResultMetric;
import com.tascape.qa.th.driver.TestDriver;
import com.tascape.qa.th.suite.Environment;
import java.nio.file.Path;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -114,7 +114,7 @@ protected <D extends EntityDriver> D getEntityDriver(TestDriver testDriver) {
return null;
}

Map<String, EntityDriver> env = AbstractSuite.getEnvionment(suiteClass);
Environment env = AbstractSuite.getEnvionment(suiteClass);
EntityDriver driver = env.get(key);
if (driver == null) {
LOG.error("Cannot find driver of name={} and type={}, please check suite test environemnt",
Expand Down

0 comments on commit 5687b2c

Please sign in to comment.