Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
313 changes: 27 additions & 286 deletions src/test/java/com/cinchapi/runway/RecordTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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<Node> 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<Class<?>, TypeAdapter<?>> typeAdapters() {
return ImmutableMap.of(Dock.class, new TypeAdapter<Dock>() {

@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<Dock> docks;

public Lock(List<Dock> 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<Stock> 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<Class<?>, TypeAdapter<?>> typeAdapters() {
return ImmutableMap.of(Tag.class, new TypeAdapter<Tag>() {

@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<SampleEnum> enumCollection = Sets.newHashSet();

public HasEnumCollection() {
enumCollection.add(SampleEnum.FOO);
}
}

class Shoe extends Record {

public Shoe(List<String> shoes) {
this.shoes = shoes;
}

List<String> shoes;
boolean ignore = false;
}

class Nock extends Mock {

@Derived
public String zipcode() {
return "30327";
}

@Derived("area")
public String city() {
return "Atlanta";
}

@Override
public Map<String, Object> 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<String, Supplier<Object>> computed() {
return ImmutableMap.of("state", () -> {
long stop = System.currentTimeMillis() + 1000;
while (System.currentTimeMillis() < stop) {
continue;
}
return "Georgia";
});
}
}

class Bock extends Nock {
@Override
public Map<String, Supplier<Object>> computed() {
return ImmutableMap.of("state",
() -> Continuation.of(UUID::randomUUID));
}
}

class Jock extends Record {

public Gock testy;
public String name;
public DeferredReference<Jock> mentor;
public List<DeferredReference<Jock>> 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<User> users() {
return db.find(User.class, Criteria.where().key("company")
.operator(Operator.LINKS_TO).value(id()));
}

@Override
public Map<String, Supplier<Object>> computed() {
return ImmutableMap.of("users", () -> users());
}
}


}
Loading