Java Code Examples for org.easymock.CaptureType#ALL

The following examples show how to use org.easymock.CaptureType#ALL . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MongoDbOutputTest.java    From pentaho-mongodb-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * Tests if mongo output configuration contains excessive fields in step input against mongo output fields, we
 * generate a mockLog record about the fields will not be used in mongo output.
 *
 * @throws Exception
 */
@Test public void testStepLogSkippedFields() throws Exception {
  MongoDbOutput output = prepareMongoDbOutputMock();

  final String[] metaNames = new String[] { "a1", "a2", "a3" };
  String[] mongoNames = new String[] { "a1", "a2" };
  Capture<String> loggerCapture = new Capture<String>( CaptureType.ALL );
  output.logBasic( EasyMock.capture( loggerCapture ) );
  EasyMock.replay( output );
  RowMetaInterface rmi = getStubRowMetaInterface( metaNames );
  List<MongoDbOutputMeta.MongoField> mongoFields = getMongoFields( mongoNames );

  output.checkInputFieldsMatch( rmi, mongoFields );
  List<String> logRecords = loggerCapture.getValues();

  Assert.assertEquals( "We have one mockLog record generated", 1, logRecords.size() );
  Assert.assertTrue( "We have a mockLog record mentions that 'a3' field will not be used.",
    logRecords.get( 0 ).contains( "a3" ) );
}
 
Example 2
Source File: HubTest.java    From floodlight_with_topoguard with Apache License 2.0 5 votes vote down vote up
@Test
public void testFloodNoBufferId() throws Exception {
    // build our expected flooded packetOut
    OFPacketOut po = ((OFPacketOut) mockFloodlightProvider.getOFMessageFactory().getMessage(OFType.PACKET_OUT))
        .setActions(Arrays.asList(new OFAction[] {new OFActionOutput().setPort(OFPort.OFPP_FLOOD.getValue())}))
        .setActionsLength((short) OFActionOutput.MINIMUM_LENGTH)
        .setBufferId(-1)
        .setInPort((short) 1)
        .setPacketData(this.testPacketSerialized);
    po.setLengthU(OFPacketOut.MINIMUM_LENGTH + po.getActionsLengthU()
            + this.testPacketSerialized.length);

    // Mock up our expected behavior
    IOFSwitch mockSwitch = createMock(IOFSwitch.class);
    
    Capture<OFMessage> wc1 = new Capture<OFMessage>(CaptureType.ALL);
    Capture<FloodlightContext> bc1 = new Capture<FloodlightContext>(CaptureType.ALL);
    
    mockSwitch.write(capture(wc1), capture(bc1));

    // Start recording the replay on the mocks
    replay(mockSwitch);
    // Get the listener and trigger the packet in
    IOFMessageListener listener = mockFloodlightProvider.getListeners().get(
            OFType.PACKET_IN).get(0);
    listener.receive(mockSwitch, this.packetIn,
                     parseAndAnnotate(this.packetIn));

    // Verify the replay matched our expectations
    verify(mockSwitch);
    
    assertTrue(wc1.hasCaptured());
    OFMessage m = wc1.getValue();
    assertEquals(po, m);
}
 
Example 3
Source File: HubTest.java    From floodlight_with_topoguard with Apache License 2.0 5 votes vote down vote up
@Test
public void testFloodBufferId() throws Exception {
    MockFloodlightProvider mockFloodlightProvider = getMockFloodlightProvider();
    this.packetIn.setBufferId(10);

    // build our expected flooded packetOut
    OFPacketOut po = ((OFPacketOut) mockFloodlightProvider.getOFMessageFactory().getMessage(OFType.PACKET_OUT))
        .setActions(Arrays.asList(new OFAction[] {new OFActionOutput().setPort(OFPort.OFPP_FLOOD.getValue())}))
        .setActionsLength((short) OFActionOutput.MINIMUM_LENGTH)
        .setBufferId(10)
        .setInPort((short) 1);
    po.setLengthU(OFPacketOut.MINIMUM_LENGTH + po.getActionsLengthU());

    // Mock up our expected behavior
    IOFSwitch mockSwitch = createMock(IOFSwitch.class);
    Capture<OFMessage> wc1 = new Capture<OFMessage>(CaptureType.ALL);
    Capture<FloodlightContext> bc1 = new Capture<FloodlightContext>(CaptureType.ALL);
    
    mockSwitch.write(capture(wc1), capture(bc1));

    // Start recording the replay on the mocks
    replay(mockSwitch);
    // Get the listener and trigger the packet in
    IOFMessageListener listener = mockFloodlightProvider.getListeners().get(
            OFType.PACKET_IN).get(0);
    listener.receive(mockSwitch, this.packetIn,
                     parseAndAnnotate(this.packetIn));

    // Verify the replay matched our expectations
    verify(mockSwitch);
    
    assertTrue(wc1.hasCaptured());
    OFMessage m = wc1.getValue();
    assertEquals(po, m);
}
 
