Package com.volantis.testtools.mock

Examples of com.volantis.testtools.mock.MockFactory


        HttpServletRequestMock request = new HttpServletRequestMock(
            "test-request", expectationContainer);
        String pathInfo = "/" + rule + "/" + fileName;
        request.expects.getPathInfo().returns(pathInfo).any();
        final MockFactory mf = MockFactory.getDefaultInstance();

        // use a vector as we need to return an enumeration for calls to
        // getHeaderNames()
        final Map params = new HashMap();
        request.fuzzy.getParameter(mf.expectsAny()).does(new MethodAction(){
            public Object perform(MethodActionEvent event) throws Throwable {
                return params.get(event.getArguments()[0]);
            }
        }).any();

        StringBuffer url = new StringBuffer(pathInfo);
        char c = '?';
        if (parameters != null) {
            url.append('/');
            for (int i = 0; i < parameters.length; i++) {
                if (parameters[i].length != 2) {
                    throw new IllegalArgumentException(
                        "Supplied parameter " +
                        i +
                        " has incorrect " +
                        "length: expected 2 got " +
                        parameters[i].length);
                }
                url.append(c).append(parameters[i][0]).append("=").append(parameters[i][1]);
                c = '&';
                params.put(parameters[i][0], parameters[i][1]);
            }
        }

        // Hack to enable gif support without having a config file.
        if (enableGif) {
            params.put("v.gifEnabled", "true");
            url.append(c).append("v.gifEnabled=true");
        }

        request.expects.getParameterNames().does(new MethodAction() {
            public Object perform(MethodActionEvent event) throws Throwable {
                return Collections.enumeration(params.keySet());
            }
        }).any();

        final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        ServletOutputStream os = new ServletOutputStream() {
            public void write(int b) {
                outputStream.write(b);
            }
        };
        HttpServletResponseMock response = new HttpServletResponseMock(
            "test-response", expectationContainer);
        response.expects.getOutputStream().returns(os).any();

        // content type should only be set once
        response.fuzzy.setContentType(mf.expectsAny()).returns().any();
        response.fuzzy.setDateHeader(mf.expectsAny(), mf.expectsAny()).returns().any();
        response.fuzzy.addDateHeader(mf.expectsAny(), mf.expectsAny()).returns().any();
        response.fuzzy.addHeader(mf.expectsAny(), mf.expectsAny()).returns().any();
        response.fuzzy.addIntHeader(mf.expectsAny(), mf.expectsAny()).returns().any();

        response.fuzzy.setContentLength(mf.expectsAny()).returns().any();

        ICSParamBuilder builder = new ICSParamBuilder();
        builder.build(new URI(url.toString()),
                      descriptor.getInputParameters());
View Full Code Here


        process.setPipeline(pipeline);

        dependencies = new Dependency[1];
        pipelineContextMock.expects.getDependencyContext().returns(
            dependencyContextMock).any();
        final MockFactory mockFactory = MockFactory.getDefaultInstance();
        dependencyContextMock.fuzzy.addDependency(
            mockFactory.expectsAny()).does(new MethodAction() {
                public Object perform(MethodActionEvent event) throws Throwable {
                    assertNull(dependencies[0]);
                    dependencies[0] = (Dependency) event.getArguments()[0];
                    return null;
                }
View Full Code Here

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

     */
    public ManagedServiceFactory createManagedServiceFactory() throws NoSuchMethodException {

        final BundleContextMock contextMock =
            new BundleContextMock("contextMock", expectations);
        final MockFactory mockFactory = MockFactory.getDefaultInstance();
        final Method registerServiceMethod = BundleContext.class.getMethod(
            "registerService",
            new Class[]{String.class, Object.class, Dictionary.class});
        final MethodIdentifier identifier =
            MethodIdentifier.getMethodIdentifier(registerServiceMethod);
        contextMock.fuzzy.registerService(
            identifier,
            EventHandler.class.getName(),
            mockFactory.expectsInstanceOf(ReportEventHandler.class),
            mockFactory.expectsInstanceOf(Dictionary.class)).returns(null).any();

        return new AbstractManagedServiceFactory(contextMock) {

            protected ReportEventHandler createEventHandler(
                Dictionary configuration)
View Full Code Here


    private MarinerServletApplication createMarinerApplication(String configURL)
            throws ServletException, IOException {

        MockFactory mockFactory = MockFactory.getDefaultInstance();
        ExpectationBuilder expectations = mockFactory.createUnorderedBuilder();

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

        final ServletContextMock servletContextMock =
                new ServletContextMock("servletContextMock", expectations);

        // =====================================================================
        //   Set Expectations
        // =====================================================================

        servletContextMock.expects.getAttribute("volantis").returns(null);
        servletContextMock.fuzzy.setAttribute("volantis",
                mockFactory.expectsInstanceOf(Volantis.class));

        File webinfDir;
        String webapp;
        if (configURL.startsWith("file:")) {
            configURL = configURL.substring(5);
            File file = new File(configURL);
            webinfDir = file.getParentFile();
            webapp = webinfDir.getParent();
        } else {
            throw new IllegalStateException(
                    "Class relative resources 'webapp' not a file URL");
        }

        createDeviceRepository(
                new File(webinfDir, "test-devices"),
                new File(webinfDir, "test-devices.mdpr"));

        servletContextMock.expects.getRealPath("/").returns(webapp).any();
        servletContextMock.expects.getInitParameter("config.file")
                .returns("/WEBINF/mcs-config.xml").any();
        servletContextMock.expects.getInitParameter("mcs.log4j.config.file")
                .returns("/WEBINF/mcs-log4j.xml").any();

        servletContextMock.expects.getAttribute("marinerApplication")
                .returns(null);
        servletContextMock.fuzzy
                .setAttribute("marinerApplication",
                        mockFactory.expectsInstanceOf(
                                MarinerServletApplication.class));

        MarinerServletApplication servletApplication =
                MarinerServletApplication.getInstance(servletContextMock);
View Full Code Here

        CacheControlConstraints constraints =
                CacheControlConstraints.getDefaultConstraints();
        CacheControlConstraintsMap constraintsMap =
                new SingleCacheControlConstraintsMap(constraints);

        MockFactory factory = MockFactory.getDefaultInstance();
        ExpectationBuilder localExpectations = factory.createUnorderedBuilder();

        RuntimeProjectMock projectMock = new RuntimeProjectMock("test",
                localExpectations);

        projectMock.expects.getCacheControlConstraintsMap()
View Full Code Here

TOP

Related Classes of com.volantis.testtools.mock.MockFactory

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.