/** * Tests {@link GeneratorSetDocReader#getGeneratorSet getGeneratorSet()} using the following * inputs. * * <p> * * <TABLE border="1" cellpadding="8"> * <TR align="left"><TH colspan=2> 1. getGeneratorSet (Success) </TH></TR> * <TR align="left"><TH> Input Choice </TH> <TH> Value </TH></TR> * <TR><TD> TupleGenerator.Count </TD> <TD> One </TD></TR> * <TR><TD> TupleGenerator.Function </TD> <TD> Defined </TD></TR> * <TR><TD> TupleGenerator.Seed </TD> <TD> Defined </TD></TR> * <TR><TD> TupleGenerator.Tuples </TD> <TD> Defined </TD></TR> * <TR><TD> Combiner.Count </TD> <TD> One </TD></TR> * <TR><TD> Combiner.Tuples </TD> <TD> Default </TD></TR> * <TR><TD> Include.Count </TD> <TD> None </TD></TR> * <TR><TD> Include.Var </TD> <TD> NA </TD></TR> * <TR><TD> Exclude.Count </TD> <TD> Many </TD></TR> * <TR><TD> Exclude.Var </TD> <TD> Valid </TD></TR> * </TABLE> */ @Test public void testGetGeneratorSet_1() { IGeneratorSet generatorSet = generatorSetResources_.read("generator-set-1.xml"); ITestCaseGenerator[] generators = IteratorUtils.toArray(generatorSet.getGenerators(), ITestCaseGenerator.class); assertEquals("Generators", 1, generators.length); TupleGenerator tupleGenerator; String functionName; TupleCombiner[] combiners; TupleCombiner combiner; VarSet varSet; IVarDef varDef; tupleGenerator = (TupleGenerator) generators[0]; assertEquals("Generator 0, seed", new Long(1234L), tupleGenerator.getRandomSeed()); assertEquals("Generator 0, defaultTupleSize", 3, tupleGenerator.getDefaultTupleSize()); functionName = "F1"; assertEquals( "getGenerator, function=" + functionName, tupleGenerator, generatorSet.getGenerator(functionName)); functionName = null; assertEquals( "getGenerator, function=" + functionName, null, generatorSet.getGenerator(functionName)); combiners = tupleGenerator .getCombiners() .toArray(new TupleCombiner[tupleGenerator.getCombiners().size()]); assertEquals("Generator 0, combiners", 1, combiners.length); combiner = combiners[0]; varSet = new VarSet("include1").addMember(new VarSet("B").addMember(new VarDef("C"))); varDef = varSet.getDescendant("B.C"); assertEquals("Combiner[0], var=" + varDef + ", eligible", true, combiner.isEligible(varDef)); varDef = new VarDef("include2"); assertEquals("Combiner[0], var=" + varDef + ", eligible", true, combiner.isEligible(varDef)); varSet = new VarSet("exclude1").addMember(new VarDef("var")).addMember(new VarDef("var2")); varDef = varSet.getDescendant("var"); assertEquals("Combiner[0], var=" + varDef + ", eligible", false, combiner.isEligible(varDef)); varDef = varSet.getDescendant("var2"); assertEquals("Combiner[0], var=" + varDef + ", eligible", true, combiner.isEligible(varDef)); varSet = new VarSet("exclude2") .addMember(new VarSet("var").addMember(new VarSet("A").addMember(new VarDef("B")))) .addMember(new VarDef("var2")); varDef = varSet.getDescendant("var.A.B"); assertEquals("Combiner[0], var=" + varDef + ", eligible", false, combiner.isEligible(varDef)); }
@Test public void testOnceTuples() { IGeneratorSet generatorSet = generatorSetResources_.read("generator-set-once.xml"); ITestCaseGenerator[] generators = IteratorUtils.toArray(generatorSet.getGenerators(), ITestCaseGenerator.class); assertEquals("Generators", 1, generators.length); TupleGenerator tupleGenerator; TupleCombiner[] combiners; TupleCombiner combiner; tupleGenerator = (TupleGenerator) generators[0]; combiners = tupleGenerator .getCombiners() .toArray(new TupleCombiner[tupleGenerator.getCombiners().size()]); assertEquals("Default generator, combiners", 1, tupleGenerator.getCombiners().size()); combiner = combiners[0]; assertSetEquals( "Other tuples", new TupleRef[] { new TupleRef() .addVarBinding(new VarBinding("X1", "V1")) .addVarBinding(new VarBinding("X2", "V2")) .addVarBinding(new VarBinding("X3", "V3")), new TupleRef() .addVarBinding(new VarBinding("X4", "V4")) .addVarBinding(new VarBinding("X5", "V5")) .addVarBinding(new VarBinding("X6", "V6")) }, combiner.getOnceTuples()); }
/** * Tests {@link GeneratorSetDocReader#getGeneratorSet getGeneratorSet()} using the following * inputs. * * <p> * * <TABLE border="1" cellpadding="8"> * <TR align="left"><TH colspan=2> 0. getGeneratorSet (Success) </TH></TR> * <TR align="left"><TH> Input Choice </TH> <TH> Value </TH></TR> * <TR><TD> TupleGenerator.Count </TD> <TD> None </TD></TR> * <TR><TD> TupleGenerator.Function </TD> <TD> NA </TD></TR> * <TR><TD> TupleGenerator.Seed </TD> <TD> NA </TD></TR> * <TR><TD> TupleGenerator.Tuples </TD> <TD> NA </TD></TR> * <TR><TD> Combiner.Count </TD> <TD> NA </TD></TR> * <TR><TD> Combiner.Tuples </TD> <TD> NA </TD></TR> * <TR><TD> Include.Count </TD> <TD> NA </TD></TR> * <TR><TD> Include.Var </TD> <TD> NA </TD></TR> * <TR><TD> Exclude.Count </TD> <TD> NA </TD></TR> * <TR><TD> Exclude.Var </TD> <TD> NA </TD></TR> * </TABLE> */ @Test public void testGetGeneratorSet_0() { IGeneratorSet generatorSet = generatorSetResources_.read("generator-set-0.xml"); ITestCaseGenerator[] generators = IteratorUtils.toArray(generatorSet.getGenerators(), ITestCaseGenerator.class); assertEquals("Generators", 0, generators.length); }
/** * Tests {@link GeneratorSetDocReader#getGeneratorSet getGeneratorSet()} using the following * inputs. * * <p> * * <TABLE border="1" cellpadding="8"> * <TR align="left"><TH colspan=2> 2. getGeneratorSet (Success) </TH></TR> * <TR align="left"><TH> Input Choice </TH> <TH> Value </TH></TR> * <TR><TD> TupleGenerator.Count </TD> <TD> Many </TD></TR> * <TR><TD> TupleGenerator.Function </TD> <TD> Default </TD></TR> * <TR><TD> TupleGenerator.Seed </TD> <TD> Default </TD></TR> * <TR><TD> TupleGenerator.Tuples </TD> <TD> Default </TD></TR> * <TR><TD> Combiner.Count </TD> <TD> None </TD></TR> * <TR><TD> Combiner.Tuples </TD> <TD> NA </TD></TR> * <TR><TD> Include.Count </TD> <TD> NA </TD></TR> * <TR><TD> Include.Var </TD> <TD> NA </TD></TR> * <TR><TD> Exclude.Count </TD> <TD> NA </TD></TR> * <TR><TD> Exclude.Var </TD> <TD> NA </TD></TR> * </TABLE> */ @Test public void testGetGeneratorSet_2() { IGeneratorSet generatorSet = generatorSetResources_.read("generator-set-2.xml"); ITestCaseGenerator[] generators = IteratorUtils.toArray(generatorSet.getGenerators(), ITestCaseGenerator.class); assertEquals("Generators", 4, generators.length); TupleGenerator tupleGenerator; String functionName; functionName = "F1"; tupleGenerator = (TupleGenerator) generatorSet.getGenerator(functionName); assertEquals("getGenerator, function=" + functionName, true, tupleGenerator != null); assertEquals("Generator(" + functionName + "), seed", null, tupleGenerator.getRandomSeed()); assertEquals( "Generator(" + functionName + "), defaultTupleSize", 1, tupleGenerator.getDefaultTupleSize()); assertEquals( "Generator(" + functionName + "), combiners", 0, tupleGenerator.getCombiners().size()); functionName = "F2"; tupleGenerator = (TupleGenerator) generatorSet.getGenerator(functionName); assertEquals("getGenerator, function=" + functionName, true, tupleGenerator != null); assertEquals("Generator(" + functionName + "), seed", null, tupleGenerator.getRandomSeed()); assertEquals( "Generator(" + functionName + "), defaultTupleSize", 1, tupleGenerator.getDefaultTupleSize()); assertEquals( "Generator(" + functionName + "), combiners", 0, tupleGenerator.getCombiners().size()); functionName = "F3"; tupleGenerator = (TupleGenerator) generatorSet.getGenerator(functionName); assertEquals("getGenerator, function=" + functionName, true, tupleGenerator != null); assertEquals("Generator(" + functionName + "), seed", null, tupleGenerator.getRandomSeed()); assertEquals( "Generator(" + functionName + "), defaultTupleSize", 1, tupleGenerator.getDefaultTupleSize()); assertEquals( "Generator(" + functionName + "), combiners", 0, tupleGenerator.getCombiners().size()); functionName = null; tupleGenerator = (TupleGenerator) generatorSet.getGenerator(functionName); assertEquals("getGenerator, function=" + functionName, true, tupleGenerator != null); assertEquals("Generator(" + functionName + "), seed", null, tupleGenerator.getRandomSeed()); assertEquals( "Generator(" + functionName + "), defaultTupleSize", 1, tupleGenerator.getDefaultTupleSize()); assertEquals( "Generator(" + functionName + "), combiners", 0, tupleGenerator.getCombiners().size()); functionName = "F4"; assertEquals( "Found default generator for function=" + functionName, true, tupleGenerator == generatorSet.getGenerator(functionName)); }
@Override public List<Disease> getAll() { Iterable<Disease> results = repository.findAll(); if (results != null) { return IteratorUtils.toList(results.iterator()); } else { throw new ElementNotFoundException(); } }
public static String[] buildLookupAttributeIds( BinaryAttributeDetector binaryAttrDetector, @Nullable Set<Attribute> attrs) { // noinspection ConstantConditions return (!CollectionUtils.isEmpty(attrs) ? ToolCollectionUtils.toArray( CollectionUtils.select( IteratorUtils.asIterable( ToolIteratorUtils.chainedArrayIterator( CollectionUtils.collect( attrs, new LdapAttributeIdTransformer(binaryAttrDetector)))), PredicateUtils.uniquePredicate()), String.class) : ArrayUtils.EMPTY_STRING_ARRAY); }
/** * Tests {@link GeneratorSetDocReader#getGeneratorSet getGeneratorSet()} using the following * inputs. * * <p> * * <TABLE border="1" cellpadding="8"> * <TR align="left"><TH colspan=2> 4. getGeneratorSet (Success) </TH></TR> * <TR align="left"><TH> Input Choice </TH> <TH> Value </TH></TR> * <TR><TD> TupleGenerator.Count </TD> <TD> One </TD></TR> * <TR><TD> TupleGenerator.Function </TD> <TD> Default </TD></TR> * <TR><TD> TupleGenerator.Seed </TD> <TD> Defined </TD></TR> * <TR><TD> TupleGenerator.Tuples </TD> <TD> Defined </TD></TR> * <TR><TD> Combiner.Count </TD> <TD> One </TD></TR> * <TR><TD> Combiner.Tuples </TD> <TD> Default </TD></TR> * <TR><TD> Include.Count </TD> <TD> One </TD></TR> * <TR><TD> Include.Var </TD> <TD> Valid </TD></TR> * <TR><TD> Exclude.Count </TD> <TD> None </TD></TR> * <TR><TD> Exclude.Var </TD> <TD> NA </TD></TR> * </TABLE> */ @Test public void testGetGeneratorSet_4() { IGeneratorSet generatorSet = generatorSetResources_.read("generator-set-4.xml"); ITestCaseGenerator[] generators = IteratorUtils.toArray(generatorSet.getGenerators(), ITestCaseGenerator.class); assertEquals("Generators", 1, generators.length); TupleGenerator tupleGenerator; String functionName; TupleCombiner[] combiners; TupleCombiner combiner; VarSet varSet; IVarDef varDef; tupleGenerator = (TupleGenerator) generators[0]; functionName = "F4"; assertEquals( "Found default generator for function=" + functionName, true, tupleGenerator == generatorSet.getGenerator(functionName)); assertEquals("Default generator, seed", new Long(12345L), tupleGenerator.getRandomSeed()); assertEquals("Default generator, defaultTupleSize", 3, tupleGenerator.getDefaultTupleSize()); combiners = tupleGenerator .getCombiners() .toArray(new TupleCombiner[tupleGenerator.getCombiners().size()]); assertEquals("Default generator, combiners", 1, tupleGenerator.getCombiners().size()); combiner = combiners[0]; assertEquals( "Combiner[0], tupleSize", tupleGenerator.getDefaultTupleSize(), combiner.getTupleSize()); varSet = new VarSet("A").addMember(new VarSet("X").addMember(new VarDef("Y"))); varDef = varSet.getDescendant("X"); assertEquals("Combiner[0], var=" + varDef + ", eligible", false, combiner.isEligible(varDef)); varDef = new VarDef("B"); assertEquals("Combiner[0], var=" + varDef + ", eligible", false, combiner.isEligible(varDef)); varDef = new VarDef("X"); assertEquals("Combiner[0], var=" + varDef + ", eligible", true, combiner.isEligible(varDef)); }
protected ConnectorObject getRemoteObject( final String connObjectKey, final ObjectClass objectClass) { ConnectorObject obj = null; try { Uid uid = new Uid(connObjectKey); obj = profile .getConnector() .getObject( objectClass, uid, MappingUtils.buildOperationOptions(IteratorUtils.<MappingItem>emptyIterator())); } catch (TimeoutException toe) { LOG.debug("Request timeout", toe); throw toe; } catch (RuntimeException ignore) { LOG.debug("While resolving {}", connObjectKey, ignore); } return obj; }
public List<User> findUsers() { return IteratorUtils.toList(userRepository.findAll().iterator()); }
@SuppressWarnings({CompilerWarnings.UNCHECKED}) private void buildEntityMetadatas() throws Exception { SessionFactoryImpl sessionFactory = ((SessionFactoryImpl) this.entityManagerFactory.getSessionFactory()); Class<?> entityBindingMappedClass; Class<? extends SdcctEntity> entityMappedClass; String entityName, entityPropName, entityPropFieldName; EntityMetadata entityMetadata; Map<String, PropertyMetadata> entityPropMetadatas; IndexedTypeDescriptor indexedEntityDesc; Method entityPropGetterMethod; boolean entityIndexed, entityPropIndexed; PropertyDescriptor indexedEntityPropDesc; PropertyMetadata entityPropMetadata; BidiMap<Integer, String> entityPropOrder; String[] entityPropOrderNames; for (PersistentClass entityBinding : metadata.getEntityBindings()) { if (((entityBindingMappedClass = entityBinding.getMappedClass()) == null) || !SdcctEntity.class.isAssignableFrom(entityBindingMappedClass)) { continue; } entityPropMetadatas = (entityMetadata = new EntityMetadataImpl( (entityName = entityBinding.getEntityName()), (entityIndexed = (indexedEntityDesc = searchIntegrator.getIndexedTypeDescriptor( (entityMappedClass = ((Class<? extends SdcctEntity>) entityBindingMappedClass)))) .isIndexed()), entityMappedClass, entityBinding.getTable().getName())) .getProperties(); this.entityMetadatas.put( ((Class<? extends SdcctEntity>) entityMappedClass.getInterfaces()[0]), entityMetadata); for (Property entityProp : IteratorUtils.asIterable( IteratorUtils.chainedIterator( ((Iterator<Property>) entityBinding.getRootClass().getPropertyIterator()), ((Iterator<Property>) entityBinding.getPropertyIterator())))) { entityPropName = entityProp.getName(); entityPropGetterMethod = entityProp.getGetter(entityMappedClass).getMethod(); if (entityProp.getColumnSpan() == 0) { continue; } entityPropIndexed = (entityIndexed && entityPropGetterMethod.isAnnotationPresent(Fields.class) && ((indexedEntityPropDesc = indexedEntityDesc.getProperty(entityPropName)) != null) && !indexedEntityPropDesc.isId()); entityPropMetadatas.put( entityPropName, (entityPropMetadata = new PropertyMetadataImpl( entityPropName, entityPropIndexed, ((Column) entityProp.getColumnIterator().next()).getName(), entityProp.getType()))); if (entityPropIndexed) { for (Field entityPropFieldAnno : entityPropGetterMethod.getAnnotation(Fields.class).value()) { if (entityPropFieldAnno.analyze() == Analyze.NO) { continue; } entityPropFieldName = entityPropFieldAnno.name(); switch (entityPropFieldAnno.analyzer().definition()) { case DbAnalyzerNames.EDGE_NGRAM: entityPropMetadata.setEdgeNgramFieldName(entityPropFieldName); break; case DbAnalyzerNames.LOWERCASE: entityPropMetadata.setLowercaseFieldName(entityPropFieldName); break; case DbAnalyzerNames.NGRAM: entityPropMetadata.setNgramFieldName(entityPropFieldName); break; case DbAnalyzerNames.PHONETIC: entityPropMetadata.setPhoneticFieldName(entityPropFieldName); break; } } } } entityMetadata.setIdProperty( entityPropMetadatas.get(entityBinding.getIdentifierProperty().getName())); entityPropOrder = entityMetadata.getPropertyOrder(); entityPropOrderNames = sessionFactory.getEntityPersister(entityName).getPropertyNames(); for (int a = 0; a < entityPropOrderNames.length; a++) { entityPropOrder.put(a, entityPropOrderNames[a]); } } LOGGER.debug( String.format( "Processed metadata for %d entities: [%s]", this.entityMetadatas.size(), this.entityMetadatas .values() .stream() .map(NamedBean::getName) .collect(Collectors.joining(", ")))); }
@Test public void test_TwoPrintJobs_SecondOneIsUsedBecauseFirstOneFails() { // // Setup routings final I_AD_PrinterRouting routing1 = helper.createPrinterRouting("printer01", "tray01", -1, -1, -1); routing1.setAD_Org_ID(1); helper.getDB().save(routing1); final I_AD_PrinterRouting routing2 = helper.createPrinterRouting("printer02", "tray01", -1, -1, -1); routing2.setAD_Org_ID(2); helper.getDB().save(routing2); // // Create printing queue helper.addToPrintQueue("01", 1, -1); // AD_Org_ID=1, C_DocType_ID=N/A helper.addToPrintQueue("02", 2, -1); // AD_Org_ID=2, C_DocType_ID=N/A // // Expect 2 print jobs to be created final int printJobsCountActual = helper.createAllPrintJobs(); Assert.assertEquals("Invalid Print Jobs count", 2, printJobsCountActual); final List<I_C_Print_Job> printJobs = helper.getDB().getRecords(I_C_Print_Job.class); Assert.assertEquals("Invalid Print Jobs count in database", 2, printJobs.size()); // Validate PrintJob 1 final I_C_Print_Job printJob1 = printJobs.get(0); { final List<I_C_Print_Job_Line> lines = IteratorUtils.toList(helper.getDAO().retrievePrintJobLines(printJob1)); Assert.assertEquals("Job1 - Only one line was expected for " + printJob1, 1, lines.size()); final I_C_Print_Job_Line line = lines.get(0); final I_C_Print_Job_Detail detail = helper.getDAO().retrievePrintJobDetails(line).get(0); Assert.assertEquals("Job1 - Invalid routing used", routing1, detail.getAD_PrinterRouting()); } // Validate PrintJob 2 final I_C_Print_Job printJob2 = printJobs.get(1); { final List<I_C_Print_Job_Line> lines = IteratorUtils.toList(helper.getDAO().retrievePrintJobLines(printJob2)); Assert.assertEquals("Job2 - Only one line was expected for " + printJob2, 1, lines.size()); final I_C_Print_Job_Line line = lines.get(0); final I_C_Print_Job_Detail detail = helper.getDAO().retrievePrintJobDetails(line).get(0); Assert.assertEquals("Job2 - Invalid routing used", routing2, detail.getAD_PrinterRouting()); } // // Everything is fine.... now drop the matching for printer01 // ... this shall produce errors when trying to generate the package for first print job { final I_AD_Printer_Matching matching = helper.getDAO().retrievePrinterMatching(helper.getSessionHostKey(), routing1); helper.getDB().delete(matching); } // // Creating next package // Expectations: printJob2 is used helper.createNextPrintPackageAndTest( printJob2, new PdfCollator().addPages(helper.getPdf("02"), 1, 20).toByteArray()); // // Validate PrintJob1 Instructions { final I_C_Print_Job_Instructions instructions1 = helper.getDAO().retrievePrintJobInstructionsForPrintJob(printJob1); // task 09028: don't check for the host key..the user shall be able to print this wherever // they are logged inAssert.assertEquals("Job1 instructions - Invalid HostKey", // helper.getSessionHostKey(), instructions1.getHostKey()); // Assert.assertEquals("Job1 instructions - Invalid status", // X_C_Print_Job_Instructions.STATUS_Error, instructions1.getStatus()); Assert.assertNotNull( "Job1 instructions - Missing error message", instructions1.getErrorMsg()); } // // Validate PrintJob2 Instructions { final I_C_Print_Job_Instructions instructions2 = helper.getDAO().retrievePrintJobInstructionsForPrintJob(printJob2); // task 09028: don't check for the host key..the user shall be able to print this wherever // they are logged in // Assert.assertEquals("Job2 instructions - Invalid HostKey", helper.getSessionHostKey(), // instructions2.getHostKey()); Assert.assertEquals( "Job2 instructions - Invalid status", X_C_Print_Job_Instructions.STATUS_Send, instructions2.getStatus()); Assert.assertNull("Job2 instructions - Missing error message", instructions2.getErrorMsg()); } // // Recreate back the HW matching for printer01 helper.createPrinterConfigAndMatching( helper.getSessionHostKey(), "printer01-hw-again", "tray01-hw-again", "printer01", "tray01"); // // Job1 instructions, prepare it again { final I_C_Print_Job_Instructions instructions1 = helper.getDAO().retrievePrintJobInstructionsForPrintJob(printJob1); instructions1.setStatus(X_C_Print_Job_Instructions.STATUS_Pending); instructions1.setErrorMsg(null); InterfaceWrapperHelper.save(instructions1); } // // Creating next package // Expectations: printJob1 is used { helper.createNextPrintPackageAndTest( printJob1, new PdfCollator().addPages(helper.getPdf("01"), 1, 20).toByteArray()); } // // Validate PrintJob2 Instructions { final I_C_Print_Job_Instructions instructions1 = helper.getDAO().retrievePrintJobInstructionsForPrintJob(printJob1); Assert.assertEquals( "Job1 instructions - Invalid status", X_C_Print_Job_Instructions.STATUS_Send, instructions1.getStatus()); Assert.assertNull("Job1 instructions - Missing error message", instructions1.getErrorMsg()); } // // Final assumptions assumePrintQueueProcessed(); assumePrintJobInstructions(X_C_Print_Job_Instructions.STATUS_Send); // everything is Send assumePrintJobsProcessed(); helper.assumeNothingLocked(); }