List of usage examples for org.apache.commons.collections PredicateUtils equalPredicate
public static Predicate equalPredicate(Object value)
From source file:ClosureExample.java
public static void main(String args[]) { Closure ifClosure = ClosureUtils.ifClosure(PredicateUtils.equalPredicate(new Integer(20)), ClosureUtils.nopClosure(), ClosureUtils.exceptionClosure()); ifClosure.execute(new Integer(20)); // ifClosure.execute(new Integer(30)); }
From source file:com.jaspersoft.jasperserver.repository.test.RepositoryServiceDependentResourcesTest.java
@Test public void shouldFindAllDependantReportsForDataSource() { assertNotNull("RepositoryService service is not wired.", getRepositoryService()); assertNotNull("SearchCriteriaFactory service is not wired.", searchCriteriaFactory); String uri = "/datasources/JServerJNDIDS"; List<ResourceLookup> resources = getRepositoryService().getDependentResources(null, uri, searchCriteriaFactory, 0, 20); assertEquals("Should find 9 dependant resources.", 9, resources.size()); assertEquals("All resources should be lookup's.", 9, CollectionUtils.countMatches(resources, PredicateUtils.instanceofPredicate(ResourceLookup.class))); Collection types = CollectionUtils.collect(resources, TransformerUtils.invokerTransformer("getResourceType")); assertEquals("All lookup's should have type ReportUnit.", 9, CollectionUtils.countMatches(types, PredicateUtils.equalPredicate( "com.jaspersoft.jasperserver.api.metadata.jasperreports.domain.ReportUnit"))); String sortOrder = ArrayUtils.toString( CollectionUtils.collect(resources, TransformerUtils.invokerTransformer("getURIString")).toArray()); assertEquals("Resources should be sorted in order.", expectedOrder, sortOrder); }
From source file:com.daimler.spm.b2bacceleratoraddon.actions.StartWorkFlowForAdmin.java
protected B2BCustomerModel findB2BAdministratorForCustomer(final B2BCustomerModel customer) { final List<B2BCustomerModel> b2bAdminGroupUsers = new ArrayList<B2BCustomerModel>(getB2bUnitService() .getUsersOfUserGroup(getB2bUnitService().getParent(customer), B2BConstants.B2BADMINGROUP, true)); // remove the user who placed the order. CollectionUtils.filter(b2bAdminGroupUsers, PredicateUtils.notPredicate(PredicateUtils.equalPredicate(customer))); return (CollectionUtils.isNotEmpty(b2bAdminGroupUsers) ? b2bAdminGroupUsers.get(0) : null); }
From source file:com.dtolabs.rundeck.core.authorization.providers.TestYamlPolicy.java
public void testApplyTest() { {// w w w. ja va 2 s . c o m //match any resource with name=~ blah, and allow all actions final Object load = yaml.load("match: \n" + " name: '.*blah.*'\n" + "allow: '*'"); assertTrue(load instanceof Map); final Map ruleSection = (Map) load; final YamlPolicy.TypeRuleContextMatcher typeRuleContext = new YamlPolicy.TypeRuleContextMatcher( ruleSection, 1); final HashMap<String, String> resmap = new HashMap<String, String>(); resmap.put("name", "blah"); Converter<String, Predicate> test1 = new Converter<String, Predicate>() { public Predicate convert(String s) { return PredicateUtils.equalPredicate(s); } }; //test single value predicate value is returned assertTrue(typeRuleContext.applyTest(resmap, false, test1, "name", "blah")); assertFalse(typeRuleContext.applyTest(resmap, false, test1, "name", "blee")); assertFalse(typeRuleContext.applyTest(resmap, false, test1, "name", new ArrayList())); assertFalse(typeRuleContext.applyTest(resmap, false, test1, "name", Arrays.asList("blah"))); assertFalse(typeRuleContext.applyTest(resmap, false, test1, "name", Arrays.asList("blah", "blah"))); assertFalse(typeRuleContext.applyTest(resmap, false, test1, "name", new Object())); //test multivalue predicate value is AND result assertTrue(typeRuleContext.applyTest(resmap, true, test1, "name", Arrays.asList("blah"))); assertTrue(typeRuleContext.applyTest(resmap, true, test1, "name", Arrays.asList("blah", "blah"))); assertFalse(typeRuleContext.applyTest(resmap, true, test1, "name", Arrays.asList("blah", "blee"))); assertFalse(typeRuleContext.applyTest(resmap, true, test1, "name", Arrays.asList("blee", "blah"))); assertFalse(typeRuleContext.applyTest(resmap, true, test1, "name", Arrays.asList("blee", "blee"))); } }
From source file:com.dtolabs.rundeck.core.authorization.providers.TestYamlPolicy.java
public void testPredicateMatchRules() { //match any resource with name=~ blah, and allow all actions final Object load = yaml.load("match: \n" + " name: '.*blah.*'\n" + "allow: '*'"); assertTrue(load instanceof Map); final Map ruleSection = (Map) load; final YamlPolicy.TypeRuleContextMatcher typeRuleContext = new YamlPolicy.TypeRuleContextMatcher(ruleSection, 1);/*from w w w. j ava 2s. c o m*/ final HashMap<String, String> resmap = new HashMap<String, String>(); resmap.put("name", "blah"); resmap.put("king", "true"); resmap.put("wave", "bland"); Converter<String, Predicate> test1 = new Converter<String, Predicate>() { public Predicate convert(String s) { return PredicateUtils.equalPredicate(s); } }; HashMap rules = new HashMap(); //test empty rules assertTrue(typeRuleContext.predicateMatchRules(rules, resmap, false, test1)); assertTrue(typeRuleContext.predicateMatchRules(rules, resmap, true, test1)); //set rules, match false rules.put("name", "bloo"); assertFalse(typeRuleContext.predicateMatchRules(rules, resmap, false, test1)); assertFalse(typeRuleContext.predicateMatchRules(rules, resmap, true, test1)); //set rules, match true rules.put("name", "blah"); assertTrue(typeRuleContext.predicateMatchRules(rules, resmap, false, test1)); assertTrue(typeRuleContext.predicateMatchRules(rules, resmap, true, test1)); //set rules, match all, false rules.put("name", "blah"); rules.put("king", "false"); assertFalse(typeRuleContext.predicateMatchRules(rules, resmap, false, test1)); assertFalse(typeRuleContext.predicateMatchRules(rules, resmap, true, test1)); //set rules, match all, true rules.put("name", "blah"); rules.put("king", "true"); assertTrue(typeRuleContext.predicateMatchRules(rules, resmap, false, test1)); assertTrue(typeRuleContext.predicateMatchRules(rules, resmap, true, test1)); //set rules, match all, false rules.put("name", "blah"); rules.put("king", "true"); rules.put("wave", "bloo"); assertFalse(typeRuleContext.predicateMatchRules(rules, resmap, false, test1)); assertFalse(typeRuleContext.predicateMatchRules(rules, resmap, true, test1)); //set rules, match all, true rules.put("name", "blah"); rules.put("king", "true"); rules.put("wave", "bland"); assertTrue(typeRuleContext.predicateMatchRules(rules, resmap, false, test1)); assertTrue(typeRuleContext.predicateMatchRules(rules, resmap, true, test1)); //set rules, additional rules match false rules.put("name", "blah"); rules.put("king", "true"); rules.put("wave", "bland"); rules.put("another", "blee"); assertFalse(typeRuleContext.predicateMatchRules(rules, resmap, false, test1)); assertFalse(typeRuleContext.predicateMatchRules(rules, resmap, true, test1)); }
From source file:org.mifos.application.reports.business.service.BranchReportServiceIntegrationTest.java
public void testReturnsClientSummaryForGivenBranchAndRunDate() throws Exception { session.save(branchReport);/* www .j ava 2 s .c o m*/ List<BranchReportClientSummaryBO> retrievedClientSummaries = branchReportService .getClientSummaryInfo(BRANCH_ID, RUN_DATE_STR); Assert.assertNotNull(retrievedClientSummaries); Assert.assertEquals(3, retrievedClientSummaries.size()); Assert.assertTrue( exists(retrievedClientSummaries, PredicateUtils.equalPredicate(centerCountClientSummary))); Assert.assertTrue( exists(retrievedClientSummaries, PredicateUtils.equalPredicate(activeClientsCountSummary))); Assert.assertTrue( exists(retrievedClientSummaries, PredicateUtils.equalPredicate(activeBorrowersCountSummary))); }
From source file:org.mifos.application.reports.business.service.BranchReportServiceIntegrationTest.java
public void testReturnsLoanArrearsAgingInfo() throws Exception { session.save(branchReport);/*from w w w . j a v a 2 s . c o m*/ List<BranchReportLoanArrearsAgingBO> retrievedLoanArrearsAgingInfo = branchReportService .getLoanArrearsAgingInfo(BRANCH_ID, RUN_DATE_STR); Assert.assertEquals(3, retrievedLoanArrearsAgingInfo.size()); Assert.assertTrue( exists(retrievedLoanArrearsAgingInfo, PredicateUtils.equalPredicate(loanArrearReportForFirstWeek))); Assert.assertTrue(exists(retrievedLoanArrearsAgingInfo, PredicateUtils.equalPredicate(loanArrearReportForSecondWeek))); Assert.assertTrue( exists(retrievedLoanArrearsAgingInfo, PredicateUtils.equalPredicate(loanArrearReportForThirdWeek))); }
From source file:org.mifos.reports.branchreport.persistence.BranchReportPersistenceIntegrationTest.java
@Test public void testGetBranchReportBatchForDateAndBranch() throws Exception { BranchReportBO branchReportBO = new BranchReportBO(BRANCH_ID, runDate); session.save(branchReportBO);/*from w w w. ja va 2s . c om*/ List<BranchReportBO> retrievedBranchReports = branchReportPersistence.getBranchReport(BRANCH_ID, runDate); assertListSizeAndTrueCondition(1, retrievedBranchReports, PredicateUtils.equalPredicate(branchReportBO)); }
From source file:org.mifos.reports.branchreport.persistence.BranchReportPersistenceIntegrationTest.java
@Test public void testRetrievesBranchReportsForGivenDate() throws Exception { BranchReportBO branchReportBO = new BranchReportBO(BRANCH_ID, runDate); session.save(branchReportBO);/* w ww . ja v a2 s.c o m*/ List<BranchReportBO> retrievedBranchReports = branchReportPersistence.getBranchReport(runDate); assertListSizeAndTrueCondition(1, retrievedBranchReports, PredicateUtils.equalPredicate(branchReportBO)); }
From source file:org.mifos.reports.branchreport.persistence.BranchReportPersistenceIntegrationTest.java
@Test public void testSaveBranchReportWithLoanArrearsAndRetrieveUsingBranchReport() throws Exception { session.save(branchReportWithLoanArrears); List<BranchReportBO> retrievedBranchReports = branchReportPersistence.getBranchReport(BRANCH_ID, runDate); assertListSizeAndTrueCondition(1, retrievedBranchReports, PredicateUtils.equalPredicate(branchReportWithLoanArrears)); }