@Test(dataProvider = "rowsetUsingCoffees") public void WebRowSetTest0004(WebRowSet wrs) throws Exception { ResultSet rs = wrs; rs.beforeFirst(); ByteArrayOutputStream baos = writeWebRowSetWithOutputStream(rs); try (WebRowSet wrs1 = readWebRowSetWithOInputStream(baos)) { assertEquals(getPrimaryKeys(wrs1), COFFEES_PRIMARY_KEYS); assertEquals(wrs1.size(), COFFEES_ROWS); } }
@Test(dataProvider = "rowsetUsingCoffees") public void WebRowSetTest0006(WebRowSet wrs) throws Exception { ResultSet rs = wrs; rs.beforeFirst(); ByteArrayOutputStream baos = writeWebRowSetWithOutputStreamWithWriter(rs); try (WebRowSet wrs1 = readWebRowSetWithOInputStreamWithReader(baos)) { assertEquals(getPrimaryKeys(wrs1), COFFEES_PRIMARY_KEYS); assertEquals(wrs1.size(), COFFEES_ROWS); } }
@Test(dataProvider = "rowSetType") public void WebRowSetTest0010(WebRowSet wrs1) throws Exception { FileInputStream fis = new FileInputStream(UPDATED_COFFEE_ROWS_XML); wrs1.readXml(fis); assertTrue(wrs1.size() == COFFEES_ROWS); assertEquals(getPrimaryKeys(wrs1), COFFEES_PRIMARY_KEYS); wrs1.beforeFirst(); while (wrs1.next()) { if (wrs1.getInt(1) == 3) { assertTrue(wrs1.rowUpdated()); assertTrue(wrs1.getInt(5) == 21 && wrs1.getInt(6) == 69); assertFalse(wrs1.rowDeleted()); assertFalse(wrs1.rowInserted()); } else { assertFalse(wrs1.rowUpdated()); assertFalse(wrs1.rowDeleted()); assertFalse(wrs1.rowInserted()); } } wrs1.close(); }
@Test(dataProvider = "rowSetType") public void WebRowSetTest0011(WebRowSet wrs1) throws Exception { int expectedSize = COFFEES_ROWS + 2; int addedRowPK = 15; int addedRowPK2 = 20; Object[] expected = Arrays.copyOf(COFFEES_PRIMARY_KEYS, expectedSize); expected[expectedSize - 2] = addedRowPK; expected[expectedSize - 1] = addedRowPK2; FileInputStream fis = new FileInputStream(INSERTED_COFFEE_ROWS_XML); wrs1.readXml(fis); assertTrue(wrs1.size() == expectedSize); assertEqualsNoOrder(getPrimaryKeys(wrs1), expected); wrs1.beforeFirst(); while (wrs1.next()) { if (wrs1.getInt(1) == 15 || wrs1.getInt(1) == 20) { assertTrue(wrs1.rowInserted()); assertFalse(wrs1.rowDeleted()); assertFalse(wrs1.rowUpdated()); } else { assertFalse(wrs1.rowInserted()); assertFalse(wrs1.rowDeleted()); assertFalse(wrs1.rowUpdated()); } } wrs1.close(); }
public void testWriteXML_Delete() throws Exception { WebRowSet webRs = newWebRowSet(); rs = st.executeQuery("SELECT * FROM USER_INFO"); webRs.populate(rs); webRs.absolute(3); webRs.deleteRow(); assertEquals(0, webRs.getRow()); webRs.writeXml(strWriter); assertTrue(webRs.isAfterLast()); Document doc = getDocument(strWriter); assertProperties(doc, webRs); assertMetadata(doc, webRs); assertData(doc, webRs); }
public static void assertData(Document doc, WebRowSet webRs) throws Exception { webRs.setShowDeleted(true); webRs.beforeFirst(); Element element = (Element) doc.getFirstChild(); Element dataEle = getElement(element, "data"); NodeList nodeList = dataEle.getChildNodes(); int rowIndex = 0; for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node instanceof Element) { rowIndex++; Element rowEle = (Element) node; assertRow(rowEle, webRs, rowIndex); } } assertEquals(webRs.size(), rowIndex); webRs.setShowDeleted(false); }
public void testReaderXml_Header() throws Exception { /* * when run on RI, the Attribute xmlns can be empty. And the * xsi:schemaLocation also can be empty. However, The value of the * attribute "prefix="xmlns",localpart="xsi" can't be empty. No matter * what the value of these attributes are, the output xml's header of * WebRowSet keeps the same. */ WebRowSet webRs = newWebRowSet(); Reader fileReader = new FileReader(XML_SRC_URL_INVALID_HEADER); webRs.readXml(fileReader); StringWriter strWriter = new StringWriter(); webRs.writeXml(strWriter); assertFalse(-1 == strWriter.toString().indexOf( "http://java.sun.com/xml/ns/jdbc")); assertFalse(-1 == strWriter.toString().indexOf( "http://www.w3.org/2001/XMLSchema-instance")); }
public void testReaderXml_Reader() throws Exception { WebRowSet webRs = newWebRowSet(); webRs.readXml(new FileReader(currentUrl)); /* * TODO A row is marked as delete in XML. The row isn't marked as delete * any more after populate to WebRowSet. */ if (!"true".equals(System.getProperty("Testing Harmony"))) { assertTrue(webRs.absolute(3)); assertEquals(3, webRs.getInt(1)); assertFalse(webRs.rowDeleted()); webRs.deleteRow(); } Document srcDoc = DocumentBuilderFactory.newInstance() .newDocumentBuilder().parse(currentUrl); XmlWriterTest.assertProperties(srcDoc, webRs); XmlWriterTest.assertMetadata(srcDoc, webRs); XmlWriterTest.assertData(srcDoc, webRs); }
public void testReaderXml_InputStream() throws Exception { WebRowSet webRs = newWebRowSet(); webRs.readXml(new FileInputStream(currentUrl)); /* * TODO A row is marked as delete in XML. The row isn't marked as delete * any more after populating to WebRowSet. */ if (!"true".equals(System.getProperty("Testing Harmony"))) { assertTrue(webRs.absolute(3)); assertEquals(3, webRs.getInt(1)); assertFalse(webRs.rowDeleted()); webRs.deleteRow(); } Document srcDoc = DocumentBuilderFactory.newInstance() .newDocumentBuilder().parse(currentUrl); XmlWriterTest.assertProperties(srcDoc, webRs); XmlWriterTest.assertMetadata(srcDoc, webRs); XmlWriterTest.assertData(srcDoc, webRs); }
protected ByteArrayOutputStream writeWebRowSetWithOutputStream(WebRowSet rs) throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { rs.writeXml(oos); } return baos; }
protected ByteArrayOutputStream writeWebRowSetWithOutputStream(ResultSet rs) throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { WebRowSet wrs = rsf.createWebRowSet(); wrs.writeXml(rs, oos); } return baos; }
protected WebRowSet readWebRowSetWithOInputStream(ByteArrayOutputStream baos) throws Exception { WebRowSet wrs1 = rsf.createWebRowSet(); try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) { wrs1.readXml(ois); } return wrs1; }
protected ByteArrayOutputStream writeWebRowSetWithOutputStreamWithWriter(ResultSet rs) throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); OutputStreamWriter osw = new OutputStreamWriter(baos); WebRowSet wrs = rsf.createWebRowSet(); wrs.writeXml(rs, osw); return baos; }
@Test(dataProvider = "rowSetType") public void WebRowSetTest0001(WebRowSet wrs1) throws Exception { try (FileReader fr = new FileReader(COFFEE_ROWS_XML)) { wrs1.readXml(fr); } assertEquals(getPrimaryKeys(wrs1), COFFEES_PRIMARY_KEYS); assertEquals(wrs1.size(), COFFEES_ROWS); wrs1.close(); }
@Test(dataProvider = "rowSetType") public void WebRowSetTest0002(WebRowSet wrs1) throws Exception { try (FileInputStream fis = new FileInputStream(COFFEE_ROWS_XML)) { wrs1.readXml(fis); } assertEquals(getPrimaryKeys(wrs1), COFFEES_PRIMARY_KEYS); assertEquals(wrs1.size(), COFFEES_ROWS); wrs1.close(); }
@Test(dataProvider = "rowsetUsingCoffees") public void WebRowSetTest0003(WebRowSet wrs) throws Exception { ByteArrayOutputStream baos = writeWebRowSetWithOutputStream(wrs); try (WebRowSet wrs1 = readWebRowSetWithOInputStream(baos)) { assertEquals(getPrimaryKeys(wrs1), COFFEES_PRIMARY_KEYS); assertEquals(wrs1.size(), COFFEES_ROWS); } }
@Test(dataProvider = "rowsetUsingCoffees") public void WebRowSetTest0005(WebRowSet wrs) throws Exception { ByteArrayOutputStream baos = writeWebRowSetWithOutputStreamWithWriter(wrs); try (WebRowSet wrs1 = readWebRowSetWithOInputStreamWithReader(baos)) { assertEquals(getPrimaryKeys(wrs1), COFFEES_PRIMARY_KEYS); assertEquals(wrs1.size(), COFFEES_ROWS); } }
@Test(dataProvider = "rowSetType") public void WebRowSetTest0008(WebRowSet wrs1) throws Exception { FileInputStream fis = new FileInputStream(COFFEE_ROWS_XML); wrs1.readXml(fis); assertTrue(wrs1.size() == COFFEES_ROWS); assertEquals(getPrimaryKeys(wrs1), COFFEES_PRIMARY_KEYS); // Validate that the rows are not marked as deleted, inserted or updated wrs1.beforeFirst(); while (wrs1.next()) { assertFalse(wrs1.rowDeleted()); assertFalse(wrs1.rowInserted()); assertFalse(wrs1.rowUpdated()); } wrs1.close(); }
@Test(dataProvider = "rowSetType") public void WebRowSetTest0012(WebRowSet wrs1) throws Exception { int expectedSize = COFFEES_ROWS + 1; int addedRowPK = 100; Object[] expected = Arrays.copyOf(COFFEES_PRIMARY_KEYS, expectedSize); expected[expectedSize - 1] = addedRowPK; FileInputStream fis = new FileInputStream(UPDATED_INSERTED_COFFEE_ROWS_XML); wrs1.readXml(fis); assertTrue(wrs1.size() == expectedSize); assertEquals(getPrimaryKeys(wrs1), expected); wrs1.beforeFirst(); while (wrs1.next()) { if (wrs1.getInt(1) == addedRowPK) { // Row that was inserted and updated assertTrue(wrs1.rowUpdated()); assertTrue( wrs1.getBigDecimal(4).equals(BigDecimal.valueOf(12.99)) && wrs1.getInt(6) == 125); assertFalse(wrs1.rowDeleted()); assertTrue(wrs1.rowInserted()); } else { // Remaining rows should only be inserted assertFalse(wrs1.rowUpdated()); assertFalse(wrs1.rowDeleted()); assertTrue(wrs1.rowInserted()); } } wrs1.close(); }