Search in sources :

Example 96 with AssertionFailedError

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

the class TestPageSettingsBlock method testDuplicatePSBRecord_bug47199.

/**
	 * The PageSettingsBlock should not allow multiple copies of the same record.  This extra assertion
	 * was added while fixing bug 47199.  All existing POI test samples comply with this requirement.
	 */
public void testDuplicatePSBRecord_bug47199() {
    // Hypothetical setup of PSB records which should cause POI to crash
    Record[] recs = { new HeaderRecord("&LSales Figures"), new HeaderRecord("&LInventory") };
    RecordStream rs = new RecordStream(Arrays.asList(recs), 0);
    try {
        new PageSettingsBlock(rs);
        throw new AssertionFailedError("Identified bug 47199b - duplicate PSB records should not be allowed");
    } catch (org.apache.poi.util.RecordFormatException e) {
        if (!e.getMessage().equals("Duplicate PageSettingsBlock record (sid=0x14)")) {
            throw new AssertionFailedError("Expected RecordFormatException due to duplicate PSB record");
        }
    }
}
Also used : RecordStream(org.apache.poi.hssf.model.RecordStream) AssertionFailedError(junit.framework.AssertionFailedError)

Example 97 with AssertionFailedError

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

the class TestWriteAccessRecord method testMissingStringHeader_bug47001a.

public void testMissingStringHeader_bug47001a() {
    /*
		 * Data taken from offset 0x0224 in
		 * attachment 23468 from bugzilla 47001
		 */
    byte[] data = HexRead.readFromString("" + "5C 00 70 00 " + "4A 61 76 61 20 45 78 63 65 6C 20 41 50 49 20 76 " + "32 2E 36 2E 34" + "20 20 20 20 20 20 20 20 20 20 20 " + "20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 " + HEX_SIXTYFOUR_SPACES);
    RecordInputStream in = TestcaseRecordInputStream.create(data);
    WriteAccessRecord rec;
    try {
        rec = new WriteAccessRecord(in);
    } catch (RecordFormatException e) {
        if (e.getMessage().equals("Not enough data (0) to read requested (1) bytes")) {
            throw new AssertionFailedError("Identified bug 47001a");
        }
        throw e;
    }
    assertEquals("Java Excel API v2.6.4", rec.getUsername());
    byte[] expectedEncoding = HexRead.readFromString("" + "15 00 00 4A 61 76 61 20 45 78 63 65 6C 20 41 50 " + "49 20 76 32 2E 36 2E 34" + "20 20 20 20 20 20 20 20 " + "20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 " + HEX_SIXTYFOUR_SPACES);
    TestcaseRecordInputStream.confirmRecordEncoding(WriteAccessRecord.sid, expectedEncoding, rec.serialize());
}
Also used : AssertionFailedError(junit.framework.AssertionFailedError)

Example 98 with AssertionFailedError

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

the class TestcaseRecordInputStream method confirmRecordEncoding.

/**
	 * Confirms data sections are equal
	 * @param msgPrefix message prefix to be displayed in case of failure
	 * @param expectedData - just raw data (without ushort sid, ushort size)
	 * @param actualRecordBytes this includes 4 prefix bytes (sid & size)
	 */
public static void confirmRecordEncoding(String msgPrefix, int expectedSid, byte[] expectedData, byte[] actualRecordBytes) throws AssertionFailedError {
    int expectedDataSize = expectedData.length;
    Assert.assertEquals("Size of encode data mismatch", actualRecordBytes.length - 4, expectedDataSize);
    Assert.assertEquals(expectedSid, LittleEndian.getShort(actualRecordBytes, 0));
    Assert.assertEquals(expectedDataSize, LittleEndian.getShort(actualRecordBytes, 2));
    for (int i = 0; i < expectedDataSize; i++) if (expectedData[i] != actualRecordBytes[i + 4]) {
        StringBuilder sb = new StringBuilder(64);
        if (msgPrefix != null) {
            sb.append(msgPrefix).append(": ");
        }
        sb.append("At offset ").append(i);
        sb.append(": expected ").append(HexDump.byteToHex(expectedData[i]));
        sb.append(" but found ").append(HexDump.byteToHex(actualRecordBytes[i + 4]));
        throw new AssertionFailedError(sb.toString());
    }
}
Also used : AssertionFailedError(junit.framework.AssertionFailedError)

Example 99 with AssertionFailedError

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

the class TestPLVRecord method testPLVRecord.

public void testPLVRecord() throws Exception {
    InputStream is = HSSFTestDataSamples.openSampleFileStream(XLS_FILENAME);
    HSSFWorkbook workbook = new HSSFWorkbook(is);
    CellRangeAddressList cellRange = new CellRangeAddressList(0, 0, 1, 1);
    DataValidationConstraint constraint = DVConstraint.createFormulaListConstraint(DV_DEFINITION);
    HSSFDataValidation dataValidation = new HSSFDataValidation(cellRange, constraint);
    // This used to throw an error before
    try {
        workbook.getSheet(SHEET_NAME).addValidationData(dataValidation);
    } catch (IllegalStateException ex) {
        throw new AssertionFailedError("Identified bug 53972, PLV record breaks addDataValidation()");
    }
}
Also used : HSSFDataValidation(org.apache.poi.hssf.usermodel.HSSFDataValidation) InputStream(java.io.InputStream) DataValidationConstraint(org.apache.poi.ss.usermodel.DataValidationConstraint) CellRangeAddressList(org.apache.poi.ss.util.CellRangeAddressList) AssertionFailedError(junit.framework.AssertionFailedError) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Example 100 with AssertionFailedError

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

the class TestRecalcIdRecord method testBadFirstField_bug48096.

public void testBadFirstField_bug48096() {
    /**
		 * Data taken from the sample file referenced in Bugzilla 48096, file offset 0x0D45.
		 * The apparent problem is that the first data short field has been written with the
		 * wrong <i>endianness</n>.  Excel seems to ignore whatever value is present in this
		 * field, and always rewrites it as (C1, 01). POI now does the same.
		 */
    byte[] badData = HexRead.readFromString("C1 01 08 00 01 C1 00 00 00 01 69 61");
    byte[] goodData = HexRead.readFromString("C1 01 08 00 C1 01 00 00 00 01 69 61");
    RecordInputStream in = TestcaseRecordInputStream.create(badData);
    RecalcIdRecord r;
    try {
        r = new RecalcIdRecord(in);
    } catch (RecordFormatException e) {
        if (e.getMessage().equals("expected 449 but got 49409")) {
            throw new AssertionFailedError("Identified bug 48096");
        }
        throw e;
    }
    assertEquals(0, in.remaining());
    assertArrayEquals(r.serialize(), goodData);
}
Also used : 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