Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.jleaf.erp.master.bo.coa.test;
- import org.jleaf.common.CommonExceptionConstants;
- import org.jleaf.core.BusinessTransaction;
- import org.jleaf.core.Dto;
- import org.jleaf.core.GeneralConstants;
- import org.jleaf.core.test.AbstractSpringDbUnitTest;
- import org.junit.Test;
- import org.junit.Assert;
- import org.junit.Before;
- import org.junit.runner.RunWith;
- import org.jleaf.core.CoreException;
- 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;
- import org.jleaf.erp.master.MasterExceptionConstants;
- import org.jleaf.util.DateUtil;
- /**
- *
- * @author Adrian
- * Jul 4, 2017
- */
- @RunWith(SpringJUnit4ClassRunner.class)
- @ContextConfiguration(locations = { "classpath:applicationContext.xml" })
- @TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)
- @Transactional
- public class TestAddActivity extends AbstractSpringDbUnitTest {
- private static final Logger log = LoggerFactory
- .getLogger(TestAddActivity.class);
- @Autowired
- @Qualifier("addActivity")
- private BusinessTransaction addActivity;
- @Before
- public void prepare() {
- deleteFromTables("t_combo_value");
- deleteFromTables("m_coa");
- deleteFromTables("m_activity_gl");
- executeSqlScript("classpath:org/jleaf/erp/master/bo/TableBase.sql", false);
- executeSqlScript("classpath:org/jleaf/erp/master/bo/coa/test/TestAddActivity.sql", false);
- }
- /*@Test
- public void testValidateNull() {
- Dto inputDto = new Dto();
- inputDto.put("code", null);
- inputDto.put("name", null);
- inputDto.put("coaId", null);
- inputDto.put("active", null);
- inputDto.put("tenantLoginId", null);
- inputDto.put("userLoginId", null);
- inputDto.put("roleLoginId", null);
- inputDto.put("datetime", null);
- log.debug("inputDto :{}", inputDto);
- try {
- addActivity.execute(inputDto);
- Assert.fail("The addActivity should be null");
- }catch(CoreException coreEx){
- log.debug("exception :{}", coreEx.getErrorKey());
- }catch(NullPointerException ex){
- Assert.fail("addActivity");
- }catch (Exception e) {
- Assert.fail("addSample");
- }
- }
- @Test
- public void testValidateDataType() {
- //TODO : Handle Input testValidateDataType
- Dto inputDto = new Dto();
- inputDto.put("code", -99l);
- inputDto.put("name", -99l);
- inputDto.put("coaId", "coaId");
- inputDto.put("active", -99l);
- inputDto.put("tenantLoginId", "tenantLoginId");
- inputDto.put("userLoginId", "userLoginId");
- inputDto.put("roleLoginId", "roleLoginId");
- inputDto.put("datetime", -99l);
- log.debug("inputDto :{}", inputDto);
- try {
- addActivity.execute(inputDto);
- Assert.fail("The addActivity should be valid");
- }catch(CoreException coreEx){
- log.debug("exception :{}", coreEx.getErrorKey());
- }catch(NumberFormatException ex){
- Assert.fail("addActivity");
- }catch (Exception e) {
- Assert.fail("addSample");
- }
- }*/
- @Test
- public void testSuccess() {
- //TODO : Handle Input testSuccess
- String code = "PRE_TAX_30";
- String name = "Prepaid Tax Art 30";
- Long coaId = 8l;
- String datetime = DateUtil.dateTimeNow();
- Long tenantLoginId = 10l;
- Long roleLoginId = 1l;
- String active = GeneralConstants.YES;
- Long userLoginId = 1l;
- Dto inputDto = new Dto();
- inputDto.put("code", code);
- inputDto.put("name", name);
- inputDto.put("coaId", coaId);
- inputDto.put("active", active);
- inputDto.put("tenantLoginId", tenantLoginId);
- inputDto.put("userLoginId", userLoginId);
- inputDto.put("roleLoginId", roleLoginId);
- inputDto.put("datetime", datetime);
- try {
- Dto outputDto = addActivity.execute(inputDto);
- log.debug("result success : {}", outputDto);
- // // TODO Fill the expected result for assert
- // Assert.assertEquals(4L, outputDto.get("id"));
- Assert.assertEquals(tenantLoginId, outputDto.get("tenantId"));
- Assert.assertEquals(code, outputDto.get("code"));
- Assert.assertEquals(name, outputDto.get("name"));
- Assert.assertEquals(coaId, outputDto.get("coaId"));
- Assert.assertEquals(datetime, outputDto.get("activeDateTime"));
- Assert.assertEquals(GeneralConstants.SPACE_VALUE, outputDto.get("nonActiveDateTime"));
- Assert.assertEquals(datetime, outputDto.get("createDateTime"));
- Assert.assertEquals(userLoginId, outputDto.get("createUserId"));
- Assert.assertEquals(datetime, outputDto.get("updateDateTime"));
- Assert.assertEquals(userLoginId, outputDto.get("updateUserId"));
- Assert.assertEquals(0L, outputDto.get("version"));
- }catch(Exception e){
- log.error("Exception{}",e);
- }
- }
- @Test
- public void testFailure() {
- String code = "PRE_TAX_29";
- String name = "Prepaid Tax Art 29";
- Long coaId = 8l;
- String datetime = DateUtil.dateTimeNow();
- Long tenantLoginId = 10l;
- Long roleLoginId = 1l;
- String active = GeneralConstants.YES;
- Long userLoginId = 1l;
- Dto inputDto = new Dto();
- inputDto.put("code", code);
- inputDto.put("name", name);
- inputDto.put("coaId", coaId);
- inputDto.put("active", active);
- inputDto.put("tenantLoginId", tenantLoginId);
- inputDto.put("userLoginId", userLoginId);
- inputDto.put("roleLoginId", roleLoginId);
- inputDto.put("datetime", datetime);
- log.debug("inputDto : {}",inputDto);
- try{
- Dto outputDto = addActivity.execute(inputDto);
- Assert.fail("This addActivity should be error: "+outputDto);
- } catch(CoreException e){
- log.error("Exception{}",e);
- } catch (Exception e){
- log.error("Exception{}",e);
- Assert.fail(e.toString());
- }
- }
- @Test
- public void testForActivityAlreadyExists() {
- String code = "PRE_TAX_29";
- String name = "Prepaid Tax Art 29";
- Long coaId = 8l;
- String datetime = DateUtil.dateTimeNow();
- Long tenantLoginId = 10l;
- Long roleLoginId = 1l;
- String active = GeneralConstants.YES;
- Long userLoginId = 1l;
- Dto inputDto = new Dto();
- inputDto.put("code", code);
- inputDto.put("name", name);
- inputDto.put("coaId", coaId);
- inputDto.put("active", active);
- inputDto.put("tenantLoginId", tenantLoginId);
- inputDto.put("userLoginId", userLoginId);
- inputDto.put("roleLoginId", roleLoginId);
- inputDto.put("datetime", datetime);
- try{
- Dto outputDto = addActivity.execute(inputDto);
- Assert.fail("This addActivity should be error: "+outputDto);
- } catch(CoreException e){
- log.error("Activity with code {0} is already exists", e);
- Assert.assertEquals(1, e.getParamValues().length);
- Assert.assertEquals(MasterExceptionConstants.ACTIVITY_ALREADY_EXISTS, e.getErrorKey());
- } catch (Exception e){
- log.error("Exception{}",e);
- Assert.fail(e.toString());
- }
- }
- @Test
- public void testForTenantLoginCantUsed() {
- String code = "PRE_TAX_29";
- String name = "Prepaid Tax Art 29";
- Long coaId = 8l;
- String datetime = DateUtil.dateTimeNow();
- Long tenantLoginId = -1l;
- Long roleLoginId = 1l;
- String active = GeneralConstants.YES;
- Long userLoginId = -1l;
- Dto inputDto = new Dto();
- inputDto.put("code", code);
- inputDto.put("name", name);
- inputDto.put("coaId", coaId);
- inputDto.put("active", active);
- inputDto.put("tenantLoginId", tenantLoginId);
- inputDto.put("userLoginId", userLoginId);
- inputDto.put("roleLoginId", roleLoginId);
- inputDto.put("datetime", datetime);
- try{
- Dto outputDto = addActivity.execute(inputDto);
- Assert.fail("This addActivity should be error: "+outputDto);
- } catch(CoreException e){
- log.error("User Login must choose other tenant, this tenant login cant be used", e);
- //Assert.assertEquals(0, e.getParamValues().length);
- Assert.assertEquals(CommonExceptionConstants.TENANT_LOGIN_CANT_USED, e.getErrorKey());
- } catch (Exception e){
- log.error("Exception{}",e);
- Assert.fail(e.toString());
- }
- }
- @Test
- public void testForDataCantUseDiffTenant() {
- String code = "PRE_TAX_29";
- String name = "Prepaid Tax Art 29";
- Long coaId = 7l;
- String datetime = DateUtil.dateTimeNow();
- Long tenantLoginId = 10l;
- Long roleLoginId = 1l;
- String active = GeneralConstants.YES;
- Long userLoginId = 1l;
- Dto inputDto = new Dto();
- inputDto.put("code", code);
- inputDto.put("name", name);
- inputDto.put("coaId", coaId);
- inputDto.put("active", active);
- inputDto.put("tenantLoginId", tenantLoginId);
- inputDto.put("userLoginId", userLoginId);
- inputDto.put("roleLoginId", roleLoginId);
- inputDto.put("datetime", datetime);
- try{
- Dto outputDto = addActivity.execute(inputDto);
- Assert.fail("This addActivity should be error: "+outputDto);
- } catch(CoreException e){
- log.error("Data {0} cannot use data {1} from different tenant", e);
- Assert.assertEquals(2, e.getParamValues().length);
- Assert.assertEquals(CommonExceptionConstants.DATA_CANT_USE_DIFF_TENANT, e.getErrorKey());
- } catch (Exception e){
- log.error("Exception{}",e);
- Assert.fail(e.toString());
- }
- }
- @Test
- public void testForComboValueNotValid() {
- String code = "PRE_TAX_30";
- String name = "Prepaid Tax Art 30";
- Long coaId = 7l;
- String datetime = DateUtil.dateTimeNow();
- Long tenantLoginId = 10l;
- Long roleLoginId = 1l;
- String active = "Default text";
- Long userLoginId = 1l;
- Dto inputDto = new Dto();
- inputDto.put("code", code);
- inputDto.put("name", name);
- inputDto.put("coaId", coaId);
- inputDto.put("active", active);
- inputDto.put("tenantLoginId", tenantLoginId);
- inputDto.put("userLoginId", userLoginId);
- inputDto.put("roleLoginId", roleLoginId);
- inputDto.put("datetime", datetime);
- try{
- Dto outputDto = addActivity.execute(inputDto);
- Assert.fail("This addActivity should be error: "+outputDto);
- } catch(CoreException e){
- log.error("Value {0} is not valid ,should not have values : {1}", e);
- Assert.assertEquals(2, e.getParamValues().length);
- Assert.assertEquals(CommonExceptionConstants.COMBO_VALUE_NOT_VALID, e.getErrorKey());
- } catch (Exception e){
- log.error("Exception{}",e);
- Assert.fail(e.toString());
- }
- }
- @Test
- public void testForCoaIdNotFound() {
- String code = "PRE_TAX_30";
- String name = "Prepaid Tax Art 30";
- Long coaId = -99l;
- String datetime = DateUtil.dateTimeNow();
- Long tenantLoginId = 10l;
- Long roleLoginId = 1l;
- String active = GeneralConstants.YES;
- Long userLoginId = 1l;
- Dto inputDto = new Dto();
- inputDto.put("code", code);
- inputDto.put("name", name);
- inputDto.put("coaId", coaId);
- inputDto.put("active", active);
- inputDto.put("tenantLoginId", tenantLoginId);
- inputDto.put("userLoginId", userLoginId);
- inputDto.put("roleLoginId", roleLoginId);
- inputDto.put("datetime", datetime);
- try{
- Dto outputDto = addActivity.execute(inputDto);
- Assert.fail("This addActivity should be error: "+outputDto);
- } catch(CoreException e){
- log.error("Coa Id {0} is not found", e);
- Assert.assertEquals(1, e.getParamValues().length);
- Assert.assertEquals(MasterExceptionConstants.COA_ID_NOT_FOUND, e.getErrorKey());
- } catch (Exception e){
- log.error("Exception{}",e);
- Assert.fail(e.toString());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement