Package com.volantis.shared.system

Examples of com.volantis.shared.system.SystemClockMock


                "removalListenerMock", expectations);

        expirationCheckerMock = new ExpirationCheckerMock(
                "expirationCheckerMock", expectations);

        clockMock = new SystemClockMock("clockMock", expectations);

        clockMock.expects.getCurrentTime().returns(Time.inMilliSeconds(0));
    }
View Full Code Here


                "<p>hello</p>"});

        // 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>"});
View Full Code Here

                "<p>hello</p>"});

        // 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; // jump into the future
        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>"});
View Full Code Here

                "<p>hello</p>"});

        // 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]);
            }
View Full Code Here

                "<p>hello</p>"});

        // 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>"});
View Full Code Here

    private SystemClockMock clockMock;

    protected void setUp() throws Exception {
        super.setUp();

        clockMock = new SystemClockMock("clockMock", expectations);
    }
View Full Code Here

        // =====================================================================
        //   Create Mocks
        // =====================================================================

        final SystemClockMock clockMock =
                new SystemClockMock("clockMock", expectations);

        final MethodExecuterMock methodExecuterMock =
                new MethodExecuterMock("methodExecuterMock", expectations);

        GetMethod getMethod = new GetMethod();
View Full Code Here

        rcd.enable();
        assertFalse(rcd.isEnabled());
    }

    public void testPriorityMaxAge() {
        final SystemClockMock clockMock =
            new SystemClockMock("clockMock", expectations);
        clockMock.expects.getCurrentTime().returns(
            Time.inMilliSeconds(System.currentTimeMillis())).any();
        final ResponseCachingDirectives rcd =
            new ResponseCachingDirectives(clockMock);
View Full Code Here

            ResponseCachingDirectives.PRIORITY_NORMAL);
        assertEquals(Period.inSeconds(150), rcd.getTimeToLive());
    }

    public void testPriorityExpires() {
        final SystemClockMock clockMock =
            new SystemClockMock("clockMock", expectations);
        final long baseTime = System.currentTimeMillis();
        clockMock.expects.getCurrentTime().returns(
            Time.inMilliSeconds(baseTime)).any();
        final ResponseCachingDirectives rcd =
            new ResponseCachingDirectives(clockMock);
View Full Code Here

            ResponseCachingDirectives.PRIORITY_NORMAL);
        assertEquals(Time.inMilliSeconds(baseTime + 1500), rcd.getExpires());
    }

    public void testMaxAge() {
        final SystemClockMock clockMock =
            new SystemClockMock("clockMock", expectations);
        final Time[] time =
            new Time[]{Time.inMilliSeconds(System.currentTimeMillis())};
        clockMock.expects.getCurrentTime().does(new MethodAction(){
                public Object perform(final MethodActionEvent event) {
                    return time[0];
View Full Code Here

TOP

Related Classes of com.volantis.shared.system.SystemClockMock

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.