com.ning.billing.util.config.catalog.XMLLoader类的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(14.0k)|赞(0)|评价(0)|浏览(107)

本文整理了Java中com.ning.billing.util.config.catalog.XMLLoader类的一些代码示例,展示了XMLLoader类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XMLLoader类的具体详情如下:
包路径:com.ning.billing.util.config.catalog.XMLLoader
类名称:XMLLoader

XMLLoader介绍

暂无

代码示例

代码示例来源:origin: com.ning.billing/killbill-catalog

  1. public static void main(final String[] args) throws Exception {
  2. if (args.length != 1) {
  3. System.err.println("Usage: <catalog filepath>");
  4. System.exit(0);
  5. }
  6. File file = new File(args[0]);
  7. if(!file.exists()) {
  8. System.err.println("Error: '" + args[0] + "' does not exist");
  9. }
  10. StandaloneCatalog catalog = XMLLoader.getObjectFromUri(file.toURI(), StandaloneCatalog.class);
  11. if (catalog != null) {
  12. System.out.println("Success: Catalog loads!");
  13. }
  14. }

代码示例来源:origin: com.ning.billing/killbill-util

  1. public static <T extends ValidatingConfig<T>> T getObjectFromString(final String uri, final Class<T> objectType) throws Exception {
  2. if (uri == null) {
  3. return null;
  4. }
  5. log.info("Initializing an object of class " + objectType.getName() + " from xml file at: " + uri);
  6. return getObjectFromStream(new URI(uri), UriAccessor.accessUri(uri), objectType);
  7. }

代码示例来源:origin: com.ning.billing/killbill-catalog

  1. @Test(groups = "fast")
  2. public void testCatalogLoad() {
  3. try {
  4. XMLLoader.getObjectFromString(Resources.getResource("WeaponsHire.xml").toExternalForm(), StandaloneCatalog.class);
  5. XMLLoader.getObjectFromString(Resources.getResource("WeaponsHireSmall.xml").toExternalForm(), StandaloneCatalog.class);
  6. XMLLoader.getObjectFromString(Resources.getResource("SpyCarBasic.xml").toExternalForm(), StandaloneCatalog.class);
  7. } catch (Exception e) {
  8. Assert.fail(e.toString());
  9. }
  10. }
  11. }

代码示例来源:origin: com.ning.billing/killbill-util

  1. public static <T extends ValidatingConfig<T>> T getObjectFromStream(final URI uri, final InputStream stream, final Class<T> clazz) throws SAXException, InvalidConfigException, JAXBException, IOException, TransformerException, ValidationException {
  2. if (stream == null) {
  3. return null;
  4. }
  5. final Object o = unmarshaller(clazz).unmarshal(stream);
  6. if (clazz.isInstance(o)) {
  7. @SuppressWarnings("unchecked") final
  8. T castObject = (T) o;
  9. try {
  10. validate(uri, castObject);
  11. } catch (ValidationException e) {
  12. e.getErrors().log(log);
  13. System.err.println(e.getErrors().toString());
  14. throw e;
  15. }
  16. return castObject;
  17. } else {
  18. return null;
  19. }
  20. }

