mirror of
https://github.com/google/nomulus.git
synced 2025-08-04 17:01:51 +02:00
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:
parent
a41677aea1
commit
5012893c1d
2396 changed files with 0 additions and 0 deletions
|
@ -0,0 +1,59 @@
|
|||
// 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.model.common;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.domain.registry.model.ofy.ObjectifyService.ofy;
|
||||
|
||||
import com.google.domain.registry.testing.AppEngineRule;
|
||||
|
||||
import com.googlecode.objectify.VoidWork;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
/** Unit tests for {@link GaeUserIdConverter}. */
|
||||
@RunWith(JUnit4.class)
|
||||
public class GaeUserIdConverterTest {
|
||||
|
||||
@Rule
|
||||
public final AppEngineRule appEngine = AppEngineRule.builder()
|
||||
.withDatastore()
|
||||
.build();
|
||||
|
||||
@After
|
||||
public void verifyNoLingeringEntities() {
|
||||
assertThat(ofy().load().type(GaeUserIdConverter.class).count()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess() {
|
||||
assertThat(GaeUserIdConverter.convertEmailAddressToGaeUserId("example@example.com"))
|
||||
.matches("[0-9]+");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_inTransaction() {
|
||||
ofy().transactNew(new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
assertThat(GaeUserIdConverter.convertEmailAddressToGaeUserId("example@example.com"))
|
||||
.matches("[0-9]+");
|
||||
}});
|
||||
}
|
||||
}
|
|
@ -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.model.common;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import com.google.common.collect.Range;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
/** Unit tests for {@link PersistedRangeLong}. */
|
||||
@RunWith(JUnit4.class)
|
||||
public class PersistedRangeLongTest {
|
||||
|
||||
private void doConversionTest(Range<Long> range) {
|
||||
assertThat(PersistedRangeLong.create(range).asRange()).isEqualTo(range);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void all() {
|
||||
doConversionTest(Range.<Long>all());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lessThan() {
|
||||
doConversionTest(Range.<Long>lessThan(10L));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void atMost() {
|
||||
doConversionTest(Range.<Long>atMost(10L));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void greaterThan() {
|
||||
doConversionTest(Range.<Long>greaterThan(10L));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void atLeast() {
|
||||
doConversionTest(Range.<Long>atLeast(10L));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void open() {
|
||||
doConversionTest(Range.<Long>open(5L, 10L));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void closed() {
|
||||
doConversionTest(Range.<Long>closed(5L, 10L));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void openClosed() {
|
||||
doConversionTest(Range.<Long>openClosed(5L, 10L));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void closedOpen() {
|
||||
doConversionTest(Range.<Long>closedOpen(5L, 10L));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void singleton() {
|
||||
doConversionTest(Range.<Long>singleton(5L));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void openClosedEmpty() {
|
||||
doConversionTest(Range.<Long>openClosed(5L, 5L));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void closedOpenEmpty() {
|
||||
doConversionTest(Range.<Long>closedOpen(5L, 5L));
|
||||
}
|
||||
}
|
56
javatests/google/registry/model/common/TimeOfYearTest.java
Normal file
56
javatests/google/registry/model/common/TimeOfYearTest.java
Normal file
|
@ -0,0 +1,56 @@
|
|||
// 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.model.common;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
/** Unit tests for {@link TimeOfYear}. */
|
||||
@RunWith(JUnit4.class)
|
||||
public class TimeOfYearTest {
|
||||
|
||||
private static final DateTime february28 = DateTime.parse("2012-02-28T01:02:03.0Z");
|
||||
private static final DateTime february29 = DateTime.parse("2012-02-29T01:02:03.0Z");
|
||||
private static final DateTime march1 = DateTime.parse("2012-03-01T01:02:03.0Z");
|
||||
|
||||
@Test
|
||||
public void testFromDateTime() throws Exception {
|
||||
// We intentionally don't allow leap years in TimeOfYear, so February 29 should be February 28.
|
||||
assertThat(TimeOfYear.fromDateTime(february28)).isEqualTo(TimeOfYear.fromDateTime(february29));
|
||||
assertThat(TimeOfYear.fromDateTime(february29)).isNotEqualTo(TimeOfYear.fromDateTime(march1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNextAfter() throws Exception {
|
||||
// This should be lossless because atOrAfter includes an exact match.
|
||||
assertThat(TimeOfYear.fromDateTime(march1).atOrAfter(march1)).isEqualTo(march1);
|
||||
// This should be a year later because we stepped forward a millisecond
|
||||
assertThat(TimeOfYear.fromDateTime(march1).atOrAfter(march1.plusMillis(1)))
|
||||
.isEqualTo(march1.plusYears(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNextBefore() throws Exception {
|
||||
// This should be lossless because beforeOrAt includes an exact match.
|
||||
assertThat(TimeOfYear.fromDateTime(march1).beforeOrAt(march1)).isEqualTo(march1);
|
||||
// This should be a year earlier because we stepped backward a millisecond
|
||||
assertThat(TimeOfYear.fromDateTime(march1).beforeOrAt(march1.minusMillis(1)))
|
||||
.isEqualTo(march1.minusYears(1));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,174 @@
|
|||
// 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.model.common;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.domain.registry.util.DateTimeUtils.END_OF_TIME;
|
||||
import static com.google.domain.registry.util.DateTimeUtils.START_OF_TIME;
|
||||
import static org.joda.time.DateTimeZone.UTC;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.collect.ImmutableSortedMap;
|
||||
import com.google.domain.registry.testing.ExceptionRule;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/** Unit tests for {@link TimedTransitionProperty}. */
|
||||
@RunWith(JUnit4.class)
|
||||
public class TimedTransitionPropertyTest {
|
||||
|
||||
@Rule
|
||||
public final ExceptionRule thrown = new ExceptionRule();
|
||||
|
||||
private static final DateTime A_LONG_TIME_AGO = new DateTime(Long.MIN_VALUE, UTC);
|
||||
|
||||
private static final DateTime DATE_1 = DateTime.parse("2001-01-01T00:00:00.0Z");
|
||||
private static final DateTime DATE_2 = DateTime.parse("2002-01-01T00:00:00.0Z");
|
||||
private static final DateTime DATE_3 = DateTime.parse("2003-01-01T00:00:00.0Z");
|
||||
|
||||
// Simple implementation of TimedTransition for testing. Public so it can be instantiated via
|
||||
// reflection.
|
||||
@VisibleForTesting
|
||||
public static class StringTimedTransition
|
||||
extends TimedTransitionProperty.TimedTransition<String> {
|
||||
private String value;
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
private static final ImmutableSortedMap<DateTime, String> values = ImmutableSortedMap.of(
|
||||
START_OF_TIME, "0",
|
||||
DATE_1, "1",
|
||||
DATE_2, "2",
|
||||
DATE_3, "3");
|
||||
|
||||
TimedTransitionProperty<String, StringTimedTransition> timedString;
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
timedString = TimedTransitionProperty.fromValueMap(values, StringTimedTransition.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_toValueMap() throws Exception {
|
||||
assertThat(timedString.toValueMap()).isEqualTo(values);
|
||||
}
|
||||
|
||||
private static void testGetValueAtTime(
|
||||
TimedTransitionProperty<String, StringTimedTransition> timedString) throws Exception {
|
||||
assertThat(timedString.getValueAtTime(A_LONG_TIME_AGO)).isEqualTo("0");
|
||||
assertThat(timedString.getValueAtTime(START_OF_TIME.minusMillis(1))).isEqualTo("0");
|
||||
assertThat(timedString.getValueAtTime(START_OF_TIME)).isEqualTo("0");
|
||||
assertThat(timedString.getValueAtTime(DATE_1.minusMillis(1))).isEqualTo("0");
|
||||
assertThat(timedString.getValueAtTime(DATE_1)).isEqualTo("1");
|
||||
assertThat(timedString.getValueAtTime(DATE_1.plusMillis(1))).isEqualTo("1");
|
||||
assertThat(timedString.getValueAtTime(DATE_2.minusMillis(1))).isEqualTo("1");
|
||||
assertThat(timedString.getValueAtTime(DATE_2)).isEqualTo("2");
|
||||
assertThat(timedString.getValueAtTime(DATE_2.plusMillis(1))).isEqualTo("2");
|
||||
assertThat(timedString.getValueAtTime(DATE_3.minusMillis(1))).isEqualTo("2");
|
||||
assertThat(timedString.getValueAtTime(DATE_3)).isEqualTo("3");
|
||||
assertThat(timedString.getValueAtTime(DATE_3.plusMillis(1))).isEqualTo("3");
|
||||
assertThat(timedString.getValueAtTime(END_OF_TIME)).isEqualTo("3");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_getValueAtTime() throws Exception {
|
||||
testGetValueAtTime(timedString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_simulatedLoad() throws Exception {
|
||||
// Just for testing, don't extract transitions from a TimedTransitionProperty in real code.
|
||||
Set<Map.Entry<DateTime, StringTimedTransition>> transitions = timedString.entrySet();
|
||||
timedString = TimedTransitionProperty.forMapify(
|
||||
ImmutableSortedMap.of(START_OF_TIME, "0"), StringTimedTransition.class);
|
||||
// Simulate a load from datastore by clearing and then re-inserting the original transitions.
|
||||
timedString.clear();
|
||||
for (Map.Entry<DateTime, StringTimedTransition> transition : transitions) {
|
||||
timedString.put(transition.getKey(), transition.getValue());
|
||||
}
|
||||
timedString.checkValidity();
|
||||
testGetValueAtTime(timedString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_valueMapNotChronologicallyOrdered() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
TimedTransitionProperty.fromValueMap(
|
||||
ImmutableSortedMap.<DateTime, String>reverseOrder().put(START_OF_TIME, "0").build(),
|
||||
StringTimedTransition.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_transitionTimeBeforeStartOfTime() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
TimedTransitionProperty.fromValueMap(
|
||||
ImmutableSortedMap.of(A_LONG_TIME_AGO, "?"), StringTimedTransition.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_noValues() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
TimedTransitionProperty.fromValueMap(
|
||||
ImmutableSortedMap.<DateTime, String>of(), StringTimedTransition.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_noValueAtStartOfTime() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
TimedTransitionProperty.fromValueMap(
|
||||
ImmutableSortedMap.of(DATE_1, "1"), StringTimedTransition.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_noValuesAfterSimulatedEmptyLoad() throws Exception {
|
||||
thrown.expect(IllegalStateException.class);
|
||||
timedString = TimedTransitionProperty.forMapify(
|
||||
ImmutableSortedMap.of(START_OF_TIME, "0"), StringTimedTransition.class);
|
||||
// Simulate a load from datastore by clearing, but don't insert any transitions.
|
||||
timedString.clear();
|
||||
timedString.checkValidity();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_noValueAtStartOfTimeAfterSimulatedLoad() throws Exception {
|
||||
thrown.expect(IllegalStateException.class);
|
||||
// Just for testing, don't extract transitions from a TimedTransitionProperty in real code.
|
||||
StringTimedTransition transition1 = timedString.get(DATE_1);
|
||||
timedString = TimedTransitionProperty.forMapify(
|
||||
ImmutableSortedMap.of(START_OF_TIME, "0"), StringTimedTransition.class);
|
||||
// Simulate a load from datastore by clearing and inserting transitions, but deliberately
|
||||
// omit a transition corresponding to START_OF_TIME.
|
||||
timedString.clear();
|
||||
timedString.put(DATE_1, transition1);
|
||||
timedString.checkValidity();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue