Add test for bug

This commit is contained in:
k.struzhkin 2019-09-11 15:44:07 +03:00
parent 15b6faecc8
commit f74a1b4282
2 changed files with 62 additions and 0 deletions

View File

@ -5,6 +5,8 @@ import lombok.extern.slf4j.Slf4j;
import org.junit.ClassRule;
import org.junit.runner.Description;
import org.junit.runner.RunWith;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
@ -17,6 +19,7 @@ import org.testcontainers.containers.PostgreSQLContainer;
import java.util.function.Consumer;
@RunWith(SpringRunner.class)
@EnableConfigurationProperties({DataSourceProperties.class})
@ContextConfiguration(initializers = DaoTestBase.Initializer.class)
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
@Slf4j
@ -52,6 +55,7 @@ public abstract class DaoTestBase extends AbstractTestUtils {
TestPropertyValues
.of(testContainers.getEnvironmentProperties(getEnvironmentPropertiesConsumer()))
.applyTo(configurableApplicationContext);
}
}

View File

@ -8,6 +8,9 @@ import com.rbkmoney.shumpune.constant.PostingOperation;
import com.rbkmoney.shumpune.dao.AccountDao;
import com.rbkmoney.shumpune.dao.PlanDao;
import com.rbkmoney.shumpune.domain.BalanceModel;
import com.rbkmoney.shumpune.domain.PostingModel;
import com.rbkmoney.shumpune.domain.PostingPlanInfo;
import com.rbkmoney.shumpune.domain.PostingPlanModel;
import com.rbkmoney.shumpune.utils.AccountGenerator;
import com.rbkmoney.shumpune.utils.PostingGenerator;
import com.rbkmoney.shumpune.utils.VectorClockSerializer;
@ -28,6 +31,8 @@ import java.util.List;
@SpringBootTest(classes = ShumpuneApplication.class)
public class ShumpuneServiceHandlerTest extends DaoTestBase {
public static final String ID = "16J1L7A6Swq.1";
@Autowired
JdbcTemplate jdbcTemplate;
@ -304,4 +309,57 @@ public class ShumpuneServiceHandlerTest extends DaoTestBase {
Assert.assertEquals(accountPrototype.getDescription(), account.getDescription());
}
@Test
public void addOrUpdatePlanLog() {
PostingPlanModel planLog = new PostingPlanModel();
PostingPlanInfo postingPlanInfo = new PostingPlanInfo();
postingPlanInfo.setClock(0L);
postingPlanInfo.setPostingOperation(PostingOperation.HOLD);
postingPlanInfo.setBatchId(1L);
postingPlanInfo.setId(ID);
planLog.setPostingPlanInfo(postingPlanInfo);
ArrayList<PostingModel> postingModels = new ArrayList<>();
PostingModel postingModel = new PostingModel();
postingModel.setAccountFromId(13L);
postingModel.setAccountToId(1L);
postingModel.setAmount(4500L);
postingModel.setCurrencySymbCode("RUB");
postingModels.add(postingModel);
postingModel = new PostingModel();
postingModel.setAccountFromId(4L);
postingModel.setAccountToId(13L);
postingModel.setAmount(10000L);
postingModel.setCurrencySymbCode("RUB");
postingModels.add(postingModel);
postingModel = new PostingModel();
postingModel.setAccountFromId(1L);
postingModel.setAccountToId(4L);
postingModel.setAmount(1500L);
postingModel.setCurrencySymbCode("RUB");
postingModels.add(postingModel);
planLog.setPostingModels(postingModels);
PostingPlanModel postingPlanModel = planDao.addOrUpdatePlanLog(planLog);
Assert.assertEquals(ID, postingPlanModel.getPostingPlanInfo().getId());
planLog.getPostingPlanInfo().setBatchId(2L);
postingPlanModel = planDao.addOrUpdatePlanLog(planLog);
Assert.assertEquals(ID, postingPlanModel.getPostingPlanInfo().getId());
planLog.getPostingPlanInfo().setPostingOperation(PostingOperation.COMMIT);
PostingPlanInfo postingPlanModelInfo = planDao.updatePlanLog(planLog.getPostingPlanInfo());
Assert.assertEquals(ID, postingPlanModelInfo.getId());
Assert.assertEquals(PostingOperation.COMMIT, postingPlanModelInfo.getPostingOperation());
planLog.getPostingPlanInfo().setPostingOperation(PostingOperation.HOLD);
postingPlanModel = planDao.addOrUpdatePlanLog(planLog);
Assert.assertEquals(PostingOperation.COMMIT, postingPlanModel.getPostingPlanInfo().getPostingOperation());
}
}