1
0
mirror of https://github.com/google/nomulus synced 2025-12-23 06:15:42 +00:00

Convert more @AutoValues to Java records (#2378)

This commit is contained in:
Ben McIlwain
2024-04-17 15:30:23 -04:00
committed by GitHub
parent 903b7979de
commit fa6898167b
19 changed files with 182 additions and 228 deletions

View File

@@ -29,6 +29,7 @@ import org.apache.beam.sdk.coders.NullableCoder;
import org.apache.beam.sdk.coders.StringUtf8Coder;
import org.apache.beam.sdk.coders.VarIntCoder;
import org.apache.beam.sdk.coders.VarLongCoder;
import org.jetbrains.annotations.NotNull;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
@@ -173,7 +174,7 @@ public abstract class BillingEvent {
/** Returns the grouping key for this {@code BillingEvent}, to generate the overall invoice. */
InvoiceGroupingKey getInvoiceGroupingKey() {
return new AutoValue_BillingEvent_InvoiceGroupingKey(
return new InvoiceGroupingKey(
billingTime().toLocalDate().withDayOfMonth(1).toString(),
years() == 0
? ""
@@ -196,9 +197,28 @@ public abstract class BillingEvent {
return String.format("%s_%s", registrarId(), tld());
}
/** Key for each {@code BillingEvent}, when aggregating for the overall invoice. */
@AutoValue
abstract static class InvoiceGroupingKey {
/**
* Key for each {@code BillingEvent}, when aggregating for the overall invoice.
*
* @param startDate The first day this invoice is valid, in yyyy-MM-dd format.
* @param endDate The last day this invoice is valid, in yyyy-MM-dd format.
* @param productAccountKey The billing account id, which is the {@code BillingEvent.billingId}.
* @param usageGroupingKey The invoice grouping key, which is the registrar ID.
* @param description The description of the item, formatted as: {@code action | TLD: tld | TERM:
* n-year}.
* @param unitPrice The cost per invoice item.
* @param unitPriceCurrency The 3-digit currency code the unit price uses.
* @param poNumber The purchase order number for the item, blank for most registrars.
*/
record InvoiceGroupingKey(
String startDate,
String endDate,
String productAccountKey,
String usageGroupingKey,
String description,
Double unitPrice,
String unitPriceCurrency,
String poNumber) {
private static final ImmutableList<String> INVOICE_HEADERS =
ImmutableList.of(
@@ -217,29 +237,6 @@ public abstract class BillingEvent {
"UnitPriceCurrency",
"PONumber");
/** Returns the first day this invoice is valid, in yyyy-MM-dd format. */
abstract String startDate();
/** Returns the last day this invoice is valid, in yyyy-MM-dd format. */
abstract String endDate();
/** Returns the billing account id, which is the {@code BillingEvent.billingId}. */
abstract String productAccountKey();
/** Returns the invoice grouping key, which is the registrar ID. */
abstract String usageGroupingKey();
/** Returns a description of the item, formatted as "action | TLD: tld | TERM: n-year." */
abstract String description();
/** Returns the cost per invoice item. */
abstract Double unitPrice();
/** Returns the 3-digit currency code the unit price uses. */
abstract String unitPriceCurrency();
/** Returns the purchase order number for the item, blank for most registrars. */
abstract String poNumber();
/** Generates the CSV header for the overall invoice. */
static String invoiceHeader() {
@@ -280,7 +277,8 @@ public abstract class BillingEvent {
private InvoiceGroupingKeyCoder() {}
@Override
public void encode(InvoiceGroupingKey value, OutputStream outStream) throws IOException {
public void encode(InvoiceGroupingKey value, @NotNull OutputStream outStream)
throws IOException {
Coder<String> stringCoder = StringUtf8Coder.of();
stringCoder.encode(value.startDate(), outStream);
stringCoder.encode(value.endDate(), outStream);
@@ -293,8 +291,8 @@ public abstract class BillingEvent {
}
@Override
public InvoiceGroupingKey decode(InputStream inStream) throws IOException {
return new AutoValue_BillingEvent_InvoiceGroupingKey(
public InvoiceGroupingKey decode(@NotNull InputStream inStream) throws IOException {
return new InvoiceGroupingKey(
stringCoder.decode(inStream),
stringCoder.decode(inStream),
stringCoder.decode(inStream),

View File

@@ -21,7 +21,6 @@ import static com.google.common.collect.Maps.newHashMap;
import static com.google.common.collect.Multimaps.newListMultimap;
import static com.google.common.collect.Multimaps.toMultimap;
import com.google.auto.value.AutoValue;
import com.google.common.base.Splitter;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
@@ -192,8 +191,8 @@ class BsaDiffCreator {
newAndRemaining.values().stream()
.filter(value -> !Objects.equals(ORDER_ID_SENTINEL, value))
.distinct()
.map(id -> BlockOrder.of(id, OrderType.CREATE)),
deleted.values().stream().distinct().map(id -> BlockOrder.of(id, OrderType.DELETE)));
.map(id -> BlockOrder.create(id, OrderType.CREATE)),
deleted.values().stream().distinct().map(id -> BlockOrder.create(id, OrderType.DELETE)));
}
Stream<BlockLabel> getLabels() {
@@ -203,7 +202,7 @@ class BsaDiffCreator {
.filter(entry -> entry.getValue().contains(ORDER_ID_SENTINEL))
.map(
entry ->
BlockLabel.of(
BlockLabel.create(
entry.getKey(),
LabelType.NEW_ORDER_ASSOCIATION,
getAllValidIdnNames(entry.getKey()))),
@@ -212,12 +211,14 @@ class BsaDiffCreator {
.filter(entry -> !entry.getValue().contains(ORDER_ID_SENTINEL))
.map(
entry ->
BlockLabel.of(
BlockLabel.create(
entry.getKey(),
LabelType.CREATE,
getAllValidIdnNames(entry.getKey()))),
Sets.difference(deleted.keySet(), newAndRemaining.keySet()).stream()
.map(label -> BlockLabel.of(label, LabelType.DELETE, getAllValidIdnNames(label))))
.map(
label ->
BlockLabel.create(label, LabelType.DELETE, getAllValidIdnNames(label))))
.flatMap(x -> x);
}
@@ -241,29 +242,21 @@ class BsaDiffCreator {
}
}
@AutoValue
abstract static class LabelOrderPair {
abstract String label();
abstract Long orderId();
record LabelOrderPair(String label, Long orderId) {
static LabelOrderPair of(String key, Long value) {
return new AutoValue_BsaDiffCreator_LabelOrderPair(key, value);
return new LabelOrderPair(key, value);
}
}
@AutoValue
abstract static class Line {
abstract String label();
abstract ImmutableList<Long> orderIds();
record Line(String label, ImmutableList<Long> orderIds) {
Stream<LabelOrderPair> labelOrderPairs(Canonicals<Long> canonicals) {
return orderIds().stream().map(id -> LabelOrderPair.of(label(), canonicals.get(id)));
}
static Line of(String label, ImmutableList<Long> orderIds) {
return new AutoValue_BsaDiffCreator_Line(label, orderIds);
return new Line(label, orderIds);
}
}
}

View File

@@ -14,7 +14,6 @@
package google.registry.bsa.api;
import com.google.auto.value.AutoValue;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableSet;
@@ -24,18 +23,11 @@ import java.util.List;
* A BSA label to block. New domains with matching second-level domain (SLD) will be denied
* registration in TLDs enrolled with BSA.
*/
@AutoValue
public abstract class BlockLabel {
public record BlockLabel(String label, LabelType labelType, ImmutableSet<String> idnTables) {
static final Joiner JOINER = Joiner.on(',');
static final Splitter SPLITTER = Splitter.on(',').trimResults();
public abstract String label();
public abstract LabelType labelType();
public abstract ImmutableSet<String> idnTables();
public String serialize() {
return JOINER.join(label(), labelType().name(), idnTables().stream().sorted().toArray());
}
@@ -43,7 +35,7 @@ public abstract class BlockLabel {
public static BlockLabel deserialize(String text) {
List<String> items = SPLITTER.splitToList(text);
try {
return of(
return create(
items.get(0),
LabelType.valueOf(items.get(1)),
ImmutableSet.copyOf(items.subList(2, items.size())));
@@ -52,8 +44,8 @@ public abstract class BlockLabel {
}
}
public static BlockLabel of(String label, LabelType type, ImmutableSet<String> idnTables) {
return new AutoValue_BlockLabel(label, type, idnTables);
public static BlockLabel create(String label, LabelType type, ImmutableSet<String> idnTables) {
return new BlockLabel(label, type, idnTables);
}
public enum LabelType {

View File

@@ -14,7 +14,6 @@
package google.registry.bsa.api;
import com.google.auto.value.AutoValue;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import java.util.List;
@@ -23,12 +22,7 @@ import java.util.List;
* A BSA order, which are needed when communicating with the BSA API while processing downloaded
* block lists.
*/
@AutoValue
public abstract class BlockOrder {
public abstract long orderId();
public abstract OrderType orderType();
public record BlockOrder(long orderId, OrderType orderType) {
static final Joiner JOINER = Joiner.on(',');
static final Splitter SPLITTER = Splitter.on(',');
@@ -40,14 +34,14 @@ public abstract class BlockOrder {
public static BlockOrder deserialize(String text) {
List<String> items = SPLITTER.splitToList(text);
try {
return of(Long.valueOf(items.get(0)), OrderType.valueOf(items.get(1)));
return create(Long.valueOf(items.get(0)), OrderType.valueOf(items.get(1)));
} catch (NumberFormatException ne) {
throw new IllegalArgumentException(text);
}
}
public static BlockOrder of(long orderId, OrderType orderType) {
return new AutoValue_BlockOrder(orderId, orderType);
public static BlockOrder create(long orderId, OrderType orderType) {
return new BlockOrder(orderId, orderType);
}
public enum OrderType {

View File

@@ -17,8 +17,6 @@ package google.registry.bsa.api;
import static com.google.common.base.Verify.verify;
import static google.registry.bsa.BsaStringUtils.PROPERTY_JOINER;
import com.google.auto.value.AutoValue;
import com.google.auto.value.extension.memoized.Memoized;
import google.registry.bsa.BsaStringUtils;
import google.registry.bsa.api.UnblockableDomain.Reason;
import java.util.List;
@@ -26,8 +24,7 @@ import java.util.Objects;
import java.util.Optional;
/** Change record of an {@link UnblockableDomain}. */
@AutoValue
public abstract class UnblockableDomainChange {
public record UnblockableDomainChange(UnblockableDomain unblockable, Optional<Reason> newReason) {
/**
* The text used in place of an empty {@link #newReason()} when an instance is serialized to
@@ -38,15 +35,10 @@ public abstract class UnblockableDomainChange {
*/
private static final String DELETE_REASON_PLACEHOLDER = "IS_DELETE";
abstract UnblockableDomain unblockable();
abstract Optional<Reason> newReason();
public String domainName() {
return unblockable().domainName();
}
@Memoized
public UnblockableDomain newValue() {
verify(newReason().isPresent(), "Removed unblockable does not have new value.");
return new UnblockableDomain(unblockable().domainName(), newReason().get());
@@ -77,27 +69,28 @@ public abstract class UnblockableDomainChange {
public static UnblockableDomainChange deserialize(String text) {
List<String> items = BsaStringUtils.PROPERTY_SPLITTER.splitToList(text);
return of(
return create(
new UnblockableDomain(items.get(0), Reason.valueOf(items.get(1))),
Objects.equals(items.get(2), DELETE_REASON_PLACEHOLDER)
? Optional.empty()
: Optional.of(Reason.valueOf(items.get(2))));
}
public static UnblockableDomainChange ofNew(UnblockableDomain unblockable) {
return of(unblockable, Optional.of(unblockable.reason()));
public static UnblockableDomainChange createNew(UnblockableDomain unblockable) {
return create(unblockable, Optional.of(unblockable.reason()));
}
public static UnblockableDomainChange ofDeleted(UnblockableDomain unblockable) {
return of(unblockable, Optional.empty());
public static UnblockableDomainChange createDeleted(UnblockableDomain unblockable) {
return create(unblockable, Optional.empty());
}
public static UnblockableDomainChange ofChanged(UnblockableDomain unblockable, Reason newReason) {
return of(unblockable, Optional.of(newReason));
public static UnblockableDomainChange createChanged(
UnblockableDomain unblockable, Reason newReason) {
return create(unblockable, Optional.of(newReason));
}
private static UnblockableDomainChange of(
private static UnblockableDomainChange create(
UnblockableDomain unblockable, Optional<Reason> newReason) {
return new AutoValue_UnblockableDomainChange(unblockable, newReason);
return new UnblockableDomainChange(unblockable, newReason);
}
}

View File

@@ -177,7 +177,7 @@ public final class DomainsRefresher {
BsaUnblockableDomain domain = nameToEntity.get(domainName);
UnblockableDomain unblockable =
UnblockableDomain.of(domain.label, domain.tld, Reason.valueOf(domain.reason.name()));
changes.add(UnblockableDomainChange.ofChanged(unblockable, Reason.REGISTERED));
changes.add(UnblockableDomainChange.createChanged(unblockable, Reason.REGISTERED));
}
// No longer registered: registered -> reserved/NONE
for (String domainName : noLongerRegistered) {
@@ -186,8 +186,8 @@ public final class DomainsRefresher {
UnblockableDomain.of(domain.label, domain.tld, Reason.valueOf(domain.reason.name()));
changes.add(
currReserved.contains(domainName)
? UnblockableDomainChange.ofChanged(unblockable, Reason.RESERVED)
: UnblockableDomainChange.ofDeleted(unblockable));
? UnblockableDomainChange.createChanged(unblockable, Reason.RESERVED)
: UnblockableDomainChange.createDeleted(unblockable));
}
// No longer reserved: reserved -> registered/None (the former duplicates with newly-registered)
for (String domainName : noLongerReserved) {
@@ -195,7 +195,7 @@ public final class DomainsRefresher {
UnblockableDomain unblockable =
UnblockableDomain.of(domain.label, domain.tld, Reason.valueOf(domain.reason.name()));
if (!currRegistered.contains(domainName)) {
changes.add(UnblockableDomainChange.ofDeleted(unblockable));
changes.add(UnblockableDomainChange.createDeleted(unblockable));
}
}
return changes.build();
@@ -230,7 +230,7 @@ public final class DomainsRefresher {
reservedNotCreated.remove(domainName);
if (newCreated.remove(domainName)) {
changes.add(
UnblockableDomainChange.ofChanged(
UnblockableDomainChange.createChanged(
unblockable.toUnblockableDomain(), Reason.REGISTERED));
}
}
@@ -240,10 +240,10 @@ public final class DomainsRefresher {
Streams.concat(
newCreated.stream()
.map(name -> new UnblockableDomain(name, Reason.REGISTERED))
.map(UnblockableDomainChange::ofNew),
.map(UnblockableDomainChange::createNew),
reservedNotCreated.stream()
.map(name -> new UnblockableDomain(name, Reason.RESERVED))
.map(UnblockableDomainChange::ofNew))
.map(UnblockableDomainChange::createNew))
.forEach(changes::add);
return changes.build();
}

View File

@@ -21,33 +21,26 @@ import static google.registry.bsa.DownloadStage.MAKE_ORDER_AND_LABEL_DIFF;
import static google.registry.bsa.DownloadStage.NOP;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableMap;
import google.registry.bsa.BlockListType;
import google.registry.bsa.DownloadStage;
import java.util.Optional;
import org.joda.time.DateTime;
/** Information needed when handling a download from BSA. */
@AutoValue
public abstract class DownloadSchedule {
abstract long jobId();
abstract DateTime jobCreationTime();
public abstract String jobName();
public abstract DownloadStage stage();
/** The most recent job that ended in the {@code DONE} stage. */
public abstract Optional<CompletedJob> latestCompleted();
/**
* Returns true if download should be processed even if the checksums show that it has not changed
* from the previous one.
*/
public abstract boolean alwaysDownload();
/**
* Information needed when handling a download from BSA.
*
* @param latestCompleted The most recent job that ended in the {@code DONE} stage.
* @param alwaysDownload Whether the download should be processed even if the checksums show that it
* has not changed from the previous one.
*/
public record DownloadSchedule(
long jobId,
DateTime jobCreationTime,
String jobName,
DownloadStage stage,
Optional<CompletedJob> latestCompleted,
boolean alwaysDownload) {
/** Updates the current job to the new stage. */
public void updateJobStage(DownloadStage stage) {
@@ -88,12 +81,12 @@ public abstract class DownloadSchedule {
bsaDownload.setStage(stage);
bsaDownload.setChecksums(checksums);
tm().put(bsaDownload);
return of(bsaDownload);
return create(bsaDownload);
});
}
static DownloadSchedule of(BsaDownload currentJob) {
return new AutoValue_DownloadSchedule(
static DownloadSchedule create(BsaDownload currentJob) {
return new DownloadSchedule(
currentJob.getJobId(),
currentJob.getCreationTime(),
currentJob.getJobName(),
@@ -102,9 +95,9 @@ public abstract class DownloadSchedule {
/* alwaysDownload= */ true);
}
static DownloadSchedule of(
static DownloadSchedule create(
BsaDownload currentJob, CompletedJob latestCompleted, boolean alwaysDownload) {
return new AutoValue_DownloadSchedule(
return new DownloadSchedule(
currentJob.getJobId(),
currentJob.getCreationTime(),
currentJob.getJobName(),
@@ -114,15 +107,10 @@ public abstract class DownloadSchedule {
}
/** Information about a completed BSA download job. */
@AutoValue
public abstract static class CompletedJob {
public abstract String jobName();
public record CompletedJob(String jobName, ImmutableMap<BlockListType, String> checksums) {
public abstract ImmutableMap<BlockListType, String> checksums();
static CompletedJob of(BsaDownload completedJob) {
return new AutoValue_DownloadSchedule_CompletedJob(
completedJob.getJobName(), completedJob.getChecksums());
public static CompletedJob create(BsaDownload completedJob) {
return new CompletedJob(completedJob.getJobName(), completedJob.getChecksums());
}
}
}

View File

@@ -100,15 +100,15 @@ public final class DownloadScheduler {
: Optional.empty();
} else if (recentDownloads.size() == 1) {
// First job ever, still in progress
return Optional.of(DownloadSchedule.of(recentDownloads.get(0)));
return Optional.of(DownloadSchedule.create(recentDownloads.get(0)));
} else {
// Job in progress, with completed previous jobs.
BsaDownload prev = recentDownloads.get(1);
verify(prev.getStage().equals(DONE), "Unexpectedly found two ongoing jobs.");
return Optional.of(
DownloadSchedule.of(
DownloadSchedule.create(
mostRecent,
CompletedJob.of(prev),
CompletedJob.create(prev),
isTimeAgain(mostRecent, maxNopInterval)));
}
});
@@ -127,8 +127,9 @@ public final class DownloadScheduler {
return prevJob
.map(
prev ->
DownloadSchedule.of(job, CompletedJob.of(prev), isTimeAgain(prev, maxNopInterval)))
.orElseGet(() -> DownloadSchedule.of(job));
DownloadSchedule.create(
job, CompletedJob.create(prev), isTimeAgain(prev, maxNopInterval)))
.orElseGet(() -> DownloadSchedule.create(job));
}
/**

View File

@@ -17,25 +17,21 @@ package google.registry.bsa.persistence;
import static com.google.common.base.Verify.verify;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import com.google.auto.value.AutoValue;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import google.registry.bsa.RefreshStage;
import org.joda.time.DateTime;
/** Information needed when handling a domain refresh. */
@AutoValue
public abstract class RefreshSchedule {
abstract long jobId();
abstract DateTime jobCreationTime();
public abstract String jobName();
public abstract RefreshStage stage();
/** The most recent job that ended in the {@code DONE} stage. */
public abstract DateTime prevRefreshTime();
/**
* Information needed when handling a domain refresh.
*
* @param prevRefreshTime The most recent job that ended in the {@code DONE} stage.
*/
public record RefreshSchedule(
long jobId,
DateTime jobCreationTime,
String jobName,
RefreshStage stage,
DateTime prevRefreshTime) {
/** Updates the current job to the new stage. */
@CanIgnoreReturnValue
@@ -50,12 +46,12 @@ public abstract class RefreshSchedule {
stage);
bsaRefresh.setStage(stage);
tm().put(bsaRefresh);
return of(bsaRefresh, prevRefreshTime());
return create(bsaRefresh, prevRefreshTime());
});
}
static RefreshSchedule of(BsaDomainRefresh job, DateTime prevJobCreationTime) {
return new AutoValue_RefreshSchedule(
static RefreshSchedule create(BsaDomainRefresh job, DateTime prevJobCreationTime) {
return new RefreshSchedule(
job.getJobId(),
job.getCreationTime(),
job.getJobName(),

View File

@@ -68,11 +68,11 @@ public class RefreshScheduler {
RefreshSchedule scheduleNewJob(DateTime prevRefreshTime) {
BsaDomainRefresh newJob = new BsaDomainRefresh();
tm().insert(newJob);
return RefreshSchedule.of(newJob, prevRefreshTime);
return RefreshSchedule.create(newJob, prevRefreshTime);
}
RefreshSchedule rescheduleOngoingJob(BsaDomainRefresh ongoingJob, DateTime prevJobStartTime) {
return RefreshSchedule.of(ongoingJob, prevJobStartTime);
return RefreshSchedule.create(ongoingJob, prevJobStartTime);
}
@VisibleForTesting

View File

@@ -57,7 +57,6 @@ import static google.registry.persistence.transaction.TransactionManagerFactory.
import static google.registry.util.DateTimeUtils.END_OF_TIME;
import static google.registry.util.DateTimeUtils.leapSafeAddYears;
import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.net.InternetDomainName;
@@ -698,18 +697,13 @@ public final class DomainCreateFlow implements MutatingFlow {
}
}
/** A class to store renewal info used in {@link BillingRecurrence} billing events. */
@AutoValue
public abstract static class RenewalPriceInfo {
static DomainCreateFlow.RenewalPriceInfo create(
/** A record to store renewal info used in {@link BillingRecurrence} billing events. */
public record RenewalPriceInfo(
RenewalPriceBehavior renewalPriceBehavior, @Nullable Money renewalPrice) {
static RenewalPriceInfo create(
RenewalPriceBehavior renewalPriceBehavior, @Nullable Money renewalPrice) {
return new AutoValue_DomainCreateFlow_RenewalPriceInfo(renewalPriceBehavior, renewalPrice);
return new RenewalPriceInfo(renewalPriceBehavior, renewalPrice);
}
public abstract RenewalPriceBehavior renewalPriceBehavior();
@Nullable
public abstract Money renewalPrice();
}
private static ImmutableList<FeeTransformResponseExtension> createResponseExtensions(

View File

@@ -72,15 +72,15 @@ class BsaDiffCreatorTest {
BsaDiff diff = diffCreator.createDiff(schedule, idnChecker);
assertThat(diff.getLabels())
.containsExactly(
BlockLabel.of("test1", LabelType.CREATE, ImmutableSet.of("JA")),
BlockLabel.of("test2", LabelType.CREATE, ImmutableSet.of("JA")),
BlockLabel.of("test3", LabelType.CREATE, ImmutableSet.of("JA")));
BlockLabel.create("test1", LabelType.CREATE, ImmutableSet.of("JA")),
BlockLabel.create("test2", LabelType.CREATE, ImmutableSet.of("JA")),
BlockLabel.create("test3", LabelType.CREATE, ImmutableSet.of("JA")));
assertThat(diff.getOrders())
.containsExactly(
BlockOrder.of(1, OrderType.CREATE),
BlockOrder.of(2, OrderType.CREATE),
BlockOrder.of(3, OrderType.CREATE),
BlockOrder.of(4, OrderType.CREATE));
BlockOrder.create(1, OrderType.CREATE),
BlockOrder.create(2, OrderType.CREATE),
BlockOrder.create(3, OrderType.CREATE),
BlockOrder.create(4, OrderType.CREATE));
}
@Test
@@ -96,16 +96,16 @@ class BsaDiffCreatorTest {
BsaDiff diff = diffCreator.createDiff(schedule, idnChecker);
assertThat(diff.getLabels())
.containsExactly(
BlockLabel.of("test1", LabelType.CREATE, ImmutableSet.of("JA")),
BlockLabel.of("test2", LabelType.CREATE, ImmutableSet.of("JA")),
BlockLabel.of("test3", LabelType.CREATE, ImmutableSet.of("JA")));
BlockLabel.create("test1", LabelType.CREATE, ImmutableSet.of("JA")),
BlockLabel.create("test2", LabelType.CREATE, ImmutableSet.of("JA")),
BlockLabel.create("test3", LabelType.CREATE, ImmutableSet.of("JA")));
assertThat(diff.getOrders())
.containsExactly(
BlockOrder.of(1, OrderType.CREATE),
BlockOrder.of(2, OrderType.CREATE),
BlockOrder.of(3, OrderType.CREATE),
BlockOrder.of(4, OrderType.CREATE),
BlockOrder.of(5, OrderType.CREATE));
BlockOrder.create(1, OrderType.CREATE),
BlockOrder.create(2, OrderType.CREATE),
BlockOrder.create(3, OrderType.CREATE),
BlockOrder.create(4, OrderType.CREATE),
BlockOrder.create(5, OrderType.CREATE));
}
@Test
@@ -140,15 +140,15 @@ class BsaDiffCreatorTest {
BsaDiff diff = diffCreator.createDiff(schedule, idnChecker);
assertThat(diff.getLabels())
.containsExactly(
BlockLabel.of("test1", LabelType.DELETE, ImmutableSet.of("JA")),
BlockLabel.of("test2", LabelType.DELETE, ImmutableSet.of("JA")),
BlockLabel.of("test3", LabelType.DELETE, ImmutableSet.of("JA")));
BlockLabel.create("test1", LabelType.DELETE, ImmutableSet.of("JA")),
BlockLabel.create("test2", LabelType.DELETE, ImmutableSet.of("JA")),
BlockLabel.create("test3", LabelType.DELETE, ImmutableSet.of("JA")));
assertThat(diff.getOrders())
.containsExactly(
BlockOrder.of(1, OrderType.DELETE),
BlockOrder.of(2, OrderType.DELETE),
BlockOrder.of(3, OrderType.DELETE),
BlockOrder.of(4, OrderType.DELETE));
BlockOrder.create(1, OrderType.DELETE),
BlockOrder.create(2, OrderType.DELETE),
BlockOrder.create(3, OrderType.DELETE),
BlockOrder.create(4, OrderType.DELETE));
}
@Test
@@ -167,8 +167,8 @@ class BsaDiffCreatorTest {
BsaDiff diff = diffCreator.createDiff(schedule, idnChecker);
assertThat(diff.getLabels())
.containsExactly(
BlockLabel.of("test1", LabelType.NEW_ORDER_ASSOCIATION, ImmutableSet.of("JA")));
assertThat(diff.getOrders()).containsExactly(BlockOrder.of(5, OrderType.CREATE));
BlockLabel.create("test1", LabelType.NEW_ORDER_ASSOCIATION, ImmutableSet.of("JA")));
assertThat(diff.getOrders()).containsExactly(BlockOrder.create(5, OrderType.CREATE));
}
@Test
@@ -187,8 +187,8 @@ class BsaDiffCreatorTest {
when(schedule.latestCompleted()).thenReturn(Optional.of(completedJob));
BsaDiff diff = diffCreator.createDiff(schedule, idnChecker);
assertThat(diff.getLabels())
.containsExactly(BlockLabel.of("test4", LabelType.CREATE, ImmutableSet.of("JA")));
assertThat(diff.getOrders()).containsExactly(BlockOrder.of(5, OrderType.CREATE));
.containsExactly(BlockLabel.create("test4", LabelType.CREATE, ImmutableSet.of("JA")));
assertThat(diff.getOrders()).containsExactly(BlockOrder.create(5, OrderType.CREATE));
}
@Test
@@ -205,7 +205,7 @@ class BsaDiffCreatorTest {
when(schedule.latestCompleted()).thenReturn(Optional.of(completedJob));
BsaDiff diff = diffCreator.createDiff(schedule, idnChecker);
assertThat(diff.getLabels()).isEmpty();
assertThat(diff.getOrders()).containsExactly(BlockOrder.of(4, OrderType.DELETE));
assertThat(diff.getOrders()).containsExactly(BlockOrder.create(4, OrderType.DELETE));
}
@Test
@@ -222,7 +222,7 @@ class BsaDiffCreatorTest {
when(schedule.latestCompleted()).thenReturn(Optional.of(completedJob));
BsaDiff diff = diffCreator.createDiff(schedule, idnChecker);
assertThat(diff.getLabels()).isEmpty();
assertThat(diff.getOrders()).containsExactly(BlockOrder.of(1, OrderType.DELETE));
assertThat(diff.getOrders()).containsExactly(BlockOrder.create(1, OrderType.DELETE));
}
@Test
@@ -240,8 +240,8 @@ class BsaDiffCreatorTest {
when(schedule.latestCompleted()).thenReturn(Optional.of(completedJob));
BsaDiff diff = diffCreator.createDiff(schedule, idnChecker);
assertThat(diff.getLabels())
.containsExactly(BlockLabel.of("test2", LabelType.DELETE, ImmutableSet.of("JA")));
assertThat(diff.getOrders()).containsExactly(BlockOrder.of(3, OrderType.DELETE));
.containsExactly(BlockLabel.create("test2", LabelType.DELETE, ImmutableSet.of("JA")));
assertThat(diff.getOrders()).containsExactly(BlockOrder.create(3, OrderType.DELETE));
}
@Test
@@ -260,13 +260,13 @@ class BsaDiffCreatorTest {
BsaDiff diff = diffCreator.createDiff(schedule, idnChecker);
assertThat(diff.getLabels())
.containsExactly(
BlockLabel.of("test1", LabelType.DELETE, ImmutableSet.of("JA")),
BlockLabel.of("test3", LabelType.DELETE, ImmutableSet.of("JA")));
BlockLabel.create("test1", LabelType.DELETE, ImmutableSet.of("JA")),
BlockLabel.create("test3", LabelType.DELETE, ImmutableSet.of("JA")));
assertThat(diff.getOrders())
.containsExactly(
BlockOrder.of(1, OrderType.DELETE),
BlockOrder.of(2, OrderType.DELETE),
BlockOrder.of(4, OrderType.DELETE));
BlockOrder.create(1, OrderType.DELETE),
BlockOrder.create(2, OrderType.DELETE),
BlockOrder.create(4, OrderType.DELETE));
}
@Test

View File

@@ -144,7 +144,7 @@ class BsaRefreshFunctionalTest {
UnblockableDomain newUnblockable = new UnblockableDomain("blocked1.app", Reason.RESERVED);
assertThat(queryUnblockableDomains()).containsExactly(newUnblockable);
assertThat(gcsClient.readRefreshChanges(jobName))
.containsExactly(UnblockableDomainChange.ofNew(newUnblockable));
.containsExactly(UnblockableDomainChange.createNew(newUnblockable));
verify(bsaReportSender, never()).removeUnblockableDomainsUpdates(anyString());
verify(bsaReportSender, times(1))
.addUnblockableDomainsUpdates("{\n \"reserved\": [\n \"blocked1.app\"\n ]\n}");
@@ -161,7 +161,7 @@ class BsaRefreshFunctionalTest {
UnblockableDomain newUnblockable = new UnblockableDomain("blocked1.dev", Reason.REGISTERED);
assertThat(queryUnblockableDomains()).containsExactly(newUnblockable);
assertThat(gcsClient.readRefreshChanges(jobName))
.containsExactly(UnblockableDomainChange.ofNew(newUnblockable));
.containsExactly(UnblockableDomainChange.createNew(newUnblockable));
verify(bsaReportSender, never()).removeUnblockableDomainsUpdates(anyString());
verify(bsaReportSender, times(1))
@@ -184,7 +184,7 @@ class BsaRefreshFunctionalTest {
assertThat(queryUnblockableDomains()).isEmpty();
assertThat(gcsClient.readRefreshChanges(jobName))
.containsExactly(
UnblockableDomainChange.ofDeleted(
UnblockableDomainChange.createDeleted(
new UnblockableDomain("blocked1.dev", Reason.REGISTERED)));
verify(bsaReportSender, never()).addUnblockableDomainsUpdates(anyString());
@@ -207,7 +207,7 @@ class BsaRefreshFunctionalTest {
assertThat(queryUnblockableDomains()).isEmpty();
assertThat(gcsClient.readRefreshChanges(jobName))
.containsExactly(
UnblockableDomainChange.ofDeleted(
UnblockableDomainChange.createDeleted(
new UnblockableDomain("blocked1.app", Reason.RESERVED)));
verify(bsaReportSender, never()).addUnblockableDomainsUpdates(anyString());
@@ -233,7 +233,7 @@ class BsaRefreshFunctionalTest {
.containsExactly(new UnblockableDomain("blocked1.app", Reason.RESERVED));
assertThat(gcsClient.readRefreshChanges(jobName))
.containsExactly(
UnblockableDomainChange.ofChanged(
UnblockableDomainChange.createChanged(
new UnblockableDomain("blocked1.app", Reason.REGISTERED), Reason.RESERVED));
InOrder inOrder = Mockito.inOrder(bsaReportSender);
inOrder.verify(bsaReportSender).removeUnblockableDomainsUpdates("[\n \"blocked1.app\"\n]");
@@ -260,7 +260,7 @@ class BsaRefreshFunctionalTest {
assertThat(queryUnblockableDomains()).containsExactly(changed);
assertThat(gcsClient.readRefreshChanges(jobName))
.containsExactly(
UnblockableDomainChange.ofChanged(
UnblockableDomainChange.createChanged(
new UnblockableDomain("blocked1.app", Reason.RESERVED), Reason.REGISTERED));
InOrder inOrder = Mockito.inOrder(bsaReportSender);
inOrder.verify(bsaReportSender).removeUnblockableDomainsUpdates("[\n \"blocked1.app\"\n]");
@@ -279,7 +279,7 @@ class BsaRefreshFunctionalTest {
UnblockableDomain newUnblockable = new UnblockableDomain("blocked1.app", Reason.REGISTERED);
assertThat(queryUnblockableDomains()).containsExactly(newUnblockable);
assertThat(gcsClient.readRefreshChanges(jobName))
.containsExactly(UnblockableDomainChange.ofNew(newUnblockable));
.containsExactly(UnblockableDomainChange.createNew(newUnblockable));
}
@Test

View File

@@ -79,7 +79,8 @@ class GcsClientTest {
@Test
void readWriteOrderDiffs_success() throws Exception {
ImmutableList<BlockOrder> orders =
ImmutableList.of(BlockOrder.of(1, OrderType.CREATE), BlockOrder.of(2, OrderType.DELETE));
ImmutableList.of(
BlockOrder.create(1, OrderType.CREATE), BlockOrder.create(2, OrderType.DELETE));
gcsClient.writeOrderDiffs("job", orders.stream());
assertThat(gcsClient.readOrderDiffs("job")).containsExactlyElementsIn(orders);
}
@@ -88,9 +89,9 @@ class GcsClientTest {
void readWriteLabelDiffs_success() throws Exception {
ImmutableList<BlockLabel> labels =
ImmutableList.of(
BlockLabel.of("1", LabelType.CREATE.CREATE, ImmutableSet.of()),
BlockLabel.of("2", LabelType.NEW_ORDER_ASSOCIATION, ImmutableSet.of("JA")),
BlockLabel.of("3", LabelType.DELETE, ImmutableSet.of("JA", "EXTENDED_LATIN")));
BlockLabel.create("1", LabelType.CREATE.CREATE, ImmutableSet.of()),
BlockLabel.create("2", LabelType.NEW_ORDER_ASSOCIATION, ImmutableSet.of("JA")),
BlockLabel.create("3", LabelType.DELETE, ImmutableSet.of("JA", "EXTENDED_LATIN")));
gcsClient.writeLabelDiffs("job", labels.stream());
assertThat(gcsClient.readLabelDiffs("job")).containsExactlyElementsIn(labels);
}

View File

@@ -28,7 +28,7 @@ class BlockLabelTest {
@BeforeEach
void setup() {
label = BlockLabel.of("buy", LabelType.CREATE, ImmutableSet.of("JA", "EXTENDED_LATIN"));
label = BlockLabel.create("buy", LabelType.CREATE, ImmutableSet.of("JA", "EXTENDED_LATIN"));
}
@Test
@@ -43,7 +43,7 @@ class BlockLabelTest {
@Test
void emptyIdns() {
label = BlockLabel.of("buy", LabelType.CREATE, ImmutableSet.of());
label = BlockLabel.create("buy", LabelType.CREATE, ImmutableSet.of());
assertThat(label.serialize()).isEqualTo("buy,CREATE");
assertThat(BlockLabel.deserialize("buy,CREATE")).isEqualTo(label);
}

View File

@@ -27,7 +27,7 @@ class BlockOrderTest {
@BeforeEach
void setup() {
order = BlockOrder.of(123, OrderType.CREATE);
order = BlockOrder.create(123, OrderType.CREATE);
}
@Test

View File

@@ -44,7 +44,7 @@ class JsonSerializationsTest {
" \"status\": \"ActivationInProgress\"",
" }",
"]"));
assertThat(toInProgressOrdersReport(Stream.of(BlockOrder.of(1, OrderType.CREATE))))
assertThat(toInProgressOrdersReport(Stream.of(BlockOrder.create(1, OrderType.CREATE))))
.hasValue(expected);
}
@@ -66,7 +66,9 @@ class JsonSerializationsTest {
"]"));
assertThat(
toInProgressOrdersReport(
Stream.of(BlockOrder.of(1, OrderType.CREATE), BlockOrder.of(2, OrderType.DELETE))))
Stream.of(
BlockOrder.create(1, OrderType.CREATE),
BlockOrder.create(2, OrderType.DELETE))))
.hasValue(expected);
}
@@ -82,7 +84,7 @@ class JsonSerializationsTest {
" \"status\": \"Active\"",
" }",
"]"));
assertThat(toCompletedOrdersReport(Stream.of(BlockOrder.of(1, OrderType.CREATE))))
assertThat(toCompletedOrdersReport(Stream.of(BlockOrder.create(1, OrderType.CREATE))))
.hasValue(expected);
}
@@ -104,7 +106,9 @@ class JsonSerializationsTest {
"]"));
assertThat(
toCompletedOrdersReport(
Stream.of(BlockOrder.of(1, OrderType.CREATE), BlockOrder.of(2, OrderType.DELETE))))
Stream.of(
BlockOrder.create(1, OrderType.CREATE),
BlockOrder.create(2, OrderType.DELETE))))
.hasValue(expected);
}

View File

@@ -68,7 +68,7 @@ public class DomainsRefresherTest {
tm().transact(() -> tm().insert(BsaUnblockableDomain.of("label.tld", Reason.REGISTERED)));
assertThat(refresher.refreshStaleUnblockables())
.containsExactly(
UnblockableDomainChange.ofDeleted(
UnblockableDomainChange.createDeleted(
new UnblockableDomain("label.tld", UnblockableDomain.Reason.REGISTERED)));
}
@@ -78,7 +78,7 @@ public class DomainsRefresherTest {
tm().transact(() -> tm().insert(BsaUnblockableDomain.of("label.tld", Reason.RESERVED)));
assertThat(refresher.refreshStaleUnblockables())
.containsExactly(
UnblockableDomainChange.ofDeleted(
UnblockableDomainChange.createDeleted(
new UnblockableDomain("label.tld", UnblockableDomain.Reason.RESERVED)));
}
@@ -88,7 +88,7 @@ public class DomainsRefresherTest {
persistBsaLabel("label");
assertThat(refresher.getNewUnblockables())
.containsExactly(
UnblockableDomainChange.ofNew(
UnblockableDomainChange.createNew(
new UnblockableDomain("label.tld", UnblockableDomain.Reason.REGISTERED)));
}
@@ -99,7 +99,7 @@ public class DomainsRefresherTest {
addReservedListsToTld("tld", ImmutableList.of("reservedList"));
assertThat(refresher.getNewUnblockables())
.containsExactly(
UnblockableDomainChange.ofNew(
UnblockableDomainChange.createNew(
new UnblockableDomain("label.tld", UnblockableDomain.Reason.RESERVED)));
}
@@ -112,7 +112,7 @@ public class DomainsRefresherTest {
assertThat(refresher.refreshStaleUnblockables())
.containsExactly(
UnblockableDomainChange.ofChanged(
UnblockableDomainChange.createChanged(
new UnblockableDomain("label.tld", UnblockableDomain.Reason.REGISTERED),
UnblockableDomain.Reason.RESERVED));
}
@@ -125,7 +125,7 @@ public class DomainsRefresherTest {
persistResource(newDomain("label.tld"));
assertThat(refresher.refreshStaleUnblockables())
.containsExactly(
UnblockableDomainChange.ofChanged(
UnblockableDomainChange.createChanged(
new UnblockableDomain("label.tld", UnblockableDomain.Reason.RESERVED),
UnblockableDomain.Reason.REGISTERED));
}
@@ -140,7 +140,7 @@ public class DomainsRefresherTest {
persistResource(newDomain("label.tld"));
assertThat(refresher.refreshStaleUnblockables())
.containsExactly(
UnblockableDomainChange.ofChanged(
UnblockableDomainChange.createChanged(
new UnblockableDomain("label.tld", UnblockableDomain.Reason.RESERVED),
UnblockableDomain.Reason.REGISTERED));
}

View File

@@ -94,7 +94,7 @@ class LabelDiffUpdatesTest {
ImmutableList<UnblockableDomain> unblockableDomains =
applyLabelDiff(
ImmutableList.of(BlockLabel.of("label", LabelType.DELETE, ImmutableSet.of())),
ImmutableList.of(BlockLabel.create("label", LabelType.DELETE, ImmutableSet.of())),
idnChecker,
schedule,
fakeClock.nowUtc());
@@ -119,7 +119,7 @@ class LabelDiffUpdatesTest {
ImmutableList<UnblockableDomain> unblockableDomains =
applyLabelDiff(
ImmutableList.of(
BlockLabel.of("label", LabelType.NEW_ORDER_ASSOCIATION, ImmutableSet.of())),
BlockLabel.create("label", LabelType.NEW_ORDER_ASSOCIATION, ImmutableSet.of())),
idnChecker,
schedule,
fakeClock.nowUtc());
@@ -146,7 +146,7 @@ class LabelDiffUpdatesTest {
ImmutableList<UnblockableDomain> unblockableDomains =
applyLabelDiff(
ImmutableList.of(BlockLabel.of("label", LabelType.CREATE, ImmutableSet.of())),
ImmutableList.of(BlockLabel.create("label", LabelType.CREATE, ImmutableSet.of())),
idnChecker,
schedule,
fakeClock.nowUtc());