public String getContentOfTestFile( final String testFilePath ) throws IOException { final File file = UnitTestUtil.getTestDataFile(testFilePath); return ObjectConverterUtil.convertFileToString(file); }
public void testNoPassword() throws Exception { SocketUtil.loadKeyStore(UnitTestUtil.getTestDataFile("metamatrix.keystore").getAbsolutePath(), null, "JKS"); //$NON-NLS-1$ //$NON-NLS-2$ }
@Test public void testUTF8() throws Exception { FileInputStream fis = new FileInputStream(UnitTestUtil.getTestDataFile("legal_notice.xml")); //$NON-NLS-1$ ReaderInputStream ris = new ReaderInputStream(new FileReader(UnitTestUtil.getTestDataFile("legal_notice.xml")), Charset.forName("UTF-8")); //$NON-NLS-1$ //$NON-NLS-2$ int value; while (true) { value = fis.read(); assertEquals(value, ris.read()); if (value == -1) { break; } } }
@Test public void testCompatibility() throws Exception { ObjectInputStream ois = new ObjectInputStream(new FileInputStream(UnitTestUtil.getTestDataFile("handshake.ser"))); Handshake hs = (Handshake)ois.readObject(); assertEquals(AuthenticationType.USERPASSWORD, hs.getAuthType()); }
@Test public void test81Schema() throws Exception { ObjectInputStream ois = new ObjectInputStream(new FileInputStream(UnitTestUtil.getTestDataFile("schema.ser"))); Schema schema = (Schema) ois.readObject(); assertNotNull(schema.getFunctions()); }
@Test public void testDeserializationUnknownChildException2() throws Exception { ClassLoader cl = new URLClassLoader(new URL[] {UnitTestUtil.getTestDataFile("test.jar").toURI().toURL()}); //$NON-NLS-1$ ArrayList<String> args = new ArrayList<String>(); args.add("Unknown Exception"); //$NON-NLS-1$ Exception obj = (Exception)ReflectionHelper.create("test.UnknownException", args, cl); //$NON-NLS-1$ ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(new ExceptionHolder(obj)); oos.flush(); ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); ExceptionHolder holder = (ExceptionHolder)ois.readObject(); Throwable e = holder.getException(); assertTrue(e instanceof TeiidRuntimeException); assertEquals("Remote test.UnknownException: Unknown Exception", e.getMessage()); //$NON-NLS-1$ }
@Test public void testDeserializationUnknownException() throws Exception { ClassLoader cl = new URLClassLoader(new URL[] {UnitTestUtil.getTestDataFile("test.jar").toURI().toURL()}); //$NON-NLS-1$ Object obj = ReflectionHelper.create("test.Test", null, cl); //$NON-NLS-1$ ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(new ExceptionHolder(new BadException(obj))); oos.flush(); ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); ExceptionHolder holder = (ExceptionHolder)ois.readObject(); assertTrue(holder.getException() instanceof BadException); assertEquals("Remote org.teiid.client.util.TestExceptionHolder$BadException: null", holder.getException().getMessage()); //$NON-NLS-1$ }
@Test public void testXmlParseBlobWithEncoding() throws Exception { String sql = "select xmlparse(document cast(? as blob)) x"; //$NON-NLS-1$ List[] expected = new List[] { Arrays.asList(ObjectConverterUtil.convertToString(new InputStreamReader(new FileInputStream(UnitTestUtil.getTestDataFile("encoding.xml")), Charset.forName("ISO-8859-1")))), }; processPreparedStatement(sql, expected, dataManager, new DefaultCapabilitiesFinder(), RealMetadataFactory.example1Cached(), Arrays.asList(blobFromFile("encoding.xml"))); }
@Test public void testDeserializationUnknownChildException() throws Exception { ClassLoader cl = new URLClassLoader(new URL[] {UnitTestUtil.getTestDataFile("test.jar").toURI().toURL()}); //$NON-NLS-1$ Exception obj = (Exception)ReflectionHelper.create("test.UnknownException", null, cl); //$NON-NLS-1$ obj.initCause(new SQLException("something bad happended")); //$NON-NLS-1$ ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(new ExceptionHolder(new BadException2(obj, "I have foreign exception embedded in me"))); //$NON-NLS-1$ oos.flush(); ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); ExceptionHolder holder = (ExceptionHolder)ois.readObject(); Throwable e = holder.getException(); assertTrue(e instanceof BadException2); assertEquals("Remote org.teiid.client.util.TestExceptionHolder$BadException2: I have foreign exception embedded in me", e.getMessage()); //$NON-NLS-1$ e = e.getCause(); assertTrue(e instanceof TeiidRuntimeException); e = e.getCause(); assertTrue(e instanceof SQLException); assertEquals("Remote java.sql.SQLException: something bad happended", e.getMessage()); //$NON-NLS-1$ }
@Test public void testSourceWarning() throws Exception { ClassLoader cl = new URLClassLoader(new URL[] {UnitTestUtil.getTestDataFile("test.jar").toURI().toURL()}); //$NON-NLS-1$ ArrayList<String> args = new ArrayList<String>(); args.add("Unknown Exception"); //$NON-NLS-1$ Exception obj = (Exception)ReflectionHelper.create("test.UnknownException", args, cl); //$NON-NLS-1$ ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(new ExceptionHolder(new SourceWarning("x", "y", obj, true))); oos.flush(); ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); ExceptionHolder holder = (ExceptionHolder)ois.readObject(); SourceWarning sw = (SourceWarning)holder.getException(); assertEquals(sw.getConnectorBindingName(), "y"); assertEquals(sw.getModelName(), "x"); assertTrue(sw.isPartialResultsError()); try { ois = new ObjectInputStream(new FileInputStream(UnitTestUtil.getTestDataFile("old-exceptionholder.ser"))); holder = (ExceptionHolder)ois.readObject(); assertTrue(holder.getException() instanceof TeiidException); } finally { ois.close(); } } }
@Test public void testXmlParseClob() throws Exception { String sql = "select xmlparse(document cast(? as clob)) x"; //$NON-NLS-1$ List[] expected = new List[] { Arrays.asList(ObjectConverterUtil.convertToString(new FileInputStream(UnitTestUtil.getTestDataFile("udf.xmi")))), }; processPreparedStatement(sql, expected, dataManager, new DefaultCapabilitiesFinder(), RealMetadataFactory.example1Cached(), Arrays.asList(TestTextTable.clobFromFile("udf.xmi"))); }
@Test public void testXmlParseBlob() throws Exception { String sql = "select xmlparse(document cast(? as blob)) x"; //$NON-NLS-1$ List[] expected = new List[] { Arrays.asList(ObjectConverterUtil.convertToString(new FileInputStream(UnitTestUtil.getTestDataFile("udf.xmi")))), }; processPreparedStatement(sql, expected, dataManager, new DefaultCapabilitiesFinder(), RealMetadataFactory.example1Cached(), Arrays.asList(blobFromFile("udf.xmi"))); }
@Test public void test83() throws FileNotFoundException, IOException, ClassNotFoundException { CompactObjectInputStream ois = new CompactObjectInputStream(new FileInputStream(UnitTestUtil.getTestDataFile("req.ser")), RequestMessage.class.getClassLoader()); RequestMessage rm = (RequestMessage) ois.readObject(); ois.close(); assertFalse(rm.isReturnAutoGeneratedKeys()); assertFalse(rm.isDelaySerialization()); }
@Test public void testSQLExceptionChain() throws Exception { ClassLoader cl = new URLClassLoader(new URL[] {UnitTestUtil.getTestDataFile("test.jar").toURI().toURL()}); //$NON-NLS-1$ Exception obj = (Exception)ReflectionHelper.create("test.UnknownException", null, cl); //$NON-NLS-1$ SQLException se = new SQLException("something bad happened");
@Test public void testTupleBufferCacheAndWithClause() throws Exception { CommandContext cc = TestProcessor.createCommandContext(); BasicSourceCapabilities bsc = TestOptimizer.getTypicalCapabilities(); bsc.setCapabilitySupport(Capability.QUERY_FROM_JOIN_SELFJOIN, true); bsc.setCapabilitySupport(Capability.QUERY_UNION, true); TransformationMetadata metadata = RealMetadataFactory.fromDDL("create foreign table test_a (a integer, b integer);", "x", "test"); String sql = ObjectConverterUtil.convertFileToString(UnitTestUtil.getTestDataFile("cte-query.sql")); ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata, new DefaultCapabilitiesFinder(bsc), cc); FakeDataManager fdm = new FakeDataManager(); fdm.registerTuples(metadata, "test_a", new List<?>[] { Arrays.asList(1, 1), Arrays.asList(3, 10),}); TestProcessor.helpProcess(plan, fdm, new List<?>[] {Arrays.asList(3, 3)}); }
public static BlobType blobFromFile(final String file) { return new BlobType(new BlobImpl(new InputStreamFactory.FileInputStreamFactory(UnitTestUtil.getTestDataFile(file)))); }
public static ClobType clobFromFile(final String file) { return new ClobType(new ClobImpl(new InputStreamFactory.FileInputStreamFactory(UnitTestUtil.getTestDataFile(file)), -1)); }