@Test(groups = "fast") public void testErrorOnDateTooEarly() throws CatalogApiException { // We find it although the date provided is too early because we default to first catalog version vc.findPlan("shotgun-monthly", dt0); try { // We **don't find it** because date is too early and not part of first catalog version vc.findPlan("shotgun-quarterly", dt0); Assert.fail("Date is too early an exception should have been thrown"); } catch (final CatalogApiException e) { Assert.assertEquals(e.getCode(), ErrorCode.CAT_NO_SUCH_PLAN.getCode()); } }
@Override public void write(final OutputStream output) throws IOException, WebApplicationException { try { final JsonGenerator generator = mapper.getFactory().createGenerator(output); generator.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false); generator.writeStartObject(); while (iterator.hasNext()) { final Tag tag = iterator.next(); final UUID accountId = tag.getObjectId(); try { invoiceUserApi.triggerInvoiceGeneration(accountId, clock.getUTCToday(), callContext); generator.writeStringField(accountId.toString(), OK); } catch (final InvoiceApiException e) { if (e.getCode() != ErrorCode.INVOICE_NOTHING_TO_DO.getCode()) { log.warn("Unable to trigger invoice generation for accountId='{}'", accountId); } generator.writeStringField(accountId.toString(), ErrorCode.fromCode(e.getCode()).toString()); } } generator.writeEndObject(); generator.close(); } finally { // In case the client goes away (IOException), make sure to close the underlying DB connection tags.close(); } } };
@Test(groups = "slow", description = "https://github.com/killbill/killbill/issues/842") public void testCreateAmbiguousPlan() throws Exception { final StandaloneCatalog catalog = XMLLoader.getObjectFromString(Resources.getResource("SpyCarAdvanced.xml").toExternalForm(), StandaloneCatalog.class); Mockito.when(overrides.getOverrides()).thenReturn(ImmutableList.of(override)); final Plan plan = standaloneCatalogWithPriceOverride.createOrFindCurrentPlan(spec, overrides); Assert.assertTrue(plan.getName().startsWith("standard-monthly-67890-")); final Matcher m = DefaultPriceOverride.CUSTOM_PLAN_NAME_PATTERN.matcher(plan.getName()); Assert.assertTrue(m.matches()); Assert.assertNotNull(catalog.findCurrentPlan("standard-monthly")); Assert.assertNotNull(standaloneCatalogWithPriceOverride.findCurrentPlan("standard-monthly")); Assert.fail(); } catch (final CatalogApiException e) { Assert.assertEquals(e.getCode(), ErrorCode.CAT_NO_SUCH_PLAN.getCode()); Assert.assertNotNull(standaloneCatalogWithPriceOverride.findCurrentPlan("standard-monthly-1"));
private void tCreateSubscriptionInternal(@Nullable final SubscriptionBaseBundle bundle, @Nullable final String productName, @Nullable final BillingPeriod term, final String planSet, final ErrorCode expected) { try { testUtil.createSubscription(true, bundle, productName, term, planSet); Assert.fail("Exception expected, error code: " + expected); } catch (final SubscriptionBaseApiException e) { assertEquals(e.getCode(), expected.getCode()); } }
@Test(groups = "slow") public void testCustomFieldBasic() throws Exception { customFieldUserApi.addCustomFields(ImmutableList.<CustomField>of(customField3, customField1), callContext); } catch (CustomFieldApiException e) { Assert.assertEquals(e.getCode(), ErrorCode.CUSTOM_FIELD_ALREADY_EXISTS.getCode()); Assert.assertEquals(all.size(), 2); Assert.assertEquals(all.size(), 3);
private DefaultPlan maybeGetOverriddenPlan(final String planName) throws CatalogApiException { final InternalTenantContext internalTenantContext = createInternalTenantContext(); try { return priceOverride.getOverriddenPlan(planName, this, internalTenantContext); } catch (final RuntimeException e) { if (e.getCause() == null || e.getCause().getCause() == null || !(e.getCause().getCause() instanceof CatalogApiException) || ((CatalogApiException) e.getCause().getCause()).getCode() != ErrorCode.CAT_NO_SUCH_PLAN.getCode()) { throw e; } else { // Otherwise, ambiguous name? See https://github.com/killbill/killbill/issues/842. return null; } } }
// Set AdListener adView.setAdListener(new AdListener() { @Override public void onFailedToReceiveAd(Ad ad, ErrorCode error) { System.err.println("Ad failed: " + ad.toString() + error.toString()); } @Override public void onReceiveAd(Ad ad) { System.out.println("Ad received: " + ad.toString()); } });
@Test(groups = "slow") public void testCreateBundlesWithSameExternalKeys() throws SubscriptionBaseApiException { final LocalDate init = clock.getUTCToday(); final DefaultSubscriptionBase subscription = testUtil.createSubscription(bundle, productName, term, planSetName, requestedDate); assertListenerStatus(); assertNotNull(subscription); Assert.fail("Should not be able to create a bundle with same externalKey"); } catch (final SubscriptionBaseApiException e) { Assert.assertEquals(e.getCode(), ErrorCode.SUB_CREATE_ACTIVE_BUNDLE_KEY_EXISTS.getCode());
private void addBadSimplePlanDescriptor(final CatalogUpdater catalogUpdater, final SimplePlanDescriptor desc) { try { catalogUpdater.addSimplePlanDescriptor(desc); fail("Should have failed to add invalid desc " + desc); } catch (final CatalogApiException e) { assertEquals(e.getCode(), ErrorCode.CAT_FAILED_SIMPLE_PLAN_VALIDATION.getCode()); } } }
@Test(groups = "slow") public void testUniqueExternalPaymentMethod() throws PaymentApiException { paymentApi.addPaymentMethod(account, "thisonewillwork", ExternalPaymentProviderPlugin.PLUGIN_NAME, true, null, ImmutableList.<PluginProperty>of(), callContext); try { paymentApi.addPaymentMethod(account, "thisonewillnotwork", ExternalPaymentProviderPlugin.PLUGIN_NAME, true, null, ImmutableList.<PluginProperty>of(), callContext); } catch (PaymentApiException e) { assertEquals(e.getCode(), ErrorCode.PAYMENT_EXTERNAL_PAYMENT_METHOD_ALREADY_EXISTS.getCode()); } }
private void remove_AUTO_INVOICE_OFF_on_clear(final UUID accountId, final InternalCallContext context) throws OverdueApiException { try { tagApi.removeTag(accountId, ObjectType.ACCOUNT, ControlTagType.AUTO_INVOICING_OFF.getId(), context); } catch (final TagApiException e) { if (e.getCode() != ErrorCode.TAG_DOES_NOT_EXIST.getCode()) { throw new OverdueApiException(e); } } }
// Set AdListener adView.setAdListener(new AdListener() { @Override public void onFailedToReceiveAd(Ad ad, ErrorCode error) { System.err.println("Ad failed: " + ad.toString() + error.toString()); } @Override public void onReceiveAd(Ad ad) { System.out.println("Ad received: " + ad.toString()); } });
protected void assertionException(final DefaultCaseResult cr, final String productName, final ProductCategory productCategory, final BillingPeriod bp, final String priceListName, final PhaseType phaseType, final StandaloneCatalog cat) { try { Assert.assertNull(cr.getResult(new PlanPhaseSpecifier(productName, bp, priceListName, phaseType), cat)); Assert.fail("Exception expected"); } catch (CatalogApiException e) { Assert.assertEquals(e.getCode(), ErrorCode.CAT_PRICE_LIST_NOT_FOUND.getCode()); } }
private void testInvalidPermissionScenario(final List<String> permissions) { try { securityApi.addRoleDefinition("failed", permissions, callContext); Assert.fail("Should fail permissions " + permissions + " were invalid"); } catch (SecurityApiException expected) { Assert.assertEquals(expected.getCode(), ErrorCode.SECURITY_INVALID_PERMISSIONS.getCode()); } }
@Override public void addTag(final UUID objectId, final ObjectType objectType, final UUID tagDefinitionId, final InternalCallContext context) throws TagApiException { final TagModelDao tag = new TagModelDao(context.getCreatedDate(), tagDefinitionId, objectId, objectType); try { tagDao.create(tag, context); } catch (TagApiException e) { // Be lenient here and make the addTag method idempotent if (ErrorCode.TAG_ALREADY_EXISTS.getCode() != e.getCode()) { throw e; } } }
AdView av = (AdView)findViewById(R.id.adView); // Set AdListener av.setAdListener(new AdListener() { AdView av = (AdView)findViewById(R.id.adView); @Override public void onFailedToReceiveAd(Ad ad, ErrorCode error) { System.err.println("Ad failed: " + ad.toString() + error.toString()); av.setVisibility(AdView.GONE);//By setting visibility to GONE, you hide the AdView, but the AdView won't refresh automaticaly anymore. } @Override public void onReceiveAd(Ad ad) { System.out.println("Ad received: " + ad.toString()); av.setVisibility(AdView.VISIBLE); } }); // Create an ad request. AdRequest adRequest = new AdRequest(); // Start loading the ad in the background. av.loadAd(adRequest);