mv com/google/domain/registry google/registry

This change renames directories in preparation for the great package
rename. The repository is now in a broken state because the code
itself hasn't been updated. However this should ensure that git
correctly preserves history for each file.
This commit is contained in:
Justine Tunney 2016-05-13 18:55:08 -04:00
parent a41677aea1
commit 5012893c1d
2396 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,28 @@
package(
default_visibility = ["//java/com/google/domain/registry:registry_project"],
)
java_library(
name = "params",
srcs = glob(["*.java"]),
deps = [
"//java/com/google/common/base",
"//java/com/google/domain/registry/tools/params",
"//javatests/com/google/domain/registry/testing",
"//third_party/java/hamcrest",
"//third_party/java/jcommander",
"//third_party/java/joda_money",
"//third_party/java/joda_time",
"//third_party/java/junit",
"//third_party/java/truth",
],
)
load("//java/com/google/testing/builddefs:GenTestRules.bzl", "GenTestRules")
GenTestRules(
name = "GeneratedTestRules",
test_files = glob(["*Test.java"]),
deps = [":params"],
)

View file

@ -0,0 +1,133 @@
// Copyright 2016 The Domain Registry 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 com.google.domain.registry.tools.params;
import static com.google.common.truth.Truth.assertThat;
import static org.joda.time.DateTimeZone.UTC;
import com.google.domain.registry.testing.ExceptionRule;
import com.beust.jcommander.ParameterException;
import org.joda.time.DateTime;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/** Unit tests for {@link DateTimeParameter}. */
@RunWith(JUnit4.class)
public class DateTimeParameterTest {
@Rule
public final ExceptionRule thrown = new ExceptionRule();
private final DateTimeParameter instance = new DateTimeParameter();
@Test
public void testConvert_numeric_returnsMillisFromEpochUtc() throws Exception {
assertThat(instance.convert("1234")).isEqualTo(new DateTime(1234L, UTC));
}
@Test
public void testConvert_iso8601_returnsSameAsDateTimeParse() throws Exception {
String exampleDate = "2014-01-01T01:02:03.004Z";
assertThat(instance.convert(exampleDate))
.isEqualTo(DateTime.parse(exampleDate));
}
@Test
public void testConvert_isoDateTimeWithMillis_returnsSameAsDateTimeParse() throws Exception {
String exampleDate = "2014-01-01T01:02:03.004Z";
assertThat(instance.convert(exampleDate)).isEqualTo(DateTime.parse(exampleDate));
}
@Test
public void testConvert_weirdTimezone_convertsToUtc() throws Exception {
assertThat(instance.convert("1984-12-18T00:00:00-0520"))
.isEqualTo(DateTime.parse("1984-12-18T05:20:00Z"));
}
@Test
public void testConvert_null_throwsException() throws Exception {
thrown.expect(NullPointerException.class);
instance.convert(null);
}
@Test
public void testConvert_empty_throwsException() throws Exception {
thrown.expect(IllegalArgumentException.class);
instance.convert("");
}
@Test
public void testConvert_sillyString_throwsException() throws Exception {
thrown.expect(IllegalArgumentException.class);
instance.convert("foo");
}
@Test
public void testConvert_partialDate_throwsException() throws Exception {
thrown.expect(IllegalArgumentException.class);
instance.convert("2014-01");
}
@Test
public void testConvert_onlyDate_throwsException() throws Exception {
thrown.expect(IllegalArgumentException.class);
instance.convert("2014-01-01");
}
@Test
public void testConvert_partialTime_throwsException() throws Exception {
thrown.expect(IllegalArgumentException.class);
instance.convert("T01:02");
}
@Test
public void testConvert_onlyTime_throwsException() throws Exception {
thrown.expect(IllegalArgumentException.class);
instance.convert("T01:02:03");
}
@Test
public void testConvert_partialDateAndPartialTime_throwsException() throws Exception {
thrown.expect(IllegalArgumentException.class);
instance.convert("9T9");
}
@Test
public void testConvert_dateAndPartialTime_throwsException() throws Exception {
thrown.expect(IllegalArgumentException.class);
instance.convert("2014-01-01T01:02");
}
@Test
public void testConvert_noTimeZone_throwsException() throws Exception {
thrown.expect(IllegalArgumentException.class);
instance.convert("2014-01-01T01:02:03");
}
@Test
public void testValidate_sillyString_throwsParameterException() throws Exception {
thrown.expect(ParameterException.class, "--time=foo not an ISO");
instance.validate("--time", "foo");
}
@Test
public void testValidate_correctInput_doesntThrow() throws Exception {
instance.validate("--time", "123");
}
}

