Search in sources :

Example 71 with VTransactionWritable

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);
    }
}
Also used : Car(io.vertigo.dynamo.store.data.domain.car.Car) VTransactionWritable(io.vertigo.commons.transaction.VTransactionWritable) Test(org.junit.Test)

Example 72 with VTransactionWritable

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);
    }
}
Also used : FileInfoStd(io.vertigo.dynamo.store.data.fileinfo.FileInfoStd) FileInfo(io.vertigo.dynamo.file.model.FileInfo) OutputStream(java.io.OutputStream) VTransactionWritable(io.vertigo.commons.transaction.VTransactionWritable) VFile(io.vertigo.dynamo.file.model.VFile) Test(org.junit.Test)

Example 73 with VTransactionWritable

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();
    }
}
Also used : Famille(io.vertigo.dynamo.store.data.domain.famille.Famille) DecimalFormat(java.text.DecimalFormat) VTransactionWritable(io.vertigo.commons.transaction.VTransactionWritable) Test(org.junit.Test)

Example 74 with VTransactionWritable

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);
    }
}
Also used : Car(io.vertigo.dynamo.store.data.domain.car.Car) VTransactionWritable(io.vertigo.commons.transaction.VTransactionWritable) Test(org.junit.Test)

Example 75 with VTransactionWritable

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);
    }
}
Also used : Car(io.vertigo.dynamo.store.data.domain.car.Car) VTransactionWritable(io.vertigo.commons.transaction.VTransactionWritable) Test(org.junit.Test)

Aggregations

VTransactionWritable (io.vertigo.commons.transaction.VTransactionWritable)80 Test (org.junit.Test)63 Car (io.vertigo.dynamo.store.data.domain.car.Car)22 TaskDefinition (io.vertigo.dynamo.task.metamodel.TaskDefinition)22 Task (io.vertigo.dynamo.task.model.Task)22 SuperHero (io.vertigo.dynamo.task.data.domain.SuperHero)18 DtList (io.vertigo.dynamo.domain.model.DtList)7 Flower (io.vertigo.dynamo.kvstore.data.Flower)6 Famille (io.vertigo.dynamo.store.data.domain.famille.Famille)6 SqlConnection (io.vertigo.database.sql.connection.SqlConnection)5 DtListURI (io.vertigo.dynamo.domain.model.DtListURI)5 DtDefinition (io.vertigo.dynamo.domain.metamodel.DtDefinition)4 DtListURIForCriteria (io.vertigo.dynamo.domain.model.DtListURIForCriteria)4 URI (io.vertigo.dynamo.domain.model.URI)4 Item (io.vertigo.dynamo.search.data.domain.Item)4 SearchIndexDefinition (io.vertigo.dynamo.search.metamodel.SearchIndexDefinition)4 Car (io.vertigo.dynamo.search_2_4.data.domain.Car)4 TaskEngineSelect (io.vertigo.dynamox.task.TaskEngineSelect)4 ArrayList (java.util.ArrayList)4 Domain (io.vertigo.dynamo.domain.metamodel.Domain)3