Example 4
Source File: StaticFlowTests.java    From floodlight_with_topoguard with Apache License 2.0 5 votes vote down vote up
@Override
public void setUp() throws Exception {
    super.setUp();
    staticFlowEntryPusher = new StaticFlowEntryPusher();
    storage = createStorageWithFlowEntries();
    dpid = HexString.toLong(TestSwitch1DPID);

    mockSwitch = createNiceMock(IOFSwitch.class);
    writeCapture = new Capture<OFMessage>(CaptureType.ALL);
    contextCapture = new Capture<FloodlightContext>(CaptureType.ALL);
    writeCaptureList = new Capture<List<OFMessage>>(CaptureType.ALL);

    //OFMessageSafeOutStream mockOutStream = createNiceMock(OFMessageSafeOutStream.class);
    mockSwitch.write(capture(writeCapture), capture(contextCapture));
    expectLastCall().anyTimes();
    mockSwitch.write(capture(writeCaptureList), capture(contextCapture));
    expectLastCall().anyTimes();
    mockSwitch.flush();
    expectLastCall().anyTimes();


    FloodlightModuleContext fmc = new FloodlightModuleContext();
    fmc.addService(IStorageSourceService.class, storage);

    MockFloodlightProvider mockFloodlightProvider = getMockFloodlightProvider();
    Map<Long, IOFSwitch> switchMap = new HashMap<Long, IOFSwitch>();
    switchMap.put(dpid, mockSwitch);
    // NO ! expect(mockFloodlightProvider.getSwitches()).andReturn(switchMap).anyTimes();
    mockFloodlightProvider.setSwitches(switchMap);
    fmc.addService(IFloodlightProviderService.class, mockFloodlightProvider);
    RestApiServer restApi = new RestApiServer();
    fmc.addService(IRestApiService.class, restApi);
    restApi.init(fmc);
    staticFlowEntryPusher.init(fmc);
    staticFlowEntryPusher.startUp(fmc);    // again, to hack unittest
}
 
