Add @VirtualEntity checking to Ofy's deleteWithoutBackup()

This was an oversight I noticed ages ago, so resurrecting some old local changes I had to correct it.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=146812322
This commit is contained in:
nickfelt 2017-02-07 11:41:05 -08:00 committed by Ben McIlwain
parent d2bc569b4b
commit 5d4a88e5ce
7 changed files with 78 additions and 12 deletions

View file

@ -17,10 +17,12 @@ package google.registry.testing;
import static google.registry.model.common.EntityGroupRoot.getCrossTldKey;
import com.googlecode.objectify.Key;
import com.googlecode.objectify.ObjectifyService;
import com.googlecode.objectify.annotation.Entity;
import com.googlecode.objectify.annotation.Id;
import com.googlecode.objectify.annotation.Parent;
import google.registry.model.ImmutableObject;
import google.registry.model.annotations.VirtualEntity;
import google.registry.model.common.EntityGroupRoot;
/**
@ -28,6 +30,10 @@ import google.registry.model.common.EntityGroupRoot;
*/
@Entity
public class TestObject extends ImmutableObject {
static {
ObjectifyService.register(TestObject.class); // Register this kind on first reference.
}
@Parent
Key<EntityGroupRoot> parent;
@ -59,4 +65,30 @@ public class TestObject extends ImmutableObject {
instance.parent = parent;
return instance;
}
/** A test @VirtualEntity model object, which should not be persisted. */
@Entity
@VirtualEntity
public static class TestVirtualObject extends ImmutableObject {
static {
ObjectifyService.register(TestVirtualObject.class); // Register this kind on first reference.
}
@Id
String id;
/**
* Expose a factory method for testing saves of virtual entities; in real life this would never
* be needed for an actual @VirtualEntity.
*/
public static TestVirtualObject create(String id) {
TestVirtualObject instance = new TestVirtualObject();
instance.id = id;
return instance;
}
public static Key<TestVirtualObject> createKey(String id) {
return Key.create(TestVirtualObject.class, id);
}
}
}