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

The following are Jave code examples for showing how to use replay() 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: dubbocloud   File: ExceptionFilterTest.java   Source Code and License Vote up 6 votes
@SuppressWarnings("unchecked")
@Test
public void testRpcException() {
    Logger logger = EasyMock.createMock(Logger.class);
    RpcContext.getContext().setRemoteAddress("127.0.0.1", 1234);
    RpcException exception = new RpcException("TestRpcException");
    logger.error(EasyMock.eq("Got unchecked and undeclared exception which called by 127.0.0.1. service: " + DemoService.class.getName() + ", method: sayHello, exception: " + RpcException.class.getName() + ": TestRpcException"), EasyMock.eq(exception));
    ExceptionFilter exceptionFilter = new ExceptionFilter(logger);
    RpcInvocation invocation = new RpcInvocation("sayHello", new Class<?>[]{String.class}, new Object[]{"world"});
    Invoker<DemoService> invoker = EasyMock.createMock(Invoker.class);
    EasyMock.expect(invoker.getInterface()).andReturn(DemoService.class);
    EasyMock.expect(invoker.invoke(EasyMock.eq(invocation))).andThrow(exception);
    
    EasyMock.replay(logger, invoker);
    
    try {
        exceptionFilter.invoke(invoker, invocation);
    } catch (RpcException e) {
        assertEquals("TestRpcException", e.getMessage());
    }
    EasyMock.verify(logger, invoker);
    RpcContext.removeContext();
}
 
Example 2
Project: EatDubbo   File: FailSafeClusterInvokerTest.java   Source Code and License Vote up 6 votes
@Test()
public void testNoInvoke() {
    dic = EasyMock.createMock(Directory.class);
    
    EasyMock.expect(dic.getUrl()).andReturn(url).anyTimes();
    EasyMock.expect(dic.list(invocation)).andReturn(null).anyTimes();
    EasyMock.expect(dic.getInterface()).andReturn(DemoService.class).anyTimes();
    
    invocation.setMethodName("method1");
    EasyMock.replay(dic);
    
    resetInvokerToNoException();
    
    FailsafeClusterInvoker<DemoService> invoker = new FailsafeClusterInvoker<DemoService>(dic);
    LogUtil.start();
    invoker.invoke(invocation);
    assertTrue(LogUtil.findMessage("No provider") > 0);
    LogUtil.stop();
}
 
Example 3
Project: dubbocloud   File: FailoverClusterInvokerTest.java   Source Code and License Vote up 6 votes
@Test()
public void testInvokeWithRPCException() {
    
    EasyMock.reset(invoker1);
    EasyMock.expect(invoker1.invoke(invocation)).andThrow(new RpcException()).anyTimes();
    EasyMock.expect(invoker1.isAvailable()).andReturn(true).anyTimes();
    EasyMock.expect(invoker1.getUrl()).andReturn(url).anyTimes();
    EasyMock.expect(invoker1.getInterface()).andReturn(FailoverClusterInvokerTest.class).anyTimes();
    EasyMock.replay(invoker1);
    
    EasyMock.reset(invoker2);
    EasyMock.expect(invoker2.invoke(invocation)).andReturn(result).anyTimes();
    EasyMock.expect(invoker2.isAvailable()).andReturn(true).anyTimes();
    EasyMock.expect(invoker2.getUrl()).andReturn(url).anyTimes();
    EasyMock.expect(invoker2.getInterface()).andReturn(FailoverClusterInvokerTest.class).anyTimes();
    EasyMock.replay(invoker2);
    
    FailoverClusterInvoker<FailoverClusterInvokerTest> invoker = new FailoverClusterInvoker<FailoverClusterInvokerTest>(dic);
    for(int i=0;i<100;i++){
        Result ret = invoker.invoke(invocation);
        assertSame(result, ret);
    }
}
 
