Package org.nanocontainer.integrationkit

Examples of org.nanocontainer.integrationkit.ContainerRecorder


* @author Konstantin Pribluda ( konstantin.pribluda(at)infodesire.com )
* @author Aslak Hellesøy
*/
public class DefaultContainerRecorderTestCase extends TestCase {
    public void testInvocationsCanBeRecordedAndReplayedOnADifferentContainerInstance() throws Exception {
        ContainerRecorder recorder = new DefaultContainerRecorder(new DefaultNanoPicoContainer());
        MutablePicoContainer recorded = recorder.getContainerProxy();

        recorded.registerComponentInstance("fruit", "apple");
        recorded.registerComponentInstance("int", new Integer(239));
        recorded.registerComponentImplementation("thing",
                ThingThatTakesParamsInConstructor.class,
                new Parameter[]{
                    ComponentParameter.DEFAULT,
                    ComponentParameter.DEFAULT,
                });

        MutablePicoContainer slave = new DefaultPicoContainer();
        recorder.replay(slave);
        assertEquals("apple", slave.getComponentInstance("fruit"));
        assertEquals("apple239", ((ThingThatTakesParamsInConstructor) slave.getComponentInstance("thing")).getValue());

        // test that we can replay once more
        MutablePicoContainer anotherSlave = new DefaultPicoContainer();
        recorder.replay(anotherSlave);
        assertEquals("apple", anotherSlave.getComponentInstance("fruit"));
        assertEquals("apple239", ((ThingThatTakesParamsInConstructor) anotherSlave.getComponentInstance("thing")).getValue());
    }
View Full Code Here


        assertEquals("apple", anotherSlave.getComponentInstance("fruit"));
        assertEquals("apple239", ((ThingThatTakesParamsInConstructor) anotherSlave.getComponentInstance("thing")).getValue());
    }

    public void testRecorderWorksAfterSerialization() throws IOException, ClassNotFoundException, IllegalAccessException, InvocationTargetException {
        ContainerRecorder recorder = new DefaultContainerRecorder(new DefaultPicoContainer());
        MutablePicoContainer recorded = recorder.getContainerProxy();
        recorded.registerComponentInstance("fruit", "apple");

        ContainerRecorder serializedRecorder = (ContainerRecorder) serializeAndDeserialize(recorder);
        MutablePicoContainer slave = new DefaultPicoContainer();
        serializedRecorder.replay(slave);
        assertEquals("apple", slave.getComponentInstance("fruit"));
    }
View Full Code Here

   * @param path the String representing the servlet path used as key for the recorder cache
   * @throws ClassNotFoundException if the container builder class is not found
   */
  public void populateContainerForPath(MutablePicoContainer container,
      String path) throws ClassNotFoundException {
    ContainerRecorder recorder;
    synchronized (recorderCache) {
      recorder = (ContainerRecorder) recorderCache.get(path);
      if (recorder == null) {
        recorder = new DefaultContainerRecorder(new DefaultPicoContainer());
        recorderCache.put(path, recorder);
        ContainerPopulator populator = createContainerPopulator(containerBuilderClassName,
                                    obtainReader(path), Thread.currentThread().getContextClassLoader());
        populator.populateContainer(recorder.getContainerProxy());
      }
    }
    recorder.replay(container);
  }
View Full Code Here

TOP

Related Classes of org.nanocontainer.integrationkit.ContainerRecorder

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.