use of io.vertigo.commons.transaction.VTransactionWritable in project vertigo by KleeGroup.
the class AbstractStoreManagerTest method testTxNativeInsertRollbackCrudSelectRollback.
@Test
public void testTxNativeInsertRollbackCrudSelectRollback() {
try (VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
final Car car = createNewCar();
nativeInsertCar(car);
}
try (VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
// on récupère la liste des voitures
checkCrudCarsCount(0);
}
}
use of io.vertigo.commons.transaction.VTransactionWritable in project vertigo by KleeGroup.
the class AbstractStoreManagerTest method testCreateFile.
@Test
public void testCreateFile() throws Exception {
try (final VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
// 1.Création du fichier depuis un fichier texte du FS
final VFile vFile = TestUtil.createVFile(fileManager, "../data/lautreamont.txt", AbstractStoreManagerTest.class);
// 2. Sauvegarde en BDD
final FileInfo fileInfo = new FileInfoStd(vFile);
final FileInfo createdFileInfo = storeManager.getFileStore().create(fileInfo);
// 3.relecture du fichier
final FileInfo readFileInfo = storeManager.getFileStore().read(createdFileInfo.getURI());
// 4. comparaison du fichier créé et du fichier lu.
final String source;
try (final OutputStream sourceOS = new java.io.ByteArrayOutputStream()) {
FileUtil.copy(vFile.createInputStream(), sourceOS);
source = sourceOS.toString();
}
final String read;
try (final OutputStream readOS = new java.io.ByteArrayOutputStream()) {
FileUtil.copy(readFileInfo.getVFile().createInputStream(), readOS);
read = readOS.toString();
}
// on vérifie que le contenu des fichiers est identique.
// assertEquals("toto", "toto");
// assertEquals("toto", "ti");
Assert.assertEquals(source, read);
Assert.assertTrue("Test contenu du fichier", read.startsWith("Chant I"));
Assert.assertTrue("Test contenu du fichier : " + secureSubString(read, 16711, "ses notes langoureuses,"), read.indexOf("ses notes langoureuses,") > 0);
Assert.assertTrue("Test contenu du fichier : " + secureSubString(read, 11004, "mal : \"Adolescent,"), read.indexOf("mal : \"Adolescent,") > 0);
// On désactive pour l'instant
// Ne marche pas sur la PIC pour cause de charset sur le àé //Assert.assertTrue("Test contenu du fichier : " + secureSubString(read, 15579, "adieu !à ;"), read.indexOf("adieu !à ;") > 0);
}
}
use of io.vertigo.commons.transaction.VTransactionWritable in project vertigo by KleeGroup.
the class AbstractStoreManagerTest method testCreateFamilleFail.
/**
* on vérifier l'exception levée si une contrainte bdd n'est pas respecté.
*/
@Test(expected = Exception.class)
public void testCreateFamilleFail() {
try (VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
final DecimalFormat df = new DecimalFormat("000000000:");
// -----
final Famille famille = new Famille();
final StringBuilder sb = new StringBuilder();
for (int i = 0; i < 4000; i++) {
sb.append(df.format(i));
}
// libelle
famille.setLibelle(sb.toString());
// On doit échouer car le libellé est trop long
storeManager.getDataStore().create(famille);
Assert.fail();
}
}
use of io.vertigo.commons.transaction.VTransactionWritable in project vertigo by KleeGroup.
the class AbstractStoreManagerTest method testTxCrudInsertCommitNativeSelectRollback.
@Test
public void testTxCrudInsertCommitNativeSelectRollback() {
try (VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
final Car car = createNewCar();
storeManager.getDataStore().create(car);
transaction.commit();
}
try (VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
// on récupère la liste des voitures
checkNativeCarsCount(1);
}
}
use of io.vertigo.commons.transaction.VTransactionWritable in project vertigo by KleeGroup.
the class AbstractStoreManagerTest method testTxCrudInsertRollbackNativeSelectRollback.
@Test
public void testTxCrudInsertRollbackNativeSelectRollback() {
try (VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
final Car car = createNewCar();
storeManager.getDataStore().create(car);
}
try (VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
checkNativeCarsCount(0);
}
}
Aggregations