001/* 002 * (C) Copyright 2014 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Stephane Lacoin 018 */ 019package org.nuxeo.runtime.test.runner; 020 021import org.apache.log4j.MDC; 022import org.junit.runners.model.FrameworkMethod; 023 024import com.google.inject.Binder; 025 026public class MDCFeature implements RunnerFeature { 027 028 protected static final String F_TEST = "fTest"; 029 030 protected static final String F_SUITE = "fSuite"; 031 032 protected static final String F_STATE = "fState"; 033 034 @Override 035 public void initialize(FeaturesRunner runner) throws Exception { 036 MDC.put(F_STATE, "initialize"); 037 } 038 039 @Override 040 public void configure(FeaturesRunner runner, Binder binder) { 041 MDC.put(F_STATE, "configure"); 042 } 043 044 @Override 045 public void beforeRun(FeaturesRunner runner) throws Exception { 046 MDC.put(F_STATE, "beforeRun"); 047 } 048 049 @Override 050 public void afterRun(FeaturesRunner runner) throws Exception { 051 MDC.put(F_STATE, "afterRun"); 052 } 053 054 @Override 055 public void start(FeaturesRunner runner) throws Exception { 056 MDC.put(F_STATE, "start"); 057 } 058 059 @Override 060 public void testCreated(Object test) throws Exception { 061 MDC.put(F_STATE, "testCreated"); 062 MDC.put(F_SUITE, test.getClass()); 063 } 064 065 @Override 066 public void stop(FeaturesRunner runner) throws Exception { 067 MDC.remove(F_STATE); 068 MDC.remove(F_SUITE); 069 MDC.remove(F_TEST); 070 } 071 072 @Override 073 public void beforeSetup(FeaturesRunner runner) throws Exception { 074 MDC.put(F_STATE, "beforeSetup"); 075 } 076 077 @Override 078 public void afterTeardown(FeaturesRunner runner) throws Exception { 079 MDC.put(F_STATE, "afterTeardown"); 080 } 081 082 @Override 083 public void beforeMethodRun(FeaturesRunner runner, FrameworkMethod method, Object test) throws Exception { 084 MDC.put(F_STATE, "beforeMethodRun"); 085 MDC.put(F_TEST, method.getMethod().getName()); 086 } 087 088 @Override 089 public void afterMethodRun(FeaturesRunner runner, FrameworkMethod method, Object test) throws Exception { 090 MDC.put(F_STATE, "afterMethodRun"); 091 MDC.remove(F_TEST); 092 } 093 094}