View file

@ -0,0 +1,101 @@
// Copyright 2016 The Domain Registry 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 com.google.domain.registry.tools.params;
import static com.google.common.truth.Truth.assertThat;
import com.google.domain.registry.testing.ExceptionRule;
import com.beust.jcommander.ParameterException;
import org.joda.time.Duration;
import org.joda.time.Period;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/** Unit tests for {@link DurationParameter}. */
@RunWith(JUnit4.class)
public class DurationParameterTest {
@Rule
public final ExceptionRule thrown = new ExceptionRule();
private final DurationParameter instance = new DurationParameter();
@Test
public void testConvert_isoHours() throws Exception {
assertThat(instance.convert("PT36H")).isEqualTo(Duration.standardHours(36));
}
@Test
public void testConvert_isoDaysAndHours() throws Exception {
assertThat(instance.convert("P1DT12H")).isEqualTo(Duration.standardHours(36));
}
@Test
public void testConvert_isoLowercase_isAllowed() throws Exception {
assertThat(instance.convert("pt36h")).isEqualTo(Duration.standardHours(36));
}
@Test
public void demonstrateThat_isoMissingP_notAllowed() throws Exception {
thrown.expect(IllegalArgumentException.class);
Period.parse("T36H");
}
@Test
public void demonstrateThat_isoMissingPT_notAllowed() throws Exception {
thrown.expect(IllegalArgumentException.class);
Period.parse("36H");
}
@Test
public void testConvert_isoMissingP_notAllowed() throws Exception {
thrown.expect(IllegalArgumentException.class);
instance.convert("T36H");
}
@Test
public void testConvert_null_throws() throws Exception {
thrown.expect(NullPointerException.class);
instance.convert(null);
}
@Test
public void testConvert_empty_throws() throws Exception {
thrown.expect(IllegalArgumentException.class);
instance.convert("");
}
@Test
public void testConvert_numeric_throws() throws Exception {
thrown.expect(IllegalArgumentException.class);
instance.convert("1234");
}
@Test
public void testConvert_sillyString_throws() throws Exception {
thrown.expect(IllegalArgumentException.class);
instance.convert("foo");
}
@Test
public void testValidate_sillyString_throws() throws Exception {
thrown.expect(ParameterException.class, "--time=foo not an");
instance.validate("--time", "foo");
}
}

View file

@ -0,0 +1,52 @@
// Copyright 2016 The Domain Registry 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 com.google.domain.registry.tools.params;
import static com.google.common.truth.Truth.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/** Unit tests for {@link HostAndPortParameter}. */
@RunWith(JUnit4.class)
public class HostAndPortParameterTest {
private final HostAndPortParameter instance = new HostAndPortParameter();
@Test
public void testConvert_hostOnly() throws Exception {
assertThat(instance.convert("foo.bar").getHostText()).isEqualTo("foo.bar");
assertThat(instance.convert("foo.bar").getPortOrDefault(31337)).isEqualTo(31337);
}
@Test
public void testConvert_hostAndPort() throws Exception {
assertThat(instance.convert("foo.bar:1234").getHostText()).isEqualTo("foo.bar");
assertThat(instance.convert("foo.bar:1234").getPortOrDefault(31337)).isEqualTo(1234);
}
@Test
public void testConvert_ipv6_hostOnly() throws Exception {
assertThat(instance.convert("[feed:a:bee]").getHostText()).isEqualTo("feed:a:bee");
assertThat(instance.convert("[feed:a:bee]").getPortOrDefault(31337)).isEqualTo(31337);
}
@Test
public void testConvert_ipv6_hostAndPort() throws Exception {
assertThat(instance.convert("[feed:a:bee]:1234").getHostText()).isEqualTo("feed:a:bee");
assertThat(instance.convert("[feed:a:bee]:1234").getPortOrDefault(31337)).isEqualTo(1234);
}
}

View file

