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

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

Introduction

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

Prototype

@Override
    public String getId() 

Source Link

Usage

From source file:at.ac.univie.isc.asio.nest.D2rqNestAssembler.java

@Override
public Container assemble(final Id name, final ByteSource source) {
    log.debug(Scope.SYSTEM.marker(), "assemble <{}> from {}", name, source);
    final Model model = LoadD2rqModel.inferBaseUri().parse(source);
    final NestConfig initial = parse(model);
    initial.getDataset().setName(name);/*w ww. j  a  v  a 2  s.  c o  m*/
    log.debug(Scope.SYSTEM.marker(), "initial config for {} : {}", name, initial);
    final NestConfig processed = postProcess(initial, configurers);
    log.debug(Scope.SYSTEM.marker(), "final config for {} : {}", name, initial);
    final AnnotationConfigApplicationContext context = create.named(name.asString());
    inject(context, processed);
    log.debug(Scope.SYSTEM.marker(), "assembled container <{}> with {} ({})", name, context.getId(), context);
    return NestContainer.wrap(context, processed);
}

From source file:org.springframework.data.gemfire.support.SpringContextBootstrappingInitializerTest.java

@Test
public void testInitWithAnnotatedClasses() {
    final AnnotationConfigApplicationContext mockApplicationContext = mock(
            AnnotationConfigApplicationContext.class, "testInitWithAnnotatedClasses");

    doNothing().when(mockApplicationContext).addApplicationListener(any(ApplicationListener.class));
    doNothing().when(mockApplicationContext).registerShutdownHook();
    doNothing().when(mockApplicationContext).refresh();
    doNothing().when(mockApplicationContext).register(Matchers.<Class<?>[]>anyVararg());
    //doNothing().when(mockApplicationContext).register(annotatedClasses(TestAppConfigOne.class, TestAppConfigTwo.class));

    when(mockApplicationContext.getId()).thenReturn("testInitWithAnnotatedClasses");
    when(mockApplicationContext.isRunning()).thenReturn(true);

    assertNull(SpringContextBootstrappingInitializer.applicationContext);

    SpringContextBootstrappingInitializer.register(TestAppConfigOne.class);
    SpringContextBootstrappingInitializer.register(TestAppConfigTwo.class);

    SpringContextBootstrappingInitializer initializer = new SpringContextBootstrappingInitializer() {
        @Override// w ww  .j  a  v a2 s. c  o  m
        protected ConfigurableApplicationContext createApplicationContext(String[] configLocations) {
            return mockApplicationContext;
        }
    };

    initializer.init(createParameters("test", "test"));

    verify(mockApplicationContext, times(1)).addApplicationListener(same(initializer));
    verify(mockApplicationContext, times(1)).registerShutdownHook();
    verify(mockApplicationContext, times(1)).register(TestAppConfigOne.class, TestAppConfigTwo.class);
    //verify(mockApplicationContext, times(1)).register(annotatedClasses(TestAppConfigOne.class, TestAppConfigTwo.class));
    //verify(mockApplicationContext, times(1)).register(Matchers.<Class<?>[]>anyVararg());
    verify(mockApplicationContext, never()).scan(any(String[].class));

    assertEquals(mockApplicationContext, SpringContextBootstrappingInitializer.getApplicationContext());
}