Examples of ReturnStub


Examples of org.jmock.core.stub.ReturnStub

    protected IsAnything anything() {
        return new IsAnything();
    }
   
    protected Stub returnValue( Object o ) {
        return new ReturnStub(o);
    }
View Full Code Here

Examples of org.jmock.core.stub.ReturnStub

        List windows = new ArrayList();
        Fragment f1 = (Fragment) fragMock.proxy();
        MutablePortletEntity entity = (MutablePortletEntity) entityMock.proxy();
        CompositeWindowList windowList = (CompositeWindowList) windowListMock.proxy();
        entityAccessMock.expects(new InvokeAtLeastOnceMatcher()).method("getPortletEntityForFragment")
                .withAnyArguments().will(new ReturnStub(entity));
        fragMock.expects(new InvokeAtLeastOnceMatcher()).method("getId").withNoArguments()
                .will(new ReturnStub("frag1"));
        entityMock.expects(new InvokeAtLeastOnceMatcher()).method("getPortletWindowList").withNoArguments().will(
                new ReturnStub(windowList));

        windowListMock.expects(new InvokeCountMatcher(4)).method("add").withAnyArguments().will(
                new ListAppendStub(windows));
       

        PortletWindow window = windowAccess.getPortletWindow(f1);
        assertNotNull(window);
        assertEquals("frag1", window.getId().toString());

        // Make sure the portlet entity's window list got updated
        assertEquals(1, windows.size());

        PortletWindow windowInList = (PortletWindow) windows.get(0);

        // The window in the entities list should be the same as the one
        // returned by getPortletWindow(f1)
        assertEquals(windowInList, window);

        // remove the window
        windowAccess.removeWindow(window);

        // Calling this after a remove go through th procedure of adding a newly
        // created window
        // back the portlet entity's list. We check this through vefirying calls
        // to our mocks
        windowAccess.getPortletWindow(f1);
       
        // Test same remove but via entity
        windowAccess.removeWindow(window);             
             
        assertNotNull(windowAccess.getPortletWindow(f1));               
       
        windowListMock.expects(new InvokeOnceMatcher()).method("iterator").withNoArguments().will(new ReturnStub(windows.iterator()));
       
        windowAccess.removeWindows(entity)
       
        windowAccess.getPortletWindow(f1);
        // Double that second call bypasses creating a new window
View Full Code Here

