當前位置: 首頁>>代碼示例>>Java>>正文


Java PowerMock.replayAll方法代碼示例

本文整理匯總了Java中org.powermock.api.easymock.PowerMock.replayAll方法的典型用法代碼示例。如果您正苦於以下問題:Java PowerMock.replayAll方法的具體用法?Java PowerMock.replayAll怎麽用?Java PowerMock.replayAll使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.powermock.api.easymock.PowerMock的用法示例。


在下文中一共展示了PowerMock.replayAll方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testSourceTasks

import org.powermock.api.easymock.PowerMock; //導入方法依賴的package包/類
@Test
public void testSourceTasks() {
    PowerMock.replayAll();

    connector.start(sourceProperties);
    List<Map<String, String>> taskConfigs = connector.taskConfigs(1);
    assertEquals(1, taskConfigs.size());
    assertEquals(FILENAME,
            taskConfigs.get(0).get(FileStreamSourceConnector.FILE_CONFIG));
    assertEquals(SINGLE_TOPIC,
            taskConfigs.get(0).get(FileStreamSourceConnector.TOPIC_CONFIG));

    // Should be able to return fewer than requested #
    taskConfigs = connector.taskConfigs(2);
    assertEquals(1, taskConfigs.size());
    assertEquals(FILENAME,
            taskConfigs.get(0).get(FileStreamSourceConnector.FILE_CONFIG));
    assertEquals(SINGLE_TOPIC,
            taskConfigs.get(0).get(FileStreamSourceConnector.TOPIC_CONFIG));

    PowerMock.verifyAll();
}
 
開發者ID:wngn123,項目名稱:wngn-jms-kafka,代碼行數:23,代碼來源:FileStreamSourceConnectorTest.java

示例2: testCancelAfterAwaitFlush