Example 4
Project: dubbox-hystrix   File: FailfastClusterInvokerTest.java   Source Code and License Vote up 6 votes
@Test()
public void testNoInvoke() {
    dic = EasyMock.createMock(Directory.class);
    
    EasyMock.expect(dic.getUrl()).andReturn(url).anyTimes();
    EasyMock.expect(dic.list(invocation)).andReturn(null).anyTimes();
    EasyMock.expect(dic.getInterface()).andReturn(FailfastClusterInvokerTest.class).anyTimes();
    
    invocation.setMethodName("method1");
    EasyMock.replay(dic);
    
    invokers.add(invoker1);
    
    resetInvoker1ToNoException();
    
    FailfastClusterInvoker<FailfastClusterInvokerTest> invoker = new FailfastClusterInvoker<FailfastClusterInvokerTest>(dic);
    try {
        invoker.invoke(invocation);
        fail();
    } catch (RpcException expected) {
        assertFalse(expected.getCause() instanceof RpcException);
    }
}
 
Example 5
Project: intellij-deps-ini4j   File: OptionsParserTest.java   Source Code and License Vote up 6 votes
@Test public void testEmptyOption() throws Exception
{
    OptionsParser parser = new OptionsParser();
    OptionsHandler handler = EasyMock.createMock(OptionsHandler.class);

    handler.startOptions();
    handler.handleOption(OPTION, null);
    handler.endOptions();
    EasyMock.replay(handler);
    Config cfg = new Config();

    cfg.setEmptyOption(true);
    parser.setConfig(cfg);
    parser.parse(new StringReader(CFG_EMPTY_OPTION), handler);
    EasyMock.verify(handler);
}
 
Example 6
Project: EatDubbo   File: CompatibleFilterFilterTest.java   Source Code and License Vote up 6 votes
@Test
public void testInvokerNonJsonPojoSerialization() {
    invocation = EasyMock.createMock(Invocation.class);
    EasyMock.expect(invocation.getMethodName()).andReturn("echo").anyTimes();
    EasyMock.expect(invocation.getParameterTypes()).andReturn(new Class<?>[] { String.class }).anyTimes();
    EasyMock.expect(invocation.getArguments()).andReturn(new Object[] { "hello" }).anyTimes();
    EasyMock.replay(invocation);
    invoker = EasyMock.createMock(Invoker.class);
    EasyMock.expect(invoker.isAvailable()).andReturn(true).anyTimes();
    EasyMock.expect(invoker.getInterface()).andReturn(DemoService.class).anyTimes();
    RpcResult result = new RpcResult();
    result.setValue("hello");
    EasyMock.expect(invoker.invoke(invocation)).andReturn(result).anyTimes();
    URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1");
    EasyMock.expect(invoker.getUrl()).andReturn(url).anyTimes();
    EasyMock.replay(invoker);
    Result filterResult = compatibleFilter.invoke(invoker, invocation);
    assertEquals("hello", filterResult.getValue());
}
 
Example 7
Project: github-test   File: ForkingClusterInvokerTest.java   Source Code and License Vote up 6 votes
private void resetInvokerToNoException() {
    EasyMock.reset(invoker1);
    EasyMock.expect(invoker1.invoke(invocation)).andReturn(result).anyTimes();
    EasyMock.expect(invoker1.getUrl()).andReturn(url).anyTimes();
    EasyMock.expect(invoker1.isAvailable()).andReturn(true).anyTimes();
    EasyMock.expect(invoker1.getInterface()).andReturn(ForkingClusterInvokerTest.class).anyTimes();
    EasyMock.replay(invoker1);
    EasyMock.reset(invoker2);
    EasyMock.expect(invoker2.invoke(invocation)).andReturn(result).anyTimes();
    EasyMock.expect(invoker2.getUrl()).andReturn(url).anyTimes();
    EasyMock.expect(invoker2.isAvailable()).andReturn(true).anyTimes();
    EasyMock.expect(invoker2.getInterface()).andReturn(ForkingClusterInvokerTest.class).anyTimes();
    EasyMock.replay(invoker2);
    EasyMock.reset(invoker3);
    EasyMock.expect(invoker3.invoke(invocation)).andReturn(result).anyTimes();
    EasyMock.expect(invoker3.getUrl()).andReturn(url).anyTimes();
    EasyMock.expect(invoker3.isAvailable()).andReturn(true).anyTimes();
    EasyMock.expect(invoker3.getInterface()).andReturn(ForkingClusterInvokerTest.class).anyTimes();
    EasyMock.replay(invoker3);
}
 
