Package org.springframework.context

Examples of org.springframework.context.ApplicationContext


    private ClientTracer clientTracer;

    @Override
    protected Application configure() {
        ApplicationContext context = new AnnotationConfigApplicationContext(JerseyTestSpringConfig.class);
        clientTracer = context.getBean(ClientTracer.class);
        return new JerseyTestConfig().property("contextConfig", context);
    }
View Full Code Here


@Ignore
public class StringConversionServiceTest {

    @Test
    public void testStartupOfSpringInegrationContext() throws Exception{
        final ApplicationContext context
            = new ClassPathXmlApplicationContext("/META-INF/spring/integration/spring-integration-context.xml",
                                                  StringConversionServiceTest.class);
        Thread.sleep(2000);
    }
View Full Code Here

        Thread.sleep(2000);
    }

    @Test
    public void testConvertStringToUpperCase() {
        final ApplicationContext context
            = new ClassPathXmlApplicationContext("/META-INF/spring/integration/spring-integration-context.xml",
                                                  StringConversionServiceTest.class);

        final StringConversionService service = context.getBean(StringConversionService.class);

        final String stringToConvert = "I love Spring Integration";
        final String expectedResult  = "I LOVE SPRING INTEGRATION";

      //  final String convertedString = service.convertToUpperCase(stringToConvert);
View Full Code Here

  private Logger logger = Logger.getLogger(OutboundGatewayTest.class)
 
  @Test
  public void insertPersonRecord() { 
    ApplicationContext context
        = new ClassPathXmlApplicationContext("/META-INF/spring/integration/spring-integration-context.xml");
    PersonService service = context.getBean(PersonService.class);
    logger.info("Creating person Instance");
    Person person = new Person();
    Calendar dateOfBirth = Calendar.getInstance();
    dateOfBirth.set(1980, 0, 1);
    person.setDateOfBirth(dateOfBirth.getTime());
View Full Code Here

public class ConsulContextRefreshedListener extends RunOnceApplicationListener<ContextRefreshedEvent> {
    private static final Logger LOGGER = LoggerFactory.getLogger(ConsulContextRefreshedListener.class);

    @Override
    public void onApplicationEventInternal(ContextRefreshedEvent event) {
        ApplicationContext context = event.getApplicationContext();
        ConsulProperties consulProperties = context.getBean(ConsulProperties.class);
        if (!consulProperties.isEnabled())
            return;

        ApplicationProperties appProps = context.getBean(ApplicationProperties.class);
        ServerProperties serverProperties = context.getBean(ServerProperties.class);
        AgentClient agentClient = context.getBean(AgentClient.class);

        Service service = new Service();
        service.setName(appProps.getId());
        Integer port = serverProperties.getPort();
        if (port == null) {
            port = 8080;
        }
        service.setPort(port);
        service.setTags(consulProperties.getTags());

        //TODO: add support for Check

        register(agentClient, service);

        String managementPort = context.getEnvironment().getProperty("management.port", (String) null);
        if (managementPort != null) {
            Service management = new Service();
            management.setName(appProps.getId() + "/management"); //TODO: configurable management suffix
            management.setPort(Integer.parseInt(managementPort));
            List<String> tags = new ArrayList<>(consulProperties.getTags());
            tags.add("management"); //TODO: configurable management tag
            management.setTags(tags);

            register(agentClient, management);
        }

        if (!appProps.getRoutes().isEmpty()) {
            try {
                KVClient kvClient = context.getBean(KVClient.class);

                String key = String.format("routing/%s", appProps.getId());
                //TODO: get routes from jax-rs and spring mvc
                kvClient.put(key, appProps.getRoutes());
            } catch (Exception e) {
View Full Code Here

  }

  @Test
  public void convertsStringToUserCorrectly() throws Exception {

    ApplicationContext context = initContextWithRepo();
    converter.setApplicationContext(context);

    when(service.canConvert(String.class, Long.class)).thenReturn(true);
    when(service.convert(anyString(), eq(Long.class))).thenReturn(1L);

    converter.convert("1", sourceDescriptor, targetDescriptor);

    UserRepository bean = context.getBean(UserRepository.class);
    UserRepository repo = (UserRepository) ((Advised) bean).getTargetSource().getTarget();

    verify(repo, times(1)).findOne(1L);
  }
View Full Code Here

   * @see DATACMNS-133
   */
  @Test
  public void discoversFactoryAndRepoFromParentApplicationContext() {

    ApplicationContext parent = initContextWithRepo();
    GenericApplicationContext context = new GenericApplicationContext(parent);
    context.refresh();

    when(service.canConvert(String.class, Long.class)).thenReturn(true);

View Full Code Here

   * @DATACMNS-583
   */
  @Test
  public void shouldReturnSourceObjectIfSourceAndTargetTypesAreTheSame() {

    ApplicationContext context = initContextWithRepo();
    converter.setApplicationContext(context);

    assertThat(converter.matches(targetDescriptor, targetDescriptor), is(true));
    assertThat((User) converter.convert(USER, targetDescriptor, targetDescriptor), is(USER));
  }
View Full Code Here

  }

  @Test
  public void registersBasicBeanDefinitions() throws Exception {

    ApplicationContext context = WebTestUtils.createApplicationContext(SampleConfig.class);
    List<String> names = Arrays.asList(context.getBeanDefinitionNames());

    assertThat(names, hasItems("pageableResolver", "sortResolver"));

    assertResolversRegistered(context, SortHandlerMethodArgumentResolver.class,
        PageableHandlerMethodArgumentResolver.class);
View Full Code Here

  }

  @Test
  public void registersHateoasSpecificBeanDefinitions() throws Exception {

    ApplicationContext context = WebTestUtils.createApplicationContext(SampleConfig.class);
    List<String> names = Arrays.asList(context.getBeanDefinitionNames());

    assertThat(names, hasItems("pagedResourcesAssembler", "pagedResourcesAssemblerArgumentResolver"));
    assertResolversRegistered(context, PagedResourcesAssemblerArgumentResolver.class);
  }
View Full Code Here

TOP

Related Classes of org.springframework.context.ApplicationContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.