Java Code Examples for org.easymock.EasyMock.createNiceMock()

The following are Jave code examples for showing how to use createNiceMock() of the org.easymock.EasyMock class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: apache-tomcat-7.0.73-with-comment   File: TestJNDIRealm.java   Source Code and License Vote up 7 votes
private NamingEnumeration<SearchResult> mockSearchResults(String password)
        throws NamingException {
    @SuppressWarnings("unchecked")
    NamingEnumeration<SearchResult> searchResults =
    EasyMock.createNiceMock(NamingEnumeration.class);
    EasyMock.expect(Boolean.valueOf(searchResults.hasMore()))
            .andReturn(Boolean.TRUE)
            .andReturn(Boolean.FALSE)
            .andReturn(Boolean.TRUE)
            .andReturn(Boolean.FALSE);
    EasyMock.expect(searchResults.next())
            .andReturn(new SearchResult("ANY RESULT", "",
                    new BasicAttributes(USER_PASSWORD_ATTR, password)))
            .times(2);
    EasyMock.replay(searchResults);
    return searchResults;
}
 
Example 2
Project: cruise-control   File: AnomalyDetectorTest.java   Source Code and License Vote up 6 votes
@Test
public void testShutdown() throws InterruptedException {
  AnomalyNotifier mockAnomalyNotifier = EasyMock.createNiceMock(AnomalyNotifier.class);
  BrokerFailureDetector mockBrokerFailureDetector = EasyMock.createNiceMock(BrokerFailureDetector.class);
  GoalViolationDetector mockGoalViolationDetector = EasyMock.createNiceMock(GoalViolationDetector.class);
  KafkaCruiseControl mockKafkaCruiseControl = EasyMock.createNiceMock(KafkaCruiseControl.class);
  ScheduledExecutorService detectorScheduler =
      Executors.newScheduledThreadPool(2, new KafkaCruiseControlThreadFactory("AnomalyDetector", false, null));

  AnomalyDetector anomalyDetector = new AnomalyDetector(new LinkedBlockingDeque<>(), 3000L, mockKafkaCruiseControl,
                                                        mockAnomalyNotifier, mockGoalViolationDetector,
                                                        mockBrokerFailureDetector, detectorScheduler);

  anomalyDetector.shutdown();
  Thread t = new Thread(anomalyDetector::shutdown);
  t.start();
  t.join(30000L);
  assertTrue(detectorScheduler.isTerminated());
}
 
Example 3
Project: dhus-core   File: TestArchiveService.java   Source Code and License Vote up 6 votes
@Test
public void testSynchronizeLocalArchive ()
      throws DataStoreLocalArchiveNotExistingException, InterruptedException
{
   int expected = 5;
   ProductService mock = EasyMock.createNiceMock (ProductService.class);
   EasyMock.expect (mock.processArchiveSync ()).andReturn (expected);
   EasyMock.replay (mock);

   archiveService.setDefaultDataStore (mock);
   int result = archiveService.synchronizeLocalArchive ();
   Assert.assertEquals (result, expected);

   expected = -1;
   mock = EasyMock.createNiceMock (ProductService.class);
   EasyMock.expect (mock.processArchiveSync ()).andThrow (
         new InterruptedException ());
   EasyMock.replay (mock);
   archiveService.setDefaultDataStore (mock);
   result = archiveService.synchronizeLocalArchive ();
   Assert.assertEquals (result, expected);
}
 
