Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id BBEFA200AE3 for ; Thu, 5 May 2016 00:57:10 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id BAAAC160A02; Wed, 4 May 2016 22:57:10 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id E6E4B1609FF for ; Thu, 5 May 2016 00:57:09 +0200 (CEST) Received: (qmail 59882 invoked by uid 500); 4 May 2016 22:57:09 -0000 Mailing-List: contact commits-help@geode.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@geode.incubator.apache.org Delivered-To: mailing list commits@geode.incubator.apache.org Received: (qmail 59865 invoked by uid 99); 4 May 2016 22:57:09 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 04 May 2016 22:57:09 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id C32961A08C0 for ; Wed, 4 May 2016 22:57:08 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -3.221 X-Spam-Level: X-Spam-Status: No, score=-3.221 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-0.001] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id Ih5uFH5MoTXd for ; Wed, 4 May 2016 22:57:06 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with SMTP id 25B4B5FCE6 for ; Wed, 4 May 2016 22:57:03 +0000 (UTC) Received: (qmail 57983 invoked by uid 99); 4 May 2016 22:57:02 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 04 May 2016 22:57:02 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 77905DFFAB; Wed, 4 May 2016 22:57:02 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: klund@apache.org To: commits@geode.incubator.apache.org Date: Wed, 04 May 2016 22:57:41 -0000 Message-Id: <722fddc80993408ab65a3afdcad2f703@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [41/63] [abbrv] incubator-geode git commit: GEODE-1323: Extend PerTestClassLoaderRunner to work with Rules archived-at: Wed, 04 May 2016 22:57:10 -0000 GEODE-1323: Extend PerTestClassLoaderRunner to work with Rules Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/a20efb92 Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/a20efb92 Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/a20efb92 Branch: refs/heads/feature/GEODE-1276 Commit: a20efb927f29512677d4191094aa3d8445549225 Parents: bcae906 Author: Jens Deppe Authored: Fri Apr 29 09:26:53 2016 -0700 Committer: Jens Deppe Committed: Fri Apr 29 10:41:49 2016 -0700 ---------------------------------------------------------------------- .../session/junit/PerTestClassLoaderRunner.java | 136 ++++--------------- 1 file changed, 28 insertions(+), 108 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/a20efb92/extensions/geode-modules-session/src/test/java/com/gemstone/gemfire/modules/session/junit/PerTestClassLoaderRunner.java ---------------------------------------------------------------------- diff --git a/extensions/geode-modules-session/src/test/java/com/gemstone/gemfire/modules/session/junit/PerTestClassLoaderRunner.java b/extensions/geode-modules-session/src/test/java/com/gemstone/gemfire/modules/session/junit/PerTestClassLoaderRunner.java index 3e5c998..dda5307 100644 --- a/extensions/geode-modules-session/src/test/java/com/gemstone/gemfire/modules/session/junit/PerTestClassLoaderRunner.java +++ b/extensions/geode-modules-session/src/test/java/com/gemstone/gemfire/modules/session/junit/PerTestClassLoaderRunner.java @@ -36,9 +36,12 @@ package com.gemstone.gemfire.modules.session.junit; import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.internal.runners.statements.Fail; import org.junit.internal.runners.statements.RunAfters; import org.junit.internal.runners.statements.RunBefores; +import org.junit.rules.MethodRule; +import org.junit.rules.TestRule; import org.junit.runners.model.FrameworkMethod; import org.junit.runners.model.InitializationError; import org.junit.runners.model.Statement; @@ -65,6 +68,9 @@ public class PerTestClassLoaderRunner extends NamedRunner { private TestClass testClassFromClassLoader; private Object beforeFromClassLoader; private Object afterFromClassLoader; + private Object ruleFromClassLoader; + private Object testRuleFromClassLoader; + private Object methodRuleFromClassLoader; /** * Instantiates a new test per class loader runner. @@ -117,6 +123,9 @@ public class PerTestClassLoaderRunner extends NamedRunner { // See withAfters and withBefores for the reason. beforeFromClassLoader = classLoader.loadClass(Before.class.getName()); afterFromClassLoader = classLoader.loadClass(After.class.getName()); + ruleFromClassLoader = classLoader.loadClass(Rule.class.getName()); + testRuleFromClassLoader = classLoader.loadClass(TestRule.class.getName()); + methodRuleFromClassLoader = classLoader.loadClass(MethodRule.class.getName()); } @Override @@ -170,114 +179,25 @@ public class PerTestClassLoaderRunner extends NamedRunner { return new RunBefores(statement, befores, target); } -// /** -// * Gets the class path. This value is cached in a static variable for performance reasons. -// * -// * @return the class path -// */ -// private static String getClassPath() -// { -// if (classPathDetermined) -// { -// return classPath; -// } -// -// classPathDetermined = true; -// // running from maven, we have the classpath in this property. -// classPath = System.getProperty("surefire.test.class.path"); -// if (classPath != null) -// { -// return classPath; -// } -// -// // For a multi module project, running it from the top we have to find it using another way. -// // We also need to set useSystemClassLoader=true in the POM so that we gets a jar with the classpath in it. -// String booterClassPath = System.getProperty("java.class.path"); -// Vector pathItems = null; -// if (booterClassPath != null) -// { -// pathItems = scanPath(booterClassPath); -// } -// // Do we have just 1 entry as classpath which is a jar? -// if (pathItems != null && pathItems.size() == 1 -// && isJar((String) pathItems.get(0))) -// { -// classPath = loadJarManifestClassPath((String) pathItems.get(0), -// "META-INF/MANIFEST.MF"); -// } -// return classPath; -// -// } + @Override + protected List rules(Object target) { + List result = testClassFromClassLoader.getAnnotatedMethodValues(target, + (Class) ruleFromClassLoader, (Class) methodRuleFromClassLoader); + + result.addAll(testClassFromClassLoader.getAnnotatedFieldValues(target, + (Class) ruleFromClassLoader, (Class) methodRuleFromClassLoader)); -// /** -// * Load jar manifest class path. -// * -// * @param path the path -// * @param fileName the file name -// * -// * @return the string -// */ -// private static String loadJarManifestClassPath(String path, String fileName) -// { -// File archive = new File(path); -// if (!archive.exists()) { -// return null; -// } -// ZipFile zipFile = null; -// -// try { -// zipFile = new ZipFile(archive); -// } catch (IOException io) { -// return null; -// } -// -// ZipEntry entry = zipFile.getEntry(fileName); -// if (entry == null) { -// return null; -// } try { -// Manifest mf = new Manifest(); -// mf.read(zipFile.getInputStream(entry)); -// -// return mf.getMainAttributes().getValue(Attributes.Name.CLASS_PATH) -// .replaceAll(" ", System.getProperty("path.separator")) -// .replaceAll("file:/", ""); -// } catch (MalformedURLException e) { -// LOGGER.throwing("ClassLoaderTestSuite", "loadJarManifestClassPath", e); -// } catch (IOException e) { -// LOGGER.throwing("ClassLoaderTestSuite", "loadJarManifestClassPath", e); -// } -// return null; -// } -// -// /** -// * Checks if is jar. -// * -// * @param pathEntry the path entry -// * -// * @return true, if is jar -// */ -// private static boolean isJar(String pathEntry) -// { -// return pathEntry.endsWith(".jar") || pathEntry.endsWith(".zip"); -// } -// -// /** -// * Scan path for all directories. -// * -// * @param classPath the class path -// * -// * @return the vector< string> -// */ -// private static Vector scanPath(String classPath) -// { -// String separator = System.getProperty("path.separator"); -// Vector pathItems = new Vector(10); -// StringTokenizer st = new StringTokenizer(classPath, separator); -// while (st.hasMoreTokens()) -// { -// pathItems.addElement(st.nextToken()); -// } -// return pathItems; -// } + return result; + } + @Override + protected List getTestRules(Object target) { + List result = testClassFromClassLoader.getAnnotatedMethodValues(target, + (Class) ruleFromClassLoader, (Class) testRuleFromClassLoader); + + result.addAll(testClassFromClassLoader.getAnnotatedFieldValues(target, + (Class) ruleFromClassLoader, (Class) testRuleFromClassLoader)); + + return result; + } }