public static <E extends Entity, O, T extends BillingExceptionBase> Pagination<E> getEntityPagination(final Long limit, final SourcePaginationBuilder<O, T> sourcePaginationBuilder, final Function<O, E> function) throws T { final Pagination<O> modelsDao = sourcePaginationBuilder.build(); return new DefaultPagination<E>(modelsDao, limit, Iterators.<E>filter(Iterators.<O, E>transform(modelsDao.iterator(), function), Predicates.<E>notNull())); }
private void checkPagination(final long nbRecords) { final Pagination<CustomField> foundCustomFields = customFieldUserApi.searchCustomFields("ACCOUNT", 0L, nbRecords + 1L, callContext); Assert.assertEquals(foundCustomFields.iterator().hasNext(), nbRecords > 0); Assert.assertEquals(foundCustomFields.getMaxNbRecords(), (Long) nbRecords); Assert.assertEquals(foundCustomFields.getTotalNbRecords(), (Long) nbRecords); final Pagination<CustomField> gotCustomFields = customFieldUserApi.getCustomFields(0L, nbRecords + 1L, callContext); Assert.assertEquals(gotCustomFields.iterator().hasNext(), nbRecords > 0); Assert.assertEquals(gotCustomFields.getMaxNbRecords(), (Long) nbRecords); Assert.assertEquals(gotCustomFields.getTotalNbRecords(), (Long) nbRecords); } }
private void checkPagination(final long nbRecords) { final Pagination<Tag> foundTags = tagUserApi.searchTags("ACCOUNT", 0L, nbRecords + 1L, callContext); Assert.assertEquals(foundTags.iterator().hasNext(), nbRecords > 0); Assert.assertEquals(foundTags.getMaxNbRecords(), (Long) nbRecords); Assert.assertEquals(foundTags.getTotalNbRecords(), (Long) nbRecords); final Pagination<Tag> gotTags = tagUserApi.getTags(0L, nbRecords + 1L, callContext); Assert.assertEquals(gotTags.iterator().hasNext(), nbRecords > 0); Assert.assertEquals(gotTags.getMaxNbRecords(), (Long) nbRecords); Assert.assertEquals(gotTags.getTotalNbRecords(), (Long) nbRecords); } }
Assert.assertEquals(search1.getMaxNbRecords(), (Long) 2L); Assert.assertEquals(search1.getTotalNbRecords(), (Long) 2L); Assert.assertEquals(ImmutableList.<Account>copyOf(search1.iterator()).size(), 2); Assert.assertEquals(search2.getMaxNbRecords(), (Long) 2L); Assert.assertEquals(search2.getTotalNbRecords(), (Long) 2L); Assert.assertEquals(ImmutableList.<Account>copyOf(search2.iterator()).size(), 1); Assert.assertEquals(search3.getMaxNbRecords(), (Long) 2L); Assert.assertEquals(search3.getTotalNbRecords(), (Long) 1L); Assert.assertEquals(ImmutableList.<Account>copyOf(search3.iterator()).size(), 1); Assert.assertEquals(ImmutableList.<Account>copyOf(search4.iterator()).size(), 0); Assert.assertEquals(ImmutableList.<Account>copyOf(search5.iterator()).size(), 1);
public static <E extends Entity, O, T extends BillingExceptionBase> Pagination<E> getEntityPagination(final Long limit, final SourcePaginationBuilder<O, T> sourcePaginationBuilder, final Function<O, E> function) throws T { final Pagination<O> modelsDao = sourcePaginationBuilder.build(); return new DefaultPagination<E>(modelsDao, limit, Iterators.<E>filter(Iterators.<O, E>transform(modelsDao.iterator(), function), Predicates.<E>notNull())); }
@Override public void write(final OutputStream output) throws IOException, WebApplicationException { final Iterator<E> iterator = entities.iterator(); try { final JsonGenerator generator = mapper.getFactory().createGenerator(output); generator.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false); generator.writeStartArray(); while (iterator.hasNext()) { final E entity = iterator.next(); final J asJson = toJson.apply(entity); if (asJson != null) { generator.writeObject(asJson); } } generator.writeEndArray(); generator.close(); } finally { // In case the client goes away (IOException), make sure to close the underlying DB connection entities.close(); } } };
final Iterator<Tag> iterator = tags.iterator();
private void checkPagination(final long nbRecords) { final Pagination<CustomField> foundCustomFields = customFieldUserApi.searchCustomFields("ACCOUNT", 0L, nbRecords + 1L, callContext); Assert.assertEquals(foundCustomFields.iterator().hasNext(), nbRecords > 0); Assert.assertEquals(foundCustomFields.getMaxNbRecords(), (Long) nbRecords); Assert.assertEquals(foundCustomFields.getTotalNbRecords(), (Long) nbRecords); final Pagination<CustomField> gotCustomFields = customFieldUserApi.getCustomFields(0L, nbRecords + 1L, callContext); Assert.assertEquals(gotCustomFields.iterator().hasNext(), nbRecords > 0); Assert.assertEquals(gotCustomFields.getMaxNbRecords(), (Long) nbRecords); Assert.assertEquals(gotCustomFields.getTotalNbRecords(), (Long) nbRecords); } }
private void checkPagination(final long nbRecords) { final Pagination<Tag> foundTags = tagUserApi.searchTags("ACCOUNT", 0L, nbRecords + 1L, callContext); Assert.assertEquals(foundTags.iterator().hasNext(), nbRecords > 0); Assert.assertEquals(foundTags.getMaxNbRecords(), (Long) nbRecords); Assert.assertEquals(foundTags.getTotalNbRecords(), (Long) nbRecords); final Pagination<Tag> gotTags = tagUserApi.getTags(0L, nbRecords + 1L, callContext); Assert.assertEquals(gotTags.iterator().hasNext(), nbRecords > 0); Assert.assertEquals(gotTags.getMaxNbRecords(), (Long) nbRecords); Assert.assertEquals(gotTags.getTotalNbRecords(), (Long) nbRecords); } }
private void verifyPayment(final PaymentModelDao loadedPaymentModelDao, final PaymentModelDao specifiedPaymentModelDao) { Assert.assertEquals(loadedPaymentModelDao.getAccountId(), specifiedPaymentModelDao.getAccountId()); Assert.assertTrue(loadedPaymentModelDao.getPaymentNumber() > 0); Assert.assertEquals(loadedPaymentModelDao.getPaymentMethodId(), specifiedPaymentModelDao.getPaymentMethodId()); Assert.assertEquals(loadedPaymentModelDao.getExternalKey(), specifiedPaymentModelDao.getExternalKey()); // Verify search APIs Assert.assertEquals(ImmutableList.<PaymentModelDao>copyOf(paymentDao.searchPayments(specifiedPaymentModelDao.getPaymentMethodId().toString(), 0L, 100L, internalCallContext).iterator()).size(), 1); Assert.assertEquals(ImmutableList.<PaymentModelDao>copyOf(paymentDao.searchPayments(specifiedPaymentModelDao.getExternalKey(), 0L, 100L, internalCallContext).iterator()).size(), 1); }
private void checkPaymentMethodPagination(final UUID paymentMethodId, final Long maxNbRecords, final boolean deleted) throws PaymentApiException { final Pagination<PaymentMethod> foundPaymentMethods = paymentApi.searchPaymentMethods(paymentMethodId.toString(), 0L, maxNbRecords + 1, false, ImmutableList.<PluginProperty>of(), callContext); Assert.assertEquals(foundPaymentMethods.iterator().hasNext(), !deleted); Assert.assertEquals(foundPaymentMethods.getMaxNbRecords(), maxNbRecords); Assert.assertEquals(foundPaymentMethods.getTotalNbRecords(), (Long) (!deleted ? 1L : 0L)); Assert.assertEquals(foundPaymentMethodsWithPluginInfo.iterator().hasNext(), !deleted); Assert.assertEquals(foundPaymentMethodsWithPluginInfo.getMaxNbRecords(), maxNbRecords); Assert.assertEquals(foundPaymentMethodsWithPluginInfo.getTotalNbRecords(), (Long) (!deleted ? 1L : 0L)); Assert.assertEquals(foundPaymentMethods2.iterator().hasNext(), !deleted); Assert.assertEquals(foundPaymentMethods2.getMaxNbRecords(), maxNbRecords); Assert.assertEquals(foundPaymentMethods2.getTotalNbRecords(), (Long) (!deleted ? 1L : 0L)); Assert.assertEquals(foundPaymentMethods2WithPluginInfo.iterator().hasNext(), !deleted); Assert.assertEquals(foundPaymentMethods2WithPluginInfo.getMaxNbRecords(), maxNbRecords); Assert.assertEquals(foundPaymentMethods2WithPluginInfo.getTotalNbRecords(), (Long) (!deleted ? 1L : 0L)); Assert.assertEquals(gotPaymentMethods.iterator().hasNext(), maxNbRecords > 0); Assert.assertEquals(gotPaymentMethods.getMaxNbRecords(), maxNbRecords); Assert.assertEquals(gotPaymentMethods.getTotalNbRecords(), maxNbRecords); Assert.assertEquals(gotPaymentMethodsWithPluginInfo.iterator().hasNext(), maxNbRecords > 0); Assert.assertEquals(gotPaymentMethodsWithPluginInfo.getMaxNbRecords(), maxNbRecords); Assert.assertEquals(gotPaymentMethodsWithPluginInfo.getTotalNbRecords(), maxNbRecords); Assert.assertEquals(gotPaymentMethods2.iterator().hasNext(), maxNbRecords > 0); Assert.assertEquals(gotPaymentMethods2.getMaxNbRecords(), maxNbRecords); Assert.assertEquals(gotPaymentMethods2.getTotalNbRecords(), maxNbRecords);
@Test(groups = "slow") public void testPaginationForPaymentByStatesAcrossTenants() throws Exception { final DateTime createdDate1 = clock.getUTCNow().minusHours(1); clock.setTime(createdDate1); final Account account = testHelper.createTestAccount(UUID.randomUUID().toString(), true); final int NB_ENTRIES = 30; for (int i = 0; i < NB_ENTRIES; i++) { final PaymentModelDao paymentModelDao1 = new PaymentModelDao(createdDate1, createdDate1, account.getId(), account.getPaymentMethodId(), UUID.randomUUID().toString()); final PaymentTransactionModelDao transaction1 = new PaymentTransactionModelDao(createdDate1, createdDate1, null, UUID.randomUUID().toString(), paymentModelDao1.getId(), TransactionType.AUTHORIZE, createdDate1, TransactionStatus.UNKNOWN, BigDecimal.TEN, Currency.AED, "unknown", ""); paymentDao.insertPaymentWithFirstTransaction(paymentModelDao1, transaction1, internalCallContext); } clock.setTime(createdDate1.plusHours(1)); final Pagination<PaymentTransactionModelDao> result = paymentDao.getByTransactionStatusAcrossTenants(ImmutableList.of(TransactionStatus.UNKNOWN), clock.getUTCNow(), createdDate1, 0L, (long) NB_ENTRIES); Assert.assertEquals(result.getTotalNbRecords(), new Long(NB_ENTRIES)); final Iterator<PaymentTransactionModelDao> iterator = result.iterator(); for (int i = 0; i < NB_ENTRIES; i++) { Assert.assertTrue(iterator.hasNext()); final PaymentTransactionModelDao nextEntry = iterator.next(); Assert.assertEquals(nextEntry.getTransactionStatus(), TransactionStatus.UNKNOWN); } }
Assert.assertFalse(foundPayments.iterator().hasNext()); Assert.assertEquals(foundPayments.getMaxNbRecords(), (Long) 0L); Assert.assertEquals(foundPayments.getTotalNbRecords(), (Long) 0L); Assert.assertFalse(foundPayments.iterator().hasNext()); Assert.assertEquals(foundPayments.getMaxNbRecords(), (Long) 0L); Assert.assertEquals(foundPayments.getTotalNbRecords(), (Long) 0L); Assert.assertFalse(foundPayments.iterator().hasNext()); Assert.assertEquals(foundPayments.getMaxNbRecords(), (Long) 0L); Assert.assertEquals(foundPayments.getTotalNbRecords(), (Long) 0L); Assert.assertTrue(foundPayments.iterator().hasNext()); Assert.assertEquals(foundPayments.getMaxNbRecords(), (Long) 1L); Assert.assertEquals(foundPayments.getTotalNbRecords(), (Long) 1L); Assert.assertTrue(foundPayments.iterator().hasNext()); Assert.assertEquals(foundPayments.getMaxNbRecords(), (Long) 1L); Assert.assertEquals(foundPayments.getTotalNbRecords(), (Long) 1L); Assert.assertEquals(foundPayments.iterator().next().getId(), payment1.getId()); Assert.assertFalse(foundPayments.iterator().hasNext()); Assert.assertEquals(foundPayments.getMaxNbRecords(), (Long) 1L); Assert.assertEquals(foundPayments.getTotalNbRecords(), (Long) 0L); Assert.assertTrue(foundPayments.iterator().hasNext()); Assert.assertEquals(foundPayments.getMaxNbRecords(), (Long) 2L); Assert.assertEquals(foundPayments.getTotalNbRecords(), (Long) 2L);
@Test(groups = "slow") public void testGetPaymentMethodsWithAndWithoutPluginInfo() throws PaymentApiException, PaymentPluginApiException { final BigDecimal requestedAmount = BigDecimal.TEN; final String paymentExternalKey = "externalKey"; final String transactionExternalKey = "transactionKey"; final Payment payment = paymentApi.createPurchase(account, account.getPaymentMethodId(), null, requestedAmount, Currency.AED, null, paymentExternalKey, transactionExternalKey, ImmutableList.<PluginProperty>of(), callContext); final Pagination<PaymentMethod> paymentMethods = paymentApi.getPaymentMethods(0L, 10L, false, null, callContext); final Pagination<PaymentMethod> paymentMethodsPlugin = paymentApi.getPaymentMethods(0L, 10L, true, null, callContext); Assert.assertTrue(paymentMethods.getTotalNbRecords() == 1); Assert.assertTrue(paymentMethodsPlugin.getTotalNbRecords() == 1); PaymentMethod paymentMethod = paymentMethods.iterator().next(); PaymentMethod paymentMethodPlugin = paymentMethodsPlugin.iterator().next(); Assert.assertEquals(paymentMethod.getAccountId(), paymentMethodPlugin.getAccountId()); Assert.assertEquals(paymentMethod.getId(), paymentMethodPlugin.getId()); Assert.assertEquals(paymentMethod.getExternalKey(), paymentMethodPlugin.getExternalKey()); Assert.assertEquals(paymentMethod.getPluginName(), paymentMethodPlugin.getPluginName()); Assert.assertNull(paymentMethod.getPluginDetail()); Assert.assertNotNull(paymentMethodPlugin.getPluginDetail()); Assert.assertTrue(paymentMethodPlugin.getPluginDetail().getProperties().isEmpty()); }
Assert.assertEquals(ImmutableList.<PaymentModelDao>copyOf(paymentDao.searchPayments(paymentModelDao.getPaymentMethodId().toString(), 0L, 100L, internalCallContext).iterator()).size(), 1); Assert.assertEquals(ImmutableList.<PaymentModelDao>copyOf(paymentDao.searchPayments(paymentModelDao.getExternalKey(), 0L, 100L, internalCallContext).iterator()).size(), 1); Assert.assertEquals(ImmutableList.<PaymentModelDao>copyOf(paymentDao.searchPayments(accountId.toString(), 0L, 100L, internalCallContext).iterator()).size(), 4); Assert.assertEquals(ImmutableList.<PaymentModelDao>copyOf(paymentDao.searchPayments("_ERRORED", 0L, 100L, internalCallContext).iterator()).size(), runNb);