001: /*
002: * Copyright 2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.module.purap.pdf;
017:
018: import java.io.ByteArrayOutputStream;
019: import java.io.FileOutputStream;
020: import java.math.BigDecimal;
021: import java.util.ArrayList;
022: import java.util.HashMap;
023: import java.util.Map;
024:
025: import org.kuali.core.service.BusinessObjectService;
026: import org.kuali.core.service.DateTimeService;
027: import org.kuali.core.service.KualiConfigurationService;
028: import org.kuali.core.util.KualiDecimal;
029: import org.kuali.kfs.KFSConstants;
030: import org.kuali.kfs.bo.Country;
031: import org.kuali.kfs.context.KualiTestBase;
032: import org.kuali.kfs.context.SpringContext;
033: import org.kuali.module.purap.bo.ItemType;
034: import org.kuali.module.purap.bo.PurchaseOrderItem;
035: import org.kuali.module.purap.bo.PurchaseOrderVendorQuote;
036: import org.kuali.module.purap.document.PurchaseOrderDocument;
037: import org.kuali.module.vendor.bo.ContractManager;
038: import org.kuali.test.ConfigureContext;
039:
040: @ConfigureContext
041: public class PurchaseOrderQuotePdfTest extends KualiTestBase {
042: PurchaseOrderVendorQuote poqv;
043: PurchaseOrderDocument po;
044: FileOutputStream fo;
045: ByteArrayOutputStream bao = new ByteArrayOutputStream();
046: PurchaseOrderQuotePdf poQuotePdf = new PurchaseOrderQuotePdf();
047:
048: @Override
049: protected void setUp() throws Exception {
050: super .setUp();
051: BusinessObjectService businessObjectService = SpringContext
052: .getBean(BusinessObjectService.class);
053: // Map poCriteria = new HashMap();
054: // poCriteria.put("documentNumber", new Integer(291190));
055: // Iterator resultIter = (businessObjectService.findMatching(PurchaseOrderDocument.class, poCriteria)).iterator();
056: // po = (PurchaseOrderDocument)(resultIter.next());
057:
058: po = new PurchaseOrderDocument();
059: po.setDeliveryCampusCode("BL");
060: po.setPurapDocumentIdentifier(new Integer(1000));
061: ContractManager contractManager = new ContractManager();
062: contractManager.setContractManagerCode(10);
063: contractManager.setContractManagerName("Julia Child");
064: contractManager.setContractManagerFaxNumber("800-111-1111");
065: contractManager.setContractManagerPhoneNumber("800-222-2222");
066: po.setContractManager(contractManager);
067:
068: po.setDeliveryCityName("Timbuktu");
069: po.setDeliveryPostalCode("90210");
070: po.setDeliveryStateCode("CA");
071: po.setDeliveryCampusCode("BL");
072: poqv = new PurchaseOrderVendorQuote();
073: po.setPurchaseOrderQuoteDueDate(SpringContext.getBean(
074: DateTimeService.class).getCurrentSqlDate());
075: poqv.setPurchaseOrder(po);
076: poqv.setPurchaseOrderVendorQuoteIdentifier(1000);
077: poqv.setVendorName("Dusty's Cellar");
078: poqv.setVendorHeaderGeneratedIdentifier(1000);
079: poqv.setVendorCityName("Okemos");
080: poqv.setVendorCountryCode("US");
081: poqv.setVendorLine1Address("1 Dobie Rd");
082: poqv.setVendorFaxNumber("517-111-1FAX");
083: poqv.setVendorPhoneNumber("1-800-DUSTY-CELL");
084: poqv.setVendorPostalCode("48864");
085: Map countryKey = new HashMap();
086: countryKey.put("postalCountryCode", "US");
087: poqv.setVendorCountry((Country) businessObjectService
088: .findByPrimaryKey(Country.class, countryKey));
089: PurchaseOrderItem poi = new PurchaseOrderItem();
090: ItemType it = new ItemType();
091: it.setItemTypeCode("ITEM");
092: it.setItemTypeDescription("ITEM");
093: poi.setItemType(it);
094: poi.setItemTypeCode(it.getItemTypeCode());
095: poi.setItemDescription("Turtle Cheesecake");
096: poi.setItemIdentifier(1000);
097: poi.setItemLineNumber(1);
098: poi.setItemQuantity(new KualiDecimal(2));
099: poi.setItemUnitOfMeasureCode("piece");
100: poi.setItemUnitPrice(new BigDecimal("5.50"));
101: ArrayList itemList = new ArrayList();
102: itemList.add(poi);
103: po.setItems(itemList);
104: fo = new FileOutputStream("POQuotePDF.pdf");
105: }
106:
107: @Override
108: protected void tearDown() throws Exception {
109: super .tearDown();
110: fo.close();
111: bao.close();
112: poQuotePdf.deletePdf("", "POQuotePDF.pdf");
113:
114: }
115:
116: /**
117: * This method creates a Purchase Order Quote PDF file. The test will fail if this method fails to generate the Purchase Order
118: * Quote PDF file. The Purchase Order Quote PDF file that is created by this method will be removed in the tearDown( ) of this
119: * class, so if you want to check how the PO Quote PDF looks like, please remove the line in tearDown( ) that invokes the
120: * deletePdf method.
121: */
122: public void testGeneratePOQuotePDF() throws Exception {
123:
124: String environment = SpringContext.getBean(
125: KualiConfigurationService.class).getPropertyString(
126: KFSConstants.ENVIRONMENT_KEY);
127:
128: poQuotePdf.generatePOQuotePDF(po, poqv, "East Lansing", "EL",
129: getLogoImageName(), bao, environment);
130: bao.writeTo(fo);
131:
132: }
133:
134: private String getLogoImageName() {
135: return "work//web-root//static//images//logo_bl.jpg";
136: }
137:
138: }
|