コード例 #1
0
  @Test
  public void testEventTrace() {
    KevoreeFactory factory = new DefaultKevoreeFactory();
    ContainerRoot model = factory.createContainerRoot();

    ContainerNode node0 = factory.createContainerNode();
    node0.setName("node0");
    model.addNodes(node0);

    ContainerNode web = factory.createContainerNode();
    web.setName("web");
    model.addNodes(web);
    node0.addHosts(web);

    try {

      ContainerRoot clonedModel = (ContainerRoot) cloner.clone(model);

      EventListenerImpl listener = new EventListenerImpl();
      model.addModelTreeListener(listener);

      ContainerNode newChildNode = factory.createContainerNode();
      newChildNode.setName("toto");
      model.addNodes(newChildNode);
      node0.addHosts(newChildNode);

      listener.traceSequence.applyOn(clonedModel);

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
コード例 #2
0
public class EventTraceTester3 {

  private KevoreeFactory factory = new DefaultKevoreeFactory();
  private ModelCloner cloner = factory.createModelCloner();
  private ModelCompare compare = factory.createModelCompare();
  private JSONModelSerializer saver = factory.createJSONSerializer();
  private JSONModelLoader loader = factory.createJSONLoader();

  @Test
  public void testEventTrace() {
    KevoreeFactory factory = new DefaultKevoreeFactory();
    ContainerRoot model = factory.createContainerRoot();

    ContainerNode node0 = factory.createContainerNode();
    node0.setName("node0");
    model.addNodes(node0);

    ContainerNode web = factory.createContainerNode();
    web.setName("web");
    model.addNodes(web);
    node0.addHosts(web);

    try {

      ContainerRoot clonedModel = (ContainerRoot) cloner.clone(model);

      EventListenerImpl listener = new EventListenerImpl();
      model.addModelTreeListener(listener);

      ContainerNode newChildNode = factory.createContainerNode();
      newChildNode.setName("toto");
      model.addNodes(newChildNode);
      node0.addHosts(newChildNode);

      listener.traceSequence.applyOn(clonedModel);

    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  private class EventListenerImpl implements ModelElementListener {

    TraceSequence traceSequence = new TraceSequence(factory);

    @Override
    public void elementChanged(ModelEvent modelEvent) {
      traceSequence.append(new Event2Trace(compare).convert(modelEvent));
    }
  }
}