📄 vouchertest.java
字号:
package org.operamasks.example.ejb.gl.service;import java.util.Date;import org.junit.After;import org.junit.Before;import org.junit.Test;import org.operamasks.example.ejb.gl.entity.AccountView;import org.operamasks.example.ejb.gl.entity.Currency;import org.operamasks.example.ejb.gl.entity.Period;import org.operamasks.example.ejb.gl.entity.Person;import org.operamasks.example.ejb.gl.entity.Voucher;import org.operamasks.example.ejb.gl.entity.VoucherAssistRecord;import org.operamasks.example.ejb.gl.entity.VoucherEntry;import org.operamasks.example.ejb.gl.entity.VoucherType;import org.operamasks.example.ejb.gl.service.IAccountViewService;import org.operamasks.example.ejb.gl.service.ICurrencyService;import org.operamasks.example.ejb.gl.service.IPeriodService;import org.operamasks.example.ejb.gl.service.IPersonService;import org.operamasks.example.ejb.gl.service.IVoucherService;import org.operamasks.example.ejb.gl.service.IVoucherTypeService;public class VoucherTest { private IVoucherService voucherService; private IPersonService personService; private IPeriodService periodService; private IVoucherTypeService voucherTypeService; private ICurrencyService currencyService; private IAccountViewService accountService; private static final int ENTRY_NUMBER = 10; private static final int ASSIST_NUMBER = 10; @Test public void testCreateVoucher() { createPerson(); createCurrency(); createAccountView(); createPeriod(); createVoucherType(); Voucher voucher = new Voucher(); voucher.setId("voucher1"); voucher.setBookedDate(new Date()); voucher.setCashier(personService.getPerson("person1")); voucher.setCurrency(currencyService.getCurrency("currency1")); voucher.setHasCashAccount(true); voucher.setIsCheck(true); voucher.setLocalCreditAmount(100.99); voucher.setLocalDebitAmout(100.99); voucher.setName("Voucher"); voucher.setNumber("001.002"); voucher.setPeriod(periodService.getPeriod("period1")); voucher.setPoster(personService.getPerson("person1")); voucher.setVoucherAbstract("这是我的第一张凭证"); voucher.setVoucherType(voucherTypeService .getVoucherType("voucherType1")); for (int i = 0; i < ENTRY_NUMBER; ++i) { voucher.getEntries().add( createVoucherEntry("entry" + i, "这是我的第" + i + "条凭证分录", i, voucher)); } voucherService.createVoucher(voucher); } @Test public void testModifyVoucher() { // fail("Not yet implemented"); } //@Test public void testRemoveVoucher() { Voucher voucher = voucherService.getVoucher("voucher1"); if (voucher != null) { voucherService.removeVoucher(voucher); } AccountView account = accountService.getAccountView("account1"); if (account != null) { accountService.removeAccountView(account); } Currency currency = currencyService.getCurrency("currency1"); if (currency != null) { currencyService.removeCurrency(currency); } Period period = periodService.getPeriod("period1"); if (period != null) { periodService.removePeriod(period); } Person person = personService.getPerson("person1"); if (person != null) { personService.removePerson(person); } VoucherType voucherType = voucherTypeService .getVoucherType("voucherType1"); if (voucherType != null) { voucherTypeService.removeVoucherType(voucherType); } } @Test public void testListVoucher() { // fail("Not yet implemented"); } public void createAccountView() { AccountView account = new AccountView(); account.setId("account1"); account.setName("Account"); account.setNumber("001"); account.setLongNumber("001"); account.setLevel(1); account.setIsBank(true); account.setIsLeaf(true); accountService.createAccountView(account); } public void createCurrency() { Currency currency = new Currency(); currency.setId("currency1"); currency.setIsocode("ISO9001"); currency.setBaseUnit("元"); currency.setPrecision("0.00"); currency.setSign("人民币"); currencyService.createCurrency(currency); } public void createPeriod() { Period period = new Period(); period.setId("period1"); period.setBeginDate(new Date()); period.setNumber("001.002"); period.setPeriodNumber(1); period.setPeriodQuarter(6); period.setPeriodNumber(12); period.setEndDate(new Date()); periodService.createPeriod(period); } public void createPerson() { Person person = new Person(); person.setId("person1"); person.setName("wanxin"); person.setBirthday(new Date()); person.setEmail("wanx@apusic.com"); person.setPosition("General"); personService.createPerson(person); } public void createVoucherType() { VoucherType voucherType = new VoucherType(); voucherType.setId("voucherType1"); voucherType.setLevel(1); voucherType.setName("Post"); voucherType.setNumber("001.002"); voucherType.setPretermit(true); voucherTypeService.createVoucherType(voucherType); } private VoucherEntry createVoucherEntry(String id, String desc, int seq, Voucher voucher) { VoucherEntry entry = new VoucherEntry(); entry.setId(id); entry.setAccountView(accountService.getAccountView("account1")); entry.setCashier(personService.getPerson("person1")); entry.setCurrency(currencyService.getCurrency("currency1")); entry.setDescription(desc); entry.setIsCheck(true); entry.setLocalAmount(100.88); entry.setPrice(2200.99); entry.setQuantity(100); entry.setSeq(seq); entry.setVoucher(voucher); /** * 给分录创建指定数目的辅助帐行记录 */ for (int i = 0; i < ASSIST_NUMBER; ++i) { entry.getVoucherAssistRecords() .add( createVoucherAssistRecord(id + "-" + "assist" + i, i, entry)); } return entry; } private VoucherAssistRecord createVoucherAssistRecord(String id, int seq, VoucherEntry entry) { VoucherAssistRecord assist = new VoucherAssistRecord(); assist.setId(id); assist.setInvoiceNumber("0001.111"); assist.setLocalAmount(200); assist.setOriginalAmount(300); assist.setQuantity(100); assist.setSettlementCode("Cashier"); assist.setSeq(seq); assist.setVoucherEntry(entry); return assist; } @Before public void setUp() throws Exception { java.util.Properties p = new java.util.Properties(); p.put(javax.naming.Context.PROVIDER_URL, "iiop://127.0.0.1:6888"); p.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, "com.apusic.naming.jndi.CNContextFactory"); javax.naming.InitialContext initCtx = new javax.naming.InitialContext(p); this.voucherService = (IVoucherService) initCtx .lookup("org.operamasks.example.gl.service.VoucherService"); this.personService = (IPersonService) initCtx .lookup("org.operamasks.example.gl.service.PersonService"); this.periodService = (IPeriodService) initCtx .lookup("org.operamasks.example.gl.service.PeriodService"); this.voucherTypeService = (IVoucherTypeService) initCtx .lookup("org.operamasks.example.gl.service.VoucherTypeService"); this.currencyService = (ICurrencyService) initCtx .lookup("org.operamasks.example.gl.service.CurrencyService"); this.accountService = (IAccountViewService) initCtx .lookup("org.operamasks.example.gl.service.AccountViewService"); } @After public void tearDown() throws Exception { this.voucherService = null; this.voucherTypeService = null; this.periodService = null; this.personService = null; this.accountService = null; this.currencyService = null; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -