@Override public Stream<T> asStream() { List<DataModelReflection> refs = new ArrayList<>(); try (DataModelSource source = factory.createSource(definition, context)) { while (true) { DataModelReflection ref = source.next(); if (ref == null) { break; } refs.add(ref); } } catch (IOException e) { throw new IllegalStateException(e); } if (refComparator != null) { refs.sort(refComparator); } return refs.stream() .sequential() .map(definition::toObject); }
@Override public void close() throws IOException { expected.close(); } }
@Override public void validate() throws IOException { VerifyEngine engine = new VerifyEngine(rule); try { engine.addExpected(expected); } finally { expected.close(); } }
private Map<List<Object>, List<DataModelReflection>> asRefMap() { Map<List<Object>, List<DataModelReflection>> results = new LinkedHashMap<>(); try (DataModelSource source = factory.createSource(definition, context)) { while (true) { DataModelReflection ref = source.next(); if (ref == null) { break; } List<Object> key = new ArrayList<>(grouping.size()); for (PropertyName name : grouping) { Object value = ref.getValue(name); key.add(value); } results.computeIfAbsent(key, k -> new ArrayList<>()).add(ref); } } catch (IOException e) { throw new IllegalStateException(e); } if (refComparator != null) { for (List<DataModelReflection> refs : results.values()) { refs.sort(refComparator); } } return results; }
@Override public List<Difference> verify(DataModelSource results) throws IOException { VerifyEngine engine = new VerifyEngine(rule); try { engine.addExpected(expected); } finally { expected.close(); } List<Difference> differences = new ArrayList<>(); differences.addAll(engine.inspectInput(results)); differences.addAll(engine.inspectRest()); return differences; }
try (DataModelSource s = target.createSource(definition, context)) { while (true) { DataModelReflection next = s.next(); if (next == null) { break;
@Override public <T> Verifier createVerifier( DataModelDefinition<T> definition, VerifyContext context) throws IOException { DataModelSource expected = expectedFactory.createSource(definition, context.getTestContext()); VerifyRule verifyRule = ruleFactory.createRule(definition, context); boolean succeed = false; try { Verifier verifier = new VerifyRuleVerifier(expected, verifyRule); succeed = true; return verifier; } finally { if (succeed == false) { expected.close(); } } } @Override
@Override public List<Difference> verify(DataModelSource results) throws IOException { long actual = 0; while (results.next() != null) { actual++; } List<Difference> result = new ArrayList<Difference>(); if (expected != actual) { result.add(createDifference(actual)); } return result; }
@Override public List<Difference> verify(DataModelSource results) throws IOException { long actual = 0; while (results.next() != null) { actual++; } List<Difference> result = new ArrayList<Difference>(); if (expected != actual) { result.add(createDifference(actual)); } return result; }
@Override public List<Difference> verify(DataModelSource results) throws IOException { long actual = 0; while (results.next() != null) { actual++; } List<Difference> result = new ArrayList<Difference>(); if (expected != actual) { result.add(createDifference(actual)); } return result; }
@Override public List<Difference> verify(DataModelSource results) throws IOException { long actual = 0; while (results.next() != null) { actual++; } List<Difference> result = new ArrayList<Difference>(); if (expected != actual) { result.add(createDifference(actual)); } return result; }
private <T> void prepare( DataModelDefinition<T> definition, ModelOutput<T> output, URI source) throws IOException { try (DataModelSource input = sources.open(definition, source, context)) { if (input == null) { throw new IOException(MessageFormat.format( Messages.getString("TestDataPreparator.errorMissingDataModelSource"), //$NON-NLS-1$ source)); } while (true) { DataModelReflection next = input.next(); if (next == null) { break; } T object = definition.toObject(next); output.write(object); } } finally { output.close(); } } }
private <T> void prepare( DataModelDefinition<T> definition, ModelOutput<T> output, DataModelSourceFactory source) throws IOException { assert definition != null; assert output != null; assert source != null; try (DataModelSource input = source.createSource(definition, context)) { if (input == null) { throw new IOException(MessageFormat.format( Messages.getString("TestModerator.errorMissingDataModelSource"), //$NON-NLS-1$ source)); } while (true) { DataModelReflection next = input.next(); if (next == null) { break; } T object = definition.toObject(next); output.write(object); } } finally { output.close(); } }
DataModelSink sink = resultDataSink.createSink(definition, context);) { while (true) { DataModelReflection next = source.next(); if (next == null) { break;
private <T> void prepare0(DataModelSourceFactory factory, Class<T> type) { try { DataModelDefinition<T> definition = getTestTools().toDataModelDefinition(type); DirectIoTestHelper helper = new DirectIoTestHelper( environment.getTestContext(), description.getBasePath(), environment.getConfiguration()); helper.truncate(description.getResourcePattern()); try (ModelOutput<T> output = helper.openOutput(type, description); DataModelSource source = factory.createSource(definition, environment.getTestContext())) { while (true) { DataModelReflection r = source.next(); if (r == null) { break; } T object = definition.toObject(r); output.write(object); } } } catch (IOException e) { throw new IllegalStateException(MessageFormat.format( Messages.getString("DirectIoOperatorTester.errorFailedToInitialize"), //$NON-NLS-1$ description), e); } } }