Example 8
Project: dubbox-hystrix   File: ListTelnetHandlerTest.java   Source Code and License Vote up 5 votes
@SuppressWarnings("unchecked")
@Test
public void testListService() throws RemotingException {
    mockInvoker = EasyMock.createMock(Invoker.class);
    EasyMock.expect(mockInvoker.getInterface()).andReturn(DemoService.class).anyTimes();
    EasyMock.expect(mockInvoker.getUrl()).andReturn(URL.valueOf("dubbo://127.0.0.1:20885/demo")).anyTimes();
    EasyMock.expect(mockInvoker.invoke((Invocation) EasyMock.anyObject())).andReturn(new RpcResult("ok")).anyTimes();
    mockChannel = EasyMock.createMock(Channel.class);
    EasyMock.expect(mockChannel.getAttribute("telnet.service")).andReturn("com.alibaba.dubbo.rpc.protocol.dubbo.support.DemoService").anyTimes();
    EasyMock.replay(mockChannel, mockInvoker);
    DubboProtocol.getDubboProtocol().export(mockInvoker);
    String result = list.telnet(mockChannel, "DemoService");
    assertEquals(methodsName, result);
    EasyMock.reset(mockChannel, mockInvoker);
}
 
Example 9
Project: dubbocloud   File: AbstractClusterInvokerTest.java   Source Code and License Vote up 5 votes
@Test
public void testCloseAvailablecheck(){
    LoadBalance lb = EasyMock.createMock(LoadBalance.class);
    EasyMock.expect(lb.select(invokers, url, invocation)).andReturn(invoker1);
    EasyMock.replay(lb);
    initlistsize5();
    
    Invoker sinvoker = cluster_nocheck.select(lb, invocation, invokers, selectedInvokers);
    Assert.assertEquals(false,sinvoker.isAvailable());
    Assert.assertEquals(invoker1,sinvoker);
    
}
 
Example 10
Project: EatDubbo   File: FailSafeClusterInvokerTest.java   Source Code and License Vote up 5 votes
/**
 * @throws java.lang.Exception
 */

@Before
public void setUp() throws Exception {
    
    dic = EasyMock.createMock(Directory.class);
    
    EasyMock.expect(dic.getUrl()).andReturn(url).anyTimes();
    EasyMock.expect(dic.list(invocation)).andReturn(invokers).anyTimes();
    EasyMock.expect(dic.getInterface()).andReturn(DemoService.class).anyTimes();
    invocation.setMethodName("method1");
    EasyMock.replay(dic);
    
    invokers.add(invoker);
}
 
Example 11
Project: dubbox-hystrix   File: InvokerTelnetHandlerTest.java   Source Code and License Vote up 5 votes
@Test
public void testMessageNull() throws RemotingException {
    mockChannel = EasyMock.createMock(Channel.class);
    EasyMock.expect(mockChannel.getAttribute("telnet.service")).andReturn(null).anyTimes();
    EasyMock.replay(mockChannel);
    String result = invoke.telnet(mockChannel, null);
    assertEquals("Please input method name, eg: \r\ninvoke xxxMethod(1234, \"abcd\", {\"prop\" : \"value\"})\r\ninvoke XxxService.xxxMethod(1234, \"abcd\", {\"prop\" : \"value\"})\r\ninvoke com.xxx.XxxService.xxxMethod(1234, \"abcd\", {\"prop\" : \"value\"})",
                 result);
    EasyMock.reset(mockChannel);
}
 
Example 12
Project: intellij-deps-ini4j   File: IniFormatterTest.java   Source Code and License Vote up 5 votes
@Test public void testWithoutConfig() throws Exception
{
    Ini ini = new Ini();
    Ini.Section sec = ini.add(Dwarfs.PROP_BASHFUL);

    sec.put(Dwarf.PROP_FORTUNE_NUMBER, null);
    IniHandler handler = EasyMock.createMock(IniHandler.class);

    handler.startIni();
    handler.startSection(Dwarfs.PROP_BASHFUL);
    handler.endSection();
    handler.endIni();
    EasyMock.replay(handler);
    verify(ini, handler);
}
 
Example 13
Project: dubbo2   File: LogTelnetHandlerTest.java   Source Code and License Vote up 5 votes
@Test
public void testChangeLogLevel() throws RemotingException {
    mockChannel = EasyMock.createMock(Channel.class);
    EasyMock.replay(mockChannel);
    String result = log.telnet(mockChannel, "error");
    assertTrue(result.contains("\r\nCURRENT LOG LEVEL:ERROR"));
    String result2 = log.telnet(mockChannel, "warn");
    assertTrue(result2.contains("\r\nCURRENT LOG LEVEL:WARN"));
    EasyMock.reset(mockChannel);
}
 
