Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.jleaf.pos2.test.employee;
- import org.jleaf.common.CommonExceptionConstants;
- import org.jleaf.core.BusinessFunction;
- 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.vehicletype.TestFindVehicleTypeById;
- 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;
- /**
- *
- * @author Desinta Aditiya, 1 August 2016
- *
- */
- @RunWith(SpringJUnit4ClassRunner.class)
- @ContextConfiguration(locations = { "classpath:applicationContext.xml" })
- @TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)
- @Transactional
- public class TestEditEmployeeJob extends AbstractSpringDbUnitTest {
- private static final Logger log = LoggerFactory
- .getLogger(TestEditEmployeeJob.class);
- @Before
- public void prepareData() {
- super.deleteFromTables("m_employee_job", "t_user", "t_combo", "t_combo_value");
- super.executeSqlScript("scripts/TestEditEmployeeJob.sql", false);
- }
- @Autowired
- @Qualifier("editEmployeeJob")
- private BusinessTransaction editEmployeeJob;
- @Autowired
- @Qualifier("findEmployeeJobById")
- private BusinessFunction findEmployeeJobById;
- @Test
- public void testSucces() {
- Dto inputDto = new Dto();
- String datetime = DateUtil.dateTimeNow();
- inputDto.put("partnerCode", "Desinta");
- inputDto.put("employeeJob", "PURCH");
- //inputDto.put("username", "Desinta");
- inputDto.put("version", 1L);
- inputDto.put("userLoginName", "Nadia");
- inputDto.put("roleLoginId", 20L);
- inputDto.put("roleLoginName", "Admin");
- inputDto.put("datetime", datetime);
- try {
- Dto outputDto = editEmployeeJob.execute(inputDto);
- log.debug("outputDto:"+outputDto);
- String newId = outputDto.getString("partnerCode");
- Assert.assertNotNull(newId);
- Dto findDto = findEmployeeJobById.execute(new Dto().put("partnerCode",
- newId));
- Assert.assertEquals("DESINTA", findDto.getString("partnerCode"));
- Assert.assertEquals("PURCH", findDto.getString("employeeJob"));
- Assert.assertEquals("Desinta", findDto.getString("username"));
- Assert.assertEquals(2L, findDto.getLong("version").longValue());
- Assert.assertEquals("20160729000000", findDto.getString("createDateTime"));
- Assert.assertEquals(datetime, findDto.getString("updateDateTime"));
- Assert.assertEquals("Nadia", findDto.getString("createUsername"));
- Assert.assertEquals("Nadia", findDto.getString("updateUsername"));
- } catch (Exception e) {
- log.error("error edit", e);
- e.printStackTrace();
- Assert.fail(e.getMessage());
- }
- }
- @Test
- public void testEditFailBecausePartnerCodeNotFound() {
- Dto input = new Dto();
- String datetime = DateUtil.dateTimeNow();
- input.put("partnerCode", "Milla");
- input.put("employeeJob", "PURCH");
- input.put("username", "Desinta");
- input.put("version", 1L);
- input.put("userLoginName", "Nadia");
- input.put("roleLoginId", 20L);
- input.put("roleLoginName", "Admin");
- input.put("datetime", datetime);
- try {
- editEmployeeJob.execute(input);
- System.err.println("dgfdhss");
- Assert.fail("Validation Partner code empty failed");
- } catch (CoreException e1) {
- // untuk masuk ke core exception
- log.debug("Masuk core exception");
- Assert.assertEquals("employee.job.id.not.found", e1.getErrorKey());
- } catch (Exception e) {
- log.error("error", e);
- Assert.fail(e.getMessage());
- }
- }
- @Test
- public void testEditFailBecauseemployeeJobNotFound() {
- Dto input = new Dto();
- String datetime = DateUtil.dateTimeNow();
- input.put("partnerCode", "Milla");
- input.put("employeeJob", "PROGRAMER");
- input.put("username", "Desinta");
- input.put("version", 1L);
- input.put("userLoginName", "Nadia");
- input.put("roleLoginId", 20L);
- input.put("roleLoginName", "Admin");
- input.put("datetime", datetime);
- try {
- editEmployeeJob.execute(input);
- System.err.println("dgfdhss");
- Assert.fail("Validation device merchant name empty failed");
- } catch (CoreException e1) {
- // untuk masuk ke core exception
- log.debug("Masuk core exception");
- Assert.assertEquals("employee.job.id.not.found", e1.getErrorKey());
- } catch (Exception e) {
- log.error("error", e);
- Assert.fail(e.getMessage());
- }
- }
- @Test
- public void testEditFailBecausePartnerCodeNotFilled() throws Exception {
- String datetime = DateUtil.dateTimeNow();
- Dto input = new Dto();
- input.put("partnerCode", "");
- input.put("employeeJob", "PURCH");
- input.put("username", "Desinta");
- input.put("version", 1L);
- input.put("userLoginName", "Nadia");
- input.put("roleLoginId", 20L);
- input.put("roleLoginName", "Admin");
- input.put("datetime", datetime);
- try {
- editEmployeeJob.execute(input);
- System.err.println("dgfdhss");
- Assert.fail("Validation device merchant name empty failed");
- } catch (CoreException e1) {
- // untuk masuk ke core exception
- log.debug("Masuk core exception");
- Assert.assertEquals("value.cannot.null", e1.getErrorKey());
- } catch (Exception e) {
- log.error("error", e);
- Assert.fail(e.getMessage());
- }
- }
- @Test
- public void tesValueBecausePartnerCodeIsExist(){
- Dto input = new Dto();
- String datetime = DateUtil.dateTimeNow();
- input.put("partnerCode", "Desinta");
- input.put("employeeJob", "PURCH");
- input.put("username", "Desinta");
- input.put("userLoginName", "Nadia");
- input.put("roleLoginId", 20L);
- input.put("roleLoginName", "Admin");
- input.put("datetime", datetime);
- try {
- editEmployeeJob.execute(input);
- System.err.println("dgfdhss");
- Assert.fail("Validation PartnerCode is Already Exists");
- } catch (CoreException e1) {
- // untuk masuk ke core exception
- log.debug("Masuk core exception");
- Assert.assertEquals("core.parameter.not.found", e1.getErrorKey());
- } catch (Exception e) {
- log.error("error", e);
- Assert.fail(e.getMessage());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment