parent
7afbe9ef92
commit
a8b29ac936
@ -1,6 +1,10 @@ |
||||
databaseChangeLog: |
||||
- include: |
||||
- file: "000_initial_schema.yaml" |
||||
- relativeToChangelogFile: "true" |
||||
- include: |
||||
- file: "001_AddrObj.yaml" |
||||
- relativeToChangelogFile: "true" |
||||
- include: |
||||
- file: "002_House.yaml" |
||||
- relativeToChangelogFile: "true" |
@ -0,0 +1,59 @@ |
||||
package me.bearns.fias; |
||||
|
||||
import me.bearns.fias.domain.FiasVersion; |
||||
import me.bearns.fias.repository.FiasVersionRepository; |
||||
import org.junit.Before; |
||||
import org.junit.Test; |
||||
import org.junit.runner.RunWith; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.boot.test.context.SpringBootTest; |
||||
import org.springframework.test.context.junit4.SpringRunner; |
||||
import org.springframework.transaction.annotation.Transactional; |
||||
|
||||
import java.util.List; |
||||
|
||||
import static org.springframework.transaction.annotation.Isolation.READ_COMMITTED; |
||||
|
||||
@RunWith(SpringRunner.class) |
||||
@SpringBootTest |
||||
public class TransactionsTest { |
||||
|
||||
private static final long FIRST = 1L; |
||||
private static final long NEXT = 2L; |
||||
|
||||
@Autowired |
||||
private FiasVersionRepository repository; |
||||
|
||||
@Before |
||||
public void before(){ |
||||
final FiasVersion version = new FiasVersion(FIRST, null, null, null); |
||||
repository.save(version); |
||||
|
||||
try { |
||||
addNext(); |
||||
} catch (Exception e) { |
||||
//just as planed
|
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
|
||||
@Test |
||||
public void transactionTest(){ |
||||
|
||||
final List<FiasVersion> versions = repository.findAll(); |
||||
|
||||
versions.stream().map(FiasVersion::getVersionId).forEach(System.out::println); |
||||
|
||||
assert versions.stream().mapToLong(FiasVersion::getVersionId).anyMatch(v -> FIRST == v); |
||||
|
||||
assert versions.stream().mapToLong(FiasVersion::getVersionId).noneMatch(v -> NEXT == v); |
||||
|
||||
} |
||||
|
||||
@Transactional |
||||
public void addNext() throws Exception { |
||||
final FiasVersion nextVersion = new FiasVersion(NEXT, null, null, null); |
||||
repository.save(nextVersion); |
||||
throw new Exception("test"); |
||||
} |
||||
} |
Loading…
Reference in new issue