import org.powermock.api.easymock.PowerMock; //導入方法依賴的package包/類
@Test
public void testCancelAfterAwaitFlush() throws Exception {
    @SuppressWarnings("unchecked")
    Callback<Void> callback = PowerMock.createMock(Callback.class);
    CountDownLatch allowStoreCompleteCountdown = new CountDownLatch(1);
    // In this test, the write should be cancelled so the callback will not be invoked and is not
    // passed to the expectStore call
    expectStore(OFFSET_KEY, OFFSET_KEY_SERIALIZED, OFFSET_VALUE, OFFSET_VALUE_SERIALIZED, null, false, allowStoreCompleteCountdown);

    PowerMock.replayAll();

    writer.offset(OFFSET_KEY, OFFSET_VALUE);
    assertTrue(writer.beginFlush());
    // Start the flush, then immediately cancel before allowing the mocked store request to finish
    Future<Void> flushFuture = writer.doFlush(callback);
    writer.cancelFlush();
    allowStoreCompleteCountdown.countDown();
    flushFuture.get(1000, TimeUnit.MILLISECONDS);

    PowerMock.verifyAll();
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:22,代碼來源:OffsetStorageWriterTest.java

示例3: testCreateConnectorAlreadyExists

import org.powermock.api.easymock.PowerMock; //導入方法依賴的package包/類
@Test
public void testCreateConnectorAlreadyExists() throws Exception {
    connector = PowerMock.createMock(BogusSourceConnector.class);
    // First addition should succeed
    expectAdd(SourceSink.SOURCE);

    Map<String, String> config = connectorConfig(SourceSink.SOURCE);
    Connector connectorMock = PowerMock.createMock(Connector.class);
    expectConfigValidation(connectorMock, true, config, config);

    EasyMock.expect(worker.getPlugins()).andReturn(plugins).times(2);
    EasyMock.expect(plugins.compareAndSwapLoaders(connectorMock)).andReturn(delegatingLoader);
    // No new connector is created
    EasyMock.expect(Plugins.compareAndSwapLoaders(delegatingLoader)).andReturn(pluginLoader);
    // Second should fail
    createCallback.onCompletion(EasyMock.<AlreadyExistsException>anyObject(), EasyMock.<Herder.Created<ConnectorInfo>>isNull());
    PowerMock.expectLastCall();

    PowerMock.replayAll();

    herder.putConnectorConfig(CONNECTOR_NAME, config, false, createCallback);
    herder.putConnectorConfig(CONNECTOR_NAME, config, false, createCallback);

    PowerMock.verifyAll();
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:26,代碼來源:StandaloneHerderTest.java

示例4: testDownloadFileWithNonExistingFile

import org.powermock.api.easymock.PowerMock; //導入方法依賴的package包/類
@Test
public void testDownloadFileWithNonExistingFile() throws IOException {
  IllegalArgumentException expectedException = new IllegalArgumentException();
  MockHttpServletRequest request = new MockHttpServletRequest(DOWNLOAD_URL +
      "file/1234/" + FORM1_QUALIFIED_NAME + "1");
  String nonExistentFile = FORM1_QUALIFIED_NAME + "1";
  expect(exporterMock.exportFile(USER_ID, PROJECT_ID, nonExistentFile))
      .andThrow(expectedException);
  PowerMock.replayAll();
  DownloadServlet download = new DownloadServlet();
  try {
    download.doGet(request, new MockHttpServletResponse());
    fail();
  } catch (IllegalArgumentException ex) {
    assertEquals(expectedException, ex);
  }
  PowerMock.verifyAll();
  }
 
開發者ID:mit-cml,項目名稱:appinventor-extensions,代碼行數:19,代碼來源:DownloadServletTest.java

示例5: testLoadAndStoreProjectSettings

import org.powermock.api.easymock.PowerMock; //導入方法依賴的package包/類
@Test
public void testLoadAndStoreProjectSettings() throws Exception {
  // Since only USER_ID_ONE is used in this test, we don't care how
  // many times getUser or getUserId are called; they'll always
  // return the same result
  expect(localUserMock.getUserId()).andReturn(USER_ID_ONE).anyTimes();
  expect(localUserMock.getUser()).andReturn(storageIo.getUser(USER_ID_ONE, USER_EMAIL_ONE)).anyTimes();
  PowerMock.replayAll();
  do_init();

  NewYoungAndroidProjectParameters params = new NewYoungAndroidProjectParameters(
      PACKAGE_BASE + PROJECT1_NAME);
  long projectId = projectServiceImpl.newProject(
      YoungAndroidProjectNode.YOUNG_ANDROID_PROJECT_TYPE, PROJECT1_NAME, params).getProjectId();

  String loadedSettings = projectServiceImpl.loadProjectSettings(projectId);
  assertEquals(
      "{\"" + SettingsConstants.PROJECT_YOUNG_ANDROID_SETTINGS + "\":" +
      "{\"" + SettingsConstants.YOUNG_ANDROID_SETTINGS_ICON + "\":\"\",\"" +
      SettingsConstants.YOUNG_ANDROID_SETTINGS_VERSION_CODE + "\":\"1\",\"" +
      SettingsConstants.YOUNG_ANDROID_SETTINGS_VERSION_NAME + "\":\"1.0\",\"" +
      SettingsConstants.YOUNG_ANDROID_SETTINGS_USES_LOCATION + "\":\"false\",\"" +
      SettingsConstants.YOUNG_ANDROID_SETTINGS_APP_NAME + "\":\"Project1\",\"" +
      SettingsConstants.YOUNG_ANDROID_SETTINGS_SIZING + "\":\"Fixed\",\"" +
      SettingsConstants.YOUNG_ANDROID_SETTINGS_SHOW_LISTS_AS_JSON + "\":\"false\",\"" +
      SettingsConstants.YOUNG_ANDROID_SETTINGS_TUTORIAL_URL + "\":\"\"}}",
      loadedSettings);

  String storedSettings =
      "{\"" + SettingsConstants.PROJECT_YOUNG_ANDROID_SETTINGS + "\":" +
      "{\"" + SettingsConstants.YOUNG_ANDROID_SETTINGS_ICON + "\":\"KittyIcon.png\"}}";
  projectServiceImpl.storeProjectSettings("test-session", projectId, storedSettings);
  loadedSettings = projectServiceImpl.loadProjectSettings(projectId);
  assertEquals(storedSettings, loadedSettings);
  PowerMock.verifyAll();
}
 
開發者ID:mit-cml,項目名稱:appinventor-extensions,代碼行數:37,代碼來源:ProjectServiceTest.java

示例6: testNoOffsetsToFlush

import org.powermock.api.easymock.PowerMock; //導入方法依賴的package包/類
@Test
public void testNoOffsetsToFlush() {
    // If no offsets are flushed, we should finish immediately and not have made any calls to the
    // underlying storage layer

    PowerMock.replayAll();

    // Should not return a future
    assertFalse(writer.beginFlush());

    PowerMock.verifyAll();
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:13,代碼來源:OffsetStorageWriterTest.java

示例7: testRestartConnectorFailureOnStart

import org.powermock.api.easymock.PowerMock; //導入方法依賴的package包/類
@Test
public void testRestartConnectorFailureOnStart() throws Exception {
    expectAdd(SourceSink.SOURCE);

    Map<String, String> config = connectorConfig(SourceSink.SOURCE);
    expectConfigValidation(config);

    worker.stopConnector(CONNECTOR_NAME);
    EasyMock.expectLastCall().andReturn(true);

    worker.startConnector(EasyMock.eq(CONNECTOR_NAME), EasyMock.eq(config),
            EasyMock.anyObject(HerderConnectorContext.class), EasyMock.eq(herder), EasyMock.eq(TargetState.STARTED));
    EasyMock.expectLastCall().andReturn(false);

    PowerMock.replayAll();

    herder.putConnectorConfig(CONNECTOR_NAME, config, false, createCallback);

    FutureCallback<Void> cb = new FutureCallback<>();
    herder.restartConnector(CONNECTOR_NAME, cb);
    try {
        cb.get(1000L, TimeUnit.MILLISECONDS);
        fail();
    } catch (ExecutionException exception) {
        assertEquals(ConnectException.class, exception.getCause().getClass());
    }

    PowerMock.verifyAll();
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:30,代碼來源:StandaloneHerderTest.java

示例8: whenFindAllCalledThenExpectRepositoryToReturnAllBotConfigs

import org.powermock.api.easymock.PowerMock; //導入方法依賴的package包/類
@Test
public void whenFindAllCalledThenExpectRepositoryToReturnAllBotConfigs() throws Exception {

    expect(ConfigurationManager.loadConfig(
            eq(BotsType.class),
            eq(BOTS_CONFIG_XML_FILENAME),
            eq(BOTS_CONFIG_XSD_FILENAME))).
            andReturn(allTheInternalBotsConfig());

    PowerMock.replayAll();

    final BotConfigRepository botConfigRepository = new BotConfigRepositoryXmlDatastore();
    final List<BotConfig> botConfigItems = botConfigRepository.findAll();

    assertThat(botConfigItems.size()).isEqualTo(2);

    assertThat(botConfigItems.get(0).getId()).isEqualTo(BOT_1_ID);
    assertThat(botConfigItems.get(0).getAlias()).isEqualTo(BOT_1_ALIAS);
    assertThat(botConfigItems.get(0).getBaseUrl()).isEqualTo(BOT_1_BASE_URL);
    assertThat(botConfigItems.get(0).getUsername()).isEqualTo(BOT_1_USERNAME);
    assertThat(botConfigItems.get(0).getPassword()).isEqualTo(BOT_1_PASSWORD);

    assertThat(botConfigItems.get(1).getId()).isEqualTo(BOT_2_ID);
    assertThat(botConfigItems.get(1).getAlias()).isEqualTo(BOT_2_ALIAS);
    assertThat(botConfigItems.get(1).getBaseUrl()).isEqualTo(BOT_2_BASE_URL);
    assertThat(botConfigItems.get(1).getUsername()).isEqualTo(BOT_2_USERNAME);
    assertThat(botConfigItems.get(1).getPassword()).isEqualTo(BOT_2_PASSWORD);

    PowerMock.verifyAll();
}
 
開發者ID:gazbert,項目名稱:bxbot-ui-server,代碼行數:31,代碼來源:TestBotConfigRepository.java

示例9: testCancelBeforeAwaitFlush

import org.powermock.api.easymock.PowerMock; //導入方法依賴的package包/類
@Test
public void testCancelBeforeAwaitFlush() {
    PowerMock.replayAll();

    writer.offset(OFFSET_KEY, OFFSET_VALUE);
    assertTrue(writer.beginFlush());
    writer.cancelFlush();

    PowerMock.verifyAll();
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:11,代碼來源:OffsetStorageWriterTest.java

示例10: testJoinLeaderCannotAssign

import org.powermock.api.easymock.PowerMock; //導入方法依賴的package包/類
@Test
public void testJoinLeaderCannotAssign() {
    // If the selected leader can't get up to the maximum offset, it will fail to assign and we should immediately
    // need to retry the join.

    // When the first round fails, we'll take an updated config snapshot
    EasyMock.expect(configStorage.snapshot()).andReturn(configState1);
    EasyMock.expect(configStorage.snapshot()).andReturn(configState2);

    PowerMock.replayAll();

    final String memberId = "member";

    client.prepareResponse(groupCoordinatorResponse(node, Errors.NONE));
    coordinator.ensureCoordinatorReady();

    // config mismatch results in assignment error
    client.prepareResponse(joinGroupFollowerResponse(1, memberId, "leader", Errors.NONE));
    MockClient.RequestMatcher matcher = new MockClient.RequestMatcher() {
        @Override
        public boolean matches(AbstractRequest body) {
            SyncGroupRequest sync = (SyncGroupRequest) body;
            return sync.memberId().equals(memberId) &&
                    sync.generationId() == 1 &&
                    sync.groupAssignment().isEmpty();
        }
    };
    client.prepareResponse(matcher, syncGroupResponse(ConnectProtocol.Assignment.CONFIG_MISMATCH, "leader", 10L,
            Collections.<String>emptyList(), Collections.<ConnectorTaskId>emptyList(), Errors.NONE));
    client.prepareResponse(joinGroupFollowerResponse(1, memberId, "leader", Errors.NONE));
    client.prepareResponse(matcher, syncGroupResponse(ConnectProtocol.Assignment.NO_ERROR, "leader", 1L,
            Collections.<String>emptyList(), Collections.singletonList(taskId1x0), Errors.NONE));
    coordinator.ensureActiveGroup();

    PowerMock.verifyAll();
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:37,代碼來源:WorkerCoordinatorTest.java

示例11: testSourceTasksStdin

import org.powermock.api.easymock.PowerMock; //導入方法依賴的package包/類
@Test
public void testSourceTasksStdin() {
    PowerMock.replayAll();

    sourceProperties.remove(FileStreamSourceConnector.FILE_CONFIG);
    connector.start(sourceProperties);
    List<Map<String, String>> taskConfigs = connector.taskConfigs(1);
    assertEquals(1, taskConfigs.size());
    assertNull(taskConfigs.get(0).get(FileStreamSourceConnector.FILE_CONFIG));

    PowerMock.verifyAll();
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:13,代碼來源:FileStreamSourceConnectorTest.java

示例12: testDoFilterShouldContinueFilterChainIfNotWhitelisted

import org.powermock.api.easymock.PowerMock; //導入方法依賴的package包/類
@Test
public void testDoFilterShouldContinueFilterChainIfNotWhitelisted() throws Exception {

  final AtomicInteger isUserWhitelistedCounter = new AtomicInteger(0);
  expect(localUserMock.getUserTosAccepted()).andReturn(true).times(1);

  // This is the key expectation, i.e. that we continue by calling the doFilter method of the
  // internal mocked FilterChain that will be passed into the tested FilterChain
  mockFilterChain.doFilter(mockServletRequest, mockServletResponse);
  EasyMock.expectLastCall().once();
  PowerMock.replayAll();

  // Here's where we say that the whitelist is not active
  OdeAuthFilter.useWhitelist.setForTest(false);

  OdeAuthFilter myAuthFilter = new OdeAuthFilter() {
    @Override
    void setUserFromUserId(String userId, boolean isAdmin, boolean isReadOnly) { localUserMock.set(new User("1", "NonSuch", "NoName", null, 0, false, false, 0, null)); return;}
    @Override
    void removeUser() {}
    @Override
    boolean isUserWhitelisted() {
      isUserWhitelistedCounter.incrementAndGet();
      return false;
    }
  };

  myAuthFilter.doMyFilter(localUserInfo, false, false, mockServletRequest, mockServletResponse, mockFilterChain);

  // isUserWhitelisted should not have been called.
  assertEquals(0, isUserWhitelistedCounter.get());
  // getUserTosAccepted should have been called once.
  PowerMock.verifyAll();
}
 
開發者ID:mit-cml,項目名稱:appinventor-extensions,代碼行數:35,代碼來源:OdeAuthFilterTest.java

示例13: testRebalanceFailedConnector

import org.powermock.api.easymock.PowerMock; //導入方法依賴的package包/類
@Test
public void testRebalanceFailedConnector() throws Exception {
    // Join group and get assignment
    EasyMock.expect(member.memberId()).andStubReturn("member");
    EasyMock.expect(worker.getPlugins()).andReturn(plugins);
    expectRebalance(1, Arrays.asList(CONN1), Arrays.asList(TASK1));
    expectPostRebalanceCatchup(SNAPSHOT);
    worker.startConnector(EasyMock.eq(CONN1), EasyMock.<Map<String, String>>anyObject(), EasyMock.<ConnectorContext>anyObject(),
            EasyMock.eq(herder), EasyMock.eq(TargetState.STARTED));
    PowerMock.expectLastCall().andReturn(true);
    EasyMock.expect(worker.isRunning(CONN1)).andReturn(true);
    EasyMock.expect(worker.connectorTaskConfigs(CONN1, MAX_TASKS, null)).andReturn(TASK_CONFIGS);
    worker.startTask(EasyMock.eq(TASK1), EasyMock.<Map<String, String>>anyObject(), EasyMock.<Map<String, String>>anyObject(),
            EasyMock.eq(herder), EasyMock.eq(TargetState.STARTED));
    PowerMock.expectLastCall().andReturn(true);
    member.poll(EasyMock.anyInt());
    PowerMock.expectLastCall();

    expectRebalance(Arrays.asList(CONN1), Arrays.asList(TASK1), ConnectProtocol.Assignment.NO_ERROR,
            1, Arrays.asList(CONN1), Arrays.<ConnectorTaskId>asList());

    // and the new assignment started
    worker.startConnector(EasyMock.eq(CONN1), EasyMock.<Map<String, String>>anyObject(), EasyMock.<ConnectorContext>anyObject(),
            EasyMock.eq(herder), EasyMock.eq(TargetState.STARTED));
    PowerMock.expectLastCall().andReturn(true);
    EasyMock.expect(worker.isRunning(CONN1)).andReturn(false);

    // worker is not running, so we should see no call to connectorTaskConfigs()

    member.poll(EasyMock.anyInt());
    PowerMock.expectLastCall();

    PowerMock.replayAll();

    herder.tick();
    herder.tick();

    PowerMock.verifyAll();
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:40,代碼來源:DistributedHerderTest.java

示例14: testSourceTasks

import org.powermock.api.easymock.PowerMock; //導入方法依賴的package包/類
@Test
public void testSourceTasks() {
  PowerMock.replayAll();
  connector.start(buildSourceProperties());
  List<Map<String, String>> taskConfigs = connector.taskConfigs(1);
  Assert.assertEquals(1, taskConfigs.size());
  Assert.assertEquals("nats", taskConfigs.get(0).get("topic"));
  Assert.assertEquals("POST", taskConfigs.get(0).get("nats.subject"));
  Assert.assertEquals("nats://localhost:4222", taskConfigs.get(0).get("nats.url"));
  Assert.assertEquals("nats-queue", taskConfigs.get(0).get("nats.queue.group"));
  PowerMock.verifyAll();
}
 
開發者ID:oystparis,項目名稱:kafka-connect-nats,代碼行數:13,代碼來源:NatsSourceConnectorTest.java

示例15: testRestartUnknownTask

import org.powermock.api.easymock.PowerMock; //導入方法依賴的package包/類
@Test
public void testRestartUnknownTask() throws Exception {
    // get the initial assignment
    EasyMock.expect(member.memberId()).andStubReturn("member");
    expectRebalance(1, Collections.<String>emptyList(), Collections.<ConnectorTaskId>emptyList());
    expectPostRebalanceCatchup(SNAPSHOT);
    member.poll(EasyMock.anyInt());
    PowerMock.expectLastCall();

    member.wakeup();
    PowerMock.expectLastCall();
    member.ensureActive();
    PowerMock.expectLastCall();
    member.poll(EasyMock.anyInt());
    PowerMock.expectLastCall();

    PowerMock.replayAll();

    FutureCallback<Void> callback = new FutureCallback<>();
    herder.tick();
    herder.restartTask(new ConnectorTaskId("blah", 0), callback);
    herder.tick();

    try {
        callback.get(1000L, TimeUnit.MILLISECONDS);
        fail("Expected NotLeaderException to be raised");
    } catch (ExecutionException e) {
        assertTrue(e.getCause() instanceof NotFoundException);
    }

    PowerMock.verifyAll();
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:33,代碼來源:DistributedHerderTest.java


注:本文中的org.powermock.api.easymock.PowerMock.replayAll方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。