Examples of org.jmock.core.stub.ReturnStub

            assertTrue("Portlet Def not found", pd.getName().equals("EntityTestPortlet"));
        }
        assertNotNull("Portlet Def is null", pd);

        Mock mockf1 = new Mock(Fragment.class);
        mockf1.expects(new InvokeAtLeastOnceMatcher()).method("getName").will(new ReturnStub(pd.getUniqueName()));
        mockf1.expects(new InvokeAtLeastOnceMatcher()).method("getId").will(new ReturnStub(TEST_ENTITY));
        ContentFragment f1 = new ContentFragmentTestImpl((Fragment) mockf1.proxy(), new HashMap());

        MutablePortletEntity entity = entityAccess
                .generateEntityFromFragment(new ContentFragmentTestImpl(f1, new HashMap()));
        PreferenceSetComposite prefs = (PreferenceSetComposite) entity.getPreferenceSet();
        prefs.remove("pref1");
        assertNotNull(prefs);
        assertNull(prefs.get("pref1"));

        // test adding a pref
        prefs.add("pref1", Arrays.asList(new String[]
        { "1" }));
        assertNotNull(prefs.get("pref1"));

        // Remove should return the deleted pref
        assertNotNull(prefs.remove("pref1"));

        // Should be gone
        assertNull(prefs.get("pref1"));

        // Add it back so we can test tole back
        prefs.add("pref1", Arrays.asList(new String[]
        { "1" }));

        entityAccess.storePortletEntity(entity);

        prefs = (PreferenceSetComposite) entity.getPreferenceSet();

        assertNotNull(prefs.get("pref1"));

        PreferenceComposite pref = (PreferenceComposite) prefs.get("pref1");

        assertEquals("1", pref.getValueAt(0));

        pref.setValueAt(0, "2");

        assertEquals("2", pref.getValueAt(0));

        prefs.add("pref2", Arrays.asList(new String[]
        { "2", "3" }));

        entity.store();

        PreferenceComposite pref2 = (PreferenceComposite) prefs.get("pref2");

        assertNotNull(pref2);

        Iterator prefsValues = pref2.getValues();
        int count = 0;
        while (prefsValues.hasNext())
        {
            prefsValues.next();
            count++;
        }

        assertEquals(2, count);

        pref2.addValue("4");
        prefsValues = pref2.getValues();
        count = 0;
        while (prefsValues.hasNext())
        {
            assertEquals(String.valueOf(count + 2), prefsValues.next());
            count++;
        }
        assertEquals(3, count);

        // testing preferences null values assignments fix, issue JS2-607
        pref2.setValueAt(0, null);       
        assertNull("pref2.value[0] should be null", pref2.getValueAt(0));       
        String[] values = pref2.getValueArray();
        assertEquals(3, values.length);
        assertNull("pref2.value[0] should be null", values[0]);
        assertEquals("3", values[1]);
        pref2.setValues(new String[]{"2",null,"3"});
        assertNull("pref2.value[1] should be null", pref2.getValueAt(1));
        values = pref2.getValueArray();
        assertEquals(3, values.length);
        assertEquals("2", values[0]);
        assertNull("pref2.value[1] should be null", values[1]);
        assertEquals("3", values[2]);
        assertTrue(pref2.isValueSet());
        pref2.setValues((String[])null);
        assertFalse(pref2.isValueSet());
        assertTrue(pref2.getValueArray().length == 0);
        pref2.setValues(new String[]{});
        assertFalse(pref2.isValueSet());
        assertTrue(pref2.getValueArray().length == 0);

        MutablePortletEntity entity2 = entityAccess.getPortletEntityForFragment(f1);
        assertTrue("entity id ", entity2.getId().toString().equals(TEST_ENTITY));
        assertNotNull("entity's portlet ", entity2.getPortletDefinition());
        mockf1.verify();

        Mock mockf2 = new Mock(Fragment.class);
        mockf2.expects(new InvokeAtLeastOnceMatcher()).method("getName").will(new ReturnStub(pd.getUniqueName()));
        ContentFragment f2 = new ContentFragmentTestImpl((Fragment) mockf2.proxy(), new HashMap());

        MutablePortletEntity entity5 = entityAccess.newPortletEntityInstance(pd);

        System.out.println("before storing entity: " + entity5.getId());

        entityAccess.storePortletEntity(entity5);
        System.out.println("store done: " + entity5.getId());
        mockf2.expects(new InvokeAtLeastOnceMatcher()).method("getId").will(new ReturnStub(entity5.getId().toString()));

        MutablePortletEntity entity6 = entityAccess.getPortletEntityForFragment(f2);
        assertNotNull(entity6);
        System.out.println("reget : " + entity6.getId());
View Full Code Here

Examples of org.jmock.core.stub.ReturnStub

        Mock entityMock = new Mock(MutablePortletEntity.class);       
        Mock portletDefinitionMock = new Mock(PortletDefinition.class);
        Mock portletApplicationMock = new Mock(PortletApplication.class);
        Mock windowListMock = new Mock(CompositeWindowList.class);
        PortletWindowListCtrl windowList = (PortletWindowListCtrl)windowListMock.proxy();
        entityMock.expects(new AnyArgumentsMatcher()).method("getPortletWindowList").withNoArguments().will(new ReturnStub(windowList));
        windowListMock.expects(new AnyArgumentsMatcher()).method("add").withAnyArguments().will(new VoidStub());
        portletApplicationMock.expects(new AnyArgumentsMatcher()).method("getId").withNoArguments().will(new ReturnStub(new JetspeedLongObjectID(1)));
        portletDefinitionMock.expects(new AnyArgumentsMatcher()).method("getPortletApplicationDefinition").withNoArguments().will(new ReturnStub(portletApplicationMock.proxy()));
        entityMock.expects(new AnyArgumentsMatcher()).method("getPortletDefinition").withNoArguments().will(new ReturnStub(portletDefinitionMock.proxy()));
        PortletWindowAccessor accessor = (PortletWindowAccessor) engine.getComponentManager().getComponent(PortletWindowAccessor.class);       
        accessor.createPortletWindow((PortletEntity)entityMock.proxy(), "111");
        accessor.createPortletWindow((PortletEntity)entityMock.proxy(), "222");
        accessor.createPortletWindow((PortletEntity)entityMock.proxy(), "333");
       
View Full Code Here

Examples of org.jmock.core.stub.ReturnStub

   
    protected static void expectAndReturn(InvocationMatcher matcher, Mock mock, String methodName, Constraint[] constraints, Object returnValue)
    {
        mock.expects(matcher).method(methodName)
                            .with(constraints)
                            .will(new ReturnStub(returnValue));
    }
