Package org.springframework.transaction

Examples of org.springframework.transaction.MockJtaTransaction


  }

  public void testBlobSerializableTypeWithJtaSynchronization() throws Exception {
    MockControl tmControl = MockControl.createControl(TransactionManager.class);
    TransactionManager tm = (TransactionManager) tmControl.getMock();
    MockJtaTransaction transaction = new MockJtaTransaction();
    tm.getStatus();
    tmControl.setReturnValue(Status.STATUS_ACTIVE, 1);
    tm.getTransaction();
    tmControl.setReturnValue(transaction, 1);

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

    lobHandler.getBlobAsBinaryStream(rs, "column");
    lobHandlerControl.setReturnValue(new ByteArrayInputStream(baos.toByteArray()));
    lobCreator.setBlobAsBytes(ps, 1, baos.toByteArray());
    lobCreatorControl.setMatcher(new ArrayMatcher());

    lobHandlerControl.replay();
    lobCreatorControl.replay();

    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));
    tmControl.replay();
    type.nullSafeSet(ps, "content", 1);
    Synchronization synch = transaction.getSynchronization();
    assertNotNull(synch);
    synch.beforeCompletion();
    synch.afterCompletion(Status.STATUS_COMMITTED);
    tmControl.verify();
  }
View Full Code Here


  }

  public void testBlobSerializableTypeWithJtaSynchronizationAndRollback() throws Exception {
    MockControl tmControl = MockControl.createControl(TransactionManager.class);
    TransactionManager tm = (TransactionManager) tmControl.getMock();
    MockJtaTransaction transaction = new MockJtaTransaction();
    tm.getStatus();
    tmControl.setReturnValue(Status.STATUS_ACTIVE, 1);
    tm.getTransaction();
    tmControl.setReturnValue(transaction, 1);

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

    lobHandler.getBlobAsBinaryStream(rs, "column");
    lobHandlerControl.setReturnValue(new ByteArrayInputStream(baos.toByteArray()));
    lobCreator.setBlobAsBytes(ps, 1, baos.toByteArray());
    lobCreatorControl.setMatcher(new ArrayMatcher());

    lobHandlerControl.replay();
    lobCreatorControl.replay();

    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));
    tmControl.replay();
    type.nullSafeSet(ps, "content", 1);
    Synchronization synch = transaction.getSynchronization();
    assertNotNull(synch);
    synch.afterCompletion(Status.STATUS_ROLLEDBACK);
    tmControl.verify();
  }
View Full Code Here

TOP

Related Classes of org.springframework.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.