Example 14
Project: ms-gs-plugins   File: BoundsUpdateTransactionListenerTest.java   Source Code and License Vote up 5 votes
@Test
public void testNoInteractionsInUnusedMethods() {
    TransactionType request = EasyMock.createNiceMock(TransactionType.class);
    EasyMock.replay(catalog, featureType1, featureType2, request);
    
    TransactionType returned = listener.beforeTransaction(request);
    Assert.assertThat(returned, Matchers.sameInstance(request));
    listener.beforeCommit(request);
    
    EasyMock.verify(catalog, featureType1, featureType2, request);
}
 
Example 15
Project: EatDubbo   File: ListTelnetHandlerTest.java   Source Code and License Vote up 5 votes
@SuppressWarnings("unchecked")
@Test
public void testList() throws RemotingException {
    mockInvoker = EasyMock.createMock(Invoker.class);
    EasyMock.expect(mockInvoker.getInterface()).andReturn(DemoService.class).anyTimes();
    EasyMock.expect(mockInvoker.getUrl()).andReturn(URL.valueOf("dubbo://127.0.0.1:20885/demo")).anyTimes();
    EasyMock.expect(mockInvoker.invoke((Invocation) EasyMock.anyObject())).andReturn(new RpcResult("ok")).anyTimes();
    mockChannel = EasyMock.createMock(Channel.class);
    EasyMock.expect(mockChannel.getAttribute("telnet.service")).andReturn(null).anyTimes();
    EasyMock.replay(mockChannel, mockInvoker);
    DubboProtocol.getDubboProtocol().export(mockInvoker);
    String result = list.telnet(mockChannel, "");
    assertEquals("com.alibaba.dubbo.rpc.protocol.dubbo.support.DemoService", result);
    EasyMock.reset(mockChannel);
}
 
Example 16
Project: dubbox-hystrix   File: InvokerTelnetHandlerTest.java   Source Code and License Vote up 5 votes
@Test
public void testInvaildMessage() throws RemotingException {
    mockChannel = EasyMock.createMock(Channel.class);
    EasyMock.expect(mockChannel.getAttribute("telnet.service")).andReturn(null).anyTimes();
    EasyMock.replay(mockChannel);
    String result = invoke.telnet(mockChannel, "(");
    assertEquals("Invalid parameters, format: service.method(args)", result);
    EasyMock.reset(mockChannel);
}
 
Example 17
Project: ibm-cos-sdk-java   File: AmazonHttpClientTest.java   Source Code and License Vote up 5 votes
@Before
public void setUp() {
    ClientConfiguration config = new ClientConfiguration();

    httpClient = EasyMock.createMock(ConnectionManagerAwareHttpClient.class);
    EasyMock.replay(httpClient);

    client = new AmazonHttpClient(config, httpClient, null);
}
 
Example 18
Project: dubbo2   File: FailbackClusterInvokerTest.java   Source Code and License Vote up 5 votes
private void resetInvokerToNoException() {
    EasyMock.reset(invoker);
    EasyMock.expect(invoker.invoke(invocation)).andReturn(result).anyTimes();
    EasyMock.expect(invoker.getUrl()).andReturn(url).anyTimes();
    EasyMock.expect(invoker.getInterface()).andReturn(FailbackClusterInvokerTest.class).anyTimes();
    EasyMock.replay(invoker);
}
 
Example 19
Project: github-test   File: ForkingClusterInvokerTest.java   Source Code and License Vote up 4 votes
/**
 * @throws java.lang.Exception
 */

@Before
public void setUp() throws Exception {

    dic = EasyMock.createMock(Directory.class);

    EasyMock.expect(dic.getUrl()).andReturn(url).anyTimes();
    EasyMock.expect(dic.list(invocation)).andReturn(invokers).anyTimes();
    EasyMock.expect(dic.getInterface()).andReturn(ForkingClusterInvokerTest.class).anyTimes();

    invocation.setMethodName("method1");
    EasyMock.replay(dic);

    invokers.add(invoker1);
    invokers.add(invoker2);
    invokers.add(invoker3);

}
 
Example 20
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);
}