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

The following are Jave code examples for showing how to use reset() 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.
+ Save this method
Example 1
Project: dubbocloud   File: InvokerTelnetHandlerTest.java   View Source Code Vote up 6 votes
@SuppressWarnings("unchecked")
@Test
public void testInvokeDefaultSService() 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:20883/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.expect(mockChannel.getLocalAddress()).andReturn(NetUtils.toAddress("127.0.0.1:5555")).anyTimes();
    EasyMock.expect(mockChannel.getRemoteAddress()).andReturn(NetUtils.toAddress("127.0.0.1:20883")).anyTimes();
    EasyMock.replay(mockChannel, mockInvoker);
    DubboProtocol.getDubboProtocol().export(mockInvoker);
    String result = invoke.telnet(mockChannel, "DemoService.echo(\"ok\")");
    assertTrue(result.contains("Use default service com.alibaba.dubbo.rpc.protocol.dubbo.support.DemoService.\r\n\"ok\"\r\n"));
    EasyMock.reset(mockChannel, mockInvoker);
}
 
Example 2
Project: github-test   File: FailoverClusterInvokerTest.java   View Source Code Vote up 6 votes
@Test
public void testInvokeWithRuntimeException() {
    EasyMock.reset(invoker1);
    EasyMock.expect(invoker1.invoke(invocation)).andThrow(new RuntimeException()).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)).andThrow(new RuntimeException()).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);
    try {
        invoker.invoke(invocation);
        fail();
    } catch (RpcException expected) {
        assertEquals(0, expected.getCode());
        assertFalse(expected.getCause() instanceof RpcException);
    }
}
 
Example 3
Project: dubbocloud   File: ForkingClusterInvokerTest.java   View Source Code 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 4
Project: dubbox-hystrix   File: ForkingClusterInvokerTest.java   View Source Code Vote up 6 votes
private void resetInvokerToException() {
    EasyMock.reset(invoker1);
    EasyMock.expect(invoker1.invoke(invocation)).andThrow(new RuntimeException()).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)).andThrow(new RuntimeException()).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)).andThrow(new RuntimeException()).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 5
Project: dubbo2   File: InvokerTelnetHandlerTest.java   View Source Code Vote up 6 votes
@SuppressWarnings("unchecked")
@Test
public void testInvokeDefaultSService() 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:20883/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.expect(mockChannel.getLocalAddress()).andReturn(NetUtils.toAddress("127.0.0.1:5555")).anyTimes();
    EasyMock.expect(mockChannel.getRemoteAddress()).andReturn(NetUtils.toAddress("127.0.0.1:20883")).anyTimes();
    EasyMock.replay(mockChannel, mockInvoker);
    DubboProtocol.getDubboProtocol().export(mockInvoker);
    String result = invoke.telnet(mockChannel, "DemoService.echo(\"ok\")");
    assertTrue(result.contains("Use default service com.alibaba.dubbo.rpc.protocol.dubbo.support.DemoService.\r\n\"ok\"\r\n"));
    EasyMock.reset(mockChannel, mockInvoker);
}
 
Example 6
Project: dubbocloud   File: ListTelnetHandlerTest.java   View Source Code Vote up 6 votes
@SuppressWarnings("unchecked")
@Test
public void testListDefault() 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, "");
    assertEquals("Use default service com.alibaba.dubbo.rpc.protocol.dubbo.support.DemoService.\r\n\r\n"
                 + methodsName, result);
    EasyMock.reset(mockChannel);
}
 
Example 7
Project: dubbo2   File: FailfastClusterInvokerTest.java   View Source Code Vote up 5 votes
private void resetInvoker1ToException(){
    EasyMock.reset(invoker1);
    EasyMock.expect(invoker1.invoke(invocation)).andThrow(new RuntimeException()).anyTimes();
    EasyMock.expect(invoker1.getUrl()).andReturn(url).anyTimes();
    EasyMock.expect(invoker1.getInterface()).andReturn(FailfastClusterInvokerTest.class).anyTimes();
    EasyMock.replay(invoker1);
}
 
Example 8
Project: dubbo2   File: LogTelnetHandlerTest.java   View Source Code Vote up 5 votes
@Test
public void testPrintLog() throws RemotingException {
    mockChannel = EasyMock.createMock(Channel.class);
    EasyMock.replay(mockChannel);
    String result = log.telnet(mockChannel, "100");
    assertTrue(result.contains("CURRENT LOG APPENDER"));
    EasyMock.reset(mockChannel);
}
 
Example 9
Project: dubbox-hystrix   File: FailSafeClusterInvokerTest.java   View Source Code Vote up 5 votes
private void resetInvokerToException(){
    EasyMock.reset(invoker);
    EasyMock.expect(invoker.invoke(invocation)).andThrow(new RuntimeException()).anyTimes();
    EasyMock.expect(invoker.getUrl()).andReturn(url).anyTimes();
    EasyMock.expect(invoker.getInterface()).andReturn(DemoService.class).anyTimes();
    EasyMock.replay(invoker);
}
 
