|
|
|
@ -1,5 +1,6 @@ |
|
|
|
|
package me.bearns.fias; |
|
|
|
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import me.bearns.fias.domain.FiasVersion; |
|
|
|
|
import me.bearns.fias.exceptions.UnmarshallingException; |
|
|
|
|
import me.bearns.fias.helper.TransactionalSaveHelper; |
|
|
|
@ -11,6 +12,7 @@ import org.junit.runner.RunWith; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.boot.test.context.SpringBootTest; |
|
|
|
|
import org.springframework.context.annotation.Import; |
|
|
|
|
import org.springframework.test.context.ActiveProfiles; |
|
|
|
|
import org.springframework.test.context.junit4.SpringRunner; |
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
@ -19,6 +21,8 @@ import java.util.List; |
|
|
|
|
import static me.bearns.fias.helper.TransactionalSaveHelper.FIRST; |
|
|
|
|
import static me.bearns.fias.helper.TransactionalSaveHelper.NEXT; |
|
|
|
|
|
|
|
|
|
@Slf4j |
|
|
|
|
@ActiveProfiles("test") |
|
|
|
|
@RunWith(SpringRunner.class) |
|
|
|
|
@SpringBootTest |
|
|
|
|
@Import(TransactionalSaveHelper.class) |
|
|
|
@ -32,12 +36,14 @@ public class TransactionsTest { |
|
|
|
|
|
|
|
|
|
@Before |
|
|
|
|
public void before(){ |
|
|
|
|
log.info("Configure test components"); |
|
|
|
|
helper.setRepository(repository); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void transactionTest(){ |
|
|
|
|
|
|
|
|
|
log.info("Run transaction test"); |
|
|
|
|
helper.addFirst(); |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
@ -45,22 +51,26 @@ public class TransactionsTest { |
|
|
|
|
assert false; |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
//just as plained
|
|
|
|
|
log.info("Caught exception, continue"); |
|
|
|
|
assert true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
final List<FiasVersion> versions = repository.findAll(); |
|
|
|
|
|
|
|
|
|
versions.stream().map(FiasVersion::getVersionId).forEach(System.out::println); |
|
|
|
|
versions.stream().map(FiasVersion::toString).forEach(log::info); |
|
|
|
|
|
|
|
|
|
assert versions.stream().mapToLong(FiasVersion::getVersionId).anyMatch(v -> FIRST == v); |
|
|
|
|
log.info("find {}", FIRST); |
|
|
|
|
|
|
|
|
|
assert versions.stream().mapToLong(FiasVersion::getVersionId).noneMatch(v -> NEXT == v); |
|
|
|
|
log.info("not find {}", NEXT); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@After |
|
|
|
|
public void clear(){ |
|
|
|
|
repository.deleteAll(); |
|
|
|
|
log.info("Clear FiasVersion repo"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|