代码示例来源:origin: com.ning.billing/killbill-overdue

  1. @Test(groups = "fast")
  2. public void testTotalUnpaidInvoiceBalanceEqualsOrExceeds() throws Exception {
  3. final String xml =
  4. "<condition>" +
  5. " <totalUnpaidInvoiceBalanceEqualsOrExceeds>100.00</totalUnpaidInvoiceBalanceEqualsOrExceeds>" +
  6. "</condition>";
  7. final InputStream is = new ByteArrayInputStream(xml.getBytes());
  8. final MockCondition c = XMLLoader.getObjectFromStreamNoValidation(is, MockCondition.class);
  9. final UUID unpaidInvoiceId = UUID.randomUUID();
  10. final BillingState state0 = new BillingState(new UUID(0L, 1L), 0, BigDecimal.ZERO, new LocalDate(),
  11. DateTimeZone.UTC, unpaidInvoiceId, PaymentResponse.INSUFFICIENT_FUNDS, new Tag[]{});
  12. final BillingState state1 = new BillingState(new UUID(0L, 1L), 1, new BigDecimal("100.00"), new LocalDate(),
  13. DateTimeZone.UTC, unpaidInvoiceId, PaymentResponse.INSUFFICIENT_FUNDS, new Tag[]{});
  14. final BillingState state2 = new BillingState(new UUID(0L, 1L), 1, new BigDecimal("200.00"), new LocalDate(),
  15. DateTimeZone.UTC, unpaidInvoiceId, PaymentResponse.INSUFFICIENT_FUNDS, new Tag[]{});
  16. Assert.assertTrue(!c.evaluate(state0, new LocalDate()));
  17. Assert.assertTrue(c.evaluate(state1, new LocalDate()));
  18. Assert.assertTrue(c.evaluate(state2, new LocalDate()));
  19. }

代码示例来源:origin: com.ning.billing/killbill-util

  1. public static <T> T getObjectFromStreamNoValidation(final InputStream stream, final Class<T> clazz) throws SAXException, InvalidConfigException, JAXBException, IOException, TransformerException {
  2. final Object o = unmarshaller(clazz).unmarshal(stream);
  3. if (clazz.isInstance(o)) {
  4. @SuppressWarnings("unchecked") final
  5. T castObject = (T) o;
  6. return castObject;
  7. } else {
  8. return null;
  9. }
  10. }

代码示例来源:origin: com.ning.billing/killbill-overdue

  1. @Test(groups = "fast")
  2. public void testNumberOfUnpaidInvoicesEqualsOrExceeds() throws Exception {
  3. final String xml =
  4. "<condition>" +
  5. " <numberOfUnpaidInvoicesEqualsOrExceeds>1</numberOfUnpaidInvoicesEqualsOrExceeds>" +
  6. "</condition>";
  7. final InputStream is = new ByteArrayInputStream(xml.getBytes());
  8. final MockCondition c = XMLLoader.getObjectFromStreamNoValidation(is, MockCondition.class);
  9. final UUID unpaidInvoiceId = UUID.randomUUID();
  10. final BillingState state0 = new BillingState(new UUID(0L, 1L), 0, BigDecimal.ZERO, new LocalDate(),
  11. DateTimeZone.UTC, unpaidInvoiceId, PaymentResponse.INSUFFICIENT_FUNDS, new Tag[]{});
  12. final BillingState state1 = new BillingState(new UUID(0L, 1L), 1, BigDecimal.ZERO, new LocalDate(),
  13. DateTimeZone.UTC, unpaidInvoiceId, PaymentResponse.INSUFFICIENT_FUNDS, new Tag[]{});
  14. final BillingState state2 = new BillingState(new UUID(0L, 1L), 2, BigDecimal.ZERO, new LocalDate(),
  15. DateTimeZone.UTC, unpaidInvoiceId, PaymentResponse.INSUFFICIENT_FUNDS, new Tag[]{});
  16. Assert.assertTrue(!c.evaluate(state0, new LocalDate()));
  17. Assert.assertTrue(c.evaluate(state1, new LocalDate()));
  18. Assert.assertTrue(c.evaluate(state2, new LocalDate()));
  19. }

代码示例来源:origin: com.ning.billing/killbill-catalog

  1. final StandaloneCatalog catalog = XMLLoader.getObjectFromUri(u, StandaloneCatalog.class);
  2. result.add(catalog);

