001/* 002 * (C) Copyright 2006-2011 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 * bstefanescu 018 */ 019package org.nuxeo.runtime.test.runner; 020 021import org.junit.runners.model.FrameworkMethod; 022 023import com.google.inject.Binder; 024 025/** 026 * These are the states the runner goes through when using runtime feature: 027 * 028 * <pre> 029 * CREATE FRAMEWORK 030 * new feature() --> constructor 031 * COLLECT DEFINED DEPLOYMENTS 032 * feature.initialize() --> can be used to configure nuxeo home or register JNDI objects 033 * START FRAMEWORK 034 * feature.start() 035 * feature.beforeRun() 036 * feature.configure() --> can be used to add guice bindings and to dynamically deploy components using the harness 037 * for each test method: 038 * feature.testCreated() 039 * feature.beforeSetup 040 * feature.beforeMethodRun() --> test method interceptor 041 * testMethod() 042 * feature.afterMethodRun() --> test method interceptor 043 * feature.afterTeardown() 044 * feature.afterRun() --> cleanup that require framework to be started 045 * STOP FRAMEWORK 046 * feature.stop() --> destructor 047 * </pre> 048 * 049 * @author <a href="mailto:[email protected]">Bogdan Stefanescu</a> 050 */ 051public interface RunnerFeature { 052 053 /** 054 * Called when preparing to run the test class. Framework is not started at this point. Here is time for the feature 055 * to configure the runner from annotations on the test class. 056 */ 057 default void initialize(FeaturesRunner runner) throws Exception { 058 } 059 060 /** 061 * Configures Guice bindings if any is required by the feature. This is called after the framework is started and 062 * before Guice module is built. The tests are launched after guice module is built. 063 */ 064 default void configure(FeaturesRunner runner, Binder binder) { 065 } 066 067 /** 068 * Before running tests. At this point Guice modules are registered and injector created. 069 */ 070 default void beforeRun(FeaturesRunner runner) throws Exception { 071 } 072 073 /** 074 * After tests were run. 075 */ 076 default void afterRun(FeaturesRunner runner) throws Exception { 077 } 078 079 /** 080 * Features are initialized. Runner is ready to create the injector. 081 */ 082 default void start(FeaturesRunner runner) throws Exception { 083 } 084 085 /** 086 * Notification that a test instance was created. Can be used by features to make custom injection or other 087 * preparation of the test instance. 088 */ 089 default void testCreated(Object test) throws Exception { 090 } 091 092 /** 093 * Before exiting the test. 094 */ 095 default void stop(FeaturesRunner runner) throws Exception { 096 } 097 098 /** 099 * Before entering in the @Before methods 100 */ 101 default void beforeSetup(FeaturesRunner runner) throws Exception { 102 } 103 104 /** 105 * After the call of the @After methods 106 */ 107 default void afterTeardown(FeaturesRunner runner) throws Exception { 108 } 109 110 /** 111 * Before a test method is invoked. 112 */ 113 default void beforeMethodRun(FeaturesRunner runner, FrameworkMethod method, Object test) throws Exception { 114 } 115 116 /** 117 * After a test method was ran. 118 */ 119 default void afterMethodRun(FeaturesRunner runner, FrameworkMethod method, Object test) throws Exception { 120 } 121 122}