Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.jleaf.erp.master.bo.partner.test;
- import org.jleaf.core.BusinessFunction;
- 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;
- @RunWith(SpringJUnit4ClassRunner.class)
- @ContextConfiguration(locations = { "classpath:applicationContext.xml" })
- @TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)
- @Transactional
- public class TestFindCtgrPartnerById extends AbstractSpringDbUnitTest {
- private static final Logger log = LoggerFactory
- .getLogger(TestFindCtgrPartnerById.class);
- @Autowired
- @Qualifier("findCtgrPartnerById")
- private BusinessFunction findCtgrPartnerById;
- @Before
- public void prepare() {
- deleteFromTables("m_ctgr_partner");
- executeSqlScript("classpath:org/jleaf/erp/master/bo/TableBase.sql", false);
- executeSqlScript("classpath:org/jleaf/erp/master/bo/partner/test/TestFindCtgrPartnerById.sql", false);
- }
- /*@Test
- public void testValidateNull() {
- Dto inputDto = new Dto();
- inputDto.put("id", null);
- log.debug("inputDto :{}", inputDto);
- try {
- findCtgrPartnerById.execute(inputDto);
- Assert.fail("The findCtgrPartnerById should be null");
- }catch(CoreException coreEx){
- log.debug("exception :{}", coreEx.getErrorKey());
- }catch(NullPointerException ex){
- Assert.fail("findCtgrPartnerById");
- }catch (Exception e) {
- Assert.fail("addSample");
- }
- }
- @Test
- public void testValidateDataType() {
- //TODO : Handle Input testValidateDataType
- Dto inputDto = new Dto();
- inputDto.put("id","id");
- log.debug("inputDto :{}", inputDto);
- try {
- findCtgrPartnerById.execute(inputDto);
- Assert.fail("The findCtgrPartnerById should be valid");
- }catch(CoreException coreEx){
- log.debug("exception :{}", coreEx.getErrorKey());
- }catch(NumberFormatException ex){
- Assert.fail("findCtgrPartnerById");
- }catch (Exception e) {
- Assert.fail("addSample");
- }
- }*/
- @Test
- public void testSuccess() {
- //TODO : Handle Input testSuccess
- Long id = 10l;
- Dto inputDto = new Dto();
- inputDto.put("id", id);
- try {
- Dto outputDto = findCtgrPartnerById.execute(inputDto);
- // TODO Fill the expected result for assert
- Assert.assertEquals(id, outputDto.get("id"));
- Assert.assertEquals(10L, outputDto.get("tenantId"));
- Assert.assertEquals("GENERAL", outputDto.get("code"));
- Assert.assertEquals("GENERAL", outputDto.get("name"));
- Assert.assertEquals(GeneralConstants.YES, outputDto.get("active"));
- Assert.assertEquals("20130620131317", outputDto.get("activeDateTime"));
- Assert.assertEquals(GeneralConstants.SPACE_VALUE, outputDto.get("nonActiveDateTime"));
- Assert.assertEquals("20130620131317", outputDto.get("createDateTime"));
- Assert.assertEquals(-1L, outputDto.get("createUserId"));
- Assert.assertEquals("20130620131317", outputDto.get("updateDateTime"));
- Assert.assertEquals(-1L, outputDto.get("updateUserId"));
- Assert.assertEquals(0L, outputDto.get("version"));
- log.debug("result : {}", outputDto);
- }catch(Exception e){
- log.error("Exception{}",e);
- }
- }
- @Test
- public void testFailure() {
- Long id = -99l;
- Dto inputDto = new Dto();
- inputDto.put("id", id);
- log.debug("inputDto : {}",inputDto);
- try{
- Dto outputDto = findCtgrPartnerById.execute(inputDto);
- Assert.fail("This findCtgrPartnerById 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 testForCtgrPartnerIdNotFound() {
- Long id = -99l;
- Dto inputDto = new Dto();
- inputDto.put("id", id);
- try{
- Dto outputDto = findCtgrPartnerById.execute(inputDto);
- Assert.fail("This findCtgrPartnerById should be error: "+outputDto);
- } catch(CoreException e){
- log.error("Category Partner Id {0} is not found", e);
- Assert.assertEquals(1, e.getParamValues().length);
- Assert.assertEquals(MasterExceptionConstants.CTGR_PARTNER_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