@ -0,0 +1,92 @@
// Copyright 2016 The Domain Registry 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 com.google.domain.registry.tools.params;
import static com.google.common.truth.Truth.assertThat;
import com.google.domain.registry.testing.ExceptionRule;
import com.beust.jcommander.ParameterException;
import org.joda.money.Money;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/** Unit tests for {@link MoneyParameter}. */
@RunWith(JUnit4.class)
public class MoneyParameterTest {
@Rule
public final ExceptionRule thrown = new ExceptionRule();
private final MoneyParameter instance = new MoneyParameter();
@Test
public void testConvert_withCurrency() throws Exception {
assertThat(instance.convert("USD 777.99")).isEqualTo(Money.parse("USD 777.99"));
}
@Test
public void testConvert_negative() throws Exception {
assertThat(instance.convert("USD -777.99")).isEqualTo(Money.parse("USD -777.99"));
}
@Test
public void testConvert_missingSpace_isForgiving() throws Exception {
assertThat(instance.convert("USD777.99")).isEqualTo(Money.parse("USD 777.99"));
}
@Test
public void testConvert_lowercase_isForgiving() throws Exception {
assertThat(instance.convert("usd777.99")).isEqualTo(Money.parse("USD 777.99"));
}
@Test
public void testConvert_badCurrency_throws() throws Exception {
thrown.expect(IllegalArgumentException.class);
instance.convert("FOO 1337");
}
@Test
public void testConvert_null_throws() throws Exception {
thrown.expect(NullPointerException.class);
instance.convert(null);
}
@Test
public void testConvert_empty_throws() throws Exception {
thrown.expect(IllegalArgumentException.class);
instance.convert("");
}
@Test
public void testConvert_sillyString_throws() throws Exception {
thrown.expect(IllegalArgumentException.class);
instance.convert("foo");
}
@Test
public void testValidate_sillyString_throws() throws Exception {
thrown.expect(ParameterException.class, "--money=foo not valid");
instance.validate("--money", "foo");
}
@Test
public void testValidate_correctInput() throws Exception {
instance.validate("--money", "USD 777");
}
}

View file

@ -0,0 +1,172 @@
// Copyright 2016 The Domain Registry 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 com.google.domain.registry.tools.params;
import static com.google.common.truth.Truth.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assume.assumeThat;
import static org.junit.Assume.assumeTrue;
import com.google.domain.registry.testing.ExceptionRule;
import com.beust.jcommander.ParameterException;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import java.io.File;
import java.nio.file.FileSystemNotFoundException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.PosixFilePermissions;
/** Unit tests for {@link PathParameter}. */
@RunWith(JUnit4.class)
public class PathParameterTest {
@Rule
public final ExceptionRule thrown = new ExceptionRule();
@Rule
public final TemporaryFolder folder = new TemporaryFolder();
// ================================ Test Convert ==============================================
private final PathParameter vanilla = new PathParameter();
@Test
public void testConvert_etcPasswd_returnsPath() throws Exception {
assertThat((Object) vanilla.convert("/etc/passwd")).isEqualTo(Paths.get("/etc/passwd"));
}
@Test
public void testConvert_null_throws() throws Exception {
thrown.expect(NullPointerException.class);
vanilla.convert(null);
}
@Test
public void testConvert_empty_throws() throws Exception {
thrown.expect(IllegalArgumentException.class);
vanilla.convert("");
}
@Test
public void testConvert_relativePath_returnsOriginalFile() throws Exception {
Path currentDirectory = Paths.get("").toAbsolutePath();
Path file = Paths.get(folder.newFile().toString());
Path relative = file.relativize(currentDirectory);
assumeThat(relative, is(not(equalTo(file))));
assumeThat(relative.toString(), startsWith("../"));
Path converted = vanilla.convert(file.toString());
assertThat((Object) converted).isEqualTo(file);
}
@Test
public void testConvert_extraSlash_returnsWithoutSlash() throws Exception {
Path file = Paths.get(folder.newFile().toString());
assertThat((Object) vanilla.convert(file + "/")).isEqualTo(file);
}
@Test
public void testConvert_uriNotProvided() throws Exception {
thrown.expect(FileSystemNotFoundException.class);
vanilla.convert("bog://bucket/lolcat");
}
// =========================== Test InputFile Validate ========================================
private final PathParameter inputFile = new PathParameter.InputFile();
@Test
public void testInputFileValidate_normalFile_works() throws Exception {
inputFile.validate("input", folder.newFile().toString());
}
@Test
public void testInputFileValidate_missingFile_throws() throws Exception {
thrown.expect(ParameterException.class, "not found");
inputFile.validate("input", new File(folder.getRoot(), "foo").toString());
}
@Test
public void testInputFileValidate_directory_throws() throws Exception {
thrown.expect(ParameterException.class, "is a directory");
inputFile.validate("input", folder.getRoot().toString());
}
@Test
public void testInputFileValidate_unreadableFile_throws() throws Exception {
Path file = Paths.get(folder.newFile().toString());
Files.setPosixFilePermissions(file, PosixFilePermissions.fromString("-w-------"));
thrown.expect(ParameterException.class, "not readable");
inputFile.validate("input", file.toString());
}
// =========================== Test OutputFile Validate ========================================
private final PathParameter outputFile = new PathParameter.OutputFile();
@Test
public void testOutputFileValidate_normalFile_works() throws Exception {
outputFile.validate("input", folder.newFile().toString());
}
@Test
public void testInputFileValidate_characterDeviceBehindSymbolicLinks_works() throws Exception {
assumeTrue(Files.exists(Paths.get("/dev/stdin")));
outputFile.validate("input", "/dev/stdin");
}
@Test
public void testOutputFileValidate_missingFile_works() throws Exception {
outputFile.validate("input", new File(folder.getRoot(), "foo").toString());
}
@Test
public void testOutputFileValidate_directory_throws() throws Exception {
thrown.expect(ParameterException.class, "is a directory");
outputFile.validate("input", folder.getRoot().toString());
}
@Test
public void testOutputFileValidate_notWritable_throws() throws Exception {
Path file = Paths.get(folder.newFile().toString());
Files.setPosixFilePermissions(file, PosixFilePermissions.fromString("r--------"));
thrown.expect(ParameterException.class, "not writable");
outputFile.validate("input", file.toString());
}
@Test
public void testOutputFileValidate_parentDirMissing_throws() throws Exception {
Path file = Paths.get(folder.getRoot().toString(), "MISSINGNO", "foo.txt");
thrown.expect(ParameterException.class, "parent dir doesn't exist");
outputFile.validate("input", file.toString());
}
@Test
public void testOutputFileValidate_parentDirIsFile_throws() throws Exception {
Path file = Paths.get(folder.newFile().toString(), "foo.txt");
thrown.expect(ParameterException.class, "parent is non-directory");
outputFile.validate("input", file.toString());
}
}

