Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.jleaf.pos2.test.vehiclegroup;
- import org.jleaf.common.CommonExceptionConstants;
- import org.jleaf.core.BusinessTransaction;
- import org.jleaf.core.CoreException;
- import org.jleaf.core.CoreExceptionConstants;
- import org.jleaf.core.Dto;
- import org.jleaf.core.GeneralConstants;
- import org.jleaf.core.test.AbstractSpringDbUnitTest;
- import org.jleaf.pos2.PosMasterExceptionConstants;
- import org.jleaf.pos2.test.vehiclegroup.TestEditVehicleGroup;
- import org.jleaf.util.DateUtil;
- 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 TestEditVehicleGroup extends AbstractSpringDbUnitTest {
- private static Logger log = LoggerFactory
- .getLogger(TestEditVehicleGroup.class);
- @Autowired
- @Qualifier("editVehicleGroup")
- private BusinessTransaction editVehicleGroup;
- @Before
- public void prepareData() {
- super.deleteFromTables("m_vehicle_group");
- super.executeSqlScript("scripts/TestEditVehicleGroup.sql", false);
- }
- @Test
- public void testEditVehicleGroupValVehicleGroupCode() throws Exception {
- String datetime = DateUtil.dateTimeNow();
- Dto inputDto = new Dto();
- inputDto.put("vehicleGroupCode", "");
- inputDto.put("vehicleGroupName", "Kendaraan Pribadi");
- inputDto.put("userLoginName", "Henokh");
- inputDto.put("userLoginId", 10L);
- inputDto.put("roleLoginId", 10L);
- inputDto.put("roleLoginName", "Admin");
- inputDto.put("datetime", datetime);
- inputDto.put("active", "Y");
- try {
- editVehicleGroup.execute(inputDto);
- Assert.fail("Validation vehicle group id empty failed");
- } catch (CoreException e1) {
- Assert.assertArrayEquals("Error key is not same",
- new String[] { CoreExceptionConstants.VALUE_CANNOT_NULL },
- new String[] { e1.getErrorKey() });
- Assert.assertArrayEquals("Argument is not valid",
- new String[] { "vehicleGroupCode" }, e1.getParamValues());
- } catch (Exception e) {
- e.printStackTrace();
- Assert.fail(e.getMessage());
- }
- }
- @Test
- public void testEditVehicleGroupValVehicleGroupName() {
- String datetime = DateUtil.dateTimeNow();
- Dto inputDto = new Dto();
- inputDto.put("vehicleGroupCode", "PRBD");
- inputDto.put("vehicleGroupName", "");
- inputDto.put("userLoginName", "Henokh");
- inputDto.put("userLoginId", 10L);
- inputDto.put("roleLoginId", 10L);
- inputDto.put("roleLoginName", "Admin");
- inputDto.put("datetime", datetime);
- inputDto.put("active", "Y");
- try {
- editVehicleGroup.execute(inputDto);
- Assert.fail("Validation vehicle group name empty failed");
- } catch (CoreException e1) {
- Assert.assertArrayEquals("Error key is not same",
- new String[] { CoreExceptionConstants.VALUE_CANNOT_NULL },
- new String[] { e1.getErrorKey() });
- Assert.assertArrayEquals("Argument is not valid",
- new String[] { "vehicleGroupName" }, e1.getParamValues());
- } catch (Exception e) {
- e.printStackTrace();
- Assert.fail(e.getMessage());
- }
- }
- @Test
- public void testEditFailBecauseVehicleGroupIdNotFound() throws Exception {
- Dto input = new Dto();
- String dateTime = DateUtil.dateTimeNow();
- input.put("vehicleGroupCode", "PNJM");
- input.put("vehicleGroupName", " Kendaraan Pinjam ");
- input.put("userLoginName", "Henokh");
- input.put("userLoginId", -1);
- input.put("datetime", dateTime);
- input.put("roleLoginName", "Admin");
- input.put("roleLoginId", -1);
- input.put("active", "Y");
- try {
- editVehicleGroup.execute(input);
- Assert.fail("vehicleGroup id not found");
- } catch (CoreException ex) {
- Assert.assertEquals(PosMasterExceptionConstants.VEHICLEGROUP_ID_NOT_FOUND,
- ex.getErrorKey());
- } catch (Exception e) {
- e.printStackTrace();
- Assert.fail(e.getMessage());
- }
- }
- @Test
- public void tesEditFailBecauseActiveNotYesOrNo() throws Exception {
- String datetime = DateUtil.dateTimeNow();
- Dto input = new Dto();
- input.put("vehicleGroupCode", "DLVRY");
- input.put("vehicleGroupName", "Kendaraan Delivery");
- input.put("userLoginName", "Henokh");
- input.put("userLoginId", -1);
- input.put("datetime", datetime);
- input.put("roleLoginName", "Admin");
- input.put("roleLoginId", -1);
- input.put("active", "K");
- try {
- editVehicleGroup.execute(input);
- Assert.fail("Test active value failed");
- } catch (CoreException ex) {
- Assert.assertEquals(CommonExceptionConstants.COMBO_VALUE_NOT_VALID,
- ex.getErrorKey());
- } catch (Exception e) {
- e.printStackTrace();
- Assert.fail(e.getMessage());
- }
- }
- @Test
- public void testEditVehicleGroupSuccessIfActiveYesAndDataYes() {
- String datetime = DateUtil.dateTimeNow();
- Dto inputDto = new Dto();
- inputDto.put("vehicleGroupCode", "PRBD");
- inputDto.put("vehicleGroupName", " Kendaraan Pribadi ");
- inputDto.put("userLoginId", 10L);
- inputDto.put("roleLoginId", 10L);
- inputDto.put("userLoginName", "Henokh");
- inputDto.put("roleLoginName", "Admin");
- inputDto.put("datetime", datetime);
- inputDto.put("active", "Y");
- try {
- Dto outputDto = editVehicleGroup.execute(inputDto);
- log.debug("======================================================= "
- + outputDto);
- Assert.assertEquals("PRBD", outputDto.getString("vehicleGroupCode"));
- Assert.assertEquals("KENDARAAN PRIBADI", outputDto.getString("vehicleGroupName"));
- Assert.assertEquals(GeneralConstants.YES,
- outputDto.getString("active"));
- Assert.assertEquals("20160713000000",
- outputDto.getString("activeDateTime"));
- Assert.assertEquals(GeneralConstants.SPACE_VALUE,
- outputDto.getString("nonActiveDateTime"));
- Assert.assertEquals(1L, outputDto.getLong("version").longValue());
- Assert.assertEquals("Henokh", outputDto.getString("createUsername"));
- Assert.assertEquals("Henokh", outputDto.getString("updateUsername"));
- Assert.assertEquals("20160713000000",
- outputDto.getString("createDateTime"));
- Assert.assertEquals(datetime, outputDto.getString("updateDateTime"));
- } catch (Exception e) {
- e.printStackTrace();
- Assert.fail(e.getMessage());
- }
- }
- @Test
- public void testEditVehicleGroupSuccessIfActiveYesAndDataNo() {
- String datetime = DateUtil.dateTimeNow();
- Dto inputDto = new Dto();
- inputDto.put("vehicleGroupCode", "PRBD");
- inputDto.put("vehicleGroupName", "Kendaraan Pribadi");
- inputDto.put("userLoginName", "Henokh");
- inputDto.put("userLoginId", -1);
- inputDto.put("datetime", datetime);
- inputDto.put("roleLoginName", "Admin");
- inputDto.put("roleLoginId", -1);
- inputDto.put("active", "Y");
- try {
- Dto outputDto = editVehicleGroup.execute(inputDto);
- log.debug("=========================------------------------------------ "
- + outputDto);
- Assert.assertEquals("PRBD", outputDto.getString("vehicleGroupCode"));
- Assert.assertEquals("KENDARAAN PRIBADI", outputDto.getString("vehicleGroupName"));
- Assert.assertEquals(GeneralConstants.YES,
- outputDto.getString("active"));
- Assert.assertEquals("20160713000000", outputDto.getString("activeDateTime"));
- Assert.assertEquals(GeneralConstants.SPACE_VALUE,
- outputDto.getString("nonActiveDateTime"));
- Assert.assertEquals(1L, outputDto.getLong("version").longValue());
- Assert.assertEquals("Henokh", outputDto.getString("createUsername"));
- Assert.assertEquals("Henokh", outputDto.getString("updateUsername"));
- Assert.assertEquals("20160713000000",
- outputDto.getString("createDateTime"));
- Assert.assertEquals(datetime, outputDto.getString("updateDateTime"));
- } catch (Exception e) {
- e.printStackTrace();
- Assert.fail(e.getMessage());
- }
- }
- @Test
- public void testEditVehicleGroupSuccessIfActiveNoAndDataYes() {
- Dto inputDto = new Dto();
- String datetime = DateUtil.dateTimeNow();
- inputDto.put("vehicleGroupCode", "PRBD");
- inputDto.put("vehicleGroupName", "Kendaraan Pribadi");
- inputDto.put("userLoginName", "Henokh");
- inputDto.put("userLoginId", 10L);
- inputDto.put("roleLoginId", 10L);
- inputDto.put("roleLoginName", "Admin");
- inputDto.put("datetime", datetime);
- inputDto.put("active", "N");
- try {
- Dto outputDto = editVehicleGroup.execute(inputDto);
- log.debug("-------------------------------------------------------------- "
- + outputDto);
- Assert.assertEquals("PRBD", outputDto.getString("vehicleGroupCode"));
- Assert.assertEquals("KENDARAAN PRIBADI", outputDto.getString("vehicleGroupName"));
- Assert.assertEquals(GeneralConstants.NO,
- outputDto.getString("active"));
- Assert.assertEquals("20160713000000",
- outputDto.getString("activeDateTime"));
- Assert.assertEquals(datetime,
- outputDto.getString("nonActiveDateTime"));
- Assert.assertEquals(1L, outputDto.getLong("version").longValue());
- Assert.assertEquals("Henokh", outputDto.getString("createUsername"));
- Assert.assertEquals("Henokh", outputDto.getString("updateUsername"));
- Assert.assertEquals("20160713000000",
- outputDto.getString("createDateTime"));
- Assert.assertEquals(datetime, outputDto.getString("updateDateTime"));
- } catch (Exception e) {
- e.printStackTrace();
- Assert.fail(e.getMessage());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment