diff --git a/src/test/java/com/cinchapi/runway/RecordTest.java b/src/test/java/com/cinchapi/runway/RecordTest.java index 6b83871..75e5ebb 100644 --- a/src/test/java/com/cinchapi/runway/RecordTest.java +++ b/src/test/java/com/cinchapi/runway/RecordTest.java @@ -17,11 +17,8 @@ import java.io.IOException; import java.util.Collection; -import java.util.List; import java.util.Map; import java.util.Set; -import java.util.UUID; -import java.util.function.Supplier; import java.util.stream.Collectors; import com.google.gson.Gson; @@ -32,21 +29,36 @@ import com.cinchapi.common.base.CheckedExceptions; import com.cinchapi.common.collect.Association; import com.cinchapi.common.collect.Collections; -import com.cinchapi.common.collect.Continuation; import com.cinchapi.common.reflect.Reflection; import com.cinchapi.concourse.Concourse; import com.cinchapi.concourse.Link; -import com.cinchapi.concourse.Tag; import com.cinchapi.concourse.lang.Criteria; import com.cinchapi.concourse.test.ClientServerTest; import com.cinchapi.concourse.thrift.Operator; import com.cinchapi.concourse.util.Random; +import com.cinchapi.runway.Testing.Bock; +import com.cinchapi.runway.Testing.Company; +import com.cinchapi.runway.Testing.Dock; +import com.cinchapi.runway.Testing.Flock; +import com.cinchapi.runway.Testing.Gock; +import com.cinchapi.runway.Testing.HasEnumCollection; +import com.cinchapi.runway.Testing.Jock; +import com.cinchapi.runway.Testing.Lock; +import com.cinchapi.runway.Testing.Mock; +import com.cinchapi.runway.Testing.Nock; +import com.cinchapi.runway.Testing.Node; +import com.cinchapi.runway.Testing.Pock; +import com.cinchapi.runway.Testing.Rock; +import com.cinchapi.runway.Testing.SampleEnum; +import com.cinchapi.runway.Testing.Shoe; +import com.cinchapi.runway.Testing.Sock; +import com.cinchapi.runway.Testing.Stock; +import com.cinchapi.runway.Testing.Tock; +import com.cinchapi.runway.Testing.User; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Lists; import com.google.common.collect.Multimap; -import com.google.common.collect.Sets; import com.google.gson.GsonBuilder; import com.google.gson.JsonElement; import com.google.gson.JsonParser; @@ -802,15 +814,15 @@ public void testMapNavigationComplex() { @Test public void testSetValueToNullRemovesFromDatabase() { - Mock mock = new Mock(); + MMock mock = new MMock(); mock.alive = true; mock.age = 10; mock.name = "Mock"; - mock.bar = false; + mock.flagged = false; mock.save(); mock.age = null; mock.save(); - mock = runway.load(Mock.class, mock.id()); + mock = runway.load(MMock.class, mock.id()); Assert.assertNull(mock.age); } @@ -1122,284 +1134,13 @@ public void testMultuSetInvalidAttributes() { // System.out.println(shoe.shoes.getClass()); // Assert.assertEquals(Lists.newArrayList("B", "D", "A"), shoe.shoes); // } - - class Node extends Record { - - public String label; - public List friends = Lists.newArrayList(); - - public Node(String label) { - this.label = label; - } - } - - class Mock extends Record { - - @Unique - @Required - public String name; - - public Integer age; - - public boolean alive = true; - + + class MMock extends Mock { + @SuppressWarnings("unused") - private boolean foo = false; - - @Readable - private boolean bar = false; - - } - - class Flock extends Record { - - public final String name; - - public Flock(String name) { - this.name = name; - } - } - - class Sock extends Record { - - public final String sock; - public final Dock dock; - - public Sock(String sock, Dock dock) { - this.sock = sock; - this.dock = dock; - } - - @Override - public Map, TypeAdapter> typeAdapters() { - return ImmutableMap.of(Dock.class, new TypeAdapter() { - - @Override - public void write(JsonWriter out, Dock value) - throws IOException { - out.value("foo"); - } - - @Override - public Dock read(JsonReader in) throws IOException { - return null; - } - - }); - } - } - - class Lock extends Record { - public final List docks; - - public Lock(List docks) { - this.docks = docks; - } - } - - class Dock extends Record { - - public final String dock; - - public Dock(String dock) { - this.dock = dock; - } - } - - class Tock extends Record { - public List stocks = Lists.newArrayList(); - public boolean zombie = false; - - public Tock() { - - } - } - - class Stock extends Record { - public Tock tock; - } - - class Pock extends Record { - public Tag tag; - - public Pock(String tag) { - this.tag = Tag.create(tag); - } - - @Override - public Map, TypeAdapter> typeAdapters() { - return ImmutableMap.of(Tag.class, new TypeAdapter() { - - @Override - public void write(JsonWriter out, Tag value) - throws IOException { - out.value(tag.toString()); - } - - @Override - public Tag read(JsonReader in) throws IOException { - return null; - } - - }); - } - - } - - enum SampleEnum { - FOO - } - - class HasEnumCollection extends Record { - Set enumCollection = Sets.newHashSet(); - - public HasEnumCollection() { - enumCollection.add(SampleEnum.FOO); - } - } - - class Shoe extends Record { - - public Shoe(List shoes) { - this.shoes = shoes; - } - - List shoes; - boolean ignore = false; - } - - class Nock extends Mock { - - @Derived - public String zipcode() { - return "30327"; - } - - @Derived("area") - public String city() { - return "Atlanta"; - } - - @Override - public Map derived() { - return ImmutableMap.of("city", "Atlanta"); - } - - } - - class Rock extends Nock { - - @Computed("county") - public String county() { - long stop = System.currentTimeMillis() + 1000; - while (System.currentTimeMillis() < stop) { - continue; - } - return "Fulton"; - } - - @Override - public Map> computed() { - return ImmutableMap.of("state", () -> { - long stop = System.currentTimeMillis() + 1000; - while (System.currentTimeMillis() < stop) { - continue; - } - return "Georgia"; - }); - } - } - - class Bock extends Nock { - @Override - public Map> computed() { - return ImmutableMap.of("state", - () -> Continuation.of(UUID::randomUUID)); - } - } - - class Jock extends Record { - - public Gock testy; - public String name; - public DeferredReference mentor; - public List> friends = Lists.newArrayList(); - - public Jock(String name) { - this.name = name; - } - - } - - class Gock extends Jock { - - public Stock stock; - public Node node; - public User user; - public Sock sock; - public Gock gock; - public Jock jock; - public Jock jock2; - public Hock hock; - public Qock qock; - - public Gock(String name) { - super(name); - } - - } - - class Hock extends Record { - - public String a; - + private boolean flagged; } - class Oock extends Hock { - - } - - class Qock extends Record { - - public String a; - - } - - class Vock extends Qock { - - public String b; - - } - - class User extends Record { - String name; - String email; - Company company; - - public User(String name, String email, Company company) { - this.name = name; - this.email = email; - this.company = company; - } - } - - class Company extends Record { - - String name; - - public Company(String name) { - this.name = name; - } - - public Set users() { - return db.find(User.class, Criteria.where().key("company") - .operator(Operator.LINKS_TO).value(id())); - } - - @Override - public Map> computed() { - return ImmutableMap.of("users", () -> users()); - } - } + } diff --git a/src/test/java/com/cinchapi/runway/Testing.java b/src/test/java/com/cinchapi/runway/Testing.java index e3821eb..dc9783b 100644 --- a/src/test/java/com/cinchapi/runway/Testing.java +++ b/src/test/java/com/cinchapi/runway/Testing.java @@ -15,6 +15,24 @@ */ package com.cinchapi.runway; +import java.io.IOException; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.UUID; +import java.util.function.Supplier; + +import com.cinchapi.common.collect.Continuation; +import com.cinchapi.concourse.Tag; +import com.cinchapi.concourse.lang.Criteria; +import com.cinchapi.concourse.thrift.Operator; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; +import com.google.gson.TypeAdapter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; + /** * Utilities for testing. * @@ -29,4 +47,293 @@ public final class Testing { private Testing() {/* no-init */} + static class Node extends Record { + + public String label; + public List friends = Lists.newArrayList(); + + public Node(String label) { + this.label = label; + } + } + + static class Mock extends Record { + + @Unique + @Required + public String name; + + public Integer age; + + public boolean alive = true; + + @SuppressWarnings("unused") + private boolean foo = false; + + @Readable + private boolean bar = false; + + } + + static class Nock extends Mock { + + @Derived + public String zipcode() { + return "30327"; + } + + @Derived("area") + public String city() { + return "Atlanta"; + } + + @Override + public Map derived() { + return ImmutableMap.of("city", "Atlanta"); + } + + } + + static class Flock extends Record { + + public final String name; + + public Flock(String name) { + this.name = name; + } + } + + static class Sock extends Record { + + public final String sock; + public final Dock dock; + + public Sock(String sock, Dock dock) { + this.sock = sock; + this.dock = dock; + } + + @Override + public Map, TypeAdapter> typeAdapters() { + return ImmutableMap.of(Dock.class, new TypeAdapter() { + + @Override + public void write(JsonWriter out, Dock value) + throws IOException { + out.value("foo"); + } + + @Override + public Dock read(JsonReader in) throws IOException { + return null; + } + + }); + } + } + + static class Lock extends Record { + public final List docks; + + public Lock(List docks) { + this.docks = docks; + } + } + + static class Dock extends Record { + + public final String dock; + + public Dock(String dock) { + this.dock = dock; + } + } + + static class Tock extends Record { + public List stocks = Lists.newArrayList(); + public boolean zombie = false; + + public Tock() { + + } + } + + static class Stock extends Record { + public Tock tock; + } + + static class Pock extends Record { + public Tag tag; + + public Pock(String tag) { + this.tag = Tag.create(tag); + } + + @Override + public Map, TypeAdapter> typeAdapters() { + return ImmutableMap.of(Tag.class, new TypeAdapter() { + + @Override + public void write(JsonWriter out, Tag value) + throws IOException { + out.value(tag.toString()); + } + + @Override + public Tag read(JsonReader in) throws IOException { + return null; + } + + }); + } + + } + + static enum SampleEnum { + FOO + } + + static class HasEnumCollection extends Record { + Set enumCollection = Sets.newHashSet(); + + public HasEnumCollection() { + enumCollection.add(SampleEnum.FOO); + } + } + + static class Shoe extends Record { + + public Shoe(List shoes) { + this.shoes = shoes; + } + + List shoes; + boolean ignore = false; + } + + static class Rock extends Nock { + + @Computed("county") + public String county() { + long stop = System.currentTimeMillis() + 1000; + while (System.currentTimeMillis() < stop) { + continue; + } + return "Fulton"; + } + + @Override + public Map> computed() { + return ImmutableMap.of("state", () -> { + long stop = System.currentTimeMillis() + 1000; + while (System.currentTimeMillis() < stop) { + continue; + } + return "Georgia"; + }); + } + } + + static class Bock extends Nock { + @Override + public Map> computed() { + return ImmutableMap.of("state", + () -> Continuation.of(UUID::randomUUID)); + } + } + + static class Jock extends Record { + + public Gock testy; + public String name; + public DeferredReference mentor; + public List> friends = Lists.newArrayList(); + + public Jock(String name) { + this.name = name; + } + + } + + static class Gock extends Jock { + + public Stock stock; + public Node node; + public User user; + public Sock sock; + public Gock gock; + public Jock jock; + public Jock jock2; + public Hock hock; + public Qock qock; + + public Gock(String name) { + super(name); + } + + } + + static class Hock extends Record { + + public String a; + + } + + static class Oock extends Hock { + + } + + static class Qock extends Record { + + public String a; + + } + + static class Vock extends Qock { + + public String b; + + } + + static class User extends Record { + String name; + String email; + Company company; + + public User(String name, String email, Company company) { + this.name = name; + this.email = email; + this.company = company; + } + } + + static class Company extends Record { + + String name; + + public Company(String name) { + this.name = name; + } + + public Set users() { + return db.find(User.class, Criteria.where().key("company") + .operator(Operator.LINKS_TO).value(id())); + } + + @Override + public Map> computed() { + return ImmutableMap.of("users", () -> users()); + } + } + + static class ExtendedDock extends Dock { + + public final String extension; + + public ExtendedDock(String dock, String extension) { + super(dock); + this.extension = extension; + } + } + }