Example usage for org.springframework.context.annotation AnnotationConfigApplicationContext setDisplayName

List of usage examples for org.springframework.context.annotation AnnotationConfigApplicationContext setDisplayName

Introduction

In this page you can find the example usage for org.springframework.context.annotation AnnotationConfigApplicationContext setDisplayName.

Prototype

public void setDisplayName(String displayName) 

Source Link

Document

Set a friendly name for this context.

Usage

From source file:at.ac.univie.isc.asio.spring.SpringContextFactory.java

public AnnotationConfigApplicationContext named(final String label) {
    final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    context.setParent(root);//from w ww  .j av a  2  s . co  m
    context.setId(root.getId() + ":" + label + ":" + counter.getAndIncrement());
    context.setDisplayName(label);
    return context;
}

From source file:com.fitbur.jestify.junit.spring.IntegrationTestRunner.java

@Override
protected Object createTest() throws Exception {
    try {//from w  w  w .  j  av  a  2s  .  c  o  m
        TestClass testClass = getTestClass();
        Class<?> javaClass = testClass.getJavaClass();
        String name = javaClass.getSimpleName();

        TestDescriptor testDescriptor = testClassContexts.computeIfAbsent(javaClass, p -> {
            Object instance;
            try {
                instance = super.createTest();
                TestContext context = new TestContext(name, javaClass, instance);
                Set<Field> candidatesFields = of(javaClass.getDeclaredFields()).parallel()
                        .filter(f -> f.isAnnotationPresent(Cut.class)).collect(toSet());

                if (candidatesFields.isEmpty()) {
                    checkState(false, "Class under test not defined in %s. "
                            + "Please annotated a single field with @Cut.", name);
                } else if (candidatesFields.size() != 1) {
                    checkState(false, "Found more than one class under test in %s. "
                            + "Please annotated only a single field with @Cut.", name);
                }

                Field cutField = candidatesFields.iterator().next();
                ClassReader testReader = new ClassReader(javaClass.getName());
                ClassReader cutReader = new ClassReader(cutField.getType().getName());

                testReader.accept(new TesAnalyzer(context), EXPAND_FRAMES);
                cutReader.accept(new CutAnalyzer(context), EXPAND_FRAMES);

                return new TestDescriptor(instance, context);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        });

        AnnotationConfigApplicationContext appContext = new AnnotationConfigApplicationContext();
        appContext.setAllowBeanDefinitionOverriding(true);
        appContext.setId(name);
        appContext.setDisplayName(name);

        Object instance = testDescriptor.getInstance();
        TestContext context = testDescriptor.getContext();
        IntegrationTestReifier reifier = new IntegrationTestReifier(appContext, instance);
        IntegrationTestCreator integrationTestCreator = new IntegrationTestCreator(context, reifier,
                appContext);
        integrationTestCreator.create();

        applicationContexts.put(javaClass, appContext);
        return instance;
    } catch (IllegalStateException e) {
        notifier.pleaseStop();
        throw e;
    }
}