/** * Prepares the target exporter's output using the specified source. * @param modelClass class of data model * @param description target importer * @param source test data * @throws IOException if failed to prepare the importer * @throws IllegalArgumentException if some parameters were {@code null} */ public void prepare( Class<?> modelClass, ExporterDescription description, DataModelSourceFactory source) throws IOException { if (modelClass == null) { throw new IllegalArgumentException("modelClass must not be null"); //$NON-NLS-1$ } if (description == null) { throw new IllegalArgumentException("description must not be null"); //$NON-NLS-1$ } if (source == null) { throw new IllegalArgumentException("source must not be null"); //$NON-NLS-1$ } DataModelDefinition<?> definition = repository.toDataModelDefinition(modelClass); prepare(definition, description, source); }
/** * Prepares the target importer's input using the specified source. * @param modelClass class of data model * @param description target importer * @param source test data * @throws IOException if failed to prepare the importer * @throws IllegalArgumentException if some parameters were {@code null} */ public void prepare( Class<?> modelClass, ImporterDescription description, DataModelSourceFactory source) throws IOException { if (modelClass == null) { throw new IllegalArgumentException("modelClass must not be null"); //$NON-NLS-1$ } if (description == null) { throw new IllegalArgumentException("description must not be null"); //$NON-NLS-1$ } if (source == null) { throw new IllegalArgumentException("source must not be null"); //$NON-NLS-1$ } DataModelDefinition<?> definition = repository.toDataModelDefinition(modelClass); prepare(definition, description, source); }
/** * Inspects the target exporter's output using specified expected data and rule. * @param modelClass class of data model * @param description target exporter * @param verifyContext current verification context * @param verifier verifier factory * @return detected invalid differences * @throws IOException if failed to inspect the result * @throws IllegalArgumentException if some parameters were {@code null} */ public List<Difference> inspect( Class<?> modelClass, ExporterDescription description, VerifyContext verifyContext, VerifierFactory verifier) throws IOException { if (modelClass == null) { throw new IllegalArgumentException("modelClass must not be null"); //$NON-NLS-1$ } if (description == null) { throw new IllegalArgumentException("description must not be null"); //$NON-NLS-1$ } if (verifyContext == null) { throw new IllegalArgumentException("verifyContext must not be null"); //$NON-NLS-1$ } if (verifier == null) { throw new IllegalArgumentException("verifier must not be null"); //$NON-NLS-1$ } DataModelDefinition<?> definition = repository.toDataModelDefinition(modelClass); return inspect(definition, description, verifyContext, verifier); }
static <T> Optional<DirectIoInfo<T>> parse( TestToolRepository tools, ClassLoader classLoader, URI uri) throws IOException { if (Objects.equals(uri.getScheme(), SCHEME_DIRECTIO) == false) { return Optional.empty(); } String body = uri.getSchemeSpecificPart(); String[] elements = body.split(":", 2); //$NON-NLS-1$ if (elements.length != 2) { return Optional.empty(); } String className = elements[0]; String dataPath = elements[1]; try { @SuppressWarnings("unchecked") Class<? extends DataFormat<T>> formatClass = (Class<? extends DataFormat<T>>) Class.forName(className, false, classLoader); DataFormat<T> format = formatClass.newInstance(); DataModelDefinition<T> definition = tools.toDataModelDefinition(format.getSupportedType()); return Optional.of(new DirectIoInfo<>(definition, formatClass, dataPath)); } catch (ClassCastException | ReflectiveOperationException e) { throw new IOException(MessageFormat.format( Messages.getString("BatchTestTool.errorInvalidDataFormatClass"), //$NON-NLS-1$ className), e); } } }
/** * Saves difference list into the specified sink. * @param modelClass class of data model * @param differences target list * @param differenceSink the difference sink * @throws IOException if failed to save the differences * @throws IllegalArgumentException if some parameters were {@code null} */ public void save( Class<?> modelClass, Iterable<Difference> differences, DifferenceSinkFactory differenceSink) throws IOException { if (modelClass == null) { throw new IllegalArgumentException("modelClass must not be null"); //$NON-NLS-1$ } if (differences == null) { throw new IllegalArgumentException("differences must not be null"); //$NON-NLS-1$ } if (differenceSink == null) { throw new IllegalArgumentException("differenceSink must not be null"); //$NON-NLS-1$ } DataModelDefinition<?> definition = repository.toDataModelDefinition(modelClass); try (DifferenceSink sink = differenceSink.createSink(definition, context)) { for (Difference difference : differences) { sink.put(difference); } } }
throw new IllegalArgumentException("target must not be null"); //$NON-NLS-1$ DataModelDefinition<?> definition = repository.toDataModelDefinition(modelClass); try (DataModelSource s = target.createSource(definition, context)) { while (true) {
verifyContext.testFinished(); DataModelDefinition<?> definition = repository.toDataModelDefinition(modelClass); try (Verifier verifier = target.createVerifier(definition, verifyContext)) { if (verifier instanceof Verifier.Validatable) {
throw new IllegalArgumentException("resultDataSink must not be null"); //$NON-NLS-1$ DataModelDefinition<?> definition = repository.toDataModelDefinition(modelClass); try (DataModelSource source = getDriver(description).createSource(definition, description, context); DataModelSink sink = resultDataSink.createSink(definition, context);) {
@SuppressWarnings("unchecked") private <T> VerifierFactory toVerifierFactory( Class<T> dataType, String expectedPath, String verifyRulePath, ModelTransformer<?> transformer, ModelTester<?>... extraRules) throws URISyntaxException, IOException { DataModelDefinition<T> definition = getTestTools().toDataModelDefinition(dataType); DataModelSourceFactory source = resolveSource(expectedPath); List<TestRule> fragments = new ArrayList<>(); for (ModelTester<?> tester : extraRules) { TestRule rule = getTestTools().toVerifyRuleFragment(definition, (ModelTester<? super T>) tester); fragments.add(rule); } VerifyRuleFactory rules = getTestTools().getVerifyRuleFactory(toUri(verifyRulePath), fragments); VerifierFactory result = getTestTools().toVerifierFactory(source, rules); if (transformer != null) { UnaryOperator<DataModelSource> filter = toDataModelSourceFilter(definition, (ModelTransformer<? super T>) transformer); result = toVerifierFactory(result, filter); } return result; }