private WithSecurityContextFactory<? extends Annotation> createFactory( WithSecurityContext withSecurityContext, TestContext testContext) { Class<? extends WithSecurityContextFactory<? extends Annotation>> clazz = withSecurityContext .factory(); try { return testContext.getApplicationContext().getAutowireCapableBeanFactory() .createBean(clazz); } catch (IllegalStateException e) { return BeanUtils.instantiateClass(clazz); } catch (Exception e) { throw new RuntimeException(e); } }
@SuppressWarnings({ "rawtypes", "unchecked" }) private TestSecurityContext createTestSecurityContext(AnnotatedElement annotated, WithSecurityContext withSecurityContext, TestContext context) { if (withSecurityContext == null) { return null; } withSecurityContext = AnnotationUtils .synthesizeAnnotation(withSecurityContext, annotated); WithSecurityContextFactory factory = createFactory(withSecurityContext, context); Class<? extends Annotation> type = (Class<? extends Annotation>) GenericTypeResolver .resolveTypeArgument(factory.getClass(), WithSecurityContextFactory.class); Annotation annotation = findAnnotation(annotated, type); TestExecutionEvent initialize = withSecurityContext.setupBefore(); try { return new TestSecurityContext(factory.createSecurityContext(annotation), initialize); } catch (RuntimeException e) { throw new IllegalStateException( "Unable to create SecurityContext using " + annotation, e); } }
@SuppressWarnings({ "rawtypes", "unchecked" }) private TestSecurityContext createTestSecurityContext(AnnotatedElement annotated, WithSecurityContext withSecurityContext, TestContext context) { if (withSecurityContext == null) { return null; } withSecurityContext = AnnotationUtils .synthesizeAnnotation(withSecurityContext, annotated); WithSecurityContextFactory factory = createFactory(withSecurityContext, context); Class<? extends Annotation> type = (Class<? extends Annotation>) GenericTypeResolver .resolveTypeArgument(factory.getClass(), WithSecurityContextFactory.class); Annotation annotation = findAnnotation(annotated, type); TestExecutionEvent initialize = withSecurityContext.setupBefore(); try { return new TestSecurityContext(factory.createSecurityContext(annotation), initialize); } catch (RuntimeException e) { throw new IllegalStateException( "Unable to create SecurityContext using " + annotation, e); } }
private WithSecurityContextFactory<? extends Annotation> createFactory( WithSecurityContext withSecurityContext, TestContext testContext) { Class<? extends WithSecurityContextFactory<? extends Annotation>> clazz = withSecurityContext .factory(); try { return testContext.getApplicationContext().getAutowireCapableBeanFactory() .createBean(clazz); } catch (IllegalStateException e) { return BeanUtils.instantiateClass(clazz); } catch (Exception e) { throw new RuntimeException(e); } }