killbill-uncached
Changes
catalog/src/test/resources/com/acme/SpyCarCustom.xml 189(+189 -0)
Details
diff --git a/catalog/src/main/java/org/killbill/billing/catalog/io/VersionedCatalogLoader.java b/catalog/src/main/java/org/killbill/billing/catalog/io/VersionedCatalogLoader.java
index 5d0e820..3404ec7 100644
--- a/catalog/src/main/java/org/killbill/billing/catalog/io/VersionedCatalogLoader.java
+++ b/catalog/src/main/java/org/killbill/billing/catalog/io/VersionedCatalogLoader.java
@@ -63,20 +63,7 @@ public class VersionedCatalogLoader implements CatalogLoader {
List<URI> xmlURIs;
if (uriString.endsWith(XML_EXTENSION)) { // Assume its an xml file
xmlURIs = new ArrayList<URI>();
- URI uri = new URI(uriString);
-
- // Try to expand the full path, if possible
- final String schemeSpecificPart = uri.getSchemeSpecificPart();
- if (schemeSpecificPart != null) {
- final String[] split = schemeSpecificPart.split("/");
- final String fileName = split[split.length - 1];
- try {
- uri = new URI(Resources.getResource(fileName).toExternalForm());
- } catch (IllegalArgumentException ignored) {
- }
- }
-
- xmlURIs.add(uri);
+ xmlURIs.add(new URI(uriString));
} else { // Assume its a directory
final String directoryContents = UriAccessor.accessUriAsString(uriString);
xmlURIs = findXmlReferences(directoryContents, new URL(uriString));
diff --git a/catalog/src/test/java/org/killbill/billing/catalog/io/TestVersionedCatalogLoader.java b/catalog/src/test/java/org/killbill/billing/catalog/io/TestVersionedCatalogLoader.java
index d6f212e..3684484 100644
--- a/catalog/src/test/java/org/killbill/billing/catalog/io/TestVersionedCatalogLoader.java
+++ b/catalog/src/test/java/org/killbill/billing/catalog/io/TestVersionedCatalogLoader.java
@@ -18,6 +18,7 @@
package org.killbill.billing.catalog.io;
+import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
@@ -37,6 +38,7 @@ import org.killbill.billing.catalog.api.CatalogApiException;
import org.killbill.billing.catalog.api.InvalidConfigException;
import org.testng.Assert;
import org.testng.annotations.Test;
+import org.weakref.jmx.internal.guava.io.Files;
import org.xml.sax.SAXException;
import com.google.common.io.Resources;
@@ -126,4 +128,43 @@ public class TestVersionedCatalogLoader extends CatalogTestSuiteNoDB {
dt = new DateTime("2011-03-03T00:00:00+00:00");
Assert.assertEquals(it.next().getEffectiveDate(), dt.toDate());
}
+
+ @Test(groups = "fast")
+ public void testLoadCatalogFromClasspathResourceFolder() throws CatalogApiException {
+ final VersionedCatalog c = loader.loadDefaultCatalog("SpyCarBasic.xml");
+ Assert.assertEquals(c.size(), 1);
+ DateTime dt = new DateTime("2013-02-08T00:00:00+00:00");
+ Assert.assertEquals(c.getEffectiveDate(), dt.toDate());
+ Assert.assertEquals(c.getCatalogName(), "SpyCarBasic");
+ }
+
+ @Test(groups = "fast", expectedExceptions = CatalogApiException.class)
+ public void testLoadCatalogFromClasspathResourceBadFolder() throws CatalogApiException {
+ loader.loadDefaultCatalog("com/acme/SpyCarCustom.xml");
+ }
+
+ @Test(groups = "fast")
+ public void testLoadCatalogFromInsideResourceFolder() throws CatalogApiException, URISyntaxException, IOException {
+ final VersionedCatalog c = loader.loadDefaultCatalog("com/acme/SpyCarCustom.xml");
+ Assert.assertEquals(c.size(), 1);
+ DateTime dt = new DateTime("2015-10-04T00:00:00+00:00");
+ Assert.assertEquals(c.getEffectiveDate(), dt.toDate());
+ Assert.assertEquals(c.getCatalogName(), "SpyCarCustom");
+ }
+
+ @Test(groups = "fast", expectedExceptions = CatalogApiException.class)
+ public void testLoadCatalogFromInsideResourceWithBadFolderName() throws CatalogApiException {
+ loader.loadDefaultCatalog("com/acme2/SpyCarCustom.xml");
+ }
+
+ @Test(groups = "fast")
+ public void testLoadCatalogFromExternalFile() throws CatalogApiException, IOException, URISyntaxException {
+ URL originURL = Resources.getResource("SpyCarBasic.xml");
+ File originFile = new File(originURL.toURI());
+ File destinationFile = new File("C:/var/tmp/SpyCarBasic.xml");
+ destinationFile.deleteOnExit();
+ Files.copy(originFile, destinationFile);
+ final VersionedCatalog c = loader.loadDefaultCatalog(destinationFile.toURI().toString());
+ Assert.assertEquals(c.getCatalogName(), "SpyCarBasic");
+ }
}
catalog/src/test/resources/com/acme/SpyCarCustom.xml 189(+189 -0)
diff --git a/catalog/src/test/resources/com/acme/SpyCarCustom.xml b/catalog/src/test/resources/com/acme/SpyCarCustom.xml
new file mode 100644
index 0000000..2d29b02
--- /dev/null
+++ b/catalog/src/test/resources/com/acme/SpyCarCustom.xml
@@ -0,0 +1,189 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!--
+ ~ Copyright 2014-2015 Groupon, Inc
+ ~ Copyright 2014-2015 The Billing Project, LLC
+ ~
+ ~ The Billing Project 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.
+ -->
+
+<catalog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:noNamespaceSchemaLocation="CatalogSchema.xsd ">
+
+ <effectiveDate>2015-10-04T00:00:00+00:00</effectiveDate>
+ <catalogName>SpyCarCustom</catalogName>
+
+ <recurringBillingMode>IN_ADVANCE</recurringBillingMode>
+
+ <currencies>
+ <currency>USD</currency>
+ <currency>GBP</currency>
+ </currencies>
+
+ <products>
+ <product name="Standard">
+ <category>BASE</category>
+ </product>
+ <product name="Sports">
+ <category>BASE</category>
+ </product>
+ <product name="Super">
+ <category>BASE</category>
+ </product>
+ </products>
+
+ <rules>
+ <changePolicy>
+ <changePolicyCase>
+ <policy>IMMEDIATE</policy>
+ </changePolicyCase>
+ </changePolicy>
+ <changeAlignment>
+ <changeAlignmentCase>
+ <alignment>START_OF_BUNDLE</alignment>
+ </changeAlignmentCase>
+ </changeAlignment>
+ <cancelPolicy>
+ <cancelPolicyCase>
+ <policy>IMMEDIATE</policy>
+ </cancelPolicyCase>
+ </cancelPolicy>
+ <createAlignment>
+ <createAlignmentCase>
+ <alignment>START_OF_BUNDLE</alignment>
+ </createAlignmentCase>
+ </createAlignment>
+ <billingAlignment>
+ <billingAlignmentCase>
+ <alignment>ACCOUNT</alignment>
+ </billingAlignmentCase>
+ </billingAlignment>
+ <priceList>
+ <priceListCase>
+ <toPriceList>DEFAULT</toPriceList>
+ </priceListCase>
+ </priceList>
+ </rules>
+
+ <plans>
+ <plan name="standard-monthly">
+ <product>Standard</product>
+ <initialPhases>
+ <phase type="TRIAL">
+ <duration>
+ <unit>DAYS</unit>
+ <number>30</number>
+ </duration>
+ <fixed>
+ <fixedPrice> <!-- empty price implies $0 -->
+ </fixedPrice>
+
+ </fixed>
+ </phase>
+ </initialPhases>
+ <finalPhase type="EVERGREEN">
+ <duration>
+ <unit>UNLIMITED</unit>
+ </duration>
+ <recurring>
+ <billingPeriod>MONTHLY</billingPeriod>
+ <recurringPrice>
+ <price>
+ <currency>GBP</currency>
+ <value>75.00</value>
+ </price>
+ <price>
+ <currency>USD</currency>
+ <value>111.00</value>
+ </price>
+ </recurringPrice>
+ </recurring>
+ </finalPhase>
+ </plan>
+ <plan name="sports-monthly">
+ <product>Sports</product>
+ <initialPhases>
+ <phase type="TRIAL">
+ <duration>
+ <unit>DAYS</unit>
+ <number>30</number>
+ </duration>
+ <fixed>
+ <fixedPrice> <!-- empty price implies $0 -->
+ </fixedPrice>
+ </fixed>
+ </phase>
+ </initialPhases>
+ <finalPhase type="EVERGREEN">
+ <duration>
+ <unit>UNLIMITED</unit>
+ </duration>
+ <recurring>
+ <billingPeriod>MONTHLY</billingPeriod>
+ <recurringPrice>
+ <price>
+ <currency>GBP</currency>
+ <value>375.00</value>
+ </price>
+ <price>
+ <currency>USD</currency>
+ <value>511.00</value>
+ </price>
+ </recurringPrice>
+ </recurring>
+ </finalPhase>
+ </plan>
+ <plan name="super-monthly">
+ <product>Super</product>
+ <initialPhases>
+ <phase type="TRIAL">
+ <duration>
+ <unit>DAYS</unit>
+ <number>30</number>
+ </duration>
+ <fixed>
+ <fixedPrice> <!-- empty price implies $0 -->
+ </fixedPrice>
+
+ </fixed>
+ </phase>
+ </initialPhases>
+ <finalPhase type="EVERGREEN">
+ <duration>
+ <unit>UNLIMITED</unit>
+ </duration>
+ <recurring>
+ <billingPeriod>MONTHLY</billingPeriod>
+ <recurringPrice>
+ <price>
+ <currency>GBP</currency>
+ <value>750.00</value>
+ </price>
+ <price>
+ <currency>USD</currency>
+ <value>1111.00</value>
+ </price>
+ </recurringPrice>
+ </recurring>
+ </finalPhase>
+ </plan>
+ </plans>
+ <priceLists>
+ <defaultPriceList name="DEFAULT">
+ <plans>
+ <plan>standard-monthly</plan>
+ <plan>sports-monthly</plan>
+ <plan>super-monthly</plan>
+ </plans>
+ </defaultPriceList>
+ </priceLists>
+</catalog>