60 lines
2.2 KiB
Java
60 lines
2.2 KiB
Java
package it.cavallium.strangedb.tests;
|
|
|
|
import it.cavallium.strangedb.java.database.DatabaseJava;
|
|
import it.cavallium.strangedb.java.objects.lists.ListQuery;
|
|
import it.cavallium.strangedb.java.objects.lists.ValuePointer;
|
|
import it.cavallium.strangedb.java.objects.lists.operations.Equals;
|
|
import org.junit.After;
|
|
import org.junit.Before;
|
|
import org.junit.Test;
|
|
|
|
import java.io.IOException;
|
|
import java.nio.file.Files;
|
|
import java.nio.file.Path;
|
|
import java.util.ArrayList;
|
|
|
|
import static org.junit.Assert.assertNotEquals;
|
|
|
|
public class QueryTests {
|
|
|
|
public static final String constantFirstName = "Jesus christ this is a very strange first name";
|
|
public static final String constantUsername = "is this an username?";
|
|
public static final String constantBio = "and is this a bio??? Are you mad?";
|
|
private Path path1;
|
|
private Path path2;
|
|
private Path path3;
|
|
private DatabaseJava db;
|
|
|
|
@Before
|
|
public void setUp() throws Exception {
|
|
path1 = Files.createTempFile("db-tests-data-", ".db");
|
|
path2 = Files.createTempFile("db-tests-blocks-", ".db");
|
|
path3 = Files.createTempFile("db-tests-references-", ".db");
|
|
db = new DatabaseJava(path1, path2, path3);
|
|
}
|
|
|
|
@Test
|
|
public void shouldCreateListAndQuery() throws IOException {
|
|
ListContainer root = db.loadRoot((db) -> new ListContainer(db, 1000));
|
|
ListQuery query = ListQuery.create(ValuePointer.ofField(User.class, "firstName"), Equals.to(constantFirstName))
|
|
.and(ValuePointer.ofField(User.class, "username"), Equals.to(constantUsername))
|
|
.and(ValuePointer.ofField(User.class, "fullInfo").field(UserFullInfo.class, "bio"), Equals.to(constantBio));
|
|
long time1 = System.currentTimeMillis();
|
|
ArrayList<User> elements = root.usersList.query(query).asList();
|
|
System.out.println("Time elapsed: " + (System.currentTimeMillis() - time1));
|
|
System.out.println("Found " + elements.size() + " elements. First 5 items:");
|
|
assertNotEquals(elements.size(), 0);
|
|
for (int i = 0; i < (elements.size() > 10 ? 10 : elements.size()); i++) {
|
|
System.out.println(elements.get(i));
|
|
}
|
|
db.close();
|
|
}
|
|
|
|
@After
|
|
public void tearDown() throws Exception {
|
|
Files.deleteIfExists(path1);
|
|
Files.deleteIfExists(path2);
|
|
Files.deleteIfExists(path3);
|
|
}
|
|
}
|