Example 4
Project: iTAP-controller   File: MockOFSwitchImpl.java   Source Code and License Vote up 6 votes
@SuppressWarnings("unchecked")
@Override
public <REPLY extends OFStatsReply> ListenableFuture<List<REPLY>> writeStatsRequest(OFStatsRequest<REPLY> request) {
    ListenableFuture<List<REPLY>> ofStatsFuture =
            EasyMock.createNiceMock(ListenableFuture.class);

    // We create a mock future and return info from the map
    try {
        OFStatsType statsType = request.getStatsType();
        List<REPLY> replies = (List<REPLY>) statsMap.get(statsType);
        EasyMock.expect(ofStatsFuture.get(EasyMock.anyLong(),
                EasyMock.anyObject(TimeUnit.class))).andReturn(replies).anyTimes();
        EasyMock.expect(ofStatsFuture.get()).andReturn(replies).anyTimes();
        EasyMock.replay(ofStatsFuture);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return ofStatsFuture;
}
 
Example 5
Project: ms-gs-plugins   File: BoundsUpdateTransactionListenerTest.java   Source Code and License Vote up 6 votes
/**
 * Issues a fake dataStoreChange insert event that affects two tile layers: "theLayer" and
 * "theGroup"
 */
private void issueInsert(Map<Object, Object> extendedProperties,
        ReferencedEnvelope affectedBounds) {
    
    TransactionType transaction = EasyMock.createNiceMock(TransactionType.class);
    EasyMock.expect(transaction.getExtendedProperties()).andStubReturn(extendedProperties);
    
    TransactionEvent event = EasyMock.createNiceMock(TransactionEvent.class);
    
    EasyMock.expect(event.getRequest()).andStubReturn(transaction);
    
    EasyMock.expect(event.getLayerName()).andStubReturn(featureTypeQName1);
    
    InsertElementType insert = EasyMock.createNiceMock(InsertElementType.class);
    
    EasyMock.expect(event.getSource()).andStubReturn(insert);
    EasyMock.expect(event.getType()).andStubReturn(TransactionEventType.PRE_INSERT);
    
    SimpleFeatureCollection affectedFeatures = EasyMock.createNiceMock(SimpleFeatureCollection.class);
    EasyMock.expect(affectedFeatures.getBounds()).andStubReturn(affectedBounds);
    EasyMock.expect(event.getAffectedFeatures()).andStubReturn(affectedFeatures);
    EasyMock.replay(transaction, event, insert, affectedFeatures);
    listener.dataStoreChange(event);
}
 
Example 6
Project: kafka-connect-fs   File: FsSourceTaskTestBase.java   Source Code and License Vote up 5 votes
@Test
public void exceptionExecutingPolicy() throws InterruptedException, IOException, IllegalAccessException {
    Map<String, String> props = new HashMap<>(taskConfig);
    task.start(props);

    Policy policy = EasyMock.createNiceMock(Policy.class);
    EasyMock.expect(policy.hasEnded()).andReturn(Boolean.FALSE);
    EasyMock.expect(policy.execute()).andThrow(new ConnectException("Exception from mock"));
    EasyMock.expect(policy.getURIs()).andReturn(null);
    EasyMock.checkOrder(policy, false);
    EasyMock.replay(policy);
    MemberModifier.field(FsSourceTask.class, "policy").set(task, policy);

    assertEquals(0, task.poll().size());
}
 
Example 7
Project: iTAP-controller   File: OFSwitchBaseTest.java   Source Code and License Vote up 5 votes
@Before
public void setUp() throws Exception {

    // Build our test packet
    IDebugCounterService debugCounter = new DebugCounterServiceImpl();
    switchManager = createMock(IOFSwitchManager.class);
    SwitchManagerCounters counters = new SwitchManagerCounters(debugCounter);

    expect(switchManager.getCounters()).andReturn(counters).anyTimes();
    replay(switchManager);

    factory = OFFactories.getFactory(OFVersion.OF_13);

    testMessage = factory.buildRoleReply()
            .setXid(1)
            .setRole(OFControllerRole.ROLE_MASTER)
            .build();

    IOFConnectionBackend conn = EasyMock.createNiceMock(IOFConnectionBackend.class);
    capturedMessage = new Capture<OFMessage>();
    conn.write(EasyMock.capture(capturedMessage));
    expectLastCall().anyTimes();
    expect(conn.getOFFactory()).andReturn(factory).anyTimes();
    expect(conn.getAuxId()).andReturn(OFAuxId.MAIN).anyTimes();
    EasyMock.replay(conn);

    IOFConnectionBackend auxConn = EasyMock.createNiceMock(IOFConnectionBackend.class);
    expect(auxConn.getOFFactory()).andReturn(factory).anyTimes();
    expect(auxConn.getAuxId()).andReturn(OFAuxId.of(1)).anyTimes();
    EasyMock.replay(auxConn);

    sw = new OFSwitchTest(conn, switchManager);
    sw.registerConnection(auxConn);
    sw.setControllerRole(OFControllerRole.ROLE_MASTER); /* must supply role now, otherwise write() will be blocked if not master/equal/other */

    switches = new ConcurrentHashMap<DatapathId, IOFSwitchBackend>();
    switches.put(sw.getId(), sw);
    reset(switchManager);
    //expect(switchManager.getSwitch(sw.getId())).andReturn(sw).anyTimes();
}
 
Example 8
Project: tomcat7   File: TestJNDIRealm.java   Source Code and License Vote up 5 votes
private DirContext mockDirContext(NamingEnumeration<SearchResult> namingEnumeration)
        throws NamingException {
    DirContext dirContext = EasyMock.createNiceMock(InitialDirContext.class);
    EasyMock.expect(dirContext.search(EasyMock.anyString(), EasyMock.anyString(),
                    EasyMock.anyObject(SearchControls.class)))
            .andReturn(namingEnumeration)
            .times(2);
    EasyMock.expect(dirContext.getNameParser(""))
            .andReturn(new NameParserImpl()).times(2);
    EasyMock.expect(dirContext.getNameInNamespace())
            .andReturn("ANY NAME")
            .times(2);
    EasyMock.replay(dirContext);
    return dirContext;
}
 
Example 9
Project: apache-tomcat-7.0.73-with-comment   File: TestJNDIRealm.java   Source Code and License Vote up 5 votes
private DirContext mockDirContext(NamingEnumeration<SearchResult> namingEnumeration)
        throws NamingException {
    DirContext dirContext = EasyMock.createNiceMock(InitialDirContext.class);
    EasyMock.expect(dirContext.search(EasyMock.anyString(), EasyMock.anyString(),
                    EasyMock.anyObject(SearchControls.class)))
            .andReturn(namingEnumeration)
            .times(2);
    EasyMock.expect(dirContext.getNameParser(""))
            .andReturn(new NameParserImpl()).times(2);
    EasyMock.expect(dirContext.getNameInNamespace())
            .andReturn("ANY NAME")
            .times(2);
    EasyMock.replay(dirContext);
    return dirContext;
}
 
Example 10
Project: intellij-deps-ini4j   File: OptionsParserTest.java   Source Code and License Vote up 5 votes
@Test public void testBad() throws Exception
{
    OptionsParser parser = new OptionsParser();
    OptionsHandler handler = EasyMock.createNiceMock(OptionsHandler.class);

    try
    {
        parser.parse(new ByteArrayInputStream(NONAME.getBytes()), handler);
        missing(InvalidFileFormatException.class);
    }
    catch (InvalidFileFormatException x)
    {
        //
    }
}
 
Example 11
Project: ms-gs-plugins   File: BoundsUpdateTransactionListenerTest.java   Source Code and License Vote up 5 votes
@Test
public void testDataStoreChangeDoesNotPropagateExceptions() {
    TransactionEvent event = EasyMock.createNiceMock(TransactionEvent.class);
    EasyMock.expect(event.getSource()).andStubThrow(new RuntimeException("This exception should be eaten to prevent the transaction from failing"));
    EasyMock.replay(catalog, featureType1, featureType2, event);
    
    listener.dataStoreChange(event);
    
    EasyMock.verify(catalog, featureType1, featureType2, event);
}
 
Example 12
Project: athena   File: IsisChannelHandlerTest.java   Source Code and License Vote up 5 votes
@Before
public void setUp() throws Exception {
    controller = EasyMock.createNiceMock(Controller.class);
    isisProcess = EasyMock.createNiceMock(IsisProcess.class);
    channelHandlerContext = EasyMock.createNiceMock(ChannelHandlerContext.class);
    channelStateEvent = EasyMock.createNiceMock(ChannelStateEvent.class);
    exceptionEvent = EasyMock.createNiceMock(ExceptionEvent.class);
    messageEvent = EasyMock.createNiceMock(MessageEvent.class);
    isisMessage = EasyMock.createNiceMock(L1L2HelloPdu.class);
    isisMessage.setInterfaceIndex(2);
    isisChannelHandler = new IsisChannelHandler(controller, isisProcessList);
}
 
Example 13
Project: athena   File: DefaultIsisControllerTest.java   Source Code and License Vote up 5 votes
@Before
public void setUp() throws Exception {
    defaultIsisController = new DefaultIsisController();
    mapper = new ObjectMapper();
    jsonNode = mapper.readTree(jsonString);
    isisRouterListener = EasyMock.createNiceMock(IsisRouterListener.class);
}
 
Example 14
Project: cruise-control   File: AnomalyDetectorTest.java   Source Code and License Vote up 4 votes
@Test
public void testDelayedCheck() throws InterruptedException, KafkaCruiseControlException {
  LinkedBlockingDeque<Anomaly> anomalies = new LinkedBlockingDeque<>();
  AnomalyNotifier mockAnomalyNotifier = EasyMock.mock(AnomalyNotifier.class);
  BrokerFailureDetector mockBrokerFailureDetector = EasyMock.createNiceMock(BrokerFailureDetector.class);
  GoalViolationDetector mockGoalViolationDetector = EasyMock.createNiceMock(GoalViolationDetector.class);
  ScheduledExecutorService mockDetectorScheduler = EasyMock.mock(ScheduledExecutorService.class);
  ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
  KafkaCruiseControl mockKafkaCruiseControl = EasyMock.mock(KafkaCruiseControl.class);

  EasyMock.expect(mockAnomalyNotifier.onBrokerFailure(EasyMock.isA(BrokerFailures.class)))
         .andReturn(AnomalyNotificationResult.check(1000L));

  // Starting periodic goal violation detection.
  EasyMock.expect(mockDetectorScheduler.scheduleAtFixedRate(EasyMock.eq(mockGoalViolationDetector),
                                                            EasyMock.anyLong(),
                                                            EasyMock.eq(3000L),
                                                            EasyMock.eq(TimeUnit.MILLISECONDS)))
          .andReturn(null);

  // Starting anomaly handler
  EasyMock.expect(mockDetectorScheduler.submit(EasyMock.isA(AnomalyDetector.AnomalyHandlerTask.class)))
          .andDelegateTo(executorService);
  // Schedule a delayed check
  EasyMock.expect(mockDetectorScheduler.schedule(EasyMock.isA(Runnable.class),
                                                 EasyMock.eq(1000L),
                                                 EasyMock.eq(TimeUnit.MILLISECONDS)))
          .andReturn(null);
  mockDetectorScheduler.shutdown();
  EasyMock.expectLastCall().andDelegateTo(executorService);
  EasyMock.expect(mockDetectorScheduler.awaitTermination(3000L, TimeUnit.MILLISECONDS)).andDelegateTo(executorService);
  EasyMock.expect(mockDetectorScheduler.isTerminated()).andDelegateTo(executorService);

  // The following state are used to test the delayed check when executor is busy.
  EasyMock.expect(mockKafkaCruiseControl.state())
          .andReturn(new KafkaCruiseControlState(ExecutorState.noTaskInProgress(), null, null));

  EasyMock.replay(mockAnomalyNotifier);
  EasyMock.replay(mockBrokerFailureDetector);
  EasyMock.replay(mockGoalViolationDetector);
  EasyMock.replay(mockDetectorScheduler);
  EasyMock.replay(mockKafkaCruiseControl);

  AnomalyDetector anomalyDetector = new AnomalyDetector(anomalies, 3000L, mockKafkaCruiseControl, mockAnomalyNotifier,
                                                        mockGoalViolationDetector, mockBrokerFailureDetector,
                                                        mockDetectorScheduler);

  try {
    anomalyDetector.startDetection();
    anomalies.add(new BrokerFailures(Collections.singletonMap(0, 100L)));
    while (!anomalies.isEmpty()) {
      // just wait for the anomalies to be drained.
    }
    anomalyDetector.shutdown();
    assertTrue(executorService.awaitTermination(5000, TimeUnit.MILLISECONDS));
    EasyMock.verify(mockAnomalyNotifier, mockDetectorScheduler, mockKafkaCruiseControl);
  } finally {
    executorService.shutdown();
  }
}
 
Example 15
Project: cruise-control   File: AnomalyDetectorTest.java   Source Code and License Vote up 4 votes
@Test
public void testFix() throws InterruptedException, KafkaCruiseControlException {
  LinkedBlockingDeque<Anomaly> anomalies = new LinkedBlockingDeque<>();
  AnomalyNotifier mockAnomalyNotifier = EasyMock.mock(AnomalyNotifier.class);
  BrokerFailureDetector mockBrokerFailureDetector = EasyMock.createNiceMock(BrokerFailureDetector.class);
  GoalViolationDetector mockGoalViolationDetector = EasyMock.createNiceMock(GoalViolationDetector.class);
  ScheduledExecutorService mockDetectorScheduler = EasyMock.mock(ScheduledExecutorService.class);
  ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
  KafkaCruiseControl mockKafkaCruiseControl = EasyMock.mock(KafkaCruiseControl.class);

  EasyMock.expect(mockAnomalyNotifier.onGoalViolation(EasyMock.isA(GoalViolations.class)))
          .andReturn(AnomalyNotificationResult.fix());

  // Starting periodic goal violation detection.
  EasyMock.expect(mockDetectorScheduler.scheduleAtFixedRate(EasyMock.eq(mockGoalViolationDetector),
                                                            EasyMock.anyLong(),
                                                            EasyMock.eq(3000L),
                                                            EasyMock.eq(TimeUnit.MILLISECONDS)))
          .andReturn(null);

  // Starting anomaly handler
  EasyMock.expect(mockDetectorScheduler.submit(EasyMock.isA(AnomalyDetector.AnomalyHandlerTask.class)))
          .andDelegateTo(executorService);

  mockDetectorScheduler.shutdown();
  EasyMock.expectLastCall().andDelegateTo(executorService);
  EasyMock.expect(mockDetectorScheduler.awaitTermination(3000L, TimeUnit.MILLISECONDS)).andDelegateTo(executorService);
  EasyMock.expect(mockDetectorScheduler.isTerminated()).andDelegateTo(executorService);

  // The following state are used to test the delayed check when executor is busy.
  EasyMock.expect(mockKafkaCruiseControl.state())
          .andReturn(new KafkaCruiseControlState(ExecutorState.noTaskInProgress(), null, null));
  EasyMock.expect(mockKafkaCruiseControl.rebalance(Collections.emptyList(), false, null))
          .andReturn(null);

  EasyMock.replay(mockAnomalyNotifier);
  EasyMock.replay(mockBrokerFailureDetector);
  EasyMock.replay(mockGoalViolationDetector);
  EasyMock.replay(mockDetectorScheduler);
  EasyMock.replay(mockKafkaCruiseControl);

  AnomalyDetector anomalyDetector = new AnomalyDetector(anomalies, 3000L, mockKafkaCruiseControl, mockAnomalyNotifier,
                                                        mockGoalViolationDetector, mockBrokerFailureDetector,
                                                        mockDetectorScheduler);

  try {
    anomalyDetector.startDetection();
    anomalies.add(new GoalViolations());
    while (!anomalies.isEmpty()) {
      // Just wait for the anomalies to be drained.
    }
    anomalyDetector.shutdown();
    assertTrue(executorService.awaitTermination(5000, TimeUnit.MILLISECONDS));
    EasyMock.verify(mockAnomalyNotifier, mockDetectorScheduler, mockKafkaCruiseControl);
  } finally {
    executorService.shutdown();
  }
}
 
Example 16
Project: iTAP-controller   File: ACLTest.java   Source Code and License Vote up 4 votes
@Override
@Before
public void setUp() throws Exception {

	super.setUp();
	cntx = new FloodlightContext();
	mockFloodlightProvider = getMockFloodlightProvider();
	mockSwitchManager = getMockSwitchService();

	debugEventService = new MockDebugEventService();
	entityClassifier = new DefaultEntityClassifier();
	tps = new MockThreadPoolService();
	deviceManager = new MockDeviceManager();
	topology = createMock(ITopologyService.class);
	debugCounterService = new MockDebugCounterService();
	storageService = new MemoryStorageSource();
	restApi = new RestApiServer();
	acl = new ACL();

	// Mock switches
	DatapathId dpid = DatapathId.of(TestSwitch1DPID);
	sw = EasyMock.createNiceMock(IOFSwitch.class);
	expect(sw.getId()).andReturn(dpid).anyTimes();
	expect(sw.getOFFactory()).andReturn(
			OFFactories.getFactory(OFVersion.OF_13)).anyTimes();
	replay(sw);
	// Load the switch map
	Map<DatapathId, IOFSwitch> switches = new HashMap<DatapathId, IOFSwitch>();
	switches.put(dpid, sw);
	mockSwitchManager.setSwitches(switches);

	FloodlightModuleContext fmc = new FloodlightModuleContext();
	fmc.addService(IFloodlightProviderService.class, mockFloodlightProvider);
	fmc.addService(IOFSwitchService.class, mockSwitchManager);
	fmc.addService(IDebugCounterService.class, debugCounterService);
	fmc.addService(IStorageSourceService.class, storageService);
	fmc.addService(IDebugEventService.class, debugEventService);
	fmc.addService(IEntityClassifierService.class, entityClassifier);
	fmc.addService(IThreadPoolService.class, tps);
	fmc.addService(IDeviceService.class, deviceManager);
	fmc.addService(ITopologyService.class, topology);
	fmc.addService(IRestApiService.class, restApi);
	fmc.addService(IACLService.class, acl);

	topology.addListener(deviceManager);
	expectLastCall().times(1);
	replay(topology);
	
	debugCounterService.init(fmc);
	entityClassifier.init(fmc);
	tps.init(fmc);
	deviceManager.init(fmc);
	storageService.init(fmc);
	restApi.init(fmc);
	acl.init(fmc);
	
	debugCounterService.startUp(fmc);
	deviceManager.startUp(fmc);
	entityClassifier.startUp(fmc);
	tps.startUp(fmc);
	storageService.startUp(fmc);
	acl.startUp(fmc);
	verify(topology);

	storageService.createTable(StaticFlowEntryPusher.TABLE_NAME, null);
	storageService.setTablePrimaryKeyName(StaticFlowEntryPusher.TABLE_NAME,
			StaticFlowEntryPusher.COLUMN_NAME);

}
 
Example 17
Project: athena   File: DefaultIsisProcessTest.java   Source Code and License Vote up 4 votes
@Before
public void setUp() throws Exception {
    isisProcess = new DefaultIsisProcess();
    isisInterface = EasyMock.createNiceMock(DefaultIsisInterface.class);
    defaultIsisProcess = new DefaultIsisProcess();
}
 
Example 18
Project: ms-gs-plugins   File: BoundsUpdateTransactionListenerTest.java   Source Code and License Vote up 4 votes
@Test
public void testAfterTransactionLayerGroupRecursive() throws Exception {
    Map<Object, Object> extendedProperties = new HashMap<Object, Object>();
    ReferencedEnvelope affectedBounds1 = new ReferencedEnvelope(-180, 0, 0, 90, WGS84);
    ReferencedEnvelope affectedBounds2 = new ReferencedEnvelope(0, 180, 0, 90, WGS84);
    ReferencedEnvelope oldBounds = new ReferencedEnvelope(-90, 0, 0, 45, WGS84);
    ReferencedEnvelope newBounds = new ReferencedEnvelope(oldBounds);
    newBounds.expandToInclude(affectedBounds1);
    newBounds.expandToInclude(affectedBounds2);
    
    EasyMock.expect(catalog.getFeatureTypeByName(featureTypeName1)).andStubReturn(featureType1);
    EasyMock.expect(featureType1.getNativeBoundingBox()).andStubReturn(oldBounds);
    
    LayerInfo layer = mockLayer(featureType1, "layer");
    LayerInfo otherLayer = mockLayer(featureType2, "otherLayer");
    
    List<LayerGroupInfo> groups = new ArrayList<>();
    
    LayerGroupInfo direct = mockGroup("direct", oldBounds, otherLayer, layer);
    direct.setBounds(EasyMock.eq(newBounds));EasyMock.expectLastCall().once(); 
    catalog.save(direct);EasyMock.expectLastCall().once();
    groups.add(direct);
    
    LayerGroupInfo indirect1 = mockGroup("indirect1", oldBounds, otherLayer, direct);
    indirect1.setBounds(EasyMock.eq(newBounds));EasyMock.expectLastCall().once(); 
    catalog.save(indirect1);EasyMock.expectLastCall().once();
    groups.add(indirect1);
    
    LayerGroupInfo indirect2 = mockGroup("indirect2", oldBounds, otherLayer, indirect1);
    indirect2.setBounds(EasyMock.eq(newBounds));EasyMock.expectLastCall().once(); 
    catalog.save(indirect2);EasyMock.expectLastCall().once();
    groups.add(indirect2);
    
    mockLayerGroupList(groups);
    
    // Verify the FT is updated
    featureType1.setNativeBoundingBox(EasyMock.eq(newBounds));EasyMock.expectLastCall().once(); 
    catalog.save(featureType1);EasyMock.expectLastCall().once();

    
    EasyMock.replay(catalog, featureType1, featureType2, layer, otherLayer);
    groups.forEach(EasyMock::replay);
    
    issueInsert(extendedProperties, affectedBounds1);
    
    issueInsert(extendedProperties, affectedBounds2);
    
    TransactionType request = EasyMock.createNiceMock(TransactionType.class);
    TransactionResponseType result = EasyMock.createNiceMock(TransactionResponseType.class);
    EasyMock.expect(request.getExtendedProperties()).andReturn(extendedProperties);
    EasyMock.replay(request, result);
    
    listener.afterTransaction(request, result, true);
    
    ReferencedEnvelope expectedEnv = new ReferencedEnvelope(affectedBounds1);
    expectedEnv.expandToInclude(affectedBounds2);
    
    EasyMock.verify(catalog, featureType1, featureType2, request, result, layer, otherLayer);
    groups.forEach(EasyMock::verify);
    
}
 
Example 19
Project: googles-monorepo-demo   File: RateLimiterTest.java   Source Code and License Vote up 4 votes
@AndroidIncompatible // EasyMock Class Extension doesn't appear to work on Android.
public void testMockingEasyMock() throws Exception {
  RateLimiter mock = EasyMock.createNiceMock(RateLimiter.class);
  EasyMock.replay(mock);
  doTestMocking(mock);
}
 
Example 20
Project: ms-gs-plugins   File: BoundsUpdateTransactionListenerTest.java   Source Code and License Vote up 4 votes
@Test
public void testAfterTransactionLayerGroup() throws Exception {
    Map<Object, Object> extendedProperties = new HashMap<Object, Object>();
    ReferencedEnvelope affectedBounds1 = new ReferencedEnvelope(-180, 0, 0, 90, WGS84);
    ReferencedEnvelope affectedBounds2 = new ReferencedEnvelope(0, 180, 0, 90, WGS84);
    ReferencedEnvelope oldBounds = new ReferencedEnvelope(-90, 0, 0, 45, WGS84);
    ReferencedEnvelope newBounds = new ReferencedEnvelope(oldBounds);
    newBounds.expandToInclude(affectedBounds1);
    newBounds.expandToInclude(affectedBounds2);
    
    EasyMock.expect(catalog.getFeatureTypeByName(featureTypeName1)).andStubReturn(featureType1);
    EasyMock.expect(featureType1.getNativeBoundingBox()).andStubReturn(oldBounds);
    
    LayerInfo layer = mockLayer(featureType1, "layer");
    LayerInfo otherLayer = mockLayer(featureType2, "otherLayer");
    
    List<LayerGroupInfo> groups = new ArrayList<>();
    
    LayerGroupInfo direct = mockGroup("direct", oldBounds, otherLayer, layer);
    direct.setBounds(EasyMock.eq(newBounds));EasyMock.expectLastCall().once(); 
    catalog.save(direct);EasyMock.expectLastCall().once();
    groups.add(direct);
    
    LayerGroupInfo directRoot = mockGroup("directRoot", oldBounds, layer, otherLayer);
    directRoot.setBounds(EasyMock.eq(newBounds));EasyMock.expectLastCall().once(); 
    catalog.save(directRoot);EasyMock.expectLastCall().once();
    groups.add(directRoot);
    
    LayerGroupInfo unaffected = mockGroup("unaffected", oldBounds, null, otherLayer);
    groups.add(unaffected);
    
    mockLayerGroupList(groups);
    
    // Verify the FT is updated
    featureType1.setNativeBoundingBox(EasyMock.eq(newBounds));EasyMock.expectLastCall().once(); 
    catalog.save(featureType1);EasyMock.expectLastCall().once();

    
    EasyMock.replay(catalog, featureType1, featureType2, layer, otherLayer);
    groups.forEach(EasyMock::replay);
    
    issueInsert(extendedProperties, affectedBounds1);
    
    issueInsert(extendedProperties, affectedBounds2);
    
    TransactionType request = EasyMock.createNiceMock(TransactionType.class);
    TransactionResponseType result = EasyMock.createNiceMock(TransactionResponseType.class);
    EasyMock.expect(request.getExtendedProperties()).andReturn(extendedProperties);
    EasyMock.replay(request, result);
    
    listener.afterTransaction(request, result, true);
    
    ReferencedEnvelope expectedEnv = new ReferencedEnvelope(affectedBounds1);
    expectedEnv.expandToInclude(affectedBounds2);
    
    EasyMock.verify(catalog, featureType1, featureType2, request, result, layer, otherLayer);
    groups.forEach(EasyMock::verify);
    
}