@Test public void testDelete() throws IOException { HashMap<String, Object> user = map( "name", "Joe", "developer", false ); jsondb.set("/", mapper.writeValueAsString(user)); Map<?, ?> result = mapper.readValue(jsondb.getAsString(""), HashMap.class); assertThat(result).hasSize(2); assertThat(jsondb.delete("/badpath")).isFalse(); result = mapper.readValue(jsondb.getAsString(""), HashMap.class); assertThat(result).hasSize(2); assertThat(jsondb.delete("/name")).isTrue(); result = mapper.readValue(jsondb.getAsString(""), HashMap.class); assertThat(result).hasSize(1); }
@Test public void testDelete() throws IOException { HashMap<String, Object> user = map( "name", "Joe", "developer", false ); jsondb.set("/", mapper.writeValueAsString(user)); Map<?, ?> result = mapper.readValue(jsondb.getAsString(""), HashMap.class); assertThat(result).hasSize(2); assertThat(jsondb.delete("/badpath")).isFalse(); result = mapper.readValue(jsondb.getAsString(""), HashMap.class); assertThat(result).hasSize(2); assertThat(jsondb.delete("/name")).isTrue(); result = mapper.readValue(jsondb.getAsString(""), HashMap.class); assertThat(result).hasSize(1); }
@Test public void testGetDepth1() throws IOException { jsondb.set("/test", mapper.writeValueAsString(map( "name", "Hiram Chirino", "props", map( "city", "Tampa", "state", "FL" ) ))); String json = jsondb.getAsString("/test", new GetOptions().depth(1)); assertThat(json).isEqualTo("{\"name\":\"Hiram Chirino\",\"props\":true}"); jsondb.delete("/test"); jsondb.set("/test/a1/b1/c1", "1"); jsondb.set("/test/a1/b2/c1", "2"); jsondb.set("/test/a2/b3/c1", "3"); jsondb.set("/test/a3/b4/c1", "4"); jsondb.set("/test/a4/b5/c1", "5"); json = jsondb.getAsString("/test", new GetOptions().depth(1)); assertThat(json).isEqualTo("{\"a1\":true,\"a2\":true,\"a3\":true,\"a4\":true}"); }
@Test public void testGetDepth1() throws IOException { jsondb.set("/test", mapper.writeValueAsString(map( "name", "Hiram Chirino", "props", map( "city", "Tampa", "state", "FL" ) ))); String json = jsondb.getAsString("/test", new GetOptions().depth(1)); assertThat(json).isEqualTo("{\"name\":\"Hiram Chirino\",\"props\":true}"); jsondb.delete("/test"); jsondb.set("/test/a1/b1/c1", "1"); jsondb.set("/test/a1/b2/c1", "2"); jsondb.set("/test/a2/b3/c1", "3"); jsondb.set("/test/a3/b4/c1", "4"); jsondb.set("/test/a4/b5/c1", "5"); json = jsondb.getAsString("/test", new GetOptions().depth(1)); assertThat(json).isEqualTo("{\"a1\":true,\"a2\":true,\"a3\":true,\"a4\":true}"); }