本文整理汇总了Java中org.easymock.Capture.newInstance方法的典型用法代码示例。如果您正苦于以下问题:Java Capture.newInstance方法的具体用法?Java Capture.newInstance怎么用?Java Capture.newInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.easymock.Capture
的用法示例。
在下文中一共展示了Capture.newInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRestartTaskLeaderRedirect
import org.easymock.Capture; //导入方法依赖的package包/类
@Test
public void testRestartTaskLeaderRedirect() throws Throwable {
ConnectorTaskId taskId = new ConnectorTaskId(CONNECTOR_NAME, 0);
final Capture<Callback<Void>> cb = Capture.newInstance();
herder.restartTask(EasyMock.eq(taskId), EasyMock.capture(cb));
expectAndCallbackNotLeaderException(cb);
EasyMock.expect(RestServer.httpRequest(EasyMock.eq("http://leader:8083/connectors/" + CONNECTOR_NAME + "/tasks/0/restart?forward=true"),
EasyMock.eq("POST"), EasyMock.isNull(), EasyMock.<TypeReference>anyObject()))
.andReturn(new RestServer.HttpResponse<>(202, new HashMap<String, List<String>>(), null));
PowerMock.replayAll();
connectorsResource.restartTask(CONNECTOR_NAME, 0, null);
PowerMock.verifyAll();
}
示例2: testRestartTaskOwnerRedirect
import org.easymock.Capture; //导入方法依赖的package包/类
@Test
public void testRestartTaskOwnerRedirect() throws Throwable {
ConnectorTaskId taskId = new ConnectorTaskId(CONNECTOR_NAME, 0);
final Capture<Callback<Void>> cb = Capture.newInstance();
herder.restartTask(EasyMock.eq(taskId), EasyMock.capture(cb));
String ownerUrl = "http://owner:8083";
expectAndCallbackException(cb, new NotAssignedException("not owner test", ownerUrl));
EasyMock.expect(RestServer.httpRequest(EasyMock.eq("http://owner:8083/connectors/" + CONNECTOR_NAME + "/tasks/0/restart?forward=false"),
EasyMock.eq("POST"), EasyMock.isNull(), EasyMock.<TypeReference>anyObject()))
.andReturn(new RestServer.HttpResponse<>(202, new HashMap<String, List<String>>(), null));
PowerMock.replayAll();
connectorsResource.restartTask(CONNECTOR_NAME, 0, true);
PowerMock.verifyAll();
}
示例3: testDispatchAction_withMiddleWare_shouldTriggerMiddleWareAndChangeState
import org.easymock.Capture; //导入方法依赖的package包/类
@Test
public void testDispatchAction_withMiddleWare_shouldTriggerMiddleWareAndChangeState() {
//GIVEN
Middleware<Integer> mockMiddleWare = createStrictMock(Middleware.class);
final Action<Integer> action = createStrictMock(Action.class);
Store<Integer> store = new Store<>(0, mockMiddleWare);
Capture<Middleware.Chain<Integer>> capturedChain = Capture.newInstance();
mockMiddleWare.intercept(capture(capturedChain));
expectLastCall()
.andAnswer(
() -> {
final Middleware.Chain<Integer> chain =
(Middleware.Chain<Integer>) getCurrentArguments()[0];
chain.proceed(chain.action());
return null;
});
expect(action.newState(0)).andReturn(1);
replay(mockMiddleWare, action);
//WHEN
store.dispatch(action);
//THEN
verify(mockMiddleWare, action);
assertThat(capturedChain.getValue().action(), is(action));
assertThat(store.getState(), is(1));
}
示例4: testDispatchAction_withMiddleWares_shouldTriggerMiddleWareAndChangeStateUsingNewAction
import org.easymock.Capture; //导入方法依赖的package包/类
@Test
public void
testDispatchAction_withMiddleWares_shouldTriggerMiddleWareAndChangeStateUsingNewAction() {
//GIVEN
Middleware<Integer> mockMiddleWare = createMock(Middleware.class);
final Action<Integer> action = createMock(Action.class);
Store<Integer> store = new Store<>(0, mockMiddleWare);
Capture<Middleware.Chain<Integer>> capturedChain = Capture.newInstance();
mockMiddleWare.intercept(capture(capturedChain));
expectLastCall()
.andAnswer(
() -> {
final Middleware.Chain<Integer> chain =
(Middleware.Chain<Integer>) getCurrentArguments()[0];
final Action<Integer> decrementAction = integer -> integer - 1;
chain.proceed(decrementAction);
return null;
});
replay(mockMiddleWare, action);
//WHEN
store.dispatch(action);
//THEN
verify(mockMiddleWare, action);
assertThat(store.getState(), is(-1));
}
示例5: testCorruptConfig
import org.easymock.Capture; //导入方法依赖的package包/类
@Test
public void testCorruptConfig() {
Map<String, String> config = new HashMap<>();
config.put(ConnectorConfig.NAME_CONFIG, CONNECTOR_NAME);
config.put(ConnectorConfig.CONNECTOR_CLASS_CONFIG, BogusSinkConnector.class.getName());
Connector connectorMock = PowerMock.createMock(Connector.class);
String error = "This is an error in your config!";
List<String> errors = new ArrayList<>(singletonList(error));
String key = "foo.invalid.key";
EasyMock.expect(connectorMock.validate(config)).andReturn(
new Config(
Arrays.asList(new ConfigValue(key, null, Collections.emptyList(), errors))
)
);
ConfigDef configDef = new ConfigDef();
configDef.define(key, ConfigDef.Type.STRING, ConfigDef.Importance.HIGH, "");
EasyMock.expect(worker.getPlugins()).andReturn(plugins).times(3);
EasyMock.expect(plugins.compareAndSwapLoaders(connectorMock)).andReturn(delegatingLoader);
EasyMock.expect(worker.getPlugins()).andStubReturn(plugins);
EasyMock.expect(plugins.newConnector(EasyMock.anyString())).andReturn(connectorMock);
EasyMock.expect(connectorMock.config()).andStubReturn(configDef);
EasyMock.expect(Plugins.compareAndSwapLoaders(delegatingLoader)).andReturn(pluginLoader);
Callback<Herder.Created<ConnectorInfo>> callback = PowerMock.createMock(Callback.class);
Capture<BadRequestException> capture = Capture.newInstance();
callback.onCompletion(
EasyMock.capture(capture), EasyMock.isNull(Herder.Created.class)
);
PowerMock.replayAll();
herder.putConnectorConfig(CONNECTOR_NAME, config, true, callback);
assertEquals(
capture.getValue().getMessage(),
"Connector configuration is invalid and contains the following 1 error(s):\n" +
error + "\n" +
"You can also find the above list of errors at the endpoint `/{connectorType}/config/validate`"
);
PowerMock.verifyAll();
}
示例6: testGetConnectorTaskConfigs
import org.easymock.Capture; //导入方法依赖的package包/类
@Test
public void testGetConnectorTaskConfigs() throws Throwable {
final Capture<Callback<List<TaskInfo>>> cb = Capture.newInstance();
herder.taskConfigs(EasyMock.eq(CONNECTOR_NAME), EasyMock.capture(cb));
expectAndCallbackResult(cb, TASK_INFOS);
PowerMock.replayAll();
List<TaskInfo> taskInfos = connectorsResource.getTaskConfigs(CONNECTOR_NAME, FORWARD);
assertEquals(TASK_INFOS, taskInfos);
PowerMock.verifyAll();
}
示例7: testPutConnectorTaskConfigs
import org.easymock.Capture; //导入方法依赖的package包/类
@Test
public void testPutConnectorTaskConfigs() throws Throwable {
final Capture<Callback<Void>> cb = Capture.newInstance();
herder.putTaskConfigs(EasyMock.eq(CONNECTOR_NAME), EasyMock.eq(TASK_CONFIGS), EasyMock.capture(cb));
expectAndCallbackResult(cb, null);
PowerMock.replayAll();
connectorsResource.putTaskConfigs(CONNECTOR_NAME, FORWARD, TASK_CONFIGS);
PowerMock.verifyAll();
}
示例8: testCreateConnectorExists
import org.easymock.Capture; //导入方法依赖的package包/类
@Test(expected = AlreadyExistsException.class)
public void testCreateConnectorExists() throws Throwable {
CreateConnectorRequest body = new CreateConnectorRequest(CONNECTOR_NAME, Collections.singletonMap(ConnectorConfig.NAME_CONFIG, CONNECTOR_NAME));
final Capture<Callback<Herder.Created<ConnectorInfo>>> cb = Capture.newInstance();
herder.putConnectorConfig(EasyMock.eq(CONNECTOR_NAME), EasyMock.eq(body.config()), EasyMock.eq(false), EasyMock.capture(cb));
expectAndCallbackException(cb, new AlreadyExistsException("already exists"));
PowerMock.replayAll();
connectorsResource.createConnector(FORWARD, body);
PowerMock.verifyAll();
}
示例9: testRestartConnectorNotFound
import org.easymock.Capture; //导入方法依赖的package包/类
@Test(expected = NotFoundException.class)
public void testRestartConnectorNotFound() throws Throwable {
final Capture<Callback<Void>> cb = Capture.newInstance();
herder.restartConnector(EasyMock.eq(CONNECTOR_NAME), EasyMock.capture(cb));
expectAndCallbackException(cb, new NotFoundException("not found"));
PowerMock.replayAll();
connectorsResource.restartConnector(CONNECTOR_NAME, FORWARD);
PowerMock.verifyAll();
}
示例10: testRestartConnectorLeaderRedirect
import org.easymock.Capture; //导入方法依赖的package包/类
@Test
public void testRestartConnectorLeaderRedirect() throws Throwable {
final Capture<Callback<Void>> cb = Capture.newInstance();
herder.restartConnector(EasyMock.eq(CONNECTOR_NAME), EasyMock.capture(cb));
expectAndCallbackNotLeaderException(cb);
EasyMock.expect(RestServer.httpRequest(EasyMock.eq("http://leader:8083/connectors/" + CONNECTOR_NAME + "/restart?forward=true"),
EasyMock.eq("POST"), EasyMock.isNull(), EasyMock.<TypeReference>anyObject()))
.andReturn(new RestServer.HttpResponse<>(202, new HashMap<String, List<String>>(), null));
PowerMock.replayAll();
connectorsResource.restartConnector(CONNECTOR_NAME, null);
PowerMock.verifyAll();
}
示例11: testPutConnectorConfig
import org.easymock.Capture; //导入方法依赖的package包/类
@Test
public void testPutConnectorConfig() throws Throwable {
final Capture<Callback<Herder.Created<ConnectorInfo>>> cb = Capture.newInstance();
herder.putConnectorConfig(EasyMock.eq(CONNECTOR_NAME), EasyMock.eq(CONNECTOR_CONFIG), EasyMock.eq(true), EasyMock.capture(cb));
expectAndCallbackResult(cb, new Herder.Created<>(false, new ConnectorInfo(CONNECTOR_NAME, CONNECTOR_CONFIG, CONNECTOR_TASK_NAMES)));
PowerMock.replayAll();
connectorsResource.putConnectorConfig(CONNECTOR_NAME, FORWARD, CONNECTOR_CONFIG);
PowerMock.verifyAll();
}
示例12: testRestartTaskNotFound
import org.easymock.Capture; //导入方法依赖的package包/类
@Test(expected = NotFoundException.class)
public void testRestartTaskNotFound() throws Throwable {
ConnectorTaskId taskId = new ConnectorTaskId(CONNECTOR_NAME, 0);
final Capture<Callback<Void>> cb = Capture.newInstance();
herder.restartTask(EasyMock.eq(taskId), EasyMock.capture(cb));
expectAndCallbackException(cb, new NotFoundException("not found"));
PowerMock.replayAll();
connectorsResource.restartTask(CONNECTOR_NAME, 0, FORWARD);
PowerMock.verifyAll();
}
示例13: testGetConnectorConfig
import org.easymock.Capture; //导入方法依赖的package包/类
@Test
public void testGetConnectorConfig() throws Throwable {
final Capture<Callback<Map<String, String>>> cb = Capture.newInstance();
herder.connectorConfig(EasyMock.eq(CONNECTOR_NAME), EasyMock.capture(cb));
expectAndCallbackResult(cb, CONNECTOR_CONFIG);
PowerMock.replayAll();
Map<String, String> connConfig = connectorsResource.getConnectorConfig(CONNECTOR_NAME, FORWARD);
assertEquals(CONNECTOR_CONFIG, connConfig);
PowerMock.verifyAll();
}
示例14: testGetConnectorConfigConnectorNotFound
import org.easymock.Capture; //导入方法依赖的package包/类
@Test(expected = NotFoundException.class)
public void testGetConnectorConfigConnectorNotFound() throws Throwable {
final Capture<Callback<Map<String, String>>> cb = Capture.newInstance();
herder.connectorConfig(EasyMock.eq(CONNECTOR_NAME), EasyMock.capture(cb));
expectAndCallbackException(cb, new NotFoundException("not found"));
PowerMock.replayAll();
connectorsResource.getConnectorConfig(CONNECTOR_NAME, FORWARD);
PowerMock.verifyAll();
}
示例15: setup
import org.easymock.Capture; //导入方法依赖的package包/类
@Before
public void setup() throws Exception {
super.setup();
contentType = Capture.newInstance();
}