Search in sources :

Example 6 with Mockery

use of org.jmock.Mockery in project sling by apache.

the class VirtualInstance method startJetty.

public synchronized void startJetty() throws Throwable {
    if (jettyServer != null) {
        return;
    }
    servletContext = new ServletContextHandler(ServletContextHandler.NO_SECURITY);
    servletContext.setContextPath("/");
    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)));
        }
    });
    PrivateAccessor.setField(servlet, "httpService", httpService);
    ComponentContext cc = null;
    PrivateAccessor.invoke(servlet, "activate", new Class[] { ComponentContext.class }, new Object[] { cc });
    ServletHolder holder = new ServletHolder(servlet);
    servletContext.addServlet(holder, "/system/console/topology/*");
    jettyServer = new Server();
    jettyServer.setHandler(servletContext);
    Connector connector = new SelectChannelConnector();
    jettyServer.setConnectors(new Connector[] { connector });
    jettyServer.start();
}
Also used : Expectations(org.jmock.Expectations) Dictionary(java.util.Dictionary) SelectChannelConnector(org.eclipse.jetty.server.nio.SelectChannelConnector) Connector(org.eclipse.jetty.server.Connector) ComponentContext(org.osgi.service.component.ComponentContext) Server(org.eclipse.jetty.server.Server) TopologyConnectorServlet(org.apache.sling.discovery.base.connectors.ping.TopologyConnectorServlet) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) HttpContext(org.osgi.service.http.HttpContext) Mockery(org.jmock.Mockery) JUnit4Mockery(org.jmock.integration.junit4.JUnit4Mockery) JUnit4Mockery(org.jmock.integration.junit4.JUnit4Mockery) SelectChannelConnector(org.eclipse.jetty.server.nio.SelectChannelConnector) HttpService(org.osgi.service.http.HttpService) TopologyConnectorServlet(org.apache.sling.discovery.base.connectors.ping.TopologyConnectorServlet) Servlet(javax.servlet.Servlet) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 7 with Mockery

use of org.jmock.Mockery in project sling by apache.

the class FormAuthenticationHandlerTest method test_getTokenFile.

@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);
            // mock no data file support with file names starting with sl
            allowing(bundleContext).getDataFile(with(new StringStartsWith("sl")));
            will(returnValue(null));
            // mock data file support for any other name
            allowing(bundleContext).getDataFile(with(any(String.class)));
            will(new RVA(root));
        }
    });
    final FormAuthenticationHandler handler = new FormAuthenticationHandler();
    // test files relative to bundle context
    File relFile0 = handler.getTokenFile("", bundleContext);
    assertEquals(root, relFile0);
    String relName1 = "rel/path";
    File relFile1 = handler.getTokenFile(relName1, bundleContext);
    assertEquals(new File(root, relName1), relFile1);
    // test file relative to sling.home if no data file support
    String relName2 = "sl/rel_to_sling.home";
    File relFile2 = handler.getTokenFile(relName2, bundleContext);
    assertEquals(new File(slingHome.getSlingHome(), relName2), relFile2);
    // test file relative to current working directory
    String relName3 = "sl/test";
    slingHome.setSlingHome(null);
    File relFile3 = handler.getTokenFile(relName3, bundleContext);
    assertEquals(new File(relName3).getAbsoluteFile(), relFile3);
    // test absolute file return
    File absFile = new File("test").getAbsoluteFile();
    File absFile0 = handler.getTokenFile(absFile.getPath(), bundleContext);
    assertEquals(absFile, absFile0);
}
Also used : Expectations(org.jmock.Expectations) StringStartsWith(org.hamcrest.text.StringStartsWith) File(java.io.File) Mockery(org.jmock.Mockery) BundleContext(org.osgi.framework.BundleContext) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 8 with Mockery

use of org.jmock.Mockery in project sling by apache.

the class StartupFilterImplTest method setup.

@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();
    requestPath = "/NO_PATH_YET";
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FilterChain(javax.servlet.FilterChain) HttpServletResponse(javax.servlet.http.HttpServletResponse) Mockery(org.jmock.Mockery) ServiceRegistration(org.osgi.framework.ServiceRegistration) Before(org.junit.Before)

Example 9 with Mockery

use of org.jmock.Mockery in project sling by apache.

the class RefreshDependenciesUtilTest method setup.

@Before
public void setup() {
    jmock = new Mockery();
    pa = jmock.mock(PackageAdmin.class);
    rdu = new RefreshDependenciesUtil(pa);
    // Test bundle depends on A directly and does not depend on B
    target = setupBundle("testBundle", "com.targetImportsOne;com.targetImportsTwo", null);
    A = setupBundle("A", null, "com.targetImportsOne");
    B = setupBundle("B", "some.import", "some.export");
    // Test bundle depends on C which in turns depends on D
    C = setupBundle("C", "com.CimportsOne", "com.targetImportsTwo");
    D = setupBundle("D", null, "com.CimportsOne");
    E = setupBundle("E", null, null);
    // F imports and exports the same packages
    F = setupBundle("F", "foo", "foo");
}
Also used : PackageAdmin(org.osgi.service.packageadmin.PackageAdmin) Mockery(org.jmock.Mockery) Before(org.junit.Before)

Example 10 with Mockery

use of org.jmock.Mockery in project geode by apache.

the class CompiledAggregateFunctionJUnitTest method setUp.

@Before
public void setUp() throws Exception {
    context = new Mockery() {

        {
            setImposteriser(ClassImposteriser.INSTANCE);
            setThreadingPolicy(new Synchroniser());
        }
    };
    cache = context.mock(InternalCache.class);
    bucketList = new ArrayList();
    bucketList.add(1);
}
Also used : ArrayList(java.util.ArrayList) InternalCache(org.apache.geode.internal.cache.InternalCache) Synchroniser(org.jmock.lib.concurrent.Synchroniser) Mockery(org.jmock.Mockery) Before(org.junit.Before)

Aggregations

Mockery (org.jmock.Mockery)32 Before (org.junit.Before)21 Expectations (org.jmock.Expectations)14 Synchroniser (org.jmock.lib.concurrent.Synchroniser)12 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 JUnit4Mockery (org.jmock.integration.junit4.JUnit4Mockery)4 Test (org.junit.Test)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 ParameterSetter (com.ibatis.sqlmap.client.extensions.ParameterSetter)2 ResultGetter (com.ibatis.sqlmap.client.extensions.ResultGetter)2 StageDao (com.thoughtworks.go.server.dao.StageDao)2 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 Dictionary (java.util.Dictionary)2 HashMap (java.util.HashMap)2 Servlet (javax.servlet.Servlet)2 BundleContext (org.osgi.framework.BundleContext)2 ComponentContext (org.osgi.service.component.ComponentContext)2 JobInstanceLog (com.thoughtworks.go.domain.JobInstanceLog)1