コード例 #1
0
  /**
   * Tests the attaching of the LeftInputAdapterNode to an ObjectSource
   *
   * @throws Exception
   */
  @Test
  public void testAttach() throws Exception {
    final MockObjectSource source = new MockObjectSource(15);

    final LeftInputAdapterNode liaNode = new LeftInputAdapterNode(1, source, buildContext);
    final Field field = ObjectSource.class.getDeclaredField("sink");
    field.setAccessible(true);
    ObjectSinkPropagator sink = (ObjectSinkPropagator) field.get(source);

    assertEquals(1, liaNode.getId());
    assertNotNull(sink);

    liaNode.attach();

    sink = (ObjectSinkPropagator) field.get(source);

    assertEquals(1, sink.getSinks().length);

    assertSame(liaNode, sink.getSinks()[0]);
  }
コード例 #2
0
ファイル: ObjectSourceTest.java プロジェクト: Zillode/drools
  @Test
  public void testAddObjectSink() throws Exception {
    final MockObjectSource source = new MockObjectSource(15);

    // We need to re-assign this var each time the sink changes references
    final Field field = ObjectSource.class.getDeclaredField("sink");
    field.setAccessible(true);
    ObjectSinkPropagator sink = (ObjectSinkPropagator) field.get(source);

    assertSame(EmptyObjectSinkAdapter.getInstance(), sink);

    final MockObjectSink sink1 = new MockObjectSink();
    source.addObjectSink(sink1);
    sink = (ObjectSinkPropagator) field.get(source);
    assertSame(SingleObjectSinkAdapter.class, sink.getClass());
    assertEquals(1, sink.getSinks().length);

    final MockObjectSink sink2 = new MockObjectSink();
    source.addObjectSink(sink2);
    sink = (ObjectSinkPropagator) field.get(source);
    assertSame(CompositeObjectSinkAdapter.class, sink.getClass());
    assertEquals(2, sink.getSinks().length);

    final MockObjectSink sink3 = new MockObjectSink();
    source.addObjectSink(sink3);
    assertSame(CompositeObjectSinkAdapter.class, sink.getClass());
    assertEquals(3, sink.getSinks().length);

    source.removeObjectSink(sink2);
    assertSame(CompositeObjectSinkAdapter.class, sink.getClass());
    assertEquals(2, sink.getSinks().length);

    source.removeObjectSink(sink1);
    sink = (ObjectSinkPropagator) field.get(source);
    assertSame(SingleObjectSinkAdapter.class, sink.getClass());
    assertEquals(1, sink.getSinks().length);

    source.removeObjectSink(sink3);
    sink = (ObjectSinkPropagator) field.get(source);
    assertSame(EmptyObjectSinkAdapter.getInstance(), sink);
    assertEquals(0, sink.getSinks().length);
  }