@Override public String push(String path, InputStream body) { String key = createKey(); set(suffix(prefix(path, "/"), "/") + key + "/", body); return key; }
@Override public String push(String path, InputStream body) { String key = createKey(); set(suffix(prefix(path, "/"), "/") + key + "/", body); return key; }
@Test public void testArrayOfObject() throws IOException { Object[] original = new Object[]{map( "id", "foo" )}; jsondb.set("/test", mapper.writeValueAsString(original)); String result1 = jsondb.getAsString("", prettyPrint).trim(); assertThat(result1).isEqualTo("{\n" + " \"test\" : [ {\n" + " \"id\" : \"foo\"\n" + " } ]\n" + "}".trim()); }
@Test public void testArrayOfObject() throws IOException { Object[] original = new Object[]{map( "id", "foo" )}; jsondb.set("/test", mapper.writeValueAsString(original)); String result1 = jsondb.getAsString("", prettyPrint).trim(); assertThat(result1).isEqualTo("{\n" + " \"test\" : [ {\n" + " \"id\" : \"foo\"\n" + " } ]\n" + "}".trim()); }
@Test public void testExists() throws IOException { HashMap<String, Object> user = map( "name", "Joe", "developer", false ); jsondb.set("/", mapper.writeValueAsString(user)); assertThat(jsondb.exists("/badpath")).isFalse(); assertThat(jsondb.exists("/name")).isTrue(); }
@Test public void testGetMissingKey() throws IOException { jsondb.set("/test", mapper.writeValueAsString(map( "name", "Hiram Chirino" ))); String json = jsondb.getAsString("/bar"); assertThat(json).isNull(); }
@Test public void testGetStartAfter() throws IOException { jsondb.set("/test", mapper.writeValueAsString(map( "user1", "test 1", "user2", "test 2", "user3", "test 3", "user4", "test 4", "user5", "test 5", "user6", "test 6" ))); String json = jsondb.getAsString("/test", new GetOptions().startAfter("user3")); assertThat(json).isEqualTo("{\"user4\":\"test 4\",\"user5\":\"test 5\",\"user6\":\"test 6\"}"); }
@Test public void testGetEndAt() throws IOException { jsondb.set("/test", mapper.writeValueAsString(map( "user1", "test 1", "user2", "test 2", "user3", "test 3", "user4", "test 4", "user5", "test 5", "user6", "test 6" ))); String json = jsondb.getAsString("/test", new GetOptions().endAt("user4")); assertThat(json).isEqualTo("{\"user1\":\"test 1\",\"user2\":\"test 2\",\"user3\":\"test 3\",\"user4\":\"test 4\"}"); }
@Test public void testGetEndBefore() throws IOException { jsondb.set("/test", mapper.writeValueAsString(map( "user1", "test 1", "user2", "test 2", "user3", "test 3", "user4", "test 4", "user5", "test 5", "user6", "test 6" ))); String json = jsondb.getAsString("/test", new GetOptions().endBefore("user5")); assertThat(json).isEqualTo("{\"user1\":\"test 1\",\"user2\":\"test 2\",\"user3\":\"test 3\",\"user4\":\"test 4\"}"); }
@Test public void testGetStartAt() throws IOException { jsondb.set("/test", mapper.writeValueAsString(map( "user1", "test 1", "user2", "test 2", "user3", "test 3", "user4", "test 4", "user5", "test 5", "user6", "test 6" ))); String json = jsondb.getAsString("/test", new GetOptions().startAt("user4")); assertThat(json).isEqualTo("{\"user4\":\"test 4\",\"user5\":\"test 5\",\"user6\":\"test 6\"}"); }
@Test public void testGetEndBefore() throws IOException { jsondb.set("/test", mapper.writeValueAsString(map( "user1", "test 1", "user2", "test 2", "user3", "test 3", "user4", "test 4", "user5", "test 5", "user6", "test 6" ))); String json = jsondb.getAsString("/test", new GetOptions().endBefore("user5")); assertThat(json).isEqualTo("{\"user1\":\"test 1\",\"user2\":\"test 2\",\"user3\":\"test 3\",\"user4\":\"test 4\"}"); }
@Test public void testGetStartAtEndAt() throws IOException { jsondb.set("/test", mapper.writeValueAsString(map( "user1", "1", "user2:1", "2", "user2:2", "3", "user2:3", "4", "user4", "5" ))); String json = jsondb.getAsString("/test", new GetOptions().startAt("user2:").endAt("user2:")); assertThat(json).isEqualTo("{\"user2:1\":\"2\",\"user2:2\":\"3\",\"user2:3\":\"4\"}"); }
@Test public void shouldAscertainPropertyPairExistence() { jsondb.set("/pair/:id", "{\"key\": \"value\"}"); assertThat(jsondb.fetchIdsByPropertyValue("/pair", "key", "value")).containsOnly("/pair/:id"); assertThat(jsondb.fetchIdsByPropertyValue("/pair", "key", "nope")).isEmpty(); }
@Test public void testGetStartAtEndAt() throws IOException { jsondb.set("/test", mapper.writeValueAsString(map( "user1", "1", "user2:1", "2", "user2:2", "3", "user2:3", "4", "user4", "5" ))); String json = jsondb.getAsString("/test", new GetOptions().startAt("user2:").endAt("user2:")); assertThat(json).isEqualTo("{\"user2:1\":\"2\",\"user2:2\":\"3\",\"user2:3\":\"4\"}"); }
@Test public void shouldAscertainPropertyPairExistence() { jsondb.set("/pair/:id", "{\"key\": \"value\"}"); assertThat(jsondb.fetchIdsByPropertyValue("/pair", "key", "value")).containsOnly("/pair/:id"); assertThat(jsondb.fetchIdsByPropertyValue("/pair", "key", "nope")).isEmpty(); }
@Test public void testGetEndAtWithDESC() throws IOException { jsondb.set("/test", mapper.writeValueAsString(map( "user1", "test 1", "user2", "test 2", "user3", "test 3", "user4", "test 4", "user5", "test 5", "user6", "test 6" ))); String json = jsondb.getAsString("/test", new GetOptions().endAt("user3").order(GetOptions.Order.DESC)); assertThat(json).isEqualTo("{\"user6\":\"test 6\",\"user5\":\"test 5\",\"user4\":\"test 4\",\"user3\":\"test 3\"}"); }
@Test public void testGetStartAfterWithDESC() throws IOException { jsondb.set("/test", mapper.writeValueAsString(map( "user1", "test 1", "user2", "test 2", "user3", "test 3", "user4", "test 4", "user5", "test 5", "user6", "test 6" ))); String json = jsondb.getAsString("/test", new GetOptions().startAfter("user3").order(GetOptions.Order.DESC)); assertThat(json).isEqualTo("{\"user2\":\"test 2\",\"user1\":\"test 1\"}"); }
@Test public void testGetStartAfterWithDESC() throws IOException { jsondb.set("/test", mapper.writeValueAsString(map( "user1", "test 1", "user2", "test 2", "user3", "test 3", "user4", "test 4", "user5", "test 5", "user6", "test 6" ))); String json = jsondb.getAsString("/test", new GetOptions().startAfter("user3").order(GetOptions.Order.DESC)); assertThat(json).isEqualTo("{\"user2\":\"test 2\",\"user1\":\"test 1\"}"); }
@Test public void testGetStartAtWithDESC() throws IOException { jsondb.set("/test", mapper.writeValueAsString(map( "user1", "test 1", "user2", "test 2", "user3", "test 3", "user4", "test 4", "user5", "test 5", "user6", "test 6" ))); String json = jsondb.getAsString("/test", new GetOptions().startAt("user2").order(GetOptions.Order.DESC)); assertThat(json).isEqualTo("{\"user2\":\"test 2\",\"user1\":\"test 1\"}"); }
@Test public void testGetEndBeforeWithDESC() throws IOException { jsondb.set("/test", mapper.writeValueAsString(map( "user1", "test 1", "user2", "test 2", "user3", "test 3", "user4", "test 4", "user5", "test 5", "user6", "test 6" ))); String json = jsondb.getAsString("/test", new GetOptions().endBefore("user2").order(GetOptions.Order.DESC)); assertThat(json).isEqualTo("{\"user6\":\"test 6\",\"user5\":\"test 5\",\"user4\":\"test 4\",\"user3\":\"test 3\"}"); }