use of org.jmock.api.Invocation in project sling by apache.
the class StartupFilterImplTest method setProvider.
private void setProvider(final TestProvider provider) throws Exception {
final BundleContext bundleContext = mockery.mock(BundleContext.class);
final Action storeStatus = new Action() {
@Override
public void describeTo(Description d) {
d.appendText("Store HTTP response values");
}
@Override
public Object invoke(Invocation invocation) throws Throwable {
lastReturnedStatus = (Integer) invocation.getParameter(0);
return null;
}
};
messageWriter = new StringWriter();
final PrintWriter responseWriter = new PrintWriter(messageWriter);
final Map<String, Object> props = new HashMap<String, Object>();
props.put(StartupFilterImpl.ACTIVE_BY_DEFAULT_PROP, Boolean.TRUE);
final ServiceReference[] providerRefs = provider == null ? null : new ServiceReference[] { provider };
mockery.checking(new Expectations() {
{
allowing(bundleContext).createFilter(with(any(String.class)));
allowing(bundleContext).addServiceListener(with(any(ServiceListener.class)));
allowing(bundleContext).addServiceListener(with(any(ServiceListener.class)), with(any(String.class)));
allowing(bundleContext).getServiceReferences(StartupInfoProvider.class.getName(), null);
will(returnValue(providerRefs));
allowing(bundleContext).getService(with(any(ServiceReference.class)));
will(returnValue(provider));
allowing(bundleContext).getProperty(with("felix.webconsole.manager.root"));
will(returnValue(CONSOLE_ROOT));
allowing(bundleContext).registerService(with(equal(Filter.class)), with(any(Filter.class)), with(any(Dictionary.class)));
will(new DoAllAction(new ChangeInteger(activeFilterCount, true), returnValue(serviceRegistration)));
allowing(response).setStatus((with(any(Integer.class))));
will(storeStatus);
allowing(response).setContentType("text/plain");
allowing(response).getWriter();
will(returnValue(responseWriter));
allowing(response).setCharacterEncoding(with(any(String.class)));
allowing(serviceRegistration).unregister();
will(new ChangeInteger(activeFilterCount, false));
allowing(request).getServletPath();
will(returnValue(""));
allowing(request).getPathInfo();
will(returnValue(getPathInfo()));
allowing(chain).doFilter(with(any(ServletRequest.class)), with(any(ServletResponse.class)));
}
});
filter.setup(bundleContext, props);
}
use of org.jmock.api.Invocation in project estatio by estatio.
the class LeaseTerm_Test method returnLeaseTerm.
private Action returnLeaseTerm() {
return new Action() {
@Override
public Object invoke(Invocation invocation) throws Throwable {
LeaseItem leaseItem = (LeaseItem) invocation.getParameter(0);
LeaseTerm leaseTerm = (LeaseTerm) invocation.getParameter(1);
LocalDate startDate = (LocalDate) invocation.getParameter(2);
LocalDate endDate = (LocalDate) invocation.getParameter(3);
LeaseTermForTesting ltt = new LeaseTermForTesting();
// relationships
ltt.setLeaseItem(leaseItem);
leaseItem.getTerms().add(ltt);
ltt.setPrevious(leaseTerm);
leaseTerm.setNext(ltt);
// set values
ltt.modifyStartDate(startDate);
ltt.modifyEndDate(endDate);
ltt.clockService = mockClockService;
return ltt;
}
@Override
public void describeTo(Description description) {
description.appendText("new Lease Term under item and with previous term");
}
};
}
use of org.jmock.api.Invocation in project activemq-artemis by apache.
the class DiscoveryNetworkReconnectTest method setUp.
@Before
public void setUp() throws Exception {
context = new JUnit4Mockery() {
{
setImposteriser(ClassImposteriser.INSTANCE);
}
};
brokerA = new BrokerService();
brokerA.setBrokerName("BrokerA");
configure(brokerA);
brokerA.addConnector("tcp://localhost:0");
brokerA.start();
brokerA.waitUntilStarted();
proxy = new SocketProxy(brokerA.getTransportConnectors().get(0).getConnectUri());
managementContext = context.mock(ManagementContext.class);
context.checking(new Expectations() {
{
allowing(managementContext).getJmxDomainName();
will(returnValue("Test"));
allowing(managementContext).setBrokerName("BrokerNC");
allowing(managementContext).start();
allowing(managementContext).isCreateConnector();
allowing(managementContext).stop();
allowing(managementContext).isConnectorStarted();
// expected MBeans
allowing(managementContext).registerMBean(with(any(Object.class)), with(equal(new ObjectName("Test:type=Broker,brokerName=BrokerNC"))));
allowing(managementContext).registerMBean(with(any(Object.class)), with(equal(new ObjectName("Test:type=Broker,brokerName=BrokerNC,service=Health"))));
allowing(managementContext).registerMBean(with(any(Object.class)), with(equal(new ObjectName("Test:type=Broker,brokerName=BrokerNC,connector=networkConnectors,networkConnectorName=NC"))));
allowing(managementContext).registerMBean(with(any(Object.class)), with(equal(new ObjectName("Test:type=Broker,brokerName=BrokerNC,service=Log4JConfiguration"))));
allowing(managementContext).registerMBean(with(any(Object.class)), with(equal(new ObjectName("Test:type=Broker,brokerName=BrokerNC,destinationType=Topic,destinationName=ActiveMQ.Advisory.Connection"))));
allowing(managementContext).registerMBean(with(any(Object.class)), with(equal(new ObjectName("Test:type=Broker,brokerName=BrokerNC,destinationType=Topic,destinationName=ActiveMQ.Advisory.NetworkBridge"))));
allowing(managementContext).registerMBean(with(any(Object.class)), with(equal(new ObjectName("Test:type=Broker,brokerName=BrokerNC,destinationType=Topic,destinationName=ActiveMQ.Advisory.MasterBroker"))));
allowing(managementContext).registerMBean(with(any(Object.class)), with(equal(new ObjectName("Test:type=Broker,brokerName=BrokerNC,service=jobScheduler,jobSchedulerName=JMS"))));
atLeast(maxReconnects - 1).of(managementContext).registerMBean(with(any(Object.class)), with(new NetworkBridgeObjectNameMatcher<>(new ObjectName("Test:type=Broker,brokerName=BrokerNC,connector=networkConnectors,networkConnectorName=NC,networkBridge=localhost/127.0.0.1_" + proxy.getUrl().getPort()))));
will(new CustomAction("signal register network mbean") {
@Override
public Object invoke(Invocation invocation) throws Throwable {
LOG.info("Mbean Registered: " + invocation.getParameter(0));
mbeanRegistered.release();
return new ObjectInstance((ObjectName) invocation.getParameter(1), "discription");
}
});
atLeast(maxReconnects - 1).of(managementContext).unregisterMBean(with(new NetworkBridgeObjectNameMatcher<>(new ObjectName("Test:type=Broker,brokerName=BrokerNC,connector=networkConnectors,networkConnectorName=NC,networkBridge=localhost/127.0.0.1_" + proxy.getUrl().getPort()))));
will(new CustomAction("signal unregister network mbean") {
@Override
public Object invoke(Invocation invocation) throws Throwable {
LOG.info("Mbean Unregistered: " + invocation.getParameter(0));
mbeanUnregistered.release();
return null;
}
});
allowing(managementContext).unregisterMBean(with(equal(new ObjectName("Test:type=Broker,brokerName=BrokerNC"))));
allowing(managementContext).unregisterMBean(with(equal(new ObjectName("Test:type=Broker,brokerName=BrokerNC,service=Health"))));
allowing(managementContext).unregisterMBean(with(equal(new ObjectName("Test:type=Broker,brokerName=BrokerNC,connector=networkConnectors,networkConnectorName=NC"))));
allowing(managementContext).unregisterMBean(with(equal(new ObjectName("Test:type=Broker,brokerName=BrokerNC,service=Log4JConfiguration"))));
allowing(managementContext).unregisterMBean(with(equal(new ObjectName("Test:type=Broker,brokerName=BrokerNC,destinationType=Topic,destinationName=ActiveMQ.Advisory.Connection"))));
allowing(managementContext).unregisterMBean(with(equal(new ObjectName("Test:type=Broker,brokerName=BrokerNC,destinationType=Topic,destinationName=ActiveMQ.Advisory.NetworkBridge"))));
allowing(managementContext).unregisterMBean(with(equal(new ObjectName("Test:type=Broker,brokerName=BrokerNC,destinationType=Topic,destinationName=ActiveMQ.Advisory.MasterBroker"))));
}
});
brokerB = new BrokerService();
brokerB.setManagementContext(managementContext);
brokerB.setBrokerName("BrokerNC");
configure(brokerB);
}
use of org.jmock.api.Invocation in project xwiki-platform by xwiki.
the class IntegrationTest method initialize.
@RenderingTestSuite.Initialized
@SuppressWarnings("unchecked")
public void initialize(final MockingComponentManager componentManager) throws Exception {
Mockery mockery = new JUnit4Mockery();
// Since we have a dependency on XWiki Platform Oldcore the Context Component Manager will be found and the
// test will try to look up the Dashboard macro in the User and Wiki Component Manager and thus need a Current
// User and a Current Wiki. It's easier for this test to simply unregister the Context Component Manager rather
// than have to provide mocks for them.
componentManager.unregisterComponent(ComponentManager.class, "context");
final SkinExtension mockSsfx = componentManager.registerMockComponent(mockery, SkinExtension.class, "ssfx", "ssfxMock");
final SkinExtension mockJsfx = componentManager.registerMockComponent(mockery, SkinExtension.class, "jsfx", "jsfxMock");
mockery.checking(new Expectations() {
{
allowing(mockSsfx).use(with("uicomponents/container/columns.css"), with(any(Map.class)));
allowing(mockSsfx).use(with("uicomponents/dashboard/dashboard.css"), with(any(Map.class)));
allowing(mockJsfx).use(with("js/scriptaculous/dragdrop.js"));
allowing(mockJsfx).use(with("js/scriptaculous/effects.js"));
allowing(mockJsfx).use(with("uicomponents/dashboard/dashboard.js"), with(any(Map.class)));
}
});
final GadgetSource mockGadgetSource = componentManager.registerMockComponent(mockery, GadgetSource.class);
mockery.checking(new Expectations() {
{
// Mock gadget for macrodashboard_nested_velocity.test
allowing(mockGadgetSource).getGadgets(with("nested_velocity"), with(any(MacroTransformationContext.class)));
will(returnValue(Arrays.asList(new Gadget("0", Arrays.asList(new WordBlock("title")), Arrays.asList(new MacroMarkerBlock("velocity", Collections.emptyMap(), "someVelocityCodeHere", Collections.singletonList(new WordBlock("someVelocityOutputHere")), true)), "1,1"))));
// Mock gadget for macrodashboard1.test
allowing(mockGadgetSource).getGadgets(with(aNull(String.class)), with(any(MacroTransformationContext.class)));
will(returnValue(Arrays.asList(new Gadget("0", Arrays.<Block>asList(new WordBlock("title")), Arrays.<Block>asList(new WordBlock("content")), "1,1"))));
allowing(mockGadgetSource).getDashboardSourceMetadata(with(AnyOf.anyOf(aNull(String.class), any(String.class))), with(any(MacroTransformationContext.class)));
will(returnValue(Collections.<Block>emptyList()));
allowing(mockGadgetSource).isEditing();
// return true on is editing, to take as many paths possible
will(returnValue(true));
}
});
// Mock VelocityManager used in macrodashboard_nested_velocity.test because we do not have an XWikiContext
// instance in the ExecutionContext.
final VelocityManager mockVelocityManager = componentManager.registerMockComponentWithId(mockery, VelocityManager.class, "velocityManagerMock");
mockery.checking(new Expectations() {
{
allowing(mockVelocityManager).getVelocityContext();
will(returnValue(new VelocityContext()));
allowing(mockVelocityManager).getCurrentVelocityContext();
will(returnValue(new VelocityContext()));
allowing(mockVelocityManager).getVelocityEngine();
will(doAll(new CustomAction("mockGetVelocityEngine") {
@Override
public Object invoke(Invocation invocation) throws Throwable {
VelocityEngine velocityEngine = componentManager.getInstance(VelocityEngine.class);
Properties properties = new Properties();
properties.setProperty("resource.loader", "file");
velocityEngine.initialize(properties);
return velocityEngine;
}
}));
allowing(mockVelocityManager).evaluate(with(any(Writer.class)), with(any(String.class)), with(any(Reader.class)));
will(doAll(new CustomAction("mockEvaluate") {
@Override
public Object invoke(Invocation invocation) throws Throwable {
VelocityEngine velocityEngine = mockVelocityManager.getVelocityEngine();
return velocityEngine.evaluate(mockVelocityManager.getVelocityContext(), (Writer) invocation.getParameter(0), (String) invocation.getParameter(1), (Reader) invocation.getParameter(2));
}
}));
}
});
componentManager.registerMockComponent(mockery, ContextualAuthorizationManager.class);
}
use of org.jmock.api.Invocation in project motan by weibocom.
the class NettyHttpRequestHandlerTest method testServerStatus.
@Test
public void testServerStatus() throws Exception {
final MessageHandler messageHandler = mockery.mock(MessageHandler.class);
final ChannelHandlerContext ctx = mockery.mock(ChannelHandlerContext.class);
mockery.checking(new Expectations() {
{
allowing(ctx).write(with(any(FullHttpResponse.class)));
will(new CustomAction("verify") {
@Override
public Object invoke(Invocation invocation) throws Throwable {
verifyStatus((FullHttpResponse) invocation.getParameter(0));
return null;
}
});
allowing(ctx).flush();
will(returnValue(null));
allowing(ctx).close();
will(returnValue(null));
allowing(messageHandler).handle(with(any(Channel.class)), with(any(Object.class)));
will(returnValue(null));
}
});
FullHttpRequest httpRequest = buildHttpRequest(NettyHttpRequestHandler.ROOT_PATH);
NettyHttpRequestHandler handler = new NettyHttpRequestHandler(null, messageHandler);
// 关闭心跳开关
MotanSwitcherUtil.setSwitcherValue(MotanConstants.REGISTRY_HEARTBEAT_SWITCHER, false);
handler.channelRead0(ctx, httpRequest);
// 打开心跳开关
MotanSwitcherUtil.setSwitcherValue(MotanConstants.REGISTRY_HEARTBEAT_SWITCHER, true);
handler.channelRead0(ctx, httpRequest);
}
Aggregations