mirror of
https://github.com/google/nomulus
synced 2026-04-24 02:00:50 +00:00
@@ -0,0 +1,74 @@
|
||||
// Copyright 2023 The Nomulus Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package google.registry.bsa.persistence;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth8.assertThat;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
|
||||
import static org.joda.time.DateTimeZone.UTC;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import google.registry.bsa.persistence.BsaDomainInUse.Reason;
|
||||
import google.registry.persistence.transaction.DatabaseException;
|
||||
import google.registry.persistence.transaction.JpaTestExtensions;
|
||||
import google.registry.persistence.transaction.JpaTestExtensions.JpaIntegrationWithCoverageExtension;
|
||||
import google.registry.testing.FakeClock;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
|
||||
/** Unit tests for {@link BsaDomainInUse}. */
|
||||
public class BsaDomainInUseTest {
|
||||
|
||||
protected FakeClock fakeClock = new FakeClock(DateTime.now(UTC));
|
||||
|
||||
@RegisterExtension
|
||||
final JpaIntegrationWithCoverageExtension jpa =
|
||||
new JpaTestExtensions.Builder().withClock(fakeClock).buildIntegrationWithCoverageExtension();
|
||||
|
||||
@Test
|
||||
void persist() {
|
||||
tm().transact(() -> tm().put(new BsaLabel("label", fakeClock.nowUtc())));
|
||||
tm().transact(() -> tm().put(new BsaDomainInUse("label", "tld", Reason.REGISTERED)));
|
||||
BsaDomainInUse persisted =
|
||||
tm().transact(() -> tm().loadByKey(BsaDomainInUse.vKey("label", "tld")));
|
||||
assertThat(persisted.label).isEqualTo("label");
|
||||
assertThat(persisted.tld).isEqualTo("tld");
|
||||
assertThat(persisted.reason).isEqualTo(Reason.REGISTERED);
|
||||
}
|
||||
|
||||
@Test
|
||||
void cascadeDeletion() {
|
||||
tm().transact(() -> tm().put(new BsaLabel("label", fakeClock.nowUtc())));
|
||||
tm().transact(() -> tm().put(new BsaDomainInUse("label", "tld", Reason.REGISTERED)));
|
||||
assertThat(tm().transact(() -> tm().loadByKeyIfPresent(BsaDomainInUse.vKey("label", "tld"))))
|
||||
.isPresent();
|
||||
tm().transact(() -> tm().delete(BsaLabel.vKey("label")));
|
||||
assertThat(tm().transact(() -> tm().loadByKeyIfPresent(BsaDomainInUse.vKey("label", "tld"))))
|
||||
.isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void insertDomainWithoutLabel() {
|
||||
assertThat(
|
||||
assertThrows(
|
||||
DatabaseException.class,
|
||||
() ->
|
||||
tm().transact(
|
||||
() -> tm().put(new BsaDomainInUse("label", "tld", Reason.REGISTERED)))))
|
||||
.hasMessageThat()
|
||||
.contains("violates foreign key constraint");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
// Copyright 2023 The Nomulus Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package google.registry.bsa.persistence;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.bsa.BlockList.BLOCK;
|
||||
import static google.registry.bsa.BlockList.BLOCK_PLUS;
|
||||
import static google.registry.bsa.DownloadStage.DOWNLOAD;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
|
||||
import static org.joda.time.DateTimeZone.UTC;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import google.registry.bsa.BlockList;
|
||||
import google.registry.persistence.transaction.JpaTestExtensions;
|
||||
import google.registry.persistence.transaction.JpaTestExtensions.JpaIntegrationWithCoverageExtension;
|
||||
import google.registry.testing.FakeClock;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
|
||||
/** Unit test for {@link BsaDownload}. */
|
||||
public class BsaDownloadTest {
|
||||
|
||||
protected FakeClock fakeClock = new FakeClock(DateTime.now(UTC));
|
||||
|
||||
@RegisterExtension
|
||||
final JpaIntegrationWithCoverageExtension jpa =
|
||||
new JpaTestExtensions.Builder().withClock(fakeClock).buildIntegrationWithCoverageExtension();
|
||||
|
||||
@Test
|
||||
void saveJob() {
|
||||
BsaDownload persisted = tm().transact(() -> tm().getEntityManager().merge(new BsaDownload()));
|
||||
assertThat(persisted.jobId).isNotNull();
|
||||
assertThat(persisted.creationTime.getTimestamp()).isEqualTo(fakeClock.nowUtc());
|
||||
assertThat(persisted.stage).isEqualTo(DOWNLOAD);
|
||||
}
|
||||
|
||||
@Test
|
||||
void loadJobByKey() {
|
||||
BsaDownload persisted = tm().transact(() -> tm().getEntityManager().merge(new BsaDownload()));
|
||||
assertThat(tm().transact(() -> tm().loadByKey(BsaDownload.vKey(persisted.jobId))))
|
||||
.isEqualTo(persisted);
|
||||
}
|
||||
|
||||
@Test
|
||||
void checksums() {
|
||||
BsaDownload job = new BsaDownload();
|
||||
assertThat(job.getChecksums()).isEmpty();
|
||||
ImmutableMap<BlockList, String> checksums = ImmutableMap.of(BLOCK, "a", BLOCK_PLUS, "b");
|
||||
job.setBlockListChecksums(checksums);
|
||||
assertThat(job.getChecksums()).isEqualTo(checksums);
|
||||
assertThat(job.blockListChecksums).isEqualTo("BLOCK=a,BLOCK_PLUS=b");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
// Copyright 2023 The Nomulus Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package google.registry.bsa.persistence;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
|
||||
import static org.joda.time.DateTimeZone.UTC;
|
||||
|
||||
import google.registry.persistence.transaction.JpaTestExtensions;
|
||||
import google.registry.persistence.transaction.JpaTestExtensions.JpaIntegrationWithCoverageExtension;
|
||||
import google.registry.testing.FakeClock;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
|
||||
/** Unit tests for {@link BsaLabel}. */
|
||||
public class BsaLabelTest {
|
||||
|
||||
protected FakeClock fakeClock = new FakeClock(DateTime.now(UTC));
|
||||
|
||||
@RegisterExtension
|
||||
final JpaIntegrationWithCoverageExtension jpa =
|
||||
new JpaTestExtensions.Builder().withClock(fakeClock).buildIntegrationWithCoverageExtension();
|
||||
|
||||
@Test
|
||||
void persist() {
|
||||
tm().transact(() -> tm().put(new BsaLabel("label", fakeClock.nowUtc())));
|
||||
BsaLabel persisted = tm().transact(() -> tm().loadByKey(BsaLabel.vKey("label")));
|
||||
assertThat(persisted.getLabel()).isEqualTo("label");
|
||||
assertThat(persisted.creationTime).isEqualTo(fakeClock.nowUtc());
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,9 @@ package google.registry.schema.integration;
|
||||
|
||||
import static com.google.common.truth.Truth.assert_;
|
||||
|
||||
import google.registry.bsa.persistence.BsaDomainInUseTest;
|
||||
import google.registry.bsa.persistence.BsaDownloadTest;
|
||||
import google.registry.bsa.persistence.BsaLabelTest;
|
||||
import google.registry.model.billing.BillingBaseTest;
|
||||
import google.registry.model.common.CursorTest;
|
||||
import google.registry.model.common.DnsRefreshRequestTest;
|
||||
@@ -82,6 +85,9 @@ import org.junit.runner.RunWith;
|
||||
BeforeSuiteTest.class,
|
||||
AllocationTokenTest.class,
|
||||
BillingBaseTest.class,
|
||||
BsaDomainInUseTest.class,
|
||||
BsaDownloadTest.class,
|
||||
BsaLabelTest.class,
|
||||
BulkPricingPackageTest.class,
|
||||
ClaimsListDaoTest.class,
|
||||
ContactHistoryTest.class,
|
||||
|
||||
Reference in New Issue
Block a user