View file

@ -0,0 +1,55 @@
// Copyright 2016 The Domain Registry 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 com.google.domain.registry.tools.params;
import static com.google.common.truth.Truth.assertThat;
import com.google.domain.registry.testing.ExceptionRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/** Unit tests for {@link PhoneNumberParameter}. */
@RunWith(JUnit4.class)
public class PhoneNumberParameterTest {
@Rule
public final ExceptionRule thrown = new ExceptionRule();
private final OptionalPhoneNumberParameter instance = new OptionalPhoneNumberParameter();
@Test
public void testConvert_e164() throws Exception {
assertThat(instance.convert("+1.2125550777")).hasValue("+1.2125550777");
}
@Test
public void testConvert_sillyString_throws() throws Exception {
thrown.expect(IllegalArgumentException.class);
instance.convert("foo");
}
@Test
public void testConvert_empty_returnsAbsent() throws Exception {
assertThat(instance.convert("")).isAbsent();
}
@Test
public void testConvert_nullString_returnsAbsent() throws Exception {
assertThat(instance.convert("null")).isAbsent();
}
}

View file

@ -0,0 +1,83 @@
// Copyright 2016 The Domain Registry 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 com.google.domain.registry.tools.params;
import static com.google.common.truth.Truth.assertThat;
import com.google.domain.registry.testing.ExceptionRule;
import com.beust.jcommander.ParameterException;
import org.joda.time.YearMonth;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/** Unit tests for {@link YearMonthParameter}. */
@RunWith(JUnit4.class)
public class YearMonthParameterTest {
@Rule
public final ExceptionRule thrown = new ExceptionRule();
private final YearMonthParameter instance = new YearMonthParameter();
@Test
public void testConvert_awfulMonth() throws Exception {
assertThat(instance.convert("1984-12")).isEqualTo(new YearMonth(1984, 12));
}
@Test
public void testConvert_null_throwsException() throws Exception {
thrown.expect(NullPointerException.class);
instance.convert(null);
}
@Test
public void testConvert_empty_throwsException() throws Exception {
thrown.expect(IllegalArgumentException.class);
instance.convert("");
}
@Test
public void testConvert_sillyString_throwsException() throws Exception {
thrown.expect(IllegalArgumentException.class);
instance.convert("foo");
}
@Test
public void testConvert_wrongOrder() throws Exception {
thrown.expect(IllegalArgumentException.class);
instance.convert("12-1984");
}
@Test
public void testConvert_noHyphen() throws Exception {
thrown.expect(IllegalArgumentException.class);
instance.convert("198412");
}
@Test
public void testValidate_sillyString_throwsParameterException() throws Exception {
thrown.expect(ParameterException.class, "--time=foo not a valid");
instance.validate("--time", "foo");
}
@Test
public void testValidate_correctInput_doesntThrow() throws Exception {
instance.validate("--time", "1984-12");
}
}