Rename BillingEvent.OneTime.cancellationTargetId

Per comments in []
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=123000109
This commit is contained in:
ctingue 2016-05-23 08:36:16 -07:00 committed by Ben McIlwain
parent 91cf36c5b9
commit 3abb29adf8
2 changed files with 37 additions and 25 deletions

View file

@ -226,11 +226,11 @@ public abstract class BillingEvent extends ImmutableObject
DateTime syntheticCreationTime; DateTime syntheticCreationTime;
/** /**
* For {@link Flag#SYNTHETIC} events, the {@link BillingEvent} from which this OneTime was * For {@link Flag#SYNTHETIC} events, a {@link Key} to the {@link BillingEvent} from which this
* created. This is needed in order to properly match billing events against * OneTime was created. This is needed in order to properly match billing events against
* {@link Cancellation}s. * {@link Cancellation}s.
*/ */
Long cancellationTargetId; Key<? extends BillingEvent> cancellationMatchingBillingEvent;
public Money getCost() { public Money getCost() {
return cost; return cost;
@ -248,8 +248,8 @@ public abstract class BillingEvent extends ImmutableObject
return syntheticCreationTime; return syntheticCreationTime;
} }
public Long getCancellationTargetId() { public Key<? extends BillingEvent> getCancellationMatchingBillingEvent() {
return cancellationTargetId; return cancellationMatchingBillingEvent;
} }
@Override @Override
@ -288,8 +288,9 @@ public abstract class BillingEvent extends ImmutableObject
return this; return this;
} }
public Builder setCancellationTargetId(Long cancellationTargetId) { public Builder setCancellationMatchingBillingEvent(
getInstance().cancellationTargetId = cancellationTargetId; Key<? extends BillingEvent> cancellationMatchingBillingEvent) {
getInstance().cancellationMatchingBillingEvent = cancellationMatchingBillingEvent;
return this; return this;
} }
@ -310,8 +311,9 @@ public abstract class BillingEvent extends ImmutableObject
"Synthetic creation time must be set if and only if the SYNTHETIC flag is set."); "Synthetic creation time must be set if and only if the SYNTHETIC flag is set.");
checkState( checkState(
instance.getFlags().contains(Flag.SYNTHETIC) instance.getFlags().contains(Flag.SYNTHETIC)
== (instance.cancellationTargetId != null), == (instance.cancellationMatchingBillingEvent != null),
"Cancellation target ID must be set if and only if the SYNTHETIC flag is set."); "Cancellation matching billing event must be set if and only if the SYNTHETIC flag "
+ "is set.");
return super.build(); return super.build();
} }
} }

View file

