mirror of
https://github.com/google/nomulus.git
synced 2025-05-01 20:47:52 +02:00
The only remaining methods on ExceptionRule after this are methods that also exist on ExpectedException, which will allow us to, in the next CL, swap out the one for the other and then run the automated refactoring to turn it all into assertThrows/expectThrows. Note that there were some assertions about root causes that couldn't easily be turned into ExpectedException invocations, so I simply converted them directly to usages of assertThrows/expectThrows. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=178623431
86 lines
3 KiB
Java
86 lines
3 KiB
Java
// Copyright 2017 The Nomulus Authors. All Rights Reserved.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package google.registry.tools;
|
|
|
|
import static google.registry.testing.DatastoreHelper.createTld;
|
|
import static google.registry.testing.DatastoreHelper.persistActiveDomainApplication;
|
|
import static google.registry.testing.DatastoreHelper.persistResource;
|
|
|
|
import com.googlecode.objectify.Key;
|
|
import google.registry.model.domain.DomainApplication;
|
|
import google.registry.model.domain.LrpTokenEntity;
|
|
import google.registry.model.reporting.HistoryEntry;
|
|
import org.junit.Before;
|
|
import org.junit.Test;
|
|
|
|
/** Unit tests for {@link GetLrpTokenCommand}. */
|
|
public class GetLrpTokenCommandTest extends CommandTestCase<GetLrpTokenCommand> {
|
|
|
|
@Before
|
|
public void before() {
|
|
createTld("tld");
|
|
DomainApplication lrpApplication = persistActiveDomainApplication("domain.tld");
|
|
HistoryEntry applicationCreateHistoryEntry = persistResource(new HistoryEntry.Builder()
|
|
.setParent(lrpApplication)
|
|
.setType(HistoryEntry.Type.DOMAIN_APPLICATION_CREATE)
|
|
.build());
|
|
persistResource(
|
|
new LrpTokenEntity.Builder()
|
|
.setAssignee("domain.tld")
|
|
.setToken("domain_token")
|
|
.setRedemptionHistoryEntry(Key.create(applicationCreateHistoryEntry))
|
|
.build());
|
|
}
|
|
|
|
@Test
|
|
public void testSuccess_byAssignee() throws Exception {
|
|
runCommand("--assignee=domain.tld");
|
|
assertInStdout("domain_token");
|
|
}
|
|
|
|
@Test
|
|
public void testSuccess_byToken() throws Exception {
|
|
runCommand("--token=domain_token");
|
|
assertInStdout("domain.tld");
|
|
assertNotInStdout("fullyQualifiedDomainName=domain.tld"); // history param should be false
|
|
}
|
|
|
|
@Test
|
|
public void testSuccess_iosByToken_withHistory() throws Exception {
|
|
runCommand("--token=domain_token", "--history");
|
|
assertInStdout("domain.tld");
|
|
assertInStdout("fullyQualifiedDomainName=domain.tld");
|
|
assertInStdout("type=DOMAIN_APPLICATION_CREATE");
|
|
}
|
|
|
|
@Test
|
|
public void testSuccess_unknownAssignee() throws Exception {
|
|
runCommand("--assignee=nobody");
|
|
assertInStdout("Token not found");
|
|
}
|
|
|
|
@Test
|
|
public void testSuccess_unknownToken() throws Exception {
|
|
runCommand("--token=bogus_token");
|
|
assertInStdout("Token not found");
|
|
}
|
|
|
|
@Test
|
|
public void testFailure_noArgs() throws Exception {
|
|
thrown.expect(IllegalArgumentException.class);
|
|
thrown.expectMessage("Exactly one of either token or assignee must be specified.");
|
|
runCommand();
|
|
}
|
|
}
|