use of org.killbill.xmlloader.ValidationErrors in project killbill by killbill.
the class TestPlanPhase method testValidation.
@Test(groups = "fast")
public void testValidation() {
final MockCatalog catalog = new MockCatalog();
DefaultPlanPhase pp = MockPlanPhase.createUSDMonthlyEvergreen(null, "1.00").setPlan(MockPlan.createBicycleNoTrialEvergreen1USD());
pp.initialize(catalog, null);
ValidationErrors errors = pp.validate(catalog, new ValidationErrors());
errors.log(log);
Assert.assertEquals(errors.size(), 1);
pp = MockPlanPhase.createUSDMonthlyEvergreen("1.00", null).setRecurring(new MockRecurring(BillingPeriod.NO_BILLING_PERIOD, MockInternationalPrice.createUSD("1.00")).setPhase(pp)).setPlan(MockPlan.createBicycleNoTrialEvergreen1USD());
pp.initialize(catalog, null);
errors = pp.validate(catalog, new ValidationErrors());
errors.log(log);
Assert.assertEquals(errors.size(), 1);
}
use of org.killbill.xmlloader.ValidationErrors in project killbill by killbill.
the class DefaultCatalogUserApi method uploadCatalog.
@Override
public void uploadCatalog(final String catalogXML, final CallContext callContext) throws CatalogApiException {
final InternalTenantContext internalTenantContext = createInternalTenantContext(callContext);
try {
final VersionedCatalog versionedCatalog = (VersionedCatalog) catalogService.getFullCatalog(false, true, internalTenantContext);
// Validation purpose: Will throw if bad XML or catalog validation fails
final InputStream stream = new ByteArrayInputStream(catalogXML.getBytes());
final StaticCatalog newCatalogVersion = XMLLoader.getObjectFromStream(new URI("dummy"), stream, StandaloneCatalog.class);
if (versionedCatalog != null) {
// currentCatalog.getCatalogName() could be null if tenant was created with a default catalog
if (versionedCatalog.getCatalogName() != null && !newCatalogVersion.getCatalogName().equals(versionedCatalog.getCatalogName())) {
final ValidationErrors errors = new ValidationErrors();
errors.add(String.format("Catalog name '%s' should match previous catalog name '%s'", newCatalogVersion.getCatalogName(), versionedCatalog.getCatalogName()), new URI("dummy"), StandaloneCatalog.class, "");
// Bummer ValidationException CTOR is private to package...
//final ValidationException validationException = new ValidationException(errors);
//throw new CatalogApiException(errors, ErrorCode.CAT_INVALID_FOR_TENANT, internalTenantContext.getTenantRecordId());
logger.info("Failed to load new catalog version: " + errors.toString());
throw new CatalogApiException(ErrorCode.CAT_INVALID_FOR_TENANT, internalTenantContext.getTenantRecordId());
}
for (StandaloneCatalog c : versionedCatalog.getVersions()) {
if (c.getEffectiveDate().compareTo(newCatalogVersion.getEffectiveDate()) == 0) {
final ValidationErrors errors = new ValidationErrors();
errors.add(String.format("Catalog version for effectiveDate '%s' already exists", newCatalogVersion.getEffectiveDate()), new URI("dummy"), StandaloneCatalog.class, "");
// Bummer ValidationException CTOR is private to package...
//final ValidationException validationException = new ValidationException(errors);
//throw new CatalogApiException(errors, ErrorCode.CAT_INVALID_FOR_TENANT, internalTenantContext.getTenantRecordId());
logger.info("Failed to load new catalog version: " + errors.toString());
throw new CatalogApiException(ErrorCode.CAT_INVALID_FOR_TENANT, internalTenantContext.getTenantRecordId());
}
}
}
catalogCache.clearCatalog(internalTenantContext);
tenantApi.addTenantKeyValue(TenantKey.CATALOG.toString(), catalogXML, callContext);
} catch (final TenantApiException e) {
throw new CatalogApiException(e);
} catch (final ValidationException e) {
throw new CatalogApiException(e, ErrorCode.CAT_INVALID_FOR_TENANT, internalTenantContext.getTenantRecordId());
} catch (final JAXBException e) {
throw new CatalogApiException(e, ErrorCode.CAT_INVALID_FOR_TENANT, internalTenantContext.getTenantRecordId());
} catch (final IOException e) {
throw new IllegalStateException(e);
} catch (final TransformerException e) {
throw new IllegalStateException(e);
} catch (final URISyntaxException e) {
throw new IllegalStateException(e);
} catch (final SAXException e) {
throw new IllegalStateException(e);
} catch (final InvalidConfigException e) {
throw new IllegalStateException(e);
}
}
use of org.killbill.xmlloader.ValidationErrors in project killbill by killbill.
the class TestInternationalPrice method testNegativeValuePrices.
@Test(groups = "fast")
public void testNegativeValuePrices() {
final StandaloneCatalog c = new MockCatalog();
c.setSupportedCurrencies(new Currency[] { Currency.GBP, Currency.EUR, Currency.USD, Currency.BRL, Currency.MXN });
final DefaultInternationalPrice p1 = new MockInternationalPrice();
p1.setPrices(new DefaultPrice[] { new DefaultPrice().setCurrency(Currency.GBP).setValue(new BigDecimal(-1)), new DefaultPrice().setCurrency(Currency.EUR).setValue(new BigDecimal(-1)), new DefaultPrice().setCurrency(Currency.USD).setValue(new BigDecimal(-1)), new DefaultPrice().setCurrency(Currency.BRL).setValue(new BigDecimal(1)), new DefaultPrice().setCurrency(Currency.MXN).setValue(new BigDecimal(1)) });
final ValidationErrors errors = p1.validate(c, new ValidationErrors());
errors.log(log);
Assert.assertEquals(errors.size(), 3);
}
use of org.killbill.xmlloader.ValidationErrors in project killbill by killbill.
the class TestPlan method testDateValidation.
@Test(groups = "fast")
public void testDateValidation() {
final StandaloneCatalog c = new MockCatalog();
c.setSupportedCurrencies(new Currency[] { Currency.GBP, Currency.EUR, Currency.USD, Currency.BRL, Currency.MXN });
final DefaultPlan p1 = MockPlan.createBicycleTrialEvergreen1USD();
p1.setPlansAllowedInBundle(-1);
p1.setEffectiveDateForExistingSubscriptions(new Date((new Date().getTime()) - (1000 * 60 * 60 * 24)));
final ValidationErrors errors = p1.validate(c, new ValidationErrors());
Assert.assertEquals(errors.size(), 3);
errors.log(log);
}
Aggregations