Package org.springframework.tests

Examples of org.springframework.tests.TimeStamped


    tb.setName(name);
    ProxyFactory pc = new ProxyFactory(tb);
    NopInterceptor di = new NopInterceptor();
    pc.addAdvice(di);
    final long ts = 37;
    pc.addAdvice(new DelegatingIntroductionInterceptor(new TimeStamped() {
      @Override
      public long getTimeStamp() {
        return ts;
      }
    }));

    ITestBean proxied = (ITestBean) createProxy(pc);
    assertEquals(name, proxied.getName());
    TimeStamped intro = (TimeStamped) proxied;
    assertEquals(ts, intro.getTimeStamp());
  }
View Full Code Here


        throw new UnsupportedOperationException();
      }
    }
    pc.addAdvisor(new DefaultIntroductionAdvisor(new MyDi()));

    TimeStamped ts = (TimeStamped) createProxy(pc);
    try {
      ts.getTimeStamp();
      fail("Should throw UnsupportedOperationException");
    }
    catch (UnsupportedOperationException ex) {
    }
  }
View Full Code Here

    // Add to head of interceptor chain
    int oldCount = config.getAdvisors().length;
    config.addAdvisor(0, new DefaultIntroductionAdvisor(ti, TimeStamped.class));
    assertTrue(config.getAdvisors().length == oldCount + 1);

    TimeStamped ts = (TimeStamped) factory.getBean("test2");
    assertEquals(time, ts.getTimeStamp());

    // Can remove
    config.removeAdvice(ti);
    assertTrue(config.getAdvisors().length == oldCount);

    // Check no change on existing object reference
    assertTrue(ts.getTimeStamp() == time);

    assertThat("Should no longer implement TimeStamped",
        factory.getBean("test2"), not(instanceOf(TimeStamped.class)));

    // Now check non-effect of removing interceptor that isn't there
    config.removeAdvice(new DebugInterceptor());
    assertTrue(config.getAdvisors().length == oldCount);

    ITestBean it = (ITestBean) ts;
    DebugInterceptor debugInterceptor = new DebugInterceptor();
    config.addAdvice(0, debugInterceptor);
    it.getSpouse();
    // Won't affect existing reference
    assertTrue(debugInterceptor.getCount() == 0);
    it = (ITestBean) factory.getBean("test2");
    it.getSpouse();
    assertEquals(1, debugInterceptor.getCount());
    config.removeAdvice(debugInterceptor);
    it.getSpouse();

    // Still invoked wiht old reference
    assertEquals(2, debugInterceptor.getCount());

    // not invoked with new object
    it = (ITestBean) factory.getBean("test2");
    it.getSpouse();
    assertEquals(2, debugInterceptor.getCount());

    // Our own timestamped reference should still work
    assertEquals(time, ts.getTimeStamp());
  }
View Full Code Here

  public void testIntroductionInterceptorWithDelegation() throws Exception {
    TestBean raw = new TestBean();
    assertTrue(! (raw instanceof TimeStamped));
    ProxyFactory factory = new ProxyFactory(raw);

    TimeStamped ts = mock(TimeStamped.class);
    long timestamp = 111L;
    given(ts.getTimeStamp()).willReturn(timestamp);

    factory.addAdvisor(0, new DefaultIntroductionAdvisor(new DelegatingIntroductionInterceptor(ts)));

    TimeStamped tsp = (TimeStamped) factory.getProxy();
    assertTrue(tsp.getTimeStamp() == timestamp);
  }
View Full Code Here

  public void testIntroductionInterceptorWithInterfaceHierarchy() throws Exception {
    TestBean raw = new TestBean();
    assertTrue(! (raw instanceof SubTimeStamped));
    ProxyFactory factory = new ProxyFactory(raw);

    TimeStamped ts = mock(SubTimeStamped.class);
    long timestamp = 111L;
    given(ts.getTimeStamp()).willReturn(timestamp);

    factory.addAdvisor(0, new DefaultIntroductionAdvisor(new DelegatingIntroductionInterceptor(ts), SubTimeStamped.class));

    SubTimeStamped tsp = (SubTimeStamped) factory.getProxy();
    assertTrue(tsp.getTimeStamp() == timestamp);
View Full Code Here

  public void testIntroductionInterceptorWithSuperInterface() throws Exception {
    TestBean raw = new TestBean();
    assertTrue(! (raw instanceof TimeStamped));
    ProxyFactory factory = new ProxyFactory(raw);

    TimeStamped ts = mock(SubTimeStamped.class);
    long timestamp = 111L;
    given(ts.getTimeStamp()).willReturn(timestamp);

    factory.addAdvisor(0, new DefaultIntroductionAdvisor(new DelegatingIntroductionInterceptor(ts), TimeStamped.class));

    TimeStamped tsp = (TimeStamped) factory.getProxy();
    assertTrue(!(tsp instanceof SubTimeStamped));
    assertTrue(tsp.getTimeStamp() == timestamp);
  }
View Full Code Here

    ProxyFactory pf = new ProxyFactory(target);
    pf.addAdvisor(0, new DefaultIntroductionAdvisor(ii));

    //assertTrue(Arrays.binarySearch(pf.getProxiedInterfaces(), TimeStamped.class) != -1);
    TimeStamped ts = (TimeStamped) pf.getProxy();

    assertTrue(ts.getTimeStamp() == t);
    ((ITester) ts).foo();

    ((ITestBean) ts).getAge();
  }
View Full Code Here

    IntroductionAdvisor ia = new DefaultIntroductionAdvisor(ii);
    assertTrue(ia.isPerInstance());
    pf.addAdvisor(0, ia);

    //assertTrue(Arrays.binarySearch(pf.getProxiedInterfaces(), TimeStamped.class) != -1);
    TimeStamped ts = (TimeStamped) pf.getProxy();

    assertThat(ts, instanceOf(TimeStamped.class));
    // Shoulnd't proxy framework interfaces
    assertTrue(!(ts instanceof MethodInterceptor));
    assertTrue(!(ts instanceof IntroductionInterceptor));

    assertTrue(ts.getTimeStamp() == t);
    ((ITester) ts).foo();
    ((ITestBean) ts).getAge();

    // Test removal
    ii.suppressInterface(TimeStamped.class);
View Full Code Here

  public void testIntroductionInterceptorDoesntReplaceToString() throws Exception {
    TestBean raw = new TestBean();
    assertTrue(! (raw instanceof TimeStamped));
    ProxyFactory factory = new ProxyFactory(raw);

    TimeStamped ts = new SerializableTimeStamped(0);

    factory.addAdvisor(0, new DefaultIntroductionAdvisor(new DelegatingIntroductionInterceptor(ts) {
      @Override
      public String toString() {
        throw new UnsupportedOperationException("Shouldn't be invoked");
      }
    }));

    TimeStamped tsp = (TimeStamped) factory.getProxy();
    assertEquals(0, tsp.getTimeStamp());

    assertEquals(raw.toString(), tsp.toString());
  }
View Full Code Here

    serializableTarget.setName("Tony");

    ProxyFactory factory = new ProxyFactory(serializableTarget);
    factory.addInterface(Person.class);
    long time = 1000;
    TimeStamped ts = new SerializableTimeStamped(time);

    factory.addAdvisor(new DefaultIntroductionAdvisor(new DelegatingIntroductionInterceptor(ts)));
    factory.addAdvice(new SerializableNopInterceptor());

    Person p = (Person) factory.getProxy();
View Full Code Here

TOP

Related Classes of org.springframework.tests.TimeStamped

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.