Example 5
Source File: ExpectedValueCheckingTest.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
@Before
public void setupMocks() throws BackendException {

    // Initialize mock controller
    ctrl = EasyMock.createStrictControl();
    ctrl.checkOrder(true);

    // Setup some config mocks and objects
    backingManager = ctrl.createMock(KeyColumnValueStoreManager.class);
    lockerProvider = ctrl.createMock(LockerProvider.class);
    globalConfig = GraphDatabaseConfiguration.buildGraphConfiguration();
    localConfig = GraphDatabaseConfiguration.buildGraphConfiguration();
    defaultConfig = GraphDatabaseConfiguration.buildGraphConfiguration();
    // Set some properties on the configs, just so that global/local/default can be easily distinguished
    globalConfig.set(GraphDatabaseConfiguration.UNIQUE_INSTANCE_ID, "global");
    localConfig.set(GraphDatabaseConfiguration.UNIQUE_INSTANCE_ID, "local");
    defaultConfig.set(GraphDatabaseConfiguration.UNIQUE_INSTANCE_ID, "default");
    defaultTxConfig = new StandardBaseTransactionConfig.Builder().customOptions(defaultConfig).timestampProvider(TimestampProviders.MICRO).build();
    backingFeatures = new StandardStoreFeatures.Builder().keyConsistent(globalConfig, localConfig).build();


    // Setup behavior specification starts below this line


    // 1. Construct manager
    // The EVCSManager ctor retrieves the backing store's features and stores it in an instance field
    expect(backingManager.getFeatures()).andReturn(backingFeatures).once();

    // 2. Begin transaction
    // EVCTx begins two transactions on the backingManager: one with globalConfig and one with localConfig
    // The capture is used in the @After method to check the config
    txConfigCapture = new Capture<BaseTransactionConfig>(CaptureType.ALL);
    inconsistentTx = ctrl.createMock(StoreTransaction.class);
    consistentTx = ctrl.createMock(StoreTransaction.class);
    expect(backingManager.beginTransaction(capture(txConfigCapture))).andReturn(inconsistentTx);
    expect(backingManager.beginTransaction(capture(txConfigCapture))).andReturn(consistentTx);

    // 3. Open a database
    backingLocker = ctrl.createMock(Locker.class);
    backingStore = ctrl.createMock(KeyColumnValueStore.class);
    expect(backingManager.openDatabase(STORE_NAME)).andReturn(backingStore);
    expect(backingStore.getName()).andReturn(STORE_NAME);
    expect(lockerProvider.getLocker(LOCKER_NAME)).andReturn(backingLocker);

    // Carry out setup behavior against mocks
    ctrl.replay();
    // 1. Construct manager
    expectManager = new ExpectedValueCheckingStoreManager(backingManager, LOCK_SUFFIX, lockerProvider, Duration.ofSeconds(1L));
    // 2. Begin transaction
    expectTx = expectManager.beginTransaction(defaultTxConfig);
    // 3. Open a database
    expectStore = expectManager.openDatabase(STORE_NAME);

    // Verify behavior and reset the mocks for test methods to use
    ctrl.verify();
    ctrl.reset();
}
 
Example 6
Source File: LinkDiscoveryManagerTest.java    From floodlight_with_topoguard with Apache License 2.0 4 votes vote down vote up
@Test
public void testSwitchAdded() throws Exception {
    LinkDiscoveryManager linkDiscovery = getLinkDiscoveryManager();
    Capture<OFMessage> wc;
    Capture<FloodlightContext> fc;
    Set<Short> qPorts;
    OFPhysicalPort ofpp = new OFPhysicalPort();
    ofpp.setName("eth4242");
    ofpp.setPortNumber((short)4242);
    ofpp.setHardwareAddress(HexString.fromHexString("5c:16:c7:00:00:01"));
    ofpp.setCurrentFeatures(0);
    ImmutablePort p1 = ImmutablePort.fromOFPhysicalPort(ofpp);
    IOFSwitch sw1 = createMockSwitch(1L);

    // Set switch map in floodlightProvider.
    Map<Long, IOFSwitch> switches = new HashMap<Long, IOFSwitch>();
    switches.put(1L, sw1);
    getMockFloodlightProvider().setSwitches(switches);

    // Create the set of ports
    List<Short> ports = new ArrayList<Short>();
    for(short p=1; p<=20; ++p) {
        ports.add(p);
    }

    // Set the captures.
    wc = new Capture<OFMessage>(CaptureType.ALL);
    fc = new Capture<FloodlightContext>(CaptureType.ALL);

    // Expect switch to return those ports.
    expect(sw1.getEnabledPortNumbers()).andReturn(ports).anyTimes();
    expect(sw1.getPort(EasyMock.anyShort())).andReturn(p1).anyTimes();
    sw1.write(capture(wc), capture(fc));
    expectLastCall().anyTimes();
    replay(sw1);

    linkDiscovery.switchActivated(sw1.getId());
    verify(sw1);

    qPorts = linkDiscovery.getQuarantinedPorts(sw1.getId());
    assertNotNull(qPorts);
    assertFalse(qPorts.isEmpty());

    Thread.sleep(100);
    qPorts = linkDiscovery.getQuarantinedPorts(sw1.getId());
    assertNotNull(qPorts);
    assertFalse(qPorts.isEmpty());

    Thread.sleep(200);
    qPorts = linkDiscovery.getQuarantinedPorts(sw1.getId());
    assertNotNull(qPorts);
    assertTrue(qPorts.isEmpty());

    // Ensure that through every switch port, an LLDP and BDDP
    // packet was sent out.  Total # of packets = # of ports * 2.
    assertTrue(wc.hasCaptured());
    List<OFMessage> msgList = wc.getValues();
    assertTrue(msgList.size() == ports.size() * 2);
}
 
