Upgrade command test classes from JUnit 4 to JUnit 5 (#700)

* Convert first batch of command tests to JUnit 5

* Upgrade rest of command tests to JUnit 5

* Migrate the last few test classes
This commit is contained in:
Ben McIlwain 2020-07-20 20:45:52 -04:00 committed by GitHub
parent b721533759
commit 9edb43f3e4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
108 changed files with 1626 additions and 1669 deletions

View file

@ -29,7 +29,7 @@ import static google.registry.testing.DatastoreHelper.persistResource;
import static org.junit.Assert.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
import com.google.common.base.VerifyException;
@ -141,7 +141,7 @@ public class DnsUpdateWriterTest {
writer.publishDomain("example1.tld");
writer.publishDomain("example2.tld");
verifyZeroInteractions(mockResolver);
verifyNoInteractions(mockResolver);
}
@Test

View file

@ -31,8 +31,8 @@ import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
import com.google.common.collect.ImmutableList;
@ -132,7 +132,7 @@ public class ExportPremiumTermsActionTest {
persistResource(Registry.get("tld").asBuilder().setPremiumList(null).build());
runAction("tld");
verifyZeroInteractions(driveConnection);
verifyNoInteractions(driveConnection);
verify(response).setStatus(SC_OK);
verify(response).setPayload("No premium lists configured");
verify(response).setContentType(PLAIN_TEXT_UTF_8);
@ -144,7 +144,7 @@ public class ExportPremiumTermsActionTest {
persistResource(Registry.get("tld").asBuilder().setDriveFolderId(null).build());
runAction("tld");
verifyZeroInteractions(driveConnection);
verifyNoInteractions(driveConnection);
verify(response).setStatus(SC_OK);
verify(response)
.setPayload("Skipping export because no Drive folder is associated with this TLD");
@ -157,7 +157,7 @@ public class ExportPremiumTermsActionTest {
deleteTld("tld");
assertThrows(RuntimeException.class, () -> runAction("tld"));
verifyZeroInteractions(driveConnection);
verifyNoInteractions(driveConnection);
verify(response).setStatus(SC_INTERNAL_SERVER_ERROR);
verify(response).setPayload(anyString());
verify(response).setContentType(PLAIN_TEXT_UTF_8);
@ -169,7 +169,7 @@ public class ExportPremiumTermsActionTest {
deletePremiumList(new PremiumList.Builder().setName("pl-name").build());
assertThrows(RuntimeException.class, () -> runAction("tld"));
verifyZeroInteractions(driveConnection);
verifyNoInteractions(driveConnection);
verify(response).setStatus(SC_INTERNAL_SERVER_ERROR);
verify(response).setPayload("Could not load premium list for " + "tld");
verify(response).setContentType(PLAIN_TEXT_UTF_8);

View file

@ -18,7 +18,7 @@ import static com.google.common.collect.Lists.newArrayList;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
import com.google.api.services.sheets.v4.Sheets;
@ -91,9 +91,9 @@ public class SheetSynchronizerTest {
public void testSynchronize_dataAndSheetEmpty_doNothing() throws Exception {
existingSheet.add(createRow("a", "b"));
sheetSynchronizer.synchronize("aSheetId", data);
verifyZeroInteractions(appendReq);
verifyZeroInteractions(clearReq);
verifyZeroInteractions(updateReq);
verifyNoInteractions(appendReq);
verifyNoInteractions(clearReq);
verifyNoInteractions(updateReq);
}
@Test
@ -103,8 +103,8 @@ public class SheetSynchronizerTest {
data = ImmutableList.of(ImmutableMap.of("a", "val1", "b", "val2"));
sheetSynchronizer.synchronize("aSheetId", data);
verifyZeroInteractions(appendReq);
verifyZeroInteractions(clearReq);
verifyNoInteractions(appendReq);
verifyNoInteractions(clearReq);
BatchUpdateValuesRequest expectedRequest = new BatchUpdateValuesRequest();
List<List<Object>> expectedVals = newArrayList();
@ -122,8 +122,8 @@ public class SheetSynchronizerTest {
data = ImmutableList.of(ImmutableMap.of("a", "val1", "b", "val2", "d", "val3"));
sheetSynchronizer.synchronize("aSheetId", data);
verifyZeroInteractions(appendReq);
verifyZeroInteractions(clearReq);
verifyNoInteractions(appendReq);
verifyNoInteractions(clearReq);
BatchUpdateValuesRequest expectedRequest = new BatchUpdateValuesRequest();
List<List<Object>> expectedVals = newArrayList();
@ -141,8 +141,8 @@ public class SheetSynchronizerTest {
data = ImmutableList.of(ImmutableMap.of("a", "val1", "b", "paddedVal", "d", "val3"));
sheetSynchronizer.synchronize("aSheetId", data);
verifyZeroInteractions(appendReq);
verifyZeroInteractions(clearReq);
verifyNoInteractions(appendReq);
verifyNoInteractions(clearReq);
BatchUpdateValuesRequest expectedRequest = new BatchUpdateValuesRequest();
List<List<Object>> expectedVals = newArrayList();
@ -162,7 +162,7 @@ public class SheetSynchronizerTest {
ImmutableMap.of("a", "val3", "b", "val4"));
sheetSynchronizer.synchronize("aSheetId", data);
verifyZeroInteractions(clearReq);
verifyNoInteractions(clearReq);
BatchUpdateValuesRequest expectedRequest = new BatchUpdateValuesRequest();
List<List<Object>> updatedVals = newArrayList();
@ -188,6 +188,6 @@ public class SheetSynchronizerTest {
sheetSynchronizer.synchronize("aSheetId", data);
verify(values).clear("aSheetId", "Registrars!3:4", new ClearValuesRequest());
verifyZeroInteractions(updateReq);
verifyNoInteractions(updateReq);
}
}

View file

@ -19,8 +19,8 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
import google.registry.testing.AppEngineRule;
@ -67,7 +67,7 @@ public class SyncRegistrarsSheetActionTest {
public void testPost_withoutParamsOrSystemProperty_dropsTask() {
runAction(null, null);
assertThat(response.getPayload()).startsWith("MISSINGNO");
verifyZeroInteractions(syncRegistrarsSheet);
verifyNoInteractions(syncRegistrarsSheet);
}
@Test
@ -104,6 +104,6 @@ public class SyncRegistrarsSheetActionTest {
action.lockHandler = new FakeLockHandler(false);
runAction(null, "foobar");
assertThat(response.getPayload()).startsWith("LOCKED");
verifyZeroInteractions(syncRegistrarsSheet);
verifyNoInteractions(syncRegistrarsSheet);
}
}

View file

@ -26,7 +26,7 @@ import static java.util.logging.Level.INFO;
import static java.util.logging.Level.SEVERE;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
import com.google.common.base.Splitter;
@ -163,7 +163,7 @@ public class EppControllerTest {
true,
true,
domainCreateXml.getBytes(UTF_8));
verifyZeroInteractions(eppMetrics);
verifyNoInteractions(eppMetrics);
}
@Test

View file

@ -25,8 +25,8 @@ import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
import com.google.appengine.tools.cloudstorage.GcsFilename;
@ -208,7 +208,7 @@ public class CopyDetailReportsActionTest {
new GcsFilename("test-bucket", "results/invoice_details_2017-10_notExistent_hello.csv"),
"hola,mundo\n3,4".getBytes(UTF_8));
action.run();
verifyZeroInteractions(driveConnection);
verifyNoInteractions(driveConnection);
}
@Test
@ -220,6 +220,6 @@ public class CopyDetailReportsActionTest {
"test-bucket", "results/invoice_details_2017-10_TheRegistrar_hello.csv"),
"hola,mundo\n3,4".getBytes(UTF_8));
action.run();
verifyZeroInteractions(driveConnection);
verifyNoInteractions(driveConnection);
}
}

View file

@ -24,8 +24,8 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
import com.google.appengine.api.users.User;
@ -245,7 +245,7 @@ public final class RequestHandlerTest {
handler.handleRequest(req, rsp);
verifyZeroInteractions(rsp);
verifyNoInteractions(rsp);
verify(bumblebeeTask).run();
assertMetric("/bumblebee", GET, AuthLevel.NONE, true);
}

View file

@ -24,7 +24,7 @@ import static google.registry.testing.LogsSubject.assertAboutLogs;
import static org.junit.Assert.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
import com.google.appengine.api.users.User;
@ -150,7 +150,7 @@ public class AuthenticatedRegistrarAccessorTest {
NO_USER, ADMIN_CLIENT_ID, SUPPORT_GROUP, lazyGroupsConnection);
assertThat(registrarAccessor.getAllClientIdWithRoles()).isEmpty();
verifyZeroInteractions(lazyGroupsConnection);
verifyNoInteractions(lazyGroupsConnection);
}
/**
@ -182,7 +182,7 @@ public class AuthenticatedRegistrarAccessorTest {
ADMIN_CLIENT_ID, ADMIN,
ADMIN_CLIENT_ID, OWNER);
verifyZeroInteractions(lazyGroupsConnection);
verifyNoInteractions(lazyGroupsConnection);
}
/**
@ -228,7 +228,7 @@ public class AuthenticatedRegistrarAccessorTest {
assertThat(registrarAccessor.getAllClientIdWithRoles())
.containsExactly(CLIENT_ID_WITH_CONTACT, OWNER);
// Make sure we didn't instantiate the lazyGroupsConnection
verifyZeroInteractions(lazyGroupsConnection);
verifyNoInteractions(lazyGroupsConnection);
}
/** Support group check throws - continue anyway. */
@ -287,7 +287,7 @@ public class AuthenticatedRegistrarAccessorTest {
CLIENT_ID_WITH_CONTACT,
NO_USER,
"<logged-out user> doesn't have access to registrar TheRegistrar");
verifyZeroInteractions(lazyGroupsConnection);
verifyNoInteractions(lazyGroupsConnection);
}
/** Succeed loading registrar if user has access to it. */
@ -307,7 +307,7 @@ public class AuthenticatedRegistrarAccessorTest {
CLIENT_ID_WITH_CONTACT,
GAE_ADMIN,
"admin admin@gmail.com has [OWNER, ADMIN] access to registrar TheRegistrar");
verifyZeroInteractions(lazyGroupsConnection);
verifyNoInteractions(lazyGroupsConnection);
}
/** Succeed loading registrar for admin even if they aren't on the approved contacts list. */
@ -317,7 +317,7 @@ public class AuthenticatedRegistrarAccessorTest {
REAL_CLIENT_ID_WITHOUT_CONTACT,
GAE_ADMIN,
"admin admin@gmail.com has [ADMIN] access to registrar NewRegistrar.");
verifyZeroInteractions(lazyGroupsConnection);
verifyNoInteractions(lazyGroupsConnection);
}
@Test
@ -332,7 +332,7 @@ public class AuthenticatedRegistrarAccessorTest {
REAL_CLIENT_ID_WITHOUT_CONTACT,
GAE_ADMIN,
"admin admin@gmail.com has [OWNER, ADMIN] access to registrar NewRegistrar.");
verifyZeroInteractions(lazyGroupsConnection);
verifyNoInteractions(lazyGroupsConnection);
}
/** Succeed loading non-REAL registrar for admin. */
@ -342,7 +342,7 @@ public class AuthenticatedRegistrarAccessorTest {
OTE_CLIENT_ID_WITHOUT_CONTACT,
GAE_ADMIN,
"admin admin@gmail.com has [OWNER, ADMIN] access to registrar OteRegistrar.");
verifyZeroInteractions(lazyGroupsConnection);
verifyNoInteractions(lazyGroupsConnection);
}
/** Fail loading registrar even if admin, if registrar doesn't exist. */
@ -352,7 +352,7 @@ public class AuthenticatedRegistrarAccessorTest {
"BadClientId",
GAE_ADMIN,
"Registrar BadClientId does not exist");
verifyZeroInteractions(lazyGroupsConnection);
verifyNoInteractions(lazyGroupsConnection);
}
private void expectGetRegistrarSuccess(String clientId, AuthResult authResult, String message)

View file

@ -19,7 +19,7 @@ import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static org.junit.Assert.assertThrows;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
import com.google.appengine.api.users.User;
@ -138,7 +138,7 @@ public class RequestAuthenticatorTest {
public void testNoAuthNeeded_noneFound() {
Optional<AuthResult> authResult = runTest(mockUserService, AUTH_NONE);
verifyZeroInteractions(mockUserService);
verifyNoInteractions(mockUserService);
assertThat(authResult).isPresent();
assertThat(authResult.get().authLevel()).isEqualTo(AuthLevel.NONE);
}
@ -149,7 +149,7 @@ public class RequestAuthenticatorTest {
Optional<AuthResult> authResult = runTest(mockUserService, AUTH_NONE);
verifyZeroInteractions(mockUserService);
verifyNoInteractions(mockUserService);
assertThat(authResult).isPresent();
assertThat(authResult.get().authLevel()).isEqualTo(AuthLevel.APP);
assertThat(authResult.get().userAuthInfo()).isEmpty();
@ -159,7 +159,7 @@ public class RequestAuthenticatorTest {
public void testInternalAuth_notInvokedInternally() {
Optional<AuthResult> authResult = runTest(mockUserService, AUTH_INTERNAL_OR_ADMIN);
verifyZeroInteractions(mockUserService);
verifyNoInteractions(mockUserService);
assertThat(authResult).isEmpty();
}
@ -169,7 +169,7 @@ public class RequestAuthenticatorTest {
Optional<AuthResult> authResult = runTest(mockUserService, AUTH_INTERNAL_OR_ADMIN);
verifyZeroInteractions(mockUserService);
verifyNoInteractions(mockUserService);
assertThat(authResult).isPresent();
assertThat(authResult.get().authLevel()).isEqualTo(AuthLevel.APP);
assertThat(authResult.get().userAuthInfo()).isEmpty();

View file

@ -31,25 +31,25 @@ import google.registry.persistence.VKey;
import google.registry.testing.FakeClock;
import google.registry.testing.InjectRule;
import org.joda.time.DateTime;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
/** Unit tests for {@link AckPollMessagesCommand}. */
public class AckPollMessagesCommandTest extends CommandTestCase<AckPollMessagesCommand> {
private FakeClock clock = new FakeClock(DateTime.parse("2015-02-04T08:16:32.064Z"));
@Rule public final InjectRule inject = new InjectRule();
@RegisterExtension public final InjectRule inject = new InjectRule();
@Before
public final void before() {
@BeforeEach
final void beforeEach() {
inject.setStaticField(Ofy.class, "clock", clock);
command.clock = clock;
}
@Test
public void testSuccess_doesntDeletePollMessagesInFuture() throws Exception {
void testSuccess_doesntDeletePollMessagesInFuture() throws Exception {
VKey<OneTime> pm1 =
persistPollMessage(316L, DateTime.parse("2014-01-01T22:33:44Z"), "foobar").createVKey();
VKey<OneTime> pm2 =
@ -70,7 +70,7 @@ public class AckPollMessagesCommandTest extends CommandTestCase<AckPollMessagesC
}
@Test
public void testSuccess_resavesAutorenewPollMessages() throws Exception {
void testSuccess_resavesAutorenewPollMessages() throws Exception {
VKey<OneTime> pm1 =
persistPollMessage(316L, DateTime.parse("2014-01-01T22:33:44Z"), "foobar").createVKey();
VKey<OneTime> pm2 =
@ -98,7 +98,7 @@ public class AckPollMessagesCommandTest extends CommandTestCase<AckPollMessagesC
}
@Test
public void testSuccess_deletesExpiredAutorenewPollMessages() throws Exception {
void testSuccess_deletesExpiredAutorenewPollMessages() throws Exception {
VKey<OneTime> pm1 =
persistPollMessage(316L, DateTime.parse("2014-01-01T22:33:44Z"), "foobar").createVKey();
VKey<OneTime> pm2 =
@ -125,7 +125,7 @@ public class AckPollMessagesCommandTest extends CommandTestCase<AckPollMessagesC
}
@Test
public void testSuccess_onlyDeletesPollMessagesMatchingMessage() throws Exception {
void testSuccess_onlyDeletesPollMessagesMatchingMessage() throws Exception {
VKey<OneTime> pm1 =
persistPollMessage(316L, DateTime.parse("2014-01-01T22:33:44Z"), "food is good")
.createVKey();
@ -143,7 +143,7 @@ public class AckPollMessagesCommandTest extends CommandTestCase<AckPollMessagesC
}
@Test
public void testSuccess_onlyDeletesPollMessagesMatchingClientId() throws Exception {
void testSuccess_onlyDeletesPollMessagesMatchingClientId() throws Exception {
VKey<OneTime> pm1 =
persistPollMessage(316L, DateTime.parse("2014-01-01T22:33:44Z"), "food is good")
.createVKey();
@ -167,7 +167,7 @@ public class AckPollMessagesCommandTest extends CommandTestCase<AckPollMessagesC
}
@Test
public void testSuccess_dryRunDoesntDeleteAnything() throws Exception {
void testSuccess_dryRunDoesntDeleteAnything() throws Exception {
OneTime pm1 = persistPollMessage(316L, DateTime.parse("2014-01-01T22:33:44Z"), "foobar");
OneTime pm2 = persistPollMessage(624L, DateTime.parse("2013-05-01T22:33:44Z"), "ninelives");
OneTime pm3 = persistPollMessage(791L, DateTime.parse("2015-01-08T22:33:44Z"), "ginger");

View file

@ -27,23 +27,19 @@ import com.google.common.net.MediaType;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.HashMap;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.mockito.junit.jupiter.MockitoExtension;
@RunWith(JUnit4.class)
public final class AppEngineConnectionTest {
/** Unit tests for {@link google.registry.tools.AppEngineConnection}. */
@ExtendWith(MockitoExtension.class)
final class AppEngineConnectionTest {
@Rule public final MockitoRule mocks = MockitoJUnit.rule();
AppEngineConnection connection;
TestHttpTransport httpTransport;
TestLowLevelHttpRequest lowLevelHttpRequest;
private AppEngineConnection connection;
private TestHttpTransport httpTransport;
private TestLowLevelHttpRequest lowLevelHttpRequest;
@Mock LowLevelHttpResponse lowLevelHttpResponse;
private final class TestHttpTransport extends HttpTransport {
@ -81,8 +77,8 @@ public final class AppEngineConnectionTest {
}
}
@Before
public void setUp() throws Exception {
@BeforeEach
void beforeEach() throws Exception {
lowLevelHttpRequest = new TestLowLevelHttpRequest();
when(lowLevelHttpResponse.getContent())
.thenReturn(new ByteArrayInputStream("MyContent".getBytes(UTF_8)));
@ -94,7 +90,7 @@ public final class AppEngineConnectionTest {
}
@Test
public void testSendGetRequest() throws Exception {
void testSendGetRequest() throws Exception {
assertThat(
connection.sendGetRequest(
"/my/path?query", ImmutableMap.of("key1", "value1", "key2", "value2")))
@ -107,7 +103,7 @@ public final class AppEngineConnectionTest {
}
@Test
public void testSendPostRequest() throws Exception {
void testSendPostRequest() throws Exception {
assertThat(
connection.sendPostRequest(
"/my/path?query",
@ -125,7 +121,7 @@ public final class AppEngineConnectionTest {
}
@Test
public void testSendJsonRequest() throws Exception {
void testSendJsonRequest() throws Exception {
when(lowLevelHttpResponse.getContent())
.thenReturn(
new ByteArrayInputStream((JSON_SAFETY_PREFIX + "{\"key\":\"value\"}").getBytes(UTF_8)));

View file

@ -17,7 +17,6 @@ package google.registry.tools;
import static com.google.common.truth.Truth.assertThat;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertThrows;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import com.google.api.client.auth.oauth2.ClientParametersAuthentication;
@ -37,25 +36,29 @@ import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.io.TempDir;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
/** Unit tests for {@link AuthModule}. */
@RunWith(JUnit4.class)
public class AuthModuleTest {
@ExtendWith(MockitoExtension.class)
class AuthModuleTest {
private static final String CLIENT_ID = "UNITTEST-CLIENT-ID";
private static final String CLIENT_SECRET = "UNITTEST-CLIENT-SECRET";
private static final String ACCESS_TOKEN = "FakeAccessToken";
private static final String REFRESH_TOKEN = "FakeReFreshToken";
@Rule
public final TemporaryFolder folder = new TemporaryFolder();
@SuppressWarnings("WeakerAccess")
@TempDir
Path folder;
private final Credential fakeCredential =
new Credential.Builder(
@ -77,8 +80,7 @@ public class AuthModuleTest {
.setClientAuthentication(new ClientParametersAuthentication(CLIENT_ID, CLIENT_SECRET))
.build();
@SuppressWarnings("unchecked")
DataStore<StoredCredential> dataStore = mock(DataStore.class);
@Mock DataStore<StoredCredential> dataStore;
class FakeDataStoreFactory extends AbstractDataStoreFactory {
@Override
@ -89,14 +91,15 @@ public class AuthModuleTest {
}
}
@Before
public void setUp() throws Exception {
@BeforeEach
void beforeEach() throws Exception {
fakeCredential.setRefreshToken(REFRESH_TOKEN);
when(dataStore.get(CLIENT_ID + " scope1")).thenReturn(new StoredCredential(fakeCredential));
}
@Test
public void test_clientScopeQualifier() {
@MockitoSettings(strictness = Strictness.LENIENT)
void test_clientScopeQualifier() {
String simpleQualifier =
AuthModule.provideClientScopeQualifier("client-id", ImmutableList.of("foo", "bar"));
@ -161,7 +164,7 @@ public class AuthModuleTest {
}
@Test
public void test_provideLocalCredentialJson() {
void test_provideLocalCredentialJson() {
String credentialJson =
AuthModule.provideLocalCredentialJson(this::getSecrets, this::getCredential, null);
Map<String, String> jsonMap =
@ -173,8 +176,9 @@ public class AuthModuleTest {
}
@Test
public void test_provideExternalCredentialJson() throws Exception {
File credentialFile = folder.newFile("credential.json");
@MockitoSettings(strictness = Strictness.LENIENT)
void test_provideExternalCredentialJson() throws Exception {
File credentialFile = folder.resolve("credential.json").toFile();
Files.write(credentialFile.toPath(), "{some_field: some_value}".getBytes(UTF_8));
String credentialJson =
AuthModule.provideLocalCredentialJson(
@ -183,7 +187,7 @@ public class AuthModuleTest {
}
@Test
public void test_provideCredential() {
void test_provideCredential() {
Credential cred = getCredential();
assertThat(cred.getAccessToken()).isEqualTo(fakeCredential.getAccessToken());
assertThat(cred.getRefreshToken()).isEqualTo(fakeCredential.getRefreshToken());
@ -192,7 +196,7 @@ public class AuthModuleTest {
}
@Test
public void test_provideCredential_notStored() throws IOException {
void test_provideCredential_notStored() throws IOException {
when(dataStore.get(CLIENT_ID + " scope1")).thenReturn(null);
assertThrows(AuthModule.LoginRequiredException.class, this::getCredential);
}

View file

@ -19,26 +19,26 @@ import static org.junit.Assert.assertThrows;
import com.beust.jcommander.ParameterException;
import google.registry.model.registrar.Registrar.Type;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link CheckDomainClaimsCommand}. */
public class CheckDomainClaimsCommandTest extends EppToolCommandTestCase<CheckDomainClaimsCommand> {
class CheckDomainClaimsCommandTest extends EppToolCommandTestCase<CheckDomainClaimsCommand> {
@Before
public void before() {
@BeforeEach
void beforeEach() {
persistNewRegistrar("adminreg", "Admin Registrar", Type.REAL, 693L);
command.registryAdminClientId = "adminreg";
}
@Test
public void testSuccess() throws Exception {
void testSuccess() throws Exception {
runCommand("--client=NewRegistrar", "example.tld");
eppVerifier.expectDryRun().verifySent("domain_check_claims.xml");
}
@Test
public void testSuccess_multipleTlds() throws Exception {
void testSuccess_multipleTlds() throws Exception {
runCommand("--client=NewRegistrar", "example.tld", "example.tld2");
eppVerifier
.expectDryRun()
@ -47,7 +47,7 @@ public class CheckDomainClaimsCommandTest extends EppToolCommandTestCase<CheckDo
}
@Test
public void testSuccess_multipleDomains() throws Exception {
void testSuccess_multipleDomains() throws Exception {
runCommand(
"--client=NewRegistrar",
"example.tld",
@ -57,7 +57,7 @@ public class CheckDomainClaimsCommandTest extends EppToolCommandTestCase<CheckDo
}
@Test
public void testSuccess_multipleDomainsAndTlds() throws Exception {
void testSuccess_multipleDomainsAndTlds() throws Exception {
runCommand(
"--client=NewRegistrar",
"example.tld",
@ -71,18 +71,18 @@ public class CheckDomainClaimsCommandTest extends EppToolCommandTestCase<CheckDo
}
@Test
public void testSuccess_unspecifiedClientId_defaultsToRegistryRegistrar() throws Exception {
void testSuccess_unspecifiedClientId_defaultsToRegistryRegistrar() throws Exception {
runCommand("example.tld");
eppVerifier.expectDryRun().expectClientId("adminreg").verifySent("domain_check_claims.xml");
}
@Test
public void testFailure_NoMainParameter() {
void testFailure_NoMainParameter() {
assertThrows(ParameterException.class, () -> runCommand("--client=NewRegistrar"));
}
@Test
public void testFailure_unknownFlag() {
void testFailure_unknownFlag() {
assertThrows(
ParameterException.class,
() -> runCommand("--client=NewRegistrar", "--unrecognized=foo", "example.tld"));

View file

@ -19,26 +19,26 @@ import static org.junit.Assert.assertThrows;
import com.beust.jcommander.ParameterException;
import google.registry.model.registrar.Registrar.Type;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link CheckDomainCommand}. */
public class CheckDomainCommandTest extends EppToolCommandTestCase<CheckDomainCommand> {
class CheckDomainCommandTest extends EppToolCommandTestCase<CheckDomainCommand> {
@Before
public void before() {
@BeforeEach
void beforeEach() {
persistNewRegistrar("adminreg", "Admin Registrar", Type.REAL, 693L);
command.registryAdminClientId = "adminreg";
}
@Test
public void testSuccess() throws Exception {
void testSuccess() throws Exception {
runCommand("--client=NewRegistrar", "example.tld");
eppVerifier.expectDryRun().verifySent("domain_check_fee.xml");
}
@Test
public void testSuccess_multipleTlds() throws Exception {
void testSuccess_multipleTlds() throws Exception {
runCommand("--client=NewRegistrar", "example.tld", "example.tld2");
eppVerifier
.expectDryRun()
@ -47,7 +47,7 @@ public class CheckDomainCommandTest extends EppToolCommandTestCase<CheckDomainCo
}
@Test
public void testSuccess_multipleDomains() throws Exception {
void testSuccess_multipleDomains() throws Exception {
runCommand(
"--client=NewRegistrar",
"example.tld",
@ -57,7 +57,7 @@ public class CheckDomainCommandTest extends EppToolCommandTestCase<CheckDomainCo
}
@Test
public void testSuccess_multipleDomainsAndTlds() throws Exception {
void testSuccess_multipleDomainsAndTlds() throws Exception {
runCommand(
"--client=NewRegistrar",
"example.tld",
@ -71,24 +71,24 @@ public class CheckDomainCommandTest extends EppToolCommandTestCase<CheckDomainCo
}
@Test
public void testSuccess_unspecifiedClientId_defaultsToRegistryRegistrar() throws Exception {
void testSuccess_unspecifiedClientId_defaultsToRegistryRegistrar() throws Exception {
runCommand("example.tld");
eppVerifier.expectDryRun().expectClientId("adminreg").verifySent("domain_check_fee.xml");
}
@Test
public void testSuccess_allocationToken_reserved() throws Exception {
void testSuccess_allocationToken_reserved() throws Exception {
runCommand("--client=NewRegistrar", "--token=abc123", "example.tld");
eppVerifier.expectDryRun().verifySent("domain_check_fee_allocationtoken.xml");
}
@Test
public void testFailure_NoMainParameter() {
void testFailure_NoMainParameter() {
assertThrows(ParameterException.class, () -> runCommand("--client=NewRegistrar"));
}
@Test
public void testFailure_unknownFlag() {
void testFailure_unknownFlag() {
assertThrows(
ParameterException.class,
() -> runCommand("--client=NewRegistrar", "--unrecognized=foo", "example.tld"));

View file

@ -35,27 +35,25 @@ import google.registry.testing.FakeClock;
import google.registry.testing.SystemPropertyRule;
import google.registry.tools.params.ParameterFactory;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.nio.file.Path;
import java.util.List;
import java.util.concurrent.locks.ReentrantLock;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.api.io.TempDir;
import org.mockito.junit.jupiter.MockitoExtension;
/**
* Base class for all command tests.
*
* @param <C> the command type
*/
@RunWith(JUnit4.class)
@ExtendWith(MockitoExtension.class)
public abstract class CommandTestCase<C extends Command> {
// Lock for stdout/stderr. Note that this is static: since we're dealing with globals, we need
@ -70,7 +68,7 @@ public abstract class CommandTestCase<C extends Command> {
public final FakeClock fakeClock = new FakeClock();
@Rule
@RegisterExtension
public final AppEngineRule appEngine =
AppEngineRule.builder()
.withDatastoreAndCloudSql()
@ -78,15 +76,12 @@ public abstract class CommandTestCase<C extends Command> {
.withTaskQueue()
.build();
@Rule public final SystemPropertyRule systemPropertyRule = new SystemPropertyRule();
@RegisterExtension final SystemPropertyRule systemPropertyRule = new SystemPropertyRule();
@Rule public final MockitoRule mocks = MockitoJUnit.rule();
@TempDir public Path tmpDir;
@Rule
public TemporaryFolder tmpDir = new TemporaryFolder();
@Before
public final void beforeCommandTestCase() throws Exception {
@BeforeEach
public final void beforeEachCommandTestCase() throws Exception {
// Ensure the UNITTEST environment has been set before constructing a new command instance.
RegistryToolEnvironment.UNITTEST.setup(systemPropertyRule);
command = newCommandInstance();
@ -101,8 +96,8 @@ public abstract class CommandTestCase<C extends Command> {
System.setErr(new PrintStream(new OutputSplitter(System.err, stderr)));
}
@After
public final void afterCommandTestCase() throws Exception {
@AfterEach
public final void afterEachCommandTestCase() {
System.setOut(oldStdout);
System.setErr(oldStderr);
streamsLock.unlock();
@ -144,10 +139,10 @@ public abstract class CommandTestCase<C extends Command> {
}
/** Writes the data to a named temporary file and then returns a path to the file. */
String writeToNamedTmpFile(String filename, byte[] data) throws IOException {
File tmpFile = tmpDir.newFile(filename);
Files.write(data, tmpFile);
return tmpFile.getPath();
private String writeToNamedTmpFile(String filename, byte[] data) throws IOException {
Path tmpFile = tmpDir.resolve(filename);
Files.write(data, tmpFile.toFile());
return tmpFile.toString();
}
/** Writes the data to a named temporary file and then returns a path to the file. */
@ -199,7 +194,7 @@ public abstract class CommandTestCase<C extends Command> {
.isEqualTo(stripImmutableObjectHashCodes(expected).trim());
}
protected void assertStdoutIs(String expected) {
void assertStdoutIs(String expected) {
assertThat(getStdoutAsString()).isEqualTo(expected);
}
@ -210,34 +205,34 @@ public abstract class CommandTestCase<C extends Command> {
}
}
protected void assertInStderr(String... expected) {
void assertInStderr(String... expected) {
String stderror = new String(stderr.toByteArray(), UTF_8);
for (String line : expected) {
assertThat(stderror).contains(line);
}
}
protected void assertNotInStdout(String expected) {
void assertNotInStdout(String expected) {
assertThat(getStdoutAsString()).doesNotContain(expected);
}
protected void assertNotInStderr(String expected) {
void assertNotInStderr(String expected) {
assertThat(getStderrAsString()).doesNotContain(expected);
}
protected String getStdoutAsString() {
String getStdoutAsString() {
return new String(stdout.toByteArray(), UTF_8);
}
protected String getStderrAsString() {
String getStderrAsString() {
return new String(stderr.toByteArray(), UTF_8);
}
protected List<String> getStdoutAsLines() {
List<String> getStdoutAsLines() {
return Splitter.on('\n').omitEmptyStrings().trimResults().splitToList(getStdoutAsString());
}
protected String stripImmutableObjectHashCodes(String string) {
private String stripImmutableObjectHashCodes(String string) {
return string.replaceAll("\\(@\\d+\\)", "(@)");
}

View file

@ -22,14 +22,15 @@ import google.registry.testing.DatastoreEntityExtension;
import google.registry.tools.EntityWrapper.Property;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
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.junit.rules.TemporaryFolder;
import org.junit.jupiter.api.io.TempDir;
public class CompareDbBackupsTest {
@ -39,26 +40,24 @@ public class CompareDbBackupsTest {
private final ByteArrayOutputStream stdout = new ByteArrayOutputStream();
private PrintStream orgStdout;
public final TemporaryFolder tempFs = new TemporaryFolder();
@TempDir Path tmpDir;
@RegisterExtension
public DatastoreEntityExtension datastoreEntityExtension = new DatastoreEntityExtension();
@BeforeEach
public void before() throws IOException {
void beforeEach() {
orgStdout = System.out;
System.setOut(new PrintStream(stdout));
tempFs.create();
}
@AfterEach
public void after() {
void afterEach() {
System.setOut(orgStdout);
tempFs.delete();
}
@Test
public void testLoadBackup() {
void testLoadBackup() {
URL backupRootFolder = Resources.getResource("google/registry/tools/datastore-export");
CompareDbBackups.main(new String[] {backupRootFolder.getPath(), backupRootFolder.getPath()});
String output = new String(stdout.toByteArray(), UTF_8);
@ -66,11 +65,12 @@ public class CompareDbBackupsTest {
}
@Test
public void testCompareBackups() throws Exception {
void testCompareBackups() throws Exception {
// Create two directories corresponding to data dumps.
File dump1 = tempFs.newFolder("dump1");
LevelDbFileBuilder builder = new LevelDbFileBuilder(new File(dump1, "output-data1"));
Path dump1 = Files.createDirectory(tmpDir.resolve("dump1"));
Path dump2 = Files.createDirectory(tmpDir.resolve("dump2"));
LevelDbFileBuilder builder = new LevelDbFileBuilder(new File(dump1.toFile(), "output-data1"));
builder.addEntity(
EntityWrapper.from(
BASE_ID,
@ -87,8 +87,7 @@ public class CompareDbBackupsTest {
.getEntity());
builder.build();
File dump2 = tempFs.newFolder("dump2");
builder = new LevelDbFileBuilder(new File(dump2, "output-data2"));
builder = new LevelDbFileBuilder(new File(dump2.toFile(), "output-data2"));
builder.addEntity(
EntityWrapper.from(
BASE_ID + 1,
@ -105,7 +104,7 @@ public class CompareDbBackupsTest {
.getEntity());
builder.build();
CompareDbBackups.main(new String[] {dump1.getCanonicalPath(), dump2.getCanonicalPath()});
CompareDbBackups.main(new String[] {dump1.toString(), dump2.toString()});
String output = new String(stdout.toByteArray(), UTF_8);
assertThat(output)
.containsMatch("(?s)1 records were removed.*eeny.*1 records were added.*blutzy");

View file

@ -23,26 +23,26 @@ import google.registry.model.ofy.Ofy;
import google.registry.testing.FakeClock;
import google.registry.testing.InjectRule;
import org.joda.time.DateTime;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
/** Unit tests for {@link CountDomainsCommand}. */
public class CountDomainsCommandTest extends CommandTestCase<CountDomainsCommand> {
protected FakeClock clock = new FakeClock(DateTime.now(UTC));
@Rule public final InjectRule inject = new InjectRule();
@RegisterExtension public final InjectRule inject = new InjectRule();
@Before
public final void before() {
@BeforeEach
final void beforeEach() {
inject.setStaticField(Ofy.class, "clock", clock);
command.clock = clock;
createTlds("foo", "bar", "baz", "qux");
}
@Test
public void testSuccess_singleTld() throws Exception {
void testSuccess_singleTld() throws Exception {
for (int i = 0; i < 51; i++) {
persistActiveDomain(String.format("test-%d.foo", i));
if (i > 31) {
@ -54,7 +54,7 @@ public class CountDomainsCommandTest extends CommandTestCase<CountDomainsCommand
}
@Test
public void testSuccess_multipleTlds() throws Exception {
void testSuccess_multipleTlds() throws Exception {
command.clock = clock;
for (int i = 0; i < 29; i++) {
persistActiveDomain(String.format("test-%d.foo", i));

View file

@ -22,34 +22,33 @@ import static org.junit.Assert.assertThrows;
import com.beust.jcommander.ParameterException;
import google.registry.model.registry.Registry;
import google.registry.testing.DeterministicStringGenerator;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link CreateAnchorTenantCommand}. */
public class CreateAnchorTenantCommandTest
extends EppToolCommandTestCase<CreateAnchorTenantCommand> {
class CreateAnchorTenantCommandTest extends EppToolCommandTestCase<CreateAnchorTenantCommand> {
@Before
public void initCommand() {
@BeforeEach
void beforeEach() {
command.passwordGenerator = new DeterministicStringGenerator("abcdefghijklmnopqrstuvwxyz");
}
@Test
public void testSuccess() throws Exception {
void testSuccess() throws Exception {
runCommandForced("--client=NewRegistrar", "--superuser",
"--reason=anchor-tenant-test", "--contact=jd1234", "--domain_name=example.tld");
eppVerifier.expectSuperuser().verifySent("domain_create_anchor_tenant.xml");
}
@Test
public void testSuccess_suppliedPassword() throws Exception {
void testSuccess_suppliedPassword() throws Exception {
runCommandForced("--client=NewRegistrar", "--superuser", "--password=foo",
"--reason=anchor-tenant-test", "--contact=jd1234", "--domain_name=example.tld");
eppVerifier.expectSuperuser().verifySent("domain_create_anchor_tenant_password.xml");
}
@Test
public void testSuccess_multipleWordReason() throws Exception {
void testSuccess_multipleWordReason() throws Exception {
runCommandForced("--client=NewRegistrar", "--superuser",
"--reason=\"anchor tenant test\"", "--contact=jd1234", "--domain_name=example.tld");
eppVerifier
@ -58,21 +57,21 @@ public class CreateAnchorTenantCommandTest
}
@Test
public void testSuccess_noReason() throws Exception {
void testSuccess_noReason() throws Exception {
runCommandForced("--client=NewRegistrar", "--superuser",
"--contact=jd1234", "--domain_name=example.tld");
eppVerifier.expectSuperuser().verifySent("domain_create_anchor_tenant_no_reason.xml");
}
@Test
public void testSuccess_feeStandard() throws Exception {
void testSuccess_feeStandard() throws Exception {
runCommandForced("--client=NewRegistrar", "--superuser", "--fee",
"--reason=anchor-tenant-test", "--contact=jd1234", "--domain_name=example.tld");
eppVerifier.expectSuperuser().verifySent("domain_create_anchor_tenant_fee_standard.xml");
}
@Test
public void testSuccess_feePremium() throws Exception {
void testSuccess_feePremium() throws Exception {
createTld("tld");
persistResource(
Registry.get("tld")
@ -85,7 +84,7 @@ public class CreateAnchorTenantCommandTest
}
@Test
public void testFailure_mainParameter() {
void testFailure_mainParameter() {
assertThrows(
ParameterException.class,
() ->
@ -100,7 +99,7 @@ public class CreateAnchorTenantCommandTest
}
@Test
public void testFailure_missingClientId() {
void testFailure_missingClientId() {
assertThrows(
ParameterException.class,
() ->
@ -112,7 +111,7 @@ public class CreateAnchorTenantCommandTest
}
@Test
public void testFailure_unknownFlag() {
void testFailure_unknownFlag() {
assertThrows(
ParameterException.class,
() ->
@ -126,7 +125,7 @@ public class CreateAnchorTenantCommandTest
}
@Test
public void testFailure_missingDomainName() {
void testFailure_missingDomainName() {
assertThrows(
ParameterException.class,
() ->
@ -139,7 +138,7 @@ public class CreateAnchorTenantCommandTest
}
@Test
public void testFailure_missingContact() {
void testFailure_missingContact() {
assertThrows(
ParameterException.class,
() ->
@ -152,7 +151,7 @@ public class CreateAnchorTenantCommandTest
}
@Test
public void testFailure_notAsSuperuser() {
void testFailure_notAsSuperuser() {
assertThrows(
IllegalArgumentException.class,
() ->

View file

@ -22,14 +22,16 @@ import static org.mockito.Mockito.when;
import com.google.api.services.dns.Dns;
import com.google.api.services.dns.model.ManagedZone;
import com.google.api.services.dns.model.ManagedZoneDnsSecConfig;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
/** Unit tests for {@link CreateCdnsTld}. */
public class CreateCdnsTldTest extends CommandTestCase<CreateCdnsTld> {
class CreateCdnsTldTest extends CommandTestCase<CreateCdnsTld> {
@Mock Dns dnsService;
@Mock Dns.ManagedZones managedZones;
@ -37,8 +39,8 @@ public class CreateCdnsTldTest extends CommandTestCase<CreateCdnsTld> {
@Captor ArgumentCaptor<String> projectId;
@Captor ArgumentCaptor<ManagedZone> requestBody;
@Before
public void setUp() throws Exception {
@BeforeEach
void beforeEach() throws Exception {
when(dnsService.managedZones()).thenReturn(managedZones);
when(managedZones.create(projectId.capture(), requestBody.capture())).thenReturn(request);
command = new CreateCdnsTld();
@ -57,7 +59,7 @@ public class CreateCdnsTldTest extends CommandTestCase<CreateCdnsTld> {
}
@Test
public void testBasicFunctionality() throws Exception {
void testBasicFunctionality() throws Exception {
runCommand("--dns_name=tld.", "--name=tld", "--description=test run", "--force");
verify(request).execute();
assertThat(projectId.getValue()).isEqualTo("test-project");
@ -66,14 +68,15 @@ public class CreateCdnsTldTest extends CommandTestCase<CreateCdnsTld> {
}
@Test
public void testNameDefault() throws Exception {
void testNameDefault() throws Exception {
runCommand("--dns_name=tld.", "--description=test run", "--force");
ManagedZone zone = requestBody.getValue();
assertThat(zone).isEqualTo(createZone("cloud-dns-registry-test", "test run", "tld.", "tld."));
}
@Test
public void testSandboxTldRestrictions() throws Exception {
@MockitoSettings(strictness = Strictness.LENIENT)
void testSandboxTldRestrictions() throws Exception {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,

View file

@ -18,19 +18,19 @@ import static org.junit.Assert.assertThrows;
import com.beust.jcommander.ParameterException;
import google.registry.testing.DeterministicStringGenerator;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link CreateContactCommand}. */
public class CreateContactCommandTest extends EppToolCommandTestCase<CreateContactCommand> {
class CreateContactCommandTest extends EppToolCommandTestCase<CreateContactCommand> {
@Before
public void initCommand() {
@BeforeEach
void beforeEach() {
command.passwordGenerator = new DeterministicStringGenerator("abcdefghijklmnopqrstuvwxyz");
}
@Test
public void testSuccess_complete() throws Exception {
void testSuccess_complete() throws Exception {
runCommandForced(
"--client=NewRegistrar",
"--id=sh8013",
@ -51,7 +51,7 @@ public class CreateContactCommandTest extends EppToolCommandTestCase<CreateConta
}
@Test
public void testSuccess_minimal() throws Exception {
void testSuccess_minimal() throws Exception {
// Will never be the case, but tests that each field can be omitted.
// Also tests the auto-gen password.
runCommandForced("--client=NewRegistrar");
@ -59,12 +59,12 @@ public class CreateContactCommandTest extends EppToolCommandTestCase<CreateConta
}
@Test
public void testFailure_missingClientId() {
void testFailure_missingClientId() {
assertThrows(ParameterException.class, this::runCommandForced);
}
@Test
public void testFailure_tooManyStreetLines() {
void testFailure_tooManyStreetLines() {
assertThrows(
IllegalArgumentException.class,
() ->
@ -77,13 +77,13 @@ public class CreateContactCommandTest extends EppToolCommandTestCase<CreateConta
}
@Test
public void testFailure_badPhone() {
void testFailure_badPhone() {
assertThrows(
ParameterException.class, () -> runCommandForced("--client=NewRegistrar", "--phone=3"));
}
@Test
public void testFailure_badFax() {
void testFailure_badFax() {
assertThrows(
ParameterException.class, () -> runCommandForced("--client=NewRegistrar", "--fax=3"));
}

View file

@ -24,19 +24,19 @@ import com.beust.jcommander.ParameterException;
import google.registry.model.registry.Registry;
import google.registry.model.registry.label.PremiumList;
import google.registry.testing.DeterministicStringGenerator;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link CreateDomainCommand}. */
public class CreateDomainCommandTest extends EppToolCommandTestCase<CreateDomainCommand> {
class CreateDomainCommandTest extends EppToolCommandTestCase<CreateDomainCommand> {
@Before
public void initCommand() {
@BeforeEach
void beforeEach() {
command.passwordGenerator = new DeterministicStringGenerator("abcdefghijklmnopqrstuvwxyz");
}
@Test
public void testSuccess_complete() throws Exception {
void testSuccess_complete() throws Exception {
runCommandForced(
"--client=NewRegistrar",
"--period=1",
@ -52,7 +52,7 @@ public class CreateDomainCommandTest extends EppToolCommandTestCase<CreateDomain
}
@Test
public void testSuccess_completeWithSquareBrackets() throws Exception {
void testSuccess_completeWithSquareBrackets() throws Exception {
runCommandForced(
"--client=NewRegistrar",
"--period=1",
@ -68,7 +68,7 @@ public class CreateDomainCommandTest extends EppToolCommandTestCase<CreateDomain
}
@Test
public void testSuccess_minimal() throws Exception {
void testSuccess_minimal() throws Exception {
// Test that each optional field can be omitted. Also tests the auto-gen password.
runCommandForced(
"--client=NewRegistrar",
@ -80,7 +80,7 @@ public class CreateDomainCommandTest extends EppToolCommandTestCase<CreateDomain
}
@Test
public void testSuccess_multipleDomains() throws Exception {
void testSuccess_multipleDomains() throws Exception {
createTld("abc");
runCommandForced(
"--client=NewRegistrar",
@ -95,7 +95,7 @@ public class CreateDomainCommandTest extends EppToolCommandTestCase<CreateDomain
}
@Test
public void testSuccess_premiumJpyDomain() throws Exception {
void testSuccess_premiumJpyDomain() throws Exception {
createTld("baar");
persistPremiumList("baar", "parajiumu,JPY 96083");
persistResource(
@ -118,7 +118,7 @@ public class CreateDomainCommandTest extends EppToolCommandTestCase<CreateDomain
}
@Test
public void testSuccess_multipleDomainsWithPremium() throws Exception {
void testSuccess_multipleDomainsWithPremium() throws Exception {
createTld("abc");
runCommandForced(
"--client=NewRegistrar",
@ -139,7 +139,7 @@ public class CreateDomainCommandTest extends EppToolCommandTestCase<CreateDomain
}
@Test
public void testFailure_duplicateDomains() {
void testFailure_duplicateDomains() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -155,7 +155,7 @@ public class CreateDomainCommandTest extends EppToolCommandTestCase<CreateDomain
}
@Test
public void testFailure_missingDomain() {
void testFailure_missingDomain() {
ParameterException thrown =
assertThrows(
ParameterException.class,
@ -169,7 +169,7 @@ public class CreateDomainCommandTest extends EppToolCommandTestCase<CreateDomain
}
@Test
public void testFailure_missingClientId() {
void testFailure_missingClientId() {
ParameterException thrown =
assertThrows(
ParameterException.class,
@ -183,7 +183,7 @@ public class CreateDomainCommandTest extends EppToolCommandTestCase<CreateDomain
}
@Test
public void testFailure_missingRegistrant() {
void testFailure_missingRegistrant() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -197,7 +197,7 @@ public class CreateDomainCommandTest extends EppToolCommandTestCase<CreateDomain
}
@Test
public void testFailure_missingAdmins() {
void testFailure_missingAdmins() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -211,7 +211,7 @@ public class CreateDomainCommandTest extends EppToolCommandTestCase<CreateDomain
}
@Test
public void testFailure_missingTechs() {
void testFailure_missingTechs() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -225,7 +225,7 @@ public class CreateDomainCommandTest extends EppToolCommandTestCase<CreateDomain
}
@Test
public void testFailure_tooManyNameServers() {
void testFailure_tooManyNameServers() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -244,7 +244,7 @@ public class CreateDomainCommandTest extends EppToolCommandTestCase<CreateDomain
}
@Test
public void testFailure_tooManyNameServers_usingSquareBracketRange() {
void testFailure_tooManyNameServers_usingSquareBracketRange() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -260,7 +260,7 @@ public class CreateDomainCommandTest extends EppToolCommandTestCase<CreateDomain
}
@Test
public void testFailure_badPeriod() {
void testFailure_badPeriod() {
ParameterException thrown =
assertThrows(
ParameterException.class,
@ -276,7 +276,7 @@ public class CreateDomainCommandTest extends EppToolCommandTestCase<CreateDomain
}
@Test
public void testFailure_dsRecordsNot4Parts() {
void testFailure_dsRecordsNot4Parts() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -292,7 +292,7 @@ public class CreateDomainCommandTest extends EppToolCommandTestCase<CreateDomain
}
@Test
public void testFailure_keyTagNotNumber() {
void testFailure_keyTagNotNumber() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -308,7 +308,7 @@ public class CreateDomainCommandTest extends EppToolCommandTestCase<CreateDomain
}
@Test
public void testFailure_algNotNumber() {
void testFailure_algNotNumber() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -324,7 +324,7 @@ public class CreateDomainCommandTest extends EppToolCommandTestCase<CreateDomain
}
@Test
public void testFailure_digestTypeNotNumber() {
void testFailure_digestTypeNotNumber() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -340,7 +340,7 @@ public class CreateDomainCommandTest extends EppToolCommandTestCase<CreateDomain
}
@Test
public void testFailure_digestNotHex() {
void testFailure_digestNotHex() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -356,7 +356,7 @@ public class CreateDomainCommandTest extends EppToolCommandTestCase<CreateDomain
}
@Test
public void testFailure_digestNotEvenLengthed() {
void testFailure_digestNotEvenLengthed() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -372,7 +372,7 @@ public class CreateDomainCommandTest extends EppToolCommandTestCase<CreateDomain
}
@Test
public void testFailure_cantForceCreatePremiumDomain_withoutForcePremiums() {
void testFailure_cantForceCreatePremiumDomain_withoutForcePremiums() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,

View file

@ -19,13 +19,13 @@ import static google.registry.testing.DatastoreHelper.createTld;
import static org.junit.Assert.assertThrows;
import com.beust.jcommander.ParameterException;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link CreateHostCommand}. */
public class CreateHostCommandTest extends EppToolCommandTestCase<CreateHostCommand> {
class CreateHostCommandTest extends EppToolCommandTestCase<CreateHostCommand> {
@Test
public void testSuccess_complete() throws Exception {
void testSuccess_complete() throws Exception {
createTld("tld");
runCommandForced(
"--client=NewRegistrar",
@ -35,7 +35,7 @@ public class CreateHostCommandTest extends EppToolCommandTestCase<CreateHostComm
}
@Test
public void testSuccess_minimal() throws Exception {
void testSuccess_minimal() throws Exception {
// Test that each optional field can be omitted.
runCommandForced(
"--client=NewRegistrar",
@ -44,12 +44,12 @@ public class CreateHostCommandTest extends EppToolCommandTestCase<CreateHostComm
}
@Test
public void testFailure_missingHost() {
void testFailure_missingHost() {
assertThrows(ParameterException.class, () -> runCommandForced("--client=NewRegistrar"));
}
@Test
public void testFailure_invalidIpAddress() {
void testFailure_invalidIpAddress() {
createTld("tld");
IllegalArgumentException thrown =
assertThrows(

View file

@ -28,11 +28,9 @@ import java.nio.charset.StandardCharsets;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
/**
* Base class for common testing setup for create and update commands for Premium Lists.
*/
public abstract class CreateOrUpdatePremiumListCommandTestCase<
T extends CreateOrUpdatePremiumListCommand> extends CommandTestCase<T> {
/** Base class for common testing setup for create and update commands for Premium Lists. */
abstract class CreateOrUpdatePremiumListCommandTestCase<T extends CreateOrUpdatePremiumListCommand>
extends CommandTestCase<T> {
@Captor
ArgumentCaptor<ImmutableMap<String, String>> urlParamCaptor;

View file

@ -32,25 +32,25 @@ import java.io.File;
import java.io.IOException;
import javax.persistence.EntityManager;
import org.joda.time.DateTime;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/**
* Base class for common testing setup for create and update commands for Reserved Lists.
*
* @param <T> command type
*/
public abstract class CreateOrUpdateReservedListCommandTestCase<
abstract class CreateOrUpdateReservedListCommandTestCase<
T extends CreateOrUpdateReservedListCommand>
extends CommandTestCase<T> {
String reservedTermsPath;
String invalidReservedTermsPath;
private String invalidReservedTermsPath;
@Before
public void init() throws IOException {
File reservedTermsFile = tmpDir.newFile("xn--q9jyb4c_common-reserved.txt");
File invalidReservedTermsFile = tmpDir.newFile("reserved-terms-wontparse.csv");
@BeforeEach
void beforeEachCreateOrUpdateReservedListCommandTestCase() throws IOException {
File reservedTermsFile = tmpDir.resolve("xn--q9jyb4c_common-reserved.txt").toFile();
File invalidReservedTermsFile = tmpDir.resolve("reserved-terms-wontparse.csv").toFile();
String reservedTermsCsv =
loadFile(CreateOrUpdateReservedListCommandTestCase.class, "example_reserved_terms.csv");
Files.asCharSink(reservedTermsFile, UTF_8).write(reservedTermsCsv);
@ -61,7 +61,7 @@ public abstract class CreateOrUpdateReservedListCommandTestCase<
}
@Test
public void testFailure_fileDoesntExist() {
void testFailure_fileDoesntExist() {
assertThat(
assertThrows(
ParameterException.class,
@ -74,7 +74,7 @@ public abstract class CreateOrUpdateReservedListCommandTestCase<
}
@Test
public void testFailure_fileDoesntParse() {
void testFailure_fileDoesntParse() {
assertThat(
assertThrows(
IllegalArgumentException.class,
@ -87,7 +87,7 @@ public abstract class CreateOrUpdateReservedListCommandTestCase<
}
@Test
public void testFailure_invalidLabel_includesFullDomainName() throws Exception {
void testFailure_invalidLabel_includesFullDomainName() throws Exception {
Files.asCharSink(new File(invalidReservedTermsPath), UTF_8)
.write("example.tld,FULLY_BLOCKED\n\n");
assertThat(

View file

@ -29,23 +29,25 @@ import com.google.common.base.VerifyException;
import com.google.common.collect.ImmutableMap;
import com.google.common.net.MediaType;
import google.registry.tools.server.CreatePremiumListAction;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentMatchers;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
/** Unit tests for {@link CreatePremiumListCommand}. */
public class CreatePremiumListCommandTest<C extends CreatePremiumListCommand>
class CreatePremiumListCommandTest<C extends CreatePremiumListCommand>
extends CreateOrUpdatePremiumListCommandTestCase<C> {
@Mock AppEngineConnection connection;
String premiumTermsPath;
private String premiumTermsPath;
String premiumTermsCsv;
String servletPath;
private String servletPath;
@Before
public void init() throws Exception {
@BeforeEach
void beforeEach() throws Exception {
command.setConnection(connection);
premiumTermsPath =
writeToNamedTmpFile(
@ -61,7 +63,7 @@ public class CreatePremiumListCommandTest<C extends CreatePremiumListCommand>
}
@Test
public void testRun() throws Exception {
void testRun() throws Exception {
runCommandForced("-i=" + premiumTermsPath, "-n=foo");
assertInStdout("Successfully");
verifySentParams(
@ -71,7 +73,7 @@ public class CreatePremiumListCommandTest<C extends CreatePremiumListCommand>
}
@Test
public void testRun_noProvidedName_usesBasenameOfInputFile() throws Exception {
void testRun_noProvidedName_usesBasenameOfInputFile() throws Exception {
runCommandForced("-i=" + premiumTermsPath);
assertInStdout("Successfully");
verifySentParams(
@ -82,7 +84,7 @@ public class CreatePremiumListCommandTest<C extends CreatePremiumListCommand>
}
@Test
public void testRun_errorResponse() throws Exception {
void testRun_errorResponse() throws Exception {
reset(connection);
command.setConnection(connection);
when(connection.sendPostRequest(
@ -95,13 +97,15 @@ public class CreatePremiumListCommandTest<C extends CreatePremiumListCommand>
}
@Test
public void testRun_noInputFileSpecified_throwsException() {
@MockitoSettings(strictness = Strictness.LENIENT)
void testRun_noInputFileSpecified_throwsException() {
ParameterException thrown = assertThrows(ParameterException.class, this::runCommand);
assertThat(thrown).hasMessageThat().contains("The following option is required");
}
@Test
public void testRun_invalidInputData() throws Exception {
@MockitoSettings(strictness = Strictness.LENIENT)
void testRun_invalidInputData() throws Exception {
premiumTermsPath =
writeToNamedTmpFile(
"tmp_file2",

View file

@ -26,7 +26,7 @@ import static org.joda.time.DateTimeZone.UTC;
import static org.junit.Assert.assertThrows;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
import com.beust.jcommander.ParameterException;
@ -39,23 +39,23 @@ import java.io.IOException;
import java.util.Optional;
import org.joda.money.CurrencyUnit;
import org.joda.time.DateTime;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentMatchers;
import org.mockito.Mock;
/** Unit tests for {@link CreateRegistrarCommand}. */
public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarCommand> {
class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarCommand> {
@Mock private AppEngineConnection connection;
@Before
public void init() {
@BeforeEach
void beforeEach() {
command.setConnection(connection);
}
@Test
public void testSuccess() throws Exception {
void testSuccess() throws Exception {
DateTime before = DateTime.now(UTC);
runCommandForced(
"--name=blobio",
@ -102,7 +102,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testSuccess_alsoSaveToCloudSql() throws Exception {
void testSuccess_alsoSaveToCloudSql() throws Exception {
runCommandForced(
"--name=blobio",
"--password=\"some_password\"",
@ -124,7 +124,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testSuccess_quotedPassword() throws Exception {
void testSuccess_quotedPassword() throws Exception {
runCommandForced(
"--name=blobio",
"--password=\"some_password\"",
@ -145,7 +145,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testSuccess_registrarTypeFlag() throws Exception {
void testSuccess_registrarTypeFlag() throws Exception {
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -165,7 +165,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testSuccess_registrarStateFlag() throws Exception {
void testSuccess_registrarStateFlag() throws Exception {
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -187,7 +187,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testSuccess_allowedTldsInNonProductionEnvironment() throws Exception {
void testSuccess_allowedTldsInNonProductionEnvironment() throws Exception {
createTlds("xn--q9jyb4c", "foobar");
runCommandInEnvironment(
@ -214,7 +214,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testSuccess_allowedTldsInPDT() throws Exception {
void testSuccess_allowedTldsInPDT() throws Exception {
createTlds("xn--q9jyb4c", "foobar");
runCommandInEnvironment(
@ -241,7 +241,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testSuccess_groupCreationCanBeDisabled() throws Exception {
void testSuccess_groupCreationCanBeDisabled() throws Exception {
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -256,11 +256,11 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--cc US",
"clientz");
verifyZeroInteractions(connection);
verifyNoInteractions(connection);
}
@Test
public void testFailure_groupCreationFails() throws Exception {
void testFailure_groupCreationFails() throws Exception {
when(connection.sendPostRequest(
ArgumentMatchers.anyString(),
ArgumentMatchers.anyMap(),
@ -287,7 +287,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testSuccess_groupCreationDoesntOccurOnAlphaEnv() throws Exception {
void testSuccess_groupCreationDoesntOccurOnAlphaEnv() throws Exception {
runCommandInEnvironment(
RegistryToolEnvironment.ALPHA,
"--name=blobio",
@ -303,11 +303,11 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--force",
"clientz");
verifyZeroInteractions(connection);
verifyNoInteractions(connection);
}
@Test
public void testSuccess_ipAllowListFlag() throws Exception {
void testSuccess_ipAllowListFlag() throws Exception {
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -331,7 +331,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testSuccess_ipAllowListFlagNull() throws Exception {
void testSuccess_ipAllowListFlagNull() throws Exception {
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -353,7 +353,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testSuccess_clientCertFileFlag() throws Exception {
void testSuccess_clientCertFileFlag() throws Exception {
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -376,7 +376,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testSuccess_clientCertHashFlag() throws Exception {
void testSuccess_clientCertHashFlag() throws Exception {
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -399,7 +399,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testSuccess_failoverClientCertFileFlag() throws Exception {
void testSuccess_failoverClientCertFileFlag() throws Exception {
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -425,7 +425,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testSuccess_ianaId() throws Exception {
void testSuccess_ianaId() throws Exception {
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -446,7 +446,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testSuccess_billingId() throws Exception {
void testSuccess_billingId() throws Exception {
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -468,7 +468,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testSuccess_poNumber() throws Exception {
void testSuccess_poNumber() throws Exception {
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -490,7 +490,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testSuccess_billingAccountMap() throws Exception {
void testSuccess_billingAccountMap() throws Exception {
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -513,7 +513,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testFailure_billingAccountMap_doesNotContainEntryForTldAllowed() {
void testFailure_billingAccountMap_doesNotContainEntryForTldAllowed() {
createTlds("foo");
IllegalArgumentException thrown =
@ -541,7 +541,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testSuccess_billingAccountMap_onlyAppliesToRealRegistrar() throws Exception {
void testSuccess_billingAccountMap_onlyAppliesToRealRegistrar() throws Exception {
createTlds("foo");
runCommandForced(
@ -565,7 +565,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testSuccess_streetAddress() throws Exception {
void testSuccess_streetAddress() throws Exception {
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -597,7 +597,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testSuccess_email() throws Exception {
void testSuccess_email() throws Exception {
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -619,7 +619,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testSuccess_fallBackToIcannReferralEmail() throws Exception {
void testSuccess_fallBackToIcannReferralEmail() throws Exception {
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -640,7 +640,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testSuccess_url() throws Exception {
void testSuccess_url() throws Exception {
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -662,7 +662,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testSuccess_phone() throws Exception {
void testSuccess_phone() throws Exception {
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -684,7 +684,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testSuccess_optionalParamsAsNull() throws Exception {
void testSuccess_optionalParamsAsNull() throws Exception {
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -715,7 +715,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testSuccess_optionalParamsAsEmptyString() throws Exception {
void testSuccess_optionalParamsAsEmptyString() throws Exception {
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -746,7 +746,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testSuccess_blockPremiumNames() throws Exception {
void testSuccess_blockPremiumNames() throws Exception {
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -768,7 +768,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testSuccess_noBlockPremiumNames() throws Exception {
void testSuccess_noBlockPremiumNames() throws Exception {
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -790,7 +790,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testSuccess_registryLockAllowed() throws Exception {
void testSuccess_registryLockAllowed() throws Exception {
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -812,7 +812,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testSuccess_registryLockDisallowed() throws Exception {
void testSuccess_registryLockDisallowed() throws Exception {
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -834,7 +834,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testFailure_badPhoneNumber() {
void testFailure_badPhoneNumber() {
ParameterException thrown =
assertThrows(
ParameterException.class,
@ -857,7 +857,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testFailure_badPhoneNumber2() {
void testFailure_badPhoneNumber2() {
ParameterException thrown =
assertThrows(
ParameterException.class,
@ -880,7 +880,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testSuccess_fax() throws Exception {
void testSuccess_fax() throws Exception {
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -902,7 +902,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testFailure_missingRegistrarType() {
void testFailure_missingRegistrarType() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -922,7 +922,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testFailure_invalidRegistrarType() {
void testFailure_invalidRegistrarType() {
assertThrows(
ParameterException.class,
() ->
@ -940,7 +940,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testFailure_invalidRegistrarState() {
void testFailure_invalidRegistrarState() {
assertThrows(
ParameterException.class,
() ->
@ -961,7 +961,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testFailure_allowedTldDoesNotExist() {
void testFailure_allowedTldDoesNotExist() {
assertThrows(
IllegalArgumentException.class,
() ->
@ -982,7 +982,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testFailure_allowedTldsInRealWithoutAbuseContact() {
void testFailure_allowedTldsInRealWithoutAbuseContact() {
createTlds("xn--q9jyb4c", "foobar");
IllegalArgumentException thrown =
assertThrows(
@ -1008,7 +1008,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testFailure_invalidIpAllowListFlag() {
void testFailure_invalidIpAllowListFlag() {
assertThrows(
IllegalArgumentException.class,
() ->
@ -1029,7 +1029,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testSuccess_ipAllowListFlagWithNull() {
void testSuccess_ipAllowListFlagWithNull() {
assertThrows(
IllegalArgumentException.class,
() ->
@ -1050,7 +1050,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testFailure_invalidCertFileContents() {
void testFailure_invalidCertFileContents() {
assertThrows(
Exception.class,
() ->
@ -1071,7 +1071,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testFailure_invalidFailoverCertFileContents() {
void testFailure_invalidFailoverCertFileContents() {
assertThrows(
IllegalArgumentException.class,
() ->
@ -1092,7 +1092,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testFailure_certHashAndCertFile() {
void testFailure_certHashAndCertFile() {
assertThrows(
IllegalArgumentException.class,
() ->
@ -1114,7 +1114,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testFailure_certHashNotBase64() {
void testFailure_certHashNotBase64() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -1137,7 +1137,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testFailure_certHashNotA256BitValue() {
void testFailure_certHashNotA256BitValue() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -1160,7 +1160,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testFailure_missingName() {
void testFailure_missingName() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -1181,7 +1181,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testFailure_missingPassword() {
void testFailure_missingPassword() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -1202,7 +1202,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testFailure_emptyPassword() {
void testFailure_emptyPassword() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -1224,7 +1224,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testFailure_clientIdTooShort() {
void testFailure_clientIdTooShort() {
assertThrows(
IllegalArgumentException.class,
() ->
@ -1244,7 +1244,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testFailure_clientIdTooLong() {
void testFailure_clientIdTooLong() {
assertThrows(
IllegalArgumentException.class,
() ->
@ -1264,7 +1264,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testFailure_missingClientId() {
void testFailure_missingClientId() {
assertThrows(
ParameterException.class,
() ->
@ -1284,7 +1284,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testFailure_missingStreetLines() {
void testFailure_missingStreetLines() {
assertThrows(
IllegalArgumentException.class,
() ->
@ -1303,7 +1303,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testFailure_missingCity() {
void testFailure_missingCity() {
assertThrows(
IllegalArgumentException.class,
() ->
@ -1324,7 +1324,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testFailure_missingState() {
void testFailure_missingState() {
assertThrows(
IllegalArgumentException.class,
() ->
@ -1345,7 +1345,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testFailure_missingZip() {
void testFailure_missingZip() {
assertThrows(
IllegalArgumentException.class,
() ->
@ -1366,7 +1366,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testFailure_missingCc() {
void testFailure_missingCc() {
assertThrows(
IllegalArgumentException.class,
() ->
@ -1387,7 +1387,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testFailure_invalidCc() {
void testFailure_invalidCc() {
assertThrows(
IllegalArgumentException.class,
() ->
@ -1409,7 +1409,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testFailure_tooManyStreetLines() {
void testFailure_tooManyStreetLines() {
assertThrows(
IllegalArgumentException.class,
() ->
@ -1432,7 +1432,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testFailure_tooFewStreetLines() {
void testFailure_tooFewStreetLines() {
assertThrows(
IllegalArgumentException.class,
() ->
@ -1452,7 +1452,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testFailure_missingIanaIdForRealRegistrar() {
void testFailure_missingIanaIdForRealRegistrar() {
assertThrows(
IllegalArgumentException.class,
() ->
@ -1471,7 +1471,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testFailure_negativeIanaId() {
void testFailure_negativeIanaId() {
assertThrows(
IllegalArgumentException.class,
() ->
@ -1491,7 +1491,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testFailure_nonIntegerIanaId() {
void testFailure_nonIntegerIanaId() {
assertThrows(
ParameterException.class,
() ->
@ -1511,7 +1511,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testFailure_negativeBillingId() {
void testFailure_negativeBillingId() {
assertThrows(
IllegalArgumentException.class,
() ->
@ -1532,7 +1532,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testFailure_nonIntegerBillingId() {
void testFailure_nonIntegerBillingId() {
assertThrows(
ParameterException.class,
() ->
@ -1553,7 +1553,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testFailure_missingPhonePasscode() {
void testFailure_missingPhonePasscode() {
assertThrows(
IllegalArgumentException.class,
() ->
@ -1572,7 +1572,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testFailure_missingIcannReferralEmail() {
void testFailure_missingIcannReferralEmail() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -1593,7 +1593,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testFailure_passcodeTooShort() {
void testFailure_passcodeTooShort() {
assertThrows(
IllegalArgumentException.class,
() ->
@ -1613,7 +1613,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testFailure_passcodeTooLong() {
void testFailure_passcodeTooLong() {
assertThrows(
IllegalArgumentException.class,
() ->
@ -1633,7 +1633,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testFailure_invalidPasscode() {
void testFailure_invalidPasscode() {
assertThrows(
IllegalArgumentException.class,
() ->
@ -1653,7 +1653,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testFailure_twoClientsSpecified() {
void testFailure_twoClientsSpecified() {
assertThrows(
IllegalArgumentException.class,
() ->
@ -1674,7 +1674,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testFailure_unknownFlag() {
void testFailure_unknownFlag() {
assertThrows(
ParameterException.class,
() ->
@ -1695,7 +1695,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testFailure_alreadyExists() {
void testFailure_alreadyExists() {
persistNewRegistrar("existing", "Existing Registrar", Registrar.Type.REAL, 1L);
IllegalStateException thrown =
assertThrows(
@ -1718,7 +1718,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testFailure_registrarNameSimilarToExisting() {
void testFailure_registrarNameSimilarToExisting() {
// Note that "tHeRe GiStRaR" normalizes identically to "The Registrar", which is created by
// AppEngineRule.
IllegalArgumentException thrown =
@ -1746,7 +1746,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testFailure_clientIdNormalizesToExisting() {
void testFailure_clientIdNormalizesToExisting() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -1772,7 +1772,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testFailure_clientIdIsInvalidFormat() {
void testFailure_clientIdIsInvalidFormat() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -1797,7 +1797,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testFailure_phone() {
void testFailure_phone() {
assertThrows(
ParameterException.class,
() ->
@ -1818,7 +1818,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testFailure_fax() {
void testFailure_fax() {
assertThrows(
ParameterException.class,
() ->
@ -1839,7 +1839,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
}
@Test
public void testFailure_badEmail() {
void testFailure_badEmail() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,

View file

@ -21,23 +21,22 @@ import static org.mockito.Mockito.verify;
import com.google.common.collect.ImmutableMap;
import com.google.common.net.MediaType;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
/** Unit tests for {@link CreateRegistrarGroupsCommand}. */
public class CreateRegistrarGroupsCommandTest extends
CommandTestCase<CreateRegistrarGroupsCommand> {
class CreateRegistrarGroupsCommandTest extends CommandTestCase<CreateRegistrarGroupsCommand> {
@Mock private AppEngineConnection connection;
@Before
public void init() {
@BeforeEach
void beforeEach() {
command.setConnection(connection);
}
@Test
public void test_createGroupsForTwoRegistrars() throws Exception {
void test_createGroupsForTwoRegistrars() throws Exception {
runCommandForced("NewRegistrar", "TheRegistrar");
verify(connection)
.sendPostRequest(
@ -55,7 +54,7 @@ public class CreateRegistrarGroupsCommandTest extends
}
@Test
public void test_throwsExceptionForNonExistentRegistrar() {
void test_throwsExceptionForNonExistentRegistrar() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,

View file

@ -30,20 +30,20 @@ import google.registry.model.registry.label.ReservedList;
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;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link CreateReservedListCommand}. */
public class CreateReservedListCommandTest extends
CreateOrUpdateReservedListCommandTestCase<CreateReservedListCommand> {
class CreateReservedListCommandTest
extends CreateOrUpdateReservedListCommandTestCase<CreateReservedListCommand> {
@Before
public void initTest() {
@BeforeEach
void beforeEach() {
createTlds("xn--q9jyb4c", "soy");
}
@Test
public void testSuccess() throws Exception {
void testSuccess() throws Exception {
runCommandForced("--name=xn--q9jyb4c_common-reserved", "--input=" + reservedTermsPath);
assertThat(ReservedList.get("xn--q9jyb4c_common-reserved")).isPresent();
ReservedList reservedList = ReservedList.get("xn--q9jyb4c_common-reserved").get();
@ -53,13 +53,13 @@ public class CreateReservedListCommandTest extends
}
@Test
public void testSuccess_unspecifiedNameDefaultsToFileName() throws Exception {
void testSuccess_unspecifiedNameDefaultsToFileName() throws Exception {
runCommandForced("--input=" + reservedTermsPath);
assertThat(ReservedList.get("xn--q9jyb4c_common-reserved")).isPresent();
}
@Test
public void testSuccess_timestampsSetCorrectly() throws Exception {
void testSuccess_timestampsSetCorrectly() throws Exception {
DateTime before = DateTime.now(UTC);
runCommandForced("--input=" + reservedTermsPath);
assertThat(ReservedList.get("xn--q9jyb4c_common-reserved")).isPresent();
@ -69,28 +69,28 @@ public class CreateReservedListCommandTest extends
}
@Test
public void testSuccess_shouldPublishDefaultsToTrue() throws Exception {
void testSuccess_shouldPublishDefaultsToTrue() throws Exception {
runCommandForced("--input=" + reservedTermsPath);
assertThat(ReservedList.get("xn--q9jyb4c_common-reserved")).isPresent();
assertThat(ReservedList.get("xn--q9jyb4c_common-reserved").get().getShouldPublish()).isTrue();
}
@Test
public void testSuccess_shouldPublishSetToTrue_works() throws Exception {
void testSuccess_shouldPublishSetToTrue_works() throws Exception {
runCommandForced("--input=" + reservedTermsPath, "--should_publish=true");
assertThat(ReservedList.get("xn--q9jyb4c_common-reserved")).isPresent();
assertThat(ReservedList.get("xn--q9jyb4c_common-reserved").get().getShouldPublish()).isTrue();
}
@Test
public void testSuccess_shouldPublishSetToFalse_works() throws Exception {
void testSuccess_shouldPublishSetToFalse_works() throws Exception {
runCommandForced("--input=" + reservedTermsPath, "--should_publish=false");
assertThat(ReservedList.get("xn--q9jyb4c_common-reserved")).isPresent();
assertThat(ReservedList.get("xn--q9jyb4c_common-reserved").get().getShouldPublish()).isFalse();
}
@Test
public void testFailure_reservedListWithThatNameAlreadyExists() {
void testFailure_reservedListWithThatNameAlreadyExists() {
ReservedList rl = persistReservedList("xn--q9jyb4c_foo", "jones,FULLY_BLOCKED");
persistResource(Registry.get("xn--q9jyb4c").asBuilder().setReservedLists(rl).build());
IllegalArgumentException thrown =
@ -101,90 +101,90 @@ public class CreateReservedListCommandTest extends
}
@Test
public void testNamingRules_commonReservedList() throws Exception {
void testNamingRules_commonReservedList() throws Exception {
runCommandForced("--name=common_abuse-list", "--input=" + reservedTermsPath);
assertThat(ReservedList.get("common_abuse-list")).isPresent();
}
@Test
public void testNamingRules_tldThatDoesNotExist_succeedsWithOverride() throws Exception {
void testNamingRules_tldThatDoesNotExist_succeedsWithOverride() throws Exception {
runNameTestWithOverride("footld_reserved-list");
}
@Test
public void testNamingRules_tldThatDoesNotExist_failsWithoutOverride() {
void testNamingRules_tldThatDoesNotExist_failsWithoutOverride() {
runNameTestExpectedFailure("footld_reserved-list", "TLD footld does not exist");
}
@Test
public void testNamingRules_underscoreIsMissing_succeedsWithOverride() throws Exception {
void testNamingRules_underscoreIsMissing_succeedsWithOverride() throws Exception {
runNameTestWithOverride("random-reserved-list");
}
@Test
public void testNamingRules_underscoreIsMissing_failsWithoutOverride() {
void testNamingRules_underscoreIsMissing_failsWithoutOverride() {
runNameTestExpectedFailure("random-reserved-list", INVALID_FORMAT_ERROR_MESSAGE);
}
@Test
public void testNamingRules_secondHalfOfNameIsMissing_succeedsWithOverride() throws Exception {
void testNamingRules_secondHalfOfNameIsMissing_succeedsWithOverride() throws Exception {
runNameTestWithOverride("soy_");
}
@Test
public void testNamingRules_secondHalfOfNameIsMissing_failsWithoutOverride() {
void testNamingRules_secondHalfOfNameIsMissing_failsWithoutOverride() {
runNameTestExpectedFailure("soy_", INVALID_FORMAT_ERROR_MESSAGE);
}
@Test
public void testNamingRules_onlyTldIsSpecifiedAsName_succeedsWithOverride() throws Exception {
void testNamingRules_onlyTldIsSpecifiedAsName_succeedsWithOverride() throws Exception {
runNameTestWithOverride("soy");
}
@Test
public void testNamingRules_onlyTldIsSpecifiedAsName_failsWithoutOverride() {
void testNamingRules_onlyTldIsSpecifiedAsName_failsWithoutOverride() {
runNameTestExpectedFailure("soy", INVALID_FORMAT_ERROR_MESSAGE);
}
@Test
public void testNamingRules_commonAsListName_succeedsWithOverride() throws Exception {
void testNamingRules_commonAsListName_succeedsWithOverride() throws Exception {
runNameTestWithOverride("invalidtld_common");
}
@Test
public void testNamingRules_commonAsListName_failsWithoutOverride() {
void testNamingRules_commonAsListName_failsWithoutOverride() {
runNameTestExpectedFailure("invalidtld_common", "TLD invalidtld does not exist");
}
@Test
public void testNamingRules_too_many_underscores_succeedsWithOverride() throws Exception {
void testNamingRules_too_many_underscores_succeedsWithOverride() throws Exception {
runNameTestWithOverride("soy_buffalo_buffalo_buffalo");
}
@Test
public void testNamingRules_too_many_underscores_failsWithoutOverride() {
void testNamingRules_too_many_underscores_failsWithoutOverride() {
runNameTestExpectedFailure("soy_buffalo_buffalo_buffalo", INVALID_FORMAT_ERROR_MESSAGE);
}
@Test
public void testNamingRules_withWeirdCharacters_succeedsWithOverride() throws Exception {
void testNamingRules_withWeirdCharacters_succeedsWithOverride() throws Exception {
runNameTestWithOverride("soy_$oy");
}
@Test
public void testNamingRules_withWeirdCharacters_failsWithoutOverride() {
void testNamingRules_withWeirdCharacters_failsWithoutOverride() {
runNameTestExpectedFailure("soy_$oy", INVALID_FORMAT_ERROR_MESSAGE);
}
@Test
public void testSaveToCloudSql_succeeds() throws Exception {
void testSaveToCloudSql_succeeds() throws Exception {
runCommandForced("--name=xn--q9jyb4c_common-reserved", "--input=" + reservedTermsPath);
verifyXnq9jyb4cInDatastore();
verifyXnq9jyb4cInCloudSql();
}
@Test
public void testSaveToCloudSql_noExceptionThrownWhenSaveFail() throws Exception {
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.
ReservedListSqlDao.save(

View file

@ -38,14 +38,14 @@ import java.math.BigDecimal;
import org.joda.money.Money;
import org.joda.time.DateTime;
import org.joda.time.Duration;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link CreateTldCommand}. */
public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
@Before
public void init() {
@BeforeEach
void beforeEach() {
persistReservedList("common_abuse", "baa,FULLY_BLOCKED");
persistReservedList("xn--q9jyb4c_abuse", "lamb,FULLY_BLOCKED");
persistReservedList("tld_banned", "kilo,FULLY_BLOCKED", "lima,FULLY_BLOCKED");
@ -55,7 +55,7 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
}
@Test
public void testSuccess() throws Exception {
void testSuccess() throws Exception {
DateTime before = DateTime.now(UTC);
runCommandForced("xn--q9jyb4c", "--roid_suffix=Q9JYB4C", "--dns_writers=FooDnsWriter");
DateTime after = DateTime.now(UTC);
@ -72,7 +72,7 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
}
@Test
public void testFailure_multipleArguments() {
void testFailure_multipleArguments() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -83,7 +83,7 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
}
@Test
public void testFailure_multipleDuplicateArguments() {
void testFailure_multipleDuplicateArguments() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -94,7 +94,7 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
}
@Test
public void testSuccess_initialTldStateFlag() throws Exception {
void testSuccess_initialTldStateFlag() throws Exception {
runCommandForced(
"--initial_tld_state=GENERAL_AVAILABILITY",
"--roid_suffix=Q9JYB4C",
@ -105,7 +105,7 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
}
@Test
public void testSuccess_initialRenewBillingCostFlag() throws Exception {
void testSuccess_initialRenewBillingCostFlag() throws Exception {
runCommandForced(
"--initial_renew_billing_cost=\"USD 42.42\"",
"--roid_suffix=Q9JYB4C",
@ -116,7 +116,7 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
}
@Test
public void testSuccess_eapFeeSchedule() throws Exception {
void testSuccess_eapFeeSchedule() throws Exception {
DateTime now = DateTime.now(UTC);
DateTime tomorrow = now.plusDays(1);
runCommandForced(
@ -137,7 +137,7 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
}
@Test
public void testSuccess_addGracePeriodFlag() throws Exception {
void testSuccess_addGracePeriodFlag() throws Exception {
runCommandForced(
"--add_grace_period=PT300S",
"--roid_suffix=Q9JYB4C",
@ -147,27 +147,27 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
}
@Test
public void testSuccess_roidSuffixWorks() throws Exception {
void testSuccess_roidSuffixWorks() throws Exception {
runCommandForced("--roid_suffix=RSUFFIX", "--dns_writers=VoidDnsWriter", "tld");
assertThat(Registry.get("tld").getRoidSuffix()).isEqualTo("RSUFFIX");
}
@Test
public void testSuccess_escrow() throws Exception {
void testSuccess_escrow() throws Exception {
runCommandForced(
"--escrow=true", "--roid_suffix=Q9JYB4C", "--dns_writers=VoidDnsWriter", "xn--q9jyb4c");
assertThat(Registry.get("xn--q9jyb4c").getEscrowEnabled()).isTrue();
}
@Test
public void testSuccess_noEscrow() throws Exception {
void testSuccess_noEscrow() throws Exception {
runCommandForced(
"--escrow=false", "--roid_suffix=Q9JYB4C", "--dns_writers=VoidDnsWriter", "xn--q9jyb4c");
assertThat(Registry.get("xn--q9jyb4c").getEscrowEnabled()).isFalse();
}
@Test
public void testSuccess_redemptionGracePeriodFlag() throws Exception {
void testSuccess_redemptionGracePeriodFlag() throws Exception {
runCommandForced(
"--redemption_grace_period=PT300S",
"--roid_suffix=Q9JYB4C",
@ -178,7 +178,7 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
}
@Test
public void testSuccess_pendingDeleteLengthFlag() throws Exception {
void testSuccess_pendingDeleteLengthFlag() throws Exception {
runCommandForced(
"--pending_delete_length=PT300S",
"--roid_suffix=Q9JYB4C",
@ -188,7 +188,7 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
}
@Test
public void testSuccess_automaticTransferLengthFlag() throws Exception {
void testSuccess_automaticTransferLengthFlag() throws Exception {
runCommandForced(
"--automatic_transfer_length=PT300S",
"--roid_suffix=Q9JYB4C",
@ -199,7 +199,7 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
}
@Test
public void testSuccess_createBillingCostFlag() throws Exception {
void testSuccess_createBillingCostFlag() throws Exception {
runCommandForced(
"--create_billing_cost=\"USD 42.42\"",
"--roid_suffix=Q9JYB4C",
@ -209,7 +209,7 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
}
@Test
public void testSuccess_restoreBillingCostFlag() throws Exception {
void testSuccess_restoreBillingCostFlag() throws Exception {
runCommandForced(
"--restore_billing_cost=\"USD 42.42\"",
"--roid_suffix=Q9JYB4C",
@ -220,7 +220,7 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
}
@Test
public void testSuccess_serverStatusChangeCostFlag() throws Exception {
void testSuccess_serverStatusChangeCostFlag() throws Exception {
runCommandForced(
"--server_status_change_cost=\"USD 42.42\"",
"--roid_suffix=Q9JYB4C",
@ -231,7 +231,7 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
}
@Test
public void testSuccess_nonUsdBillingCostFlag() throws Exception {
void testSuccess_nonUsdBillingCostFlag() throws Exception {
runCommandForced(
"--create_billing_cost=\"JPY 12345\"",
"--restore_billing_cost=\"JPY 67890\"",
@ -247,7 +247,7 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
}
@Test
public void testSuccess_multipartTld() throws Exception {
void testSuccess_multipartTld() throws Exception {
runCommandForced("co.uk", "--roid_suffix=COUK", "--dns_writers=VoidDnsWriter");
Registry registry = Registry.get("co.uk");
@ -259,7 +259,7 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
}
@Test
public void testSuccess_setReservedLists() throws Exception {
void testSuccess_setReservedLists() throws Exception {
runCommandForced(
"--reserved_lists=xn--q9jyb4c_abuse,common_abuse",
"--roid_suffix=Q9JYB4C",
@ -270,7 +270,7 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
}
@Test
public void testFailure_invalidAddGracePeriod() {
void testFailure_invalidAddGracePeriod() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -284,7 +284,7 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
}
@Test
public void testFailure_invalidRedemptionGracePeriod() {
void testFailure_invalidRedemptionGracePeriod() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -298,7 +298,7 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
}
@Test
public void testFailure_invalidPendingDeleteLength() {
void testFailure_invalidPendingDeleteLength() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -312,7 +312,7 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
}
@Test
public void testFailure_invalidTldState() {
void testFailure_invalidTldState() {
ParameterException thrown =
assertThrows(
ParameterException.class,
@ -326,7 +326,7 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
}
@Test
public void testFailure_bothTldStateFlags() {
void testFailure_bothTldStateFlags() {
DateTime now = DateTime.now(UTC);
IllegalArgumentException thrown =
assertThrows(
@ -345,7 +345,7 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
}
@Test
public void testFailure_negativeInitialRenewBillingCost() {
void testFailure_negativeInitialRenewBillingCost() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -359,7 +359,7 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
}
@Test
public void testFailure_invalidEapCurrency() {
void testFailure_invalidEapCurrency() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -373,7 +373,7 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
}
@Test
public void testFailure_noTldName() {
void testFailure_noTldName() {
ParameterException thrown = assertThrows(ParameterException.class, this::runCommandForced);
assertThat(thrown)
.hasMessageThat()
@ -381,7 +381,7 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
}
@Test
public void testFailure_noDnsWriter() {
void testFailure_noDnsWriter() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -390,7 +390,7 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
}
@Test
public void testFailure_alreadyExists() {
void testFailure_alreadyExists() {
createTld("xn--q9jyb4c");
IllegalStateException thrown =
assertThrows(
@ -402,7 +402,7 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
}
@Test
public void testFailure_tldStartsWithDigit() {
void testFailure_tldStartsWithDigit() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -411,7 +411,7 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
}
@Test
public void testSuccess_setAllowedRegistrants() throws Exception {
void testSuccess_setAllowedRegistrants() throws Exception {
runCommandForced(
"--allowed_registrants=alice,bob",
"--roid_suffix=Q9JYB4C",
@ -422,7 +422,7 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
}
@Test
public void testSuccess_setAllowedNameservers() throws Exception {
void testSuccess_setAllowedNameservers() throws Exception {
runCommandForced(
"--allowed_nameservers=ns1.example.com,ns2.example.com",
"--roid_suffix=Q9JYB4C",
@ -433,22 +433,22 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
}
@Test
public void testSuccess_setCommonReservedListOnTld() throws Exception {
void testSuccess_setCommonReservedListOnTld() throws Exception {
runSuccessfulReservedListsTest("common_abuse");
}
@Test
public void testSuccess_setTldSpecificReservedListOnTld() throws Exception {
void testSuccess_setTldSpecificReservedListOnTld() throws Exception {
runSuccessfulReservedListsTest("xn--q9jyb4c_abuse");
}
@Test
public void testSuccess_setCommonReservedListAndTldSpecificReservedListOnTld() throws Exception {
void testSuccess_setCommonReservedListAndTldSpecificReservedListOnTld() throws Exception {
runSuccessfulReservedListsTest("common_abuse,xn--q9jyb4c_abuse");
}
@Test
public void testFailure_setReservedListFromOtherTld() {
void testFailure_setReservedListFromOtherTld() {
runFailureReservedListsTest(
"tld_banned",
IllegalArgumentException.class,
@ -456,12 +456,12 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
}
@Test
public void testSuccess_setReservedListFromOtherTld_withOverride() throws Exception {
void testSuccess_setReservedListFromOtherTld_withOverride() throws Exception {
runReservedListsTestOverride("tld_banned");
}
@Test
public void testFailure_setCommonAndReservedListFromOtherTld() {
void testFailure_setCommonAndReservedListFromOtherTld() {
runFailureReservedListsTest(
"common_abuse,tld_banned",
IllegalArgumentException.class,
@ -469,7 +469,7 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
}
@Test
public void testSuccess_setCommonAndReservedListFromOtherTld_withOverride() throws Exception {
void testSuccess_setCommonAndReservedListFromOtherTld_withOverride() throws Exception {
runReservedListsTestOverride("common_abuse,tld_banned");
String errMsg =
"Error overridden: The reserved list(s) tld_banned "
@ -478,7 +478,7 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
}
@Test
public void testFailure_setMultipleReservedListsFromOtherTld() {
void testFailure_setMultipleReservedListsFromOtherTld() {
runFailureReservedListsTest(
"tld_banned,soy_expurgated",
IllegalArgumentException.class,
@ -486,12 +486,12 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
}
@Test
public void testSuccess_setMultipleReservedListsFromOtherTld_withOverride() throws Exception {
void testSuccess_setMultipleReservedListsFromOtherTld_withOverride() throws Exception {
runReservedListsTestOverride("tld_banned,soy_expurgated");
}
@Test
public void testFailure_setNonExistentReservedLists() {
void testFailure_setNonExistentReservedLists() {
runFailureReservedListsTest(
"xn--q9jyb4c_asdf,common_asdsdgh",
IllegalArgumentException.class,
@ -499,7 +499,7 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
}
@Test
public void testSuccess_setPremiumList() throws Exception {
void testSuccess_setPremiumList() throws Exception {
runCommandForced(
"--premium_list=xn--q9jyb4c",
"--roid_suffix=Q9JYB4C",
@ -509,7 +509,7 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
}
@Test
public void testSuccess_setDriveFolderIdToValue() throws Exception {
void testSuccess_setDriveFolderIdToValue() throws Exception {
runCommandForced(
"--drive_folder_id=madmax2030",
"--roid_suffix=Q9JYB4C",
@ -519,7 +519,7 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
}
@Test
public void testSuccess_setDriveFolderIdToNull() throws Exception {
void testSuccess_setDriveFolderIdToNull() throws Exception {
runCommandForced(
"--drive_folder_id=null",
"--roid_suffix=Q9JYB4C",
@ -529,7 +529,7 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
}
@Test
public void testFailure_setPremiumListThatDoesntExist() {
void testFailure_setPremiumListThatDoesntExist() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -543,7 +543,7 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
}
@Test
public void testFailure_specifiedDnsWriters_dontExist() {
void testFailure_specifiedDnsWriters_dontExist() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,

View file

@ -29,19 +29,22 @@ import static org.mockito.Mockito.when;
import com.google.common.collect.ImmutableMap;
import com.google.common.net.MediaType;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
/** Unit tests for {@link CurlCommand}. */
public class CurlCommandTest extends CommandTestCase<CurlCommand> {
class CurlCommandTest extends CommandTestCase<CurlCommand> {
@Mock private AppEngineConnection connection;
@Mock private AppEngineConnection connectionForService;
@Before
public void init() {
@BeforeEach
void beforeEach() {
command.setConnection(connection);
when(connection.withService(any())).thenReturn(connectionForService);
}
@ -49,7 +52,7 @@ public class CurlCommandTest extends CommandTestCase<CurlCommand> {
@Captor ArgumentCaptor<ImmutableMap<String, String>> urlParamCaptor;
@Test
public void testGetInvocation() throws Exception {
void testGetInvocation() throws Exception {
runCommand("--path=/foo/bar?a=1&b=2", "--service=TOOLS");
verify(connection).withService(TOOLS);
verifyNoMoreInteractions(connection);
@ -58,7 +61,7 @@ public class CurlCommandTest extends CommandTestCase<CurlCommand> {
}
@Test
public void testExplicitGetInvocation() throws Exception {
void testExplicitGetInvocation() throws Exception {
runCommand("--path=/foo/bar?a=1&b=2", "--request=GET", "--service=BACKEND");
verify(connection).withService(BACKEND);
verifyNoMoreInteractions(connection);
@ -67,7 +70,7 @@ public class CurlCommandTest extends CommandTestCase<CurlCommand> {
}
@Test
public void testPostInvocation() throws Exception {
void testPostInvocation() throws Exception {
runCommand("--path=/foo/bar?a=1&b=2", "--data=some data", "--service=DEFAULT");
verify(connection).withService(DEFAULT);
verifyNoMoreInteractions(connection);
@ -80,7 +83,7 @@ public class CurlCommandTest extends CommandTestCase<CurlCommand> {
}
@Test
public void testPostInvocation_withContentType() throws Exception {
void testPostInvocation_withContentType() throws Exception {
runCommand(
"--path=/foo/bar?a=1&b=2",
"--data=some data",
@ -97,7 +100,8 @@ public class CurlCommandTest extends CommandTestCase<CurlCommand> {
}
@Test
public void testPostInvocation_badContentType() throws Exception {
@MockitoSettings(strictness = Strictness.LENIENT)
void testPostInvocation_badContentType() throws Exception {
assertThrows(
IllegalArgumentException.class,
() ->
@ -111,7 +115,7 @@ public class CurlCommandTest extends CommandTestCase<CurlCommand> {
}
@Test
public void testMultiDataPost() throws Exception {
void testMultiDataPost() throws Exception {
runCommand(
"--path=/foo/bar?a=1&b=2", "--data=first=100", "-d", "second=200", "--service=PUBAPI");
verify(connection).withService(PUBAPI);
@ -125,7 +129,7 @@ public class CurlCommandTest extends CommandTestCase<CurlCommand> {
}
@Test
public void testDataDoesntSplit() throws Exception {
void testDataDoesntSplit() throws Exception {
runCommand(
"--path=/foo/bar?a=1&b=2", "--data=one,two", "--service=PUBAPI");
verify(connection).withService(PUBAPI);
@ -139,7 +143,7 @@ public class CurlCommandTest extends CommandTestCase<CurlCommand> {
}
@Test
public void testExplicitPostInvocation() throws Exception {
void testExplicitPostInvocation() throws Exception {
runCommand("--path=/foo/bar?a=1&b=2", "--request=POST", "--service=TOOLS");
verify(connection).withService(TOOLS);
verifyNoMoreInteractions(connection);
@ -152,7 +156,8 @@ public class CurlCommandTest extends CommandTestCase<CurlCommand> {
}
@Test
public void testGetWithBody() throws Exception {
@MockitoSettings(strictness = Strictness.LENIENT)
void testGetWithBody() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,

View file

@ -27,12 +27,11 @@ import google.registry.model.domain.token.AllocationToken.TokenType;
import google.registry.model.reporting.HistoryEntry;
import java.util.Collection;
import javax.annotation.Nullable;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link DeleteAllocationTokensCommand}. */
public class DeleteAllocationTokensCommandTest
extends CommandTestCase<DeleteAllocationTokensCommand> {
class DeleteAllocationTokensCommandTest extends CommandTestCase<DeleteAllocationTokensCommand> {
private AllocationToken preRed1;
private AllocationToken preRed2;
@ -41,8 +40,8 @@ public class DeleteAllocationTokensCommandTest
private AllocationToken othrRed;
private AllocationToken othrNot;
@Before
public void init() {
@BeforeEach
void beforeEach() {
createTlds("foo", "bar");
preRed1 = persistToken("prefix12345AA", null, true);
preRed2 = persistToken("prefixgh8907a", null, true);
@ -53,7 +52,7 @@ public class DeleteAllocationTokensCommandTest
}
@Test
public void test_deleteOnlyUnredeemedTokensWithPrefix() throws Exception {
void test_deleteOnlyUnredeemedTokensWithPrefix() throws Exception {
runCommandForced("--prefix", "prefix");
assertThat(reloadTokens(preNot1, preNot2)).isEmpty();
assertThat(reloadTokens(preRed1, preRed2, othrRed, othrNot))
@ -61,7 +60,7 @@ public class DeleteAllocationTokensCommandTest
}
@Test
public void test_deleteSingleAllocationToken() throws Exception {
void test_deleteSingleAllocationToken() throws Exception {
runCommandForced("--prefix", "asdgfho7HASDS");
assertThat(reloadTokens(othrNot)).isEmpty();
assertThat(reloadTokens(preRed1, preRed2, preNot1, preNot2, othrRed))
@ -69,7 +68,7 @@ public class DeleteAllocationTokensCommandTest
}
@Test
public void test_deleteParticularTokens() throws Exception {
void test_deleteParticularTokens() throws Exception {
runCommandForced("--tokens", "prefix2978204,asdgfho7HASDS");
assertThat(reloadTokens(preNot1, othrNot)).isEmpty();
assertThat(reloadTokens(preRed1, preRed2, preNot2, othrRed))
@ -77,14 +76,14 @@ public class DeleteAllocationTokensCommandTest
}
@Test
public void test_deleteTokensWithNonExistentPrefix_doesNothing() throws Exception {
void test_deleteTokensWithNonExistentPrefix_doesNothing() throws Exception {
runCommandForced("--prefix", "nonexistent");
assertThat(reloadTokens(preRed1, preRed2, preNot1, preNot2, othrRed, othrNot))
.containsExactly(preRed1, preRed2, preNot1, preNot2, othrRed, othrNot);
}
@Test
public void test_dryRun_deletesNothing() throws Exception {
void test_dryRun_deletesNothing() throws Exception {
runCommandForced("--prefix", "prefix", "--dry_run");
assertThat(reloadTokens(preRed1, preRed2, preNot1, preNot2, othrRed, othrNot))
.containsExactly(preRed1, preRed2, preNot1, preNot2, othrRed, othrNot);
@ -92,7 +91,7 @@ public class DeleteAllocationTokensCommandTest
}
@Test
public void test_defaultOptions_doesntDeletePerDomainTokens() throws Exception {
void test_defaultOptions_doesntDeletePerDomainTokens() throws Exception {
AllocationToken preDom1 = persistToken("prefixasdfg897as", "foo.bar", false);
AllocationToken preDom2 = persistToken("prefix98HAZXadbn", "foo.bar", true);
runCommandForced("--prefix", "prefix");
@ -102,7 +101,7 @@ public class DeleteAllocationTokensCommandTest
}
@Test
public void test_withDomains_doesDeletePerDomainTokens() throws Exception {
void test_withDomains_doesDeletePerDomainTokens() throws Exception {
AllocationToken preDom1 = persistToken("prefixasdfg897as", "foo.bar", false);
AllocationToken preDom2 = persistToken("prefix98HAZXadbn", "foo.bar", true);
runCommandForced("--prefix", "prefix", "--with_domains");
@ -112,7 +111,7 @@ public class DeleteAllocationTokensCommandTest
}
@Test
public void testSkipUnlimitedUseTokens() throws Exception {
void testSkipUnlimitedUseTokens() throws Exception {
AllocationToken unlimitedUseToken =
persistResource(
new AllocationToken.Builder()
@ -124,7 +123,7 @@ public class DeleteAllocationTokensCommandTest
}
@Test
public void test_batching() throws Exception {
void test_batching() throws Exception {
for (int i = 0; i < 50; i++) {
persistToken(String.format("batch%2d", i), null, i % 2 == 0);
}
@ -134,7 +133,7 @@ public class DeleteAllocationTokensCommandTest
}
@Test
public void test_prefixIsRequired() {
void test_prefixIsRequired() {
IllegalArgumentException thrown =
assertThrows(IllegalArgumentException.class, this::runCommandForced);
assertThat(thrown)
@ -143,7 +142,7 @@ public class DeleteAllocationTokensCommandTest
}
@Test
public void testFailure_bothPrefixAndTokens() {
void testFailure_bothPrefixAndTokens() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -154,7 +153,7 @@ public class DeleteAllocationTokensCommandTest
}
@Test
public void testFailure_emptyPrefix() {
void testFailure_emptyPrefix() {
IllegalArgumentException thrown =
assertThrows(IllegalArgumentException.class, () -> runCommandForced("--prefix", ""));
assertThat(thrown).hasMessageThat().isEqualTo("Provided prefix should not be blank");

View file

@ -17,39 +17,39 @@ package google.registry.tools;
import static org.junit.Assert.assertThrows;
import com.beust.jcommander.ParameterException;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link DeleteDomainCommand}. */
public class DeleteDomainCommandTest extends EppToolCommandTestCase<DeleteDomainCommand> {
class DeleteDomainCommandTest extends EppToolCommandTestCase<DeleteDomainCommand> {
@Test
public void testSuccess() throws Exception {
void testSuccess() throws Exception {
runCommand("--client=NewRegistrar", "--domain_name=example.tld", "--force", "--reason=Test");
eppVerifier.verifySent("domain_delete.xml");
}
@Test
public void testSuccess_multipleWordReason() throws Exception {
void testSuccess_multipleWordReason() throws Exception {
runCommandForced(
"--client=NewRegistrar", "--domain_name=example.tld", "--reason=\"Test test\"");
eppVerifier.verifySent("domain_delete_multiple_word_reason.xml");
}
@Test
public void testSuccess_immediately() throws Exception {
void testSuccess_immediately() throws Exception {
runCommandForced(
"--client=NewRegistrar", "--domain_name=example.tld", "--immediately", "--reason=Test");
eppVerifier.expectSuperuser().verifySent("domain_delete_immediately.xml");
}
@Test
public void testSuccess_requestedByRegistrarFalse() throws Exception {
void testSuccess_requestedByRegistrarFalse() throws Exception {
runCommandForced("--client=NewRegistrar", "--domain_name=example.tld", "--reason=Test");
eppVerifier.verifySent("domain_delete.xml");
}
@Test
public void testSuccess_requestedByRegistrarTrue() throws Exception {
void testSuccess_requestedByRegistrarTrue() throws Exception {
runCommandForced(
"--client=NewRegistrar",
"--domain_name=example.tld",
@ -59,28 +59,28 @@ public class DeleteDomainCommandTest extends EppToolCommandTestCase<DeleteDomain
}
@Test
public void testFailure_noReason() {
void testFailure_noReason() {
assertThrows(
ParameterException.class,
() -> runCommand("--client=NewRegistrar", "--domain_name=example.tld", "--force"));
}
@Test
public void testFailure_missingClientId() {
void testFailure_missingClientId() {
assertThrows(
ParameterException.class,
() -> runCommand("--domain_name=example.tld", "--force", "--reason=Test"));
}
@Test
public void testFailure_missingDomainName() {
void testFailure_missingDomainName() {
assertThrows(
ParameterException.class,
() -> runCommand("--client=NewRegistrar", "--force", "--reason=Test"));
}
@Test
public void testFailure_unknownFlag() {
void testFailure_unknownFlag() {
assertThrows(
ParameterException.class,
() ->
@ -93,7 +93,7 @@ public class DeleteDomainCommandTest extends EppToolCommandTestCase<DeleteDomain
}
@Test
public void testFailure_mainParameter() {
void testFailure_mainParameter() {
assertThrows(
ParameterException.class,
() ->

View file

@ -17,26 +17,26 @@ package google.registry.tools;
import static org.junit.Assert.assertThrows;
import com.beust.jcommander.ParameterException;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link DeleteHostCommand}. */
public class DeleteHostCommandTest extends EppToolCommandTestCase<DeleteHostCommand> {
class DeleteHostCommandTest extends EppToolCommandTestCase<DeleteHostCommand> {
@Test
public void testSuccess() throws Exception {
void testSuccess() throws Exception {
runCommand("--client=NewRegistrar", "--host=ns1.example.tld", "--force", "--reason=Test");
eppVerifier.verifySent("host_delete.xml");
}
@Test
public void testSuccess_multipleWordReason() throws Exception {
void testSuccess_multipleWordReason() throws Exception {
runCommand(
"--client=NewRegistrar", "--host=ns1.example.tld", "--force", "--reason=\"Test test\"");
eppVerifier.verifySent("host_delete_multiple_word_reason.xml");
}
@Test
public void testSuccess_requestedByRegistrarFalse() throws Exception {
void testSuccess_requestedByRegistrarFalse() throws Exception {
runCommand(
"--client=NewRegistrar",
"--host=ns1.example.tld",
@ -47,7 +47,7 @@ public class DeleteHostCommandTest extends EppToolCommandTestCase<DeleteHostComm
}
@Test
public void testSuccess_requestedByRegistrarTrue() throws Exception {
void testSuccess_requestedByRegistrarTrue() throws Exception {
runCommand(
"--client=NewRegistrar",
"--host=ns1.example.tld",
@ -58,28 +58,28 @@ public class DeleteHostCommandTest extends EppToolCommandTestCase<DeleteHostComm
}
@Test
public void testFailure_noReason() {
void testFailure_noReason() {
assertThrows(
ParameterException.class,
() -> runCommand("--client=NewRegistrar", "--host=ns1.example.tld", "--force"));
}
@Test
public void testFailure_missingClientId() {
void testFailure_missingClientId() {
assertThrows(
ParameterException.class,
() -> runCommand("--host=ns1.example.tld", "--force", "--reason=Test"));
}
@Test
public void testFailure_missingHostName() {
void testFailure_missingHostName() {
assertThrows(
ParameterException.class,
() -> runCommand("--client=NewRegistrar", "--force", "--reason=Test"));
}
@Test
public void testFailure_unknownFlag() {
void testFailure_unknownFlag() {
assertThrows(
ParameterException.class,
() ->
@ -92,7 +92,7 @@ public class DeleteHostCommandTest extends EppToolCommandTestCase<DeleteHostComm
}
@Test
public void testFailure_mainParameter() {
void testFailure_mainParameter() {
assertThrows(
ParameterException.class,
() ->

View file

@ -26,13 +26,13 @@ import static org.junit.Assert.assertThrows;
import google.registry.model.registry.Registry;
import google.registry.model.registry.label.PremiumList;
import google.registry.model.registry.label.PremiumList.PremiumListEntry;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link DeletePremiumListCommand}. */
public class DeletePremiumListCommandTest extends CommandTestCase<DeletePremiumListCommand> {
class DeletePremiumListCommandTest extends CommandTestCase<DeletePremiumListCommand> {
@Test
public void testSuccess() throws Exception {
void testSuccess() throws Exception {
PremiumList premiumList = persistPremiumList("xn--q9jyb4c", "blah,USD 100");
assertThat(loadPremiumListEntries(premiumList)).hasSize(1);
runCommand("--force", "--name=xn--q9jyb4c");
@ -47,7 +47,7 @@ public class DeletePremiumListCommandTest extends CommandTestCase<DeletePremiumL
}
@Test
public void testFailure_whenPremiumListDoesNotExist() {
void testFailure_whenPremiumListDoesNotExist() {
IllegalArgumentException thrown =
assertThrows(IllegalArgumentException.class, () -> runCommandForced("--name=foo"));
assertThat(thrown)
@ -56,7 +56,7 @@ public class DeletePremiumListCommandTest extends CommandTestCase<DeletePremiumL
}
@Test
public void testFailure_whenPremiumListIsInUse() {
void testFailure_whenPremiumListIsInUse() {
PremiumList premiumList = persistPremiumList("xn--q9jyb4c", "blah,USD 100");
createTld("xn--q9jyb4c");
persistResource(Registry.get("xn--q9jyb4c").asBuilder().setPremiumList(premiumList).build());

View file

@ -23,28 +23,28 @@ import static org.junit.Assert.assertThrows;
import google.registry.model.registry.Registry;
import google.registry.model.registry.label.ReservedList;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link DeleteReservedListCommand}. */
public class DeleteReservedListCommandTest extends CommandTestCase<DeleteReservedListCommand> {
class DeleteReservedListCommandTest extends CommandTestCase<DeleteReservedListCommand> {
ReservedList reservedList;
private ReservedList reservedList;
@Before
public void init() {
@BeforeEach
void beforeEach() {
reservedList = persistReservedList("common", "blah,FULLY_BLOCKED");
}
@Test
public void testSuccess() throws Exception {
void testSuccess() throws Exception {
assertThat(reservedList.getReservedListEntries()).hasSize(1);
runCommandForced("--name=common");
assertThat(ReservedList.get("common")).isEmpty();
}
@Test
public void testFailure_whenReservedListDoesNotExist() {
void testFailure_whenReservedListDoesNotExist() {
String expectedError =
"Cannot delete the reserved list doesntExistReservedList because it doesn't exist.";
IllegalArgumentException thrown =
@ -55,7 +55,7 @@ public class DeleteReservedListCommandTest extends CommandTestCase<DeleteReserve
}
@Test
public void testFailure_whenReservedListIsInUse() {
void testFailure_whenReservedListIsInUse() {
createTld("xn--q9jyb4c");
persistResource(Registry.get("xn--q9jyb4c").asBuilder().setReservedLists(reservedList).build());
IllegalArgumentException thrown =

View file

@ -28,17 +28,17 @@ import google.registry.model.registry.Registry;
import google.registry.model.registry.Registry.RegistryNotFoundException;
import google.registry.model.registry.Registry.TldType;
import org.joda.time.DateTime;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link DeleteTldCommand}. */
public class DeleteTldCommandTest extends CommandTestCase<DeleteTldCommand> {
class DeleteTldCommandTest extends CommandTestCase<DeleteTldCommand> {
private static final String TLD_REAL = "tldreal";
private static final String TLD_TEST = "tldtest";
@Before
public void setUp() {
@BeforeEach
void beforeEach() {
persistResource(
newRegistry(
TLD_REAL,
@ -54,7 +54,7 @@ public class DeleteTldCommandTest extends CommandTestCase<DeleteTldCommand> {
}
@Test
public void testSuccess_otherTldUnaffected() throws Exception {
void testSuccess_otherTldUnaffected() throws Exception {
runCommandForced("--tld=" + TLD_TEST);
Registry.get(TLD_REAL);
@ -62,24 +62,24 @@ public class DeleteTldCommandTest extends CommandTestCase<DeleteTldCommand> {
}
@Test
public void testFailure_whenTldDoesNotExist() {
void testFailure_whenTldDoesNotExist() {
assertThrows(RegistryNotFoundException.class, () -> runCommandForced("--tld=nonexistenttld"));
}
@Test
public void testFailure_whenTldIsReal() {
void testFailure_whenTldIsReal() {
assertThrows(IllegalStateException.class, () -> runCommandForced("--tld=" + TLD_REAL));
}
@Test
public void testFailure_whenDomainsArePresent() {
void testFailure_whenDomainsArePresent() {
persistDeletedDomain("domain." + TLD_TEST, DateTime.parse("2000-01-01TZ"));
assertThrows(IllegalStateException.class, () -> runCommandForced("--tld=" + TLD_TEST));
}
@Test
public void testFailure_whenRegistrarLinksToTld() {
void testFailure_whenRegistrarLinksToTld() {
allowRegistrarAccess("TheRegistrar", TLD_TEST);
assertThrows(IllegalStateException.class, () -> runCommandForced("--tld=" + TLD_TEST));

View file

@ -58,14 +58,11 @@ import java.util.Set;
import java.util.stream.Collectors;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
/** Unit tests for {@link google.registry.tools.DomainLockUtils}. */
@RunWith(JUnit4.class)
public final class DomainLockUtilsTest {
private static final String DOMAIN_NAME = "example.tld";
@ -74,7 +71,7 @@ public final class DomainLockUtilsTest {
private final FakeClock clock = new FakeClock(DateTime.now(DateTimeZone.UTC));
private DomainLockUtils domainLockUtils;
@Rule
@RegisterExtension
public final AppEngineRule appEngineRule =
AppEngineRule.builder()
.withDatastoreAndCloudSql()
@ -85,23 +82,24 @@ public final class DomainLockUtilsTest {
private DomainBase domain;
@Before
public void setup() {
@BeforeEach
void setup() {
createTlds("tld", "net");
HostResource host = persistActiveHost("ns1.example.net");
domain = persistResource(newDomainBase(DOMAIN_NAME, host));
AppEngineServiceUtils appEngineServiceUtils = mock(AppEngineServiceUtils.class);
when(appEngineServiceUtils.getServiceHostname("backend")).thenReturn("backend.hostname.fake");
domainLockUtils = new DomainLockUtils(
new DeterministicStringGenerator(Alphabets.BASE_58),
"adminreg",
AsyncTaskEnqueuerTest.createForTesting(
appEngineServiceUtils, clock, standardSeconds(90)));
domainLockUtils =
new DomainLockUtils(
new DeterministicStringGenerator(Alphabets.BASE_58),
"adminreg",
AsyncTaskEnqueuerTest.createForTesting(
appEngineServiceUtils, clock, standardSeconds(90)));
}
@Test
public void testSuccess_createLock() {
void testSuccess_createLock() {
RegistryLock lock =
domainLockUtils.saveNewRegistryLockRequest(DOMAIN_NAME, "TheRegistrar", POC_ID, false);
assertNoDomainChanges();
@ -109,7 +107,7 @@ public final class DomainLockUtilsTest {
}
@Test
public void testSuccess_createUnlock() {
void testSuccess_createUnlock() {
domainLockUtils.administrativelyApplyLock(DOMAIN_NAME, "TheRegistrar", POC_ID, false);
RegistryLock lock =
domainLockUtils.saveNewRegistryUnlockRequest(
@ -118,7 +116,7 @@ public final class DomainLockUtilsTest {
}
@Test
public void testSuccess_createUnlock_adminUnlockingAdmin() {
void testSuccess_createUnlock_adminUnlockingAdmin() {
domainLockUtils.administrativelyApplyLock(DOMAIN_NAME, "TheRegistrar", null, true);
RegistryLock lock =
domainLockUtils.saveNewRegistryUnlockRequest(
@ -127,7 +125,7 @@ public final class DomainLockUtilsTest {
}
@Test
public void testSuccess_createLock_previousLockExpired() {
void testSuccess_createLock_previousLockExpired() {
domainLockUtils.saveNewRegistryLockRequest(DOMAIN_NAME, "TheRegistrar", POC_ID, false);
clock.advanceBy(standardDays(1));
RegistryLock lock =
@ -137,7 +135,7 @@ public final class DomainLockUtilsTest {
}
@Test
public void testSuccess_createUnlock_previousUnlockRequestExpired() {
void testSuccess_createUnlock_previousUnlockRequestExpired() {
domainLockUtils.administrativelyApplyLock(DOMAIN_NAME, "TheRegistrar", POC_ID, false);
domainLockUtils.saveNewRegistryUnlockRequest(
DOMAIN_NAME, "TheRegistrar", false, Optional.empty());
@ -150,7 +148,7 @@ public final class DomainLockUtilsTest {
}
@Test
public void testSuccess_applyLockDomain() {
void testSuccess_applyLockDomain() {
RegistryLock lock =
domainLockUtils.saveNewRegistryLockRequest(DOMAIN_NAME, "TheRegistrar", POC_ID, false);
domainLockUtils.verifyAndApplyLock(lock.getVerificationCode(), false);
@ -158,7 +156,7 @@ public final class DomainLockUtilsTest {
}
@Test
public void testSuccess_applyUnlockDomain() {
void testSuccess_applyUnlockDomain() {
domainLockUtils.administrativelyApplyLock(DOMAIN_NAME, "TheRegistrar", POC_ID, false);
RegistryLock unlock =
domainLockUtils.saveNewRegistryUnlockRequest(
@ -168,7 +166,7 @@ public final class DomainLockUtilsTest {
}
@Test
public void testSuccess_applyAdminLock_onlyHistoryEntry() {
void testSuccess_applyAdminLock_onlyHistoryEntry() {
RegistryLock lock =
domainLockUtils.saveNewRegistryLockRequest(DOMAIN_NAME, "TheRegistrar", null, true);
domainLockUtils.verifyAndApplyLock(lock.getVerificationCode(), true);
@ -176,7 +174,7 @@ public final class DomainLockUtilsTest {
}
@Test
public void testSuccess_applyAdminUnlock_onlyHistoryEntry() {
void testSuccess_applyAdminUnlock_onlyHistoryEntry() {
RegistryLock lock =
domainLockUtils.saveNewRegistryLockRequest(DOMAIN_NAME, "TheRegistrar", null, true);
domainLockUtils.verifyAndApplyLock(lock.getVerificationCode(), true);
@ -188,20 +186,20 @@ public final class DomainLockUtilsTest {
}
@Test
public void testSuccess_administrativelyLock_nonAdmin() {
void testSuccess_administrativelyLock_nonAdmin() {
domainLockUtils.administrativelyApplyLock(
DOMAIN_NAME, "TheRegistrar", "Marla.Singer@crr.com", false);
verifyProperlyLockedDomain(false);
}
@Test
public void testSuccess_administrativelyLock_admin() {
void testSuccess_administrativelyLock_admin() {
domainLockUtils.administrativelyApplyLock(DOMAIN_NAME, "TheRegistrar", null, true);
verifyProperlyLockedDomain(true);
}
@Test
public void testSuccess_administrativelyUnlock_nonAdmin() {
void testSuccess_administrativelyUnlock_nonAdmin() {
RegistryLock lock =
domainLockUtils.saveNewRegistryLockRequest(DOMAIN_NAME, "TheRegistrar", POC_ID, false);
domainLockUtils.verifyAndApplyLock(lock.getVerificationCode(), false);
@ -211,7 +209,7 @@ public final class DomainLockUtilsTest {
}
@Test
public void testSuccess_administrativelyUnlock_admin() {
void testSuccess_administrativelyUnlock_admin() {
RegistryLock lock =
domainLockUtils.saveNewRegistryLockRequest(DOMAIN_NAME, "TheRegistrar", null, true);
domainLockUtils.verifyAndApplyLock(lock.getVerificationCode(), true);
@ -221,7 +219,7 @@ public final class DomainLockUtilsTest {
}
@Test
public void testSuccess_regularLock_relockSet() {
void testSuccess_regularLock_relockSet() {
domainLockUtils.administrativelyApplyLock(DOMAIN_NAME, "TheRegistrar", POC_ID, false);
RegistryLock oldLock =
domainLockUtils.administrativelyApplyUnlock(
@ -235,7 +233,7 @@ public final class DomainLockUtilsTest {
}
@Test
public void testSuccess_administrativelyLock_relockSet() {
void testSuccess_administrativelyLock_relockSet() {
domainLockUtils.administrativelyApplyLock(DOMAIN_NAME, "TheRegistrar", POC_ID, false);
RegistryLock oldLock =
domainLockUtils.administrativelyApplyUnlock(
@ -248,7 +246,7 @@ public final class DomainLockUtilsTest {
}
@Test
public void testSuccess_createUnlock_relockDuration() {
void testSuccess_createUnlock_relockDuration() {
domainLockUtils.administrativelyApplyLock(DOMAIN_NAME, "TheRegistrar", POC_ID, false);
RegistryLock lock =
domainLockUtils.saveNewRegistryUnlockRequest(
@ -257,7 +255,7 @@ public final class DomainLockUtilsTest {
}
@Test
public void testSuccess_unlock_relockSubmitted() {
void testSuccess_unlock_relockSubmitted() {
domainLockUtils.administrativelyApplyLock(DOMAIN_NAME, "TheRegistrar", POC_ID, false);
RegistryLock lock =
domainLockUtils.saveNewRegistryUnlockRequest(
@ -278,7 +276,7 @@ public final class DomainLockUtilsTest {
}
@Test
public void testFailure_createUnlock_alreadyPendingUnlock() {
void testFailure_createUnlock_alreadyPendingUnlock() {
RegistryLock lock =
domainLockUtils.saveNewRegistryLockRequest(DOMAIN_NAME, "TheRegistrar", POC_ID, false);
domainLockUtils.verifyAndApplyLock(lock.getVerificationCode(), false);
@ -296,7 +294,7 @@ public final class DomainLockUtilsTest {
}
@Test
public void testFailure_createUnlock_nonAdminUnlockingAdmin() {
void testFailure_createUnlock_nonAdminUnlockingAdmin() {
RegistryLock lock =
domainLockUtils.saveNewRegistryLockRequest(DOMAIN_NAME, "TheRegistrar", null, true);
domainLockUtils.verifyAndApplyLock(lock.getVerificationCode(), true);
@ -311,7 +309,7 @@ public final class DomainLockUtilsTest {
}
@Test
public void testFailure_createLock_unknownDomain() {
void testFailure_createLock_unknownDomain() {
assertThat(
assertThrows(
IllegalArgumentException.class,
@ -323,7 +321,7 @@ public final class DomainLockUtilsTest {
}
@Test
public void testFailure_createLock_alreadyPendingLock() {
void testFailure_createLock_alreadyPendingLock() {
domainLockUtils.saveNewRegistryLockRequest(DOMAIN_NAME, "TheRegistrar", POC_ID, false);
assertThat(
assertThrows(
@ -336,7 +334,7 @@ public final class DomainLockUtilsTest {
}
@Test
public void testFailure_createLock_alreadyLocked() {
void testFailure_createLock_alreadyLocked() {
persistResource(domain.asBuilder().setStatusValues(REGISTRY_LOCK_STATUSES).build());
assertThat(
assertThrows(
@ -349,7 +347,7 @@ public final class DomainLockUtilsTest {
}
@Test
public void testFailure_createUnlock_alreadyUnlocked() {
void testFailure_createUnlock_alreadyUnlocked() {
assertThat(
assertThrows(
IllegalArgumentException.class,
@ -361,7 +359,7 @@ public final class DomainLockUtilsTest {
}
@Test
public void testFailure_applyLock_alreadyApplied() {
void testFailure_applyLock_alreadyApplied() {
RegistryLock lock =
domainLockUtils.saveNewRegistryLockRequest(DOMAIN_NAME, "TheRegistrar", POC_ID, false);
domainLockUtils.verifyAndApplyLock(lock.getVerificationCode(), false);
@ -376,7 +374,7 @@ public final class DomainLockUtilsTest {
}
@Test
public void testFailure_applyLock_expired() {
void testFailure_applyLock_expired() {
RegistryLock lock =
domainLockUtils.saveNewRegistryLockRequest(DOMAIN_NAME, "TheRegistrar", POC_ID, false);
clock.advanceBy(standardDays(1));
@ -390,7 +388,7 @@ public final class DomainLockUtilsTest {
}
@Test
public void testFailure_applyLock_nonAdmin_applyAdminLock() {
void testFailure_applyLock_nonAdmin_applyAdminLock() {
RegistryLock lock =
domainLockUtils.saveNewRegistryLockRequest(DOMAIN_NAME, "TheRegistrar", null, true);
assertThat(
@ -403,7 +401,7 @@ public final class DomainLockUtilsTest {
}
@Test
public void testFailure_applyUnlock_alreadyUnlocked() {
void testFailure_applyUnlock_alreadyUnlocked() {
RegistryLock lock =
domainLockUtils.saveNewRegistryLockRequest(DOMAIN_NAME, "TheRegistrar", POC_ID, false);
domainLockUtils.verifyAndApplyLock(lock.getVerificationCode(), false);
@ -422,7 +420,7 @@ public final class DomainLockUtilsTest {
}
@Test
public void testFailure_applyLock_alreadyLocked() {
void testFailure_applyLock_alreadyLocked() {
RegistryLock lock =
domainLockUtils.saveNewRegistryLockRequest(DOMAIN_NAME, "TheRegistrar", POC_ID, false);
String verificationCode = lock.getVerificationCode();

View file

@ -17,23 +17,17 @@ package google.registry.tools;
import static com.google.common.truth.Truth.assertThat;
import java.io.File;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.junit.jupiter.api.Test;
@RunWith(JUnit4.class)
public class DumpGoldenSchemaCommandTest extends CommandTestCase<DumpGoldenSchemaCommand> {
/** Unit tests for {@link google.registry.tools.DumpGoldenSchemaCommand}. */
class DumpGoldenSchemaCommandTest extends CommandTestCase<DumpGoldenSchemaCommand> {
@Rule public TemporaryFolder tmp = new TemporaryFolder();
public DumpGoldenSchemaCommandTest() {}
DumpGoldenSchemaCommandTest() {}
@Test
public void testSchemaGeneration() throws Exception {
runCommand(
"--output=" + tmp.getRoot() + File.separatorChar + "golden.sql", "--start_postgresql");
assertThat(new File(tmp.getRoot(), "golden.sql").length()).isGreaterThan(1);
void testSchemaGeneration() throws Exception {
File schemaFile = tmpDir.resolve("golden.sql").toFile();
runCommand("--output=" + schemaFile.toString(), "--start_postgresql");
assertThat(schemaFile.length()).isGreaterThan(1);
}
}

View file

@ -22,17 +22,16 @@ import com.google.common.io.Files;
import google.registry.rde.RdeTestData;
import google.registry.testing.BouncyCastleProviderRule;
import google.registry.testing.FakeKeyringModule;
import java.io.File;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import java.nio.file.Path;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
/** Unit tests for {@link EncryptEscrowDepositCommand}. */
public class EncryptEscrowDepositCommandTest
extends CommandTestCase<EncryptEscrowDepositCommand> {
@Rule
public final BouncyCastleProviderRule bouncy = new BouncyCastleProviderRule();
@RegisterExtension public final BouncyCastleProviderRule bouncy = new BouncyCastleProviderRule();
private final ByteSource depositXml = loadBytes(RdeTestData.class, "deposit_full.xml");
@ -43,23 +42,22 @@ public class EncryptEscrowDepositCommandTest
return res;
}
@Before
public void before() {
@BeforeEach
void beforeEach() {
command.encryptor = createEncryptor();
}
@Test
public void testSuccess() throws Exception {
File outDir = tmpDir.newFolder();
File depositFile = tmpDir.newFile("deposit.xml");
Files.write(depositXml.read(), depositFile);
runCommand(
"--tld=lol",
"--input=" + depositFile.getPath(),
"--outdir=" + outDir.getPath());
assertThat(outDir.list()).asList().containsExactly(
"lol_2010-10-17_full_S1_R0.ryde",
"lol_2010-10-17_full_S1_R0.sig",
"lol.pub");
void testSuccess() throws Exception {
Path depositFile = tmpDir.resolve("deposit.xml");
Files.write(depositXml.read(), depositFile.toFile());
runCommand("--tld=lol", "--input=" + depositFile, "--outdir=" + tmpDir.toString());
assertThat(tmpDir.toFile().list())
.asList()
.containsExactly(
"deposit.xml",
"lol_2010-10-17_full_S1_R0.ryde",
"lol_2010-10-17_full_S1_R0.sig",
"lol.pub");
}
}

View file

@ -22,22 +22,20 @@ import com.google.common.collect.ImmutableList;
import com.google.storage.onestore.v3.OnestoreEntity.EntityProto;
import com.google.storage.onestore.v3.OnestoreEntity.Property;
import google.registry.testing.AppEngineRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
@RunWith(JUnit4.class)
/** Unit tests for {@link EntityWrapper}. */
public final class EntityWrapperTest {
private static final String TEST_ENTITY_KIND = "TestEntity";
private static final int ARBITRARY_KEY_ID = 1001;
@Rule
@RegisterExtension
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
@Test
public void testEquals() {
void testEquals() {
// Create an entity with a key and some properties.
Entity entity = new Entity(TEST_ENTITY_KIND, ARBITRARY_KEY_ID);
// Note that we need to specify these as long for property comparisons to work because that's
@ -73,7 +71,7 @@ public final class EntityWrapperTest {
}
@Test
public void testDifferentPropertiesNotEqual() {
void testDifferentPropertiesNotEqual() {
Entity entity = new Entity(TEST_ENTITY_KIND, ARBITRARY_KEY_ID);
// Note that we need to specify these as long for property comparisons to work because that's
// how they are deserialized from protos.
@ -98,7 +96,7 @@ public final class EntityWrapperTest {
}
@Test
public void testDifferentKeysNotEqual() {
void testDifferentKeysNotEqual() {
EntityProto proto1 =
EntityTranslator.convertToPb(new Entity(TEST_ENTITY_KIND, ARBITRARY_KEY_ID));
EntityProto proto2 =
@ -115,7 +113,7 @@ public final class EntityWrapperTest {
}
@Test
public void testComparisonAgainstNonComparableEntities() {
void testComparisonAgainstNonComparableEntities() {
EntityWrapper ce = new EntityWrapper(new Entity(TEST_ENTITY_KIND, ARBITRARY_KEY_ID));
// Note: this has to be "isNotEqualTo()" and not isNotNull() because we want to test the
// equals() method and isNotNull() just checks for "ce != null".

View file

@ -21,7 +21,7 @@ import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import google.registry.tools.server.ToolsTestData;
import java.util.List;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link EppToolCommand}. */
public class EppToolCommandTest extends EppToolCommandTestCase<EppToolCommand> {
@ -50,7 +50,7 @@ public class EppToolCommandTest extends EppToolCommandTestCase<EppToolCommand> {
}
@Test
public void testSuccess_singleXmlCommand() throws Exception {
void testSuccess_singleXmlCommand() throws Exception {
// The choice of xml file is arbitrary.
runCommandForced(
"--client=NewRegistrar",
@ -59,7 +59,7 @@ public class EppToolCommandTest extends EppToolCommandTestCase<EppToolCommand> {
}
@Test
public void testSuccess_multipleXmlCommands() throws Exception {
void testSuccess_multipleXmlCommands() throws Exception {
// The choice of xml files is arbitrary.
runCommandForced(
"--client=NewRegistrar",
@ -73,7 +73,7 @@ public class EppToolCommandTest extends EppToolCommandTestCase<EppToolCommand> {
}
@Test
public void testFailure_nonexistentClientId() {
void testFailure_nonexistentClientId() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,

View file

@ -16,8 +16,8 @@ package google.registry.tools;
import static google.registry.testing.DatastoreHelper.createTlds;
import org.junit.After;
import org.junit.Before;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
/**
* Abstract class for commands that construct + send EPP commands.
@ -31,15 +31,15 @@ public abstract class EppToolCommandTestCase<C extends EppToolCommand> extends C
EppToolVerifier eppVerifier;
@Before
public void init() {
@BeforeEach
public void beforeEachEppToolCommandTestCase() {
// Create two TLDs for commands that allow multiple TLDs at once.
createTlds("tld", "tld2");
eppVerifier = EppToolVerifier.create(command).expectClientId("NewRegistrar");
}
@After
public void cleanup() throws Exception {
@AfterEach
public void afterEachEppToolCommandTestCase() throws Exception {
eppVerifier.verifyNoMoreSent();
}
}

View file

@ -71,7 +71,7 @@ public class EppToolVerifier {
*
* <p>Must be called at least once before any {@link #verifySent} calls.
*/
public EppToolVerifier expectClientId(String clientId) {
EppToolVerifier expectClientId(String clientId) {
this.clientId = clientId;
return this;
}
@ -81,7 +81,7 @@ public class EppToolVerifier {
*
* <p>If not called, {@link #verifySent} will expect the "superuser" flag to be false.
*/
public EppToolVerifier expectSuperuser() {
EppToolVerifier expectSuperuser() {
this.superuser = true;
return this;
}
@ -91,7 +91,7 @@ public class EppToolVerifier {
*
* <p>If not called, {@link #verifySent} will expect the "dryRun" flag to be false.
*/
public EppToolVerifier expectDryRun() {
EppToolVerifier expectDryRun() {
this.dryRun = true;
return this;
}
@ -141,7 +141,7 @@ public class EppToolVerifier {
*
* <p>If multiple EPPs are expected, the verifySent* call order must match the EPP order.
*/
public EppToolVerifier verifySentAny() throws Exception {
EppToolVerifier verifySentAny() throws Exception {
setArgumentsIfNeeded();
paramIndex++;
assertThat(capturedParams.size()).isAtLeast(paramIndex);
@ -151,7 +151,7 @@ public class EppToolVerifier {
/**
* Test that no more EPPs were sent, after any that were expected in previous "verifySent" calls.
*/
public void verifyNoMoreSent() throws Exception {
void verifyNoMoreSent() throws Exception {
setArgumentsIfNeeded();
assertThat(
capturedParams

View file

@ -20,48 +20,48 @@ import static org.junit.Assert.assertThrows;
import com.beust.jcommander.ParameterException;
import google.registry.tools.server.ToolsTestData;
import java.io.ByteArrayInputStream;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link ExecuteEppCommand}. */
public class ExecuteEppCommandTest extends EppToolCommandTestCase<ExecuteEppCommand> {
class ExecuteEppCommandTest extends EppToolCommandTestCase<ExecuteEppCommand> {
private String xmlInput;
private String eppFile;
@Before
public void initCommand() throws Exception {
@BeforeEach
void beforeEach() throws Exception {
xmlInput = ToolsTestData.loadFile("contact_create.xml");
eppFile = writeToNamedTmpFile("eppFile", xmlInput);
}
@Test
public void testSuccess() throws Exception {
void testSuccess() throws Exception {
runCommand("--client=NewRegistrar", "--force", eppFile);
eppVerifier.verifySent("contact_create.xml");
}
@Test
public void testSuccess_dryRun() throws Exception {
void testSuccess_dryRun() throws Exception {
runCommand("--client=NewRegistrar", "--dry_run", eppFile);
eppVerifier.expectDryRun().verifySent("contact_create.xml");
}
@Test
public void testSuccess_withSuperuser() throws Exception {
void testSuccess_withSuperuser() throws Exception {
runCommand("--client=NewRegistrar", "--superuser", "--force", eppFile);
eppVerifier.expectSuperuser().verifySent("contact_create.xml");
}
@Test
public void testSuccess_fromStdin() throws Exception {
void testSuccess_fromStdin() throws Exception {
System.setIn(new ByteArrayInputStream(xmlInput.getBytes(UTF_8)));
runCommand("--client=NewRegistrar", "--force");
eppVerifier.verifySent("contact_create.xml");
}
@Test
public void testSuccess_multipleFiles() throws Exception {
void testSuccess_multipleFiles() throws Exception {
String xmlInput2 = ToolsTestData.loadFile("domain_check.xml");
String eppFile2 = writeToNamedTmpFile("eppFile2", xmlInput2);
runCommand("--client=NewRegistrar", "--force", eppFile, eppFile2);
@ -71,19 +71,19 @@ public class ExecuteEppCommandTest extends EppToolCommandTestCase<ExecuteEppComm
}
@Test
public void testFailure_missingClientId() {
void testFailure_missingClientId() {
assertThrows(ParameterException.class, () -> runCommand("--force", "foo.xml"));
}
@Test
public void testFailure_forceAndDryRunIncompatible() {
void testFailure_forceAndDryRunIncompatible() {
assertThrows(
IllegalArgumentException.class,
() -> runCommand("--client=NewRegistrar", "--force", "--dry_run", eppFile));
}
@Test
public void testFailure_unknownFlag() {
void testFailure_unknownFlag() {
assertThrows(
ParameterException.class,
() -> runCommand("--client=NewRegistrar", "--unrecognized=foo", "--force", "foo.xml"));

View file

@ -26,6 +26,8 @@ import static org.joda.time.DateTimeZone.UTC;
import static org.junit.Assert.assertThrows;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import com.beust.jcommander.ParameterException;
import com.google.appengine.tools.remoteapi.RemoteApiException;
@ -50,30 +52,29 @@ import java.io.File;
import java.util.Collection;
import javax.annotation.Nullable;
import org.joda.time.DateTime;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentMatchers;
/** Unit tests for {@link GenerateAllocationTokensCommand}. */
public class GenerateAllocationTokensCommandTest
extends CommandTestCase<GenerateAllocationTokensCommand> {
class GenerateAllocationTokensCommandTest extends CommandTestCase<GenerateAllocationTokensCommand> {
@Before
public void init() {
@BeforeEach
void beforeEach() {
command.stringGenerator = new DeterministicStringGenerator(Alphabets.BASE_58);
command.retrier =
new Retrier(new FakeSleeper(new FakeClock(DateTime.parse("2000-01-01TZ"))), 3);
}
@Test
public void testSuccess_oneToken() throws Exception {
void testSuccess_oneToken() throws Exception {
runCommand("--prefix", "blah", "--number", "1", "--length", "9");
assertAllocationTokens(createToken("blah123456789", null, null));
assertInStdout("blah123456789");
}
@Test
public void testSuccess_threeTokens() throws Exception {
void testSuccess_threeTokens() throws Exception {
runCommand("--prefix", "foo", "--number", "3", "--length", "10");
assertAllocationTokens(
createToken("foo123456789A", null, null),
@ -83,28 +84,29 @@ public class GenerateAllocationTokensCommandTest
}
@Test
public void testSuccess_defaults() throws Exception {
void testSuccess_defaults() throws Exception {
runCommand("--number", "1");
assertAllocationTokens(createToken("123456789ABCDEFG", null, null));
assertInStdout("123456789ABCDEFG");
}
@Test
public void testSuccess_retry() throws Exception {
GenerateAllocationTokensCommand spyCommand = spy(command);
void testSuccess_retry() throws Exception {
command = spy(command);
RemoteApiException fakeException = new RemoteApiException("foo", "foo", "foo", new Exception());
doThrow(fakeException)
.doThrow(fakeException)
.doCallRealMethod()
.when(spyCommand)
.when(command)
.saveTokens(ArgumentMatchers.any());
runCommand("--number", "1");
assertAllocationTokens(createToken("123456789ABCDEFG", null, null));
assertInStdout("123456789ABCDEFG");
verify(command, times(3)).saveTokens(ArgumentMatchers.any());
}
@Test
public void testSuccess_tokenCollision() throws Exception {
void testSuccess_tokenCollision() throws Exception {
AllocationToken existingToken =
persistResource(
new AllocationToken.Builder()
@ -117,14 +119,14 @@ public class GenerateAllocationTokensCommandTest
}
@Test
public void testSuccess_dryRun_outputsButDoesntSave() throws Exception {
void testSuccess_dryRun_outputsButDoesntSave() throws Exception {
runCommand("--prefix", "foo", "--number", "2", "--length", "10", "--dry_run");
assertAllocationTokens();
assertInStdout("foo123456789A\nfooBCDEFGHJKL");
}
@Test
public void testSuccess_largeNumberOfTokens() throws Exception {
void testSuccess_largeNumberOfTokens() throws Exception {
command.stringGenerator =
new DeterministicStringGenerator(Alphabets.BASE_58, Rule.PREPEND_COUNTER);
runCommand("--prefix", "ooo", "--number", "100", "--length", "16");
@ -134,9 +136,9 @@ public class GenerateAllocationTokensCommandTest
}
@Test
public void testSuccess_domainNames() throws Exception {
void testSuccess_domainNames() throws Exception {
createTld("tld");
File domainNamesFile = tmpDir.newFile("domain_names.txt");
File domainNamesFile = tmpDir.resolve("domain_names.txt").toFile();
Files.asCharSink(domainNamesFile, UTF_8).write("foo1.tld\nboo2.tld\nbaz9.tld\n");
runCommand("--domain_names_file", domainNamesFile.getPath());
assertAllocationTokens(
@ -148,7 +150,7 @@ public class GenerateAllocationTokensCommandTest
}
@Test
public void testSuccess_promotionToken() throws Exception {
void testSuccess_promotionToken() throws Exception {
DateTime promoStart = DateTime.now(UTC);
DateTime promoEnd = promoStart.plusMonths(1);
runCommand(
@ -178,14 +180,14 @@ public class GenerateAllocationTokensCommandTest
}
@Test
public void testSuccess_specifyTokens() throws Exception {
void testSuccess_specifyTokens() throws Exception {
runCommand("--tokens", "foobar,foobaz");
assertAllocationTokens(createToken("foobar", null, null), createToken("foobaz", null, null));
assertInStdout("foobar", "foobaz");
}
@Test
public void testSuccess_specifyManyTokens() throws Exception {
void testSuccess_specifyManyTokens() throws Exception {
command.stringGenerator =
new DeterministicStringGenerator(Alphabets.BASE_58, Rule.PREPEND_COUNTER);
Collection<String> sampleTokens = command.stringGenerator.createStrings(13, 100);
@ -195,7 +197,7 @@ public class GenerateAllocationTokensCommandTest
}
@Test
public void testFailure_mustSpecifyNumberOfTokensOrDomainsFile() {
void testFailure_mustSpecifyNumberOfTokensOrDomainsFile() {
IllegalArgumentException thrown =
assertThrows(IllegalArgumentException.class, () -> runCommand("--prefix", "FEET"));
assertThat(thrown)
@ -204,7 +206,7 @@ public class GenerateAllocationTokensCommandTest
}
@Test
public void testFailure_mustNotSpecifyBothNumberOfTokensAndDomainsFile() {
void testFailure_mustNotSpecifyBothNumberOfTokensAndDomainsFile() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -219,7 +221,7 @@ public class GenerateAllocationTokensCommandTest
}
@Test
public void testFailure_mustNotSpecifyBothNumberOfTokensAndTokenStrings() {
void testFailure_mustNotSpecifyBothNumberOfTokensAndTokenStrings() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -234,7 +236,7 @@ public class GenerateAllocationTokensCommandTest
}
@Test
public void testFailure_mustNotSpecifyBothTokenStringsAndDomainsFile() {
void testFailure_mustNotSpecifyBothTokenStringsAndDomainsFile() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -249,9 +251,9 @@ public class GenerateAllocationTokensCommandTest
}
@Test
public void testFailure_specifiesAlreadyExistingToken() throws Exception {
void testFailure_specifiesAlreadyExistingToken() throws Exception {
runCommand("--tokens", "foobar");
beforeCommandTestCase(); // reset the command variables
beforeEachCommandTestCase(); // reset the command variables
IllegalArgumentException thrown =
assertThrows(IllegalArgumentException.class, () -> runCommand("--tokens", "foobar,foobaz"));
assertThat(thrown)
@ -260,7 +262,7 @@ public class GenerateAllocationTokensCommandTest
}
@Test
public void testFailure_invalidTokenType() {
void testFailure_invalidTokenType() {
ParameterException thrown =
assertThrows(
ParameterException.class,
@ -271,7 +273,7 @@ public class GenerateAllocationTokensCommandTest
}
@Test
public void testFailure_invalidTokenStatusTransition() {
void testFailure_invalidTokenStatusTransition() {
assertThat(
assertThrows(
ParameterException.class,
@ -286,7 +288,7 @@ public class GenerateAllocationTokensCommandTest
}
@Test
public void testFailure_lengthOfZero() {
void testFailure_lengthOfZero() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -298,7 +300,7 @@ public class GenerateAllocationTokensCommandTest
}
@Test
public void testFailure_unlimitedUseMustHaveTransitions() {
void testFailure_unlimitedUseMustHaveTransitions() {
assertThat(
assertThrows(
IllegalArgumentException.class,

View file

@ -41,21 +41,15 @@ import java.io.IOException;
import java.io.Reader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import org.joda.time.DateTime;
import org.json.simple.JSONValue;
import org.json.simple.parser.ParseException;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link GenerateDnsReportCommand}. */
public class GenerateDnsReportCommandTest extends CommandTestCase<GenerateDnsReportCommand> {
@Rule
public final TemporaryFolder folder = new TemporaryFolder();
class GenerateDnsReportCommandTest extends CommandTestCase<GenerateDnsReportCommand> {
private final DateTime now = DateTime.now(UTC);
private final FakeClock clock = new FakeClock();
@ -120,9 +114,9 @@ public class GenerateDnsReportCommandTest extends CommandTestCase<GenerateDnsRep
"192.168.1.1",
"2607:f8b0:400d:c00:0:0:0:c1"));
@Before
public void init() throws Exception {
output = Paths.get(folder.newFile().toString());
@BeforeEach
void beforeEach() throws Exception {
output = tmpDir.resolve("out.dat");
command.clock = clock;
clock.setTo(now);
@ -165,7 +159,7 @@ public class GenerateDnsReportCommandTest extends CommandTestCase<GenerateDnsRep
}
@Test
public void testSuccess() throws Exception {
void testSuccess() throws Exception {
runCommand("--output=" + output, "--tld=xn--q9jyb4c");
Iterable<?> output = (Iterable<?>) getOutputAsJson();
assertThat(output).containsAnyOf(DOMAIN1_OUTPUT, DOMAIN1_OUTPUT_ALT);
@ -173,7 +167,7 @@ public class GenerateDnsReportCommandTest extends CommandTestCase<GenerateDnsRep
}
@Test
public void testSuccess_skipDeletedDomain() throws Exception {
void testSuccess_skipDeletedDomain() throws Exception {
persistResource(domain1.asBuilder().setDeletionTime(now).build());
runCommand("--output=" + output, "--tld=xn--q9jyb4c");
assertThat((Iterable<?>) getOutputAsJson())
@ -181,7 +175,7 @@ public class GenerateDnsReportCommandTest extends CommandTestCase<GenerateDnsRep
}
@Test
public void testSuccess_skipDeletedNameserver() throws Exception {
void testSuccess_skipDeletedNameserver() throws Exception {
persistResource(nameserver1.asBuilder().setDeletionTime(now).build());
runCommand("--output=" + output, "--tld=xn--q9jyb4c");
Iterable<?> output = (Iterable<?>) getOutputAsJson();
@ -190,7 +184,7 @@ public class GenerateDnsReportCommandTest extends CommandTestCase<GenerateDnsRep
}
@Test
public void testSuccess_skipClientHoldDomain() throws Exception {
void testSuccess_skipClientHoldDomain() throws Exception {
persistResource(domain1.asBuilder().addStatusValue(StatusValue.CLIENT_HOLD).build());
runCommand("--output=" + output, "--tld=xn--q9jyb4c");
assertThat((Iterable<?>) getOutputAsJson())
@ -198,7 +192,7 @@ public class GenerateDnsReportCommandTest extends CommandTestCase<GenerateDnsRep
}
@Test
public void testSuccess_skipServerHoldDomain() throws Exception {
void testSuccess_skipServerHoldDomain() throws Exception {
persistResource(domain1.asBuilder().addStatusValue(StatusValue.SERVER_HOLD).build());
runCommand("--output=" + output, "--tld=xn--q9jyb4c");
assertThat((Iterable<?>) getOutputAsJson())
@ -206,7 +200,7 @@ public class GenerateDnsReportCommandTest extends CommandTestCase<GenerateDnsRep
}
@Test
public void testSuccess_skipPendingDeleteDomain() throws Exception {
void testSuccess_skipPendingDeleteDomain() throws Exception {
persistResource(
domain1
.asBuilder()
@ -219,7 +213,7 @@ public class GenerateDnsReportCommandTest extends CommandTestCase<GenerateDnsRep
}
@Test
public void testSuccess_skipDomainsWithoutNameservers() throws Exception {
void testSuccess_skipDomainsWithoutNameservers() throws Exception {
persistResource(domain1.asBuilder().setNameservers(ImmutableSet.of()).build());
runCommand("--output=" + output, "--tld=xn--q9jyb4c");
assertThat((Iterable<?>) getOutputAsJson())
@ -227,12 +221,12 @@ public class GenerateDnsReportCommandTest extends CommandTestCase<GenerateDnsRep
}
@Test
public void testFailure_tldDoesNotExist() {
void testFailure_tldDoesNotExist() {
assertThrows(IllegalArgumentException.class, () -> runCommand("--tld=foobar"));
}
@Test
public void testFailure_missingTldParameter() {
void testFailure_missingTldParameter() {
assertThrows(ParameterException.class, () -> runCommand(""));
}
}

View file

@ -26,21 +26,24 @@ import google.registry.testing.InjectRule;
import google.registry.testing.TaskQueueHelper.TaskMatcher;
import google.registry.util.AppEngineServiceUtils;
import java.util.Optional;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
/** Unit tests for {@link GenerateEscrowDepositCommand}. */
@MockitoSettings(strictness = Strictness.LENIENT)
public class GenerateEscrowDepositCommandTest
extends CommandTestCase<GenerateEscrowDepositCommand> {
@Rule public final InjectRule inject = new InjectRule();
@RegisterExtension public final InjectRule inject = new InjectRule();
@Mock AppEngineServiceUtils appEngineServiceUtils;
@Before
public void before() {
@BeforeEach
void beforeEach() {
createTld("tld");
createTld("anothertld");
command = new GenerateEscrowDepositCommand();
@ -52,7 +55,7 @@ public class GenerateEscrowDepositCommandTest
}
@Test
public void testCommand_missingTld() {
void testCommand_missingTld() {
ParameterException thrown =
assertThrows(
ParameterException.class,
@ -62,7 +65,7 @@ public class GenerateEscrowDepositCommandTest
}
@Test
public void testCommand_emptyTld() {
void testCommand_emptyTld() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -77,7 +80,7 @@ public class GenerateEscrowDepositCommandTest
}
@Test
public void testCommand_invalidTld() {
void testCommand_invalidTld() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -92,7 +95,7 @@ public class GenerateEscrowDepositCommandTest
}
@Test
public void testCommand_missingWatermark() {
void testCommand_missingWatermark() {
ParameterException thrown =
assertThrows(
ParameterException.class,
@ -103,7 +106,7 @@ public class GenerateEscrowDepositCommandTest
}
@Test
public void testCommand_emptyWatermark() {
void testCommand_emptyWatermark() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -112,7 +115,7 @@ public class GenerateEscrowDepositCommandTest
}
@Test
public void testCommand_missingOutdir() {
void testCommand_missingOutdir() {
ParameterException thrown =
assertThrows(
ParameterException.class,
@ -123,7 +126,7 @@ public class GenerateEscrowDepositCommandTest
}
@Test
public void testCommand_emptyOutdir() {
void testCommand_emptyOutdir() {
ParameterException thrown =
assertThrows(
ParameterException.class,
@ -138,7 +141,7 @@ public class GenerateEscrowDepositCommandTest
}
@Test
public void testCommand_invalidWatermark() {
void testCommand_invalidWatermark() {
ParameterException thrown =
assertThrows(
ParameterException.class,
@ -153,7 +156,7 @@ public class GenerateEscrowDepositCommandTest
}
@Test
public void testCommand_invalidMode() {
void testCommand_invalidMode() {
ParameterException thrown =
assertThrows(
ParameterException.class,
@ -170,7 +173,7 @@ public class GenerateEscrowDepositCommandTest
}
@Test
public void testCommand_invalidRevision() {
void testCommand_invalidRevision() {
ParameterException thrown =
assertThrows(
ParameterException.class,
@ -185,7 +188,7 @@ public class GenerateEscrowDepositCommandTest
}
@Test
public void testCommand_success() throws Exception {
void testCommand_success() throws Exception {
runCommand("--tld=tld", "--watermark=2017-01-01T00:00:00Z", "--mode=thin", "-r 42", "-o test");
assertTasksEnqueued(
@ -202,7 +205,7 @@ public class GenerateEscrowDepositCommandTest
}
@Test
public void testCommand_successWithDefaultRevision() throws Exception {
void testCommand_successWithDefaultRevision() throws Exception {
runCommand("--tld=tld", "--watermark=2017-01-01T00:00:00Z", "--mode=thin", "-o test");
assertTasksEnqueued(
@ -218,7 +221,7 @@ public class GenerateEscrowDepositCommandTest
}
@Test
public void testCommand_successWithDefaultMode() throws Exception {
void testCommand_successWithDefaultMode() throws Exception {
runCommand("--tld=tld", "--watermark=2017-01-01T00:00:00Z", "-r=42", "-o test");
assertTasksEnqueued(
@ -235,7 +238,7 @@ public class GenerateEscrowDepositCommandTest
}
@Test
public void testCommand_successWithMultipleArgumentValues() throws Exception {
void testCommand_successWithMultipleArgumentValues() throws Exception {
runCommand(
"--tld=tld,anothertld",
"--watermark=2017-01-01T00:00:00Z,2017-01-02T00:00:00Z",

View file

@ -22,60 +22,54 @@ import com.google.common.io.Files;
import com.google.common.io.Resources;
import google.registry.persistence.NomulusPostgreSql;
import java.io.File;
import org.junit.Before;
import org.junit.ClassRule;
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.nio.file.Path;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
/** Unit tests for {@link GenerateSqlSchemaCommand}. */
@RunWith(JUnit4.class)
public class GenerateSqlSchemaCommandTest extends CommandTestCase<GenerateSqlSchemaCommand> {
@Testcontainers
class GenerateSqlSchemaCommandTest extends CommandTestCase<GenerateSqlSchemaCommand> {
private String containerHostName;
private int containerPort;
@Rule public TemporaryFolder tmp = new TemporaryFolder();
@ClassRule
public static PostgreSQLContainer postgres =
@Container
private static PostgreSQLContainer postgres =
new PostgreSQLContainer(NomulusPostgreSql.getDockerTag())
.withDatabaseName("postgres")
.withUsername("postgres")
.withPassword("domain-registry");
public GenerateSqlSchemaCommandTest() {}
@Before
public void setUp() {
@BeforeEach
void beforeEach() {
containerHostName = postgres.getContainerIpAddress();
containerPort = postgres.getMappedPort(GenerateSqlSchemaCommand.POSTGRESQL_PORT);
}
@Test
public void testSchemaGeneration() throws Exception {
void testSchemaGeneration() throws Exception {
runCommand(
"--out_file=" + tmp.getRoot() + File.separatorChar + "schema.sql",
"--out_file=" + tmpDir.resolve("schema.sql").toString(),
"--db_host=" + containerHostName,
"--db_port=" + containerPort);
// We don't verify the exact contents of the result SQL file because that would be too brittle,
// but we check to make sure that a couple parts of it are named as we expect them to be
// TODO: try running the schema against the test database.
File sqlFile = new File(tmp.getRoot(), "schema.sql");
assertThat(sqlFile.exists()).isTrue();
String fileContent = Files.asCharSource(sqlFile, UTF_8).read();
File schemaFile = tmpDir.resolve("schema.sql").toFile();
assertThat(schemaFile.exists()).isTrue();
String fileContent = Files.asCharSource(schemaFile, UTF_8).read();
assertThat(fileContent).contains("create table \"Domain\" (");
assertThat(fileContent).contains("repo_id text not null,");
}
@Test
public void testIncompatibleFlags() throws Exception {
void testIncompatibleFlags() throws Exception {
runCommand(
"--out_file=" + tmp.getRoot() + File.separatorChar + "schema.sql",
"--out_file=" + tmpDir.resolve("schema.sql").toString(),
"--db_host=" + containerHostName,
"--db_port=" + containerPort,
"--start_postgresql");
@ -83,17 +77,17 @@ public class GenerateSqlSchemaCommandTest extends CommandTestCase<GenerateSqlSch
}
@Test
public void testDockerPostgresql() throws Exception {
runCommand(
"--start_postgresql", "--out_file=" + tmp.getRoot() + File.separatorChar + "schema.sql");
assertThat(new File(tmp.getRoot(), "schema.sql").exists()).isTrue();
void testDockerPostgresql() throws Exception {
Path schemaFile = tmpDir.resolve("schema.sql");
runCommand("--start_postgresql", "--out_file=" + schemaFile.toString());
assertThat(schemaFile.toFile().exists()).isTrue();
}
@Test
public void validateGeneratedSchemaIsSameAsSchemaInFile() throws Exception {
runCommand(
"--start_postgresql", "--out_file=" + tmp.getRoot() + File.separatorChar + "schema.sql");
assertThat(new File(tmp.getRoot(), "schema.sql").toURI().toURL())
void validateGeneratedSchemaIsSameAsSchemaInFile() throws Exception {
Path schemaFile = tmpDir.resolve("schema.sql");
runCommand("--start_postgresql", "--out_file=" + schemaFile.toString());
assertThat(schemaFile.toFile().toURI().toURL())
.hasSameContentAs(Resources.getResource("sql/schema/db-schema.sql.generated"));
}
}

View file

@ -29,13 +29,13 @@ import com.googlecode.objectify.Key;
import google.registry.model.domain.DomainBase;
import google.registry.model.domain.token.AllocationToken;
import org.joda.time.DateTime;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link GetAllocationTokenCommand}. */
public class GetAllocationTokenCommandTest extends CommandTestCase<GetAllocationTokenCommand> {
class GetAllocationTokenCommandTest extends CommandTestCase<GetAllocationTokenCommand> {
@Test
public void testSuccess_oneToken() throws Exception {
void testSuccess_oneToken() throws Exception {
createTlds("bar");
AllocationToken token =
persistResource(
@ -49,7 +49,7 @@ public class GetAllocationTokenCommandTest extends CommandTestCase<GetAllocation
}
@Test
public void testSuccess_multipleTokens() throws Exception {
void testSuccess_multipleTokens() throws Exception {
createTlds("baz");
ImmutableList<AllocationToken> tokens =
persistSimpleResources(
@ -73,7 +73,7 @@ public class GetAllocationTokenCommandTest extends CommandTestCase<GetAllocation
}
@Test
public void testSuccess_redeemedToken() throws Exception {
void testSuccess_redeemedToken() throws Exception {
createTld("tld");
DomainBase domain =
persistActiveDomain("fqqdn.tld", DateTime.parse("2016-04-07T22:19:17.044Z"));
@ -92,7 +92,7 @@ public class GetAllocationTokenCommandTest extends CommandTestCase<GetAllocation
}
@Test
public void testSuccess_oneTokenDoesNotExist() throws Exception {
void testSuccess_oneTokenDoesNotExist() throws Exception {
createTlds("bar");
AllocationToken token =
persistResource(
@ -107,7 +107,7 @@ public class GetAllocationTokenCommandTest extends CommandTestCase<GetAllocation
}
@Test
public void testFailure_noAllocationTokensSpecified() {
void testFailure_noAllocationTokensSpecified() {
assertThrows(ParameterException.class, this::runCommand);
}
}

View file

@ -24,23 +24,23 @@ import google.registry.model.tmch.ClaimsListShard;
import java.io.File;
import java.nio.file.Files;
import org.joda.time.DateTime;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link GetClaimsListCommand}. */
public class GetClaimsListCommandTest extends CommandTestCase<GetClaimsListCommand> {
class GetClaimsListCommandTest extends CommandTestCase<GetClaimsListCommand> {
@Test
public void testSuccess_getWorks() throws Exception {
void testSuccess_getWorks() throws Exception {
ClaimsListShard.create(DateTime.now(UTC), ImmutableMap.of("a", "1", "b", "2")).save();
File output = tmpDir.newFile();
File output = tmpDir.resolve("claims.txt").toFile();
runCommand("--output=" + output.getAbsolutePath());
assertThat(readAllLines(output.toPath(), UTF_8)).containsExactly("a,1", "b,2");
}
@Test
public void testSuccess_endsWithNewline() throws Exception {
void testSuccess_endsWithNewline() throws Exception {
ClaimsListShard.create(DateTime.now(UTC), ImmutableMap.of("a", "1")).save();
File output = tmpDir.newFile();
File output = tmpDir.resolve("claims.txt").toFile();
runCommand("--output=" + output.getAbsolutePath());
assertThat(new String(Files.readAllBytes(output.toPath()), UTF_8)).endsWith("\n");
}

View file

@ -24,21 +24,21 @@ import static org.junit.Assert.assertThrows;
import com.beust.jcommander.ParameterException;
import org.joda.time.DateTime;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link GetContactCommand}. */
public class GetContactCommandTest extends CommandTestCase<GetContactCommand> {
class GetContactCommandTest extends CommandTestCase<GetContactCommand> {
DateTime now = DateTime.now(UTC);
private DateTime now = DateTime.now(UTC);
@Before
public void initialize() {
@BeforeEach
void beforeEach() {
createTld("tld");
}
@Test
public void testSuccess() throws Exception {
void testSuccess() throws Exception {
persistActiveContact("sh8013");
runCommand("sh8013");
assertInStdout("contactId=sh8013");
@ -46,7 +46,7 @@ public class GetContactCommandTest extends CommandTestCase<GetContactCommand> {
}
@Test
public void testSuccess_expand() throws Exception {
void testSuccess_expand() throws Exception {
persistActiveContact("sh8013");
runCommand("sh8013", "--expand");
assertInStdout("contactId=sh8013");
@ -55,7 +55,7 @@ public class GetContactCommandTest extends CommandTestCase<GetContactCommand> {
}
@Test
public void testSuccess_multipleArguments() throws Exception {
void testSuccess_multipleArguments() throws Exception {
persistActiveContact("sh8013");
persistActiveContact("jd1234");
runCommand("sh8013", "jd1234");
@ -66,25 +66,25 @@ public class GetContactCommandTest extends CommandTestCase<GetContactCommand> {
}
@Test
public void testSuccess_deletedContact() throws Exception {
void testSuccess_deletedContact() throws Exception {
persistDeletedContact("sh8013", now.minusDays(1));
runCommand("sh8013");
assertInStdout("Contact 'sh8013' does not exist or is deleted");
}
@Test
public void testSuccess_contactDoesNotExist() throws Exception {
void testSuccess_contactDoesNotExist() throws Exception {
runCommand("nope");
assertInStdout("Contact 'nope' does not exist or is deleted");
}
@Test
public void testFailure_noContact() {
void testFailure_noContact() {
assertThrows(ParameterException.class, this::runCommand);
}
@Test
public void testSuccess_contactDeletedInFuture() throws Exception {
void testSuccess_contactDeletedInFuture() throws Exception {
persistResource(
newContactResource("sh8013").asBuilder().setDeletionTime(now.plusDays(1)).build());
runCommand("sh8013", "--read_timestamp=" + now.plusMonths(1));

View file

@ -24,21 +24,21 @@ import static org.junit.Assert.assertThrows;
import com.beust.jcommander.ParameterException;
import org.joda.time.DateTime;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link GetDomainCommand}. */
public class GetDomainCommandTest extends CommandTestCase<GetDomainCommand> {
class GetDomainCommandTest extends CommandTestCase<GetDomainCommand> {
DateTime now = DateTime.now(UTC);
private DateTime now = DateTime.now(UTC);
@Before
public void initialize() {
@BeforeEach
void beforeEach() {
createTld("tld");
}
@Test
public void testSuccess() throws Exception {
void testSuccess() throws Exception {
persistActiveDomain("example.tld");
runCommand("example.tld");
assertInStdout("fullyQualifiedDomainName=example.tld");
@ -47,7 +47,7 @@ public class GetDomainCommandTest extends CommandTestCase<GetDomainCommand> {
}
@Test
public void testSuccess_expand() throws Exception {
void testSuccess_expand() throws Exception {
persistActiveDomain("example.tld");
runCommand("example.tld", "--expand");
assertInStdout("fullyQualifiedDomainName=example.tld");
@ -57,7 +57,7 @@ public class GetDomainCommandTest extends CommandTestCase<GetDomainCommand> {
}
@Test
public void testSuccess_multipleArguments() throws Exception {
void testSuccess_multipleArguments() throws Exception {
persistActiveDomain("example.tld");
persistActiveDomain("example2.tld");
runCommand("example.tld", "example2.tld");
@ -68,7 +68,7 @@ public class GetDomainCommandTest extends CommandTestCase<GetDomainCommand> {
}
@Test
public void testSuccess_domainDeletedInFuture() throws Exception {
void testSuccess_domainDeletedInFuture() throws Exception {
persistResource(newDomainBase("example.tld").asBuilder()
.setDeletionTime(now.plusDays(1)).build());
runCommand("example.tld", "--read_timestamp=" + now.plusMonths(1));
@ -76,31 +76,31 @@ public class GetDomainCommandTest extends CommandTestCase<GetDomainCommand> {
}
@Test
public void testSuccess_deletedDomain() throws Exception {
void testSuccess_deletedDomain() throws Exception {
persistDeletedDomain("example.tld", now.minusDays(1));
runCommand("example.tld");
assertInStdout("Domain 'example.tld' does not exist or is deleted");
}
@Test
public void testSuccess_domainDoesNotExist() throws Exception {
void testSuccess_domainDoesNotExist() throws Exception {
runCommand("something.tld");
assertInStdout("Domain 'something.tld' does not exist or is deleted");
}
@Test
public void testFailure_tldDoesNotExist() throws Exception {
void testFailure_tldDoesNotExist() throws Exception {
runCommand("example.foo");
assertInStdout("Domain 'example.foo' does not exist or is deleted");
}
@Test
public void testFailure_noDomainName() {
void testFailure_noDomainName() {
assertThrows(ParameterException.class, this::runCommand);
}
@Test
public void testSuccess_oneDomainDoesNotExist() throws Exception {
void testSuccess_oneDomainDoesNotExist() throws Exception {
persistActiveDomain("example.tld");
createTld("com");
runCommand("example.com", "example.tld");

View file

@ -24,24 +24,24 @@ import google.registry.model.domain.Period;
import google.registry.model.reporting.HistoryEntry;
import google.registry.testing.FakeClock;
import org.joda.time.DateTime;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link GetClaimsListCommand}. */
public class GetHistoryEntriesCommandTest extends CommandTestCase<GetHistoryEntriesCommand> {
class GetHistoryEntriesCommandTest extends CommandTestCase<GetHistoryEntriesCommand> {
private final FakeClock clock = new FakeClock(DateTime.parse("2000-01-01T00:00:00Z"));
private DomainBase domain;
@Before
public void setup() {
@BeforeEach
void beforeEach() {
createTld("tld");
domain = persistActiveDomain("example.tld");
}
@Test
public void testSuccess_works() throws Exception {
void testSuccess_works() throws Exception {
persistResource(
makeHistoryEntry(
domain,
@ -61,7 +61,7 @@ public class GetHistoryEntriesCommandTest extends CommandTestCase<GetHistoryEntr
}
@Test
public void testSuccess_noTrid() throws Exception {
void testSuccess_noTrid() throws Exception {
persistResource(
makeHistoryEntry(
domain,

View file

@ -24,21 +24,21 @@ import static org.junit.Assert.assertThrows;
import com.beust.jcommander.ParameterException;
import org.joda.time.DateTime;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link GetHostCommand}. */
public class GetHostCommandTest extends CommandTestCase<GetHostCommand> {
class GetHostCommandTest extends CommandTestCase<GetHostCommand> {
DateTime now = DateTime.now(UTC);
private DateTime now = DateTime.now(UTC);
@Before
public void initialize() {
@BeforeEach
void beforeEach() {
createTld("tld");
}
@Test
public void testSuccess() throws Exception {
void testSuccess() throws Exception {
persistActiveHost("ns1.example.tld");
runCommand("ns1.example.tld");
assertInStdout("fullyQualifiedHostName=ns1.example.tld");
@ -46,7 +46,7 @@ public class GetHostCommandTest extends CommandTestCase<GetHostCommand> {
}
@Test
public void testSuccess_expand() throws Exception {
void testSuccess_expand() throws Exception {
persistActiveHost("ns1.example.tld");
runCommand("ns1.example.tld", "--expand");
assertInStdout("fullyQualifiedHostName=ns1.example.tld");
@ -55,7 +55,7 @@ public class GetHostCommandTest extends CommandTestCase<GetHostCommand> {
}
@Test
public void testSuccess_multipleArguments() throws Exception {
void testSuccess_multipleArguments() throws Exception {
persistActiveHost("ns1.example.tld");
persistActiveHost("ns2.example.tld");
runCommand("ns1.example.tld", "ns2.example.tld");
@ -66,7 +66,7 @@ public class GetHostCommandTest extends CommandTestCase<GetHostCommand> {
}
@Test
public void testSuccess_multipleTlds() throws Exception {
void testSuccess_multipleTlds() throws Exception {
persistActiveHost("ns1.example.tld");
createTld("tld2");
persistActiveHost("ns1.example.tld2");
@ -76,20 +76,20 @@ public class GetHostCommandTest extends CommandTestCase<GetHostCommand> {
}
@Test
public void testSuccess_deletedHost() throws Exception {
void testSuccess_deletedHost() throws Exception {
persistDeletedHost("ns1.example.tld", now.minusDays(1));
runCommand("ns1.example.tld");
assertInStdout("Host 'ns1.example.tld' does not exist or is deleted");
}
@Test
public void testSuccess_hostDoesNotExist() throws Exception {
void testSuccess_hostDoesNotExist() throws Exception {
runCommand("foo.example.tld");
assertInStdout("Host 'foo.example.tld' does not exist or is deleted");
}
@Test
public void testSuccess_hostDeletedInFuture() throws Exception {
void testSuccess_hostDeletedInFuture() throws Exception {
persistResource(
newHostResource("ns1.example.tld").asBuilder()
.setDeletionTime(now.plusDays(1))
@ -99,14 +99,14 @@ public class GetHostCommandTest extends CommandTestCase<GetHostCommand> {
}
@Test
public void testSuccess_externalHost() throws Exception {
void testSuccess_externalHost() throws Exception {
persistActiveHost("ns1.example.foo");
runCommand("ns1.example.foo");
assertInStdout("fullyQualifiedHostName=ns1.example.foo");
}
@Test
public void testFailure_noHostName() {
void testFailure_noHostName() {
assertThrows(ParameterException.class, this::runCommand);
}
}

View file

@ -22,24 +22,23 @@ import google.registry.export.datastore.DatastoreAdmin;
import google.registry.export.datastore.DatastoreAdmin.Get;
import google.registry.export.datastore.Operation;
import java.io.IOException;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
/** Unit tests for {@link GetOperationStatusCommand}. */
@RunWith(JUnit4.class)
public class GetOperationStatusCommandTest extends CommandTestCase<GetOperationStatusCommand> {
class GetOperationStatusCommandTest extends CommandTestCase<GetOperationStatusCommand> {
@Mock private DatastoreAdmin datastoreAdmin;
@Mock private Get getRequest;
@Captor ArgumentCaptor<String> operationName;
@Before
public void setup() throws IOException {
@BeforeEach
void beforeEach() throws IOException {
command.datastoreAdmin = datastoreAdmin;
when(datastoreAdmin.get(operationName.capture())).thenReturn(getRequest);
@ -47,13 +46,14 @@ public class GetOperationStatusCommandTest extends CommandTestCase<GetOperationS
}
@Test
public void test_success() throws Exception {
void test_success() throws Exception {
runCommand("projects/project-id/operations/HASH");
assertThat(operationName.getValue()).isEqualTo("projects/project-id/operations/HASH");
}
@Test
public void test_failure_tooManyNames() {
@MockitoSettings(strictness = Strictness.LENIENT)
void test_failure_tooManyNames() {
assertThrows(IllegalArgumentException.class, () -> runCommand("a", "b"));
}
}

View file

@ -18,37 +18,37 @@ import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertThrows;
import com.beust.jcommander.ParameterException;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link GetRegistrarCommand}. */
public class GetRegistrarCommandTest extends CommandTestCase<GetRegistrarCommand> {
class GetRegistrarCommandTest extends CommandTestCase<GetRegistrarCommand> {
@Test
public void testSuccess() throws Exception {
void testSuccess() throws Exception {
// This registrar is created by AppEngineRule.
runCommand("NewRegistrar");
}
@Test
public void testSuccess_multipleArguments() throws Exception {
void testSuccess_multipleArguments() throws Exception {
// Registrars are created by AppEngineRule.
runCommand("NewRegistrar", "TheRegistrar");
}
@Test
public void testFailure_registrarDoesNotExist() {
void testFailure_registrarDoesNotExist() {
IllegalArgumentException thrown =
assertThrows(IllegalArgumentException.class, () -> runCommand("ClientZ"));
assertThat(thrown).hasMessageThat().contains("Registrar with id ClientZ does not exist");
}
@Test
public void testFailure_noRegistrarName() {
void testFailure_noRegistrarName() {
assertThrows(ParameterException.class, this::runCommand);
}
@Test
public void testFailure_oneRegistrarDoesNotExist() {
void testFailure_oneRegistrarDoesNotExist() {
IllegalArgumentException thrown =
assertThrows(IllegalArgumentException.class, () -> runCommand("NewRegistrar", "ClientZ"));
assertThat(thrown).hasMessageThat().contains("Registrar with id ClientZ does not exist");

View file

@ -27,21 +27,21 @@ import static org.junit.Assert.assertThrows;
import com.beust.jcommander.ParameterException;
import org.joda.time.DateTime;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link GetResourceByKeyCommand}. */
public class GetResourceByKeyCommandTest extends CommandTestCase<GetResourceByKeyCommand> {
class GetResourceByKeyCommandTest extends CommandTestCase<GetResourceByKeyCommand> {
DateTime now = DateTime.now(UTC);
private DateTime now = DateTime.now(UTC);
@Before
public void initialize() {
@BeforeEach
void beforeEach() {
createTld("tld");
}
@Test
public void testSuccess_domain() throws Exception {
void testSuccess_domain() throws Exception {
persistActiveDomain("example.tld");
runCommand("agR0ZXN0chULEgpEb21haW5CYXNlIgUyLVRMRAw");
assertInStdout("fullyQualifiedDomainName=example.tld");
@ -49,7 +49,7 @@ public class GetResourceByKeyCommandTest extends CommandTestCase<GetResourceByKe
}
@Test
public void testSuccess_domain_expand() throws Exception {
void testSuccess_domain_expand() throws Exception {
persistActiveDomain("example.tld");
runCommand("agR0ZXN0chULEgpEb21haW5CYXNlIgUyLVRMRAw", "--expand");
assertInStdout("fullyQualifiedDomainName=example.tld");
@ -58,7 +58,7 @@ public class GetResourceByKeyCommandTest extends CommandTestCase<GetResourceByKe
}
@Test
public void testSuccess_domain_multipleArguments() throws Exception {
void testSuccess_domain_multipleArguments() throws Exception {
persistActiveDomain("example.tld");
persistActiveDomain("example2.tld");
runCommand(
@ -68,7 +68,7 @@ public class GetResourceByKeyCommandTest extends CommandTestCase<GetResourceByKe
}
@Test
public void testFailure_domain_oneDoesNotExist() {
void testFailure_domain_oneDoesNotExist() {
persistActiveDomain("example.tld");
NullPointerException thrown =
assertThrows(
@ -83,7 +83,7 @@ public class GetResourceByKeyCommandTest extends CommandTestCase<GetResourceByKe
}
@Test
public void testSuccess_deletedDomain() throws Exception {
void testSuccess_deletedDomain() throws Exception {
persistDeletedDomain("example.tld", now.minusDays(1));
runCommand("agR0ZXN0chULEgpEb21haW5CYXNlIgUyLVRMRAw");
assertInStdout("fullyQualifiedDomainName=example.tld");
@ -91,14 +91,14 @@ public class GetResourceByKeyCommandTest extends CommandTestCase<GetResourceByKe
}
@Test
public void testSuccess_contact() throws Exception {
void testSuccess_contact() throws Exception {
persistActiveContact("sh8013");
runCommand("agR0ZXN0chsLEg9Db250YWN0UmVzb3VyY2UiBjItUk9JRAw");
assertInStdout("contactId=sh8013");
}
@Test
public void testSuccess_contact_expand() throws Exception {
void testSuccess_contact_expand() throws Exception {
persistActiveContact("sh8013");
runCommand("agR0ZXN0chsLEg9Db250YWN0UmVzb3VyY2UiBjItUk9JRAw", "--expand");
assertInStdout("contactId=sh8013");
@ -106,7 +106,7 @@ public class GetResourceByKeyCommandTest extends CommandTestCase<GetResourceByKe
}
@Test
public void testSuccess_contact_multipleArguments() throws Exception {
void testSuccess_contact_multipleArguments() throws Exception {
persistActiveContact("sh8013");
persistActiveContact("jd1234");
runCommand(
@ -117,7 +117,7 @@ public class GetResourceByKeyCommandTest extends CommandTestCase<GetResourceByKe
}
@Test
public void testFailure_contact_oneDoesNotExist() {
void testFailure_contact_oneDoesNotExist() {
persistActiveContact("sh8013");
NullPointerException thrown =
assertThrows(
@ -132,7 +132,7 @@ public class GetResourceByKeyCommandTest extends CommandTestCase<GetResourceByKe
}
@Test
public void testSuccess_deletedContact() throws Exception {
void testSuccess_deletedContact() throws Exception {
persistDeletedContact("sh8013", now.minusDays(1));
runCommand("agR0ZXN0chsLEg9Db250YWN0UmVzb3VyY2UiBjItUk9JRAw");
assertInStdout("contactId=sh8013");
@ -140,14 +140,14 @@ public class GetResourceByKeyCommandTest extends CommandTestCase<GetResourceByKe
}
@Test
public void testSuccess_host() throws Exception {
void testSuccess_host() throws Exception {
persistActiveHost("ns1.example.tld");
runCommand("agR0ZXN0chgLEgxIb3N0UmVzb3VyY2UiBjItUk9JRAw");
assertInStdout("fullyQualifiedHostName=ns1.example.tld");
}
@Test
public void testSuccess_host_expand() throws Exception {
void testSuccess_host_expand() throws Exception {
persistActiveHost("ns1.example.tld");
runCommand("agR0ZXN0chgLEgxIb3N0UmVzb3VyY2UiBjItUk9JRAw", "--expand");
assertInStdout("fullyQualifiedHostName=ns1.example.tld");
@ -155,7 +155,7 @@ public class GetResourceByKeyCommandTest extends CommandTestCase<GetResourceByKe
}
@Test
public void testSuccess_host_multipleArguments() throws Exception {
void testSuccess_host_multipleArguments() throws Exception {
persistActiveHost("ns1.example.tld");
persistActiveHost("ns2.example.tld");
runCommand(
@ -166,7 +166,7 @@ public class GetResourceByKeyCommandTest extends CommandTestCase<GetResourceByKe
}
@Test
public void testFailure_host_oneDoesNotExist() {
void testFailure_host_oneDoesNotExist() {
persistActiveHost("ns1.example.tld");
NullPointerException thrown =
assertThrows(
@ -181,7 +181,7 @@ public class GetResourceByKeyCommandTest extends CommandTestCase<GetResourceByKe
}
@Test
public void testSuccess_deletedHost() throws Exception {
void testSuccess_deletedHost() throws Exception {
persistDeletedHost("ns1.example.tld", now.minusDays(1));
runCommand("agR0ZXN0chgLEgxIb3N0UmVzb3VyY2UiBjItUk9JRAw");
assertInStdout("fullyQualifiedHostName=ns1.example.tld");
@ -189,7 +189,7 @@ public class GetResourceByKeyCommandTest extends CommandTestCase<GetResourceByKe
}
@Test
public void testSuccess_mixedTypes() throws Exception {
void testSuccess_mixedTypes() throws Exception {
persistActiveDomain("example.tld");
persistActiveContact("sh8013");
persistActiveHost("ns1.example.tld");
@ -203,7 +203,7 @@ public class GetResourceByKeyCommandTest extends CommandTestCase<GetResourceByKe
}
@Test
public void testFailure_keyDoesNotExist() {
void testFailure_keyDoesNotExist() {
NullPointerException thrown =
assertThrows(
NullPointerException.class,
@ -214,7 +214,7 @@ public class GetResourceByKeyCommandTest extends CommandTestCase<GetResourceByKe
}
@Test
public void testFailure_nonsenseKey() {
void testFailure_nonsenseKey() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class, () -> runCommand("agR0ZXN0chULEgpEb21haW5CYXN"));
@ -222,7 +222,7 @@ public class GetResourceByKeyCommandTest extends CommandTestCase<GetResourceByKe
}
@Test
public void testFailure_noParameters() {
void testFailure_noParameters() {
assertThrows(ParameterException.class, this::runCommand);
}
}

View file

@ -19,12 +19,13 @@ import static com.google.common.truth.Truth.assertWithMessage;
import com.google.re2j.Matcher;
import com.google.re2j.Pattern;
import google.registry.model.EntityClasses;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link GetSchemaTreeCommand}. */
public class GetSchemaTreeCommandTest extends CommandTestCase<GetSchemaTreeCommand> {
class GetSchemaTreeCommandTest extends CommandTestCase<GetSchemaTreeCommand> {
@Test
public void testAllClassesPrintedExactlyOnce() throws Exception {
void testAllClassesPrintedExactlyOnce() throws Exception {
runCommand();
String stdout = getStdoutAsString();
for (Class<?> clazz : EntityClasses.ALL_CLASSES) {

View file

@ -19,36 +19,35 @@ import static google.registry.testing.DatastoreHelper.createTlds;
import static org.junit.Assert.assertThrows;
import com.beust.jcommander.ParameterException;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link GetTldCommand}. */
public class GetTldCommandTest extends CommandTestCase<GetTldCommand> {
class GetTldCommandTest extends CommandTestCase<GetTldCommand> {
@Test
public void testSuccess() throws Exception {
void testSuccess() throws Exception {
createTld("xn--q9jyb4c");
runCommand("xn--q9jyb4c");
}
@Test
public void testSuccess_multipleArguments() throws Exception {
void testSuccess_multipleArguments() throws Exception {
createTlds("xn--q9jyb4c", "example");
runCommand("xn--q9jyb4c", "example");
}
@Test
public void testFailure_tldDoesNotExist() {
void testFailure_tldDoesNotExist() {
assertThrows(IllegalArgumentException.class, () -> runCommand("xn--q9jyb4c"));
}
@Test
public void testFailure_noTldName() {
void testFailure_noTldName() {
assertThrows(ParameterException.class, this::runCommand);
}
@Test
public void testFailure_oneTldDoesNotExist() {
void testFailure_oneTldDoesNotExist() {
createTld("xn--q9jyb4c");
assertThrows(IllegalArgumentException.class, () -> runCommand("xn--q9jyb4c", "example"));
}

View file

@ -25,12 +25,12 @@ import google.registry.testing.FakeKeyringModule;
import google.registry.testing.InjectRule;
import java.nio.file.Files;
import java.nio.file.Path;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
/** Unit tests for {@link GhostrydeCommand}. */
public class GhostrydeCommandTest extends CommandTestCase<GhostrydeCommand> {
class GhostrydeCommandTest extends CommandTestCase<GhostrydeCommand> {
private static final byte[] SONG_BY_CHRISTINA_ROSSETTI = (""
+ "When I am dead, my dearest, \n"
@ -51,50 +51,50 @@ public class GhostrydeCommandTest extends CommandTestCase<GhostrydeCommand> {
+ "Haply I may remember, \n"
+ " And haply may forget. \n").getBytes(UTF_8);
@Rule
public final InjectRule inject = new InjectRule();
@RegisterExtension final InjectRule inject = new InjectRule();
@Rule
public final BouncyCastleProviderRule bouncy = new BouncyCastleProviderRule();
@RegisterExtension final BouncyCastleProviderRule bouncy = new BouncyCastleProviderRule();
private Keyring keyring;
@Before
public void before() {
@BeforeEach
void beforeEach() {
keyring = new FakeKeyringModule().get();
command.rdeStagingDecryptionKey = keyring::getRdeStagingDecryptionKey;
command.rdeStagingEncryptionKey = keyring::getRdeStagingEncryptionKey;
}
@Test
public void testParameters_cantSpecifyBothEncryptAndDecrypt() {
void testParameters_cantSpecifyBothEncryptAndDecrypt() {
IllegalArgumentException thrown =
assertThrows(IllegalArgumentException.class, () -> runCommand("--encrypt", "--decrypt"));
assertThat(thrown).hasMessageThat().isEqualTo("Please specify either --encrypt or --decrypt");
}
@Test
public void testParameters_mustSpecifyOneOfEncryptOrDecrypt() {
void testParameters_mustSpecifyOneOfEncryptOrDecrypt() throws Exception {
Path inputFile = Files.createFile(tmpDir.resolve("foo.dat"));
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
() -> runCommand("--input=" + tmpDir.newFile(), "--output=" + tmpDir.newFile()));
() -> runCommand("--input=" + inputFile.toString(), "--output=bar.dat"));
assertThat(thrown).hasMessageThat().isEqualTo("Please specify either --encrypt or --decrypt");
}
@Test
public void testEncrypt_outputPathIsRequired() {
void testEncrypt_outputPathIsRequired() throws Exception {
Path inputFile = Files.createFile(tmpDir.resolve("foo.dat"));
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
() -> runCommand("--encrypt", "--input=" + tmpDir.newFile()));
() -> runCommand("--encrypt", "--input=" + inputFile.toString()));
assertThat(thrown).hasMessageThat().isEqualTo("--output path is required in --encrypt mode");
}
@Test
public void testEncrypt_outputIsAFile_writesToFile() throws Exception {
Path inFile = tmpDir.newFile("atrain.txt").toPath();
Path outFile = tmpDir.newFile().toPath();
void testEncrypt_outputIsAFile_writesToFile() throws Exception {
Path inFile = tmpDir.resolve("atrain.txt");
Path outFile = tmpDir.resolve("out.dat");
Files.write(inFile, SONG_BY_CHRISTINA_ROSSETTI);
runCommand("--encrypt", "--input=" + inFile, "--output=" + outFile);
byte[] decoded =
@ -103,24 +103,23 @@ public class GhostrydeCommandTest extends CommandTestCase<GhostrydeCommand> {
}
@Test
public void testEncrypt_outputIsADirectory_appendsGhostrydeExtension() throws Exception {
Path inFile = tmpDir.newFile("atrain.txt").toPath();
Path outDir = tmpDir.newFolder().toPath();
void testEncrypt_outputIsADirectory_appendsGhostrydeExtension() throws Exception {
Path inFile = tmpDir.resolve("atrain.txt");
Files.write(inFile, SONG_BY_CHRISTINA_ROSSETTI);
runCommand("--encrypt", "--input=" + inFile, "--output=" + outDir);
Path lenOutFile = outDir.resolve("atrain.txt.length");
runCommand("--encrypt", "--input=" + inFile, "--output=" + tmpDir.toString());
Path lenOutFile = tmpDir.resolve("atrain.txt.length");
assertThat(Ghostryde.readLength(Files.newInputStream(lenOutFile)))
.isEqualTo(SONG_BY_CHRISTINA_ROSSETTI.length);
Path outFile = outDir.resolve("atrain.txt.ghostryde");
Path outFile = tmpDir.resolve("atrain.txt.ghostryde");
byte[] decoded =
Ghostryde.decode(Files.readAllBytes(outFile), keyring.getRdeStagingDecryptionKey());
assertThat(decoded).isEqualTo(SONG_BY_CHRISTINA_ROSSETTI);
}
@Test
public void testDecrypt_outputIsAFile_writesToFile() throws Exception {
Path inFile = tmpDir.newFile().toPath();
Path outFile = tmpDir.newFile().toPath();
void testDecrypt_outputIsAFile_writesToFile() throws Exception {
Path inFile = tmpDir.resolve("atrain.txt");
Path outFile = tmpDir.resolve("out.dat");
Files.write(
inFile, Ghostryde.encode(SONG_BY_CHRISTINA_ROSSETTI, keyring.getRdeStagingEncryptionKey()));
runCommand("--decrypt", "--input=" + inFile, "--output=" + outFile);
@ -128,19 +127,18 @@ public class GhostrydeCommandTest extends CommandTestCase<GhostrydeCommand> {
}
@Test
public void testDecrypt_outputIsADirectory_AppendsDecryptExtension() throws Exception {
Path inFile = tmpDir.newFolder().toPath().resolve("atrain.ghostryde");
Path outDir = tmpDir.newFolder().toPath();
void testDecrypt_outputIsADirectory_AppendsDecryptExtension() throws Exception {
Path inFile = tmpDir.resolve("atrain.ghostryde");
Files.write(
inFile, Ghostryde.encode(SONG_BY_CHRISTINA_ROSSETTI, keyring.getRdeStagingEncryptionKey()));
runCommand("--decrypt", "--input=" + inFile, "--output=" + outDir);
Path outFile = outDir.resolve("atrain.ghostryde.decrypt");
runCommand("--decrypt", "--input=" + inFile, "--output=" + tmpDir.toString());
Path outFile = tmpDir.resolve("atrain.ghostryde.decrypt");
assertThat(Files.readAllBytes(outFile)).isEqualTo(SONG_BY_CHRISTINA_ROSSETTI);
}
@Test
public void testDecrypt_outputIsStdOut() throws Exception {
Path inFile = tmpDir.newFolder().toPath().resolve("atrain.ghostryde");
void testDecrypt_outputIsStdOut() throws Exception {
Path inFile = tmpDir.resolve("atrain.ghostryde");
Files.write(
inFile, Ghostryde.encode(SONG_BY_CHRISTINA_ROSSETTI, keyring.getRdeStagingEncryptionKey()));
runCommand("--decrypt", "--input=" + inFile);

View file

@ -27,17 +27,17 @@ import google.registry.export.datastore.DatastoreAdmin.Get;
import google.registry.export.datastore.DatastoreAdmin.Import;
import google.registry.export.datastore.Operation;
import java.util.Collection;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
/** Unit tests for {@link ImportDatastoreCommand}. */
@RunWith(JUnit4.class)
public class ImportDatastoreCommandTest extends CommandTestCase<ImportDatastoreCommand> {
@MockitoSettings(strictness = Strictness.LENIENT)
class ImportDatastoreCommandTest extends CommandTestCase<ImportDatastoreCommand> {
@Captor ArgumentCaptor<String> backupUrl;
@Captor ArgumentCaptor<Collection<String>> kinds;
@ -49,8 +49,8 @@ public class ImportDatastoreCommandTest extends CommandTestCase<ImportDatastoreC
@Mock private Operation importOperation;
@Mock private Operation getOperation;
@Before
public void setup() throws Exception {
@BeforeEach
void beforeEach() throws Exception {
command.datastoreAdmin = datastoreAdmin;
when(datastoreAdmin.importBackup(backupUrl.capture(), kinds.capture()))
@ -63,7 +63,7 @@ public class ImportDatastoreCommandTest extends CommandTestCase<ImportDatastoreC
}
@Test
public void test_importAllKinds_immediateSuccess() throws Exception {
void test_importAllKinds_immediateSuccess() throws Exception {
runCommandForced(
"--poll_interval", "PT0.001S",
"--backup_url", "gs://bucket/export-id/export-id.overall_export_metadata");
@ -74,7 +74,7 @@ public class ImportDatastoreCommandTest extends CommandTestCase<ImportDatastoreC
}
@Test
public void test_importSomeKinds_immediateSuccess() throws Exception {
void test_importSomeKinds_immediateSuccess() throws Exception {
runCommandForced(
"--poll_interval",
"PT0.001S",
@ -91,7 +91,7 @@ public class ImportDatastoreCommandTest extends CommandTestCase<ImportDatastoreC
}
@Test
public void test_delayedSuccess_sync() throws Exception {
void test_delayedSuccess_sync() throws Exception {
when(importOperation.isProcessing()).thenReturn(true);
when(getOperation.isProcessing()).thenReturn(true).thenReturn(false);
when(getOperation.isSuccessful()).thenReturn(true);
@ -103,7 +103,7 @@ public class ImportDatastoreCommandTest extends CommandTestCase<ImportDatastoreC
}
@Test
public void test_delayedSuccess_async() throws Exception {
void test_delayedSuccess_async() throws Exception {
when(importOperation.isProcessing()).thenReturn(false);
when(getOperation.isProcessing()).thenReturn(true).thenReturn(false);
when(getOperation.isSuccessful()).thenReturn(true);
@ -118,7 +118,7 @@ public class ImportDatastoreCommandTest extends CommandTestCase<ImportDatastoreC
}
@Test
public void test_failure_notAllowedInProduction() {
void test_failure_notAllowedInProduction() {
assertThrows(
IllegalArgumentException.class,
() ->
@ -132,7 +132,7 @@ public class ImportDatastoreCommandTest extends CommandTestCase<ImportDatastoreC
}
@Test
public void test_success_runInProduction() throws Exception {
void test_success_runInProduction() throws Exception {
runCommandInEnvironment(
RegistryToolEnvironment.PRODUCTION,
"--force",

View file

@ -28,6 +28,7 @@ import java.io.IOException;
/** Utility class for building a leveldb logfile. */
public final class LevelDbFileBuilder {
private final FileOutputStream out;
private byte[] currentBlock = new byte[BLOCK_SIZE];

View file

@ -28,26 +28,24 @@ import google.registry.testing.DatastoreHelper;
import google.registry.tools.EntityWrapper.Property;
import java.io.File;
import java.io.IOException;
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.nio.file.Path;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.api.io.TempDir;
@RunWith(JUnit4.class)
/** Unit tests for {@link LevelDbFileBuilder}. */
public class LevelDbFileBuilderTest {
public static final int BASE_ID = 1001;
private static final int BASE_ID = 1001;
@Rule public final TemporaryFolder tempFs = new TemporaryFolder();
@TempDir Path tmpDir;
@Rule
@RegisterExtension
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
@Test
public void testSingleRecordWrites() throws IOException {
File subdir = tempFs.newFolder("folder");
File logFile = new File(subdir, "testfile");
void testSingleRecordWrites() throws IOException {
File logFile = tmpDir.resolve("testfile").toFile();
LevelDbFileBuilder builder = new LevelDbFileBuilder(logFile);
EntityWrapper entity =
EntityWrapper.from(
@ -64,9 +62,8 @@ public class LevelDbFileBuilderTest {
}
@Test
public void testMultipleRecordWrites() throws IOException {
File subdir = tempFs.newFolder("folder");
File logFile = new File(subdir, "testfile");
void testMultipleRecordWrites() throws IOException {
File logFile = tmpDir.resolve("testfile").toFile();
LevelDbFileBuilder builder = new LevelDbFileBuilder(logFile);
// Generate enough records to cross a block boundary. These records end up being around 80
@ -93,9 +90,8 @@ public class LevelDbFileBuilderTest {
}
@Test
public void testOfyEntityWrite() throws Exception {
File subdir = tempFs.newFolder("folder");
File logFile = new File(subdir, "testfile");
void testOfyEntityWrite() throws Exception {
File logFile = tmpDir.resolve("testfile").toFile();
LevelDbFileBuilder builder = new LevelDbFileBuilder(logFile);
ContactResource contact = DatastoreHelper.newContactResource("contact");

View file

@ -31,7 +31,7 @@ import java.util.List;
import org.junit.jupiter.api.Test;
/** Unit tests of {@link LevelDbLogReader}. */
public final class LevelDbLogReaderTest {
final class LevelDbLogReaderTest {
// Size of the test record. Any value < 256 will do.
private static final int TEST_RECORD_SIZE = 231;
@ -53,13 +53,13 @@ public final class LevelDbLogReaderTest {
}
@Test
public void testSimpleBlock() throws IOException {
void testSimpleBlock() throws IOException {
TestBlock block = makeBlockOfRepeatingBytes(0);
assertThat(readIncrementally(block.data)).hasSize(block.recordCount);
}
@Test
public void testLargeRecord() throws IOException {
void testLargeRecord() throws IOException {
byte[] block0 = new byte[LevelDbLogReader.BLOCK_SIZE];
addRecord(block0, 0, ChunkType.FIRST, MAX_RECORD, (byte) 1);
assertThat(readIncrementally(block0)).isEmpty();
@ -88,7 +88,7 @@ public final class LevelDbLogReaderTest {
}
@Test
public void readFromMultiBlockStream() throws IOException {
void readFromMultiBlockStream() throws IOException {
TestBlock block0 = makeBlockOfRepeatingBytes(0);
TestBlock block1 = makeBlockOfRepeatingBytes(138);
assertThat(readIncrementally(block0.data, block1.data))
@ -112,7 +112,7 @@ public final class LevelDbLogReaderTest {
}
@Test
public void testChunkTypesToCode() {
void testChunkTypesToCode() {
// Verify that we're translating chunk types to code values correctly.z
assertThat(ChunkType.fromCode(ChunkType.END.getCode())).isEqualTo(ChunkType.END);
assertThat(ChunkType.fromCode(ChunkType.FULL.getCode())).isEqualTo(ChunkType.FULL);

View file

@ -20,7 +20,7 @@ import google.registry.tools.LevelDbLogReader.ChunkType;
class LevelDbUtil {
public static final int MAX_RECORD = LevelDbLogReader.BLOCK_SIZE - LevelDbLogReader.HEADER_SIZE;
static final int MAX_RECORD = LevelDbLogReader.BLOCK_SIZE - LevelDbLogReader.HEADER_SIZE;
/** Adds a new record header to "bytes" at "pos", returns the new position. */
private static int addRecordHeader(byte[] bytes, int pos, ChunkType type, int size) {

View file

@ -27,9 +27,9 @@ import google.registry.model.registry.Registry;
import google.registry.testing.FakeClock;
import google.registry.testing.InjectRule;
import org.joda.time.DateTime;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
/** Unit tests for {@link ListCursorsCommand}. */
public class ListCursorsCommandTest extends CommandTestCase<ListCursorsCommand> {
@ -40,22 +40,22 @@ public class ListCursorsCommandTest extends CommandTestCase<ListCursorsCommand>
private static final String HEADER_TWO =
"--------------------------------------------------------------------------";
@Rule public final InjectRule inject = new InjectRule();
@RegisterExtension public final InjectRule inject = new InjectRule();
@Before
public void before() {
@BeforeEach
void beforeEach() {
inject.setStaticField(
Ofy.class, "clock", new FakeClock(DateTime.parse("1984-12-21T06:07:08.789Z")));
}
@Test
public void testListCursors_noTlds_printsNothing() throws Exception {
void testListCursors_noTlds_printsNothing() throws Exception {
runCommand("--type=BRDA");
assertThat(getStdoutAsString()).isEmpty();
}
@Test
public void testListCursors_twoTldsOneAbsent_printsAbsentAndTimestampSorted() throws Exception {
void testListCursors_twoTldsOneAbsent_printsAbsentAndTimestampSorted() throws Exception {
createTlds("foo", "bar");
persistResource(
Cursor.create(CursorType.BRDA, DateTime.parse("1984-12-18TZ"), Registry.get("bar")));
@ -70,19 +70,19 @@ public class ListCursorsCommandTest extends CommandTestCase<ListCursorsCommand>
}
@Test
public void testListCursors_badCursor_throwsIae() {
void testListCursors_badCursor_throwsIae() {
ParameterException thrown =
assertThrows(ParameterException.class, () -> runCommand("--type=love"));
assertThat(thrown).hasMessageThat().contains("Invalid value for --type parameter.");
}
@Test
public void testListCursors_lowercaseCursor_isAllowed() throws Exception {
void testListCursors_lowercaseCursor_isAllowed() throws Exception {
runCommand("--type=brda");
}
@Test
public void testListCursors_filterEscrowEnabled_doesWhatItSays() throws Exception {
void testListCursors_filterEscrowEnabled_doesWhatItSays() throws Exception {
createTlds("foo", "bar");
persistResource(Registry.get("bar").asBuilder().setEscrowEnabled(true).build());
runCommand("--type=BRDA", "--escrow_enabled");

View file

@ -27,18 +27,14 @@ import google.registry.testing.FakeClock;
import google.registry.util.Clock;
import java.io.IOException;
import org.joda.time.DateTime;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
/** Unit tests for {@link google.registry.tools.ListDatastoreOperationsCommand}. */
@RunWith(JUnit4.class)
public class ListDatastoreOperationsCommandTest
extends CommandTestCase<ListDatastoreOperationsCommand> {
class ListDatastoreOperationsCommandTest extends CommandTestCase<ListDatastoreOperationsCommand> {
@Mock private DatastoreAdmin datastoreAdmin;
@Mock private ListOperations listOperationsRequest;
@ -46,25 +42,24 @@ public class ListDatastoreOperationsCommandTest
private final Clock clock = new FakeClock(new DateTime("2019-01-01T00:00:30Z"));
@Before
public void setup() throws IOException {
@BeforeEach
void beforeEach() throws IOException {
command.datastoreAdmin = datastoreAdmin;
command.clock = clock;
when(datastoreAdmin.list(filterClause.capture())).thenReturn(listOperationsRequest);
when(datastoreAdmin.listAll()).thenReturn(listOperationsRequest);
when(listOperationsRequest.execute()).thenReturn(new OperationList());
}
@Test
public void testListAll() throws Exception {
void testListAll() throws Exception {
when(datastoreAdmin.listAll()).thenReturn(listOperationsRequest);
runCommand();
verify(datastoreAdmin, times(1)).listAll();
verifyNoMoreInteractions(datastoreAdmin);
}
@Test
public void testListWithFilter() throws Exception {
void testListWithFilter() throws Exception {
when(datastoreAdmin.list(filterClause.capture())).thenReturn(listOperationsRequest);
runCommand("--start_time_filter=PT30S");
verify(datastoreAdmin, times(1)).list(filterClause.capture());
assertThat(filterClause.getValue())

View file

@ -27,7 +27,9 @@ import com.google.common.collect.ImmutableMap;
import com.google.common.net.MediaType;
import google.registry.model.registry.Registry.TldType;
import google.registry.tools.server.ListDomainsAction;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
/**
* Unit tests for {@link ListDomainsCommand}.
@ -47,7 +49,8 @@ public class ListDomainsCommandTest extends ListObjectsCommandTestCase<ListDomai
}
@Test
public void test_tldsParamTooLong() {
@MockitoSettings(strictness = Strictness.LENIENT)
void test_tldsParamTooLong() {
String tldsParam = "--tlds=foo,bar" + Strings.repeat(",baz", 300);
IllegalArgumentException thrown =
assertThrows(IllegalArgumentException.class, () -> runCommand(tldsParam));
@ -57,7 +60,7 @@ public class ListDomainsCommandTest extends ListObjectsCommandTestCase<ListDomai
}
@Test
public void test_bothParamsSpecified() throws Exception {
void test_bothParamsSpecified() throws Exception {
runCommand("--tlds=foo,bar", "--limit=100");
verify(connection)
.sendPostRequest(
@ -68,7 +71,7 @@ public class ListDomainsCommandTest extends ListObjectsCommandTestCase<ListDomai
}
@Test
public void test_defaultsToAllRealTlds() throws Exception {
void test_defaultsToAllRealTlds() throws Exception {
createTlds("tldone", "tldtwo");
persistResource(newRegistry("fake", "FAKE").asBuilder().setTldType(TldType.TEST).build());
runCommand();

View file

@ -21,7 +21,7 @@ import google.registry.tools.server.ListHostsAction;
*
* @see ListObjectsCommandTestCase
*/
public class ListHostsCommandTest extends ListObjectsCommandTestCase<ListHostsCommand> {
class ListHostsCommandTest extends ListObjectsCommandTestCase<ListHostsCommand> {
@Override
final String getTaskPath() {

View file

@ -29,8 +29,8 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.net.MediaType;
import java.util.Optional;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
/** Abstract base class for unit tests of commands that list object data using a back-end task. */
@ -47,16 +47,14 @@ public abstract class ListObjectsCommandTestCase<C extends ListObjectsCommand>
return ImmutableMap.of();
}
ImmutableList<String> otherParams = ImmutableList.of();
private ImmutableList<String> otherParams = ImmutableList.of();
@Before
public void init() throws Exception {
@BeforeEach
void beforeEachListObjectsCommandTestCase() throws Exception {
ImmutableMap<String, Object> otherParameters = getOtherParameters();
if (!otherParameters.isEmpty()) {
otherParams =
otherParameters
.entrySet()
.stream()
otherParameters.entrySet().stream()
.map(entry -> String.format("--%s=%s", entry.getKey(), entry.getValue()))
.collect(toImmutableList());
}
@ -83,26 +81,26 @@ public abstract class ListObjectsCommandTestCase<C extends ListObjectsCommand>
}
@Test
public void testRun_noFields() throws Exception {
void testRun_noFields() throws Exception {
runCommand(otherParams);
verifySent(null, Optional.empty(), Optional.empty());
}
@Test
public void testRun_oneField() throws Exception {
void testRun_oneField() throws Exception {
runCommand(
new ImmutableList.Builder<String>().addAll(otherParams).add("--fields=fieldName").build());
verifySent("fieldName", Optional.empty(), Optional.empty());
}
@Test
public void testRun_wildcardField() throws Exception {
void testRun_wildcardField() throws Exception {
runCommand(new ImmutableList.Builder<String>().addAll(otherParams).add("--fields=*").build());
verifySent("*", Optional.empty(), Optional.empty());
}
@Test
public void testRun_header() throws Exception {
void testRun_header() throws Exception {
runCommand(
new ImmutableList.Builder<String>()
.addAll(otherParams)
@ -112,7 +110,7 @@ public abstract class ListObjectsCommandTestCase<C extends ListObjectsCommand>
}
@Test
public void testRun_noHeader() throws Exception {
void testRun_noHeader() throws Exception {
runCommand(
new ImmutableList.Builder<String>()
.addAll(otherParams)
@ -122,7 +120,7 @@ public abstract class ListObjectsCommandTestCase<C extends ListObjectsCommand>
}
@Test
public void testRun_fullFieldNames() throws Exception {
void testRun_fullFieldNames() throws Exception {
runCommand(
new ImmutableList.Builder<String>()
.addAll(otherParams)
@ -132,7 +130,7 @@ public abstract class ListObjectsCommandTestCase<C extends ListObjectsCommand>
}
@Test
public void testRun_allParameters() throws Exception {
void testRun_allParameters() throws Exception {
runCommand(
new ImmutableList.Builder<String>()
.addAll(otherParams)

View file

@ -21,8 +21,7 @@ import google.registry.tools.server.ListPremiumListsAction;
*
* @see ListObjectsCommandTestCase
*/
public class ListPremiumListsCommandTest
extends ListObjectsCommandTestCase<ListPremiumListsCommand> {
class ListPremiumListsCommandTest extends ListObjectsCommandTestCase<ListPremiumListsCommand> {
@Override
final String getTaskPath() {

View file

@ -21,8 +21,7 @@ import google.registry.tools.server.ListRegistrarsAction;
*
* @see ListObjectsCommandTestCase
*/
public class ListRegistrarsCommandTest
extends ListObjectsCommandTestCase<ListRegistrarsCommand> {
class ListRegistrarsCommandTest extends ListObjectsCommandTestCase<ListRegistrarsCommand> {
@Override
final String getTaskPath() {

View file

@ -21,8 +21,7 @@ import google.registry.tools.server.ListReservedListsAction;
*
* @see ListObjectsCommandTestCase
*/
public class ListReservedListsCommandTest
extends ListObjectsCommandTestCase<ListReservedListsCommand> {
class ListReservedListsCommandTest extends ListObjectsCommandTestCase<ListReservedListsCommand> {
@Override
final String getTaskPath() {

View file

@ -21,7 +21,7 @@ import google.registry.tools.server.ListTldsAction;
*
* @see ListObjectsCommandTestCase
*/
public class ListTldsCommandTest extends ListObjectsCommandTestCase<ListTldsCommand> {
class ListTldsCommandTest extends ListObjectsCommandTestCase<ListTldsCommand> {
@Override
final String getTaskPath() {

View file

@ -17,50 +17,50 @@ package google.registry.tools;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.persistNewRegistrar;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.verifyNoInteractions;
import com.google.common.collect.ImmutableMap;
import com.google.common.net.MediaType;
import google.registry.model.registrar.Registrar;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
@RunWith(JUnit4.class)
public class LoadTestCommandTest extends CommandTestCase<LoadTestCommand> {
AppEngineConnection connection = mock(AppEngineConnection.class);
/** Unit tests for {@link LoadTestCommand}. */
class LoadTestCommandTest extends CommandTestCase<LoadTestCommand> {
@Before
public void setUp() {
@Mock private AppEngineConnection connection;
@BeforeEach
void beforeEach() {
command.setConnection(connection);
createTld("example");
persistNewRegistrar("acme", "ACME", Registrar.Type.REAL, 99L);
}
@Test
public void test_defaults() throws Exception {
void test_defaults() throws Exception {
runCommandForced();
ImmutableMap<String, Object> parms = new ImmutableMap.Builder<String, Object>()
.put("tld", "example")
.put("clientId", "acme")
.put("successfulHostCreates", 1)
.put("successfulDomainCreates", 1)
.put("successfulContactCreates", 1)
.put("hostInfos", 1)
.put("domainInfos", 1)
.put("contactInfos", 1)
.put("runSeconds", 4600)
.build();
ImmutableMap<String, Object> params =
new ImmutableMap.Builder<String, Object>()
.put("tld", "example")
.put("clientId", "acme")
.put("successfulHostCreates", 1)
.put("successfulDomainCreates", 1)
.put("successfulContactCreates", 1)
.put("hostInfos", 1)
.put("domainInfos", 1)
.put("contactInfos", 1)
.put("runSeconds", 4600)
.build();
verify(connection)
.sendPostRequest(
eq("/_dr/loadtest"), eq(parms), eq(MediaType.PLAIN_TEXT_UTF_8), eq(new byte[0]));
eq("/_dr/loadtest"), eq(params), eq(MediaType.PLAIN_TEXT_UTF_8), eq(new byte[0]));
}
@Test
public void test_overrides() throws Exception {
void test_overrides() throws Exception {
createTld("foo");
runCommandForced(
"--tld=foo",
@ -72,38 +72,39 @@ public class LoadTestCommandTest extends CommandTestCase<LoadTestCommand> {
"--domain_infos=14",
"--contact_infos=15",
"--run_seconds=16");
ImmutableMap<String, Object> parms = new ImmutableMap.Builder<String, Object>()
.put("tld", "foo")
.put("clientId", "NewRegistrar")
.put("successfulHostCreates", 10)
.put("successfulDomainCreates", 11)
.put("successfulContactCreates", 12)
.put("hostInfos", 13)
.put("domainInfos", 14)
.put("contactInfos", 15)
.put("runSeconds", 16)
.build();
ImmutableMap<String, Object> params =
new ImmutableMap.Builder<String, Object>()
.put("tld", "foo")
.put("clientId", "NewRegistrar")
.put("successfulHostCreates", 10)
.put("successfulDomainCreates", 11)
.put("successfulContactCreates", 12)
.put("hostInfos", 13)
.put("domainInfos", 14)
.put("contactInfos", 15)
.put("runSeconds", 16)
.build();
verify(connection)
.sendPostRequest(
eq("/_dr/loadtest"), eq(parms), eq(MediaType.PLAIN_TEXT_UTF_8), eq(new byte[0]));
eq("/_dr/loadtest"), eq(params), eq(MediaType.PLAIN_TEXT_UTF_8), eq(new byte[0]));
}
@Test
public void test_badTLD() throws Exception {
void test_badTLD() throws Exception {
runCommand("--tld=bogus");
verifyZeroInteractions(connection);
verifyNoInteractions(connection);
assertInStderr("No such TLD: bogus");
}
@Test
public void test_badClientId() throws Exception {
void test_badClientId() throws Exception {
runCommand("--client_id=badaddry");
verifyZeroInteractions(connection);
verifyNoInteractions(connection);
assertInStderr("No such client: badaddry");
}
@Test
public void test_noProduction() throws Exception {
void test_noProduction() throws Exception {
runCommandInEnvironment(RegistryToolEnvironment.PRODUCTION);
assertInStderr("You may not run a load test against production.");
}

View file

@ -37,14 +37,14 @@ import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import org.joda.time.Duration;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link LockDomainCommand}. */
public class LockDomainCommandTest extends CommandTestCase<LockDomainCommand> {
class LockDomainCommandTest extends CommandTestCase<LockDomainCommand> {
@Before
public void before() {
@BeforeEach
void beforeEach() {
persistNewRegistrar("adminreg", "Admin Registrar", Type.REAL, 693L);
createTld("tld");
command.registryAdminClientId = "adminreg";
@ -57,7 +57,7 @@ public class LockDomainCommandTest extends CommandTestCase<LockDomainCommand> {
}
@Test
public void testSuccess_locksDomain() throws Exception {
void testSuccess_locksDomain() throws Exception {
DomainBase domain = persistActiveDomain("example.tld");
runCommandForced("--client=TheRegistrar", "example.tld");
assertThat(reloadResource(domain).getStatusValues())
@ -65,7 +65,7 @@ public class LockDomainCommandTest extends CommandTestCase<LockDomainCommand> {
}
@Test
public void testSuccess_partiallyUpdatesStatuses() throws Exception {
void testSuccess_partiallyUpdatesStatuses() throws Exception {
DomainBase domain =
persistResource(
newDomainBase("example.tld")
@ -78,7 +78,7 @@ public class LockDomainCommandTest extends CommandTestCase<LockDomainCommand> {
}
@Test
public void testSuccess_manyDomains() throws Exception {
void testSuccess_manyDomains() throws Exception {
// Create 26 domains -- one more than the number of entity groups allowed in a transaction (in
// case that was going to be the failure point).
List<DomainBase> domains = new ArrayList<>();
@ -98,7 +98,7 @@ public class LockDomainCommandTest extends CommandTestCase<LockDomainCommand> {
}
@Test
public void testFailure_domainDoesntExist() {
void testFailure_domainDoesntExist() {
IllegalArgumentException e =
assertThrows(
IllegalArgumentException.class,
@ -107,7 +107,7 @@ public class LockDomainCommandTest extends CommandTestCase<LockDomainCommand> {
}
@Test
public void testSuccess_alreadyLockedDomain_performsNoAction() throws Exception {
void testSuccess_alreadyLockedDomain_performsNoAction() throws Exception {
DomainBase domain =
persistResource(
newDomainBase("example.tld")
@ -119,7 +119,7 @@ public class LockDomainCommandTest extends CommandTestCase<LockDomainCommand> {
}
@Test
public void testSuccess_defaultsToAdminRegistrar_ifUnspecified() throws Exception {
void testSuccess_defaultsToAdminRegistrar_ifUnspecified() throws Exception {
DomainBase domain = persistActiveDomain("example.tld");
runCommandForced("example.tld");
assertThat(getMostRecentRegistryLockByRepoId(domain.getRepoId()).get().getRegistrarId())
@ -127,7 +127,7 @@ public class LockDomainCommandTest extends CommandTestCase<LockDomainCommand> {
}
@Test
public void testFailure_duplicateDomainsAreSpecified() {
void testFailure_duplicateDomainsAreSpecified() {
IllegalArgumentException e =
assertThrows(
IllegalArgumentException.class,

View file

@ -29,30 +29,27 @@ import google.registry.model.registrar.Registrar;
import google.registry.testing.AppEngineRule;
import java.util.Arrays;
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 org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
/** Unit tests for {@link MutatingCommand}. */
@RunWith(JUnit4.class)
public class MutatingCommandTest {
@Rule
@RegisterExtension
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
Registrar registrar1;
Registrar registrar2;
Registrar newRegistrar1;
Registrar newRegistrar2;
HostResource host1;
HostResource host2;
HostResource newHost1;
HostResource newHost2;
private Registrar registrar1;
private Registrar registrar2;
private Registrar newRegistrar1;
private Registrar newRegistrar2;
private HostResource host1;
private HostResource host2;
private HostResource newHost1;
private HostResource newHost2;
@Before
public void init() {
@BeforeEach
void beforeEach() {
registrar1 = persistNewRegistrar("Registrar1", "Registrar1", Registrar.Type.REAL, 1L);
registrar2 = persistNewRegistrar("Registrar2", "Registrar2", Registrar.Type.REAL, 2L);
newRegistrar1 = registrar1.asBuilder().setBillingIdentifier(42L).build();
@ -68,7 +65,7 @@ public class MutatingCommandTest {
}
@Test
public void testSuccess_noChanges() throws Exception {
void testSuccess_noChanges() throws Exception {
MutatingCommand command = new MutatingCommand() {
@Override
protected void init() {}
@ -79,7 +76,7 @@ public class MutatingCommandTest {
}
@Test
public void testSuccess_update() throws Exception {
void testSuccess_update() throws Exception {
MutatingCommand command = new MutatingCommand() {
@Override
public void init() {
@ -112,7 +109,7 @@ public class MutatingCommandTest {
}
@Test
public void testSuccess_create() throws Exception {
void testSuccess_create() throws Exception {
ofy().deleteWithoutBackup().entities(Arrays.asList(host1, host2, registrar1, registrar2)).now();
MutatingCommand command = new MutatingCommand() {
@Override
@ -146,7 +143,7 @@ public class MutatingCommandTest {
}
@Test
public void testSuccess_delete() throws Exception {
void testSuccess_delete() throws Exception {
MutatingCommand command = new MutatingCommand() {
@Override
protected void init() {
@ -179,7 +176,7 @@ public class MutatingCommandTest {
}
@Test
public void testSuccess_noopUpdate() throws Exception {
void testSuccess_noopUpdate() throws Exception {
MutatingCommand command = new MutatingCommand() {
@Override
protected void init() {
@ -203,7 +200,7 @@ public class MutatingCommandTest {
}
@Test
public void testSuccess_batching() throws Exception {
void testSuccess_batching() throws Exception {
MutatingCommand command = new MutatingCommand() {
@Override
protected void init() {
@ -239,7 +236,7 @@ public class MutatingCommandTest {
}
@Test
public void testSuccess_batching_partialExecutionWorks() throws Exception {
void testSuccess_batching_partialExecutionWorks() throws Exception {
// The expected behavior here is that the first transaction will work and be committed, and
// the second transaction will throw an IllegalStateException and not commit.
MutatingCommand command = new MutatingCommand() {
@ -281,7 +278,7 @@ public class MutatingCommandTest {
}
@Test
public void testFailure_nullEntityChange() {
void testFailure_nullEntityChange() {
MutatingCommand command = new MutatingCommand() {
@Override
protected void init() {
@ -292,7 +289,7 @@ public class MutatingCommandTest {
}
@Test
public void testFailure_updateSameEntityTwice() {
void testFailure_updateSameEntityTwice() {
MutatingCommand command =
new MutatingCommand() {
@Override
@ -309,7 +306,7 @@ public class MutatingCommandTest {
}
@Test
public void testFailure_updateDifferentLongId() {
void testFailure_updateDifferentLongId() {
MutatingCommand command = new MutatingCommand() {
@Override
protected void init() {
@ -323,7 +320,7 @@ public class MutatingCommandTest {
}
@Test
public void testFailure_updateDifferentStringId() {
void testFailure_updateDifferentStringId() {
MutatingCommand command =
new MutatingCommand() {
@Override
@ -338,7 +335,7 @@ public class MutatingCommandTest {
}
@Test
public void testFailure_updateDifferentKind() {
void testFailure_updateDifferentKind() {
MutatingCommand command =
new MutatingCommand() {
@Override
@ -353,7 +350,7 @@ public class MutatingCommandTest {
}
@Test
public void testFailure_updateModifiedEntity() throws Exception {
void testFailure_updateModifiedEntity() throws Exception {
MutatingCommand command =
new MutatingCommand() {
@Override
@ -368,7 +365,7 @@ public class MutatingCommandTest {
}
@Test
public void testFailure_createExistingEntity() throws Exception {
void testFailure_createExistingEntity() throws Exception {
MutatingCommand command =
new MutatingCommand() {
@Override
@ -383,7 +380,7 @@ public class MutatingCommandTest {
}
@Test
public void testFailure_deleteChangedEntity() throws Exception {
void testFailure_deleteChangedEntity() throws Exception {
MutatingCommand command =
new MutatingCommand() {
@Override
@ -398,7 +395,7 @@ public class MutatingCommandTest {
}
@Test
public void testFailure_deleteRemovedEntity() throws Exception {
void testFailure_deleteRemovedEntity() throws Exception {
MutatingCommand command =
new MutatingCommand() {
@Override

View file

@ -21,7 +21,7 @@ import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import google.registry.tools.server.ToolsTestData;
import java.util.List;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link MutatingEppToolCommand}. */
public class MutatingEppToolCommandTest extends EppToolCommandTestCase<MutatingEppToolCommand> {
@ -50,7 +50,7 @@ public class MutatingEppToolCommandTest extends EppToolCommandTestCase<MutatingE
}
@Test
public void testSuccess_dryrun() throws Exception {
void testSuccess_dryrun() throws Exception {
// The choice of xml file is arbitrary.
runCommand(
"--client=NewRegistrar",
@ -60,7 +60,7 @@ public class MutatingEppToolCommandTest extends EppToolCommandTestCase<MutatingE
}
@Test
public void testFailure_cantUseForceWithDryRun() {
void testFailure_cantUseForceWithDryRun() {
Exception e =
assertThrows(
IllegalArgumentException.class,

View file

@ -21,7 +21,7 @@ import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import google.registry.tools.server.ToolsTestData;
import java.util.List;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link NonMutatingEppToolCommand}. */
public class NonMutatingEppToolCommandTest
@ -34,8 +34,7 @@ public class NonMutatingEppToolCommandTest
@Parameter(names = {"--client"})
String clientId;
@Parameter
List<String> xmlPayloads;
@Parameter List<String> xmlPayloads;
@Override
void initEppToolCommand() {
@ -51,14 +50,14 @@ public class NonMutatingEppToolCommandTest
}
@Test
public void testSuccess_doesntPrompt_whenNotForced() throws Exception {
void testSuccess_doesntPrompt_whenNotForced() throws Exception {
// The choice of xml file is arbitrary.
runCommand("--client=NewRegistrar", ToolsTestData.loadFile("domain_check.xml"));
eppVerifier.expectDryRun().verifySent("domain_check.xml");
}
@Test
public void testFailure_doesntAllowForce() {
void testFailure_doesntAllowForce() {
Exception e =
assertThrows(
IllegalArgumentException.class,

View file

@ -21,26 +21,23 @@ import google.registry.testing.AppEngineRule;
import google.registry.tools.EntityWrapper.Property;
import java.io.File;
import java.io.IOException;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.api.io.TempDir;
@RunWith(JUnit4.class)
/** Unit tests for {@link RecordAccumulator}. */
public class RecordAccumulatorTest {
private static final int BASE_ID = 1001;
@Rule public final TemporaryFolder tempFs = new TemporaryFolder();
@TempDir public File tmpDir;
@Rule
@RegisterExtension
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
@Test
public void testReadDirectory() throws IOException {
File subdir = tempFs.newFolder("folder");
LevelDbFileBuilder builder = new LevelDbFileBuilder(new File(subdir, "data1"));
void testReadDirectory() throws IOException {
LevelDbFileBuilder builder = new LevelDbFileBuilder(new File(tmpDir, "data1"));
// Note that we need to specify property values as "Long" for property comparisons to work
// correctly because that's how they are deserialized from protos.
@ -60,7 +57,7 @@ public class RecordAccumulatorTest {
builder.addEntity(e2.getEntity());
builder.build();
builder = new LevelDbFileBuilder(new File(subdir, "data2"));
builder = new LevelDbFileBuilder(new File(tmpDir, "data2"));
// Duplicate of the record in the other file.
builder.addEntity(
@ -81,7 +78,7 @@ public class RecordAccumulatorTest {
builder.build();
ImmutableSet<EntityWrapper> entities =
RecordAccumulator.readDirectory(subdir, any -> true).getEntityWrapperSet();
RecordAccumulator.readDirectory(tmpDir, any -> true).getEntityWrapperSet();
assertThat(entities).containsExactly(e1, e2, e3);
}
}

View file

@ -32,21 +32,21 @@ import google.registry.model.registrar.Registrar;
import google.registry.model.registrar.RegistrarContact;
import java.nio.file.Files;
import java.nio.file.Paths;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link RegistrarContactCommand}. */
public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContactCommand> {
class RegistrarContactCommandTest extends CommandTestCase<RegistrarContactCommand> {
private String output;
@Before
public void before() throws Exception {
output = tmpDir.newFile().toString();
@BeforeEach
void beforeEach() {
output = tmpDir.resolve("temp.dat").toString();
}
@Test
public void testList() throws Exception {
void testList() throws Exception {
Registrar registrar = loadRegistrar("NewRegistrar");
RegistrarContact.updateContacts(
registrar,
@ -72,7 +72,7 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
}
@Test
public void testUpdate() throws Exception {
void testUpdate() throws Exception {
Registrar registrar = loadRegistrar("NewRegistrar");
ImmutableList<RegistrarContact> contacts = ImmutableList.of(
new RegistrarContact.Builder()
@ -115,7 +115,7 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
}
@Test
public void testUpdate_enableConsoleAccess() throws Exception {
void testUpdate_enableConsoleAccess() throws Exception {
Registrar registrar = loadRegistrar("NewRegistrar");
persistSimpleResource(
new RegistrarContact.Builder()
@ -137,7 +137,7 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
}
@Test
public void testUpdate_disableConsoleAccess() throws Exception {
void testUpdate_disableConsoleAccess() throws Exception {
Registrar registrar = loadRegistrar("NewRegistrar");
persistSimpleResource(
new RegistrarContact.Builder()
@ -156,7 +156,7 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
}
@Test
public void testUpdate_unsetOtherWhoisAbuseFlags() throws Exception {
void testUpdate_unsetOtherWhoisAbuseFlags() throws Exception {
Registrar registrar = loadRegistrar("NewRegistrar");
persistSimpleResource(
new RegistrarContact.Builder()
@ -190,7 +190,7 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
}
@Test
public void testUpdate_cannotUnsetOnlyWhoisAbuseContact() {
void testUpdate_cannotUnsetOnlyWhoisAbuseContact() {
Registrar registrar = loadRegistrar("NewRegistrar");
persistSimpleResource(
new RegistrarContact.Builder()
@ -217,7 +217,7 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
}
@Test
public void testUpdate_emptyCommandModifiesNothing() throws Exception {
void testUpdate_emptyCommandModifiesNothing() throws Exception {
Registrar registrar = loadRegistrar("NewRegistrar");
RegistrarContact existingContact = persistSimpleResource(
new RegistrarContact.Builder()
@ -249,7 +249,7 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
}
@Test
public void testUpdate_listOfTypesWorks() throws Exception {
void testUpdate_listOfTypesWorks() throws Exception {
Registrar registrar = loadRegistrar("NewRegistrar");
persistSimpleResource(
new RegistrarContact.Builder()
@ -274,7 +274,7 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
}
@Test
public void testUpdate_clearAllTypes() throws Exception {
void testUpdate_clearAllTypes() throws Exception {
Registrar registrar = loadRegistrar("NewRegistrar");
persistSimpleResource(
new RegistrarContact.Builder()
@ -293,7 +293,7 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
}
@Test
public void testCreate_withAdminType() throws Exception {
void testCreate_withAdminType() throws Exception {
Registrar registrar = loadRegistrar("NewRegistrar");
runCommandForced(
"--mode=CREATE",
@ -322,7 +322,7 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
}
@Test
public void testDelete() throws Exception {
void testDelete() throws Exception {
assertThat(loadRegistrar("NewRegistrar").getContacts()).isNotEmpty();
runCommandForced(
"--mode=DELETE",
@ -332,7 +332,7 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
}
@Test
public void testDelete_failsOnDomainWhoisAbuseContact() {
void testDelete_failsOnDomainWhoisAbuseContact() {
RegistrarContact registrarContact = loadRegistrar("NewRegistrar").getContacts().asList().get(0);
persistSimpleResource(
registrarContact.asBuilder().setVisibleInDomainWhoisAsAbuse(true).build());
@ -347,7 +347,7 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
}
@Test
public void testCreate_withConsoleAccessEnabled() throws Exception {
void testCreate_withConsoleAccessEnabled() throws Exception {
runCommandForced(
"--mode=CREATE",
"--name=Jim Doe",
@ -360,7 +360,7 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
}
@Test
public void testCreate_withNoContactTypes() throws Exception {
void testCreate_withNoContactTypes() throws Exception {
runCommandForced(
"--mode=CREATE", "--name=Jim Doe", "--email=jim.doe@example.com", "NewRegistrar");
RegistrarContact registrarContact = loadRegistrar("NewRegistrar").getContacts().asList().get(1);
@ -368,7 +368,7 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
}
@Test
public void testCreate_syncingRequiredSetToTrue() throws Exception {
void testCreate_syncingRequiredSetToTrue() throws Exception {
persistResource(
loadRegistrar("NewRegistrar").asBuilder().setContactsRequireSyncing(false).build());
@ -379,7 +379,7 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
}
@Test
public void testCreate_setAllowedToSetRegistryLockPassword() throws Exception {
void testCreate_setAllowedToSetRegistryLockPassword() throws Exception {
runCommandForced(
"--mode=CREATE",
"--name=Jim Doe",
@ -393,7 +393,7 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
}
@Test
public void testUpdate_setAllowedToSetRegistryLockPassword() throws Exception {
void testUpdate_setAllowedToSetRegistryLockPassword() throws Exception {
Registrar registrar = loadRegistrar("NewRegistrar");
RegistrarContact registrarContact =
persistSimpleResource(
@ -436,7 +436,7 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
}
@Test
public void testUpdate_setAllowedToSetRegistryLockPassword_removesOldPassword() throws Exception {
void testUpdate_setAllowedToSetRegistryLockPassword_removesOldPassword() throws Exception {
Registrar registrar = loadRegistrar("NewRegistrar");
RegistrarContact registrarContact =
persistSimpleResource(
@ -460,7 +460,7 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
}
@Test
public void testCreate_failure_badEmail() {
void testCreate_failure_badEmail() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -473,7 +473,7 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
}
@Test
public void testCreate_failure_nullEmail() {
void testCreate_failure_nullEmail() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,

View file

@ -18,25 +18,22 @@ import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertThrows;
import google.registry.testing.SystemPropertyRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
/** Unit tests for {@link RegistryToolEnvironment}. */
@RunWith(JUnit4.class)
public class RegistryToolEnvironmentTest {
class RegistryToolEnvironmentTest {
@Rule public final SystemPropertyRule systemPropertyRule = new SystemPropertyRule();
@RegisterExtension final SystemPropertyRule systemPropertyRule = new SystemPropertyRule();
@Test
public void testGet_withoutSetup_throws() {
void testGet_withoutSetup_throws() {
RegistryToolEnvironment.reset();
assertThrows(IllegalStateException.class, RegistryToolEnvironment::get);
}
@Test
public void testSetup_changesEnvironmentReturnedByGet() {
void testSetup_changesEnvironmentReturnedByGet() {
RegistryToolEnvironment.UNITTEST.setup(systemPropertyRule);
assertThat(RegistryToolEnvironment.get()).isEqualTo(RegistryToolEnvironment.UNITTEST);
@ -45,33 +42,33 @@ public class RegistryToolEnvironmentTest {
}
@Test
public void testFromArgs_shortNotation_works() {
assertThat(RegistryToolEnvironment.parseFromArgs(new String[] { "-e", "alpha" }))
void testFromArgs_shortNotation_works() {
assertThat(RegistryToolEnvironment.parseFromArgs(new String[] {"-e", "alpha"}))
.isEqualTo(RegistryToolEnvironment.ALPHA);
}
@Test
public void testFromArgs_longNotation_works() {
assertThat(RegistryToolEnvironment.parseFromArgs(new String[] { "--environment", "alpha" }))
void testFromArgs_longNotation_works() {
assertThat(RegistryToolEnvironment.parseFromArgs(new String[] {"--environment", "alpha"}))
.isEqualTo(RegistryToolEnvironment.ALPHA);
}
@Test
public void testFromArgs_uppercase_works() {
assertThat(RegistryToolEnvironment.parseFromArgs(new String[] { "-e", "QA" }))
void testFromArgs_uppercase_works() {
assertThat(RegistryToolEnvironment.parseFromArgs(new String[] {"-e", "QA"}))
.isEqualTo(RegistryToolEnvironment.QA);
}
@Test
public void testFromArgs_equalsNotation_works() {
assertThat(RegistryToolEnvironment.parseFromArgs(new String[] { "-e=sandbox" }))
void testFromArgs_equalsNotation_works() {
assertThat(RegistryToolEnvironment.parseFromArgs(new String[] {"-e=sandbox"}))
.isEqualTo(RegistryToolEnvironment.SANDBOX);
assertThat(RegistryToolEnvironment.parseFromArgs(new String[] { "--environment=sandbox" }))
assertThat(RegistryToolEnvironment.parseFromArgs(new String[] {"--environment=sandbox"}))
.isEqualTo(RegistryToolEnvironment.SANDBOX);
}
@Test
public void testFromArgs_envFlagAfterCommandName_getsIgnored() {
void testFromArgs_envFlagAfterCommandName_getsIgnored() {
assertThrows(
IllegalArgumentException.class,
() ->
@ -80,34 +77,33 @@ public class RegistryToolEnvironmentTest {
}
@Test
public void testFromArgs_missingEnvironmentFlag_throwsIae() {
void testFromArgs_missingEnvironmentFlag_throwsIae() {
assertThrows(
IllegalArgumentException.class,
() -> RegistryToolEnvironment.parseFromArgs(new String[] {}));
}
@Test
public void testFromArgs_extraEnvFlagAfterCommandName_getsIgnored() {
String[] args = new String[] {
"-e", "alpha",
"registrar_activity_report",
"-e", "1406851199"};
void testFromArgs_extraEnvFlagAfterCommandName_getsIgnored() {
String[] args = new String[] {"-e", "alpha", "registrar_activity_report", "-e", "1406851199"};
assertThat(RegistryToolEnvironment.parseFromArgs(args))
.isEqualTo(RegistryToolEnvironment.ALPHA);
}
@Test
public void testFromArgs_loggingFlagWithUnderscores_isntConsideredCommand() {
String[] args = new String[] {
"--logging_properties_file", "my_file.properties",
"-e", "alpha",
"list_tlds"};
void testFromArgs_loggingFlagWithUnderscores_isntConsideredCommand() {
String[] args =
new String[] {
"--logging_properties_file", "my_file.properties",
"-e", "alpha",
"list_tlds"
};
assertThat(RegistryToolEnvironment.parseFromArgs(args))
.isEqualTo(RegistryToolEnvironment.ALPHA);
}
@Test
public void testFromArgs_badName_throwsIae() {
void testFromArgs_badName_throwsIae() {
assertThrows(
IllegalArgumentException.class,
() -> RegistryToolEnvironment.parseFromArgs(new String[] {"-e", "alphaville"}));

View file

@ -32,26 +32,26 @@ import google.registry.testing.InjectRule;
import google.registry.util.Clock;
import java.util.List;
import org.joda.time.DateTime;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.testcontainers.shaded.com.google.common.collect.ImmutableList;
/** Unit tests for {@link RenewDomainCommand}. */
public class RenewDomainCommandTest extends EppToolCommandTestCase<RenewDomainCommand> {
@Rule public final InjectRule inject = new InjectRule();
@RegisterExtension public final InjectRule inject = new InjectRule();
private final Clock clock = new FakeClock(DateTime.parse("2015-04-05T05:05:05Z"));
@Before
public void before() {
@BeforeEach
void beforeEach() {
inject.setStaticField(Ofy.class, "clock", clock);
command.clock = clock;
}
@Test
public void testSuccess() throws Exception {
void testSuccess() throws Exception {
persistResource(
persistActiveDomain(
"domain.tld",
@ -94,7 +94,7 @@ public class RenewDomainCommandTest extends EppToolCommandTestCase<RenewDomainCo
}
@Test
public void testSuccess_multipleDomains_renewsAndUsesEachDomainsRegistrar() throws Exception {
void testSuccess_multipleDomains_renewsAndUsesEachDomainsRegistrar() throws Exception {
persistThreeDomains();
runCommandForced("--period 3", "domain1.tld", "domain2.tld", "domain3.tld");
eppVerifier
@ -113,7 +113,7 @@ public class RenewDomainCommandTest extends EppToolCommandTestCase<RenewDomainCo
}
@Test
public void testSuccess_multipleDomains_renewsAndUsesSpecifiedRegistrar() throws Exception {
void testSuccess_multipleDomains_renewsAndUsesSpecifiedRegistrar() throws Exception {
persistThreeDomains();
persistNewRegistrar("reg3", "Registrar 3", Registrar.Type.REAL, 9783L);
runCommandForced("--period 3", "domain1.tld", "domain2.tld", "domain3.tld", "-u", "-c reg3");
@ -133,7 +133,7 @@ public class RenewDomainCommandTest extends EppToolCommandTestCase<RenewDomainCo
}
@Test
public void testFailure_domainDoesntExist() {
void testFailure_domainDoesntExist() {
IllegalArgumentException e =
assertThrows(IllegalArgumentException.class, () -> runCommandForced("nonexistent.tld"));
assertThat(e)
@ -142,7 +142,7 @@ public class RenewDomainCommandTest extends EppToolCommandTestCase<RenewDomainCo
}
@Test
public void testFailure_domainIsDeleted() {
void testFailure_domainIsDeleted() {
persistDeletedDomain("deleted.tld", DateTime.parse("2012-10-05T05:05:05Z"));
IllegalArgumentException e =
assertThrows(IllegalArgumentException.class, () -> runCommandForced("deleted.tld"));
@ -150,7 +150,7 @@ public class RenewDomainCommandTest extends EppToolCommandTestCase<RenewDomainCo
}
@Test
public void testFailure_duplicateDomainSpecified() {
void testFailure_duplicateDomainSpecified() {
IllegalArgumentException e =
assertThrows(
IllegalArgumentException.class, () -> runCommandForced("dupe.tld", "dupe.tld"));
@ -158,7 +158,7 @@ public class RenewDomainCommandTest extends EppToolCommandTestCase<RenewDomainCo
}
@Test
public void testFailure_cantRenewForTenYears() {
void testFailure_cantRenewForTenYears() {
persistActiveDomain(
"domain.tld",
DateTime.parse("2014-09-05T05:05:05Z"),
@ -170,7 +170,7 @@ public class RenewDomainCommandTest extends EppToolCommandTestCase<RenewDomainCo
}
@Test
public void testFailure_missingDomainNames() {
void testFailure_missingDomainNames() {
assertThrows(ParameterException.class, () -> runCommand("--period 4"));
}
}

View file

@ -17,8 +17,8 @@ package google.registry.tools;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.tools.RequestFactoryModule.REQUEST_TIMEOUT_MS;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
import com.google.api.client.http.GenericUrl;
@ -28,32 +28,29 @@ import com.google.api.client.http.HttpRequestInitializer;
import google.registry.config.RegistryConfig;
import google.registry.testing.SystemPropertyRule;
import google.registry.util.GoogleCredentialsBundle;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.mockito.junit.jupiter.MockitoExtension;
@RunWith(JUnit4.class)
/** Unit tests for {@link RequestFactoryModule}. */
@ExtendWith(MockitoExtension.class)
public class RequestFactoryModuleTest {
@Rule public final MockitoRule mockitoRule = MockitoJUnit.rule();
@Rule public final SystemPropertyRule systemPropertyRule = new SystemPropertyRule();
@RegisterExtension final SystemPropertyRule systemPropertyRule = new SystemPropertyRule();
@Mock public GoogleCredentialsBundle credentialsBundle;
@Mock public HttpRequestInitializer httpRequestInitializer;
@Before
public void setUp() {
@BeforeEach
void beforeEach() {
RegistryToolEnvironment.UNITTEST.setup(systemPropertyRule);
when(credentialsBundle.getHttpRequestInitializer()).thenReturn(httpRequestInitializer);
}
@Test
public void test_provideHttpRequestFactory_localhost() throws Exception {
void test_provideHttpRequestFactory_localhost() throws Exception {
// Make sure that localhost creates a request factory with an initializer.
boolean origIsLocal = RegistryConfig.CONFIG_SETTINGS.get().appEngine.isLocal;
RegistryConfig.CONFIG_SETTINGS.get().appEngine.isLocal = true;
@ -64,14 +61,15 @@ public class RequestFactoryModuleTest {
assertThat(initializer).isNotNull();
HttpRequest request = factory.buildGetRequest(new GenericUrl("http://localhost"));
initializer.initialize(request);
verifyZeroInteractions(httpRequestInitializer);
verifyNoInteractions(httpRequestInitializer);
} finally {
RegistryConfig.CONFIG_SETTINGS.get().appEngine.isLocal = origIsLocal;
}
}
@Test
public void test_provideHttpRequestFactory_remote() throws Exception {
void test_provideHttpRequestFactory_remote() throws Exception {
when(credentialsBundle.getHttpRequestInitializer()).thenReturn(httpRequestInitializer);
// Make sure that example.com creates a request factory with the UNITTEST client id but no
boolean origIsLocal = RegistryConfig.CONFIG_SETTINGS.get().appEngine.isLocal;
RegistryConfig.CONFIG_SETTINGS.get().appEngine.isLocal = false;

View file

@ -25,13 +25,13 @@ import google.registry.model.ImmutableObject;
import google.registry.model.contact.ContactResource;
import google.registry.model.ofy.CommitLogManifest;
import google.registry.model.ofy.CommitLogMutation;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link ResaveEntitiesCommand}. */
public class ResaveEntitiesCommandTest extends CommandTestCase<ResaveEntitiesCommand> {
class ResaveEntitiesCommandTest extends CommandTestCase<ResaveEntitiesCommand> {
@Test
public void testSuccess_createsCommitLogs() throws Exception {
void testSuccess_createsCommitLogs() throws Exception {
ContactResource contact1 = persistActiveContact("contact1");
ContactResource contact2 = persistActiveContact("contact2");
deleteEntitiesOfTypes(CommitLogManifest.class, CommitLogMutation.class);

View file

@ -28,14 +28,14 @@ import google.registry.model.ofy.CommitLogMutation;
import google.registry.model.registrar.Registrar;
import google.registry.model.registrar.RegistrarContact;
import google.registry.model.registry.Registry;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link ResaveEnvironmentEntitiesCommand}. */
public class ResaveEnvironmentEntitiesCommandTest
class ResaveEnvironmentEntitiesCommandTest
extends CommandTestCase<ResaveEnvironmentEntitiesCommand> {
@Test
public void testSuccess_noop() throws Exception {
void testSuccess_noop() throws Exception {
// Get rid of all the entities that this command runs on so that it does nothing.
deleteEntitiesOfTypes(
Registry.class,
@ -49,7 +49,7 @@ public class ResaveEnvironmentEntitiesCommandTest
}
@Test
public void testSuccess_createsCommitLogs() throws Exception {
void testSuccess_createsCommitLogs() throws Exception {
createTld("tld");
deleteEntitiesOfTypes(CommitLogManifest.class, CommitLogMutation.class);
assertThat(ofy().load().type(CommitLogManifest.class).keys()).isEmpty();

View file

@ -22,13 +22,13 @@ import google.registry.model.ImmutableObject;
import google.registry.model.contact.ContactResource;
import google.registry.model.ofy.CommitLogManifest;
import google.registry.model.ofy.CommitLogMutation;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link ResaveEppResourceCommand}. */
public class ResaveEppResourcesCommandTest extends CommandTestCase<ResaveEppResourceCommand> {
class ResaveEppResourcesCommandTest extends CommandTestCase<ResaveEppResourceCommand> {
@Test
public void testSuccess_createsCommitLogs() throws Exception {
void testSuccess_createsCommitLogs() throws Exception {
ContactResource contact = persistActiveContact("contact");
deleteEntitiesOfTypes(CommitLogManifest.class, CommitLogMutation.class);
assertThat(ofy().load().type(CommitLogManifest.class).keys()).isEmpty();

View file

@ -24,29 +24,31 @@ import com.google.common.collect.ImmutableMultimap;
import google.registry.testing.AppEngineAdminApiHelper;
import google.registry.testing.InjectRule;
import google.registry.util.AppEngineServiceUtils;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
/** Unit tests for {@link SetNumInstancesCommand}. */
public class SetNumInstancesCommandTest extends CommandTestCase<SetNumInstancesCommand> {
@Rule public final InjectRule inject = new InjectRule();
@RegisterExtension public final InjectRule inject = new InjectRule();
@Mock AppEngineServiceUtils appEngineServiceUtils;
private final String projectId = "domain-registry-test";
@Before
public void before() {
@BeforeEach
void beforeEach() {
command = new SetNumInstancesCommand();
command.appEngineServiceUtils = appEngineServiceUtils;
command.projectId = projectId;
}
@Test
public void test_missingService_throwsException() {
void test_missingService_throwsException() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -55,7 +57,7 @@ public class SetNumInstancesCommandTest extends CommandTestCase<SetNumInstancesC
}
@Test
public void test_emptyService_throwsException() {
void test_emptyService_throwsException() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -64,7 +66,7 @@ public class SetNumInstancesCommandTest extends CommandTestCase<SetNumInstancesC
}
@Test
public void test_invalidService_throwsException() {
void test_invalidService_throwsException() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -75,7 +77,7 @@ public class SetNumInstancesCommandTest extends CommandTestCase<SetNumInstancesC
}
@Test
public void test_missingVersion_throwsException() {
void test_missingVersion_throwsException() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -84,7 +86,7 @@ public class SetNumInstancesCommandTest extends CommandTestCase<SetNumInstancesC
}
@Test
public void test_emptyVersion_throwsException() {
void test_emptyVersion_throwsException() {
ParameterException thrown =
assertThrows(
ParameterException.class,
@ -93,7 +95,7 @@ public class SetNumInstancesCommandTest extends CommandTestCase<SetNumInstancesC
}
@Test
public void test_missingNumInstances_throwsException() {
void test_missingNumInstances_throwsException() {
ParameterException thrown =
assertThrows(
ParameterException.class, () -> runCommand("--services=DEFAULT", "--versions=version"));
@ -103,7 +105,7 @@ public class SetNumInstancesCommandTest extends CommandTestCase<SetNumInstancesC
}
@Test
public void test_invalidNumInstances_throwsException() {
void test_invalidNumInstances_throwsException() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -112,7 +114,7 @@ public class SetNumInstancesCommandTest extends CommandTestCase<SetNumInstancesC
}
@Test
public void test_versionNotNullWhenSettingAllNonLiveVersions_throwsException() {
void test_versionNotNullWhenSettingAllNonLiveVersions_throwsException() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -120,8 +122,9 @@ public class SetNumInstancesCommandTest extends CommandTestCase<SetNumInstancesC
assertThat(thrown).hasMessageThat().contains("Number of instances must be greater than zero");
}
@MockitoSettings(strictness = Strictness.LENIENT)
@Test
public void test_settingNonManualScalingVersions_throwsException() {
void test_settingNonManualScalingVersions_throwsException() {
command.appengine =
new AppEngineAdminApiHelper.Builder()
.setAppId(projectId)
@ -143,8 +146,9 @@ public class SetNumInstancesCommandTest extends CommandTestCase<SetNumInstancesC
.contains("--versions cannot be set if --non_live_versions is set");
}
@MockitoSettings(strictness = Strictness.LENIENT)
@Test
public void test_validParameters_succeeds() throws Exception {
void test_validParameters_succeeds() throws Exception {
command.appengine =
new AppEngineAdminApiHelper.Builder()
.setAppId(projectId)
@ -156,8 +160,9 @@ public class SetNumInstancesCommandTest extends CommandTestCase<SetNumInstancesC
verify(appEngineServiceUtils, times(1)).setNumInstances("default", "version", 10L);
}
@MockitoSettings(strictness = Strictness.LENIENT)
@Test
public void test_validShortParametersAndLowercaseService_succeeds() throws Exception {
void test_validShortParametersAndLowercaseService_succeeds() throws Exception {
command.appengine =
new AppEngineAdminApiHelper.Builder()
.setAppId(projectId)
@ -169,8 +174,9 @@ public class SetNumInstancesCommandTest extends CommandTestCase<SetNumInstancesC
verify(appEngineServiceUtils, times(1)).setNumInstances("default", "version", 10L);
}
@MockitoSettings(strictness = Strictness.LENIENT)
@Test
public void test_settingMultipleServicesAndVersions_succeeds() throws Exception {
void test_settingMultipleServicesAndVersions_succeeds() throws Exception {
command.appengine =
new AppEngineAdminApiHelper.Builder()
.setAppId(projectId)
@ -191,7 +197,7 @@ public class SetNumInstancesCommandTest extends CommandTestCase<SetNumInstancesC
}
@Test
public void test_settingAllNonLiveVersions_succeeds() throws Exception {
void test_settingAllNonLiveVersions_succeeds() throws Exception {
command.appengine =
new AppEngineAdminApiHelper.Builder()
.setAppId(projectId)
@ -209,7 +215,7 @@ public class SetNumInstancesCommandTest extends CommandTestCase<SetNumInstancesC
}
@Test
public void test_noNonLiveVersions_succeeds() throws Exception {
void test_noNonLiveVersions_succeeds() throws Exception {
command.appengine =
new AppEngineAdminApiHelper.Builder()
.setAppId(projectId)

View file

@ -43,19 +43,19 @@ import org.joda.money.CurrencyUnit;
import org.joda.money.Money;
import org.joda.time.DateTime;
import org.joda.time.Duration;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link SetupOteCommand}. */
public class SetupOteCommandTest extends CommandTestCase<SetupOteCommand> {
class SetupOteCommandTest extends CommandTestCase<SetupOteCommand> {
static final String PASSWORD = "abcdefghijklmnop";
private static final String PASSWORD = "abcdefghijklmnop";
DeterministicStringGenerator passwordGenerator =
private DeterministicStringGenerator passwordGenerator =
new DeterministicStringGenerator("abcdefghijklmnopqrstuvwxyz");
@Before
public void init() {
@BeforeEach
void beforeEach() {
command.passwordGenerator = passwordGenerator;
command.clock = new FakeClock(DateTime.parse("2018-07-07TZ"));
persistPremiumList("default_sandbox_list", "sandbox,USD 1000");
@ -133,7 +133,7 @@ public class SetupOteCommandTest extends CommandTestCase<SetupOteCommand> {
}
@Test
public void testSuccess() throws Exception {
void testSuccess() throws Exception {
runCommandForced(
"--ip_allow_list=1.1.1.1",
"--registrar=blobio",
@ -159,7 +159,7 @@ public class SetupOteCommandTest extends CommandTestCase<SetupOteCommand> {
}
@Test
public void testSuccess_shortRegistrarName() throws Exception {
void testSuccess_shortRegistrarName() throws Exception {
runCommandForced(
"--ip_allow_list=1.1.1.1",
"--registrar=abc",
@ -185,7 +185,7 @@ public class SetupOteCommandTest extends CommandTestCase<SetupOteCommand> {
}
@Test
public void testSuccess_certificateHash() throws Exception {
void testSuccess_certificateHash() throws Exception {
runCommandForced(
"--ip_allow_list=1.1.1.1",
"--registrar=blobio",
@ -203,7 +203,7 @@ public class SetupOteCommandTest extends CommandTestCase<SetupOteCommand> {
}
@Test
public void testSuccess_multipleIps() throws Exception {
void testSuccess_multipleIps() throws Exception {
runCommandForced(
"--ip_allow_list=1.1.1.1,2.2.2.2",
"--registrar=blobio",
@ -230,7 +230,7 @@ public class SetupOteCommandTest extends CommandTestCase<SetupOteCommand> {
}
@Test
public void testFailure_missingIpAllowList() {
void testFailure_missingIpAllowList() {
ParameterException thrown =
assertThrows(
ParameterException.class,
@ -243,7 +243,7 @@ public class SetupOteCommandTest extends CommandTestCase<SetupOteCommand> {
}
@Test
public void testFailure_missingRegistrar() {
void testFailure_missingRegistrar() {
ParameterException thrown =
assertThrows(
ParameterException.class,
@ -256,7 +256,7 @@ public class SetupOteCommandTest extends CommandTestCase<SetupOteCommand> {
}
@Test
public void testFailure_missingCertificateFileAndCertificateHash() {
void testFailure_missingCertificateFileAndCertificateHash() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -270,7 +270,7 @@ public class SetupOteCommandTest extends CommandTestCase<SetupOteCommand> {
}
@Test
public void testFailure_suppliedCertificateFileAndCertificateHash() {
void testFailure_suppliedCertificateFileAndCertificateHash() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -288,7 +288,7 @@ public class SetupOteCommandTest extends CommandTestCase<SetupOteCommand> {
}
@Test
public void testFailure_missingEmail() {
void testFailure_missingEmail() {
ParameterException thrown =
assertThrows(
ParameterException.class,
@ -301,7 +301,7 @@ public class SetupOteCommandTest extends CommandTestCase<SetupOteCommand> {
}
@Test
public void testFailure_invalidCert() {
void testFailure_invalidCert() {
CertificateParsingException thrown =
assertThrows(
CertificateParsingException.class,
@ -315,7 +315,7 @@ public class SetupOteCommandTest extends CommandTestCase<SetupOteCommand> {
}
@Test
public void testFailure_invalidRegistrar() {
void testFailure_invalidRegistrar() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -329,7 +329,7 @@ public class SetupOteCommandTest extends CommandTestCase<SetupOteCommand> {
}
@Test
public void testFailure_registrarTooShort() {
void testFailure_registrarTooShort() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -343,7 +343,7 @@ public class SetupOteCommandTest extends CommandTestCase<SetupOteCommand> {
}
@Test
public void testFailure_registrarTooLong() {
void testFailure_registrarTooLong() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -357,7 +357,7 @@ public class SetupOteCommandTest extends CommandTestCase<SetupOteCommand> {
}
@Test
public void testFailure_registrarInvalidCharacter() {
void testFailure_registrarInvalidCharacter() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -371,7 +371,7 @@ public class SetupOteCommandTest extends CommandTestCase<SetupOteCommand> {
}
@Test
public void testFailure_tldExists() {
void testFailure_tldExists() {
createTld("blobio-sunrise");
IllegalStateException thrown =
assertThrows(
@ -386,7 +386,7 @@ public class SetupOteCommandTest extends CommandTestCase<SetupOteCommand> {
}
@Test
public void testSuccess_tldExists_replaceExisting() throws Exception {
void testSuccess_tldExists_replaceExisting() throws Exception {
createTld("blobio-sunrise");
runCommandForced(
@ -401,7 +401,7 @@ public class SetupOteCommandTest extends CommandTestCase<SetupOteCommand> {
}
@Test
public void testFailure_registrarExists() {
void testFailure_registrarExists() {
Registrar registrar = loadRegistrar("TheRegistrar").asBuilder()
.setClientId("blobio-1")
.setRegistrarName("blobio-1")
@ -420,7 +420,7 @@ public class SetupOteCommandTest extends CommandTestCase<SetupOteCommand> {
}
@Test
public void testSuccess_registrarExists_replaceExisting() throws Exception {
void testSuccess_registrarExists_replaceExisting() throws Exception {
Registrar registrar = loadRegistrar("TheRegistrar").asBuilder()
.setClientId("blobio-1")
.setRegistrarName("blobio-1")

View file

@ -39,43 +39,39 @@ import java.util.ArrayList;
import java.util.List;
import org.joda.time.DateTime;
import org.joda.time.Duration;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
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;
@RunWith(JUnit4.class)
public class ShellCommandTest {
/** Unit tests for {@link ShellCommand}. */
class ShellCommandTest {
@Rule public final SystemPropertyRule systemPropertyRule = new SystemPropertyRule();
@RegisterExtension final SystemPropertyRule systemPropertyRule = new SystemPropertyRule();
CommandRunner cli = mock(CommandRunner.class);
FakeClock clock = new FakeClock(DateTime.parse("2000-01-01TZ"));
private FakeClock clock = new FakeClock(DateTime.parse("2000-01-01TZ"));
PrintStream orgStdout;
PrintStream orgStderr;
private PrintStream orgStdout;
private PrintStream orgStderr;
ByteArrayOutputStream stdout;
ByteArrayOutputStream stderr;
private ByteArrayOutputStream stdout;
private ByteArrayOutputStream stderr;
public ShellCommandTest() {}
@Before
public void setUp() {
@BeforeEach
void beforeEach() {
orgStdout = System.out;
orgStderr = System.err;
}
@After
public void tearDown() {
@AfterEach
void afterEach() {
System.setOut(orgStdout);
System.setErr(orgStderr);
}
@Test
public void testParsing() {
void testParsing() {
assertThat(ShellCommand.parseCommand("foo bar 123 baz+ // comment \"string data\""))
.isEqualTo(new String[] {"foo", "bar", "123", "baz+", "//", "comment", "string data"});
assertThat(ShellCommand.parseCommand("\"got \\\" escapes?\""))
@ -87,18 +83,20 @@ public class ShellCommandTest {
CommandRunner commandRunner, Duration delay, String... commands) throws Exception {
ArrayDeque<String> queue = new ArrayDeque<String>(ImmutableList.copyOf(commands));
BufferedReader bufferedReader = mock(BufferedReader.class);
when(bufferedReader.readLine()).thenAnswer((x) -> {
clock.advanceBy(delay);
if (queue.isEmpty()) {
throw new IOException();
}
return queue.poll();
});
when(bufferedReader.readLine())
.thenAnswer(
(x) -> {
clock.advanceBy(delay);
if (queue.isEmpty()) {
throw new IOException();
}
return queue.poll();
});
return new ShellCommand(bufferedReader, clock, commandRunner);
}
@Test
public void testCommandProcessing() throws Exception {
void testCommandProcessing() throws Exception {
MockCli cli = new MockCli();
ShellCommand shellCommand =
createShellCommand(cli, Duration.ZERO, "test1 foo bar", "test2 foo bar");
@ -110,7 +108,7 @@ public class ShellCommandTest {
}
@Test
public void testNoIdleWhenInAlpha() throws Exception {
void testNoIdleWhenInAlpha() throws Exception {
RegistryToolEnvironment.ALPHA.setup(systemPropertyRule);
MockCli cli = new MockCli();
ShellCommand shellCommand =
@ -119,7 +117,7 @@ public class ShellCommandTest {
}
@Test
public void testNoIdleWhenInSandbox() throws Exception {
void testNoIdleWhenInSandbox() throws Exception {
RegistryToolEnvironment.SANDBOX.setup(systemPropertyRule);
MockCli cli = new MockCli();
ShellCommand shellCommand =
@ -128,7 +126,7 @@ public class ShellCommandTest {
}
@Test
public void testIdleWhenOverHourInProduction() throws Exception {
void testIdleWhenOverHourInProduction() throws Exception {
RegistryToolEnvironment.PRODUCTION.setup(systemPropertyRule);
MockCli cli = new MockCli();
ShellCommand shellCommand =
@ -138,7 +136,7 @@ public class ShellCommandTest {
}
@Test
public void testNoIdleWhenUnderHourInProduction() throws Exception {
void testNoIdleWhenUnderHourInProduction() throws Exception {
RegistryToolEnvironment.PRODUCTION.setup(systemPropertyRule);
MockCli cli = new MockCli();
ShellCommand shellCommand =
@ -156,7 +154,7 @@ public class ShellCommandTest {
}
@Test
public void testMultipleCommandInvocations() throws Exception {
void testMultipleCommandInvocations() throws Exception {
try (RegistryCli cli =
new RegistryCli("unittest", ImmutableMap.of("test_command", TestCommand.class))) {
RegistryToolEnvironment.UNITTEST.setup(systemPropertyRule);
@ -173,7 +171,7 @@ public class ShellCommandTest {
}
@Test
public void testNonExistentCommand() {
void testNonExistentCommand() {
try (RegistryCli cli =
new RegistryCli("unittest", ImmutableMap.of("test_command", TestCommand.class))) {
@ -183,9 +181,7 @@ public class ShellCommandTest {
}
private void performJCommanderCompletorTest(
String line,
int expectedBackMotion,
String... expectedCompletions) {
String line, int expectedBackMotion, String... expectedCompletions) {
JCommander jcommander = new JCommander();
jcommander.setProgramName("test");
jcommander.addCommand("help", new HelpCommand(jcommander));
@ -201,7 +197,7 @@ public class ShellCommandTest {
}
@Test
public void testCompletion_commands() {
void testCompletion_commands() {
performJCommanderCompletorTest("", 0, "testCommand ", "testAnotherCommand ", "help ");
performJCommanderCompletorTest("n", 1);
performJCommanderCompletorTest("test", 4, "testCommand ", "testAnotherCommand ");
@ -211,7 +207,7 @@ public class ShellCommandTest {
}
@Test
public void testCompletion_help() {
void testCompletion_help() {
performJCommanderCompletorTest("h", 1, "help ");
performJCommanderCompletorTest("help ", 0, "testCommand ", "testAnotherCommand ", "help ");
performJCommanderCompletorTest("help testC", 5, "testCommand ");
@ -219,7 +215,7 @@ public class ShellCommandTest {
}
@Test
public void testCompletion_documentation() {
void testCompletion_documentation() {
performJCommanderCompletorTest(
"testCommand ",
0,
@ -239,7 +235,7 @@ public class ShellCommandTest {
}
@Test
public void testCompletion_arguments() {
void testCompletion_arguments() {
performJCommanderCompletorTest("testCommand -", 1, "-x ", "--xparam ", "--xorg ");
performJCommanderCompletorTest("testCommand --wrong", 7);
performJCommanderCompletorTest("testCommand noise --", 2, "--xparam ", "--xorg ");
@ -247,7 +243,7 @@ public class ShellCommandTest {
}
@Test
public void testCompletion_enum() {
void testCompletion_enum() {
performJCommanderCompletorTest("testCommand --xorg P", 1, "PRIVATE ", "PUBLIC ");
performJCommanderCompletorTest("testCommand --xorg PU", 2, "PUBLIC ");
performJCommanderCompletorTest(
@ -255,7 +251,7 @@ public class ShellCommandTest {
}
@Test
public void testEncapsulatedOutputStream_basicFuncionality() {
void testEncapsulatedOutputStream_basicFuncionality() {
ByteArrayOutputStream backing = new ByteArrayOutputStream();
try (PrintStream out =
new PrintStream(new ShellCommand.EncapsulatingOutputStream(backing, "out: "))) {
@ -267,7 +263,7 @@ public class ShellCommandTest {
}
@Test
public void testEncapsulatedOutputStream_emptyStream() {
void testEncapsulatedOutputStream_emptyStream() {
ByteArrayOutputStream backing = new ByteArrayOutputStream();
try (PrintStream out =
new PrintStream(new ShellCommand.EncapsulatingOutputStream(backing, "out: "))) {}
@ -275,7 +271,7 @@ public class ShellCommandTest {
}
@Test
public void testEncapsulatedOutput_command() throws Exception {
void testEncapsulatedOutput_command() throws Exception {
RegistryToolEnvironment.ALPHA.setup(systemPropertyRule);
captureOutput();
ShellCommand shellCommand =
@ -299,7 +295,7 @@ public class ShellCommandTest {
}
@Test
public void testEncapsulatedOutput_throws() throws Exception {
void testEncapsulatedOutput_throws() throws Exception {
RegistryToolEnvironment.ALPHA.setup(systemPropertyRule);
captureOutput();
ShellCommand shellCommand =
@ -319,7 +315,7 @@ public class ShellCommandTest {
}
@Test
public void testEncapsulatedOutput_noCommand() throws Exception {
void testEncapsulatedOutput_noCommand() throws Exception {
captureOutput();
ShellCommand shellCommand =
createShellCommand(
@ -353,15 +349,13 @@ public class ShellCommandTest {
}
@Parameter(
names = {"-x", "--xparam"},
description = "test parameter"
)
names = {"-x", "--xparam"},
description = "test parameter")
String xparam = "default value";
@Parameter(
names = {"--xorg"},
description = "test organization"
)
names = {"--xorg"},
description = "test organization")
OrgType orgType = OrgType.PRIVATE;
// List for recording command invocations by run().
@ -373,7 +367,7 @@ public class ShellCommandTest {
@Parameter(description = "normal argument")
List<String> args;
public TestCommand() {}
TestCommand() {}
@Override
public void run() {

View file

@ -29,20 +29,20 @@ import google.registry.model.eppcommon.StatusValue;
import google.registry.model.host.HostResource;
import google.registry.persistence.VKey;
import javax.xml.bind.annotation.adapters.HexBinaryAdapter;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link UniformRapidSuspensionCommand}. */
public class UniformRapidSuspensionCommandTest
class UniformRapidSuspensionCommandTest
extends EppToolCommandTestCase<UniformRapidSuspensionCommand> {
HostResource ns1;
HostResource ns2;
HostResource urs1;
HostResource urs2;
private HostResource ns1;
private HostResource ns2;
private HostResource urs1;
private HostResource urs2;
@Before
public void initResources() {
@BeforeEach
void beforeEach() {
// Since the command's history client ID must be CharlestonRoad, resave TheRegistrar that way.
persistResource(
loadRegistrar("TheRegistrar").asBuilder().setClientId("CharlestonRoad").build());
@ -66,7 +66,7 @@ public class UniformRapidSuspensionCommandTest
}
@Test
public void testCommand_addsLocksReplacesHostsAndDsDataPrintsUndo() throws Exception {
void testCommand_addsLocksReplacesHostsAndDsDataPrintsUndo() throws Exception {
persistDomainWithHosts(ns1, ns2);
runCommandForced(
"--domain_name=evil.tld",
@ -86,7 +86,7 @@ public class UniformRapidSuspensionCommandTest
}
@Test
public void testCommand_respectsExistingHost() throws Exception {
void testCommand_respectsExistingHost() throws Exception {
persistDomainWithHosts(urs2, ns1);
runCommandForced("--domain_name=evil.tld", "--hosts=urs1.example.com,urs2.example.com");
eppVerifier
@ -100,7 +100,7 @@ public class UniformRapidSuspensionCommandTest
}
@Test
public void testCommand_generatesUndoForUndelegatedDomain() throws Exception {
void testCommand_generatesUndoForUndelegatedDomain() throws Exception {
persistActiveDomain("evil.tld");
runCommandForced("--domain_name=evil.tld", "--hosts=urs1.example.com,urs2.example.com");
eppVerifier.verifySentAny();
@ -110,7 +110,7 @@ public class UniformRapidSuspensionCommandTest
}
@Test
public void testCommand_generatesUndoWithLocksToPreserve() throws Exception {
void testCommand_generatesUndoWithLocksToPreserve() throws Exception {
persistResource(
newDomainBase("evil.tld").asBuilder()
.addStatusValue(StatusValue.SERVER_DELETE_PROHIBITED)
@ -123,7 +123,7 @@ public class UniformRapidSuspensionCommandTest
}
@Test
public void testUndo_removesLocksReplacesHostsAndDsData() throws Exception {
void testUndo_removesLocksReplacesHostsAndDsData() throws Exception {
persistDomainWithHosts(urs1, urs2);
runCommandForced(
"--domain_name=evil.tld", "--undo", "--hosts=ns1.example.com,ns2.example.com");
@ -135,7 +135,7 @@ public class UniformRapidSuspensionCommandTest
}
@Test
public void testUndo_respectsLocksToPreserveFlag() throws Exception {
void testUndo_respectsLocksToPreserveFlag() throws Exception {
persistDomainWithHosts(urs1, urs2);
runCommandForced(
"--domain_name=evil.tld",
@ -150,7 +150,7 @@ public class UniformRapidSuspensionCommandTest
}
@Test
public void testFailure_locksToPreserveWithoutUndo() {
void testFailure_locksToPreserveWithoutUndo() {
persistActiveDomain("evil.tld");
IllegalArgumentException thrown =
assertThrows(
@ -162,7 +162,7 @@ public class UniformRapidSuspensionCommandTest
}
@Test
public void testFailure_domainNameRequired() {
void testFailure_domainNameRequired() {
persistActiveDomain("evil.tld");
ParameterException thrown =
assertThrows(
@ -172,7 +172,7 @@ public class UniformRapidSuspensionCommandTest
}
@Test
public void testFailure_extraFieldInDsData() {
void testFailure_extraFieldInDsData() {
persistActiveDomain("evil.tld");
IllegalArgumentException thrown =
assertThrows(
@ -185,7 +185,7 @@ public class UniformRapidSuspensionCommandTest
}
@Test
public void testFailure_missingFieldInDsData() {
void testFailure_missingFieldInDsData() {
persistActiveDomain("evil.tld");
IllegalArgumentException thrown =
assertThrows(
@ -198,7 +198,7 @@ public class UniformRapidSuspensionCommandTest
}
@Test
public void testFailure_malformedDsData() {
void testFailure_malformedDsData() {
persistActiveDomain("evil.tld");
IllegalArgumentException thrown =
assertThrows(

View file

@ -40,14 +40,14 @@ import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import org.joda.time.Duration;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link UnlockDomainCommand}. */
public class UnlockDomainCommandTest extends CommandTestCase<UnlockDomainCommand> {
class UnlockDomainCommandTest extends CommandTestCase<UnlockDomainCommand> {
@Before
public void before() {
@BeforeEach
void beforeEach() {
persistNewRegistrar("adminreg", "Admin Registrar", Type.REAL, 693L);
createTld("tld");
command.registryAdminClientId = "adminreg";
@ -68,14 +68,14 @@ public class UnlockDomainCommandTest extends CommandTestCase<UnlockDomainCommand
}
@Test
public void testSuccess_unlocksDomain() throws Exception {
void testSuccess_unlocksDomain() throws Exception {
DomainBase domain = persistLockedDomain("example.tld", "TheRegistrar");
runCommandForced("--client=TheRegistrar", "example.tld");
assertThat(reloadResource(domain).getStatusValues()).containsNoneIn(REGISTRY_LOCK_STATUSES);
}
@Test
public void testSuccess_partiallyUpdatesStatuses() throws Exception {
void testSuccess_partiallyUpdatesStatuses() throws Exception {
DomainBase domain = persistLockedDomain("example.tld", "TheRegistrar");
domain =
persistResource(
@ -89,7 +89,7 @@ public class UnlockDomainCommandTest extends CommandTestCase<UnlockDomainCommand
}
@Test
public void testSuccess_manyDomains() throws Exception {
void testSuccess_manyDomains() throws Exception {
// Create 26 domains -- one more than the number of entity groups allowed in a transaction (in
// case that was going to be the failure point).
List<DomainBase> domains = new ArrayList<>();
@ -108,7 +108,7 @@ public class UnlockDomainCommandTest extends CommandTestCase<UnlockDomainCommand
}
@Test
public void testFailure_domainDoesntExist() {
void testFailure_domainDoesntExist() {
IllegalArgumentException e =
assertThrows(
IllegalArgumentException.class,
@ -117,14 +117,14 @@ public class UnlockDomainCommandTest extends CommandTestCase<UnlockDomainCommand
}
@Test
public void testSuccess_alreadyUnlockedDomain_performsNoAction() throws Exception {
void testSuccess_alreadyUnlockedDomain_performsNoAction() throws Exception {
DomainBase domain = persistActiveDomain("example.tld");
runCommandForced("--client=TheRegistrar", "example.tld");
assertThat(reloadResource(domain)).isEqualTo(domain);
}
@Test
public void testSuccess_defaultsToAdminRegistrar_ifUnspecified() throws Exception {
void testSuccess_defaultsToAdminRegistrar_ifUnspecified() throws Exception {
DomainBase domain = persistLockedDomain("example.tld", "TheRegistrar");
runCommandForced("example.tld");
assertThat(getMostRecentRegistryLockByRepoId(domain.getRepoId()).get().getRegistrarId())
@ -132,7 +132,7 @@ public class UnlockDomainCommandTest extends CommandTestCase<UnlockDomainCommand
}
@Test
public void testFailure_duplicateDomainsAreSpecified() {
void testFailure_duplicateDomainsAreSpecified() {
IllegalArgumentException e =
assertThrows(
IllegalArgumentException.class,

View file

@ -47,26 +47,26 @@ import google.registry.model.reporting.HistoryEntry;
import google.registry.testing.FakeClock;
import google.registry.testing.InjectRule;
import org.joda.time.DateTime;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
/** Unit tests for {@link UnrenewDomainCommand}. */
public class UnrenewDomainCommandTest extends CommandTestCase<UnrenewDomainCommand> {
@Rule public final InjectRule inject = new InjectRule();
@RegisterExtension public final InjectRule inject = new InjectRule();
private final FakeClock clock = new FakeClock(DateTime.parse("2016-12-06T13:55:01Z"));
@Before
public void before() {
@BeforeEach
void beforeEach() {
createTld("tld");
inject.setStaticField(Ofy.class, "clock", clock);
command.clock = clock;
}
@Test
public void test_unrenewTwoDomains_worksSuccessfully() throws Exception {
void test_unrenewTwoDomains_worksSuccessfully() throws Exception {
ContactResource contact = persistActiveContact("jd1234");
clock.advanceOneMilli();
persistDomainWithDependentResources(
@ -91,7 +91,7 @@ public class UnrenewDomainCommandTest extends CommandTestCase<UnrenewDomainComma
}
@Test
public void test_unrenewDomain_savesDependentEntitiesCorrectly() throws Exception {
void test_unrenewDomain_savesDependentEntitiesCorrectly() throws Exception {
ContactResource contact = persistActiveContact("jd1234");
clock.advanceOneMilli();
persistDomainWithDependentResources(
@ -155,7 +155,7 @@ public class UnrenewDomainCommandTest extends CommandTestCase<UnrenewDomainComma
}
@Test
public void test_periodTooLow_fails() {
void test_periodTooLow_fails() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class, () -> runCommandForced("--period", "0", "domain.tld"));
@ -163,7 +163,7 @@ public class UnrenewDomainCommandTest extends CommandTestCase<UnrenewDomainComma
}
@Test
public void test_periodTooHigh_fails() {
void test_periodTooHigh_fails() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class, () -> runCommandForced("--period", "10", "domain.tld"));
@ -171,7 +171,7 @@ public class UnrenewDomainCommandTest extends CommandTestCase<UnrenewDomainComma
}
@Test
public void test_varietyOfInvalidDomains_displaysErrors() {
void test_varietyOfInvalidDomains_displaysErrors() {
DateTime now = clock.nowUtc();
persistResource(
newDomainBase("deleting.tld")

View file

@ -31,13 +31,12 @@ import com.google.common.collect.ImmutableSortedMap;
import google.registry.model.domain.token.AllocationToken;
import google.registry.model.domain.token.AllocationToken.TokenStatus;
import org.joda.time.DateTime;
import org.junit.Test;
import org.junit.jupiter.api.Test;
public class UpdateAllocationTokensCommandTest
extends CommandTestCase<UpdateAllocationTokensCommand> {
class UpdateAllocationTokensCommandTest extends CommandTestCase<UpdateAllocationTokensCommand> {
@Test
public void testUpdateTlds_setTlds() throws Exception {
void testUpdateTlds_setTlds() throws Exception {
AllocationToken token =
persistResource(builderWithPromo().setAllowedTlds(ImmutableSet.of("toRemove")).build());
runCommandForced("--prefix", "token", "--allowed_tlds", "tld,example");
@ -45,7 +44,7 @@ public class UpdateAllocationTokensCommandTest
}
@Test
public void testUpdateTlds_clearTlds() throws Exception {
void testUpdateTlds_clearTlds() throws Exception {
AllocationToken token =
persistResource(builderWithPromo().setAllowedTlds(ImmutableSet.of("toRemove")).build());
runCommandForced("--prefix", "token", "--allowed_tlds", "");
@ -53,7 +52,7 @@ public class UpdateAllocationTokensCommandTest
}
@Test
public void testUpdateClientIds_setClientIds() throws Exception {
void testUpdateClientIds_setClientIds() throws Exception {
AllocationToken token =
persistResource(
builderWithPromo().setAllowedClientIds(ImmutableSet.of("toRemove")).build());
@ -63,7 +62,7 @@ public class UpdateAllocationTokensCommandTest
}
@Test
public void testUpdateClientIds_clearClientIds() throws Exception {
void testUpdateClientIds_clearClientIds() throws Exception {
AllocationToken token =
persistResource(
builderWithPromo().setAllowedClientIds(ImmutableSet.of("toRemove")).build());
@ -72,14 +71,14 @@ public class UpdateAllocationTokensCommandTest
}
@Test
public void testUpdateDiscountFraction() throws Exception {
void testUpdateDiscountFraction() throws Exception {
AllocationToken token = persistResource(builderWithPromo().setDiscountFraction(0.5).build());
runCommandForced("--prefix", "token", "--discount_fraction", "0.15");
assertThat(reloadResource(token).getDiscountFraction()).isEqualTo(0.15);
}
@Test
public void testUpdateStatusTransitions() throws Exception {
void testUpdateStatusTransitions() throws Exception {
DateTime now = DateTime.now(UTC);
AllocationToken token = persistResource(builderWithPromo().build());
runCommandForced(
@ -94,7 +93,7 @@ public class UpdateAllocationTokensCommandTest
}
@Test
public void testUpdateStatusTransitions_badTransitions() {
void testUpdateStatusTransitions_badTransitions() {
DateTime now = DateTime.now(UTC);
persistResource(builderWithPromo().build());
IllegalArgumentException thrown =
@ -114,7 +113,7 @@ public class UpdateAllocationTokensCommandTest
}
@Test
public void testUpdate_onlyWithPrefix() throws Exception {
void testUpdate_onlyWithPrefix() throws Exception {
AllocationToken token =
persistResource(builderWithPromo().setAllowedTlds(ImmutableSet.of("tld")).build());
AllocationToken otherToken =
@ -130,7 +129,7 @@ public class UpdateAllocationTokensCommandTest
}
@Test
public void testUpdate_onlyTokensProvided() throws Exception {
void testUpdate_onlyTokensProvided() throws Exception {
AllocationToken firstToken =
persistResource(builderWithPromo().setAllowedTlds(ImmutableSet.of("tld")).build());
AllocationToken secondToken =
@ -154,7 +153,7 @@ public class UpdateAllocationTokensCommandTest
}
@Test
public void testDoNothing() throws Exception {
void testDoNothing() throws Exception {
AllocationToken token =
persistResource(
builderWithPromo()
@ -170,7 +169,7 @@ public class UpdateAllocationTokensCommandTest
}
@Test
public void testFailure_bothTokensAndPrefix() {
void testFailure_bothTokensAndPrefix() {
assertThat(
assertThrows(
IllegalArgumentException.class,
@ -180,7 +179,7 @@ public class UpdateAllocationTokensCommandTest
}
@Test
public void testFailure_neitherTokensNorPrefix() {
void testFailure_neitherTokensNorPrefix() {
assertThat(
assertThrows(
IllegalArgumentException.class, () -> runCommandForced("--allowed_tlds", "tld")))
@ -189,7 +188,7 @@ public class UpdateAllocationTokensCommandTest
}
@Test
public void testFailure_emptyPrefix() {
void testFailure_emptyPrefix() {
IllegalArgumentException thrown =
assertThrows(IllegalArgumentException.class, () -> runCommandForced("--prefix", ""));
assertThat(thrown).hasMessageThat().isEqualTo("Provided prefix should not be blank");

View file

@ -26,16 +26,16 @@ import google.registry.model.common.Cursor.CursorType;
import google.registry.model.registry.Registry;
import google.registry.model.registry.Registry.RegistryNotFoundException;
import org.joda.time.DateTime;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link UpdateCursorsCommand}. */
public class UpdateCursorsCommandTest extends CommandTestCase<UpdateCursorsCommand> {
class UpdateCursorsCommandTest extends CommandTestCase<UpdateCursorsCommand> {
Registry registry;
private Registry registry;
@Before
public void before() {
@BeforeEach
void beforeEach() {
createTld("foo");
registry = Registry.get("foo");
}
@ -66,33 +66,33 @@ public class UpdateCursorsCommandTest extends CommandTestCase<UpdateCursorsComma
}
@Test
public void testSuccess_oldValueisEmpty() throws Exception {
void testSuccess_oldValueisEmpty() throws Exception {
assertThat(ofy().load().key(Cursor.createKey(CursorType.BRDA, registry)).now()).isNull();
doUpdateTest();
}
@Test
public void testSuccess_hasOldValue() throws Exception {
void testSuccess_hasOldValue() throws Exception {
persistResource(Cursor.create(CursorType.BRDA, DateTime.parse("1950-12-18TZ"), registry));
doUpdateTest();
}
@Test
public void testSuccess_global_hasOldValue() throws Exception {
void testSuccess_global_hasOldValue() throws Exception {
persistResource(
Cursor.createGlobal(CursorType.RECURRING_BILLING, DateTime.parse("1950-12-18TZ")));
doGlobalUpdateTest();
}
@Test
public void testSuccess_global_oldValueisEmpty() throws Exception {
void testSuccess_global_oldValueisEmpty() throws Exception {
assertThat(ofy().load().key(Cursor.createGlobalKey(CursorType.RECURRING_BILLING)).now())
.isNull();
doGlobalUpdateTest();
}
@Test
public void testSuccess_multipleTlds_hasOldValue() throws Exception {
void testSuccess_multipleTlds_hasOldValue() throws Exception {
createTld("bar");
Registry registry2 = Registry.get("bar");
persistResource(Cursor.create(CursorType.BRDA, DateTime.parse("1950-12-18TZ"), registry));
@ -110,7 +110,7 @@ public class UpdateCursorsCommandTest extends CommandTestCase<UpdateCursorsComma
}
@Test
public void testSuccess_multipleTlds_oldValueisEmpty() throws Exception {
void testSuccess_multipleTlds_oldValueisEmpty() throws Exception {
createTld("bar");
Registry registry2 = Registry.get("bar");
assertThat(ofy().load().key(Cursor.createKey(CursorType.BRDA, registry)).now()).isNull();
@ -128,14 +128,14 @@ public class UpdateCursorsCommandTest extends CommandTestCase<UpdateCursorsComma
}
@Test
public void testFailure_badTld() {
void testFailure_badTld() {
assertThrows(
RegistryNotFoundException.class,
() -> runCommandForced("--type=brda", "--timestamp=1984-12-18T00:00:00Z", "bar"));
}
@Test
public void testFailure_badCursorType() {
void testFailure_badCursorType() {
ParameterException thrown =
assertThrows(
ParameterException.class,

View file

@ -31,13 +31,13 @@ import google.registry.model.domain.DesignatedContact;
import google.registry.model.eppcommon.StatusValue;
import google.registry.model.host.HostResource;
import google.registry.persistence.VKey;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link UpdateDomainCommand}. */
public class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand> {
class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand> {
@Test
public void testSuccess_complete() throws Exception {
void testSuccess_complete() throws Exception {
runCommandForced(
"--client=NewRegistrar",
"--add_nameservers=ns1.zdns.google,ns2.zdns.google",
@ -57,7 +57,7 @@ public class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomain
}
@Test
public void testSuccess_completeWithSquareBrackets() throws Exception {
void testSuccess_completeWithSquareBrackets() throws Exception {
runCommandForced(
"--client=NewRegistrar",
"--add_nameservers=ns[1-2].zdns.google",
@ -77,7 +77,7 @@ public class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomain
}
@Test
public void testSuccess_multipleDomains() throws Exception {
void testSuccess_multipleDomains() throws Exception {
runCommandForced(
"--client=NewRegistrar",
"--add_nameservers=ns1.zdns.google,ns2.zdns.google",
@ -100,12 +100,12 @@ public class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomain
}
@Test
public void testSuccess_multipleDomains_setNameservers() throws Exception {
void testSuccess_multipleDomains_setNameservers() throws Exception {
runTest_multipleDomains_setNameservers("-n ns1.foo.fake,ns2.foo.fake");
}
@Test
public void testSuccess_multipleDomains_setNameserversWithSquareBrackets() throws Exception {
void testSuccess_multipleDomains_setNameserversWithSquareBrackets() throws Exception {
runTest_multipleDomains_setNameservers("-n ns[1-2].foo.fake");
}
@ -135,7 +135,7 @@ public class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomain
}
@Test
public void testSuccess_add() throws Exception {
void testSuccess_add() throws Exception {
runCommandForced(
"--client=NewRegistrar",
"--add_nameservers=ns2.zdns.google,ns3.zdns.google",
@ -148,7 +148,7 @@ public class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomain
}
@Test
public void testSuccess_remove() throws Exception {
void testSuccess_remove() throws Exception {
runCommandForced(
"--client=NewRegistrar",
"--remove_nameservers=ns4.zdns.google",
@ -161,14 +161,14 @@ public class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomain
}
@Test
public void testSuccess_change() throws Exception {
void testSuccess_change() throws Exception {
runCommandForced(
"--client=NewRegistrar", "--registrant=crr-admin", "--password=2fooBAR", "example.tld");
eppVerifier.verifySent("domain_update_change.xml");
}
@Test
public void testSuccess_setNameservers() throws Exception {
void testSuccess_setNameservers() throws Exception {
HostResource host1 = persistActiveHost("ns1.zdns.google");
HostResource host2 = persistActiveHost("ns2.zdns.google");
ImmutableSet<VKey<HostResource>> nameservers =
@ -181,7 +181,7 @@ public class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomain
}
@Test
public void testSuccess_setContacts() throws Exception {
void testSuccess_setContacts() throws Exception {
ContactResource adminContact1 = persistResource(newContactResource("crr-admin1"));
ContactResource adminContact2 = persistResource(newContactResource("crr-admin2"));
ContactResource techContact1 = persistResource(newContactResource("crr-tech1"));
@ -211,7 +211,7 @@ public class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomain
}
@Test
public void testSuccess_setStatuses() throws Exception {
void testSuccess_setStatuses() throws Exception {
HostResource host = persistActiveHost("ns1.zdns.google");
ImmutableSet<VKey<HostResource>> nameservers = ImmutableSet.of(host.createVKey());
persistResource(
@ -229,14 +229,14 @@ public class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomain
}
@Test
public void testSuccess_setDsRecords() throws Exception {
void testSuccess_setDsRecords() throws Exception {
runCommandForced(
"--client=NewRegistrar", "--ds_records=1 2 3 abcd,4 5 6 EF01", "example.tld");
eppVerifier.verifySent("domain_update_set_ds_records.xml");
}
@Test
public void testSuccess_setDsRecords_withUnneededClear() throws Exception {
void testSuccess_setDsRecords_withUnneededClear() throws Exception {
runCommandForced(
"--client=NewRegistrar",
"--ds_records=1 2 3 abcd,4 5 6 EF01",
@ -246,7 +246,7 @@ public class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomain
}
@Test
public void testSuccess_clearDsRecords() throws Exception {
void testSuccess_clearDsRecords() throws Exception {
runCommandForced(
"--client=NewRegistrar",
"--clear_ds_records",
@ -255,7 +255,7 @@ public class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomain
}
@Test
public void testFailure_cantUpdateRegistryLockedDomainEvenAsSuperuser() {
void testFailure_cantUpdateRegistryLockedDomainEvenAsSuperuser() {
HostResource host = persistActiveHost("ns1.zdns.google");
ImmutableSet<VKey<HostResource>> nameservers = ImmutableSet.of(host.createVKey());
persistResource(
@ -280,7 +280,7 @@ public class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomain
}
@Test
public void testFailure_duplicateDomains() {
void testFailure_duplicateDomains() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -295,7 +295,7 @@ public class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomain
}
@Test
public void testFailure_missingDomain() {
void testFailure_missingDomain() {
ParameterException thrown =
assertThrows(
ParameterException.class,
@ -306,7 +306,7 @@ public class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomain
}
@Test
public void testFailure_missingClientId() {
void testFailure_missingClientId() {
ParameterException thrown =
assertThrows(
ParameterException.class,
@ -315,7 +315,7 @@ public class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomain
}
@Test
public void testFailure_addTooManyNameServers() {
void testFailure_addTooManyNameServers() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -334,7 +334,7 @@ public class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomain
}
@Test
public void testFailure_providedNameserversAndAddNameservers() {
void testFailure_providedNameserversAndAddNameservers() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -352,7 +352,7 @@ public class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomain
}
@Test
public void testFailure_providedNameserversAndRemoveNameservers() {
void testFailure_providedNameserversAndRemoveNameservers() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -370,7 +370,7 @@ public class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomain
}
@Test
public void testFailure_providedAdminsAndAddAdmins() {
void testFailure_providedAdminsAndAddAdmins() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -388,7 +388,7 @@ public class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomain
}
@Test
public void testFailure_providedAdminsAndRemoveAdmins() {
void testFailure_providedAdminsAndRemoveAdmins() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -406,7 +406,7 @@ public class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomain
}
@Test
public void testFailure_providedTechsAndAddTechs() {
void testFailure_providedTechsAndAddTechs() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -423,7 +423,7 @@ public class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomain
}
@Test
public void testFailure_providedTechsAndRemoveTechs() {
void testFailure_providedTechsAndRemoveTechs() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -440,7 +440,7 @@ public class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomain
}
@Test
public void testFailure_providedStatusesAndAddStatuses() {
void testFailure_providedStatusesAndAddStatuses() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -458,7 +458,7 @@ public class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomain
}
@Test
public void testFailure_providedStatusesAndRemoveStatuses() {
void testFailure_providedStatusesAndRemoveStatuses() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -476,7 +476,7 @@ public class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomain
}
@Test
public void testFailure_provideDsRecordsAndAddDsRecords() {
void testFailure_provideDsRecordsAndAddDsRecords() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -494,7 +494,7 @@ public class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomain
}
@Test
public void testFailure_provideDsRecordsAndRemoveDsRecords() {
void testFailure_provideDsRecordsAndRemoveDsRecords() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -512,7 +512,7 @@ public class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomain
}
@Test
public void testFailure_clearDsRecordsAndAddDsRecords() {
void testFailure_clearDsRecordsAndAddDsRecords() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@ -530,7 +530,7 @@ public class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomain
}
@Test
public void testFailure_clearDsRecordsAndRemoveDsRecords() {
void testFailure_clearDsRecordsAndRemoveDsRecords() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,

View file

@ -24,22 +24,22 @@ import static org.mockito.Mockito.when;
import com.google.common.collect.ImmutableMap;
import com.google.common.net.MediaType;
import google.registry.tools.server.UpdatePremiumListAction;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
/** Unit tests for {@link UpdatePremiumListCommand}. */
public class UpdatePremiumListCommandTest<C extends UpdatePremiumListCommand>
class UpdatePremiumListCommandTest<C extends UpdatePremiumListCommand>
extends CreateOrUpdatePremiumListCommandTestCase<C> {
@Mock AppEngineConnection connection;
String premiumTermsPath;
private String premiumTermsPath;
String premiumTermsCsv;
String servletPath;
private String servletPath;
@Before
public void init() throws Exception {
@BeforeEach
void beforeEach() throws Exception {
command.setConnection(connection);
servletPath = "/_dr/admin/updatePremiumList";
premiumTermsPath =
@ -52,7 +52,7 @@ public class UpdatePremiumListCommandTest<C extends UpdatePremiumListCommand>
}
@Test
public void testRun() throws Exception {
void testRun() throws Exception {
runCommandForced("-i=" + premiumTermsPath, "-n=foo");
verifySentParams(
connection,
@ -61,7 +61,7 @@ public class UpdatePremiumListCommandTest<C extends UpdatePremiumListCommand>
}
@Test
public void testRun_noProvidedName_usesBasenameOfInputFile() throws Exception {
void testRun_noProvidedName_usesBasenameOfInputFile() throws Exception {
runCommandForced("-i=" + premiumTermsPath);
assertInStdout("Successfully");
verifySentParams(

View file

@ -39,13 +39,13 @@ import google.registry.util.CidrAddressBlock;
import java.util.Optional;
import org.joda.money.CurrencyUnit;
import org.joda.time.DateTime;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link UpdateRegistrarCommand}. */
public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarCommand> {
class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarCommand> {
@Test
public void testSuccess_alsoUpdateInCloudSql() throws Exception {
void testSuccess_alsoUpdateInCloudSql() throws Exception {
assertThat(loadRegistrar("NewRegistrar").verifyPassword("some_password")).isFalse();
jpaTm().transact(() -> jpaTm().saveNew(loadRegistrar("NewRegistrar")));
runCommand("--password=some_password", "--force", "NewRegistrar");
@ -58,14 +58,14 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
}
@Test
public void testSuccess_password() throws Exception {
void testSuccess_password() throws Exception {
assertThat(loadRegistrar("NewRegistrar").verifyPassword("some_password")).isFalse();
runCommand("--password=some_password", "--force", "NewRegistrar");
assertThat(loadRegistrar("NewRegistrar").verifyPassword("some_password")).isTrue();
}
@Test
public void testSuccess_registrarType() throws Exception {
void testSuccess_registrarType() throws Exception {
persistResource(
loadRegistrar("NewRegistrar")
.asBuilder()
@ -78,7 +78,7 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
}
@Test
public void testFailure_noPasscodeOnChangeToReal() {
void testFailure_noPasscodeOnChangeToReal() {
persistResource(
loadRegistrar("NewRegistrar")
.asBuilder()
@ -94,14 +94,14 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
}
@Test
public void testSuccess_registrarState() throws Exception {
void testSuccess_registrarState() throws Exception {
assertThat(loadRegistrar("NewRegistrar").getState()).isEqualTo(State.ACTIVE);
runCommand("--registrar_state=SUSPENDED", "--force", "NewRegistrar");
assertThat(loadRegistrar("NewRegistrar").getState()).isEqualTo(State.SUSPENDED);
}
@Test
public void testSuccess_allowedTlds() throws Exception {
void testSuccess_allowedTlds() throws Exception {
persistWhoisAbuseContact();
createTlds("xn--q9jyb4c", "foobar");
persistResource(
@ -119,7 +119,7 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
}
@Test
public void testSuccess_addAllowedTlds() throws Exception {
void testSuccess_addAllowedTlds() throws Exception {
persistWhoisAbuseContact();
createTlds("xn--q9jyb4c", "foo", "bar");
persistResource(
@ -137,7 +137,7 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
}
@Test
public void testSuccess_addAllowedTldsWithDupes() throws Exception {
void testSuccess_addAllowedTldsWithDupes() throws Exception {
persistWhoisAbuseContact();
createTlds("xn--q9jyb4c", "foo", "bar");
persistResource(
@ -155,7 +155,7 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
}
@Test
public void testSuccess_allowedTldsInNonProductionEnvironment() throws Exception {
void testSuccess_allowedTldsInNonProductionEnvironment() throws Exception {
createTlds("xn--q9jyb4c", "foobar");
persistResource(
loadRegistrar("NewRegistrar")
@ -172,7 +172,7 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
}
@Test
public void testSuccess_allowedTldsInPdtRegistrar() throws Exception {
void testSuccess_allowedTldsInPdtRegistrar() throws Exception {
createTlds("xn--q9jyb4c", "foobar");
persistResource(
loadRegistrar("NewRegistrar")
@ -191,7 +191,7 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
}
@Test
public void testSuccess_ipAllowList() throws Exception {
void testSuccess_ipAllowList() throws Exception {
assertThat(loadRegistrar("NewRegistrar").getIpAddressAllowList()).isEmpty();
runCommand("--ip_allow_list=192.168.1.1,192.168.0.2/16", "--force", "NewRegistrar");
assertThat(loadRegistrar("NewRegistrar").getIpAddressAllowList())
@ -201,7 +201,7 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
}
@Test
public void testSuccess_clearIpAllowList_useNull() throws Exception {
void testSuccess_clearIpAllowList_useNull() throws Exception {
persistResource(
loadRegistrar("NewRegistrar")
.asBuilder()
@ -216,7 +216,7 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
}
@Test
public void testSuccess_clearIpAllowList_useEmpty() throws Exception {
void testSuccess_clearIpAllowList_useEmpty() throws Exception {
persistResource(
loadRegistrar("NewRegistrar")
.asBuilder()
@ -231,7 +231,7 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
}
@Test
public void testSuccess_certFile() throws Exception {
void testSuccess_certFile() throws Exception {
Registrar registrar = loadRegistrar("NewRegistrar");
assertThat(registrar.getClientCertificate()).isNull();
assertThat(registrar.getClientCertificateHash()).isNull();
@ -244,7 +244,7 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
}
@Test
public void testSuccess_certHash() throws Exception {
void testSuccess_certHash() throws Exception {
assertThat(loadRegistrar("NewRegistrar").getClientCertificateHash()).isNull();
runCommand("--cert_hash=" + SAMPLE_CERT_HASH, "--force", "NewRegistrar");
assertThat(loadRegistrar("NewRegistrar").getClientCertificateHash())
@ -252,7 +252,7 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
}
@Test
public void testSuccess_clearCert() throws Exception {
void testSuccess_clearCert() throws Exception {
persistResource(
loadRegistrar("NewRegistrar")
.asBuilder()
@ -264,7 +264,7 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
}
@Test
public void testSuccess_clearCertHash() throws Exception {
void testSuccess_clearCertHash() throws Exception {
persistResource(
loadRegistrar("NewRegistrar")
.asBuilder()
@ -276,28 +276,28 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
}
@Test
public void testSuccess_ianaId() throws Exception {
void testSuccess_ianaId() throws Exception {
assertThat(loadRegistrar("NewRegistrar").getIanaIdentifier()).isEqualTo(8);
runCommand("--iana_id=12345", "--force", "NewRegistrar");
assertThat(loadRegistrar("NewRegistrar").getIanaIdentifier()).isEqualTo(12345);
}
@Test
public void testSuccess_billingId() throws Exception {
void testSuccess_billingId() throws Exception {
assertThat(loadRegistrar("NewRegistrar").getBillingIdentifier()).isNull();
runCommand("--billing_id=12345", "--force", "NewRegistrar");
assertThat(loadRegistrar("NewRegistrar").getBillingIdentifier()).isEqualTo(12345);
}
@Test
public void testSuccess_poNumber() throws Exception {
void testSuccess_poNumber() throws Exception {
assertThat(loadRegistrar("NewRegistrar").getPoNumber()).isEmpty();
runCommand("--po_number=52345", "--force", "NewRegistrar");
assertThat(loadRegistrar("NewRegistrar").getPoNumber()).hasValue("52345");
}
@Test
public void testSuccess_billingAccountMap() throws Exception {
void testSuccess_billingAccountMap() throws Exception {
assertThat(loadRegistrar("NewRegistrar").getBillingAccountMap()).isEmpty();
runCommand("--billing_account_map=USD=abc123,JPY=789xyz", "--force", "NewRegistrar");
assertThat(loadRegistrar("NewRegistrar").getBillingAccountMap())
@ -305,7 +305,7 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
}
@Test
public void testFailure_billingAccountMap_doesNotContainEntryForTldAllowed() {
void testFailure_billingAccountMap_doesNotContainEntryForTldAllowed() {
createTlds("foo");
assertThat(loadRegistrar("NewRegistrar").getBillingAccountMap()).isEmpty();
IllegalArgumentException thrown =
@ -322,7 +322,7 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
}
@Test
public void testSuccess_billingAccountMap_onlyAppliesToRealRegistrar() throws Exception {
void testSuccess_billingAccountMap_onlyAppliesToRealRegistrar() throws Exception {
createTlds("foo");
assertThat(loadRegistrar("NewRegistrar").getBillingAccountMap()).isEmpty();
runCommand("--billing_account_map=JPY=789xyz", "--allowed_tlds=foo", "--force", "NewRegistrar");
@ -331,7 +331,7 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
}
@Test
public void testSuccess_billingAccountMap_partialUpdate() throws Exception {
void testSuccess_billingAccountMap_partialUpdate() throws Exception {
createTlds("foo");
persistResource(
loadRegistrar("NewRegistrar")
@ -345,7 +345,7 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
}
@Test
public void testSuccess_streetAddress() throws Exception {
void testSuccess_streetAddress() throws Exception {
runCommand(
"--street=\"1234 Main St\"",
"--street \"4th Floor\"",
@ -370,35 +370,35 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
}
@Test
public void testSuccess_blockPremiumNames() throws Exception {
void testSuccess_blockPremiumNames() throws Exception {
assertThat(loadRegistrar("NewRegistrar").getBlockPremiumNames()).isFalse();
runCommandForced("--block_premium=true", "NewRegistrar");
assertThat(loadRegistrar("NewRegistrar").getBlockPremiumNames()).isTrue();
}
@Test
public void testSuccess_resetBlockPremiumNames() throws Exception {
void testSuccess_resetBlockPremiumNames() throws Exception {
persistResource(loadRegistrar("NewRegistrar").asBuilder().setBlockPremiumNames(true).build());
runCommandForced("--block_premium=false", "NewRegistrar");
assertThat(loadRegistrar("NewRegistrar").getBlockPremiumNames()).isFalse();
}
@Test
public void testSuccess_allowRegistryLock() throws Exception {
void testSuccess_allowRegistryLock() throws Exception {
assertThat(loadRegistrar("NewRegistrar").isRegistryLockAllowed()).isFalse();
runCommandForced("--registry_lock_allowed=true", "NewRegistrar");
assertThat(loadRegistrar("NewRegistrar").isRegistryLockAllowed()).isTrue();
}
@Test
public void testSuccess_disallowRegistryLock() throws Exception {
void testSuccess_disallowRegistryLock() throws Exception {
persistResource(loadRegistrar("NewRegistrar").asBuilder().setRegistryLockAllowed(true).build());
runCommandForced("--registry_lock_allowed=false", "NewRegistrar");
assertThat(loadRegistrar("NewRegistrar").isRegistryLockAllowed()).isFalse();
}
@Test
public void testSuccess_unspecifiedBooleansArentChanged() throws Exception {
void testSuccess_unspecifiedBooleansArentChanged() throws Exception {
persistResource(
loadRegistrar("NewRegistrar")
.asBuilder()
@ -414,7 +414,7 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
}
@Test
public void testSuccess_updateMultiple() throws Exception {
void testSuccess_updateMultiple() throws Exception {
assertThat(loadRegistrar("TheRegistrar").getState()).isEqualTo(State.ACTIVE);
assertThat(loadRegistrar("NewRegistrar").getState()).isEqualTo(State.ACTIVE);
runCommandForced("--registrar_state=SUSPENDED", "TheRegistrar", "NewRegistrar");
@ -423,7 +423,7 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
}
@Test
public void testSuccess_resetOptionalParamsNullString() throws Exception {
void testSuccess_resetOptionalParamsNullString() throws Exception {
Registrar registrar = loadRegistrar("NewRegistrar");
registrar =
persistResource(
@ -466,7 +466,7 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
}
@Test
public void testSuccess_resetOptionalParamsEmptyString() throws Exception {
void testSuccess_resetOptionalParamsEmptyString() throws Exception {
Registrar registrar = loadRegistrar("NewRegistrar");
registrar =
persistResource(
@ -509,7 +509,7 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
}
@Test
public void testSuccess_setIcannEmail() throws Exception {
void testSuccess_setIcannEmail() throws Exception {
runCommand("--icann_referral_email=foo@bar.test", "--force", "TheRegistrar");
Registrar registrar = loadRegistrar("TheRegistrar");
assertThat(registrar.getIcannReferralEmail()).isEqualTo("foo@bar.test");
@ -517,20 +517,20 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
}
@Test
public void testSuccess_setEmail() throws Exception {
void testSuccess_setEmail() throws Exception {
runCommand("--email=foo@bar.baz", "--force", "TheRegistrar");
Registrar registrar = loadRegistrar("TheRegistrar");
assertThat(registrar.getEmailAddress()).isEqualTo("foo@bar.baz");
}
@Test
public void testSuccess_setWhoisServer_works() throws Exception {
void testSuccess_setWhoisServer_works() throws Exception {
runCommand("--whois=whois.goth.black", "--force", "NewRegistrar");
assertThat(loadRegistrar("NewRegistrar").getWhoisServer()).isEqualTo("whois.goth.black");
}
@Test
public void testSuccess_triggerGroupSyncing_works() throws Exception {
void testSuccess_triggerGroupSyncing_works() throws Exception {
persistResource(
loadRegistrar("NewRegistrar").asBuilder().setContactsRequireSyncing(false).build());
assertThat(loadRegistrar("NewRegistrar").getContactsRequireSyncing()).isFalse();
@ -539,83 +539,83 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
}
@Test
public void testFailure_invalidRegistrarType() {
void testFailure_invalidRegistrarType() {
assertThrows(
ParameterException.class,
() -> runCommand("--registrar_type=INVALID_TYPE", "--force", "NewRegistrar"));
}
@Test
public void testFailure_invalidRegistrarState() {
void testFailure_invalidRegistrarState() {
assertThrows(
ParameterException.class,
() -> runCommand("--registrar_state=INVALID_STATE", "--force", "NewRegistrar"));
}
@Test
public void testFailure_negativeIanaId() {
void testFailure_negativeIanaId() {
assertThrows(
IllegalArgumentException.class,
() -> runCommand("--iana_id=-1", "--force", "NewRegistrar"));
}
@Test
public void testFailure_nonIntegerIanaId() {
void testFailure_nonIntegerIanaId() {
assertThrows(
ParameterException.class, () -> runCommand("--iana_id=ABC123", "--force", "NewRegistrar"));
}
@Test
public void testFailure_negativeBillingId() {
void testFailure_negativeBillingId() {
assertThrows(
IllegalArgumentException.class,
() -> runCommand("--billing_id=-1", "--force", "NewRegistrar"));
}
@Test
public void testFailure_nonIntegerBillingId() {
void testFailure_nonIntegerBillingId() {
assertThrows(
ParameterException.class,
() -> runCommand("--billing_id=ABC123", "--force", "NewRegistrar"));
}
@Test
public void testFailure_passcodeTooShort() {
void testFailure_passcodeTooShort() {
assertThrows(
IllegalArgumentException.class,
() -> runCommand("--passcode=0123", "--force", "NewRegistrar"));
}
@Test
public void testFailure_passcodeTooLong() {
void testFailure_passcodeTooLong() {
assertThrows(
IllegalArgumentException.class,
() -> runCommand("--passcode=012345", "--force", "NewRegistrar"));
}
@Test
public void testFailure_invalidPasscode() {
void testFailure_invalidPasscode() {
assertThrows(
IllegalArgumentException.class,
() -> runCommand("--passcode=code1", "--force", "NewRegistrar"));
}
@Test
public void testFailure_allowedTldDoesNotExist() {
void testFailure_allowedTldDoesNotExist() {
assertThrows(
IllegalArgumentException.class,
() -> runCommand("--allowed_tlds=foobar", "--force", "NewRegistrar"));
}
@Test
public void testFailure_addAllowedTldDoesNotExist() {
void testFailure_addAllowedTldDoesNotExist() {
assertThrows(
IllegalArgumentException.class,
() -> runCommand("--add_allowed_tlds=foobar", "--force", "NewRegistrar"));
}
@Test
public void testFailure_allowedTldsAndAddAllowedTlds() {
void testFailure_allowedTldsAndAddAllowedTlds() {
assertThrows(
IllegalArgumentException.class,
() ->
@ -623,7 +623,7 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
}
@Test
public void testFailure_setAllowedTldsWithoutAbuseContact() {
void testFailure_setAllowedTldsWithoutAbuseContact() {
createTlds("bar");
IllegalArgumentException thrown =
assertThrows(
@ -638,7 +638,7 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
}
@Test
public void testFailure_addAllowedTldsWithoutAbuseContact() {
void testFailure_addAllowedTldsWithoutAbuseContact() {
createTlds("bar");
IllegalArgumentException thrown =
assertThrows(
@ -653,21 +653,21 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
}
@Test
public void testFailure_invalidIpAllowList() {
void testFailure_invalidIpAllowList() {
assertThrows(
IllegalArgumentException.class,
() -> runCommand("--ip_allow_list=foobarbaz", "--force", "NewRegistrar"));
}
@Test
public void testFailure_invalidCertFileContents() {
void testFailure_invalidCertFileContents() {
assertThrows(
Exception.class,
() -> runCommand("--cert_file=" + writeToTmpFile("ABCDEF"), "--force", "NewRegistrar"));
}
@Test
public void testFailure_certHashAndCertFile() {
void testFailure_certHashAndCertFile() {
assertThrows(
IllegalArgumentException.class,
() ->
@ -679,12 +679,12 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
}
@Test
public void testFailure_missingClientId() {
void testFailure_missingClientId() {
assertThrows(ParameterException.class, () -> runCommand("--force"));
}
@Test
public void testFailure_missingStreetLines() {
void testFailure_missingStreetLines() {
assertThrows(
IllegalArgumentException.class,
() ->
@ -698,7 +698,7 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
}
@Test
public void testFailure_missingCity() {
void testFailure_missingCity() {
assertThrows(
IllegalArgumentException.class,
() ->
@ -714,7 +714,7 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
}
@Test
public void testFailure_missingState() {
void testFailure_missingState() {
assertThrows(
IllegalArgumentException.class,
() ->
@ -730,7 +730,7 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
}
@Test
public void testFailure_missingZip() {
void testFailure_missingZip() {
assertThrows(
IllegalArgumentException.class,
() ->
@ -746,7 +746,7 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
}
@Test
public void testFailure_missingCc() {
void testFailure_missingCc() {
assertThrows(
IllegalArgumentException.class,
() ->
@ -762,7 +762,7 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
}
@Test
public void testFailure_missingInvalidCc() {
void testFailure_missingInvalidCc() {
assertThrows(
IllegalArgumentException.class,
() ->
@ -779,7 +779,7 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
}
@Test
public void testFailure_tooManyStreetLines() {
void testFailure_tooManyStreetLines() {
assertThrows(
IllegalArgumentException.class,
() ->
@ -797,7 +797,7 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
}
@Test
public void testFailure_tooFewStreetLines() {
void testFailure_tooFewStreetLines() {
assertThrows(
IllegalArgumentException.class,
() ->
@ -812,21 +812,21 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
}
@Test
public void testFailure_unknownFlag() {
void testFailure_unknownFlag() {
assertThrows(
ParameterException.class,
() -> runCommand("--force", "--unrecognized_flag=foo", "NewRegistrar"));
}
@Test
public void testFailure_doesNotExist() {
void testFailure_doesNotExist() {
IllegalArgumentException thrown =
assertThrows(IllegalArgumentException.class, () -> runCommand("--force", "ClientZ"));
assertThat(thrown).hasMessageThat().contains("Registrar ClientZ not found");
}
@Test
public void testFailure_registrarNameSimilarToExisting() {
void testFailure_registrarNameSimilarToExisting() {
// Note that "tHeRe GiStRaR" normalizes identically to "The Registrar", which is created by
// AppEngineRule.
assertThrows(
@ -835,7 +835,7 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
}
@Test
public void testSuccess_poNumberNotSpecified_doesntWipeOutExisting() throws Exception {
void testSuccess_poNumberNotSpecified_doesntWipeOutExisting() throws Exception {
Registrar registrar =
persistResource(
loadRegistrar("NewRegistrar").asBuilder().setPoNumber(Optional.of("1664")).build());
@ -847,7 +847,7 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
}
@Test
public void testSuccess_poNumber_canBeBlanked() throws Exception {
void testSuccess_poNumber_canBeBlanked() throws Exception {
persistResource(
loadRegistrar("NewRegistrar").asBuilder().setPoNumber(Optional.of("1664")).build());
runCommand("--po_number=null", "--force", "NewRegistrar");
@ -855,7 +855,7 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
}
@Test
public void testFailure_badEmail() {
void testFailure_badEmail() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,

View file

@ -26,15 +26,15 @@ import com.google.common.collect.ImmutableMap;
import google.registry.model.registry.label.ReservedList;
import google.registry.model.registry.label.ReservedList.ReservedListEntry;
import google.registry.model.registry.label.ReservedListSqlDao;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link UpdateReservedListCommand}. */
public class UpdateReservedListCommandTest extends
CreateOrUpdateReservedListCommandTestCase<UpdateReservedListCommand> {
class UpdateReservedListCommandTest
extends CreateOrUpdateReservedListCommandTestCase<UpdateReservedListCommand> {
@Before
public void setup() {
@BeforeEach
void beforeEach() {
populateInitialReservedListInDatastore(true);
}
@ -60,17 +60,17 @@ public class UpdateReservedListCommandTest extends
}
@Test
public void testSuccess() throws Exception {
void testSuccess() throws Exception {
runSuccessfulUpdateTest("--name=xn--q9jyb4c_common-reserved", "--input=" + reservedTermsPath);
}
@Test
public void testSuccess_unspecifiedNameDefaultsToFileName() throws Exception {
void testSuccess_unspecifiedNameDefaultsToFileName() throws Exception {
runSuccessfulUpdateTest("--input=" + reservedTermsPath);
}
@Test
public void testSuccess_lastUpdateTime_updatedCorrectly() throws Exception {
void testSuccess_lastUpdateTime_updatedCorrectly() throws Exception {
ReservedList original = ReservedList.get("xn--q9jyb4c_common-reserved").get();
runCommandForced("--input=" + reservedTermsPath);
ReservedList updated = ReservedList.get("xn--q9jyb4c_common-reserved").get();
@ -80,7 +80,7 @@ public class UpdateReservedListCommandTest extends
}
@Test
public void testSuccess_shouldPublish_setToFalseCorrectly() throws Exception {
void testSuccess_shouldPublish_setToFalseCorrectly() throws Exception {
runSuccessfulUpdateTest("--input=" + reservedTermsPath, "--should_publish=false");
assertThat(ReservedList.get("xn--q9jyb4c_common-reserved")).isPresent();
ReservedList reservedList = ReservedList.get("xn--q9jyb4c_common-reserved").get();
@ -88,7 +88,7 @@ public class UpdateReservedListCommandTest extends
}
@Test
public void testSuccess_shouldPublish_doesntOverrideFalseIfNotSpecified() throws Exception {
void testSuccess_shouldPublish_doesntOverrideFalseIfNotSpecified() throws Exception {
populateInitialReservedListInDatastore(false);
runCommandForced("--input=" + reservedTermsPath);
assertThat(ReservedList.get("xn--q9jyb4c_common-reserved")).isPresent();
@ -107,7 +107,7 @@ public class UpdateReservedListCommandTest extends
}
@Test
public void testFailure_reservedListDoesntExist() {
void testFailure_reservedListDoesntExist() {
String errorMessage =
"Could not update reserved list xn--q9jyb4c_poobah because it doesn't exist.";
IllegalArgumentException thrown =
@ -119,7 +119,7 @@ public class UpdateReservedListCommandTest extends
}
@Test
public void testSaveToCloudSql_succeeds() throws Exception {
void testSaveToCloudSql_succeeds() throws Exception {
populateInitialReservedListInCloudSql(true);
runCommandForced("--name=xn--q9jyb4c_common-reserved", "--input=" + reservedTermsPath);
verifyXnq9jyb4cInDatastore();
@ -127,7 +127,7 @@ public class UpdateReservedListCommandTest extends
}
@Test
public void testSaveToCloudSql_succeedsEvenPreviousListNotExist() throws Exception {
void testSaveToCloudSql_succeedsEvenPreviousListNotExist() throws Exception {
// Note that, during the dual-write phase, we always save the reserved list to Cloud SQL without
// checking if there is a list with same name. This is to backfill the existing list in Cloud
// Datastore when we update it.

View file

@ -17,48 +17,48 @@ package google.registry.tools;
import static org.junit.Assert.assertThrows;
import com.beust.jcommander.ParameterException;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link UpdateServerLocksCommand}. */
public class UpdateServerLocksCommandTest extends EppToolCommandTestCase<UpdateServerLocksCommand> {
class UpdateServerLocksCommandTest extends EppToolCommandTestCase<UpdateServerLocksCommand> {
@Test
public void testSuccess_applyOne() throws Exception {
void testSuccess_applyOne() throws Exception {
runCommandForced("--client=NewRegistrar", "--registrar_request=true", "--reason=Test",
"--domain_name=example.tld", "--apply=serverRenewProhibited");
eppVerifier.verifySent("update_server_locks_apply_one.xml");
}
@Test
public void testSuccess_multipleWordReason() throws Exception {
void testSuccess_multipleWordReason() throws Exception {
runCommandForced("--client=NewRegistrar", "--registrar_request=false",
"--reason=\"Test this\"", "--domain_name=example.tld", "--apply=serverRenewProhibited");
eppVerifier.verifySent("update_server_locks_multiple_word_reason.xml");
}
@Test
public void testSuccess_removeOne() throws Exception {
void testSuccess_removeOne() throws Exception {
runCommandForced("--client=NewRegistrar", "--registrar_request=true", "--reason=Test",
"--domain_name=example.tld", "--remove=serverRenewProhibited");
eppVerifier.verifySent("update_server_locks_remove_one.xml");
}
@Test
public void testSuccess_applyAll() throws Exception {
void testSuccess_applyAll() throws Exception {
runCommandForced("--client=NewRegistrar", "--registrar_request=true", "--reason=Test",
"--domain_name=example.tld", "--apply=all");
eppVerifier.verifySent("update_server_locks_apply_all.xml");
}
@Test
public void testSuccess_removeAll() throws Exception {
void testSuccess_removeAll() throws Exception {
runCommandForced("--client=NewRegistrar", "--registrar_request=true", "--reason=Test",
"--domain_name=example.tld", "--remove=all");
eppVerifier.verifySent("update_server_locks_remove_all.xml");
}
@Test
public void testFailure_applyAllRemoveOne_failsDueToOverlap() {
void testFailure_applyAllRemoveOne_failsDueToOverlap() {
assertThrows(
IllegalArgumentException.class,
() ->
@ -72,7 +72,7 @@ public class UpdateServerLocksCommandTest extends EppToolCommandTestCase<UpdateS
}
@Test
public void testFailure_illegalStatus() {
void testFailure_illegalStatus() {
// The EPP status is a valid one by RFC, but invalid for this command.
assertThrows(
IllegalArgumentException.class,
@ -86,7 +86,7 @@ public class UpdateServerLocksCommandTest extends EppToolCommandTestCase<UpdateS
}
@Test
public void testFailure_unrecognizedStatus() {
void testFailure_unrecognizedStatus() {
// Handles a status passed to the command that doesn't correspond to any
// EPP-valid status.
assertThrows(
@ -101,7 +101,7 @@ public class UpdateServerLocksCommandTest extends EppToolCommandTestCase<UpdateS
}
@Test
public void testFailure_mainParameter() {
void testFailure_mainParameter() {
assertThrows(
ParameterException.class,
() ->
@ -115,7 +115,7 @@ public class UpdateServerLocksCommandTest extends EppToolCommandTestCase<UpdateS
}
@Test
public void testFailure_noOp() {
void testFailure_noOp() {
assertThrows(
IllegalArgumentException.class,
() ->
@ -130,7 +130,7 @@ public class UpdateServerLocksCommandTest extends EppToolCommandTestCase<UpdateS
}
@Test
public void testFailure_missingClientId() {
void testFailure_missingClientId() {
assertThrows(
ParameterException.class,
() ->
@ -142,7 +142,7 @@ public class UpdateServerLocksCommandTest extends EppToolCommandTestCase<UpdateS
}
@Test
public void testFailure_unknownFlag() {
void testFailure_unknownFlag() {
assertThrows(
ParameterException.class,
() ->
@ -156,7 +156,7 @@ public class UpdateServerLocksCommandTest extends EppToolCommandTestCase<UpdateS
}
@Test
public void testFailure_noReasonWhenNotRegistrarRequested() {
void testFailure_noReasonWhenNotRegistrarRequested() {
assertThrows(
IllegalArgumentException.class,
() ->
@ -168,7 +168,7 @@ public class UpdateServerLocksCommandTest extends EppToolCommandTestCase<UpdateS
}
@Test
public void testFailure_missingRegistrarRequest() {
void testFailure_missingRegistrarRequest() {
assertThrows(
ParameterException.class,
() ->

Some files were not shown because too many files have changed in this diff Show more