Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package id.co.sts.firebase.bo.device.test;
- import id.co.sts.firebase.FirebaseExceptionConstants;
- import org.jleaf.core.BusinessFunction;
- import org.jleaf.core.BusinessTransaction;
- import org.jleaf.core.CoreException;
- import org.jleaf.core.Dto;
- import org.jleaf.core.test.AbstractSpringDbUnitTest;
- import org.junit.Assert;
- import org.junit.Before;
- import org.junit.Test;
- import org.junit.runner.RunWith;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Qualifier;
- import org.springframework.test.context.ContextConfiguration;
- import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
- import org.springframework.test.context.transaction.TransactionConfiguration;
- import org.springframework.transaction.annotation.Transactional;
- @RunWith(SpringJUnit4ClassRunner.class)
- @ContextConfiguration(locations = { "classpath:applicationContext.xml" })
- @TransactionConfiguration(transactionManager = "transactionManager", defaultRollback=true)
- @Transactional
- public class TestInactiveDevice extends AbstractSpringDbUnitTest{
- private static final Logger log = LoggerFactory.getLogger(TestInactiveDevice.class);
- @Autowired
- @Qualifier("inactiveDevice")
- BusinessTransaction inactiveDevice;
- @Autowired
- @Qualifier("findProjectById")
- BusinessFunction findProjectById;
- @Before
- public void prepareData(){
- log.debug("Prepare data");
- super.executeSqlScript("scripts/TestInactiveDevice.sql", false);
- }
- @Test
- public void testSuccess(){
- log.debug("Test Success");
- Dto inputDto = new Dto();
- inputDto.put("projectId", 50L);
- inputDto.put("uuid", "UID1");
- inputDto.put("active", "N");
- log.debug("input : "+inputDto);
- try {
- log.debug("Call bt inactive device");
- Dto outputDto = inactiveDevice.execute(inputDto);
- log.debug("output dari inactiveDevice : "+outputDto);
- Dto inputDtoForFindProjectById = new Dto();
- inputDtoForFindProjectById.put("id", outputDto.get("projectId"));
- Dto deviceDto = findProjectById.execute(inputDtoForFindProjectById);
- Assert.assertEquals(inputDto.get("projectId"), deviceDto.get("projectId"));
- Assert.assertEquals(inputDto.get("uuid"), outputDto.get("uuid"));
- Assert.assertEquals(inputDto.get("active"), outputDto.get("active"));
- } catch (Exception e) {
- // TODO: handle exception
- log.error("error inactive device");
- Assert.fail(e.toString());
- }
- }
- @Test
- public void testSuccessNonActive(){
- log.debug("Test Success Change Active to N");
- Dto inputDto = new Dto();
- inputDto.put("projectId", 50L);
- inputDto.put("uuid", "UID1");
- inputDto.put("active", "Y");
- log.debug("input : "+inputDto);
- try {
- log.debug("Call bt inactive device");
- Dto outputDto = inactiveDevice.execute(inputDto);
- log.debug("output dari inactiveDevice : "+outputDto);
- Assert.assertEquals(inputDto.get("projectId"), outputDto.get("projectId"));
- Assert.assertEquals(inputDto.get("uuid"), outputDto.get("uuid"));
- Assert.assertEquals("N", outputDto.get("active"));
- } catch (Exception e) {
- // TODO: handle exception
- log.error("error inactive device");
- Assert.fail(e.toString());
- }
- }
- @Test
- public void testErrorDeviceNotFound(){
- log.debug("Test Error Project Not Found");
- Dto inputDto = new Dto();
- inputDto.put("projectId", 92L);
- inputDto.put("uuid", "UID1");
- inputDto.put("active", "Y");
- log.debug("input : "+inputDto);
- try {
- log.debug("Call bt inactive device");
- Dto outputDto = inactiveDevice.execute(inputDto);
- Assert.fail("This inactive device should be error : "+outputDto);
- } catch (CoreException e) {
- log.debug("Core Exception");
- log.debug(e.getErrorKey());
- Assert.assertEquals(FirebaseExceptionConstants.DEVICE_NOT_FOUND, e.getErrorKey());
- } catch (Exception e) {
- // TODO: handle exception
- log.error("error inactive device", e);
- Assert.fail(e.toString());
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement