From a66ba5310b3ca2a7e21b2679abb662b2a6778da5 Mon Sep 17 00:00:00 2001 From: mcilwain Date: Fri, 18 Jan 2019 14:24:17 -0800 Subject: [PATCH] Include the premium/reserved list tests in external release This was missed in [] ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=229994119 --- .../label/GenrulePremiumListTest.java | 65 ++++++++++++++++++ .../label/GenruleReservedListTest.java | 68 +++++++++++++++++++ 2 files changed, 133 insertions(+) create mode 100644 javatests/google/registry/model/registry/label/GenrulePremiumListTest.java create mode 100644 javatests/google/registry/model/registry/label/GenruleReservedListTest.java diff --git a/javatests/google/registry/model/registry/label/GenrulePremiumListTest.java b/javatests/google/registry/model/registry/label/GenrulePremiumListTest.java new file mode 100644 index 000000000..3c44d5c58 --- /dev/null +++ b/javatests/google/registry/model/registry/label/GenrulePremiumListTest.java @@ -0,0 +1,65 @@ +// Copyright 2017 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.assertWithMessage; +import static java.nio.charset.StandardCharsets.UTF_8; + +import com.google.common.flogger.FluentLogger; +import com.google.common.io.Resources; +import com.google.common.reflect.ClassPath; +import com.google.common.reflect.ClassPath.ResourceInfo; +import google.registry.testing.AppEngineRule; +import java.net.URL; +import java.util.List; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** Presubmit tests for {@link PremiumList} configuration files. */ +@RunWith(JUnit4.class) +public class GenrulePremiumListTest { + + private static final FluentLogger logger = FluentLogger.forEnclosingClass(); + private static final String LISTS_DIRECTORY = "google/registry/config/files/premium/"; + + @Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build(); + + @Test + public void testParse_allPremiumLists() throws Exception { + ClassPath classpath = ClassPath.from(getClass().getClassLoader()); + int numParsed = 0; + for (ResourceInfo resource : classpath.getResources()) { + if (resource.getResourceName().startsWith(LISTS_DIRECTORY) + && resource.getResourceName().endsWith(".txt")) { + testParseOfPremiumListFile(resource.getResourceName()); + numParsed++; + } + } + assertWithMessage("No premium lists found").that(numParsed).isAtLeast(1); + } + + private static void testParseOfPremiumListFile(String path) { + try { + URL url = Resources.getResource(path); + List lines = Resources.readLines(url, UTF_8); + new PremiumList.Builder().setName("premium-list").build().parse(lines); + } catch (Exception e) { + throw new AssertionError("Error in premium list " + path, e); + } + logger.atInfo().log("Premium list '%s' parsed successfully.", path); + } +} diff --git a/javatests/google/registry/model/registry/label/GenruleReservedListTest.java b/javatests/google/registry/model/registry/label/GenruleReservedListTest.java new file mode 100644 index 000000000..306deacd7 --- /dev/null +++ b/javatests/google/registry/model/registry/label/GenruleReservedListTest.java @@ -0,0 +1,68 @@ +// Copyright 2017 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.assertWithMessage; +import static java.nio.charset.StandardCharsets.UTF_8; + +import com.google.common.flogger.FluentLogger; +import com.google.common.io.Resources; +import com.google.common.reflect.ClassPath; +import com.google.common.reflect.ClassPath.ResourceInfo; +import google.registry.testing.AppEngineRule; +import java.net.URL; +import java.util.List; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** Presubmit tests for {@link ReservedList} configuration files. */ +@RunWith(JUnit4.class) +public class GenruleReservedListTest { + + private static final FluentLogger logger = FluentLogger.forEnclosingClass(); + private static final String LISTS_DIRECTORY = "google/registry/config/files/reserved/"; + + @Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build(); + + @Test + public void testParse_allReservedLists() throws Exception { + ClassPath classpath = ClassPath.from(getClass().getClassLoader()); + int numParsed = 0; + for (ResourceInfo resource : classpath.getResources()) { + if (resource.getResourceName().startsWith(LISTS_DIRECTORY) + && resource.getResourceName().endsWith(".txt")) { + testParseOfReservedListFile(resource.getResourceName()); + numParsed++; + } + } + assertWithMessage("No reserved lists found").that(numParsed).isAtLeast(1); + } + + private static void testParseOfReservedListFile(String path) { + try { + URL url = Resources.getResource(path); + List lines = Resources.readLines(url, UTF_8); + new ReservedList.Builder() + .setName("reserved-list") + .setReservedListMapFromLines(lines) + .build(); + } catch (Exception e) { + throw new AssertionError("Error in reserved list " + path, e); + } + logger.atInfo().log("Reserved list '%s' parsed successfully.", path); + } +}