Example 7
Source File: OFChannelHandlerTest.java    From floodlight_with_topoguard with Apache License 2.0 4 votes vote down vote up
@Before
public void setUp() throws Exception {
    controller = createMock(Controller.class);
    threadPool = createMock(IThreadPoolService.class);
    ctx = createMock(ChannelHandlerContext.class);
    channelStateEvent = createMock(ChannelStateEvent.class);
    channel = createMock(Channel.class);
    messageEvent = createMock(MessageEvent.class);
    exceptionEventCapture = new Capture<ExceptionEvent>(CaptureType.ALL);
    pipeline = createMock(ChannelPipeline.class);
    writeCapture = new Capture<List<OFMessage>>(CaptureType.ALL);
    sw = createMock(IOFSwitch.class);
    seenXids = null;

    // TODO: should mock IDebugCounterService and make sure
    // the expected counters are updated.
    debugCounterService = new DebugCounter();
    Controller.Counters counters =
            new Controller.Counters();
    counters.createCounters(debugCounterService);
    expect(controller.getCounters()).andReturn(counters).anyTimes();
    replay(controller);
    handler = new OFChannelHandler(controller);
    verify(controller);
    reset(controller);

    resetChannel();

    // thread pool is usually not called, so start empty replay
    replay(threadPool);

    // replay controller. Reset it if you need more specific behavior
    replay(controller);

    // replay switch. Reset it if you need more specific behavior
    replay(sw);

    // Mock ctx and channelStateEvent
    expect(ctx.getChannel()).andReturn(channel).anyTimes();
    expect(channelStateEvent.getChannel()).andReturn(channel).anyTimes();
    replay(ctx, channelStateEvent);

    /* Setup an exception event capture on the channel. Right now
     * we only expect exception events to be send up the channel.
     * However, it's easy to extend to other events if we need it
     */
    pipeline.sendUpstream(capture(exceptionEventCapture));
    expectLastCall().anyTimes();
    replay(pipeline);
}
 
Example 8
Source File: MetricCalculatorTest.java    From attic-aurora with Apache License 2.0 4 votes vote down vote up
@Test
public void testRun() {
  FakeClock clock = new FakeClock();
  StatsProvider statsProvider = createMock(StatsProvider.class);
  StatsProvider untracked = createMock(StatsProvider.class);
  MetricCalculatorSettings settings = new MetricCalculatorSettings(
      10000,
      ImmutableSet.of(JOB_UPTIMES, MEDIANS, PLATFORM_UPTIME),
      ImmutableSet.of(JOB_UPTIMES, MEDIANS, PLATFORM_UPTIME));
  StorageTestUtil storageUtil = new StorageTestUtil(this);
  MetricCalculator calculator = new MetricCalculator(
      storageUtil.storage,
      clock,
      settings,
      statsProvider);

  expect(statsProvider.untracked()).andReturn(untracked).anyTimes();

  Capture<String> names = new Capture<>(CaptureType.ALL);
  expect(untracked.makeGauge(EasyMock.capture(names), EasyMock.anyObject()))
      .andReturn(EasyMock.anyObject())
      .anyTimes();

  IScheduledTask task1 = makeTask(ImmutableMap.of(clock.nowMillis() - 1000, PENDING), 0);
  IScheduledTask task2 = makeTask(ImmutableMap.of(clock.nowMillis() - 2000, PENDING), 1);
  IScheduledTask task3 = makeTask(ImmutableMap.of(clock.nowMillis() - 3000, PENDING), 2);
  IScheduledTask task4 = makeTask(ImmutableMap.of(clock.nowMillis() - 4000, PENDING), 3, false);

  clock.advance(Amount.of(10L, Time.SECONDS));
  storageUtil.expectTaskFetch(Query.unscoped(), task1, task2, task3, task4);
  storageUtil.expectOperations();

  control.replay();
  calculator.run();

  Set<String> metricNames = generateMetricNames(
      ImmutableSet.of(task1, task2, task3, task4),
      ImmutableSet.of(PROD_METRICS, NON_PROD_METRICS));

  assertEquals(metricNames, ImmutableSet.copyOf(names.getValues()));
}