代码示例来源:origin: com.ning.billing/killbill-util

  1. public static <T extends ValidatingConfig<T>> T getObjectFromUri(final URI uri, final Class<T> objectType) throws Exception {
  2. if (uri == null) {
  3. return null;
  4. }
  5. log.info("Initializing an object of class " + objectType.getName() + " from xml file at: " + uri);
  6. return getObjectFromStream(uri, UriAccessor.accessUri(uri), objectType);
  7. }

代码示例来源:origin: com.ning.billing/killbill-overdue

  1. @Test(groups = "fast")
  2. public void testTimeSinceEarliestUnpaidInvoiceEqualsOrExceeds() throws Exception {
  3. final String xml =
  4. "<condition>" +
  5. " <timeSinceEarliestUnpaidInvoiceEqualsOrExceeds><unit>DAYS</unit><number>10</number></timeSinceEarliestUnpaidInvoiceEqualsOrExceeds>" +
  6. "</condition>";
  7. final InputStream is = new ByteArrayInputStream(xml.getBytes());
  8. final MockCondition c = XMLLoader.getObjectFromStreamNoValidation(is, MockCondition.class);
  9. final UUID unpaidInvoiceId = UUID.randomUUID();
  10. final LocalDate now = new LocalDate();
  11. final BillingState state0 = new BillingState(new UUID(0L, 1L), 0, BigDecimal.ZERO, null,
  12. DateTimeZone.UTC, unpaidInvoiceId, PaymentResponse.INSUFFICIENT_FUNDS, new Tag[]{});
  13. final BillingState state1 = new BillingState(new UUID(0L, 1L), 1, new BigDecimal("100.00"), now.minusDays(10),
  14. DateTimeZone.UTC, unpaidInvoiceId, PaymentResponse.INSUFFICIENT_FUNDS, new Tag[]{});
  15. final BillingState state2 = new BillingState(new UUID(0L, 1L), 1, new BigDecimal("200.00"), now.minusDays(20),
  16. DateTimeZone.UTC, unpaidInvoiceId, PaymentResponse.INSUFFICIENT_FUNDS, new Tag[]{});
  17. Assert.assertTrue(!c.evaluate(state0, now));
  18. Assert.assertTrue(c.evaluate(state1, now));
  19. Assert.assertTrue(c.evaluate(state2, now));
  20. }

代码示例来源:origin: com.ning.billing/killbill-overdue

  1. @Test(groups = "fast")
  2. public void testConfigLoad() throws Exception {
  3. XMLLoader.getObjectFromString(Resources.getResource("OverdueConfig.xml").toExternalForm(), OverdueConfig.class);
  4. }
  5. }

代码示例来源:origin: com.ning.billing/killbill-catalog

  1. @Test(groups = "fast")
  2. public void test() throws Exception {
  3. final URI uri = new URI(Resources.getResource("WeaponsHireSmall.xml").toExternalForm());
  4. final StandaloneCatalog catalog = XMLLoader.getObjectFromUri(uri, StandaloneCatalog.class);
  5. Assert.assertNotNull(catalog);
  6. final PlanRules rules = catalog.getPlanRules();
  7. final PlanSpecifier specifier = new PlanSpecifier("Laser-Scope", ProductCategory.ADD_ON, BillingPeriod.MONTHLY,
  8. "DEFAULT");
  9. final PlanAlignmentCreate alignment = rules.getPlanCreateAlignment(specifier, catalog);
  10. Assert.assertEquals(alignment, PlanAlignmentCreate.START_OF_SUBSCRIPTION);
  11. final PlanSpecifier specifier2 = new PlanSpecifier("Extra-Ammo", ProductCategory.ADD_ON, BillingPeriod.MONTHLY,
  12. "DEFAULT");
  13. final PlanAlignmentCreate alignment2 = rules.getPlanCreateAlignment(specifier2, catalog);
  14. Assert.assertEquals(alignment2, PlanAlignmentCreate.START_OF_BUNDLE);
  15. }
  16. }

