private <T> DataModelDefinition<T> toDataModelDefinition(Class<T> dataType) { try { return getTestTools().toDataModelDefinition(dataType); } catch (IOException e) { throw new IllegalStateException(MessageFormat.format( "failed to analyze the data model type: {0}", dataType.getName()), e); } }
/** * Converts an output path to {@link DataModelSinkFactory} to write to the path. * @param path the output path * @return the target sink factory * @since 0.6.0 */ protected final DataModelSinkFactory toDataModelSinkFactory(File path) { return getTestTools().getDataModelSinkFactory(path.toURI()); }
/** * Converts an output path to {@link DifferenceSinkFactory} to write to the path. * @param path the output path * @return the target sink factory * @since 0.6.0 */ protected final DifferenceSinkFactory toDifferenceSinkFactory(File path) { return getTestTools().getDifferenceSinkFactory(path.toURI()); }
/** * Converts {@link ModelVerifier} into {@link VerifyRuleFactory}. * @param rulePath the path which represents the verification rule description * @param extraRules the extra verification rules * @return the equivalent {@link VerifyRuleFactory} * @since 0.6.0 */ protected final VerifyRuleFactory toVerifyRuleFactory( String rulePath, List<? extends ModelTester<? super T>> extraRules) { try { TestDataToolProvider tools = getTestTools(); List<TestRule> fragments = new ArrayList<>(); for (ModelTester<? super T> tester : extraRules) { fragments.add(tools.toVerifyRuleFragment(getDataModelDefinition(), tester)); } return tools.getVerifyRuleFactory(toUri(rulePath), fragments); } catch (URISyntaxException e) { throw new IllegalStateException(MessageFormat.format( "Invalid rule path: {0}", //$NON-NLS-1$ rulePath), e); } }
/** * Converts a pair of expected data set factory and verify rule factory into {@link VerifyRuleFactory}. * @param expectedFactory the expected data set factory * @param ruleFactory the verification rule factory * @return the {@link VerifierFactory} which provides a verifier using the expected data set and verification rule * @since 0.6.0 */ protected final VerifierFactory toVerifierFactory( DataModelSourceFactory expectedFactory, VerifyRuleFactory ruleFactory) { return getTestTools().toVerifierFactory(expectedFactory, ruleFactory); } }
/** * Converts {@link ModelVerifier} into {@link VerifyRuleFactory}. * @param modelVerifier the original verifier * @return the equivalent {@link VerifyRuleFactory} * @since 0.6.0 */ protected final VerifyRuleFactory toVerifyRuleFactory(ModelVerifier<? super T> modelVerifier) { return getTestTools().toVerifyRuleFactory(getDataModelDefinition(), modelVerifier); }
/** * Converts a source path into {@link DataModelSourceFactory} which provides data models. * This implementation lazily converts source contents into equivalent {@link DataModelReflection}s. * @param sourcePath the source path * @return the {@link DataModelSourceFactory} * @throws IllegalArgumentException if the target resource is not found */ protected final DataModelSourceFactory toDataModelSourceFactory(String sourcePath) { if (sourcePath == null) { throw new IllegalArgumentException("sourcePath must not be null"); //$NON-NLS-1$ } URI sourceUri; try { sourceUri = toUri(sourcePath); } catch (URISyntaxException e) { throw new IllegalArgumentException(MessageFormat.format( Messages.getString("DriverElementBase.errorInvalidUri"), //$NON-NLS-1$ sourcePath), e); } return getTestTools().getDataModelSourceFactory(sourceUri); }
private <T> DataModelDefinition<T> toDataModelDefinition(Class<T> dataType) { try { return getTestTools().toDataModelDefinition(dataType); } catch (IOException e) { throw new IllegalStateException(MessageFormat.format( "failed to analyze the data model type: {0}", dataType.getName()), e); } } }
/** * Converts an output path to {@link DataModelSinkFactory} to write to the path. * @param path the output path * @return the target sink factory * @since 0.6.0 */ protected final DataModelSinkFactory toDataModelSinkFactory(String path) { return getTestTools().getDataModelSinkFactory(toOutputUri(path)); }
/** * Converts an output path to {@link DifferenceSinkFactory} to write to the path. * @param path the output path * @return the target sink factory * @since 0.6.0 */ protected final DifferenceSinkFactory toDifferenceSinkFactory(String path) { return getTestTools().getDifferenceSinkFactory(toOutputUri(path)); }
/** * Returns the data model definition for this port. * @return the data model definition */ public final DataModelDefinition<T> getDataModelDefinition() { try { TestDataToolProvider tools = getTestTools(); return tools.toDataModelDefinition(modelType); } catch (IOException e) { throw new IllegalStateException(MessageFormat.format( Messages.getString("DriverInputBase.errorInvalidDataModel"), //$NON-NLS-1$ name, modelType.getName()), e); } }
/** * Sets a data objects for this external resource. * @param objects a list of data model objects */ @SuppressWarnings({ "rawtypes", "unchecked" }) public final void prepare(Iterable<?> objects) { try { DataModelDefinition def = getTestTools().toDataModelDefinition(description.getModelType()); prepare(toDataModelSourceFactory(def, objects)); } catch (IOException e) { throw new IllegalStateException(e); } }
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); } } }