Package org.springframework.tests.sample.beans

Examples of org.springframework.tests.sample.beans.TestBean


    ppc2Properties = new Properties();
    ppc2Properties.setProperty(P2, P2_LOCAL_PROPS_VAL);
    ppc2.postProcessBeanFactory(bf);

    TestBean p1Bean = bf.getBean("p1Bean", TestBean.class);
    assertThat(p1Bean.getName(), equalTo(P1_LOCAL_PROPS_VAL));

    TestBean p2Bean = bf.getBean("p2Bean", TestBean.class);
    assertThat(p2Bean.getName(), equalTo(P1_LOCAL_PROPS_VAL));
    assertThat(p2Bean.getCountry(), equalTo(P2_SYSTEM_PROPS_VAL));

    System.clearProperty(P2);
    getModifiableSystemEnvironment().remove(P2);
  }
View Full Code Here


    pc.addAdvice(mami4);
    pc.addAdvice(mami5);
    pc.addAdvice(mami6);

    // We don't care about the object
    pc.setTarget(new TestBean());
    AopProxy aop = createAopProxy(pc);
    ITestBean tb = (ITestBean) aop.getProxy();

    String newName = "foo";
    tb.setName(newName);
View Full Code Here

      @Override
      public boolean matches(Method m, Class<?> targetClass) {
        return m.getParameterTypes().length == 0 || "exceptional".equals(m.getName());
      }
    };
    TestBean target = new TestBean();
    target.setAge(80);
    ProxyFactory pf = new ProxyFactory(target);
    pf.addAdvice(new NopInterceptor());
    pf.addAdvisor(matchesNoArgs);
    assertEquals("Advisor was added", matchesNoArgs, pf.getAdvisors()[1]);
    ITestBean proxied = (ITestBean) createProxy(pf);

    assertEquals(0, cca.getCalls());
    assertEquals(0, cca.getCalls("getAge"));
    assertEquals(target.getAge(), proxied.getAge());
    assertEquals(2, cca.getCalls());
    assertEquals(2, cca.getCalls("getAge"));
    assertEquals(0, cca.getCalls("setAge"));
    // Won't be advised
    proxied.setAge(26);
View Full Code Here

        if (m.getName().startsWith("set"))
          throw rex;
      }
    };

    TestBean target = new TestBean();
    target.setAge(80);
    NopInterceptor nop1 = new NopInterceptor();
    NopInterceptor nop2 = new NopInterceptor();
    ProxyFactory pf = new ProxyFactory(target);
    pf.addAdvice(nop1);
    pf.addAdvice(ba);
    pf.addAdvice(nop2);
    ITestBean proxied = (ITestBean) createProxy(pf);
    // Won't throw an exception
    assertEquals(target.getAge(), proxied.getAge());
    assertEquals(1, ba.getCalls());
    assertEquals(1, ba.getCalls("getAge"));
    assertEquals(1, nop1.getCount());
    assertEquals(1, nop2.getCount());
    // Will fail, after invoking Nop1
    try {
      proxied.setAge(26);
      fail("before advice should have ended chain");
    }
    catch (RuntimeException ex) {
      assertEquals(rex, ex);
    }
    assertEquals(2, ba.getCalls());
    assertEquals(2, nop1.getCount());
    // Nop2 didn't get invoked when the exception was thrown
    assertEquals(1, nop2.getCount());
    // Shouldn't have changed value in joinpoint
    assertEquals(target.getAge(), proxied.getAge());
  }
View Full Code Here

      @Override
      public boolean matches(Method m, Class<?> targetClass) {
        return m.getReturnType() == int.class;
      }
    };
    TestBean target = new TestBean();
    ProxyFactory pf = new ProxyFactory(target);
    pf.addAdvice(new NopInterceptor());
    pf.addAdvisor(matchesInt);
    assertEquals("Advisor was added", matchesInt, pf.getAdvisors()[1]);
    ITestBean proxied = (ITestBean) createProxy(pf);
View Full Code Here

  }

  @Test
  public void testAfterReturningAdvisorIsNotInvokedOnException() {
    CountingAfterReturningAdvice car = new CountingAfterReturningAdvice();
    TestBean target = new TestBean();
    ProxyFactory pf = new ProxyFactory(target);
    pf.addAdvice(new NopInterceptor());
    pf.addAdvice(car);
    assertEquals("Advice was wrapped in Advisor and added", car, pf.getAdvisors()[1].getAdvice());
    ITestBean proxied = (ITestBean) createProxy(pf);
View Full Code Here

    System.getProperties().put("country", "UK");
    try {
      ac.refresh();

      TestBean tb0 = ac.getBean("tb0", TestBean.class);

      TestBean tb1 = ac.getBean("tb1", TestBean.class);
      assertEquals("XXXmyNameYYY42ZZZ", tb1.getName());
      assertEquals(42, tb1.getAge());

      TestBean tb2 = ac.getBean("tb2", TestBean.class);
      assertEquals("{ XXXmyNameYYY42ZZZ }", tb2.getName());
      assertEquals(42, tb2.getAge());
      assertEquals("123 UK", tb2.getCountry());

      ValueTestBean tb3 = ac.getBean("tb3", ValueTestBean.class);
      assertEquals("XXXmyNameYYY42ZZZ", tb3.name);
      assertEquals(42, tb3.age);
      assertEquals(42, tb3.ageFactory.getObject().intValue());
View Full Code Here

    sw.start("prototype");
    System.getProperties().put("name", "juergen");
    System.getProperties().put("country", "UK");
    try {
      for (int i = 0; i < 100000; i++) {
        TestBean tb = (TestBean) ac.getBean("test");
        assertEquals("juergen", tb.getName());
        assertEquals("UK", tb.getCountry());
      }
      sw.stop();
    }
    finally {
      System.getProperties().remove("country");
View Full Code Here

    request.setAttribute("test1", "value1");
    request.setAttribute("test2", "value2");
    WebApplicationContext wac = new StaticWebApplicationContext();
    request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
    TestBean command = new TestBean();
    request.setAttribute("command", command);

    request.setAttribute(WebUtils.INCLUDE_REQUEST_URI_ATTRIBUTE, "/form.do");
    simpleDispatcherServlet.service(request, response);
View Full Code Here

    request.setAttribute("test1", "value1");
    request.setAttribute("test2", "value2");
    WebApplicationContext wac = new StaticWebApplicationContext();
    request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
    TestBean command = new TestBean();
    request.setAttribute("command", command);

    request.setAttribute(WebUtils.INCLUDE_REQUEST_URI_ATTRIBUTE, "/form.do");
    simpleDispatcherServlet.setCleanupAfterInclude(false);
    simpleDispatcherServlet.service(request, response);
View Full Code Here

TOP

Related Classes of org.springframework.tests.sample.beans.TestBean

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.