Search in sources :

Example 91 with AssertionFailedError

use of junit.framework.AssertionFailedError in project poi by apache.

the class TestPageSettingsBlock method testDuplicateHeaderFooterInside_bug48026.

public void testDuplicateHeaderFooterInside_bug48026() {
    Record[] recs = { BOFRecord.createSheetBOF(), new IndexRecord(), //PageSettingsBlock
    new HeaderRecord("&LDecember"), new FooterRecord("&LJanuary"), new DimensionsRecord(), new WindowTwoRecord(), //CustomViewSettingsRecordAggregate
    new UserSViewBegin(HexRead.readFromString("53 CE BD CC DE 38 44 45 97 C1 5C 89 F9 37 32 1B 01 00 00 00 64 00 00 00 40 00 00 00 03 00 00 00 7D 00 00 20 00 00 34 00 00 00 18 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FF FF FF")), new SelectionRecord(0, 0), // the other is matched with a CustomViewSettingsRecordAggregate having UserSViewBegin with the same GUID
    new HeaderFooterRecord(HexRead.readFromString("9C 08 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 34 33 00 00 00 00 00 00 00 00")), new HeaderFooterRecord(HexRead.readFromString("9C 08 00 00 00 00 00 00 00 00 00 00 53 CE BD CC DE 38 44 45 97 C1 5C 89 F9 37 32 1B 34 33 00 00 00 00 00 00 00 00")), new UserSViewEnd(HexRead.readFromString("01 00")), EOFRecord.instance };
    RecordStream rs = new RecordStream(Arrays.asList(recs), 0);
    InternalSheet sheet;
    try {
        sheet = InternalSheet.createSheet(rs);
    } catch (RuntimeException e) {
        if (e.getMessage().equals("Duplicate PageSettingsBlock record (sid=0x89c)")) {
            throw new AssertionFailedError("Identified bug 48026");
        }
        throw e;
    }
    RecordCollector rv = new RecordCollector();
    sheet.visitContainedRecords(rv, 0);
    Record[] outRecs = rv.getRecords();
    assertEquals(recs.length + 1, outRecs.length);
    //expected order of records:
    Record[] expectedRecs = { //BOFRecord
    recs[0], //IndexRecord
    recs[1], //HeaderRecord
    recs[2], //FooterRecord
    recs[3], // DimensionsRecord
    recs[4], // WindowTwoRecord
    recs[5], // UserSViewBegin
    recs[6], // SelectionRecord
    recs[7], //HeaderRecord
    recs[2], //FooterRecord
    recs[3], // HeaderFooterRecord
    recs[8], // UserSViewEnd
    recs[10], //EOFRecord
    recs[11] };
    for (int i = 0; i < expectedRecs.length; i++) {
        assertEquals("Record mismatch at index " + i, expectedRecs[i].getClass(), outRecs[i].getClass());
    }
    HeaderFooterRecord hd1 = (HeaderFooterRecord) expectedRecs[10];
    //GUID is zero
    assertArrayEquals(new byte[16], hd1.getGuid());
    assertTrue(hd1.isCurrentSheet());
    UserSViewBegin svb = (UserSViewBegin) expectedRecs[6];
    HeaderFooterRecord hd2 = (HeaderFooterRecord) recs[9];
    assertFalse(hd2.isCurrentSheet());
    //GUIDs of HeaderFooterRecord and UserSViewBegin must be the same
    assertArrayEquals(svb.getGuid(), hd2.getGuid());
}
Also used : RecordCollector(org.apache.poi.hssf.usermodel.RecordInspector.RecordCollector) RecordStream(org.apache.poi.hssf.model.RecordStream) InternalSheet(org.apache.poi.hssf.model.InternalSheet) AssertionFailedError(junit.framework.AssertionFailedError)

Example 92 with AssertionFailedError

use of junit.framework.AssertionFailedError in project poi by apache.

the class TestPageSettingsBlock method testPrintSetup_bug46548.

public void testPrintSetup_bug46548() {
    // PageSettingBlock in this file contains PLS (sid=x004D) record
    // followed by ContinueRecord (sid=x003C)
    HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("ex46548-23133.xls");
    HSSFSheet sheet = wb.getSheetAt(0);
    HSSFPrintSetup ps = sheet.getPrintSetup();
    try {
        ps.getCopies();
    } catch (NullPointerException e) {
        e.printStackTrace();
        throw new AssertionFailedError("Identified bug 46548: PageSettingBlock missing PrintSetupRecord record");
    }
}
Also used : HSSFPrintSetup(org.apache.poi.hssf.usermodel.HSSFPrintSetup) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) AssertionFailedError(junit.framework.AssertionFailedError) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Example 93 with AssertionFailedError

