/
NikolayIvkin
/
tutorials1
Обзор
Документация
Войти
/
NikolayIvkin
/
tutorials1
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
spring-integration/src/test/java/com/baeldung/tx/TxIntegrationTest.java
56 строк
2 KB
Eric Martin
Merge pull request #8125 from eugenp/revert-8119-BAEL-3275-2
01 ноя 2019, 04:43
01 ноя 2019, 04:43
3225470
Код
Авторство
О чём код?
package com.baeldung.tx; import org.junit.Assert; import org.junit.Test; import org.springframework.context.support.AbstractApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import java.io.File; import java.io.FileWriter; import java.io.IOException; public final class TxIntegrationTest { private static final String CONTEXT_CONFIG = "classpath:META-INF/spring/integration/spring-integration-tx-context.xml"; @Test public void whenFileDoesntStartWithFail_thenTxSuccessful() throws InterruptedException, IOException { final AbstractApplicationContext context = new ClassPathXmlApplicationContext(CONTEXT_CONFIG); String fileName = System.getProperty("java.io.tmpdir") + "/tx/test1.txt"; FileWriter fw = new FileWriter(fileName); fw.write("PASSED!"); fw.close(); context.registerShutdownHook(); Thread.sleep(5000); File file = new File(fileName + ".PASSED"); Assert.assertTrue(file.exists()); } @Test public void whenFileStartsWithFail_thenTxFailed() { String fileName = System.getProperty("java.io.tmpdir") + "/tx/test2.txt"; try { final AbstractApplicationContext context = new ClassPathXmlApplicationContext(CONTEXT_CONFIG); FileWriter fw = new FileWriter(fileName); fw.write("FAILED!"); fw.close(); context.registerShutdownHook(); Thread.sleep(5000); } catch (Exception e) { // Exception is expected, do nothing } File file = new File(fileName + ".FAILED"); Assert.assertTrue(file.exists()); } }