Search in sources :

Example 1 with IMocksControl

use of org.easymock.IMocksControl in project camel by apache.

the class DefaultCxfBindingTest method testPopupalteCxfResponseFromExchange.

@Test
public void testPopupalteCxfResponseFromExchange() {
    DefaultCxfBinding cxfBinding = new DefaultCxfBinding();
    cxfBinding.setHeaderFilterStrategy(new DefaultHeaderFilterStrategy());
    Exchange exchange = new DefaultExchange(context, ExchangePattern.InOut);
    org.apache.cxf.message.Exchange cxfExchange = new org.apache.cxf.message.ExchangeImpl();
    exchange.setProperty(CxfConstants.DATA_FORMAT_PROPERTY, DataFormat.PAYLOAD);
    exchange.getOut().setHeader("soapAction", "urn:hello:world");
    exchange.getOut().setHeader("MyFruitHeader", "peach");
    exchange.getOut().addAttachment("att-1", new DataHandler(new FileDataSource("pom.xml")));
    exchange.getOut().getAttachmentObject("att-1").setHeader("attachment-header", "value 1");
    IMocksControl control = EasyMock.createNiceControl();
    Endpoint endpoint = control.createMock(Endpoint.class);
    Binding binding = control.createMock(Binding.class);
    EasyMock.expect(endpoint.getBinding()).andReturn(binding);
    org.apache.cxf.message.Message cxfMessage = new org.apache.cxf.message.MessageImpl();
    EasyMock.expect(binding.createMessage()).andReturn(cxfMessage);
    cxfExchange.put(Endpoint.class, endpoint);
    control.replay();
    cxfBinding.populateCxfResponseFromExchange(exchange, cxfExchange);
    cxfMessage = cxfExchange.getOutMessage();
    assertNotNull(cxfMessage);
    Map<String, List<String>> headers = CastUtils.cast((Map<?, ?>) cxfMessage.get(Message.PROTOCOL_HEADERS));
    assertNotNull(headers);
    assertTrue(headers.size() == 2);
    verifyHeader(headers, "soapaction", "urn:hello:world");
    verifyHeader(headers, "SoapAction", "urn:hello:world");
    verifyHeader(headers, "SOAPAction", "urn:hello:world");
    verifyHeader(headers, "myfruitheader", "peach");
    verifyHeader(headers, "myFruitHeader", "peach");
    verifyHeader(headers, "MYFRUITHEADER", "peach");
    Collection<Attachment> attachments = cxfMessage.getAttachments();
    assertNotNull(attachments);
    assertNotNull(attachments.size() == 1);
    Attachment att = attachments.iterator().next();
    assertEquals("att-1", att.getId());
    assertEquals("value 1", att.getHeader("attachment-header"));
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Binding(org.apache.cxf.binding.Binding) Message(org.apache.cxf.message.Message) DefaultHeaderFilterStrategy(org.apache.camel.impl.DefaultHeaderFilterStrategy) Attachment(org.apache.cxf.message.Attachment) DataHandler(javax.activation.DataHandler) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) IMocksControl(org.easymock.IMocksControl) Endpoint(org.apache.cxf.endpoint.Endpoint) FileDataSource(javax.activation.FileDataSource) List(java.util.List) MessageImpl(org.apache.cxf.message.MessageImpl) Test(org.junit.Test)

Example 2 with IMocksControl

use of org.easymock.IMocksControl in project commons by twitter.

the class ServerSetImplTest method testUnwatchOnException.

@Test
public void testUnwatchOnException() throws Exception {
    IMocksControl control = createControl();
    ZooKeeperClient zkClient = control.createMock(ZooKeeperClient.class);
    Watcher onExpirationWatcher = control.createMock(Watcher.class);
    expect(zkClient.registerExpirationHandler(anyObject(Command.class))).andReturn(onExpirationWatcher);
    expect(zkClient.get()).andThrow(new InterruptedException());
    expect(zkClient.unregister(onExpirationWatcher)).andReturn(true);
    control.replay();
    Group group = new Group(zkClient, ZooDefs.Ids.OPEN_ACL_UNSAFE, "/blabla");
    ServerSetImpl serverset = new ServerSetImpl(zkClient, group);
    try {
        serverset.watch(new DynamicHostSet.HostChangeMonitor<ServiceInstance>() {

            @Override
            public void onChange(ImmutableSet<ServiceInstance> hostSet) {
            }
        });
        fail("Expected MonitorException");
    } catch (DynamicHostSet.MonitorException e) {
    // expected
    }
    control.verify();
}
Also used : Group(com.twitter.common.zookeeper.Group) Watcher(org.apache.zookeeper.Watcher) ServiceInstance(com.twitter.thrift.ServiceInstance) DynamicHostSet(com.twitter.common.net.pool.DynamicHostSet) IMocksControl(org.easymock.IMocksControl) ZooKeeperClient(com.twitter.common.zookeeper.ZooKeeperClient) Command(com.twitter.common.base.Command) Override(java.lang.Override) BaseZooKeeperTest(com.twitter.common.zookeeper.testing.BaseZooKeeperTest) Test(org.junit.Test)

