@Test public void testCreate() throws Exception { String path = "/"; String name = "roottest-create"; byte[] data = "foo".getBytes(); WebResource wr = znodesr.path(path).queryParam("dataformat", "utf8") .queryParam("name", name); Builder builder = wr.accept(MediaType.APPLICATION_JSON); ClientResponse cr; cr = builder.post(ClientResponse.class, data); Assert.assertEquals(ClientResponse.Status.CREATED, cr.getClientResponseStatus()); ZPath zpath = cr.getEntity(ZPath.class); Assert.assertEquals(new ZPath(path + name), zpath); Assert.assertEquals(znodesr.path(path).toString(), zpath.uri); // use out-of-band method to verify byte[] rdata = zk.getData(zpath.path, false, new Stat()); Assert.assertTrue(new String(rdata) + " == " + new String(data), Arrays.equals(rdata, data)); }
@Test public void testCreate() throws Exception { LOG.info("STARTING " + getName()); String path = "/"; String name = "roottest-create"; byte[] data = "foo".getBytes(); WebResource wr = znodesr.path(path).queryParam("dataformat", "utf8") .queryParam("name", name); Builder builder = wr.accept(MediaType.APPLICATION_JSON); ClientResponse cr; cr = builder.post(ClientResponse.class, data); assertEquals(ClientResponse.Status.CREATED, cr.getClientResponseStatus()); ZPath zpath = cr.getEntity(ZPath.class); assertEquals(new ZPath(path + name), zpath); assertEquals(znodesr.path(path).toString(), zpath.uri); // use out-of-band method to verify byte[] rdata = zk.getData(zpath.path, false, new Stat()); assertTrue(new String(rdata) + " == " + new String(data), Arrays.equals(rdata, data)); }
public JAXBContextResolver() throws Exception { Class[] typesArr = new Class[]{ZPath.class, ZStat.class, ZChildrenJSON.class}; typesSet = new HashSet<Class>(Arrays.asList(typesArr)); context = new JSONJAXBContext( JSONConfiguration.mapped() .arrays("children") .nonStrings("czxid") .nonStrings("mzxid") .nonStrings("ctime") .nonStrings("mtime") .nonStrings("version") .nonStrings("cversion") .nonStrings("aversion") .nonStrings("ephemeralOwner") .nonStrings("dataLength") .nonStrings("numChildren") .nonStrings("pzxid") .build(), typesArr); }
@Test public void testCreate() throws Exception { LOG.info("STARTING " + getName()); String path = "/"; String name = "roottest-create"; byte[] data = "foo".getBytes(); WebResource wr = r.path(path).queryParam("dataformat", "utf8") .queryParam("name", name); Builder builder = wr.accept(MediaType.APPLICATION_JSON); ClientResponse cr; cr = builder.post(ClientResponse.class, data); assertEquals(ClientResponse.Status.CREATED, cr.getClientResponseStatus()); ZPath zpath = cr.getEntity(ZPath.class); assertEquals(new ZPath(path + name), zpath); assertEquals(r.path(path).toString(), zpath.uri); // use out-of-band method to verify byte[] rdata = zk.getData(zpath.path, false, new Stat()); assertTrue(new String(rdata) + " == " + new String(data), Arrays.equals(rdata, data)); }
@Parameters public static Collection<Object[]> data() throws Exception { String baseZnode = Base.createBaseZNode(); return Arrays.asList(new Object[][] { {MediaType.APPLICATION_JSON, baseZnode, "foo bar", "utf8", ClientResponse.Status.CREATED, new ZPath(baseZnode + "/foo bar"), null, false }, {MediaType.APPLICATION_JSON, baseZnode, "c-t1", "utf8", ClientResponse.Status.CREATED, new ZPath(baseZnode + "/c-t1"), null, false }, {MediaType.APPLICATION_JSON, baseZnode, "c-t1", "utf8", ClientResponse.Status.CONFLICT, null, null, false }, {MediaType.APPLICATION_JSON, baseZnode, "c-t2", "utf8", ClientResponse.Status.CREATED, new ZPath(baseZnode + "/c-t2"), "".getBytes(), false }, {MediaType.APPLICATION_JSON, baseZnode, "c-t2", "utf8", ClientResponse.Status.CONFLICT, null, null, false }, {MediaType.APPLICATION_JSON, baseZnode, "c-t3", "utf8", ClientResponse.Status.CREATED, new ZPath(baseZnode + "/c-t3"), "foo".getBytes(), false }, {MediaType.APPLICATION_JSON, baseZnode, "c-t3", "utf8", ClientResponse.Status.CONFLICT, null, null, false }, {MediaType.APPLICATION_JSON, baseZnode, "c-t4", "base64", ClientResponse.Status.CREATED, new ZPath(baseZnode + "/c-t4"), "foo".getBytes(), false }, {MediaType.APPLICATION_JSON, baseZnode, "c-", "utf8", ClientResponse.Status.CREATED, new ZPath(baseZnode + "/c-"), null, true }, {MediaType.APPLICATION_JSON, baseZnode, "c-", "utf8", ClientResponse.Status.CREATED, new ZPath(baseZnode + "/c-"), null, true } }); }
public CreateTest(String accept, String path, String name, String encoding, ClientResponse.Status status, ZPath expectedPath, byte[] data, boolean sequence) { this.accept = accept; this.path = path; this.name = name; this.encoding = encoding; this.expectedStatus = status; this.expectedPath = expectedPath; this.data = data; this.sequence = sequence; }