use of org.teiid.core.types.XMLType in project teiid by teiid.
the class TestStringToXmlTransform method testGoodElement.
@Test
public void testGoodElement() throws Exception {
String xml = // $NON-NLS-1$
"<customer>\n" + // $NON-NLS-1$
"<name>ABC</name>" + // $NON-NLS-1$
"<age>32</age>" + // $NON-NLS-1$
"</customer>";
StringToSQLXMLTransform transform = new StringToSQLXMLTransform();
XMLType xmlValue = (XMLType) transform.transformDirect(xml);
assertEquals(xml.replaceAll("[\r]", ""), xmlValue.getString().replaceAll("[\r]", ""));
assertEquals(XMLType.Type.ELEMENT, xmlValue.getType());
}
use of org.teiid.core.types.XMLType in project teiid by teiid.
the class TestResultSet method testXML.
@Test
public void testXML() throws Exception {
StatementImpl statement = createMockStatement(ResultSet.TYPE_FORWARD_ONLY);
ResultsFuture<LobChunk> future = new ResultsFuture<LobChunk>();
future.getResultsReceiver().receiveResults(new LobChunk("<a/>".getBytes(Charset.forName("UTF-8")), true));
XMLType result = new XMLType();
Mockito.stub(statement.getDQP().requestNextLobChunk(0, 0, result.getReferenceStreamId())).toReturn(future);
ResultsMessage resultsMsg = new ResultsMessage();
result.setEncoding("UTF-8");
resultsMsg.setResults(new List<?>[] { Arrays.asList(result) });
resultsMsg.setLastRow(1);
resultsMsg.setFirstRow(1);
resultsMsg.setFinalRow(1);
// $NON-NLS-1$
resultsMsg.setColumnNames(new String[] { "x" });
// $NON-NLS-1$
resultsMsg.setDataTypes(new String[] { "xml" });
ResultSetImpl cs = new ResultSetImpl(resultsMsg, statement);
cs.next();
assertEquals("<a/>", cs.getString(1));
}
use of org.teiid.core.types.XMLType in project teiid by teiid.
the class TestProcessor method examineResults.
/**
* @param expectedResults
* @param bufferMgr
* @param tsID
* @throws TeiidComponentException
* @throws TeiidProcessingException
* @throws IOException
* @since 4.3
*/
static void examineResults(List[] expectedResults, BufferManager bufferMgr, TupleBuffer tsID) throws TeiidComponentException, SQLException, TeiidProcessingException, IOException {
// Create QueryResults from TupleSource
TupleSource ts = tsID.createIndexedTupleSource();
long count = tsID.getRowCount();
// Compare actual to expected row count
// $NON-NLS-1$
assertEquals("Did not get expected row count: ", expectedResults.length, count);
// Walk results and compare
for (int i = 0; i < count; i++) {
List record = ts.nextTuple();
// handle xml
if (record.size() == 1 && expectedResults[i].size() == 1) {
Object cellValue = record.get(0);
if (cellValue instanceof XMLType) {
XMLType id = (XMLType) cellValue;
String actualDoc = id.getString();
if (expectedResults[i].size() == 1) {
compareDocuments((String) expectedResults[i].get(0), actualDoc);
continue;
}
} else if (cellValue instanceof Clob) {
Clob id = (Clob) cellValue;
String actualDoc = ClobType.getString(id);
if (expectedResults[i].size() == 1) {
compareDocuments((String) expectedResults[i].get(0), actualDoc);
continue;
}
}
}
// $NON-NLS-1$ //$NON-NLS-2$
assertEquals("Row " + i + " does not match expected: ", expectedResults[i], record);
}
ts.closeSource();
}
use of org.teiid.core.types.XMLType in project teiid by teiid.
the class TestSQLXMLProcessing method testStaxComment.
@Test
public void testStaxComment() throws Exception {
// $NON-NLS-1$
String sql = "select * from xmltable('/*:Person/phoneNumber' passing cast(? as xml) columns x string path 'type', y string path 'number') as x";
List<?>[] expected = new List<?>[] { Arrays.asList(null, "8881112222") };
XMLInputFactory factory = XMLInputFactory.newFactory();
XMLEventReader reader = factory.createXMLEventReader(new StringReader("<Person><!--hello--><phoneNumber><number>8881112222</number></phoneNumber></Person>"));
XMLType value = new XMLType(new StAXSQLXML(new StAXSource(reader)));
value.setType(Type.DOCUMENT);
Command command = helpParse(sql);
CommandContext context = createCommandContext();
QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
context.setMetadata(metadata);
CapabilitiesFinder capFinder = new DefaultCapabilitiesFinder();
ProcessorPlan plan = helpGetPlan(command, metadata, capFinder, context);
setParameterValues(Arrays.asList(value), command, context);
doProcess(plan, dataManager, expected, context);
}
use of org.teiid.core.types.XMLType in project teiid by teiid.
the class TestFunctionResolving method assertEval.
/**
* Helper to verify the result of an expression.
*
* @param expr SQL expression.
* @param result Expected result.
* @throws Exception
*/
public static void assertEval(String expr, String result) throws Exception {
Expression ex = TestFunctionResolving.getExpression(expr);
Object val = Evaluator.evaluate(ex);
String valStr;
if (val instanceof Clob) {
valStr = ClobType.getString((Clob) val);
} else if (val instanceof XMLType) {
valStr = ((XMLType) val).getString();
} else {
valStr = val.toString();
}
assertEquals(result, valStr);
}
Aggregations