@ -85,17 +85,6 @@ public class BillingEventTest extends EntityTestCase {
.setCost(Money.of(USD, 1)) .setCost(Money.of(USD, 1))
.setEventTime(now) .setEventTime(now)
.setBillingTime(now.plusDays(5)))); .setBillingTime(now.plusDays(5))));
oneTimeSynthetic = persistResource(commonInit(
new BillingEvent.OneTime.Builder()
.setParent(historyEntry)
.setReason(Reason.CREATE)
.setFlags(ImmutableSet.of(BillingEvent.Flag.ANCHOR_TENANT, BillingEvent.Flag.SYNTHETIC))
.setSyntheticCreationTime(now.plusDays(10))
.setCancellationTargetId(1L)
.setPeriodYears(2)
.setCost(Money.of(USD, 1))
.setEventTime(now)
.setBillingTime(now.plusDays(5))));
recurring = persistResource(commonInit( recurring = persistResource(commonInit(
new BillingEvent.Recurring.Builder() new BillingEvent.Recurring.Builder()
.setParent(historyEntry) .setParent(historyEntry)
@ -103,6 +92,17 @@ public class BillingEventTest extends EntityTestCase {
.setReason(Reason.RENEW) .setReason(Reason.RENEW)
.setEventTime(now.plusYears(1)) .setEventTime(now.plusYears(1))
.setRecurrenceEndTime(END_OF_TIME))); .setRecurrenceEndTime(END_OF_TIME)));
oneTimeSynthetic = persistResource(commonInit(
new BillingEvent.OneTime.Builder()
.setParent(historyEntry)
.setReason(Reason.CREATE)
.setFlags(ImmutableSet.of(BillingEvent.Flag.ANCHOR_TENANT, BillingEvent.Flag.SYNTHETIC))
.setSyntheticCreationTime(now.plusDays(10))
.setCancellationMatchingBillingEvent(Key.create(recurring))
.setPeriodYears(2)
.setCost(Money.of(USD, 1))
.setEventTime(now)
.setBillingTime(now.plusDays(5))));
cancellationOneTime = persistResource(commonInit( cancellationOneTime = persistResource(commonInit(
new BillingEvent.Cancellation.Builder() new BillingEvent.Cancellation.Builder()
.setParent(historyEntry2) .setParent(historyEntry2)
@ -137,6 +137,7 @@ public class BillingEventTest extends EntityTestCase {
@Test @Test
public void testPersistence() throws Exception { public void testPersistence() throws Exception {
assertThat(ofy().load().entity(oneTime).now()).isEqualTo(oneTime); assertThat(ofy().load().entity(oneTime).now()).isEqualTo(oneTime);
assertThat(ofy().load().entity(oneTimeSynthetic).now()).isEqualTo(oneTimeSynthetic);
assertThat(ofy().load().entity(recurring).now()).isEqualTo(recurring); assertThat(ofy().load().entity(recurring).now()).isEqualTo(recurring);
assertThat(ofy().load().entity(cancellationOneTime).now()).isEqualTo(cancellationOneTime); assertThat(ofy().load().entity(cancellationOneTime).now()).isEqualTo(cancellationOneTime);
assertThat(ofy().load().entity(cancellationRecurring).now()).isEqualTo(cancellationRecurring); assertThat(ofy().load().entity(cancellationRecurring).now()).isEqualTo(cancellationRecurring);
@ -165,6 +166,13 @@ public class BillingEventTest extends EntityTestCase {
.containsExactly(modification); .containsExactly(modification);
} }
@Test
public void testCancellationMatching() throws Exception {
Key<?> recurringKey = ofy().load().entity(oneTimeSynthetic).now()
.getCancellationMatchingBillingEvent();
assertThat(ofy().load().key(recurringKey).now()).isEqualTo(recurring);
}
@Test @Test
public void testIndexing() throws Exception { public void testIndexing() throws Exception {
verifyIndexing(oneTime, "clientId", "eventTime", "billingTime", "syntheticCreationTime"); verifyIndexing(oneTime, "clientId", "eventTime", "billingTime", "syntheticCreationTime");
@ -183,6 +191,7 @@ public class BillingEventTest extends EntityTestCase {
"Synthetic creation time must be set if and only if the SYNTHETIC flag is set."); "Synthetic creation time must be set if and only if the SYNTHETIC flag is set.");
oneTime.asBuilder() oneTime.asBuilder()
.setFlags(ImmutableSet.of(BillingEvent.Flag.SYNTHETIC)) .setFlags(ImmutableSet.of(BillingEvent.Flag.SYNTHETIC))
.setCancellationMatchingBillingEvent(Key.create(recurring))
.build(); .build();
} }
@ -197,22 +206,23 @@ public class BillingEventTest extends EntityTestCase {
} }
@Test @Test
public void testFailure_syntheticFlagWithoutCancellationTargetId() { public void testFailure_syntheticFlagWithoutCancellationMatchingKey() {
thrown.expect( thrown.expect(
IllegalStateException.class, IllegalStateException.class,
"Synthetic creation time must be set if and only if the SYNTHETIC flag is set."); "Cancellation matching billing event must be set if and only if the SYNTHETIC flag is set");
oneTime.asBuilder() oneTime.asBuilder()
.setFlags(ImmutableSet.of(BillingEvent.Flag.SYNTHETIC)) .setFlags(ImmutableSet.of(BillingEvent.Flag.SYNTHETIC))
.setSyntheticCreationTime(END_OF_TIME)
.build(); .build();
} }
@Test @Test
public void testFailure_cancellationTargetIdWithoutFlag() { public void testFailure_cancellationMatchingKeyWithoutFlag() {
thrown.expect( thrown.expect(
IllegalStateException.class, IllegalStateException.class,
"Cancellation target ID must be set if and only if the SYNTHETIC flag is set"); "Cancellation matching billing event must be set if and only if the SYNTHETIC flag is set");
oneTime.asBuilder() oneTime.asBuilder()
.setCancellationTargetId(2L) .setCancellationMatchingBillingEvent(Key.create(recurring))
.build(); .build();
} }