Package example.scannable

Examples of example.scannable.FooService


  @Test
  public void testFooService() throws Exception {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(getConfigLocations(), getClass());

    FooService fooService = (FooService) ctx.getBean("fooServiceImpl");
    ServiceInvocationCounter serviceInvocationCounter = (ServiceInvocationCounter) ctx.getBean("serviceInvocationCounter");

    assertEquals(0, serviceInvocationCounter.getCount());

    assertTrue(fooService.isInitCalled());
    assertEquals(1, serviceInvocationCounter.getCount());

    String value = fooService.foo(1);
    assertEquals("bar", value);
    assertEquals(2, serviceInvocationCounter.getCount());

    fooService.foo(1);
    assertEquals(3, serviceInvocationCounter.getCount());
  }
View Full Code Here


  @Test
  public void testFooService() throws Exception {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(getConfigLocations(), getClass());

    FooService fooService = ctx.getBean("fooServiceImpl", FooService.class);
    ServiceInvocationCounter serviceInvocationCounter = ctx.getBean("serviceInvocationCounter", ServiceInvocationCounter.class);

    String value = fooService.foo(1);
    assertEquals("bar", value);

    Future<?> future = fooService.asyncFoo(1);
    assertTrue(future instanceof FutureTask);
    assertEquals("bar", future.get());

    assertEquals(2, serviceInvocationCounter.getCount());

    fooService.foo(1);
    assertEquals(3, serviceInvocationCounter.getCount());
  }
View Full Code Here

    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(ComponentScanWithScopedProxy.class);
    ctx.getBeanFactory().registerScope("myScope", new SimpleMapScope());
    ctx.refresh();
    // should cast to the interface
    FooService bean = (FooService) ctx.getBean("scopedProxyTestBean");
    // should be dynamic proxy
    assertThat(AopUtils.isJdkDynamicProxy(bean), is(true));
    // test serializability
    assertThat(bean.foo(1), equalTo("bar"));
    FooService deserialized = (FooService) SerializationTestUtils.serializeAndDeserialize(bean);
    assertThat(deserialized, notNullValue());
    assertThat(deserialized.foo(1), equalTo("bar"));
  }
View Full Code Here

    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(ComponentScanWithScopedProxyThroughRegex.class);
    ctx.getBeanFactory().registerScope("myScope", new SimpleMapScope());
    ctx.refresh();
    // should cast to the interface
    FooService bean = (FooService) ctx.getBean("scopedProxyTestBean");
    // should be dynamic proxy
    assertThat(AopUtils.isJdkDynamicProxy(bean), is(true));
  }
View Full Code Here

    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(ComponentScanWithScopedProxyThroughAspectJPattern.class);
    ctx.getBeanFactory().registerScope("myScope", new SimpleMapScope());
    ctx.refresh();
    // should cast to the interface
    FooService bean = (FooService) ctx.getBean("scopedProxyTestBean");
    // should be dynamic proxy
    assertThat(AopUtils.isJdkDynamicProxy(bean), is(true));
  }
View Full Code Here

    assertThat(AopUtils.isCglibProxy(ctx.getBean(FooService.class)), is(true));
  }


  private void aspectIsApplied(ApplicationContext ctx) throws Exception {
    FooService fooService = ctx.getBean(FooService.class);
    ServiceInvocationCounter counter = ctx.getBean(ServiceInvocationCounter.class);

    assertEquals(0, counter.getCount());

    assertTrue(fooService.isInitCalled());
    assertEquals(1, counter.getCount());

    String value = fooService.foo(1);
    assertEquals("bar", value);
    assertEquals(2, counter.getCount());

    fooService.foo(1);
    assertEquals(3, counter.getCount());
  }
View Full Code Here

  public void testInterfacesScopedProxy() throws Exception {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
        "org/springframework/context/annotation/scopedProxyInterfacesTests.xml");
    context.getBeanFactory().registerScope("myScope", new SimpleMapScope());
    // should cast to the interface
    FooService bean = (FooService) context.getBean("scopedProxyTestBean");
    // should be dynamic proxy
    assertTrue(AopUtils.isJdkDynamicProxy(bean));
    // test serializability
    assertEquals("bar", bean.foo(1));
    FooService deserialized = (FooService) SerializationTestUtils.serializeAndDeserialize(bean);
    assertNotNull(deserialized);
    assertEquals("bar", deserialized.foo(1));
  }
View Full Code Here

    scanner.setIncludeAnnotationConfig(false);
    scanner.setBeanNameGenerator(new TestBeanNameGenerator());
    int beanCount = scanner.scan(BASE_PACKAGE);
    assertEquals(6, beanCount);
    context.refresh();
    FooService fooService = (FooService) context.getBean("fooService");
    assertFalse(fooService.isInitCalled());
    try {
      fooService.foo(123);
      fail("NullPointerException expected; fooDao must not have been set");
    }
    catch (NullPointerException expected) {
    }
  }
View Full Code Here

    scanner.setIncludeAnnotationConfig(true);
    scanner.setBeanNameGenerator(new TestBeanNameGenerator());
    scanner.setAutowireCandidatePatterns(new String[] { "*FooDao" });
    scanner.scan(BASE_PACKAGE);
    context.refresh();
    FooService fooService = (FooService) context.getBean("fooService");
    assertEquals("bar", fooService.foo(123));
  }
View Full Code Here

TOP

Related Classes of example.scannable.FooService

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.