View Full Code Here

Examples of org.jmock.core.stub.ReturnStub

   
    protected static void expectAndReturn(InvocationMatcher matcher, Mock mock, String methodName, Object returnValue)
    {
        mock.expects(matcher).method(methodName)
                            .withNoArguments()
                            .will(new ReturnStub(returnValue));
    }
View Full Code Here

Examples of org.jmock.core.stub.ReturnStub

        List windows = new ArrayList();
        ContentFragment f1 = new ContentFragmentImpl((Fragment) fragMock.proxy(), new HashMap());
        MutablePortletEntity entity = (MutablePortletEntity) entityMock.proxy();
        CompositeWindowList windowList = (CompositeWindowList) windowListMock.proxy();
        entityAccessMock.expects(new InvokeAtLeastOnceMatcher()).method("getPortletEntityForFragment")
                .withAnyArguments().will(new ReturnStub(entity));
        fragMock.expects(new InvokeAtLeastOnceMatcher()).method("getId").withNoArguments()
                .will(new ReturnStub("frag1"));
        entityMock.expects(new InvokeAtLeastOnceMatcher()).method("getPortletWindowList").withNoArguments().will(
                new ReturnStub(windowList));
        entityMock.expects(new InvokeAtLeastOnceMatcher()).method("getId").withNoArguments().will(
            new ReturnStub(new JetspeedObjectID("entity1")));

        windowListMock.expects(new InvokeCountMatcher(4)).method("add").withAnyArguments().will(
                new ListAppendStub(windows));
       

        PortletWindow window = windowAccess.getPortletWindow(f1);
        assertNotNull(window);
        assertEquals("frag1", window.getId().toString());

        // Make sure the portlet entity's window list got updated
        assertEquals(1, windows.size());

        PortletWindow windowInList = (PortletWindow) windows.get(0);

        // The window in the entities list should be the same as the one
        // returned by getPortletWindow(f1)
        assertEquals(windowInList, window);

        // remove the window
        windowAccess.removeWindow(window);

        // Calling this after a remove go through th procedure of adding a newly
        // created window
        // back the portlet entity's list. We check this through vefirying calls
        // to our mocks
        windowAccess.getPortletWindow(f1);
       
        // Test same remove but via entity
        windowAccess.removeWindow(window);             

        assertNotNull(windowAccess.getPortletWindow(f1));               
       
        windowListMock.expects(new InvokeOnceMatcher()).method("iterator").withNoArguments().will(new ReturnStub(windows.iterator()));

/*       
        windowAccess.removeWindows(entity); 
       
        windowAccess.getPortletWindow(f1);
View Full Code Here

Examples of org.jmock.core.stub.ReturnStub

                new IsScmTagParamtersEquals( new ScmTagParameters( "[my prefix] copy for tag release-label" ) )};
        scmProviderMock
            .expects( new InvokeOnceMatcher() )
            .method( "tag" )
            .with( arguments )
            .will( new ReturnStub( new TagScmResult( "...", Collections.singletonList( new ScmFile( getPath (rootProject
                       .getFile() ), ScmFileStatus.TAGGED ) ) ) ) );

        ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.ROLE );
        stub.setScmProvider( (ScmProvider) scmProviderMock.proxy() );
View Full Code Here

Examples of org.jmock.core.stub.ReturnStub

       
        scmProviderMock
            .expects( new InvokeOnceMatcher() )
            .method( "tag" )
            .with( arguments )
            .will( new ReturnStub( new TagScmResult( "...", Collections.singletonList( new ScmFile( getPath (rootProject
                       .getFile() ), ScmFileStatus.TAGGED ) ) ) ) );

        ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.ROLE );
        stub.setScmProvider( (ScmProvider) scmProviderMock.proxy() );
        stub.addScmRepositoryForUrl( scmUrl, repository );
View Full Code Here

Examples of org.jmock.core.stub.ReturnStub

            new IsScmTagParamtersEquals( new ScmTagParameters( "[my prefix] copy for tag release-label" ) )};
        scmProviderMock
            .expects( new InvokeOnceMatcher() )
            .method( "tag" )
            .with( arguments )
            .will( new ReturnStub( new TagScmResult( "...", Collections.singletonList( new ScmFile( getPath (rootProject
                       .getFile() ), ScmFileStatus.TAGGED ) ) ) ) );

        ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.ROLE );
        stub.setScmProvider( (ScmProvider) scmProviderMock.proxy() );
        stub.addScmRepositoryForUrl( "scm:svn:" + scmUrl, repository );
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.