代码示例来源:origin: com.ning.billing/killbill-util

  1. @Test(groups = "fast")
  2. public void test() throws Exception {
  3. final InputStream is = new ByteArrayInputStream(TEST_XML.getBytes());
  4. final XmlTestClass test = XMLLoader.getObjectFromStream(new URI("internal:/"), is, XmlTestClass.class);
  5. assertEquals(test.getFoo(), "foo");
  6. assertEquals(test.getBar(), 1.0);
  7. assertEquals(test.getLala(), 42);
  8. final String output = XMLWriter.writeXML(test, XmlTestClass.class);
  9. //System.out.println(output);
  10. assertEquals(output.replaceAll("\\s", ""), TEST_XML.replaceAll("\\s", ""));
  11. }
  12. }

代码示例来源:origin: com.ning.billing/killbill-overdue

  1. @Test(groups = "fast")
  2. public void testResponseForLastFailedPaymentIn() throws Exception {
  3. final String xml =
  4. "<condition>" +
  5. " <responseForLastFailedPaymentIn><response>INSUFFICIENT_FUNDS</response><response>DO_NOT_HONOR</response></responseForLastFailedPaymentIn>" +
  6. "</condition>";
  7. final InputStream is = new ByteArrayInputStream(xml.getBytes());
  8. final MockCondition c = XMLLoader.getObjectFromStreamNoValidation(is, MockCondition.class);
  9. final UUID unpaidInvoiceId = UUID.randomUUID();
  10. final LocalDate now = new LocalDate();
  11. final BillingState state0 = new BillingState(new UUID(0L, 1L), 0, BigDecimal.ZERO, null,
  12. DateTimeZone.UTC, unpaidInvoiceId, PaymentResponse.LOST_OR_STOLEN_CARD, new Tag[]{});
  13. final BillingState state1 = new BillingState(new UUID(0L, 1L), 1, new BigDecimal("100.00"), now.minusDays(10),
  14. DateTimeZone.UTC, unpaidInvoiceId, PaymentResponse.INSUFFICIENT_FUNDS, new Tag[]{});
  15. final BillingState state2 = new BillingState(new UUID(0L, 1L), 1, new BigDecimal("200.00"), now.minusDays(20),
  16. DateTimeZone.UTC, unpaidInvoiceId, PaymentResponse.DO_NOT_HONOR, new Tag[]{});
  17. Assert.assertTrue(!c.evaluate(state0, now));
  18. Assert.assertTrue(c.evaluate(state1, now));
  19. Assert.assertTrue(c.evaluate(state2, now));
  20. }

代码示例来源:origin: com.ning.billing/killbill-overdue

  1. @LifecycleHandlerType(LifecycleLevel.LOAD_CATALOG)
  2. public synchronized void loadConfig() throws ServiceException {
  3. if (!isConfigLoaded) {
  4. try {
  5. final URI u = new URI(properties.getConfigURI());
  6. overdueConfig = XMLLoader.getObjectFromUri(u, OverdueConfig.class);
  7. // File not found?
  8. if (overdueConfig == null) {
  9. log.warn("Unable to load the overdue config from " + properties.getConfigURI());
  10. overdueConfig = new OverdueConfig();
  11. }
  12. isConfigLoaded = true;
  13. } catch (final URISyntaxException e) {
  14. overdueConfig = new OverdueConfig();
  15. } catch (final IllegalArgumentException e) {
  16. overdueConfig = new OverdueConfig();
  17. } catch (final Exception e) {
  18. throw new ServiceException(e);
  19. }
  20. factory.setOverdueConfig(overdueConfig);
  21. ((DefaultOverdueUserApi) userApi).setOverdueConfig(overdueConfig);
  22. }
  23. }

