mirror of
https://github.com/google/nomulus.git
synced 2025-06-11 15:04:46 +02:00
Merge two reserved list entities (#616)
* Merge reserved list * Replace INSTANCE with getInstance() * Fix broken test * Rebase on master * Simplify class
This commit is contained in:
parent
34b737edf2
commit
11fb271fb4
25 changed files with 455 additions and 824 deletions
|
@ -18,6 +18,7 @@ import static com.google.common.truth.Truth.assertThat;
|
|||
|
||||
import google.registry.persistence.NomulusPostgreSql;
|
||||
import google.registry.persistence.transaction.JpaTransactionManager;
|
||||
import google.registry.testing.DatastoreEntityExtension;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
|
@ -26,6 +27,7 @@ import org.apache.beam.sdk.options.PipelineOptionsFactory;
|
|||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.testcontainers.containers.PostgreSQLContainer;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
|
@ -38,6 +40,9 @@ public class BeamJpaModuleTest {
|
|||
@Container
|
||||
public PostgreSQLContainer database = new PostgreSQLContainer(NomulusPostgreSql.getDockerTag());
|
||||
|
||||
@RegisterExtension
|
||||
public DatastoreEntityExtension datastoreEntityExtension = new DatastoreEntityExtension();
|
||||
|
||||
@TempDir File tempFolder;
|
||||
|
||||
private File credentialFile;
|
||||
|
@ -51,7 +56,7 @@ public class BeamJpaModuleTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void getJpaTransactionManager_local() {
|
||||
void getJpaTransactionManager_local() {
|
||||
JpaTransactionManager jpa =
|
||||
DaggerBeamJpaModule_JpaTransactionManagerComponent.builder()
|
||||
.beamJpaModule(new BeamJpaModule(credentialFile.getAbsolutePath()))
|
||||
|
|
|
@ -0,0 +1,124 @@
|
|||
// Copyright 2019 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.model.registry.label;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import google.registry.model.registry.label.ReservedList.ReservedListEntry;
|
||||
import google.registry.persistence.transaction.JpaTestRules;
|
||||
import google.registry.persistence.transaction.JpaTestRules.JpaIntegrationWithCoverageExtension;
|
||||
import google.registry.testing.DatastoreEntityExtension;
|
||||
import google.registry.testing.FakeClock;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
|
||||
/** Unit tests for {@link ReservedListSqlDao}. */
|
||||
public class ReservedListSqlDaoTest {
|
||||
|
||||
private final FakeClock fakeClock = new FakeClock();
|
||||
|
||||
@RegisterExtension
|
||||
@Order(value = 1)
|
||||
DatastoreEntityExtension datastoreEntityExtension = new DatastoreEntityExtension();
|
||||
|
||||
@RegisterExtension
|
||||
JpaIntegrationWithCoverageExtension jpa =
|
||||
new JpaTestRules.Builder().withClock(fakeClock).buildIntegrationWithCoverageExtension();
|
||||
|
||||
private ImmutableMap<String, ReservedListEntry> test_reservations;
|
||||
|
||||
private ReservedList test_reserved_list;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
test_reservations =
|
||||
ImmutableMap.of(
|
||||
"food",
|
||||
ReservedListEntry.create("food", ReservationType.RESERVED_FOR_SPECIFIC_USE, null),
|
||||
"music",
|
||||
ReservedListEntry.create("music", ReservationType.FULLY_BLOCKED, "fully blocked"));
|
||||
|
||||
test_reserved_list =
|
||||
new ReservedList.Builder()
|
||||
.setName("testlist")
|
||||
.setLastUpdateTime(fakeClock.nowUtc())
|
||||
.setShouldPublish(false)
|
||||
.setReservedListMap(test_reservations)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void save_worksSuccessfully() {
|
||||
ReservedListSqlDao.save(test_reserved_list);
|
||||
jpaTm()
|
||||
.transact(
|
||||
() -> {
|
||||
ReservedList persistedList =
|
||||
jpaTm()
|
||||
.getEntityManager()
|
||||
.createQuery("FROM ReservedList WHERE name = :name", ReservedList.class)
|
||||
.setParameter("name", "testlist")
|
||||
.getSingleResult();
|
||||
assertThat(persistedList.getReservedListEntries())
|
||||
.containsExactlyEntriesIn(test_reservations);
|
||||
assertThat(persistedList.getLastUpdateTime()).isEqualTo(fakeClock.nowUtc());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkExists_worksSuccessfully() {
|
||||
assertThat(ReservedListSqlDao.checkExists("testlist")).isFalse();
|
||||
ReservedListSqlDao.save(test_reserved_list);
|
||||
assertThat(ReservedListSqlDao.checkExists("testlist")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getLatestRevision_worksSuccessfully() {
|
||||
assertThat(ReservedListSqlDao.getLatestRevision("testlist").isPresent()).isFalse();
|
||||
ReservedListSqlDao.save(test_reserved_list);
|
||||
ReservedList persistedList = ReservedListSqlDao.getLatestRevision("testlist").get();
|
||||
assertThat(persistedList.getRevisionId()).isNotNull();
|
||||
assertThat(persistedList.getLastUpdateTime()).isEqualTo(fakeClock.nowUtc());
|
||||
assertThat(persistedList.getName()).isEqualTo("testlist");
|
||||
assertThat(persistedList.getShouldPublish()).isFalse();
|
||||
assertThat(persistedList.getReservedListEntries()).containsExactlyEntriesIn(test_reservations);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getLatestRevision_returnsLatestRevision() {
|
||||
ReservedListSqlDao.save(
|
||||
new ReservedList.Builder()
|
||||
.setName("testlist")
|
||||
.setLastUpdateTime(fakeClock.nowUtc())
|
||||
.setShouldPublish(false)
|
||||
.setReservedListMap(
|
||||
ImmutableMap.of(
|
||||
"old",
|
||||
ReservedListEntry.create(
|
||||
"old", ReservationType.RESERVED_FOR_SPECIFIC_USE, null)))
|
||||
.build());
|
||||
ReservedListSqlDao.save(test_reserved_list);
|
||||
ReservedList persistedList = ReservedListSqlDao.getLatestRevision("testlist").get();
|
||||
assertThat(persistedList.getRevisionId()).isNotNull();
|
||||
assertThat(persistedList.getLastUpdateTime()).isEqualTo(fakeClock.nowUtc());
|
||||
assertThat(persistedList.getName()).isEqualTo("testlist");
|
||||
assertThat(persistedList.getShouldPublish()).isFalse();
|
||||
assertThat(persistedList.getReservedListEntries()).containsExactlyEntriesIn(test_reservations);
|
||||
}
|
||||
}
|
|
@ -16,11 +16,13 @@ package google.registry.persistence;
|
|||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import google.registry.testing.DatastoreEntityExtension;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.testcontainers.containers.PostgreSQLContainer;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
|
@ -33,6 +35,9 @@ public class PersistenceModuleTest {
|
|||
private final PostgreSQLContainer database =
|
||||
new PostgreSQLContainer(NomulusPostgreSql.getDockerTag());
|
||||
|
||||
@RegisterExtension
|
||||
public DatastoreEntityExtension datastoreEntityExtension = new DatastoreEntityExtension();
|
||||
|
||||
private EntityManagerFactory emf;
|
||||
|
||||
@BeforeEach
|
||||
|
|
|
@ -23,6 +23,7 @@ import google.registry.model.history.ContactHistoryTest;
|
|||
import google.registry.model.history.HostHistoryTest;
|
||||
import google.registry.model.poll.PollMessageTest;
|
||||
import google.registry.model.registry.RegistryLockDaoTest;
|
||||
import google.registry.model.registry.label.ReservedListSqlDaoTest;
|
||||
import google.registry.model.reporting.Spec11ThreatMatchTest;
|
||||
import google.registry.persistence.transaction.JpaEntityCoverage;
|
||||
import google.registry.schema.cursor.CursorDaoTest;
|
||||
|
@ -31,7 +32,6 @@ import google.registry.schema.integration.SqlIntegrationTestSuite.BeforeSuiteTes
|
|||
import google.registry.schema.registrar.RegistrarDaoTest;
|
||||
import google.registry.schema.server.LockDaoTest;
|
||||
import google.registry.schema.tld.PremiumListDaoTest;
|
||||
import google.registry.schema.tld.ReservedListDaoTest;
|
||||
import google.registry.schema.tmch.ClaimsListDaoTest;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
|
@ -84,8 +84,8 @@ import org.junit.runner.RunWith;
|
|||
PollMessageTest.class,
|
||||
PremiumListDaoTest.class,
|
||||
RegistrarDaoTest.class,
|
||||
ReservedListSqlDaoTest.class,
|
||||
RegistryLockDaoTest.class,
|
||||
ReservedListDaoTest.class,
|
||||
Spec11ThreatMatchTest.class,
|
||||
// AfterSuiteTest must be the last entry. See class javadoc for details.
|
||||
AfterSuiteTest.class
|
||||
|
|
|
@ -20,11 +20,13 @@ import static google.registry.testing.LogsSubject.assertAboutLogs;
|
|||
import com.google.common.testing.TestLogHandler;
|
||||
import google.registry.persistence.transaction.JpaTestRules;
|
||||
import google.registry.persistence.transaction.JpaTestRules.JpaIntegrationWithCoverageExtension;
|
||||
import google.registry.testing.DatastoreEntityExtension;
|
||||
import google.registry.testing.FakeClock;
|
||||
import java.util.Optional;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.joda.time.Duration;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
|
||||
|
@ -35,6 +37,10 @@ public class LockDaoTest {
|
|||
private final TestLogHandler logHandler = new TestLogHandler();
|
||||
private final Logger loggerToIntercept = Logger.getLogger(LockDao.class.getCanonicalName());
|
||||
|
||||
@RegisterExtension
|
||||
@Order(value = 1)
|
||||
public DatastoreEntityExtension datastoreEntityExtension = new DatastoreEntityExtension();
|
||||
|
||||
@RegisterExtension
|
||||
public final JpaIntegrationWithCoverageExtension jpa =
|
||||
new JpaTestRules.Builder().withClock(fakeClock).buildIntegrationWithCoverageExtension();
|
||||
|
|
|
@ -1,110 +0,0 @@
|
|||
// Copyright 2019 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.schema.tld;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import google.registry.model.registry.label.ReservationType;
|
||||
import google.registry.persistence.transaction.JpaTestRules;
|
||||
import google.registry.persistence.transaction.JpaTestRules.JpaIntegrationWithCoverageExtension;
|
||||
import google.registry.schema.tld.ReservedList.ReservedEntry;
|
||||
import google.registry.testing.FakeClock;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
|
||||
/** Unit tests for {@link ReservedListDao}. */
|
||||
public class ReservedListDaoTest {
|
||||
|
||||
private final FakeClock fakeClock = new FakeClock();
|
||||
|
||||
@RegisterExtension
|
||||
public final JpaIntegrationWithCoverageExtension jpa =
|
||||
new JpaTestRules.Builder().withClock(fakeClock).buildIntegrationWithCoverageExtension();
|
||||
|
||||
private static final ImmutableMap<String, ReservedEntry> TEST_RESERVATIONS =
|
||||
ImmutableMap.of(
|
||||
"food",
|
||||
ReservedEntry.create(ReservationType.RESERVED_FOR_SPECIFIC_USE, null),
|
||||
"music",
|
||||
ReservedEntry.create(ReservationType.FULLY_BLOCKED, "fully blocked"));
|
||||
|
||||
@Test
|
||||
public void save_worksSuccessfully() {
|
||||
ReservedList reservedList = ReservedList.create("testname", false, TEST_RESERVATIONS);
|
||||
ReservedListDao.save(reservedList);
|
||||
jpaTm()
|
||||
.transact(
|
||||
() -> {
|
||||
ReservedList persistedList =
|
||||
jpaTm()
|
||||
.getEntityManager()
|
||||
.createQuery("FROM ReservedList WHERE name = :name", ReservedList.class)
|
||||
.setParameter("name", "testname")
|
||||
.getSingleResult();
|
||||
assertThat(persistedList.getLabelsToReservations())
|
||||
.containsExactlyEntriesIn(TEST_RESERVATIONS);
|
||||
assertThat(persistedList.getCreationTimestamp()).isEqualTo(fakeClock.nowUtc());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkExists_worksSuccessfully() {
|
||||
assertThat(ReservedListDao.checkExists("testlist")).isFalse();
|
||||
ReservedListDao.save(ReservedList.create("testlist", false, TEST_RESERVATIONS));
|
||||
assertThat(ReservedListDao.checkExists("testlist")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getLatestRevision_worksSuccessfully() {
|
||||
assertThat(ReservedListDao.getLatestRevision("testlist").isPresent()).isFalse();
|
||||
ReservedListDao.save(ReservedList.create("testlist", false, TEST_RESERVATIONS));
|
||||
ReservedList persistedList = ReservedListDao.getLatestRevision("testlist").get();
|
||||
assertThat(persistedList.getRevisionId()).isNotNull();
|
||||
assertThat(persistedList.getCreationTimestamp()).isEqualTo(fakeClock.nowUtc());
|
||||
assertThat(persistedList.getName()).isEqualTo("testlist");
|
||||
assertThat(persistedList.getShouldPublish()).isFalse();
|
||||
assertThat(persistedList.getLabelsToReservations()).containsExactlyEntriesIn(TEST_RESERVATIONS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getLatestRevision_returnsLatestRevision() {
|
||||
ReservedListDao.save(
|
||||
ReservedList.create(
|
||||
"testlist",
|
||||
false,
|
||||
ImmutableMap.of(
|
||||
"old", ReservedEntry.create(ReservationType.RESERVED_FOR_SPECIFIC_USE, null))));
|
||||
ReservedListDao.save(ReservedList.create("testlist", false, TEST_RESERVATIONS));
|
||||
ReservedList persistedList = ReservedListDao.getLatestRevision("testlist").get();
|
||||
assertThat(persistedList.getRevisionId()).isNotNull();
|
||||
assertThat(persistedList.getCreationTimestamp()).isEqualTo(fakeClock.nowUtc());
|
||||
assertThat(persistedList.getName()).isEqualTo("testlist");
|
||||
assertThat(persistedList.getShouldPublish()).isFalse();
|
||||
assertThat(persistedList.getLabelsToReservations()).containsExactlyEntriesIn(TEST_RESERVATIONS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getLatestRevisionCached_worksSuccessfully() {
|
||||
ReservedListDao.save(ReservedList.create("testlist", false, TEST_RESERVATIONS));
|
||||
ReservedList persistedList = ReservedListDao.getLatestRevisionCached("testlist").get();
|
||||
assertThat(persistedList.getRevisionId()).isNotNull();
|
||||
assertThat(persistedList.getCreationTimestamp()).isEqualTo(fakeClock.nowUtc());
|
||||
assertThat(persistedList.getName()).isEqualTo("testlist");
|
||||
assertThat(persistedList.getShouldPublish()).isFalse();
|
||||
assertThat(persistedList.getLabelsToReservations()).containsExactlyEntriesIn(TEST_RESERVATIONS);
|
||||
}
|
||||
}
|
|
@ -1,85 +0,0 @@
|
|||
// Copyright 2019 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.schema.tld;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.model.registry.label.ReservationType.FULLY_BLOCKED;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import google.registry.model.registry.label.ReservationType;
|
||||
import google.registry.schema.tld.ReservedList.ReservedEntry;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
/** Unit tests for {@link ReservedList} */
|
||||
@RunWith(JUnit4.class)
|
||||
public class ReservedListTest {
|
||||
|
||||
@Test
|
||||
public void verifyConstructorAndGetters_workCorrectly() {
|
||||
ReservedList reservedList =
|
||||
ReservedList.create(
|
||||
"app",
|
||||
false,
|
||||
ImmutableMap.of(
|
||||
"book",
|
||||
ReservedEntry.create(ReservationType.ALLOWED_IN_SUNRISE, null),
|
||||
"music",
|
||||
ReservedEntry.create(
|
||||
ReservationType.RESERVED_FOR_ANCHOR_TENANT, "reserved for anchor tenant")));
|
||||
|
||||
assertThat(reservedList.getName()).isEqualTo("app");
|
||||
assertThat(reservedList.getShouldPublish()).isFalse();
|
||||
assertThat(reservedList.getLabelsToReservations())
|
||||
.containsExactly(
|
||||
"book",
|
||||
ReservedEntry.create(ReservationType.ALLOWED_IN_SUNRISE, null),
|
||||
"music",
|
||||
ReservedEntry.create(
|
||||
ReservationType.RESERVED_FOR_ANCHOR_TENANT, "reserved for anchor tenant"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void create_throwsExceptionWhenLabelIsNotLowercase() {
|
||||
Exception e =
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
ReservedList.create(
|
||||
"UPPER.tld",
|
||||
true,
|
||||
ImmutableMap.of("UPPER", ReservedEntry.create(FULLY_BLOCKED, ""))));
|
||||
assertThat(e)
|
||||
.hasMessageThat()
|
||||
.contains("Label(s) [UPPER] must be in puny-coded, lower-case form");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void create_labelMustBePunyCoded() {
|
||||
Exception e =
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
ReservedList.create(
|
||||
"lower.みんな",
|
||||
true,
|
||||
ImmutableMap.of("みんな", ReservedEntry.create(FULLY_BLOCKED, ""))));
|
||||
assertThat(e)
|
||||
.hasMessageThat()
|
||||
.contains("Label(s) [みんな] must be in puny-coded, lower-case form");
|
||||
}
|
||||
}
|
|
@ -19,7 +19,9 @@ import static com.google.common.truth.Truth.assertThat;
|
|||
import com.google.common.collect.ImmutableMap;
|
||||
import google.registry.persistence.transaction.JpaTestRules;
|
||||
import google.registry.persistence.transaction.JpaTestRules.JpaIntegrationWithCoverageExtension;
|
||||
import google.registry.testing.DatastoreEntityExtension;
|
||||
import google.registry.testing.FakeClock;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
|
||||
|
@ -32,6 +34,10 @@ public class ClaimsListDaoTest {
|
|||
public final JpaIntegrationWithCoverageExtension jpa =
|
||||
new JpaTestRules.Builder().withClock(fakeClock).buildIntegrationWithCoverageExtension();
|
||||
|
||||
@RegisterExtension
|
||||
@Order(value = 1)
|
||||
public final DatastoreEntityExtension datastoreEntityExtension = new DatastoreEntityExtension();
|
||||
|
||||
@Test
|
||||
public void trySave_insertsClaimsListSuccessfully() {
|
||||
ClaimsList claimsList =
|
||||
|
|
|
@ -1,126 +0,0 @@
|
|||
// Copyright 2019 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.tools;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.model.registry.label.ReservationType.ALLOWED_IN_SUNRISE;
|
||||
import static google.registry.model.registry.label.ReservationType.FULLY_BLOCKED;
|
||||
import static google.registry.tools.CreateOrUpdateReservedListCommand.parseToReservationsByLabels;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import google.registry.model.registry.label.ReservationType;
|
||||
import google.registry.schema.tld.ReservedList.ReservedEntry;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
/** Unit tests for {@link CreateOrUpdateReservedListCommand}. */
|
||||
@RunWith(JUnit4.class)
|
||||
public class CreateOrUpdateReservedListCommandTest {
|
||||
|
||||
@Test
|
||||
public void parseToReservationsByLabels_worksCorrectly() {
|
||||
assertThat(
|
||||
parseToReservationsByLabels(
|
||||
ImmutableList.of(
|
||||
"reserveddomain,FULLY_BLOCKED",
|
||||
"availableinga,ALLOWED_IN_SUNRISE#allowed_in_sunrise",
|
||||
"fourletterword,FULLY_BLOCKED")))
|
||||
.containsExactly(
|
||||
"reserveddomain",
|
||||
ReservedEntry.create(ReservationType.FULLY_BLOCKED, ""),
|
||||
"availableinga",
|
||||
ReservedEntry.create(ALLOWED_IN_SUNRISE, "allowed_in_sunrise"),
|
||||
"fourletterword",
|
||||
ReservedEntry.create(FULLY_BLOCKED, ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseToReservationsByLabels_throwsExceptionForInvalidLabel() {
|
||||
Throwable thrown =
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
parseToReservationsByLabels(
|
||||
ImmutableList.of("reserveddomain,FULLY_BLOCKED", "UPPER,FULLY_BLOCKED")));
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.isEqualTo("Label 'UPPER' must be in puny-coded, lower-case form");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseToReservationsByLabels_throwsExceptionForNonPunyCodedLabel() {
|
||||
Throwable thrown =
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
parseToReservationsByLabels(
|
||||
ImmutableList.of("reserveddomain,FULLY_BLOCKED", "みんな,FULLY_BLOCKED")));
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.isEqualTo("Label 'みんな' must be in puny-coded, lower-case form");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseToReservationsByLabels_throwsExceptionForInvalidReservationType() {
|
||||
Throwable thrown =
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
parseToReservationsByLabels(
|
||||
ImmutableList.of(
|
||||
"reserveddomain,FULLY_BLOCKED", "invalidtype,INVALID_RESERVATION_TYPE")));
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.isEqualTo(
|
||||
"No enum constant"
|
||||
+ " google.registry.model.registry.label.ReservationType.INVALID_RESERVATION_TYPE");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseToReservationsByLabels_throwsExceptionForInvalidLines() {
|
||||
Throwable thrown =
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
parseToReservationsByLabels(
|
||||
ImmutableList.of(
|
||||
"reserveddomain,FULLY_BLOCKED,too,many,parts",
|
||||
"fourletterword,FULLY_BLOCKED")));
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.isEqualTo(
|
||||
"Could not parse line in reserved list: reserveddomain,FULLY_BLOCKED,too,many,parts");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseToReservationsByLabels_throwsExceptionForDuplicateEntries() {
|
||||
Throwable thrown =
|
||||
assertThrows(
|
||||
IllegalStateException.class,
|
||||
() ->
|
||||
parseToReservationsByLabels(
|
||||
ImmutableList.of(
|
||||
"reserveddomain,FULLY_BLOCKED",
|
||||
"fourletterword,FULLY_BLOCKED",
|
||||
"fourletterword,FULLY_BLOCKED")));
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.isEqualTo(
|
||||
"Reserved list cannot contain duplicate labels. Dupes (with counts) were:"
|
||||
+ " [fourletterword x 2]");
|
||||
}
|
||||
}
|
|
@ -22,15 +22,16 @@ import static java.nio.charset.StandardCharsets.UTF_8;
|
|||
import static org.junit.Assert.assertThrows;
|
||||
|
||||
import com.beust.jcommander.ParameterException;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.io.Files;
|
||||
import com.google.common.truth.Truth8;
|
||||
import google.registry.model.registry.label.ReservedList;
|
||||
import google.registry.schema.tld.ReservedList.ReservedEntry;
|
||||
import google.registry.schema.tld.ReservedListDao;
|
||||
import google.registry.model.registry.label.ReservedList.ReservedListEntry;
|
||||
import google.registry.model.registry.label.ReservedListSqlDao;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import javax.persistence.EntityManager;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -100,12 +101,20 @@ public abstract class CreateOrUpdateReservedListCommandTestCase<
|
|||
.isEqualTo("Label example.tld must not be a multi-level domain name");
|
||||
}
|
||||
|
||||
google.registry.schema.tld.ReservedList createCloudSqlReservedList(
|
||||
String name, boolean shouldPublish, Map<String, ReservedEntry> labelsToEntries) {
|
||||
return google.registry.schema.tld.ReservedList.create(name, shouldPublish, labelsToEntries);
|
||||
ReservedList createCloudSqlReservedList(
|
||||
String name,
|
||||
DateTime creationTime,
|
||||
boolean shouldPublish,
|
||||
ImmutableMap<String, ReservedListEntry> labelsToEntries) {
|
||||
return new ReservedList.Builder()
|
||||
.setName(name)
|
||||
.setLastUpdateTime(creationTime)
|
||||
.setShouldPublish(shouldPublish)
|
||||
.setReservedListMap(labelsToEntries)
|
||||
.build();
|
||||
}
|
||||
|
||||
google.registry.schema.tld.ReservedList getCloudSqlReservedList(String name) {
|
||||
ReservedList getCloudSqlReservedList(String name) {
|
||||
return jpaTm()
|
||||
.transact(
|
||||
() -> {
|
||||
|
@ -117,27 +126,25 @@ public abstract class CreateOrUpdateReservedListCommandTestCase<
|
|||
.setParameter("name", name)
|
||||
.getSingleResult();
|
||||
return em.createQuery(
|
||||
"FROM ReservedList rl LEFT JOIN FETCH rl.labelsToReservations WHERE"
|
||||
"FROM ReservedList rl LEFT JOIN FETCH rl.reservedListMap WHERE"
|
||||
+ " rl.revisionId = :revisionId",
|
||||
google.registry.schema.tld.ReservedList.class)
|
||||
ReservedList.class)
|
||||
.setParameter("revisionId", revisionId)
|
||||
.getSingleResult();
|
||||
});
|
||||
}
|
||||
|
||||
void verifyXnq9jyb4cInCloudSql() {
|
||||
assertThat(ReservedListDao.checkExists("xn--q9jyb4c_common-reserved")).isTrue();
|
||||
google.registry.schema.tld.ReservedList persistedList =
|
||||
getCloudSqlReservedList("xn--q9jyb4c_common-reserved");
|
||||
assertThat(ReservedListSqlDao.checkExists("xn--q9jyb4c_common-reserved")).isTrue();
|
||||
ReservedList persistedList = getCloudSqlReservedList("xn--q9jyb4c_common-reserved");
|
||||
assertThat(persistedList.getName()).isEqualTo("xn--q9jyb4c_common-reserved");
|
||||
assertThat(persistedList.getShouldPublish()).isTrue();
|
||||
assertThat(persistedList.getCreationTimestamp()).isEqualTo(fakeClock.nowUtc());
|
||||
assertThat(persistedList.getLabelsToReservations())
|
||||
assertThat(persistedList.getReservedListEntries())
|
||||
.containsExactly(
|
||||
"baddies",
|
||||
ReservedEntry.create(FULLY_BLOCKED, ""),
|
||||
ReservedListEntry.create("baddies", FULLY_BLOCKED, ""),
|
||||
"ford",
|
||||
ReservedEntry.create(FULLY_BLOCKED, "random comment"));
|
||||
ReservedListEntry.create("ford", FULLY_BLOCKED, "random comment"));
|
||||
}
|
||||
|
||||
void verifyXnq9jyb4cInDatastore() {
|
||||
|
|
|
@ -27,8 +27,8 @@ import static org.junit.Assert.assertThrows;
|
|||
import com.google.common.collect.ImmutableMap;
|
||||
import google.registry.model.registry.Registry;
|
||||
import google.registry.model.registry.label.ReservedList;
|
||||
import google.registry.schema.tld.ReservedList.ReservedEntry;
|
||||
import google.registry.schema.tld.ReservedListDao;
|
||||
import google.registry.model.registry.label.ReservedList.ReservedListEntry;
|
||||
import google.registry.model.registry.label.ReservedListSqlDao;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
@ -187,11 +187,13 @@ public class CreateReservedListCommandTest extends
|
|||
public void testSaveToCloudSql_noExceptionThrownWhenSaveFail() throws Exception {
|
||||
// Note that, during the dual-write phase, we want to make sure that no exception will be
|
||||
// thrown if saving reserved list to Cloud SQL fails.
|
||||
ReservedListDao.save(
|
||||
ReservedListSqlDao.save(
|
||||
createCloudSqlReservedList(
|
||||
"xn--q9jyb4c_common-reserved",
|
||||
fakeClock.nowUtc(),
|
||||
true,
|
||||
ImmutableMap.of("testdomain", ReservedEntry.create(FULLY_BLOCKED, ""))));
|
||||
ImmutableMap.of(
|
||||
"testdomain", ReservedListEntry.create("testdomain", FULLY_BLOCKED, ""))));
|
||||
runCommandForced("--name=xn--q9jyb4c_common-reserved", "--input=" + reservedTermsPath);
|
||||
verifyXnq9jyb4cInDatastore();
|
||||
}
|
||||
|
|
|
@ -24,8 +24,8 @@ import static org.junit.Assert.assertThrows;
|
|||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import google.registry.model.registry.label.ReservedList;
|
||||
import google.registry.schema.tld.ReservedList.ReservedEntry;
|
||||
import google.registry.schema.tld.ReservedListDao;
|
||||
import google.registry.model.registry.label.ReservedList.ReservedListEntry;
|
||||
import google.registry.model.registry.label.ReservedListSqlDao;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -50,11 +50,13 @@ public class UpdateReservedListCommandTest extends
|
|||
}
|
||||
|
||||
private void populateInitialReservedListInCloudSql(boolean shouldPublish) {
|
||||
ReservedListDao.save(
|
||||
ReservedListSqlDao.save(
|
||||
createCloudSqlReservedList(
|
||||
"xn--q9jyb4c_common-reserved",
|
||||
fakeClock.nowUtc(),
|
||||
shouldPublish,
|
||||
ImmutableMap.of("helicopter", ReservedEntry.create(FULLY_BLOCKED, ""))));
|
||||
ImmutableMap.of(
|
||||
"helicopter", ReservedListEntry.create("helicopter", FULLY_BLOCKED, ""))));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -131,6 +133,6 @@ public class UpdateReservedListCommandTest extends
|
|||
// Datastore when we update it.
|
||||
runCommandForced("--name=xn--q9jyb4c_common-reserved", "--input=" + reservedTermsPath);
|
||||
verifyXnq9jyb4cInDatastore();
|
||||
assertThat(ReservedListDao.checkExists("xn--q9jyb4c_common-reserved")).isTrue();
|
||||
assertThat(ReservedListSqlDao.checkExists("xn--q9jyb4c_common-reserved")).isTrue();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue