@Test(expected = Exception.class) public void checkThatExceptionsAreNotSilentlySwallowed() throws Exception { SpringJUnit4ClassRunner runner = new SpringJUnit4ClassRunner(getClass()) { @Override protected TestContextManager createTestContextManager(Class<?> clazz) { return new TestContextManager(clazz) { @Override public void prepareTestInstance(Object testInstance) { throw new RuntimeException( "This RuntimeException should be caught and wrapped in an Exception."); } }; } }; runner.createTest(); }
/** * Creates a new {@link TestContextManager} for the supplied test class. * <p> * Can be overridden by subclasses. * * @param clazz * the test class to be managed */ @Override protected TestContextManager createTestContextManager(final Class<?> clazz) { return new TestContextManager(clazz) { @Override public void beforeTestClass() throws Exception { super.beforeTestClass(); } @Override public void afterTestClass() throws Exception { // If we aren't caching the Spring context them mark it dirty so // it is destroyed. if (!cacheSpringContext) { final TestContext testContext = getTestContext(); testContext.markApplicationContextDirty(HierarchyMode.EXHAUSTIVE); testContext.setAttribute(DependencyInjectionTestExecutionListener.REINJECT_DEPENDENCIES_ATTRIBUTE, Boolean.TRUE); } super.afterTestClass(); } }; }
@Test(expected = Exception.class) public void checkThatExceptionsAreNotSilentlySwallowed() throws Exception { SpringJUnit4ClassRunner runner = new SpringJUnit4ClassRunner(getClass()) { @Override protected TestContextManager createTestContextManager(Class<?> clazz) { return new TestContextManager(clazz) { @Override public void prepareTestInstance(Object testInstance) { throw new RuntimeException("This RuntimeException should be caught and wrapped in an Exception."); } }; } }; runner.createTest(); }
@Before public void setUp() throws Exception { testContextManager = new TestContextManager(getClass()); testContextManager.prepareTestInstance(this); judgmentsServer.deleteByQuery("*:*"); judgmentsServer.commit(); indexJudgments(); }
@Before public void setUp() throws Exception { this.testContextManager = new TestContextManager( getClass() ); this.testContextManager.prepareTestInstance( this ); KettleEnvironment.init(); PentahoSessionHolder.setStrategyName( PentahoSessionHolder.MODE_GLOBAL ); mockVersionManager(); removePentahoRootFolder(); startMicroPlatform(); createSystemUser(); createTester(); createPurRepository(); loginAsTester(); }
/** * Wrap the supplied {@link Statement} with a {@code RunBeforeTestMethodCallbacks} statement. * @see RunBeforeTestMethodCallbacks */ private Statement withBeforeTestMethodCallbacks(Statement statement, FrameworkMethod frameworkMethod, Object testInstance, TestContextManager testContextManager) { return new RunBeforeTestMethodCallbacks( statement, testInstance, frameworkMethod.getMethod(), testContextManager); }
/** * Wrap the supplied {@link Statement} with a {@code RunAfterTestMethodCallbacks} statement. * @see RunAfterTestMethodCallbacks */ private Statement withAfterTestMethodCallbacks(Statement statement, FrameworkMethod frameworkMethod, Object testInstance, TestContextManager testContextManager) { return new RunAfterTestMethodCallbacks( statement, testInstance, frameworkMethod.getMethod(), testContextManager); }
@Override protected TestContextManager createTestContextManager(Class<?> clazz) { // System.err.println("IntegrationRunner createTestContextManager clazz:" + clazz.getName()); try { TestContextManager manager = super.createTestContextManager(clazz); // System.err.println("IntegrationRunner createTestContextManager manager:" + manager); return manager; } catch (RuntimeException e) { e.printStackTrace(); throw e; } }
/** * Get the {@link TestContextManager} associated with the supplied {@code ExtensionContext}. * @return the {@code TestContextManager} (never {@code null}) */ private static TestContextManager getTestContextManager(ExtensionContext context) { Assert.notNull(context, "ExtensionContext must not be null"); Class<?> testClass = context.getRequiredTestClass(); Store store = getStore(context); return store.getOrComputeIfAbsent(testClass, TestContextManager::new, TestContextManager.class); }
@Before public void setUp() throws Exception { testContextManager = new TestContextManager(getClass()); testContextManager.prepareTestInstance(this); solrJudgmentsServer.deleteByQuery("*:*"); solrJudgmentsServer.commit(); indexJudgments(); }
@Before public void setUp() throws Exception { testContextManager = new TestContextManager(getClass()); testContextManager.prepareTestInstance(this); solrJudgmentsServer.deleteByQuery("*:*"); solrJudgmentsServer.commit(); }
/** * Called reflectively by {@link #createTest()} to set up the Spring test context manager in the child * classloader. * * @param testInstance - an instance of the class under test in the current ClassLoader * @return a new TestContextManager */ public static TestContextManager createTestContextManager(Object testInstance) { TestContextManager testContextManager = new TestContextManager(testInstance.getClass()); try { testContextManager.prepareTestInstance(testInstance); } catch (Exception e) { throw new RuntimeException("Failed setting up Spring test instance", e); } return testContextManager; }
/** * Called reflectively by {@link #ensureInitialized()} to set up the Spring test context manager in the remote * classloader. * * @param testInstance - an instance of the class under test in the current ClassLoader * @return a new TestContextManager */ private static TestContextManager createTestContextManager(Object testInstance) { TestContextManager testContextManager = new TestContextManager(testInstance.getClass()); try { testContextManager.prepareTestInstance(testInstance); } catch (Exception e) { throw new ClassLoaderException("Failed setting up Spring test instance", e); } return testContextManager; }
private final void clearTestContextCache(TestContextManager testContextManager) throws Exception { // well this is fun... Field contextCacheField = TestContextManager.class.getDeclaredField("contextCache"); contextCacheField.setAccessible(true); Object cache = contextCacheField.get(null); Method method = cache.getClass().getDeclaredMethod("clear"); method.setAccessible(true); method.invoke(cache); }
private static TestContextManager getTestContextManager(ExtensionContext context) { Assert.notNull(context, "ExtensionContext must not be null"); Class<?> testClass = context.getTestClass().get(); ExtensionContext.Store store = context.getStore(NAMESPACE); return store.getOrComputeIfAbsent(testClass, TestContextManager::new, TestContextManager.class); }
/** * Get the {@link TestContextManager} associated with this runner. */ protected final TestContextManager getTestContextManager() { return this.testContextManager; }
/** * Apply <em>class-level</em> features of the <em>Spring TestContext * Framework</em> to the supplied {@code base} statement. * <p>Specifically, this method retrieves the {@link TestContextManager} * used by this rule and its associated {@link SpringMethodRule} and * invokes the {@link TestContextManager#beforeTestClass() beforeTestClass()} * and {@link TestContextManager#afterTestClass() afterTestClass()} methods * on the {@code TestContextManager}. * <p>In addition, this method checks whether the test is enabled in * the current execution environment. This prevents classes with a * non-matching {@code @IfProfileValue} annotation from running altogether, * even skipping the execution of {@code beforeTestClass()} methods * in {@code TestExecutionListeners}. * @param base the base {@code Statement} that this rule should be applied to * @param description a {@code Description} of the current test execution * @return a statement that wraps the supplied {@code base} with class-level * features of the Spring TestContext Framework * @see #getTestContextManager * @see #withBeforeTestClassCallbacks * @see #withAfterTestClassCallbacks * @see #withProfileValueCheck * @see #withTestContextManagerCacheEviction */ @Override public Statement apply(Statement base, Description description) { Class<?> testClass = description.getTestClass(); if (logger.isDebugEnabled()) { logger.debug("Applying SpringClassRule to test class [" + testClass.getName() + "]"); } validateSpringMethodRuleConfiguration(testClass); TestContextManager testContextManager = getTestContextManager(testClass); Statement statement = base; statement = withBeforeTestClassCallbacks(statement, testContextManager); statement = withAfterTestClassCallbacks(statement, testContextManager); statement = withProfileValueCheck(statement, testClass); statement = withTestContextManagerCacheEviction(statement, testClass); return statement; }
/** * Apply <em>instance-level</em> and <em>method-level</em> features of * the <em>Spring TestContext Framework</em> to the supplied {@code base} * statement. * <p>Specifically, this method invokes the * {@link TestContextManager#prepareTestInstance prepareTestInstance()}, * {@link TestContextManager#beforeTestMethod beforeTestMethod()}, and * {@link TestContextManager#afterTestMethod afterTestMethod()} methods * on the {@code TestContextManager}, potentially with Spring timeouts * and repetitions. * <p>In addition, this method checks whether the test is enabled in * the current execution environment. This prevents methods with a * non-matching {@code @IfProfileValue} annotation from running altogether, * even skipping the execution of {@code prepareTestInstance()} methods * in {@code TestExecutionListeners}. * @param base the base {@code Statement} that this rule should be applied to * @param frameworkMethod the method which is about to be invoked on the test instance * @param testInstance the current test instance * @return a statement that wraps the supplied {@code base} with instance-level * and method-level features of the Spring TestContext Framework * @see #withBeforeTestMethodCallbacks * @see #withAfterTestMethodCallbacks * @see #withPotentialRepeat * @see #withPotentialTimeout * @see #withTestInstancePreparation * @see #withProfileValueCheck */ @Override public Statement apply(Statement base, FrameworkMethod frameworkMethod, Object testInstance) { if (logger.isDebugEnabled()) { logger.debug("Applying SpringMethodRule to test method [" + frameworkMethod.getMethod() + "]"); } Class<?> testClass = testInstance.getClass(); validateSpringClassRuleConfiguration(testClass); TestContextManager testContextManager = SpringClassRule.getTestContextManager(testClass); Statement statement = base; statement = withBeforeTestMethodCallbacks(statement, frameworkMethod, testInstance, testContextManager); statement = withAfterTestMethodCallbacks(statement, frameworkMethod, testInstance, testContextManager); statement = withTestInstancePreparation(statement, testInstance, testContextManager); statement = withPotentialRepeat(statement, frameworkMethod, testInstance); statement = withPotentialTimeout(statement, frameworkMethod, testInstance); statement = withProfileValueCheck(statement, frameworkMethod, testInstance); return statement; }
/** * Wrap the supplied {@link Statement} with a {@code RunPrepareTestInstanceCallbacks} statement. * @see RunPrepareTestInstanceCallbacks */ private Statement withTestInstancePreparation(Statement statement, Object testInstance, TestContextManager testContextManager) { return new RunPrepareTestInstanceCallbacks(statement, testInstance, testContextManager); }
public SpringFlowableTestCase() { this.testContextManager = new TestContextManager(getClass()); }
public SpringFlowableIdmTestCase() { this.testContextManager = new TestContextManager(getClass()); }
public SpringActivitiTestCase() { super(); this.testContextManager = new TestContextManager(getClass()); }
@Override protected TestContextManager createTestContextManager(Class<?> testClass) { return new SynchronizedTestContextManager(testClass); }
@Before public void setUpSpringContext() throws Exception { TestContextManager testContextManager = new TestContextManager(getClass()); testContextManager.prepareTestInstance(this); }
/** * Constructs a new AbstractJUnit38SpringContextTests instance; initializes * the internal {@link TestContextManager} for the current test; and * retrieves the configured (or default) {@link ProfileValueSource}. */ public AbstractJUnit38SpringContextTests() { super(); this.testContextManager = new TestContextManager(getClass()); this.profileValueSource = ProfileValueUtils.retrieveProfileValueSource(getClass()); }
public ParameterizedDependencyInjectionTests(final String employeeBeanName, final String employeeName) throws Exception { this.testContextManager = new TestContextManager(getClass()); this.employeeBeanName = employeeBeanName; this.employeeName = employeeName; }
@Override protected TestContextManager createTestContextManager(Class<?> clazz) { System.setProperty("APP_ENV", "default"); return super.createTestContextManager(clazz); }
@Before public void setUp() throws Exception { this.testContextManager = new TestContextManager( getClass() ); this.testContextManager.prepareTestInstance( this ); IRepositoryVersionManager mockRepositoryVersionManager = mock( IRepositoryVersionManager.class ); when( mockRepositoryVersionManager.isVersioningEnabled( anyString() ) ).thenReturn( true ); when( mockRepositoryVersionManager.isVersionCommentEnabled( anyString() ) ).thenReturn( false ); JcrRepositoryFileUtils.setRepositoryVersionManager( mockRepositoryVersionManager ); loginAsRepositoryAdmin(); SimpleJcrTestUtils.deleteItem( testJcrTemplate, ServerRepositoryPaths.getPentahoRootFolderPath() ); mp = new MicroPlatform(); // used by DefaultPentahoJackrabbitAccessControlHelper mp.defineInstance( "tenantedUserNameUtils", userNameUtils ); mp.defineInstance( "tenantedRoleNameUtils", roleNameUtils ); mp.defineInstance( IAuthorizationPolicy.class, authorizationPolicy ); mp.defineInstance( ITenantManager.class, tenantManager ); mp.defineInstance( "roleAuthorizationPolicyRoleBindingDaoTarget", roleBindingDaoTarget ); mp.defineInstance( "repositoryAdminUsername", repositoryAdminUsername ); mp.defineInstance( "RepositoryFileProxyFactory", new RepositoryFileProxyFactory( testJcrTemplate, repositoryFileDao ) ); mp.defineInstance( "useMultiByteEncoding", new Boolean( false ) ); // Start the micro-platform mp.start(); loginAsRepositoryAdmin(); setAclManagement(); systemTenant = tenantManager.createTenant( null, ServerRepositoryPaths.getPentahoRootFolderName(), singleTenantAdminRoleName, tenantAuthenticatedRoleName, "Anonymous" ); userRoleDao.createUser( systemTenant, sysAdminUserName, "password", "", new String[] { singleTenantAdminRoleName } ); logout(); super.setUp(); KettleEnvironment.init(); // programmatically register plugins, annotation based plugins do not get loaded unless // they are in kettle's plugins folder. JobEntryPluginType.getInstance().registerCustom( JobEntryAttributeTesterJobEntry.class, "test", "JobEntryAttributeTester", "JobEntryAttributeTester", "JobEntryAttributeTester", "" ); StepPluginType.getInstance().registerCustom( TransStepAttributeTesterTransStep.class, "test", "StepAttributeTester", "StepAttributeTester", "StepAttributeTester", "" ); repositoryMeta = new PurRepositoryMeta(); repositoryMeta.setName( "JackRabbit" ); repositoryMeta.setDescription( "JackRabbit test repository" ); userInfo = new UserInfo( EXP_LOGIN, "password", EXP_USERNAME, "Apache Tomcat user", true ); repository = new PurRepository(); repository.init( repositoryMeta ); login( sysAdminUserName, systemTenant, new String[] { singleTenantAdminRoleName, tenantAuthenticatedRoleName } ); ITenant tenantAcme = tenantManager.createTenant( systemTenant, EXP_TENANT, singleTenantAdminRoleName, tenantAuthenticatedRoleName, "Anonymous" ); userRoleDao.createUser( tenantAcme, EXP_LOGIN, "password", "", new String[] { singleTenantAdminRoleName } ); logout(); setUpUser(); PurRepository purRep = (PurRepository) repository; purRep.setPurRepositoryConnector( new PurRepositoryConnector( purRep, (PurRepositoryMeta) repositoryMeta, purRep .getRootRef() ) ); ( (PurRepository) repository ).setTest( repo ); repository.connect( EXP_LOGIN, "password" ); login( EXP_LOGIN, tenantAcme, new String[] { singleTenantAdminRoleName, tenantAuthenticatedRoleName } ); System.out.println( "PUR NAME!!!: " + repo.getClass().getCanonicalName() ); RepositoryFile repositoryFile = repo.getFile( ClientRepositoryPaths.getPublicFolderPath() ); Serializable repositoryFileId = repositoryFile.getId(); List<RepositoryFile> files = repo.getChildren( repositoryFileId ); StringBuilder buf = new StringBuilder(); for ( RepositoryFile file : files ) { buf.append( "\n" ).append( file ); } assertTrue( "files not deleted: " + buf, files.isEmpty() ); }
@Before public void setUp() throws Exception { this.testContextManager = new TestContextManager( getClass() ); this.testContextManager.prepareTestInstance( this ); loginAsRepositoryAdmin(); SimpleJcrTestUtils.deleteItem( testJcrTemplate, ServerRepositoryPaths.getPentahoRootFolderPath() ); mp = new MicroPlatform(); // used by DefaultPentahoJackrabbitAccessControlHelper mp.defineInstance( "tenantedUserNameUtils", userNameUtils ); mp.defineInstance( "tenantedRoleNameUtils", roleNameUtils ); mp.defineInstance( IAuthorizationPolicy.class, authorizationPolicy ); mp.defineInstance( ITenantManager.class, tenantManager ); mp.defineInstance( "roleAuthorizationPolicyRoleBindingDaoTarget", roleBindingDaoTarget ); mp.defineInstance( "repositoryAdminUsername", repositoryAdminUsername ); mp.defineInstance( "RepositoryFileProxyFactory", new RepositoryFileProxyFactory( testJcrTemplate, repositoryFileDao ) ); mp.defineInstance( "useMultiByteEncoding", new Boolean( false ) ); mp.defineInstance( IAclService.class, new Boolean( false ) ); // Start the micro-platform mp.start(); loginAsRepositoryAdmin(); setAclManagement(); systemTenant = tenantManager.createTenant( null, ServerRepositoryPaths.getPentahoRootFolderName(), singleTenantAdminRoleName, tenantAuthenticatedRoleName, "Anonymous" ); userRoleDao.createUser( systemTenant, sysAdminUserName, "password", "", new String[] { singleTenantAdminRoleName } ); logout(); super.setUp(); KettleEnvironment.init(); // programmatically register plugins, annotation based plugins do not get loaded unless // they are in kettle's plugins folder. JobEntryPluginType.getInstance().registerCustom( JobEntryAttributeTesterJobEntry.class, "test", "JobEntryAttributeTester", "JobEntryAttributeTester", "JobEntryAttributeTester", "" ); StepPluginType.getInstance().registerCustom( TransStepAttributeTesterTransStep.class, "test", "StepAttributeTester", "StepAttributeTester", "StepAttributeTester", "" ); repositoryMeta = new PurRepositoryMeta(); repositoryMeta.setName( "JackRabbit" ); repositoryMeta.setDescription( "JackRabbit test repository" ); userInfo = new UserInfo( EXP_LOGIN, "password", EXP_USERNAME, "Apache Tomcat user", true ); repository = new PurRepository(); repository.init( repositoryMeta ); login( sysAdminUserName, systemTenant, new String[] { singleTenantAdminRoleName, tenantAuthenticatedRoleName } ); ITenant tenantAcme = tenantManager.createTenant( systemTenant, EXP_TENANT, singleTenantAdminRoleName, tenantAuthenticatedRoleName, "Anonymous" ); userRoleDao.createUser( tenantAcme, EXP_LOGIN, "password", "", new String[] { singleTenantAdminRoleName } ); logout(); setUpUser(); PurRepository purRep = (PurRepository) repository; final PurRepositoryConnector purRepositoryConnector = new PurRepositoryConnector( purRep, (PurRepositoryMeta) repositoryMeta, purRep.getRootRef() ); purRep.setPurRepositoryConnector( purRepositoryConnector ); purRep.setTest( repo ); repository.connect( EXP_LOGIN, "password" ); login( EXP_LOGIN, tenantAcme, new String[] { singleTenantAdminRoleName, tenantAuthenticatedRoleName } ); System.out.println( "PUR NAME!!!: " + repo.getClass().getCanonicalName() ); RepositoryFile repositoryFile = repo.getFile( ClientRepositoryPaths.getPublicFolderPath() ); Serializable repositoryFileId = repositoryFile.getId(); List<RepositoryFile> files = repo.getChildren( repositoryFileId ); StringBuilder buf = new StringBuilder(); for ( RepositoryFile file : files ) { buf.append( "\n" ).append( file ); } assertTrue( "files not deleted: " + buf, files.isEmpty() ); }
public SpringProcessEngineTestCase() { super(); this.testContextManager = new TestContextManager(getClass()); }
/** * Construct a new {@code RunBeforeTestMethodCallbacks} statement. * @param next the next {@code Statement} in the execution chain * @param testInstance the current test instance (never {@code null}) * @param testMethod the test method which is about to be executed on the * test instance * @param testContextManager the TestContextManager upon which to call * {@code beforeTestMethod()} */ public RunBeforeTestMethodCallbacks(Statement next, Object testInstance, Method testMethod, TestContextManager testContextManager) { this.next = next; this.testInstance = testInstance; this.testMethod = testMethod; this.testContextManager = testContextManager; }