use of junit.framework.AssertionFailedError in project poi by apache.

the class TestPageSettingsBlock method testMissingHeaderFooter.

/**
	 * Excel tolerates missing header / footer records, but adds them (empty) in when re-saving.
	 * This is not critical functionality but it has been decided to keep POI consistent with
	 * Excel in this regard.
	 */
public void testMissingHeaderFooter() {
    // initialise PSB with some records, but not the header / footer
    Record[] recs = { new HCenterRecord(), new VCenterRecord() };
    RecordStream rs = new RecordStream(Arrays.asList(recs), 0);
    PageSettingsBlock psb = new PageSettingsBlock(rs);
    // serialize the PSB to see what records come out
    RecordCollector rc = new RecordCollector();
    psb.visitContainedRecords(rc);
    Record[] outRecs = rc.getRecords();
    if (outRecs.length == 2) {
        throw new AssertionFailedError("PageSettingsBlock didn't add missing header/footer records");
    }
    assertEquals(4, outRecs.length);
    assertEquals(HeaderRecord.class, outRecs[0].getClass());
    assertEquals(FooterRecord.class, outRecs[1].getClass());
    assertEquals(HCenterRecord.class, outRecs[2].getClass());
    assertEquals(VCenterRecord.class, outRecs[3].getClass());
    // make sure the added header / footer records are empty
    HeaderRecord hr = (HeaderRecord) outRecs[0];
    assertEquals("", hr.getText());
    FooterRecord fr = (FooterRecord) outRecs[1];
    assertEquals("", fr.getText());
}
Also used : RecordStream(org.apache.poi.hssf.model.RecordStream) RecordCollector(org.apache.poi.hssf.usermodel.RecordInspector.RecordCollector) AssertionFailedError(junit.framework.AssertionFailedError)

Example 94 with AssertionFailedError

use of junit.framework.AssertionFailedError in project poi by apache.

the class TestPageSettingsBlock method testLateHeaderFooter_bug46953.

/**
	 * Bug 46953 occurred because POI didn't handle late PSB records properly.
	 */
public void testLateHeaderFooter_bug46953() {
    int rowIx = 5;
    int colIx = 6;
    NumberRecord nr = new NumberRecord();
    nr.setRow(rowIx);
    nr.setColumn((short) colIx);
    nr.setValue(3.0);
    Record[] recs = { BOFRecord.createSheetBOF(), new HeaderRecord("&LSales Figures"), new FooterRecord("&LJanuary"), new DimensionsRecord(), new WindowTwoRecord(), new HeaderFooterRecord(HexRead.readFromString("9C 08 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 C4 60 00 00 00 00 00 00 00 00")), EOFRecord.instance };
    RecordStream rs = new RecordStream(Arrays.asList(recs), 0);
    InternalSheet sheet = InternalSheet.createSheet(rs);
    RecordCollector rv = new RecordCollector();
    sheet.visitContainedRecords(rv, 0);
    Record[] outRecs = rv.getRecords();
    if (outRecs[4] == EOFRecord.instance) {
        throw new AssertionFailedError("Identified bug 46953 - EOF incorrectly appended to PSB");
    }
    // +1 for index record
    assertEquals(recs.length + 1, outRecs.length);
    assertEquals(BOFRecord.class, outRecs[0].getClass());
    assertEquals(IndexRecord.class, outRecs[1].getClass());
    assertEquals(HeaderRecord.class, outRecs[2].getClass());
    assertEquals(FooterRecord.class, outRecs[3].getClass());
    assertEquals(HeaderFooterRecord.class, outRecs[4].getClass());
    assertEquals(DimensionsRecord.class, outRecs[5].getClass());
    assertEquals(WindowTwoRecord.class, outRecs[6].getClass());
    assertEquals(EOFRecord.instance, outRecs[7]);
}
Also used : RecordCollector(org.apache.poi.hssf.usermodel.RecordInspector.RecordCollector) RecordStream(org.apache.poi.hssf.model.RecordStream) InternalSheet(org.apache.poi.hssf.model.InternalSheet) AssertionFailedError(junit.framework.AssertionFailedError)

Example 95 with AssertionFailedError

use of junit.framework.AssertionFailedError in project poi by apache.

the class TestPageSettingsBlock method testDuplicateHeaderFooter_bug48026.

