Examples of MethodAction


Examples of com.volantis.testtools.mock.method.MethodAction

    public void testExpiryModeNoKeyAttrAuto() throws Exception {

        final CacheProperties[] cacheProperties = new CacheProperties[1];

        contextMock.fuzzy.pushObject(mockFactory.expectsInstanceOf(
            CacheProperties.class), Boolean.FALSE).does(new MethodAction() {
                public Object perform(final MethodActionEvent event)
                        throws Throwable {
                    cacheProperties[0] = (CacheProperties) event.getArguments()[0];
                    return null;
                }
View Full Code Here

Examples of com.volantis.testtools.mock.method.MethodAction

        // create a system clock mock
        final long[] timeShift = new long[1];
        timeShift[0] = 0;
        final SystemClockMock clock = new SystemClockMock("clock", expectations);
        clock.expects.getCurrentTime().does(new MethodAction() {
            public Object perform(MethodActionEvent event) throws Throwable {
                return Time.inMilliSeconds(
                    System.currentTimeMillis() + timeShift[0]);
            }
        }).any();
View Full Code Here

Examples of com.volantis.testtools.mock.method.MethodAction

        // create a system clock mock
        final long[] timeShift = new long[1];
        timeShift[0] = 0;
        final SystemClockMock clock = new SystemClockMock("clock", expectations);
        clock.expects.getCurrentTime().does(new MethodAction() {
            public Object perform(MethodActionEvent event) throws Throwable {
                return Time.inMilliSeconds(
                    System.currentTimeMillis() + timeShift[0]);
            }
        }).any();
View Full Code Here

Examples of com.volantis.testtools.mock.method.MethodAction

        // create a system clock mock
        final long[] timeShift = new long[1];
        timeShift[0] = 10000; // 10 seconds
        final SystemClockMock clock = new SystemClockMock("clock", expectations);
        clock.expects.getCurrentTime().does(new MethodAction() {
            public Object perform(MethodActionEvent event) throws Throwable {
                return Time.inMilliSeconds(
                    System.currentTimeMillis() + timeShift[0]);
            }
        }).any();
View Full Code Here

Examples of com.volantis.testtools.mock.method.MethodAction

        // create a system clock mock
        final long[] timeShift = new long[1];
        timeShift[0] = 0;
        final SystemClockMock clock = new SystemClockMock("clock", expectations);
        clock.expects.getCurrentTime().does(new MethodAction() {
            public Object perform(MethodActionEvent event) throws Throwable {
                return Time.inMilliSeconds(
                    System.currentTimeMillis() + timeShift[0]);
            }
        }).any();

        // create a manager using the system clock mock
        final URLContentManager manager = createURLContentManager(
            clock, Period.INDEFINITELY, true, 1000);
        final URL url = serverMock.getURL("/blah.txt?foo");
        URLContent content = manager.getURLContent(url, null, null);
        assertEquals("Content was received", "<p>hello</p>\n",
            toString(content.getInputStream()));
        assertEquals(Cacheability.CACHEABLE,
            content.getDependency().getCacheability());
        assertEquals(Freshness.FRESH,
            content.getDependency().freshness(null));
        assertTrue(Comparator.GE.compare(Period.inSeconds(10),
            content.getDependency().getTimeToLive()));
        assertTrue(Comparator.LT.compare(Period.inSeconds(5),
            content.getDependency().getTimeToLive()));

        // get the same resource when the cached entry become stale
        timeShift[0] = 20000;
        serverMock.addTransaction(new String[]{
                "GET /blah.txt?foo HTTP/1.1",
                "If-None-Match: \"aa\"",
                UA_STRING,
                "Host: " + serverMock.getServerAddress()},
            new String[]{
                "HTTP/1.0 200 OK",
                "Date: " +
                    RFC1123.format(new Date(clock.getCurrentTime().inMillis())),
                "Content-Type: text/plain",
                "Cache-Control: max-age=10",
                "ETag: \"aa2\"",
                "",
                "<p>hello2</p>"});

        // because of the 20 sec time travel, cached content expired
        assertEquals(Cacheability.CACHEABLE,
            content.getDependency().getCacheability());
        assertEquals(Freshness.REVALIDATE,
            content.getDependency().freshness(null));
        assertEquals(Period.ZERO, content.getDependency().getTimeToLive());

        // let's revalidate the dependency
        final DependencyContextMock dependencyContextMock =
            new DependencyContextMock("dependencyContextMock", expectations);
        final MockFactory mockFactory = MockFactory.getDefaultInstance();
        final URLContent[] contents = new URLContent[1];
        dependencyContextMock.fuzzy.setProperty(
            url, mockFactory.expectsAny()).does(new MethodAction() {
                    public Object perform(final MethodActionEvent event)
                            throws Throwable {
                        contents[0] = (URLContent) event.getArguments()[1];
                        return null;
                    }
                });
        content.getDependency().revalidate(dependencyContextMock);
        // there should be a URLContent object stored in the dependency context
        assertEquals("New content is returned", "<p>hello2</p>\n",
            toString(contents[0].getInputStream()));
        // cached content is fresh again
        assertEquals(Cacheability.CACHEABLE,
            contents[0].getDependency().getCacheability());
        assertEquals(Freshness.FRESH,
            contents[0].getDependency().freshness(null));
        assertTrue(Comparator.GE.compare(Period.inSeconds(10),
            contents[0].getDependency().getTimeToLive()));
        // all transactions should have been used up by this time
        assertFalse(serverMock.hasTransactions());

        // manager only returns the content from the dependency context
        dependencyContextMock.expects.removeProperty(url).does(
            new MethodAction() {
                public Object perform(final MethodActionEvent event)
                        throws Throwable {
                    final URLContent content = contents[0];
                    contents[0] = null;
                    return content;
View Full Code Here

Examples of com.volantis.testtools.mock.method.MethodAction

        outputElementMock1.expects.getName().returns("output element 1").any();

        outputElementMock2.expects.getName().returns("output element 2").any();

        // Create an action which fakes the iteration of two elements.
        MethodAction action = new OutputStyledElementsIterateMethodAction() {
            public void iterate(OutputStyledElementIteratee iteratee) {
                assertEquals(IterationAction.CONTINUE,
                        iteratee.next(outputElementMock1));
                assertEquals(IterationAction.CONTINUE,
                        iteratee.next(outputElementMock2));
View Full Code Here

Examples of com.volantis.testtools.mock.method.MethodAction

        outputElementMock1.expects.getName().returns("output element 1").any();

        outputElementMock2.expects.getName().returns("output element 2").any();

        // Create an action which fakes the iteration of two elements.
        MethodAction action = new OutputStyledElementsIterateMethodAction() {
            public void iterate(OutputStyledElementIteratee iteratee) {
                assertEquals(IterationAction.CONTINUE,
                        iteratee.next(outputElementMock1));
                assertEquals(IterationAction.CONTINUE,
                    iteratee.next(outputElementMock2));
View Full Code Here

Examples of com.volantis.testtools.mock.method.MethodAction

                classSelectorMock);
        selectorSequenceMock.expects.addSelector(classSelectorMock);

        // Create an action which fakes the mock path accept() method to visit
        // a pseudo class and element.
        MethodAction visitorAction = new PseudoStylePathAcceptMethodAction() {
            public void accept(PseudoStyleEntityVisitor visitor) {
                visitor.visit(pseudoClassSetMock);
                visitor.visit(pseudoElementMock);
            }
        };
        pseudoStylePathMock.fuzzy.accept(mockFactory.expectsInstanceOf(
                PseudoStyleEntityVisitor.class)).does(visitorAction);

        // Create the pseudo class selector.
        styleSheetFactoryMock.expects.createPseudoClassSelector("link").
                returns(pseudoClassSelectorMock);
        selectorSequenceMock.expects.addSelector(pseudoClassSelectorMock);

        // Create an action which fakes the mock stateful pseudo class iterate()
        // method and pretends to iterate over a single individual pseudo class.
        MethodAction iterateAction = new StatefulPseudoClassSetIterateMethodAction() {
            public void iterate(StatefulPseudoClassIteratee iteratee) {
                iteratee.next(pseudoClassMock);
            }
        };
        pseudoClassSetMock.fuzzy.iterate(mockFactory.expectsInstanceOf(
View Full Code Here

Examples of com.volantis.testtools.mock.method.MethodAction

            returns(paneInstance).any();
        pageContextMock.expects.initialisedCanvas().returns(true).any();
        pageContextMock.expects.getProtocol().returns(protocol).any();
        pageContextMock.fuzzy.pushOutputBuffer(
            mockFactory.expectsInstanceOf(DOMOutputBuffer.class)).does(
                new MethodAction() {
                    public Object perform(MethodActionEvent event)
                        throws Throwable {
                        Object buffer = event.getArgument(OutputBuffer.class);

                        outputBufferStack.push(buffer);

                        return null;
                    }
                }).any();
        pageContextMock.fuzzy.popOutputBuffer(
            mockFactory.expectsInstanceOf(DOMOutputBuffer.class)).does(
                new MethodAction() {
                    public Object perform(MethodActionEvent event)
                        throws Throwable {

                        return outputBufferStack.pop();
                    }
                }).any();
        pageContextMock.expects.getCurrentOutputBuffer().does(
            new MethodAction() {
                public Object perform(MethodActionEvent event) throws Throwable {
                    return outputBufferStack.peek();
                }
            }).any();

        final ExpressionFactory expressionFactory =
            ExpressionFactory.getDefaultInstance();
        final NamespacePrefixTracker prefixTracker =
            NamespaceFactory.getDefaultInstance().createPrefixTracker();
        prefixTracker.startPrefixMapping("meta-property",
            XDIMESchemata.XDIME2_MCS_NAMESPACE);
        final ExpressionContext expressionContext =
            expressionFactory.createExpressionContext(null, prefixTracker);

        final EnvironmentContextMock environmentContextMock =
            new EnvironmentContextMock("environmentContextMock", expectations);
        environmentContextMock.expects.getExpressionContext()
                .returns(expressionContext).any();
        requestContextMock.expects.getEnvironmentContext()
                .returns(environmentContextMock);
        pageContextMock.fuzzy.getElementMetaData(mockFactory.expectsAny()).does(
            new MethodAction() {
                public Object perform(MethodActionEvent event) throws Throwable {
                    final String id = (String) event.getArguments()[0];
                    return getMetaData(id);
                }
            }).any();
        pageContextMock.expects.getPageMetaData().does(
            new MethodAction() {
                public Object perform(MethodActionEvent event) throws Throwable {
                    return getMetaData(null);
                }
            }).any();
View Full Code Here

Examples of com.volantis.testtools.mock.method.MethodAction

            new DOMProtocolMock("DOMProtocolMock", expectations,
                new DefaultProtocolSupportFactory(), null);
        protocolMock.expects.pushHeadBuffer().any();
        final List scriptAttributesList = new LinkedList();
        protocolMock.fuzzy.writeOpenScript(mockFactory.expectsAny()).does(
            new MethodAction() {
                public Object perform(MethodActionEvent event) {
                    scriptAttributesList.add(event.getArguments()[0]);
                    return null;
                }
            }).any();
        protocolMock.fuzzy.writeCloseScript(mockFactory.expectsAny()).returns().any();
        protocolMock.expects.popHeadBuffer().any();
        protocolMock.expects.getDOMFactory().returns(
            DOMFactory.getDefaultInstance()).any();
        final PageHead pageHead = new PageHead();
        pageHead.setOutputBufferFactory(
            new DOMOutputBufferFactory(DOMFactory.getDefaultInstance()));
        protocolMock.expects.getPageHead().returns(pageHead).any();
        protocolMock.fuzzy.createScriptElement(
            mockFactory.expectsInstanceOf(ScriptAttributes.class)).does(
                new MethodAction(){
                    public Object perform(final MethodActionEvent event)
                            throws Throwable {
                        final ScriptAttributes attributes =
                            (ScriptAttributes) event.getArguments()[0];
                        final Element scriptElement =
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.