Example 10
Project: ibm-cos-sdk-java   File: AmazonHttpClientTest.java   View Source Code Vote up 5 votes
@Test
public void testUserAgentPrefixAndSuffixAreAdded() throws Exception {
    String prefix = "somePrefix", suffix = "someSuffix";
    Request<?> request = mockRequest(SERVER_NAME, HttpMethodName.PUT, URI_NAME, true);

    HttpResponseHandler<AmazonWebServiceResponse<Object>> handler = createStubResponseHandler();
    EasyMock.replay(handler);
    ClientConfiguration config =
            new ClientConfiguration().withUserAgentPrefix(prefix).withUserAgentSuffix(suffix);

    Capture<HttpRequestBase> capturedRequest = new Capture<HttpRequestBase>();

    EasyMock.reset(httpClient);
    EasyMock
            .expect(httpClient.execute(
                    EasyMock.capture(capturedRequest), EasyMock.<HttpContext>anyObject()))
            .andReturn(createBasicHttpResponse())
            .once();
    EasyMock.replay(httpClient);

    AmazonHttpClient client = new AmazonHttpClient(config, httpClient, null);

    client.requestExecutionBuilder().request(request).execute(handler);

    String userAgent = capturedRequest.getValue().getFirstHeader("User-Agent").getValue();
    Assert.assertTrue(userAgent.startsWith(prefix));
    Assert.assertTrue(userAgent.endsWith(suffix));
}
 
Example 11
Project: dubbo2   File: ListTelnetHandlerTest.java   View Source Code 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 = list.telnet(mockChannel, "xx");
    assertEquals("No such service xx", result);
    EasyMock.reset(mockChannel);
}
 
Example 12
Project: dubbox-hystrix   File: FailbackClusterInvokerTest.java   View Source Code Vote up 5 votes
private void resetInvokerToException() {
    EasyMock.reset(invoker);
    EasyMock.expect(invoker.invoke(invocation)).andThrow(new RuntimeException()).anyTimes();
    EasyMock.expect(invoker.getUrl()).andReturn(url).anyTimes();
    EasyMock.expect(invoker.getInterface()).andReturn(FailbackClusterInvokerTest.class).anyTimes();
    EasyMock.replay(invoker);
}
 
Example 13
Project: dubbo2   File: FailbackClusterInvokerTest.java   View Source Code 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 14
Project: EatDubbo   File: LogTelnetHandlerTest.java   View Source Code 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 15
Project: dubbocloud   File: FailSafeClusterInvokerTest.java   View Source Code 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(DemoService.class).anyTimes();
    EasyMock.replay(invoker);
}
 
Example 16
Project: EatDubbo   File: LogTelnetHandlerTest.java   View Source Code Vote up 5 votes
@Test
public void testPrintLog() throws RemotingException {
    mockChannel = EasyMock.createMock(Channel.class);
    EasyMock.replay(mockChannel);
    String result = log.telnet(mockChannel, "100");
    assertTrue(result.contains("CURRENT LOG APPENDER"));
    EasyMock.reset(mockChannel);
}
 
Example 17
Project: dubbo2   File: ListTelnetHandlerTest.java   View Source Code Vote up 5 votes
@SuppressWarnings("unchecked")
@Test
public void testListDetailService() 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, "-l DemoService");
    assertEquals(detailMethods, result);
    EasyMock.reset(mockChannel, mockInvoker);
}
 
Example 18
Project: dubbo2   File: PortTelnetHandlerTest.java   View Source Code Vote up 4 votes
@After
public void after() {
    EasyMock.reset(mockInvoker);
    ProtocolUtils.closeAll();
}
 
Example 19
Project: ibm-cos-sdk-java   File: AmazonHttpClientTest.java   View Source Code Vote up 4 votes
private void mockFailure(final int contentLength) throws IOException {

        EasyMock.reset(httpClient);

        EasyMock
            .expect(httpClient.getConnectionManager())
            .andReturn(null)
            .anyTimes();

        for (int i = 0; i < 4; ++i) {
            EasyMock
                .expect(httpClient.execute(
                        EasyMock.<HttpUriRequest>anyObject(),
                        EasyMock.<HttpContext>anyObject()))
                .andAnswer(new IAnswer<org.apache.http.HttpResponse>() {

                    @Override
                    public org.apache.http.HttpResponse answer()
                            throws Throwable {

                        HttpEntityEnclosingRequestBase request =
                                (HttpEntityEnclosingRequestBase)
                                        EasyMock.getCurrentArguments()[0];

                        InputStream stream = request.getEntity().getContent();
                        int len = 0;
                        while (true) {
                            int b = stream.read(new byte[1024]);
                            if (b == -1) {
                                break;
                            }
                            len += b;
                        }

                        assertEquals(contentLength, len);

                        throw new IOException("BOOM");
                    }
                });
        }

        EasyMock.replay(httpClient);
    }
 
Example 20
Project: EatDubbo   File: CurrentTelnetHandlerTest.java   View Source Code Vote up 4 votes
@After
public void after() {
    EasyMock.reset(mockChannel);
}