public void testGetValidatorsFromInterface() { mockValidatorFileParser.expectAndReturn( "parseActionValidatorConfigs", C.args( C.IS_NOT_NULL, C.IS_NOT_NULL, C.eq("com/opensymphony/xwork2/SimpleAction-validation.xml")), new ArrayList()); mockValidatorFileParser.expectAndReturn( "parseActionValidatorConfigs", C.args( C.IS_NOT_NULL, C.IS_NOT_NULL, C.eq("com/opensymphony/xwork2/SimpleAction-validationAlias-validation.xml")), new ArrayList()); mockValidatorFileParser.expectAndReturn( "parseActionValidatorConfigs", C.args( C.IS_NOT_NULL, C.IS_NOT_NULL, C.eq("com/opensymphony/xwork2/test/DataAware-validation.xml")), new ArrayList()); mockValidatorFileParser.expectAndReturn( "parseActionValidatorConfigs", C.args( C.IS_NOT_NULL, C.IS_NOT_NULL, C.eq("com/opensymphony/xwork2/test/DataAware-validationAlias-validation.xml")), new ArrayList()); actionValidatorManager.getValidators(SimpleAction3.class, alias); mockValidatorFileParser.verify(); }
public void testSameAliasWithDifferentClass() { mockValidatorFileParser.expectAndReturn( "parseActionValidatorConfigs", C.args( C.IS_NOT_NULL, C.IS_NOT_NULL, C.eq("com/opensymphony/xwork2/SimpleAction-validation.xml")), new ArrayList()); mockValidatorFileParser.expectAndReturn( "parseActionValidatorConfigs", C.args( C.IS_NOT_NULL, C.IS_NOT_NULL, C.eq("com/opensymphony/xwork2/SimpleAction-validationAlias-validation.xml")), new ArrayList()); mockValidatorFileParser.expectAndReturn( "parseActionValidatorConfigs", C.args( C.IS_NOT_NULL, C.IS_NOT_NULL, C.eq("com/opensymphony/xwork2/test/SimpleAction2-validation.xml")), new ArrayList()); mockValidatorFileParser.expectAndReturn( "parseActionValidatorConfigs", C.args( C.IS_NOT_NULL, C.IS_NOT_NULL, C.eq("com/opensymphony/xwork2/test/SimpleAction2-validationAlias-validation.xml")), new ArrayList()); actionValidatorManager.getValidators(SimpleAction.class, alias); actionValidatorManager.getValidators(SimpleAction2.class, alias); mockValidatorFileParser.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()); }
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 testDoDefaultInvalidId() throws Exception { Long id = new Long(1); mockFieldLayoutManager.expectAndReturn( "getMutableFieldLayoutScheme", P.args(new IsEqual(id)), null); efls.setId(id); assertEquals(Action.INPUT, efls.doDefault()); checkSingleElementCollection(efls.getErrorMessages(), "Invalid id '" + id + "'."); mockFieldLayoutManager.verify(); }
public void testPermissionConditionNoIssue() { wfc.setupResult("getCaller", "bob"); wfe.setupResult("getId", new Long(101)); try { assertFalse(condition.passesCondition(transientVars, args, null)); fail("No issue; should have thrown a DataAccessException"); } catch (DataAccessException dae) { } }
public void testDoValidationInvalidId() throws Exception { mockFieldLayoutManager.expectAndReturn("getFieldLayoutSchemes", Collections.EMPTY_LIST); Long id = new Long(1); mockFieldLayoutManager.expectAndReturn( "getMutableFieldLayoutScheme", P.args(new IsEqual(id)), null); efls.setFieldLayoutSchemeName("Some Name"); efls.setId(id); assertEquals(Action.INPUT, efls.execute()); checkSingleElementCollection(efls.getErrorMessages(), "Invalid id '" + id + "'."); mockFieldLayoutManager.verify(); }
@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 testAddNonExistingPet() throws Exception { action.setShoppingCart((ShoppingCart) mockShoppingCart.proxy()); mockPetStore.expectAndReturn("getPet", new Long(123), null); action.setPetId(123); String result = action.execute(); assertEquals(Action.ERROR, result); mockPetStore.verify(); mockShoppingCart.verify(); }
public void testAddPet() throws Exception { action.setShoppingCart((ShoppingCart) mockShoppingCart.proxy()); mockPetStore.expectAndReturn("getPet", new Long(123), pet); mockShoppingCart.expect("addPet", pet); action.setPetId(123); String result = action.execute(); assertEquals(Action.SUCCESS, result); mockPetStore.verify(); mockShoppingCart.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"); }
@Before public void setUp() throws Exception { final MockProviderAccessor mpa = new MockProviderAccessor(); user = new User("test", mpa, new MockCrowdService()); permissionManagerMock = new Mock(PermissionManager.class); permissionManagerMock.setStrict(true); projectManagerMock = new Mock(ProjectManager.class); projectManagerMock.setStrict(true); projectRoleManagerMock = new Mock(ProjectRoleManager.class); projectRoleManagerMock.setStrict(true); }
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 testHasPermissionProjectNullRole() { 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(); projectRoleManagerMock.expectAndReturn( "getProjectRole", P.args(P.eq(TestProjectShareTypePermissionChecker.MOCK_ROLE.getId())), null); final ProjectRoleManager projectRoleManager = (ProjectRoleManager) projectRoleManagerMock.proxy(); final ShareTypePermissionChecker checker = new ProjectShareTypePermissionChecker( projectManager, permissionManager, projectRoleManager); assertFalse( checker.hasPermission(user, TestProjectShareTypePermissionChecker.PROJECT_ROLE_PERMISSION)); projectManagerMock.verify(); permissionManagerMock.verify(); projectRoleManagerMock.verify(); }
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 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"); }
@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 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 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); }
public void testAddPetWithPetIdOfZero() throws Exception { action.setShoppingCart((ShoppingCart) mockShoppingCart.proxy()); action.setPetId(0); String result = action.execute(); assertEquals(Action.ERROR, result); mockPetStore.verify(); mockShoppingCart.verify(); }
@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); } }
@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); }
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); }
@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(); }
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 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); }
public void testBuildsValidatorsForAliasError() { boolean pass = false; try { mockValidatorFileParser.expectAndReturn( "parseActionValidatorConfigs", C.args( C.IS_NOT_NULL, C.IS_NOT_NULL, C.eq("com/opensymphony/xwork2/TestBean-validation.xml")), new ArrayList()); mockValidatorFileParser.expectAndThrow( "parseActionValidatorConfigs", C.args( C.IS_NOT_NULL, C.IS_NOT_NULL, C.eq("com/opensymphony/xwork2/TestBean-badtest-validation.xml")), new ConfigurationException()); List validatorList = actionValidatorManager.getValidators(TestBean.class, "badtest"); } catch (XWorkException ex) { pass = true; } mockValidatorFileParser.verify(); assertTrue("Didn't throw exception on load failure", pass); }
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 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)); }