diff options
author | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-11 23:06:58 +0000 |
---|---|---|
committer | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-11 23:06:58 +0000 |
commit | 3dd7e2c4da9c80b8182a2d04dc129a67aa7910df (patch) | |
tree | 71b970aa1c5987564405511d3912044387118fd4 /sca-java-1.x/branches/sca-java-0.99/samples/quote-xquery/src/main/java | |
parent | 0f3f9b59b310833f31ba234ee4aefa808649833c (diff) |
Moving 1.x branches
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835121 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-1.x/branches/sca-java-0.99/samples/quote-xquery/src/main/java')
14 files changed, 577 insertions, 0 deletions
diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/quote-xquery/src/main/java/xquery/quote/AvailQuoteProviderImpl.java b/sca-java-1.x/branches/sca-java-0.99/samples/quote-xquery/src/main/java/xquery/quote/AvailQuoteProviderImpl.java new file mode 100644 index 0000000000..146939c190 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/quote-xquery/src/main/java/xquery/quote/AvailQuoteProviderImpl.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package xquery.quote; + +import org.example.avail.AvailQuote; +import org.osoa.sca.annotations.Service; + +@Service(AvailQuoteProviderService.class) +public class AvailQuoteProviderImpl implements AvailQuoteProviderService { + + public AvailQuote provideAvailQuote(String dummyString) { + return TestHelper.buildAvailQuoteData(); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/quote-xquery/src/main/java/xquery/quote/AvailQuoteProviderNodeInfo.java b/sca-java-1.x/branches/sca-java-0.99/samples/quote-xquery/src/main/java/xquery/quote/AvailQuoteProviderNodeInfo.java new file mode 100644 index 0000000000..ac55c02efa --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/quote-xquery/src/main/java/xquery/quote/AvailQuoteProviderNodeInfo.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package xquery.quote; + +import net.sf.saxon.om.NodeInfo; + +import org.osoa.sca.annotations.Remotable; +import org.osoa.sca.annotations.Service; + +@Remotable +@Service +public interface AvailQuoteProviderNodeInfo { + NodeInfo provideAvailQuote(String dummyString); +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/quote-xquery/src/main/java/xquery/quote/AvailQuoteProviderService.java b/sca-java-1.x/branches/sca-java-0.99/samples/quote-xquery/src/main/java/xquery/quote/AvailQuoteProviderService.java new file mode 100644 index 0000000000..2715be19a9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/quote-xquery/src/main/java/xquery/quote/AvailQuoteProviderService.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package xquery.quote; + +import org.example.avail.AvailQuote; +import org.osoa.sca.annotations.Remotable; +import org.osoa.sca.annotations.Service; + +@Remotable +@Service +public interface AvailQuoteProviderService { + AvailQuote provideAvailQuote(String dummyString); +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/quote-xquery/src/main/java/xquery/quote/ExternalReferencesQuoteJoin.java b/sca-java-1.x/branches/sca-java-0.99/samples/quote-xquery/src/main/java/xquery/quote/ExternalReferencesQuoteJoin.java new file mode 100644 index 0000000000..84abb5c520 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/quote-xquery/src/main/java/xquery/quote/ExternalReferencesQuoteJoin.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package xquery.quote; + +import org.example.quote.Quote; +import org.osoa.sca.annotations.Remotable; +import org.osoa.sca.annotations.Service; + +@Remotable +@Service +public interface ExternalReferencesQuoteJoin { + public Quote joinPriceAndAvailQuotes(float taxRate); +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/quote-xquery/src/main/java/xquery/quote/PriceQuoteProvider.java b/sca-java-1.x/branches/sca-java-0.99/samples/quote-xquery/src/main/java/xquery/quote/PriceQuoteProvider.java new file mode 100644 index 0000000000..a8bfc6ca1f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/quote-xquery/src/main/java/xquery/quote/PriceQuoteProvider.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package xquery.quote; + +import org.example.price.PriceQuote; +import org.osoa.sca.annotations.Remotable; +import org.osoa.sca.annotations.Service; + +@Remotable +@Service +public interface PriceQuoteProvider { + + public PriceQuote providePriceQuote(); +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/quote-xquery/src/main/java/xquery/quote/PriceQuoteProviderImpl.java b/sca-java-1.x/branches/sca-java-0.99/samples/quote-xquery/src/main/java/xquery/quote/PriceQuoteProviderImpl.java new file mode 100644 index 0000000000..cbd71f6279 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/quote-xquery/src/main/java/xquery/quote/PriceQuoteProviderImpl.java @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package xquery.quote; + +import org.example.price.PriceQuote; + +public class PriceQuoteProviderImpl implements PriceQuoteProvider { + public PriceQuote providePriceQuote() { + return TestHelper.buildPriceQuoteData(); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/quote-xquery/src/main/java/xquery/quote/PriceQuoteProviderNodeInfo.java b/sca-java-1.x/branches/sca-java-0.99/samples/quote-xquery/src/main/java/xquery/quote/PriceQuoteProviderNodeInfo.java new file mode 100644 index 0000000000..c95c979c64 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/quote-xquery/src/main/java/xquery/quote/PriceQuoteProviderNodeInfo.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package xquery.quote; + +import net.sf.saxon.om.NodeInfo; + +import org.osoa.sca.annotations.Remotable; +import org.osoa.sca.annotations.Service; + +@Remotable +@Service +public interface PriceQuoteProviderNodeInfo { + public NodeInfo providePriceQuote(); +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/quote-xquery/src/main/java/xquery/quote/PropertiesQuoteJoin.java b/sca-java-1.x/branches/sca-java-0.99/samples/quote-xquery/src/main/java/xquery/quote/PropertiesQuoteJoin.java new file mode 100644 index 0000000000..3a70f619a0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/quote-xquery/src/main/java/xquery/quote/PropertiesQuoteJoin.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package xquery.quote; + +import org.example.quote.Quote; +import org.osoa.sca.annotations.Remotable; +import org.osoa.sca.annotations.Service; + +@Remotable +@Service +public interface PropertiesQuoteJoin { + public Quote joinPriceAndAvailQuotes(); +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/quote-xquery/src/main/java/xquery/quote/QuoteCalculator.java b/sca-java-1.x/branches/sca-java-0.99/samples/quote-xquery/src/main/java/xquery/quote/QuoteCalculator.java new file mode 100644 index 0000000000..0b90c9fb0f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/quote-xquery/src/main/java/xquery/quote/QuoteCalculator.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package xquery.quote; + +import org.osoa.sca.annotations.Remotable; +import org.osoa.sca.annotations.Service; + +@Remotable +@Service +public interface QuoteCalculator { + public float calculateTotalPrice(float taxRate, int quantity, float price, boolean fillOrder); +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/quote-xquery/src/main/java/xquery/quote/QuoteCalculatorImpl.java b/sca-java-1.x/branches/sca-java-0.99/samples/quote-xquery/src/main/java/xquery/quote/QuoteCalculatorImpl.java new file mode 100644 index 0000000000..34fd24fbe5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/quote-xquery/src/main/java/xquery/quote/QuoteCalculatorImpl.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package xquery.quote; + +public class QuoteCalculatorImpl implements QuoteCalculator { + + public float calculateTotalPrice(float taxRate, int quantity, float price, + boolean fillOrder) { + float totalTax, costNoTax, totalCost; + if (fillOrder) + { + // Calculate the total tax + totalTax = taxRate * quantity * price; + // Calculate the total cost without tax + costNoTax = quantity * price; + // Add the tax and the cost to get the total cost + totalCost = totalTax + costNoTax; + } + else + { + totalCost = 0; + } + return totalCost; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/quote-xquery/src/main/java/xquery/quote/QuoteJoin.java b/sca-java-1.x/branches/sca-java-0.99/samples/quote-xquery/src/main/java/xquery/quote/QuoteJoin.java new file mode 100644 index 0000000000..fd16c4b4c5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/quote-xquery/src/main/java/xquery/quote/QuoteJoin.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package xquery.quote; + +import org.example.avail.AvailQuote; +import org.example.price.PriceQuote; +import org.example.quote.Quote; +import org.osoa.sca.annotations.Remotable; +import org.osoa.sca.annotations.Service; + +@Remotable +@Service +public interface QuoteJoin { + public Quote joinPriceAndAvailQuotes(PriceQuote priceQuote, AvailQuote availQuote, float taxRate); +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/quote-xquery/src/main/java/xquery/quote/QuoteJoinLocal.java b/sca-java-1.x/branches/sca-java-0.99/samples/quote-xquery/src/main/java/xquery/quote/QuoteJoinLocal.java new file mode 100644 index 0000000000..5d1c7066fe --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/quote-xquery/src/main/java/xquery/quote/QuoteJoinLocal.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package xquery.quote; + +import org.example.avail.AvailQuote; +import org.example.price.PriceQuote; +import org.example.quote.Quote; + +public interface QuoteJoinLocal { + public Quote joinPriceAndAvailQuotes(PriceQuote priceQuote, AvailQuote availQuote, float taxRate); + public Quote joinPriceAndAvailQuotesWs(PriceQuote priceQuote, AvailQuote availQuote, float taxRate); + public Quote joinPriceAndAvailQuotes(); + public Quote joinPriceAndAvailQuotes(float taxRate); + +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/quote-xquery/src/main/java/xquery/quote/QuoteJoinLocalImpl.java b/sca-java-1.x/branches/sca-java-0.99/samples/quote-xquery/src/main/java/xquery/quote/QuoteJoinLocalImpl.java new file mode 100644 index 0000000000..2eff74fbc1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/quote-xquery/src/main/java/xquery/quote/QuoteJoinLocalImpl.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package xquery.quote; + +import org.example.avail.AvailQuote; +import org.example.price.PriceQuote; +import org.example.quote.Quote; +import org.osoa.sca.annotations.Reference; + +public class QuoteJoinLocalImpl implements QuoteJoinLocal { + private QuoteJoin quoteJoin; + private QuoteJoin quoteJoinWs; + private PropertiesQuoteJoin propertiesQuoteJoin; + private ExternalReferencesQuoteJoin externalServicesQuoteJoin; + + @Reference + public void setQuoteJoin(QuoteJoin quoteJoin) { + this.quoteJoin = quoteJoin; + } + + @Reference + public void setQuoteJoinWs(QuoteJoin quoteJoinWs) { + this.quoteJoinWs = quoteJoinWs; + } + + @Reference + public void setPropertiesQuoteJoin(PropertiesQuoteJoin propertiesQuoteJoin) { + this.propertiesQuoteJoin = propertiesQuoteJoin; + } + + @Reference + public void setExternalServicesQuoteJoin(ExternalReferencesQuoteJoin externalServicesQuoteJoin) { + this.externalServicesQuoteJoin = externalServicesQuoteJoin; + } + + public Quote joinPriceAndAvailQuotes(PriceQuote priceQuote, AvailQuote availQuote, float taxRate) { + return quoteJoin.joinPriceAndAvailQuotes(priceQuote, availQuote, taxRate); + } + + public Quote joinPriceAndAvailQuotesWs(PriceQuote priceQuote, AvailQuote availQuote, float taxRate) { + return quoteJoinWs.joinPriceAndAvailQuotes(priceQuote, availQuote, taxRate); + } + + public Quote joinPriceAndAvailQuotes(float taxRate) { + return externalServicesQuoteJoin.joinPriceAndAvailQuotes(taxRate); + } + + public Quote joinPriceAndAvailQuotes() { + return propertiesQuoteJoin.joinPriceAndAvailQuotes(); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/quote-xquery/src/main/java/xquery/quote/TestHelper.java b/sca-java-1.x/branches/sca-java-0.99/samples/quote-xquery/src/main/java/xquery/quote/TestHelper.java new file mode 100644 index 0000000000..65b4df0468 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/quote-xquery/src/main/java/xquery/quote/TestHelper.java @@ -0,0 +1,144 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package xquery.quote; + + +import java.io.IOException; +import java.math.BigInteger; +import java.util.List; + +import junit.framework.TestCase; + +import org.example.avail.AvailFactory; +import org.example.avail.AvailQuote; +import org.example.avail.AvailRequest; +import org.example.price.PriceFactory; +import org.example.price.PriceQuote; +import org.example.price.PriceRequest; +import org.example.price.PriceRequests; +import org.example.price.ShipAddress; +import org.example.quote.Quote; +import org.example.quote.QuoteResponse; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.XMLHelper; +import commonj.sdo.impl.HelperProvider; + +public class TestHelper { + + public static AvailQuote buildAvailQuoteData() { + AvailQuote availQuote = AvailFactory.INSTANCE.createAvailQuote(); + AvailRequest availRequest = AvailFactory.INSTANCE.createAvailRequest(); + availRequest.setWidgetId(BigInteger.valueOf(12)); + availRequest.setRequestedQuantity(10); + availRequest.setQuantityAvail(true); + availRequest.setShipDate("2003-03-22"); + availQuote.getAvailRequest().add(availRequest); + + availRequest = AvailFactory.INSTANCE.createAvailRequest(); + availRequest.setWidgetId(BigInteger.valueOf(134)); + availRequest.setRequestedQuantity(345); + availRequest.setQuantityAvail(false); + availRequest.setShipDate("BackOrder"); + availQuote.getAvailRequest().add(availRequest); + + availRequest = AvailFactory.INSTANCE.createAvailRequest(); + availRequest.setWidgetId(BigInteger.valueOf(211)); + availRequest.setRequestedQuantity(100); + availRequest.setQuantityAvail(true); + availRequest.setShipDate("2003-04-21"); + availQuote.getAvailRequest().add(availRequest); + + return availQuote; + } + + public static PriceQuote buildPriceQuoteData() { + PriceQuote priceQuote = PriceFactory.INSTANCE.createPriceQuote(); + priceQuote.setCustomerName("Acme Inc"); + + ShipAddress shipAddress = PriceFactory.INSTANCE.createShipAddress(); + shipAddress.setStreet("12 Springs Rd"); + shipAddress.setCity("Morris Plains"); + shipAddress.setState("nj"); + shipAddress.setZip("07960"); + priceQuote.setShipAddress(shipAddress); + + PriceRequests priceRequests = PriceFactory.INSTANCE.createPriceRequests(); + PriceRequest priceRequest = PriceFactory.INSTANCE.createPriceRequest(); + priceRequest.setWidgetId(BigInteger.valueOf(12)); + priceRequest.setPrice(1.00f); + priceRequests.getPriceRequest().add(priceRequest); + + priceRequest = PriceFactory.INSTANCE.createPriceRequest(); + priceRequest.setWidgetId(BigInteger.valueOf(134)); + priceRequest.setPrice(34.10f); + priceRequests.getPriceRequest().add(priceRequest); + + priceRequest = PriceFactory.INSTANCE.createPriceRequest(); + priceRequest.setWidgetId(BigInteger.valueOf(211)); + priceRequest.setPrice(10.00f); + priceRequests.getPriceRequest().add(priceRequest); + + priceQuote.setPriceRequests(priceRequests); + + return priceQuote; + } + + public static void assertQuote(AvailQuote availQuote, PriceQuote priceQuote, Quote quote, float taxRate) { + QuoteCalculatorImpl quoteCalculatorImpl = new QuoteCalculatorImpl(); + + TestCase.assertEquals(priceQuote.getCustomerName(), quote.getName()); + ShipAddress shipAddress = priceQuote.getShipAddress(); + TestCase.assertEquals(shipAddress.getStreet()+","+shipAddress.getCity()+","+shipAddress.getState().toUpperCase()+","+shipAddress.getZip(), quote.getAddress()); + List availRequests = availQuote.getAvailRequest(); + List priceRequests = priceQuote.getPriceRequests().getPriceRequest(); + List quoteResponses = quote.getQuoteResponse(); + TestCase.assertEquals(availRequests.size(), priceRequests.size()); + TestCase.assertEquals(availRequests.size(), quoteResponses.size()); + + for(int i=0; i<availRequests.size(); i++) { + AvailRequest availRequest = (AvailRequest)availRequests.get(i); + PriceRequest priceRequest = (PriceRequest)priceRequests.get(i); + QuoteResponse quoteResponse = (QuoteResponse)quoteResponses.get(i); + TestCase.assertEquals(availRequest.getWidgetId(), quoteResponse.getWidgetId()); + TestCase.assertEquals(priceRequest.getPrice(), quoteResponse.getUnitPrice()); + TestCase.assertEquals(availRequest.getRequestedQuantity(), quoteResponse.getRequestedQuantity()); + TestCase.assertEquals(availRequest.isQuantityAvail(), quoteResponse.isFillOrder()); + if(availRequest.getShipDate()==null) { + TestCase.assertNull(quoteResponse.getShipDate()); + } else { + TestCase.assertEquals(availRequest.getShipDate(), quoteResponse.getShipDate()); + } + TestCase.assertEquals(taxRate, quoteResponse.getTaxRate()); + TestCase.assertEquals(quoteCalculatorImpl.calculateTotalPrice(taxRate, availRequest.getRequestedQuantity(), priceRequest.getPrice(), availRequest.isQuantityAvail()), quoteResponse.getTotalCost()); + } + } + + public static void serializeToSystemOut(DataObject object, String name) { + XMLHelper helper = HelperProvider.INSTANCE.xmlHelper(); + + try { + helper.save(object, null, name, System.out); + System.out.println(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} |