Example 3 with IMocksControl

use of org.easymock.IMocksControl in project guice by google.

the class ContextPathTest method runTest.

private void runTest(final String requestURI, final String servletPath, final String contextPath, final boolean filterResult, final boolean fooResult, final boolean barResult) throws Exception {
    IMocksControl testControl = createControl();
    barServlet.clear();
    fooServlet.clear();
    TestFilterChain testFilterChain = new TestFilterChain();
    HttpServletRequest req = testControl.createMock(HttpServletRequest.class);
    HttpServletResponse res = testControl.createMock(HttpServletResponse.class);
    expect(req.getMethod()).andReturn("GET").anyTimes();
    expect(req.getRequestURI()).andReturn(requestURI).anyTimes();
    expect(req.getServletPath()).andReturn(servletPath).anyTimes();
    expect(req.getContextPath()).andReturn(contextPath).anyTimes();
    testControl.replay();
    guiceFilter.doFilter(req, res, testFilterChain);
    assertEquals(filterResult, testFilterChain.isTriggered());
    assertEquals(fooResult, fooServlet.isTriggered());
    assertEquals(barResult, barServlet.isTriggered());
    testControl.verify();
}
Also used : IMocksControl(org.easymock.IMocksControl) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse)

Example 4 with IMocksControl

use of org.easymock.IMocksControl in project intellij-community by JetBrains.

the class PyTestCreatorTest method testCreateTest.

public void testCreateTest() throws Exception {
    myFixture.configureByFile("/create_tests/create_tst.py");
    final IMocksControl mockControl = createNiceControl();
    final CreateTestDialog dialog = mockControl.createMock(CreateTestDialog.class);
    expect(dialog.getFileName()).andReturn("tests.py").anyTimes();
    expect(dialog.getClassName()).andReturn("Spam").anyTimes();
    // Target dir is first module source
    final VirtualFile root = ModuleRootManager.getInstance(myFixture.getModule()).getSourceRoots()[0];
    expect(dialog.getTargetDir()).andReturn(root.getCanonicalPath()).anyTimes();
    expect(dialog.getMethods()).andReturn(Arrays.asList("eggs", "eggs_and_ham")).anyTimes();
    mockControl.replay();
    WriteCommandAction.runWriteCommandAction(myFixture.getProject(), () -> {
        final PsiFile file = PyTestCreator.generateTest(myFixture.getProject(), dialog).getContainingFile();
        myFixture.configureByText(file.getFileType(), file.getText());
        myFixture.checkResultByFile("/create_tests/create_tst.expected.py");
    });
}
Also used : IMocksControl(org.easymock.IMocksControl) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile)

Example 5 with IMocksControl

use of org.easymock.IMocksControl in project karaf by apache.

the class DeployerTest method testUpdateSimpleFeature.

