Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class DnsRefreshRequest extends ImmutableObject {
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Id
@SuppressWarnings("unused")
protected long id;
protected Long id;

@Column(nullable = false)
@Enumerated(EnumType.STRING)
Expand Down Expand Up @@ -109,9 +109,7 @@ private DnsRefreshRequest(
checkNotNull(tld, "TLD cannot be null");
checkNotNull(requestTime, "Request time cannot be null");
checkNotNull(lastProcessTime, "Last process time cannot be null");
if (id != null) {
this.id = id;
}
this.id = id;
this.type = type;
this.name = name;
this.tld = tld;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class BulkPricingPackage extends ImmutableObject implements Buildable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "package_promotion_id")
long bulkPricingId;
Long bulkPricingId;

/** The allocation token string for the bulk pricing package. */
@Column(nullable = false)
Expand Down Expand Up @@ -84,7 +84,7 @@ public class BulkPricingPackage extends ImmutableObject implements Buildable {
*/
@Nullable Instant lastNotificationSent;

public long getId() {
public Long getId() {
return bulkPricingId;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;

import com.beust.jcommander.Parameter;
import com.google.common.collect.ImmutableList;
import google.registry.model.domain.token.AllocationToken;
import google.registry.model.domain.token.AllocationToken.TokenType;
import google.registry.model.domain.token.BulkPricingPackage;
Expand All @@ -30,7 +31,7 @@
import org.joda.money.Money;

/** Shared base class for commands to create or update a {@link BulkPricingPackage} object. */
abstract class CreateOrUpdateBulkPricingPackageCommand extends MutatingCommand {
abstract class CreateOrUpdateBulkPricingPackageCommand extends ConfirmingCommand {

@Parameter(description = "Allocation token String of the bulk token", required = true)
List<String> mainParameters;
Expand Down Expand Up @@ -61,6 +62,8 @@ abstract class CreateOrUpdateBulkPricingPackageCommand extends MutatingCommand {
"The next date that the bulk pricing package should be billed for its annual fee")
Instant nextBillingDate;

private ImmutableList<BulkPricingPackage> packagesToSave;

/** Returns the existing BulkPricingPackage or null if it does not exist. */
@Nullable
abstract BulkPricingPackage getOldBulkPricingPackage(String token);
Expand All @@ -87,6 +90,7 @@ boolean clearLastNotificationSent() {

@Override
protected final void init() throws Exception {
ImmutableList.Builder<BulkPricingPackage> packagesBuilder = new ImmutableList.Builder<>();
for (String token : mainParameters) {
tm().transact(
() -> {
Expand All @@ -110,9 +114,20 @@ protected final void init() throws Exception {
if (clearLastNotificationSent()) {
builder.setLastNotificationSent((Instant) null);
}
BulkPricingPackage newBulkPricingPackage = builder.build();
stageEntityChange(oldBulkPricingPackage, newBulkPricingPackage);
packagesBuilder.add(builder.build());
});
}
packagesToSave = packagesBuilder.build();
}

@Override
protected String prompt() {
return String.format("Save %d bulk pricing package(s)?", packagesToSave.size());
}

@Override
protected String execute() {
tm().transact(() -> tm().putAll(packagesToSave));
return String.format("Saved %d bulk pricing package(s).", packagesToSave.size());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ public class DnsRefreshRequestTest extends EntityTestCase {

@Test
void testPersistence() {
assertThat(request.id).isNull();
assertThat(request.getLastProcessTime()).isEqualTo(START_INSTANT);
fakeClock.advanceOneMilli();
tm().transact(() -> tm().insert(request));
fakeClock.advanceOneMilli();
ImmutableList<DnsRefreshRequest> requests = loadAllOf(DnsRefreshRequest.class);
assertThat(requests.size()).isEqualTo(1);
assertThat(requests.get(0)).isEqualTo(request);
assertThat(requests.get(0).id).isNotNull();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,13 @@ void testPersistence() {
.setNextBillingDate(Instant.parse("2011-11-12T05:00:00Z"))
.build();

assertThat(bulkPricingPackage.getId()).isNull();
tm().transact(() -> tm().put(bulkPricingPackage));
BulkPricingPackage persisted =
tm().transact(() -> BulkPricingPackage.loadByTokenString("abc123")).get();
assertThat(persisted.getId()).isNotNull();
assertAboutImmutableObjects()
.that(tm().transact(() -> BulkPricingPackage.loadByTokenString("abc123")).get())
.that(persisted)
.isEqualExceptFields(bulkPricingPackage, "bulkPricingId");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,34 @@ void testSuccess() throws Exception {
assertThat(bulkPricingPackage.getLastNotificationSent()).isEmpty();
}

@Test
void testSuccess_multipleTokens() throws Exception {
for (String token : ImmutableSet.of("abc123", "def456")) {
persistResource(
new AllocationToken.Builder()
.setToken(token)
.setTokenType(TokenType.BULK_PRICING)
.setCreationTimeForTest(Instant.parse("2010-11-12T05:00:00Z"))
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setRenewalPrice(Money.of(USD, 0))
.setAllowedEppActions(ImmutableSet.of(CommandName.CREATE))
.setDiscountFraction(1.0)
.build());
}
runCommandForced(
"--max_domains=100",
"--max_creates=500",
"--price=USD 1000.00",
"--next_billing_date=2012-03-17T00:00:00Z",
"abc123",
"def456");

assertThat(tm().transact(() -> BulkPricingPackage.loadByTokenString("abc123"))).isPresent();
assertThat(tm().transact(() -> BulkPricingPackage.loadByTokenString("def456"))).isPresent();
}

@Test
void testFailure_tokenIsNotBulkType() throws Exception {
persistResource(
Expand Down
Loading