Package org.easymock

Examples of org.easymock.IMocksControl


    browserInfo.setId(1L);

    CharArrayWriter out = new CharArrayWriter();
    PrintWriter writer = new PrintWriter(out);

    IMocksControl control = EasyMock.createControl();

    HttpServletResponse response = control.createMock(HttpServletResponse.class);
    response.setCharacterEncoding("UTF-8");
    expect(response.getWriter()).andReturn(writer).anyTimes();
    HttpServletRequest request = control.createMock(HttpServletRequest.class);
    expect(request.getParameter("listBrowsers")).andReturn(null);
    expect(request.getParameter("nextBrowserId")).andReturn(null);
    expect(request.getParameter("id")).andReturn(browserInfo.getId().toString());
    control.replay();

    SlaveBrowser slave = new SlaveBrowser(new Time() {
      int i = 0;

      public Instant now() {
View Full Code Here


     * Verifies that all trained methods have been invoked on all mock objects (created by {@link #newMock(Class)}, then
     * switches each mock object back to training mode.
     */
    public void verify()
    {
        IMocksControl control = getMocksControl();

        control.verify();
        control.reset();
    }
View Full Code Here

            Object cache = createCache(64);
            File tmpfile = getTmpFile("Hello World!", cache);
            assertNull("expects no tmp file", tmpfile);
            close(cache);
           
            IMocksControl control = EasyMock.createControl();
           
            Bus b = control.createMock(Bus.class);
            EasyMock.expect(b.getProperty("bus.io.CachedOutputStream.Threshold")).andReturn("4");
            EasyMock.expect(b.getProperty("bus.io.CachedOutputStream.MaxSize")).andReturn(null);
            EasyMock.expect(b.getProperty("bus.io.CachedOutputStream.CipherTransformation")).andReturn(null);
       
            BusFactory.setThreadDefaultBus(b);
           
            control.replay();

            cache = createCache();
            tmpfile = getTmpFile("Hello World!", cache);
            assertNotNull("expects a tmp file", tmpfile);
            assertTrue("expects a tmp file", tmpfile.exists());
            close(cache);
            assertFalse("expects no tmp file", tmpfile.exists());
           
            control.verify();
        } finally {
            BusFactory.setThreadDefaultBus(oldbus);
        }
    }
View Full Code Here

        result.setEncode(false);
        result.setPrependServletContext(false);
        result.setAnchor("fragment");
        result.setUrlHelper(new DefaultUrlHelper());

        IMocksControl control = createControl();
        ActionProxy mockActionProxy = control.createMock(ActionProxy.class);
        ActionInvocation mockInvocation = control.createMock(ActionInvocation.class);
        expect(mockInvocation.getProxy()).andReturn(mockActionProxy);
        expect(mockInvocation.getResultCode()).andReturn("myResult");
        expect(mockActionProxy.getConfig()).andReturn(actionConfig);
        expect(mockInvocation.getInvocationContext()).andReturn(context);
        expect(mockInvocation.getStack()).andReturn(stack).anyTimes();

        control.replay();
        result.setActionMapper(container.getInstance(ActionMapper.class));
        result.execute(mockInvocation);
        assertEquals("/myNamespace/myAction.action?param1=value+1&param2=value+2&param3=value+3#fragment", res.getRedirectedUrl());

        control.verify();
    }
View Full Code Here

        result.setEncode(false);
        result.setPrependServletContext(false);
        result.setAnchor("fragment");
        result.setUrlHelper(new DefaultUrlHelper());

        IMocksControl control = createControl();
        ActionProxy mockActionProxy = control.createMock(ActionProxy.class);
        ActionInvocation mockInvocation = control.createMock(ActionInvocation.class);
        expect(mockInvocation.getProxy()).andReturn(mockActionProxy);
        expect(mockInvocation.getResultCode()).andReturn("myResult");
        expect(mockActionProxy.getConfig()).andReturn(actionConfig);
        expect(mockInvocation.getInvocationContext()).andReturn(context);

        control.replay();
        result.setActionMapper(container.getInstance(ActionMapper.class));
        result.execute(mockInvocation);
        assertEquals("/myNamespace/myAction.action?param1=value+1&param2=value+2&param3=value+3#fragment", res.getRedirectedUrl());

        control.verify();
    }
View Full Code Here

        result.setEncode(false);
        result.setPrependServletContext(false);
        result.setAnchor("fragment");
        result.setUrlHelper(new DefaultUrlHelper());

        IMocksControl control = createControl();
        ActionProxy mockActionProxy = control.createMock(ActionProxy.class);
        ActionInvocation mockInvocation = control.createMock(ActionInvocation.class);
        expect(mockInvocation.getProxy()).andReturn(mockActionProxy);
        expect(mockInvocation.getResultCode()).andReturn("myResult");
        expect(mockActionProxy.getConfig()).andReturn(actionConfig);
        expect(mockInvocation.getInvocationContext()).andReturn(context);

        control.replay();
        result.setActionMapper(container.getInstance(ActionMapper.class));
        result.execute(mockInvocation);
        assertEquals("/myNamespace/myAction.action?param1=value+1&param2=value+2&param3=value+3#fragment", res.getRedirectedUrl());
        control.verify();
    }
