public void testDurableWithQueueThrowsException() throws Exception { Jms11Support jmsSupport = new Jms11Support(new JmsConnector(), null, false, false); Mock mockQueue = new Mock(Queue.class); Queue queue = (Queue) mockQueue.proxy(); String durableName = "durableName"; boolean noLocal = true; Mock mockSession = new Mock(Session.class); try { jmsSupport.createConsumer( (Session) mockSession.proxy(), queue, null, noLocal, durableName, false); } catch (JMSException jmsex) { // expected assertEquals( "Wrong exception text.", "A durable subscriber name was set but the destination was not a Topic", jmsex.getMessage()); } mockQueue.verify(); mockSession.verify(); }
@Test public void testHasPermissionProjectUserHasPermission() { projectManagerMock.expectAndReturn( "getProjectObj", P.args( P.eq(new Long(TestProjectShareTypePermissionChecker.PROJECT_PERMISSION.getParam1()))), TestProjectShareTypePermissionChecker.MOCK_PROJECT); final ProjectManager projectManager = (ProjectManager) projectManagerMock.proxy(); permissionManagerMock.expectAndReturn( "hasPermission", P.args( P.eq(Permissions.BROWSE), P.eq(TestProjectShareTypePermissionChecker.MOCK_PROJECT), P.eq(user)), Boolean.TRUE); final PermissionManager permissionManager = (PermissionManager) permissionManagerMock.proxy(); final ShareTypePermissionChecker checker = new ProjectShareTypePermissionChecker(projectManager, permissionManager, null); assertTrue( checker.hasPermission(user, TestProjectShareTypePermissionChecker.PROJECT_PERMISSION)); projectManagerMock.verify(); permissionManagerMock.verify(); }
@Test public void testHasPermissionProjectRoleNullUserHasNoPermission() { projectManagerMock.expectAndReturn( "getProjectObj", P.args( P.eq( new Long( TestProjectShareTypePermissionChecker.PROJECT_ROLE_PERMISSION.getParam1()))), TestProjectShareTypePermissionChecker.MOCK_PROJECT); final ProjectManager projectManager = (ProjectManager) projectManagerMock.proxy(); final PermissionManager permissionManager = (PermissionManager) permissionManagerMock.proxy(); final ProjectRoleManager projectRoleManager = (ProjectRoleManager) projectRoleManagerMock.proxy(); final ShareTypePermissionChecker checker = new ProjectShareTypePermissionChecker( projectManager, permissionManager, projectRoleManager); assertFalse( checker.hasPermission(null, TestProjectShareTypePermissionChecker.PROJECT_ROLE_PERMISSION)); projectManagerMock.verify(); permissionManagerMock.verify(); projectRoleManagerMock.verify(); }
protected void setUp() throws Exception { super.setUp(); bob = createMockUser("bob"); bill = createMockUser("bill"); issue = EntityUtils.createValue( "Issue", EasyMap.build( "id", new Long(1), "project", new Long(2), "workflowId", new Long(100), "reporter", "bob")); project = EntityUtils.createValue("Project", EasyMap.build("id", new Long(2))); condition = new AllowOnlyReporter(); wfc = new Mock(WorkflowContext.class); wfe = new Mock(WorkflowEntry.class); args = EasyMap.build("permission", "create issue"); transientVars = EasyMap.build("context", wfc.proxy(), "entry", wfe.proxy()); }
@Test(expected = PluginParseException.class) public void testCreateBadXml() { XmlDynamicPluginFactory factory = new XmlDynamicPluginFactory("foo"); Mock mockModuleDescriptorFactory = new Mock(ModuleDescriptorFactory.class); Mock mockArtifact = new Mock(PluginArtifact.class); mockArtifact.expectAndReturn("toFile", new File("sadfasdf")); factory.create( (PluginArtifact) mockArtifact.proxy(), (ModuleDescriptorFactory) mockModuleDescriptorFactory.proxy()); }
public void testDoExecute() throws Exception { MockHttpServletResponse response = JiraTestUtil.setupExpectedRedirect("ViewFieldLayoutSchemes.jspa"); Mock mockFieldLayoutShceme = new Mock(FieldLayoutScheme.class); mockFieldLayoutShceme.setStrict(true); String name = "some name"; mockFieldLayoutShceme.expectVoid("setName", P.args(new IsEqual(name))); String description = "Test Description"; mockFieldLayoutShceme.expectVoid("setDescription", P.args(new IsEqual(description))); mockFieldLayoutShceme.expectVoid("store"); Long id = new Long(1); mockFieldLayoutShceme.expectAndReturn("getId", id); FieldLayoutScheme fieldLayoutScheme = (FieldLayoutScheme) mockFieldLayoutShceme.proxy(); mockFieldLayoutManager.expectAndReturn( "getFieldLayoutSchemes", EasyList.build(fieldLayoutScheme)); mockFieldLayoutManager.expectAndReturn( "getMutableFieldLayoutScheme", P.args(new IsEqual(id)), fieldLayoutScheme); efls.setFieldLayoutSchemeName(name); efls.setFieldLayoutSchemeDescription(description); efls.setId(id); assertEquals(Action.NONE, efls.execute()); response.verify(); mockFieldLayoutShceme.verify(); mockFieldLayoutManager.verify(); }
public void testMessageResequencer() throws Exception { Mock session = MuleTestUtils.getMockSession(); UMOComponent testComponent = getTestComponent(getTestDescriptor("test", Apple.class.getName())); assertNotNull(testComponent); UMOInboundRouterCollection messageRouter = new InboundRouterCollection(); SimpleEventResequencer router = new SimpleEventResequencer(3); messageRouter.addRouter(router); messageRouter.setCatchAllStrategy(new LoggingCatchAllStrategy()); UMOMessage message1 = new MuleMessage("test event A"); UMOMessage message2 = new MuleMessage("test event B"); UMOMessage message3 = new MuleMessage("test event C"); UMOEndpoint endpoint = getTestEndpoint("Test1Provider", UMOEndpoint.ENDPOINT_TYPE_SENDER); UMOEvent event1 = new MuleEvent(message1, endpoint, (UMOSession) session.proxy(), false); UMOEvent event2 = new MuleEvent(message2, endpoint, (UMOSession) session.proxy(), false); UMOEvent event3 = new MuleEvent(message3, endpoint, (UMOSession) session.proxy(), false); assertTrue(router.isMatch(event1)); assertTrue(router.isMatch(event2)); assertTrue(router.isMatch(event3)); assertNull(router.process(event2)); assertNull(router.process(event3)); UMOEvent[] results = router.process(event1); assertNotNull(results); assertEquals(3, results.length); assertEquals("test event B", results[0].getMessageAsString()); assertEquals("test event C", results[1].getMessageAsString()); assertEquals("test event A", results[2].getMessageAsString()); // set a resequencing comparator router.setComparator(new EventPayloadComparator()); assertNull(router.process(event2)); assertNull(router.process(event3)); results = router.process(event1); assertNotNull(results); assertEquals(3, results.length); assertEquals("test event A", results[0].getMessageAsString()); assertEquals("test event B", results[1].getMessageAsString()); assertEquals("test event C", results[2].getMessageAsString()); }
public void testFilteringOutboundRouter() throws Exception { Mock session = MuleTestUtils.getMockSession(); OutboundRouterCollection messageRouter = new OutboundRouterCollection(); messageRouter.setCatchAllStrategy(new LoggingCatchAllStrategy()); UMOEndpoint endpoint1 = getTestEndpoint("Test1Provider", UMOEndpoint.ENDPOINT_TYPE_SENDER); assertNotNull(endpoint1); FilteringOutboundRouter router = new FilteringOutboundRouter(); PayloadTypeFilter filter = new PayloadTypeFilter(String.class); router.setFilter(filter); List endpoints = new ArrayList(); endpoints.add(endpoint1); router.setEndpoints(endpoints); assertFalse(router.isUseTemplates()); assertEquals(filter, router.getFilter()); UMOMessage message = new MuleMessage("test event"); assertTrue(router.isMatch(message)); session.expect("dispatchEvent", C.eq(message, endpoint1)); router.route(message, (UMOSession) session.proxy(), false); session.verify(); message = new MuleMessage("test event"); session.expectAndReturn("sendEvent", C.eq(message, endpoint1), message); UMOMessage result = router.route(message, (UMOSession) session.proxy(), true); assertNotNull(result); assertEquals(message, result); session.verify(); message = new MuleMessage(new Exception("test event")); assertTrue(!router.isMatch(message)); router.setTransformer( new AbstractTransformer() { public Object doTransform(Object src, String encoding) throws TransformerException { return ((Exception) src).getMessage(); } }); assertTrue(router.isMatch(message)); }
public void testDestinationTopic() throws Exception { // prepare the mock Mock mock = new Mock(Topic.class); Topic topic = (Topic) mock.proxy(); assertTrue(resolver.isTopic(topic)); mock.verify(); }
public void testDestinationNotTopic() throws Exception { // prepare the mock Mock mock = new Mock(Queue.class); Queue queue = (Queue) mock.proxy(); assertFalse(resolver.isTopic(queue)); mock.verify(); }
public void testNoLocalNotCalledForQueue() throws Exception { Jms11Support jmsSupport = new Jms11Support(new JmsConnector(), null, false, false); Mock mockQueue = new Mock(Queue.class); Queue queue = (Queue) mockQueue.proxy(); boolean noLocal = true; FullConstraintMatcher matcher = new FullConstraintMatcher(new Constraint[] {C.eq(queue), C.IS_NULL}); Mock mockSession = new Mock(Session.class); mockSession.expect("createConsumer", matcher); jmsSupport.createConsumer((Session) mockSession.proxy(), queue, null, noLocal, null, false); mockQueue.verify(); mockSession.verify(); }
public void testNoLocalCalledForNonDurableTopic() throws Exception { Jms11Support jmsSupport = new Jms11Support(new JmsConnector(), null, false, false); Mock mockTopic = new Mock(Topic.class); Topic topic = (Topic) mockTopic.proxy(); boolean noLocal = true; FullConstraintMatcher matcher = new FullConstraintMatcher(new Constraint[] {C.eq(topic), C.IS_NULL, C.IS_TRUE}); Mock mockSession = new Mock(Session.class); mockSession.expect("createConsumer", matcher); jmsSupport.createConsumer((Session) mockSession.proxy(), topic, null, noLocal, null, true); mockTopic.verify(); mockSession.verify(); }
protected void setUp() throws Exception { super.setUp(); mockPetStore = new Mock(PetStore.class); action = new AddPetToShoppingCart(); action.setPetStore((PetStore) mockPetStore.proxy()); pet = new Pet(); pet.setId(123); }
@Override protected void setUp() throws Exception { actionValidatorManager = new DefaultActionValidatorManager(); super.setUp(); mockValidatorFileParser = new Mock(ValidatorFileParser.class); actionValidatorManager.setValidatorFileParser( (ValidatorFileParser) mockValidatorFileParser.proxy()); mockValidatorFactory = new Mock(ValidatorFactory.class); actionValidatorManager.setValidatorFactory((ValidatorFactory) mockValidatorFactory.proxy()); stubValueStack = new StubValueStack(); ActionContext.setContext(new ActionContext(new HashMap<String, Object>())); ActionContext.getContext().setValueStack(stubValueStack); DefaultFileManagerFactory factory = new DefaultFileManagerFactory(); factory.setContainer(container); factory.setFileManager(new DefaultFileManager()); actionValidatorManager.setFileManagerFactory(factory); }
public void testSuccessfulExceptionRouter() throws Exception { Mock session = getMockSession(); OutboundMessageRouter messageRouter = new OutboundMessageRouter(); messageRouter.setCatchAllStrategy(new LoggingCatchAllStrategy()); UMOEndpoint endpoint1 = new MuleEndpoint("test://AlwaysFail", false); UMOEndpoint endpoint2 = new MuleEndpoint("test://AlwaysFail", false); UMOEndpoint endpoint3 = new MuleEndpoint("test://Dummy", false); ExceptionBasedRouter router = new ExceptionBasedRouter(); RegExFilter filter = new RegExFilter("(.*) event"); router.setFilter(filter); List endpoints = new ArrayList(); endpoints.add(endpoint1); endpoints.add(endpoint2); endpoints.add(endpoint3); router.setEndpoints(endpoints); assertEquals(filter, router.getFilter()); UMOMessage message = new MuleMessage("test event", null); assertTrue(router.isMatch(message)); // Only one dispatch should be called as the others should fail session.expect("dispatchEvent", C.eq(message, endpoint1)); router.route(message, (UMOSession) session.proxy(), false); session.verify(); message = new MuleMessage("test event", null); // Only one send should be called as the others should fail session.expectAndReturn("sendEvent", C.eq(message, endpoint1), message); UMOMessage result = router.route(message, (UMOSession) session.proxy(), true); assertNotNull(result); assertEquals(message, result); session.verify(); }
@Test public void test_should_set_property_hello() { BeanPropertyExpressionEnricher propertyExpressionEnricher = new BeanPropertyExpressionEnricher(); Mock muleMessageMock = new Mock(MuleMessage.class); TestObject testObject = new TestObject(); muleMessageMock.expectAndReturn("getPayload", testObject); propertyExpressionEnricher.enrich("hello", (MuleMessage) muleMessageMock.proxy(), "Test me"); assertEquals(testObject.getHello(), "Test me"); }
public void testValidConversion() { Mock mockManager = new Mock(UMOManager.class); try { MuleManager.setInstance((UMOManager) mockManager.proxy()); Object obj = getValidConvertedType(); mockManager.expectAndReturn(getLookupMethod(), C.eq("test://Test"), obj); Object result = getConverter().convert(obj.getClass(), "test://Test"); assertNotNull(result); mockManager.verify(); } finally { MuleManager.setInstance(null); } }
@Test public void testInitSuccessful() throws PluginParseException { MockControl mockRendererComponentFactoryDescriptorControl = MockClassControl.createControl(RendererComponentFactoryDescriptor.class); RendererComponentFactoryDescriptor mockRendererComponentFactoryDescriptor = (RendererComponentFactoryDescriptor) mockRendererComponentFactoryDescriptorControl.getMock(); Mock mockPlugin = new Mock(Plugin.class); final Mock mockRendererComponent = new Mock(RendererComponent.class); final RendererComponent originalRendererComponent = (RendererComponent) mockRendererComponent.proxy(); mockRendererComponentFactoryDescriptor.getPlugin(); mockRendererComponentFactoryDescriptorControl.setReturnValue(null); Map params = new HashMap(); params.put("rendererComponentClass", "java.lang.String"); mockRendererComponentFactoryDescriptor.getParams(); mockRendererComponentFactoryDescriptorControl.setReturnValue(params); mockRendererComponentFactoryDescriptor.getCompleteKey(); mockRendererComponentFactoryDescriptorControl.setReturnValue("pluginkey"); mockRendererComponentFactoryDescriptor.getPlugin(); mockRendererComponentFactoryDescriptorControl.setReturnValue(mockPlugin.proxy()); mockRendererComponentFactoryDescriptorControl.replay(); SimpleRendererComponentFactory simpleRendererComponentFactory = new SimpleRendererComponentFactory() { RendererComponent loadRendererComponent(Class rendererComponentClass) throws ClassNotFoundException { return originalRendererComponent; } }; simpleRendererComponentFactory.init(mockRendererComponentFactoryDescriptor); RendererComponent rendererComponent = simpleRendererComponentFactory.getRendererComponent(); assertNotNull(rendererComponent); assertEquals(originalRendererComponent, rendererComponent); }
@Test public void test_should_set_property_third() { BeanPropertyExpressionEnricher propertyExpressionEnricher = new BeanPropertyExpressionEnricher(); Mock muleMessageMock = new Mock(MuleMessage.class); TestObject testObject = new TestObject(); muleMessageMock.expectAndReturn("getPayload", testObject); propertyExpressionEnricher.enrich( "first.second.third", (MuleMessage) muleMessageMock.proxy(), "This is a test"); assertEquals(testObject.getFirst().getSecond().getThird(), "This is a test"); }
public void testInvalidConversion() { Mock mockManager = new Mock(UMOManager.class); MuleManager.setInstance((UMOManager) mockManager.proxy()); Object obj = getValidConvertedType(); mockManager.expectAndReturn(getLookupMethod(), C.eq("TestBad"), null); try { getConverter().convert(obj.getClass(), "TestBad"); fail("should throw an exception if not found"); } catch (Exception e) { // exprected mockManager.verify(); } finally { MuleManager.setInstance(null); } }
@Test public void testHasPermissionNoProject() { projectManagerMock.expectAndReturn( "getProjectObj", P.args( P.eq(new Long(TestProjectShareTypePermissionChecker.PROJECT_PERMISSION.getParam1()))), null); final ProjectManager projectManager = (ProjectManager) projectManagerMock.proxy(); final ShareTypePermissionChecker checker = new ProjectShareTypePermissionChecker(projectManager, null, null); assertFalse( checker.hasPermission(user, TestProjectShareTypePermissionChecker.PROJECT_PERMISSION)); projectManagerMock.verify(); }
public void testDoDefault() throws Exception { Long id = new Long(1); Mock mockFieldLayoutScheme = new Mock(FieldLayoutScheme.class); mockFieldLayoutScheme.setStrict(true); String name = "Test Name"; mockFieldLayoutScheme.expectAndReturn("getName", name); String description = "Test Description"; mockFieldLayoutScheme.expectAndReturn("getDescription", description); mockFieldLayoutManager.expectAndReturn( "getMutableFieldLayoutScheme", P.args(new IsEqual(id)), mockFieldLayoutScheme.proxy()); efls.setId(id); assertEquals(Action.INPUT, efls.doDefault()); assertEquals(name, efls.getFieldLayoutSchemeName()); assertEquals(description, efls.getFieldLayoutSchemeDescription()); mockFieldLayoutScheme.verify(); mockFieldLayoutManager.verify(); }
public void testLifeCycleMethods() throws Exception { getManager(true); Mock mockPool = new Mock(ObjectPool.class); mockPool.expect("onAdd", C.IS_NOT_NULL); mockPool.expect("onRemove", C.IS_NOT_NULL); MuleDescriptor descriptor = getTestDescriptor("apple", Apple.class.getName()); CommonsPoolProxyFactory factory = (CommonsPoolProxyFactory) getProxyFactory(descriptor, (ObjectPool) mockPool.proxy()); assertNotNull(factory); Object obj = factory.makeObject(); assertNotNull(obj); assertTrue(factory.validateObject(obj)); factory.activateObject(obj); factory.passivateObject(obj); factory.destroyObject(obj); }
@Test public void testInitInvalidClass() { MockControl mockRendererComponentFactoryDescriptorControl = MockClassControl.createControl(RendererComponentFactoryDescriptor.class); RendererComponentFactoryDescriptor mockRendererComponentFactoryDescriptor = (RendererComponentFactoryDescriptor) mockRendererComponentFactoryDescriptorControl.getMock(); Mock mockPlugin = new Mock(Plugin.class); mockRendererComponentFactoryDescriptor.getPlugin(); mockRendererComponentFactoryDescriptorControl.setReturnValue(null); Map params = new HashMap(); params.put("rendererComponentClass", "com.test.invalid.class"); mockRendererComponentFactoryDescriptor.getParams(); mockRendererComponentFactoryDescriptorControl.setReturnValue(params); mockRendererComponentFactoryDescriptor.getCompleteKey(); mockRendererComponentFactoryDescriptorControl.setReturnValue("pluginkey"); mockRendererComponentFactoryDescriptor.getPlugin(); mockRendererComponentFactoryDescriptorControl.setReturnValue(mockPlugin.proxy()); mockPlugin.expectAndThrow( "loadClass", new Constraint[] {new IsEqual("com.test.invalid.class"), new IsAnything()}, new ClassNotFoundException()); mockRendererComponentFactoryDescriptorControl.replay(); SimpleRendererComponentFactory simpleRendererComponentFactory = new SimpleRendererComponentFactory() { RendererComponent loadRendererComponent(Class rendererComponentClass) throws ClassNotFoundException { throw new ClassNotFoundException(); } }; try { simpleRendererComponentFactory.init(mockRendererComponentFactoryDescriptor); fail("Expected exception"); } catch (PluginParseException e) { assertTrue(e.getMessage().indexOf("Could not load renderer") >= 0); assertTrue(e.getMessage().indexOf("pluginkey") > 0); assertTrue(e.getMessage().indexOf("com.test.invalid.class") > 0); } }
public void testDoValidationDuplicateName() throws Exception { Mock mockFieldLayoutShceme = new Mock(FieldLayoutScheme.class); mockFieldLayoutShceme.setStrict(true); String name = "some name"; mockFieldLayoutShceme.expectAndReturn("getName", name); // Return a different id to cause an error mockFieldLayoutShceme.expectAndReturn("getId", new Long(2)); Long id = new Long(1); FieldLayoutScheme fieldLayoutScheme = (FieldLayoutScheme) mockFieldLayoutShceme.proxy(); mockFieldLayoutManager.expectAndReturn( "getFieldLayoutSchemes", EasyList.build(fieldLayoutScheme)); efls.setFieldLayoutSchemeName(name); efls.setId(id); assertEquals(Action.INPUT, efls.execute()); assertEquals(1, efls.getErrors().size()); assertEquals( "A field configuration scheme with this name already exists.", efls.getErrors().get("fieldLayoutSchemeName")); mockFieldLayoutShceme.verify(); mockFieldLayoutManager.verify(); }
protected void setUp() throws Exception { super.setUp(); mockFieldLayoutManager = new Mock(FieldLayoutManager.class); mockFieldLayoutManager.setStrict(true); efls = new EditFieldLayoutScheme((FieldLayoutManager) mockFieldLayoutManager.proxy()); }
public void testOutboundMessageRouter() throws Exception { Mock session = MuleTestUtils.getMockSession(); session.expectAndReturn("getComponent", getTestComponent(getTestDescriptor("test", "blah"))); OutboundRouterCollection messageRouter = new OutboundRouterCollection(); messageRouter.setCatchAllStrategy(new LoggingCatchAllStrategy()); assertNotNull(messageRouter.getCatchAllStrategy()); UMOEndpoint endpoint1 = getTestEndpoint("Test1Provider", UMOEndpoint.ENDPOINT_TYPE_SENDER); assertNotNull(endpoint1); UMOEndpoint endpoint2 = getTestEndpoint("Test2Provider", UMOEndpoint.ENDPOINT_TYPE_SENDER); assertNotNull(endpoint2); FilteringOutboundRouter router1 = new FilteringOutboundRouter(); PayloadTypeFilter filter = new PayloadTypeFilter(String.class); router1.setFilter(filter); List endpoints = new ArrayList(); endpoints.add(endpoint1); router1.setEndpoints(endpoints); FilteringOutboundRouter router2 = new FilteringOutboundRouter(); PayloadTypeFilter filter2 = new PayloadTypeFilter(); filter2.setExpectedType(Exception.class); router2.setFilter(filter2); endpoints = new ArrayList(); endpoints.add(endpoint2); router2.setEndpoints(endpoints); messageRouter.addRouter(router1); assertEquals(1, messageRouter.getRouters().size()); assertNotNull(messageRouter.removeRouter(router1)); assertEquals(0, messageRouter.getRouters().size()); List list = new ArrayList(); list.add(router1); list.add(router2); messageRouter.setRouters(list); UMOMessage message = new MuleMessage("test event"); session.expect("dispatchEvent", C.eq(message, endpoint1)); messageRouter.route(message, (UMOSession) session.proxy(), false); session.verify(); message = new MuleMessage(new IllegalArgumentException()); session.expectAndReturn("getComponent", getTestComponent(getTestDescriptor("test", "blah"))); session.expect("dispatchEvent", C.eq(message, endpoint2)); messageRouter.route(message, (UMOSession) session.proxy(), false); session.verify(); FilteringOutboundRouter router3 = new FilteringOutboundRouter(); router3.setFilter(new PayloadTypeFilter(Object.class)); endpoints = new ArrayList(); endpoints.add(endpoint2); router3.setEndpoints(endpoints); messageRouter.addRouter(router3); // now the message should be routed twice to different endpoints message = new MuleMessage("testing multiple routing"); session.expectAndReturn("getComponent", getTestComponent(getTestDescriptor("test", "blah"))); session.expectAndReturn("getComponent", getTestComponent(getTestDescriptor("test", "blah"))); session.expect("dispatchEvent", C.eq(message, endpoint1)); session.expect("dispatchEvent", C.eq(message, endpoint2)); messageRouter.setMatchAll(true); messageRouter.route(message, (UMOSession) session.proxy(), false); session.verify(); }