public void tagAdded(final ObjectType objectType, final UUID objectId, final String name, final InternalCallContext context) { if (objectType.equals(ObjectType.ACCOUNT)) { tagAddedForAccount(objectId, name, context); } else if (objectType.equals(ObjectType.BUNDLE)) { tagAddedForBundle(objectId, name, context); } else if (objectType.equals(ObjectType.INVOICE)) { tagAddedForInvoice(objectId, name, context); } else if (objectType.equals(ObjectType.PAYMENT)) { tagAddedForPayment(objectId, name, context); } else { log.info("Ignoring tag addition of {} for object id {} (type {})", new Object[]{name, objectId.toString(), objectType.toString()}); } }
public void tagRemoved(final ObjectType objectType, final UUID objectId, final String name, final InternalCallContext context) { if (objectType.equals(ObjectType.ACCOUNT)) { tagRemovedForAccount(objectId, name, context); } else if (objectType.equals(ObjectType.BUNDLE)) { tagRemovedForBundle(objectId, name, context); } else if (objectType.equals(ObjectType.INVOICE)) { tagRemovedForInvoice(objectId, name, context); } else if (objectType.equals(ObjectType.PAYMENT)) { tagRemovedForPayment(objectId, name, context); } else { log.info("Ignoring tag removal of {} for object id {} (type {})", new Object[]{name, objectId.toString(), objectType.toString()}); } }
tagDao.tagRemoved(ObjectType.ACCOUNT, account.getId(), tag, internalCallContext); tagDao.tagAdded(ObjectType.ACCOUNT, account.getId(), tag, internalCallContext);
@Override public Void call() throws Exception { tagDao.tagAdded(event.getObjectType(), event.getObjectId(), event.getTagDefinition().getName(), createCallContext(event)); return null; } });
@Override public Void call() throws Exception { tagDao.tagRemoved(event.getObjectType(), event.getObjectId(), event.getTagDefinition().getName(), createCallContext(event)); return null; } });
@Test(groups = "slow") public void testAddAndRemoveTagsForAccount() throws Exception { final String name = UUID.randomUUID().toString().substring(0, 20); final String accountKey = UUID.randomUUID().toString(); final Account accountData = new MockAccountBuilder(UUID.randomUUID()) .externalKey(accountKey) .currency(Currency.MXN) .build(); Mockito.when(accountInternalApi.getAccountById(Mockito.eq(accountData.getId()), Mockito.<InternalCallContext>any())).thenReturn(accountData); Mockito.when(accountInternalApi.getAccountByKey(Mockito.eq(accountData.getExternalKey()), Mockito.<InternalCallContext>any())).thenReturn(accountData); final UUID accountId = accountData.getId(); Assert.assertEquals(accountTagSqlDao.getTagsForAccountByKey(accountKey, internalCallContext).size(), 0); tagDao.tagAdded(ObjectType.ACCOUNT, accountId, name, internalCallContext); Assert.assertEquals(accountTagSqlDao.getTagsForAccountByKey(accountKey, internalCallContext).size(), 1); tagDao.tagRemoved(ObjectType.ACCOUNT, accountId, name, internalCallContext); Assert.assertEquals(accountTagSqlDao.getTagsForAccountByKey(accountKey, internalCallContext).size(), 0); }
@Override public Void call() throws Exception { tagDao.tagAdded(event.getObjectType(), event.getObjectId(), event.getTagDefinition().getName(), createCallContext(event)); return null; } });
@Override public Void call() throws Exception { tagDao.tagRemoved(event.getObjectType(), event.getObjectId(), event.getTagDefinition().getName(), createCallContext(event)); return null; } });
@Test(groups = "slow") public void testAddAndRemoveTagsForBundle() throws Exception { final String name = UUID.randomUUID().toString().substring(0, 20); final String externalKey = UUID.randomUUID().toString(); final Account accountData = new MockAccountBuilder() .currency(Currency.MXN) .build(); Mockito.when(accountInternalApi.getAccountById(Mockito.eq(accountData.getId()), Mockito.<InternalCallContext>any())).thenReturn(accountData); Mockito.when(accountInternalApi.getAccountByKey(Mockito.eq(accountData.getExternalKey()), Mockito.<InternalCallContext>any())).thenReturn(accountData); final UUID bundleId = UUID.randomUUID(); final SubscriptionBundle bundle = Mockito.mock(SubscriptionBundle.class); Mockito.when(bundle.getId()).thenReturn(bundleId); Mockito.when(bundle.getAccountId()).thenReturn(accountData.getId()); Mockito.when(bundle.getExternalKey()).thenReturn(externalKey); Mockito.when(entitlementInternalApi.getBundleFromId(Mockito.eq(bundleId), Mockito.<InternalCallContext>any())).thenReturn(bundle); Assert.assertEquals(subscriptionTransitionTagSqlDao.getTagsForBusinessSubscriptionTransitionByKey(externalKey, internalCallContext).size(), 0); tagDao.tagAdded(ObjectType.BUNDLE, bundleId, name, internalCallContext); Assert.assertEquals(subscriptionTransitionTagSqlDao.getTagsForBusinessSubscriptionTransitionByKey(externalKey, internalCallContext).size(), 1); tagDao.tagRemoved(ObjectType.BUNDLE, bundleId, name, internalCallContext); Assert.assertEquals(subscriptionTransitionTagSqlDao.getTagsForBusinessSubscriptionTransitionByKey(externalKey, internalCallContext).size(), 0); } }