View Full Code Here

    /**
     * Verifies each created mock object, then resets the mock for additional training.
     */
    protected final void verify()
    {
        IMocksControl control = getMocksControl();

        control.verify();
        control.reset();
    }
View Full Code Here

        assertEquals("HelloMINAWorld", toString(cba));
    }

    public void testCompositeCursor() throws Exception {
        IMocksControl mc = createStrictControl();

        ByteArray ba1 = getByteArrayFactory().create(10);
        ByteArray ba2 = getByteArrayFactory().create(10);
        ByteArray ba3 = getByteArrayFactory().create(10);


        CompositeByteArray cba = new CompositeByteArray();
        cba.addLast(ba1);
        cba.addLast(ba2);
        cba.addLast(ba3);

        CursorListener cl = mc.createMock(CursorListener.class);

        mc.reset();
        mc.replay();
        Cursor cursor = cba.cursor(cl);
        mc.verify();

        mc.reset();
        cl.enteredFirstComponent(0, ba1);
        mc.replay();
        cursor.get();
        mc.verify();

        mc.reset();
        mc.replay();
        cursor.setIndex(10);
        mc.verify();

        mc.reset();
        cl.enteredNextComponent(10, ba2);
        mc.replay();
        cursor.put((byte) 55);
        mc.verify();

        mc.reset();
        mc.replay();
        cursor.setIndex(9);
        mc.verify();

        mc.reset();
        cl.enteredPreviousComponent(0, ba1);
        cl.enteredNextComponent(10, ba2);
        mc.replay();
        cursor.putInt(66);
        mc.verify();

        mc.reset();
        cl.enteredNextComponent(20, ba3);
        mc.replay();
        cursor.setIndex(29);
        cursor.get();
        mc.verify();

        cba.removeLast(); // Force cursor to relocate itself.

        mc.reset();
        cl.enteredLastComponent(10, ba2);
        mc.replay();
        cursor.setIndex(15);
        cursor.get();
        mc.verify();

        mc.reset();
        cl.enteredPreviousComponent(0, ba1);
        mc.replay();
        cursor.setIndex(0);
        cursor.get();
        mc.verify();
    }
View Full Code Here

        Assert.assertEquals(EXPECTED_SUBJECT_DN, cert2.getSubjectDN().toString());
    }
   
    @Test
    public void testSaveUserCert() throws Exception {
        IMocksControl c = EasyMock.createControl();
        LdapSearch ldapSearch = c.createMock(LdapSearch.class);
        ldapSearch.bind(EasyMock.eq(EXPECTED_SUBJECT_DN2 + "," + ROOT_DN), EasyMock.anyObject(Attributes.class));
        EasyMock.expectLastCall().once();
        LdapCertificateRepo ldapCertRepo = new LdapCertificateRepo(ldapSearch, LDAP_CERT_CONFIG, ROOT_DN);
        X509Certificate cert = getTestCert();

        c.replay();
        UseKeyWithType key = new UseKeyWithType();
        key.setApplication(Applications.PKIX.getUri());
        key.setIdentifier(EXPECTED_SUBJECT_DN2);
        ldapCertRepo.saveCertificate(cert, key);
        c.verify();
    }
View Full Code Here

        c.verify();
    }

    @Test
    public void testSaveServiceCert() throws Exception {
        IMocksControl c = EasyMock.createControl();
        LdapSearch ldapSearch = c.createMock(LdapSearch.class);
        ldapSearch.bind(EasyMock.eq(EXPECTED_DN_FOR_SERVICE + "," + ROOT_DN), EasyMock.anyObject(Attributes.class));
        EasyMock.expectLastCall().once();
        LdapCertificateRepo ldapCertRepo = new LdapCertificateRepo(ldapSearch, LDAP_CERT_CONFIG, ROOT_DN);
        X509Certificate cert = getTestCert();

        c.replay();
        UseKeyWithType key = new UseKeyWithType();
        key.setApplication(Applications.SERVICE_NAME.getUri());
        key.setIdentifier(EXPECTED_SERVICE_URI);
        ldapCertRepo.saveCertificate(cert, key);
        c.verify();
    }
View Full Code Here

TOP

Related Classes of org.easymock.IMocksControl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.