public void testDuplicateHeaderFooter_bug48026() {
    Record[] recs = { BOFRecord.createSheetBOF(), new IndexRecord(), //PageSettingsBlock
    new HeaderRecord("&LDecember"), new FooterRecord("&LJanuary"), new DimensionsRecord(), new WindowTwoRecord(), //CustomViewSettingsRecordAggregate
    new UserSViewBegin(HexRead.readFromString("53 CE BD CC DE 38 44 45 97 C1 5C 89 F9 37 32 1B 01 00 00 00 64 00 00 00 40 00 00 00 03 00 00 00 7D 00 00 20 00 00 34 00 00 00 18 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FF FF FF")), new SelectionRecord(0, 0), new UserSViewEnd(HexRead.readFromString("01 00")), // the other is matched with a CustomViewSettingsRecordAggregate having UserSViewBegin with the same GUID
    new HeaderFooterRecord(HexRead.readFromString("9C 08 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 34 33 00 00 00 00 00 00 00 00")), new HeaderFooterRecord(HexRead.readFromString("9C 08 00 00 00 00 00 00 00 00 00 00 53 CE BD CC DE 38 44 45 97 C1 5C 89 F9 37 32 1B 34 33 00 00 00 00 00 00 00 00")), EOFRecord.instance };
    RecordStream rs = new RecordStream(Arrays.asList(recs), 0);
    InternalSheet sheet;
    try {
        sheet = InternalSheet.createSheet(rs);
    } catch (RuntimeException e) {
        if (e.getMessage().equals("Duplicate PageSettingsBlock record (sid=0x89c)")) {
            throw new AssertionFailedError("Identified bug 48026");
        }
        throw e;
    }
    RecordCollector rv = new RecordCollector();
    sheet.visitContainedRecords(rv, 0);
    Record[] outRecs = rv.getRecords();
    assertEquals(recs.length, outRecs.length);
    //expected order of records:
    Record[] expectedRecs = { //BOFRecord
    recs[0], //IndexRecord
    recs[1], //HeaderRecord
    recs[2], //FooterRecord
    recs[3], //HeaderFooterRecord
    recs[9], // DimensionsRecord
    recs[4], // WindowTwoRecord
    recs[5], // UserSViewBegin
    recs[6], // SelectionRecord
    recs[7], // HeaderFooterRecord
    recs[10], // UserSViewEnd
    recs[8], //EOFRecord
    recs[11] };
    for (int i = 0; i < expectedRecs.length; i++) {
        assertEquals("Record mismatch at index " + i, expectedRecs[i].getClass(), outRecs[i].getClass());
    }
    HeaderFooterRecord hd1 = (HeaderFooterRecord) expectedRecs[4];
    //GUID is zero
    assertArrayEquals(new byte[16], hd1.getGuid());
    assertTrue(hd1.isCurrentSheet());
    UserSViewBegin svb = (UserSViewBegin) expectedRecs[7];
    HeaderFooterRecord hd2 = (HeaderFooterRecord) expectedRecs[9];
    assertFalse(hd2.isCurrentSheet());
    //GUIDs of HeaderFooterRecord and UserSViewBegin must be the same
    assertArrayEquals(svb.getGuid(), hd2.getGuid());
}
Also used : RecordCollector(org.apache.poi.hssf.usermodel.RecordInspector.RecordCollector) RecordStream(org.apache.poi.hssf.model.RecordStream) InternalSheet(org.apache.poi.hssf.model.InternalSheet) AssertionFailedError(junit.framework.AssertionFailedError)

Aggregations

AssertionFailedError (junit.framework.AssertionFailedError)787 TestFailureException (org.apache.openejb.test.TestFailureException)503 JMSException (javax.jms.JMSException)336 EJBException (javax.ejb.EJBException)334 RemoteException (java.rmi.RemoteException)268 InitialContext (javax.naming.InitialContext)168 RemoveException (javax.ejb.RemoveException)80 CreateException (javax.ejb.CreateException)77 NamingException (javax.naming.NamingException)65 BasicStatefulObject (org.apache.openejb.test.stateful.BasicStatefulObject)42 Test (org.junit.Test)42 BasicBmpObject (org.apache.openejb.test.entity.bmp.BasicBmpObject)41 BasicStatelessObject (org.apache.openejb.test.stateless.BasicStatelessObject)38 CountDownLatch (java.util.concurrent.CountDownLatch)28 EntityManager (javax.persistence.EntityManager)21 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)21 EntityManagerFactory (javax.persistence.EntityManagerFactory)17 IOException (java.io.IOException)16 DataSource (javax.sql.DataSource)16 ConnectionFactory (javax.jms.ConnectionFactory)15