@Test
public void testUpdateSimpleFeature() throws Exception {
    IMocksControl c = EasyMock.createControl();
    final String dataDir = "data1";
    TestDownloadManager manager = new TestDownloadManager(getClass(), dataDir);
    RepositoryImpl repo = new RepositoryImpl(getClass().getResource(dataDir + "/features.xml").toURI());
    repo.load(true);
    Feature f100 = repo.getFeatures()[0];
    Feature f101 = repo.getFeatures()[1];
    Deployer.DeployCallback callback = c.createMock(Deployer.DeployCallback.class);
    BundleInstallSupport installSupport = c.createMock(BundleInstallSupportImpl.class);
    Deployer deployer = new Deployer(manager, resolver, installSupport, callback);
    final TestBundle bundleA = createTestBundle(1L, Bundle.ACTIVE, dataDir, "a100");
    callback.print(EasyMock.anyString(), EasyMock.anyBoolean());
    EasyMock.expectLastCall().anyTimes();
    callback.callListeners(DeploymentEvent.DEPLOYMENT_STARTED);
    EasyMock.expectLastCall();
    installSupport.stopBundle(EasyMock.eq(bundleA), anyInt());
    EasyMock.expectLastCall().andStubAnswer(() -> {
        bundleA.state = Bundle.RESOLVED;
        return null;
    });
    installSupport.updateBundle(EasyMock.eq(bundleA), EasyMock.anyObject(), EasyMock.anyObject());
    EasyMock.expectLastCall().andStubAnswer(new IAnswer<Object>() {

        @Override
        public Object answer() throws Throwable {
            URL loc = getClass().getResource(dataDir + "/" + "a101" + ".mf");
            Manifest man = new Manifest(loc.openStream());
            Hashtable<String, String> headers = new Hashtable<>();
            for (Map.Entry<Object, Object> attr : man.getMainAttributes().entrySet()) {
                headers.put(attr.getKey().toString(), attr.getValue().toString());
            }
            bundleA.update(headers);
            return null;
        }
    });
    installSupport.startBundle(EasyMock.eq(bundleA));
    EasyMock.expectLastCall();
    installSupport.replaceDigraph(EasyMock.anyObject(), EasyMock.anyObject());
    EasyMock.expectLastCall();
    callback.saveState(EasyMock.anyObject());
    EasyMock.expectLastCall();
    installSupport.installConfigs(f101);
    EasyMock.expectLastCall();
    installSupport.installLibraries(f101);
    EasyMock.expectLastCall();
    callback.callListeners(DeploymentEvent.BUNDLES_INSTALLED);
    EasyMock.expectLastCall();
    installSupport.resolveBundles(EasyMock.eq(Collections.singleton(bundleA)), EasyMock.anyObject(), EasyMock.anyObject());
    EasyMock.expectLastCall();
    callback.callListeners(DeploymentEvent.BUNDLES_RESOLVED);
    EasyMock.expectLastCall();
    installSupport.refreshPackages(EasyMock.eq(Collections.singleton(bundleA)));
    EasyMock.expectLastCall();
    callback.callListeners(FeatureEventMatcher.eq(new FeatureEvent(FeatureEvent.EventType.FeatureUninstalled, f100, FeaturesService.ROOT_REGION, false)));
    EasyMock.expectLastCall();
    callback.callListeners(FeatureEventMatcher.eq(new FeatureEvent(FeatureEvent.EventType.FeatureInstalled, f101, FeaturesService.ROOT_REGION, false)));
    EasyMock.expectLastCall();
    callback.callListeners(DeploymentEvent.DEPLOYMENT_FINISHED);
    EasyMock.expectLastCall();
    c.replay();
    Deployer.DeploymentState dstate = new Deployer.DeploymentState();
    dstate.state = new State();
    addToMapSet(dstate.state.installedFeatures, ROOT_REGION, f100.getId());
    addToMapSet(dstate.state.managedBundles, ROOT_REGION, 1L);
    dstate.bundles = new HashMap<>();
    dstate.bundles.put(1L, bundleA);
    dstate.bundlesPerRegion = new HashMap<>();
    addToMapSet(dstate.bundlesPerRegion, ROOT_REGION, 1L);
    dstate.features = new HashMap<>();
    dstate.features.put(f100.getId(), f100);
    dstate.features.put(f101.getId(), f101);
    dstate.filtersPerRegion = new HashMap<>();
    dstate.filtersPerRegion.put(ROOT_REGION, new HashMap<>());
    Deployer.DeploymentRequest request = new Deployer.DeploymentRequest();
    request.bundleUpdateRange = DEFAULT_BUNDLE_UPDATE_RANGE;
    request.featureResolutionRange = DEFAULT_FEATURE_RESOLUTION_RANGE;
    request.globalRepository = null;
    request.options = EnumSet.noneOf(Option.class);
    request.overrides = Collections.emptySet();
    request.stateChanges = Collections.emptyMap();
    request.updateSnaphots = UPDATE_SNAPSHOTS_NONE;
    request.requirements = new HashMap<>();
    addToMapSet(request.requirements, ROOT_REGION, f101.getName() + "/" + new VersionRange(f101.getVersion(), true));
    deployer.deploy(dstate, request);
    c.verify();
}
Also used : TestBundle(org.apache.karaf.features.internal.support.TestBundle) VersionRange(org.apache.felix.utils.version.VersionRange) Feature(org.apache.karaf.features.Feature) URL(java.net.URL) IMocksControl(org.easymock.IMocksControl) FeatureEvent(org.apache.karaf.features.FeatureEvent) Hashtable(java.util.Hashtable) Manifest(java.util.jar.Manifest) TestDownloadManager(org.apache.karaf.features.internal.support.TestDownloadManager) EasyMock.anyObject(org.easymock.EasyMock.anyObject) Test(org.junit.Test)

Aggregations

IMocksControl (org.easymock.IMocksControl)24 Test (org.junit.Test)14 HttpServletRequest (javax.servlet.http.HttpServletRequest)9 HttpServletResponse (javax.servlet.http.HttpServletResponse)9 FakeHttpServletRequest (com.google.gerrit.util.http.testutil.FakeHttpServletRequest)5 FakeHttpServletResponse (com.google.gerrit.util.http.testutil.FakeHttpServletResponse)5 FilterChain (javax.servlet.FilterChain)5 FilterConfig (javax.servlet.FilterConfig)5 Feature (org.apache.karaf.features.Feature)5 TestBundle (org.apache.karaf.features.internal.support.TestBundle)5 TestDownloadManager (org.apache.karaf.features.internal.support.TestDownloadManager)5 Bundle (org.osgi.framework.Bundle)5 EasyMockSupport (org.easymock.EasyMockSupport)4 Capture (org.easymock.Capture)3 HashMap (java.util.HashMap)2 List (java.util.List)2 MocksControl (org.easymock.internal.MocksControl)2 DBUtility (com.alibaba.cobar.manager.jdbcmock.domain.DBUtility)1 SalesOrder (com.alibaba.cobar.manager.jdbcmock.domain.SalesOrder)1 SalesOrderImpl (com.alibaba.cobar.manager.jdbcmock.domain.SalesOrderImpl)1