Package org.jmock

Examples of org.jmock.Mockery


    private static final String CTX = "";

    public void test_getBaseUrl() {

        final Mockery ctx = new Mockery();
        final HttpServletRequest request = ctx.mock(HttpServletRequest.class);
        ctx.checking(new Expectations() {
            {
                // general setup on each calls
                allowing(request).getServerName();
                will(returnValue(NAME));
                allowing(request).getContextPath();
View Full Code Here


        TopologyConnectorServlet servlet = new TopologyConnectorServlet();
        PrivateAccessor.setField(servlet, "config", config);
        PrivateAccessor.setField(servlet, "clusterViewService", clusterViewService);
        PrivateAccessor.setField(servlet, "announcementRegistry", announcementRegistry);

        Mockery context = new JUnit4Mockery();
        final HttpService httpService = context.mock(HttpService.class);
        context.checking(new Expectations() {
            {
                allowing(httpService).registerServlet(with(any(String.class)),
                        with(any(Servlet.class)),
                        with(any(Dictionary.class)),
                        with(any(HttpContext.class)));
View Full Code Here

      return mockResourceResolverFactory(null);
    }

    public static ResourceResolverFactory mockResourceResolverFactory(final SlingRepository repositoryOrNull)
            throws Exception {
        Mockery context = new JUnit4Mockery();

        final ResourceResolverFactory resourceResolverFactory = context
                .mock(ResourceResolverFactory.class);
        // final ResourceResolver resourceResolver = new MockResourceResolver();
        // final ResourceResolver resourceResolver = new
        // MockedResourceResolver();

        context.checking(new Expectations() {
            {
                allowing(resourceResolverFactory)
                        .getAdministrativeResourceResolver(null);
                will(new Action() {
View Full Code Here

        return resourceResolverFactory;
    }

    public static SlingSettingsService mockSlingSettingsService(
            final String slingId) {
        Mockery context = new JUnit4Mockery();

        final SlingSettingsService settingsService = context
                .mock(SlingSettingsService.class);
        context.checking(new Expectations() {
            {
                allowing(settingsService).getSlingId();
                will(returnValue(slingId));
            }
        });
View Full Code Here

        });
        return settingsService;
    }

    public static ComponentContext mockComponentContext() {
        Mockery context = new JUnit4Mockery();
        final BundleContext bc = context.mock(BundleContext.class);
        context.checking(new Expectations() {
            {
                allowing(bc).registerService(with(any(String.class)),
                        with(any(Object.class)), with(any(Dictionary.class)));
                will(VoidAction.INSTANCE);
            }
        });

        final ComponentContext cc = context.mock(ComponentContext.class);
        context.checking(new Expectations() {
            {
                allowing(cc).getProperties();
                will(returnValue(new Properties()));

                allowing(cc).getBundleContext();
View Full Code Here

    @Test public void test_getTokenFile() {
        final File root = new File("bundle999").getAbsoluteFile();
        final SlingHomeAction slingHome = new SlingHomeAction();
        slingHome.setSlingHome(new File("sling").getAbsolutePath());

        Mockery context = new Mockery();
        final BundleContext bundleContext = context.mock(BundleContext.class);

        context.checking(new Expectations() {
            {
                // mock access to sling.home framework property
                allowing(bundleContext).getProperty("sling.home");
                will(slingHome);
View Full Code Here

* */
public class DeepNodeCreatorTest {

    @Test
    public void testExistingNode() throws Exception {
        final Mockery mockery = new Mockery();
        final DeepNodeCreator c = new DeepNodeCreator();
        final String path = "/foo/bar";
        final Session s = mockery.mock(Session.class);
        final Node n = mockery.mock(Node.class);
       
        mockery.checking(new Expectations() {{
            allowing(s).itemExists(path);
            will(returnValue(true));

            allowing(s).getItem(path);
            will(returnValue(n));
View Full Code Here

        final Node result = c.deepCreateNode(path, s, null);
        assertTrue("Expecting deepCreate to return existing node", result == n);
    }
   
    public void testCreateFromRoot() throws Exception {
        final Mockery mockery = new Mockery();
        final DeepNodeCreator c = new DeepNodeCreator();
        final String rootPath = "/";
        final String fooPath = "/foo";
        final String barPath = "/foo/bar";
        final Session s = mockery.mock(Session.class);
        final Node root = mockery.mock(Node.class, rootPath);
        final Node foo = mockery.mock(Node.class, fooPath);
        final Node bar = mockery.mock(Node.class, barPath);
        final String testNodeType = "NT_TEST";
       
        mockery.checking(new Expectations() {{
            allowing(s).itemExists(barPath);
            will(returnValue(false));

            allowing(s).itemExists(fooPath);
            will(returnValue(false));
View Full Code Here

        final Node result = c.deepCreateNode(barPath, s, testNodeType);
        assertTrue("Expecting deepCreate to return create node", result == bar);
    }
   
    public void testCreateWithVariousTypes() throws Exception {
        final Mockery mockery = new Mockery();
       
        final String fooPath = "/foo";
        final String barPath = "/foo/bar";
        final String wiiPath = "/foo/bar/wii";
        final Session s = mockery.mock(Session.class);
        final Node foo = mockery.mock(Node.class, fooPath);
        final Node bar = mockery.mock(Node.class, barPath);
        final Node wii = mockery.mock(Node.class, wiiPath);
       
        mockery.checking(new Expectations() {{
            allowing(s).itemExists(wiiPath);
            will(returnValue(false));

            allowing(s).itemExists(barPath);
            will(returnValue(false));
View Full Code Here

    private static final String CONSOLE_ROOT = "/test/system/console";

    @Before
    public void setup() {
        activeFilterCount = new AtomicInteger();
        mockery = new Mockery();
        request = mockery.mock(HttpServletRequest.class);
        response = mockery.mock(HttpServletResponse.class);
        chain = mockery.mock(FilterChain.class);
        serviceRegistration = mockery.mock(ServiceRegistration.class);
        filter = new TestFilterImpl();
View Full Code Here

TOP

Related Classes of org.jmock.Mockery

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.