Search in sources :

Example 1 with NotActiveException

use of java.io.NotActiveException in project robovm by robovm.

the class Test method test_registerValidation.

public void test_registerValidation() throws Exception {
    // Regression Test for Harmony-2402
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    new ObjectOutputStream(baos);
    ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
    try {
        ois.registerValidation(null, 256);
        fail("NotActiveException should be thrown");
    } catch (NotActiveException nae) {
    // expected
    }
    // Regression Test for Harmony-3916
    baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(new RegisterValidationClass());
    oos.close();
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    ObjectInputStream fis = new ObjectInputStream(bais);
    // should not throw NotActiveException
    fis.readObject();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) NotActiveException(java.io.NotActiveException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 2 with NotActiveException

use of java.io.NotActiveException in project robovm by robovm.

the class Test method test_defaultReadObject.

/**
     * java.io.ObjectInputStream#defaultReadObject()
     */
public void test_defaultReadObject() throws Exception {
    // SM. This method may as well be private, as if called directly it
    // throws an exception.
    String s = "HelloWorld";
    oos.writeObject(s);
    oos.close();
    ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
    try {
        ois.defaultReadObject();
        fail("NotActiveException expected");
    } catch (NotActiveException e) {
    // Desired behavior
    } finally {
        ois.close();
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) NotActiveException(java.io.NotActiveException) ObjectInputStream(java.io.ObjectInputStream)

Example 3 with NotActiveException

use of java.io.NotActiveException in project robovm by robovm.

the class OldObjectOutputStreamTest method test_putFields.

public void test_putFields() throws Exception {
    /*
         * "SerializableTestHelper" is an object created for these tests with
         * two fields (Strings) and simple implementations of readObject and
         * writeObject which simply read and write the first field but not the
         * second one.
         */
    SerializableTestHelper sth;
    try {
        oos.putFields();
        fail("Test 1: NotActiveException expected.");
    } catch (NotActiveException e) {
    // Expected.
    }
    oos.writeObject(new SerializableTestHelper("Gabba", "Jabba"));
    oos.flush();
    ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
    sth = (SerializableTestHelper) (ois.readObject());
    assertEquals("Test 2: readFields or writeFields failed; first field not set.", "Gabba", sth.getText1());
    assertNull("Test 3: readFields or writeFields failed; second field should not have been set.", sth.getText2());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) NotActiveException(java.io.NotActiveException) ObjectInputStream(java.io.ObjectInputStream)

Example 4 with NotActiveException

use of java.io.NotActiveException in project jPOS by jpos.

the class TransactionManagerTest method testCommit4.

@Test
public void testCommit4() throws Throwable {
    LogEvent evt = new LogEvent("testTransactionManagerTag");
    transactionManager.commit(1, 100L, new NotActiveException("testTransactionManagerParam1"), members, true, evt, null);
    assertEquals("(ArrayList) members.size()", 0, members.size());
}
Also used : LogEvent(org.jpos.util.LogEvent) NotActiveException(java.io.NotActiveException) Test(org.junit.Test)

Example 5 with NotActiveException

use of java.io.NotActiveException in project jPOS by jpos.

the class TransactionManagerTest method testPrepare10.

@Test
public void testPrepare10() throws Throwable {
    HasEntry hasEntry = new HasEntry();
    AbstractList<TransactionParticipant> arrayList = new ArrayList();
    arrayList.add(new Debug());
    int result = transactionManager.prepare(1, 100L, new NotActiveException("testTransactionManagerParam1"), members, arrayList.iterator(), members.add(hasEntry), null, null);
    assertEquals("(ArrayList) members.size()", 2, members.size());
    assertSame("(ArrayList) members.get(0)", hasEntry, members.get(0));
    assertEquals("result", 0, result);
}
Also used : BSHTransactionParticipant(org.jpos.transaction.participant.BSHTransactionParticipant) HasEntry(org.jpos.transaction.participant.HasEntry) ArrayList(java.util.ArrayList) NotActiveException(java.io.NotActiveException) Debug(org.jpos.transaction.participant.Debug) CheckPoint(org.jpos.transaction.participant.CheckPoint) Test(org.junit.Test)

Aggregations

NotActiveException (java.io.NotActiveException)10 Test (org.junit.Test)6 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ObjectInputStream (java.io.ObjectInputStream)4 LogEvent (org.jpos.util.LogEvent)4 ArrayList (java.util.ArrayList)2 BSHTransactionParticipant (org.jpos.transaction.participant.BSHTransactionParticipant)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 CheckPoint (org.jpos.transaction.participant.CheckPoint)1 Debug (org.jpos.transaction.participant.Debug)1 HasEntry (org.jpos.transaction.participant.HasEntry)1 Trace (org.jpos.transaction.participant.Trace)1