strangedb-server/src/test/java/it/cavallium/strangedb/server/GetSetExistsTest.java

58 lines
1.4 KiB
Java
Raw Normal View History

2019-03-09 18:53:30 +01:00
package it.cavallium.strangedb.server;
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 static junit.framework.Assert.*;
public class GetSetExistsTest {
private Path path1;
private Path path2;
private Path path3;
private DatabaseSimple db;
@Before
public void setUp() throws Exception {
path1 = Files.createTempFile("db-tests-", ".db");
path2 = Files.createTempFile("db-tests-", ".db");
path3 = Files.createTempFile("db-tests-", ".db");
db = new DatabaseSimple(path1, path2, path3);
}
@Test
public void shouldSetObject() throws IOException {
assertTrue(db.exists(""));
assertEquals(db.get(""), "{}");
db.set("", "{}");
assertTrue(db.exists(""));
assertEquals(db.get(""), "{}");
db.set("brightness", "\"15\"");
}
@Test
public void shouldGetObject() throws IOException {
assertFalse(db.exists("brightness"));
db.set("brightness", "\"15\"");
assertTrue(db.exists("brightness"));
assertEquals(db.get("brightness"), "\"15\"");
assertEquals(db.get(""), "{brightness:\"15\"}");
db.set("brightness", "\"16\"");
assertEquals(db.get("brightness"), "\"16\"");
assertEquals(db.get(""), "{brightness:\"16\"}");
}
@After
public void tearDown() throws Exception {
db.close();
Files.deleteIfExists(path1);
Files.deleteIfExists(path2);
Files.deleteIfExists(path3);
}
}