Java Code Examples for io.paperdb.Paper#put()

The following examples show how to use io.paperdb.Paper#put() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PaperDeprecatedAPITest.java    From Paper with Apache License 2.0 6 votes vote down vote up
@Test
public void testClear() throws Exception {
    Paper.put("persons", TestDataGenerator.genPersonList(10));
    Paper.put("persons2", TestDataGenerator.genPersonList(20));
    assertTrue(Paper.exist("persons"));
    assertTrue(Paper.exist("persons2"));

    Paper.clear(getTargetContext());
    // init() call is not required after clear()
    assertFalse(Paper.exist("persons"));
    assertFalse(Paper.exist("persons2"));

    // Should be possible to continue to use Paper after clear()
    Paper.put("persons3", TestDataGenerator.genPersonList(30));
    assertTrue(Paper.exist("persons3"));
    assertThat(Paper.<List>get("persons3")).hasSize(30);
}
 
Example 2
Source File: DataTest.java    From Paper with Apache License 2.0 5 votes vote down vote up
@Test
public void testPutGetList() {
    final List<Person> inserted = genPersonList(10000);
    Paper.put("persons", inserted);
    List<Person> persons = Paper.get("persons");
    assertThat(persons).isEqualTo(inserted);
}
 
Example 3
Source File: DataTest.java    From Paper with Apache License 2.0 5 votes vote down vote up
@Test
public void testPutMap() {
    final Map<Integer, Person> inserted = genPersonMap(10000);
    Paper.put("persons", inserted);

    final Map<Integer, Person> personMap = Paper.get("persons");
    assertThat(personMap).isEqualTo(inserted);
}
 
Example 4
Source File: DataTest.java    From Paper with Apache License 2.0 5 votes vote down vote up
@Test
public void testPutPOJO() {
    final Person person = genPerson(new Person(), 1);
    Paper.put("profile", person);

    final Person savedPerson = Paper.get("profile");
    assertThat(savedPerson).isEqualTo(person);
    assertThat(savedPerson).isNotSameAs(person);
}
 
Example 5
Source File: PaperDeprecatedAPITest.java    From Paper with Apache License 2.0 5 votes vote down vote up
@Test
public void testDelete() throws Exception {
    Paper.put("persons", TestDataGenerator.genPersonList(10));
    assertTrue(Paper.exist("persons"));
    Paper.delete("persons");
    assertFalse(Paper.exist("persons"));
}
 
Example 6
Source File: PaperDeprecatedAPITest.java    From Paper with Apache License 2.0 5 votes vote down vote up
@Test
public void testPutGetNormalAfterReinit() {
    Paper.put("city", "Lund");
    String val = Paper.get("city", "default");
    Paper.init(getTargetContext());// Reinit Paper instance
    assertThat(val).isEqualTo("Lund");
}
 
Example 7
Source File: PaperDeprecatedAPITest.java    From Paper with Apache License 2.0 5 votes vote down vote up
@Test
public void testValidKeyNames() {
    Paper.put("city", "Lund");
    assertThat(Paper.get("city")).isEqualTo("Lund");

    Paper.put("city.dasd&%", "Lund");
    assertThat(Paper.get("city.dasd&%")).isEqualTo("Lund");

    Paper.put("city-ads", "Lund");
    assertThat(Paper.get("city-ads")).isEqualTo("Lund");
}
 
Example 8
Source File: DataTest.java    From Paper with Apache License 2.0 4 votes vote down vote up
@Test
public void testPutEmptyList() throws Exception {
    final List<Person> inserted = genPersonList(0);
    Paper.put("persons", inserted);
    assertThat(Paper.<List>get("persons")).isEmpty();
}
 
Example 9
Source File: DataTest.java    From Paper with Apache License 2.0 4 votes vote down vote up
private Object testReadWriteWithoutClassCheck(Object originObj) {
    Paper.put("obj", originObj);
    Object readObj = Paper.get("obj");
    assertThat(readObj).isEqualTo(originObj);
    return readObj;
}
 
Example 10
Source File: PaperDeprecatedAPITest.java    From Paper with Apache License 2.0 4 votes vote down vote up
@Test
public void testExist() throws Exception {
    assertFalse(Paper.exist("persons"));
    Paper.put("persons", TestDataGenerator.genPersonList(10));
    assertTrue(Paper.exist("persons"));
}
 
Example 11
Source File: PaperDeprecatedAPITest.java    From Paper with Apache License 2.0 4 votes vote down vote up
@Test
public void testPutGetNormal() {
    Paper.put("city", "Lund");
    String val = Paper.get("city", "default");
    assertThat(val).isEqualTo("Lund");
}
 
Example 12
Source File: PaperDeprecatedAPITest.java    From Paper with Apache License 2.0 4 votes vote down vote up
@Test
public void testReplace() {
    Paper.put("city", "Lund");
    Paper.put("city", "Kyiv");
    assertThat(Paper.get("city")).isEqualTo("Kyiv");
}
 
Example 13
Source File: PaperDeprecatedAPITest.java    From Paper with Apache License 2.0 4 votes vote down vote up
@Test(expected = PaperDbException.class)
public void testInvalidKeyNameBackslash() {
    Paper.put("city/ads", "Lund");
    assertThat(Paper.get("city/ads")).isEqualTo("Lund");
}