代码示例来源:origin: com.ning.billing/killbill-util

  1. @Test(groups = "fast")
  2. public void test() throws SAXException, InvalidConfigException, JAXBException, IOException, TransformerException, URISyntaxException, ValidationException {
  3. final InputStream is = new ByteArrayInputStream(TEST_XML.getBytes());
  4. final XmlTestClass test = XMLLoader.getObjectFromStream(new URI("internal:/"), is, XmlTestClass.class);
  5. assertEquals(test.getFoo(), "foo");
  6. assertEquals(test.getBar(), 1.0);
  7. assertEquals(test.getLala(), 42);
  8. }
  9. }

代码示例来源:origin: com.ning.billing/killbill-overdue

  1. @Test(groups = "slow")
  2. public void testWrapperNoConfig() throws Exception {
  3. overdueWrapperFactory.setOverdueConfig(null);
  4. final Account account;
  5. final OverdueWrapper wrapper;
  6. final OverdueState state;
  7. final InputStream is = new ByteArrayInputStream(testOverdueHelper.getConfigXml().getBytes());
  8. final OverdueConfig config = XMLLoader.getObjectFromStreamNoValidation(is, OverdueConfig.class);
  9. state = config.getStateSet().findState(DefaultBlockingState.CLEAR_STATE_NAME);
  10. account = testOverdueHelper.createAccount(clock.getUTCToday().minusDays(31));
  11. wrapper = overdueWrapperFactory.createOverdueWrapperFor(account);
  12. final OverdueState result = wrapper.refresh(internalCallContext);
  13. Assert.assertEquals(result.getName(), state.getName());
  14. Assert.assertEquals(result.blockChanges(), state.blockChanges());
  15. Assert.assertEquals(result.disableEntitlementAndChangesBlocked(), state.disableEntitlementAndChangesBlocked());
  16. }
  17. }

代码示例来源:origin: com.ning.billing/killbill-overdue

  1. "</condition>";
  2. final InputStream is = new ByteArrayInputStream(xml.getBytes());
  3. final MockCondition c = XMLLoader.getObjectFromStreamNoValidation(is, MockCondition.class);
  4. final UUID unpaidInvoiceId = UUID.randomUUID();

代码示例来源:origin: com.ning.billing/killbill-overdue

  1. "</overdueConfig>";
  2. final InputStream is = new ByteArrayInputStream(xml.getBytes());
  3. final OverdueConfig c = XMLLoader.getObjectFromStreamNoValidation(is, OverdueConfig.class);
  4. Assert.assertEquals(c.getStateSet().size(), 2);

代码示例来源:origin: com.ning.billing/killbill-overdue

  1. @Test(groups = "slow")
  2. public void testApplicator() throws Exception {
  3. final InputStream is = new ByteArrayInputStream(testOverdueHelper.getConfigXml().getBytes());
  4. final OverdueConfig config = XMLLoader.getObjectFromStreamNoValidation(is, OverdueConfig.class);
  5. overdueWrapperFactory.setOverdueConfig(config);
  6. final Account account = Mockito.mock(Account.class);
  7. Mockito.when(account.getId()).thenReturn(UUID.randomUUID());
  8. final OverdueStateSet overdueStateSet = config.getStateSet();
  9. final OverdueState clearState = config.getStateSet().findState(DefaultBlockingState.CLEAR_STATE_NAME);
  10. OverdueState state;
  11. state = config.getStateSet().findState("OD1");
  12. applicator.apply(overdueStateSet, null, account, clearState, state, internalCallContext);
  13. testOverdueHelper.checkStateApplied(state);
  14. checkBussEvent("OD1");
  15. state = config.getStateSet().findState("OD2");
  16. applicator.apply(overdueStateSet, null, account, clearState, state, internalCallContext);
  17. testOverdueHelper.checkStateApplied(state);
  18. checkBussEvent("OD2");
  19. state = config.getStateSet().findState("OD3");
  20. applicator.apply(overdueStateSet, null, account, clearState, state, internalCallContext);
  21. testOverdueHelper.checkStateApplied(state);
  22. checkBussEvent("OD3");
  23. }

相关文章