Package org.springframework.tests.transaction

Examples of org.springframework.tests.transaction.MockJtaTransaction


  }

  @Test
  public void testBlobSerializableTypeWithJtaSynchronization() throws Exception {
    TransactionManager tm = mock(TransactionManager.class);
    MockJtaTransaction transaction = new MockJtaTransaction();
    given(tm.getStatus()).willReturn(Status.STATUS_ACTIVE);
    given(tm.getTransaction()).willReturn(transaction);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject("content");
    oos.close();

    given(lobHandler.getBlobAsBinaryStream(rs, "column")).willReturn(
        new ByteArrayInputStream(baos.toByteArray()));

    BlobSerializableType type = new BlobSerializableType(lobHandler, tm);
    assertEquals(1, type.sqlTypes().length);
    assertEquals(Types.BLOB, type.sqlTypes()[0]);
    assertEquals(Serializable.class, type.returnedClass());
    assertTrue(type.isMutable());

    assertEquals("content", type.nullSafeGet(rs, new String[] {"column"}, null));
    type.nullSafeSet(ps, "content", 1);
    Synchronization synch = transaction.getSynchronization();
    assertNotNull(synch);
    synch.beforeCompletion();
    synch.afterCompletion(Status.STATUS_COMMITTED);
    verify(lobCreator).setBlobAsBytes(ps, 1, baos.toByteArray());
  }
View Full Code Here


  }

  @Test
  public void testBlobSerializableTypeWithJtaSynchronizationAndRollback() throws Exception {
    TransactionManager tm = mock(TransactionManager.class);
    MockJtaTransaction transaction = new MockJtaTransaction();
    given(tm.getStatus()).willReturn(Status.STATUS_ACTIVE);
    given(tm.getTransaction()).willReturn(transaction);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject("content");
    oos.close();

    given(lobHandler.getBlobAsBinaryStream(rs, "column")).willReturn(
        new ByteArrayInputStream(baos.toByteArray()));

    BlobSerializableType type = new BlobSerializableType(lobHandler, tm);
    assertEquals(1, type.sqlTypes().length);
    assertEquals(Types.BLOB, type.sqlTypes()[0]);
    assertEquals(Serializable.class, type.returnedClass());
    assertTrue(type.isMutable());

    assertEquals("content", type.nullSafeGet(rs, new String[] {"column"}, null));
    type.nullSafeSet(ps, "content", 1);
    Synchronization synch = transaction.getSynchronization();
    assertNotNull(synch);
    synch.afterCompletion(Status.STATUS_ROLLEDBACK);
    verify(lobCreator).setBlobAsBytes(ps, 1, baos.toByteArray());
  }
View Full Code Here

TOP

Related Classes of org.springframework.tests.transaction.MockJtaTransaction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.