use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.mappingTest.InputData in project legend-engine by finos.
the class MappingTestRunner method buildTestConnection.
private void buildTestConnection(Consumer<? super Connection> connectionRegistrar) {
if (this.mappingTest.inputData.size() != 1) {
throw new RuntimeException("Only tests with one input data set are currently supported; " + mappingTest.inputData.size() + " supplied");
}
InputData input = this.mappingTest.inputData.get(0);
if (input instanceof ObjectInputData) {
ObjectInputData objectInputData = ((ObjectInputData) input);
if (ObjectInputType.JSON.equals(objectInputData.inputType)) {
JsonModelConnection jsonModelConnection = new JsonModelConnection();
jsonModelConnection._class = objectInputData.sourceClass;
jsonModelConnection.url = DataProtocolHandler.DATA_PROTOCOL_NAME + ":" + MediaType.APPLICATION_JSON + ";base64," + Base64.getEncoder().encodeToString(objectInputData.data.getBytes(StandardCharsets.UTF_8));
connectionRegistrar.accept(jsonModelConnection);
} else if (ObjectInputType.XML.equals(objectInputData.inputType)) {
XmlModelConnection xmlModelConnection = new XmlModelConnection();
xmlModelConnection._class = objectInputData.sourceClass;
xmlModelConnection.url = DataProtocolHandler.DATA_PROTOCOL_NAME + ":" + MediaType.APPLICATION_XML + ";base64," + Base64.getEncoder().encodeToString(objectInputData.data.getBytes(StandardCharsets.UTF_8));
connectionRegistrar.accept(xmlModelConnection);
} else {
throw new UnsupportedOperationException("Unsupported Pure mapping test input data type '" + objectInputData.inputType + '"');
}
} else {
connectionRegistrar.accept(getTestConnectionFromFactories(input));
}
}
use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.mappingTest.InputData in project legend-engine by finos.
the class RelationalConnectionFactory method tryBuildFromInputData.
@Override
public Optional<Connection> tryBuildFromInputData(InputData inputData) {
if (inputData instanceof RelationalInputData) {
RelationalInputData relationalInputData = (RelationalInputData) inputData;
RelationalDatabaseConnection connection = new RelationalDatabaseConnection();
connection.databaseType = DatabaseType.H2;
connection.type = DatabaseType.H2;
connection.element = relationalInputData.database;
connection.authenticationStrategy = new TestDatabaseAuthenticationStrategy();
LocalH2DatasourceSpecification localH2DatasourceSpecification = new LocalH2DatasourceSpecification();
if (relationalInputData.inputType == RelationalInputType.SQL) {
localH2DatasourceSpecification.testDataSetupSqls = Lists.mutable.of(relationalInputData.data.split("(?<!\\\\);")).collect(r -> r.replace("\\;", ";") + ";");
} else if (relationalInputData.inputType == RelationalInputType.CSV) {
localH2DatasourceSpecification.testDataSetupCsv = relationalInputData.data;
} else {
throw new RuntimeException(relationalInputData.inputType + " is not supported");
}
connection.datasourceSpecification = localH2DatasourceSpecification;
return Optional.of(connection);
}
return Optional.empty();
}
use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.mappingTest.InputData in project legend-engine by finos.
the class RelationalGrammarComposerExtension method getExtraMappingTestInputDataComposers.
@Override
public List<Function2<InputData, PureGrammarComposerContext, String>> getExtraMappingTestInputDataComposers() {
return Lists.mutable.with((inputData, context) -> {
if (inputData instanceof RelationalInputData) {
RelationalInputData relationalInputData = (RelationalInputData) inputData;
String data;
if (relationalInputData.inputType == RelationalInputType.SQL) {
MutableList<String> lines = org.eclipse.collections.api.factory.Lists.mutable.of(relationalInputData.data.replace("\r", "").replace("\n", "").split("(?<!\\\\);"));
data = "\n" + lines.collect(l -> getTabString(5) + convertString(l + ";\n", true).replace("\\\\;", "\\;")).makeString("+\n");
} else if (relationalInputData.inputType == RelationalInputType.CSV) {
MutableList<String> lines = org.eclipse.collections.api.factory.Lists.mutable.of(relationalInputData.data.split("\\n"));
lines.add("\n\n");
data = "\n" + lines.collect(l -> getTabString(5) + convertString(l + "\n", true)).makeString("+\n");
} else {
data = relationalInputData.data;
}
return "<Relational, " + relationalInputData.inputType + ", " + relationalInputData.database + ", " + data + "\n" + getTabString(4) + ">";
}
return null;
});
}
use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.mappingTest.InputData in project legend-engine by finos.
the class HelperMappingBuilder method processMappingTestInputData.
public static void processMappingTestInputData(InputData inputData, CompileContext context) {
if (inputData instanceof ObjectInputData) {
ObjectInputData objectInputData = (ObjectInputData) inputData;
if (objectInputData.inputType == null) {
throw new EngineException("Object input data does not have a format type", objectInputData.sourceInformation, EngineErrorType.COMPILATION);
}
context.resolveClass(objectInputData.sourceClass, objectInputData.sourceInformation);
} else {
context.getCompilerExtensions().getExtraMappingTestInputDataProcessors().forEach(processor -> processor.value(inputData, context));
}
}
use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.mappingTest.InputData in project legend-engine by finos.
the class MappingParseTreeWalker method visitMappingTestInputData.
private InputData visitMappingTestInputData(MappingParserGrammar.TestInputElementContext ctx) {
SourceInformation testInputDataSourceInformation = this.walkerSourceInformation.getSourceInformation(ctx);
String inputDataType = ctx.testInputType().getText();
MappingTestInputDataParser mappingTestInputDataParser = this.extensions.getExtraMappingTestInputDataParser(inputDataType);
if (mappingTestInputDataParser == null) {
throw new EngineException("Unsupported mapping test input data type '" + inputDataType + "'", testInputDataSourceInformation, EngineErrorType.PARSER);
}
return mappingTestInputDataParser.parse(ctx, this.walkerSourceInformation);
}
Aggregations