google-nomulus/javatests/google/registry/model/domain/LrpTokenEntityTest.java
mcilwain 7dc224627f Automatically refactor more exception testing to use new JUnit rules
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=178911894
2017-12-27 10:42:36 -05:00

89 lines
3.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.model.domain;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.persistActiveDomainApplication;
import static google.registry.testing.DatastoreHelper.persistResource;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.googlecode.objectify.Key;
import google.registry.model.EntityTestCase;
import google.registry.model.reporting.HistoryEntry;
import org.junit.Before;
import org.junit.Test;
/** Unit tests for {@link LrpTokenEntity}. */
public class LrpTokenEntityTest extends EntityTestCase {
LrpTokenEntity unredeemedToken;
LrpTokenEntity redeemedToken;
@Before
public void setUp() throws Exception {
createTld("tld");
DomainApplication lrpApplication = persistActiveDomainApplication("domain.tld");
HistoryEntry applicationCreateHistoryEntry = persistResource(new HistoryEntry.Builder()
.setParent(lrpApplication)
.setType(HistoryEntry.Type.DOMAIN_APPLICATION_CREATE)
.build());
unredeemedToken = persistResource(
new LrpTokenEntity.Builder()
.setAssignee("1:1020304")
.setToken("a0b1c2d3e4f5g6")
.setValidTlds(ImmutableSet.of("tld"))
.setMetadata(ImmutableMap.of("foo", "bar"))
.build());
redeemedToken = persistResource(
new LrpTokenEntity.Builder()
.setAssignee("2:org.testdomain")
.setToken("h0i1j2k3l4m")
.setRedemptionHistoryEntry(Key.create(applicationCreateHistoryEntry))
.setValidTlds(ImmutableSet.of("tld"))
.setMetadata(ImmutableMap.of("bar", "foo"))
.build());
}
@Test
public void testPersistence() throws Exception {
assertThat(ofy().load().entity(redeemedToken).now()).isEqualTo(redeemedToken);
}
@Test
public void testSuccess_loadByToken() throws Exception {
assertThat(ofy().load().key(Key.create(LrpTokenEntity.class, "a0b1c2d3e4f5g6")).now())
.isEqualTo(unredeemedToken);
}
@Test
public void testSuccess_loadByAssignee() throws Exception {
assertThat(
ofy().load().type(LrpTokenEntity.class).filter("assignee", "1:1020304").first().now())
.isEqualTo(unredeemedToken);
}
@Test
public void testSuccess_isRedeemed() throws Exception {
assertThat(redeemedToken.isRedeemed()).isTrue();
assertThat(unredeemedToken.isRedeemed()).isFalse();
}
@Test
public void testIndexing() throws Exception {
verifyIndexing(redeemedToken, "assignee", "token");
}
}