@Test public void testGet() throws Exception { LOG.info("STARTING " + getName()); if (expectedStat != null) { if (expectedStat.data64 != null || expectedStat.dataUtf8 == null) { zk.setData(expectedStat.path, expectedStat.data64, -1); } else { zk.setData(expectedStat.path, expectedStat.dataUtf8.getBytes(), -1); } } ClientResponse cr = znodesr.path(path).queryParam("dataformat", encoding) .accept(accept).get(ClientResponse.class); assertEquals(expectedStatus, cr.getClientResponseStatus()); if (expectedStat == null) { return; } ZStat zstat = cr.getEntity(ZStat.class); assertEquals(expectedStat, zstat); assertEquals(znodesr.path(path).toString(), zstat.uri); }
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 testGet() throws Exception { if (expectedStat != null) { if (expectedStat.data64 != null || expectedStat.dataUtf8 == null) { zk.setData(expectedStat.path, expectedStat.data64, -1); } else { zk.setData(expectedStat.path, expectedStat.dataUtf8.getBytes(), -1); } } ClientResponse cr = znodesr.path(path).queryParam("dataformat", encoding) .accept(accept).get(ClientResponse.class); Assert.assertEquals(expectedStatus, cr.getClientResponseStatus()); if (expectedStat == null) { return; } ZStat zstat = cr.getEntity(ZStat.class); Assert.assertEquals(expectedStat, zstat); Assert.assertEquals(znodesr.path(path).toString(), zstat.uri); }
@Test public void testGet() throws Exception { LOG.info("STARTING " + getName()); if (expectedStat != null) { if (expectedStat.data64 != null || expectedStat.dataUtf8 == null) { zk.setData(expectedStat.path, expectedStat.data64, -1); } else { zk.setData(expectedStat.path, expectedStat.dataUtf8.getBytes(), -1); } } ClientResponse cr = r.path(path).queryParam("dataformat", encoding) .accept(accept).get(ClientResponse.class); assertEquals(expectedStatus, cr.getClientResponseStatus()); if (expectedStat == null) { return; } ZStat zstat = cr.getEntity(ZStat.class); assertEquals(expectedStat, zstat); assertEquals(r.path(path).toString(), zstat.uri); }
@PUT @Produces( { MediaType.APPLICATION_JSON, "application/javascript", MediaType.APPLICATION_XML }) @Consumes(MediaType.APPLICATION_OCTET_STREAM) public Response setZNode( @PathParam("path") String path, @QueryParam("callback") String callback, @DefaultValue("-1") @QueryParam("version") String versionParam, @DefaultValue("base64") @QueryParam("dataformat") String dataformat, @DefaultValue("false") @QueryParam("null") String setNull, @Context UriInfo ui, byte[] data) throws InterruptedException, KeeperException { ensurePathNotNull(path); int version; try { version = Integer.parseInt(versionParam); } catch (NumberFormatException e) { throw new WebApplicationException(Response.status( Response.Status.BAD_REQUEST).entity( new ZError(ui.getRequestUri().toString(), path + " bad version " + versionParam)).build()); } if (setNull.equals("true")) { data = null; } Stat stat = zk.setData(path, data, version); ZStat zstat = new ZStat(path, ui.getAbsolutePath().toString(), null, null, stat.getCzxid(), stat.getMzxid(), stat.getCtime(), stat .getMtime(), stat.getVersion(), stat.getCversion(), stat.getAversion(), stat.getEphemeralOwner(), stat .getDataLength(), stat.getNumChildren(), stat .getPzxid()); return Response.status(Response.Status.OK).entity( new JSONWithPadding(zstat, callback)).build(); }
@Parameters public static Collection<Object[]> data() throws Exception { String baseZnode = Base.createBaseZNode(); return Arrays.asList(new Object[][] { {MediaType.APPLICATION_JSON, baseZnode + "/s-t1", "utf8", ClientResponse.Status.OK, new ZStat(baseZnode + "/s-t1", null, null), null }, {MediaType.APPLICATION_JSON, baseZnode + "/s-t2", "utf8", ClientResponse.Status.OK, new ZStat(baseZnode + "/s-t2", null, null), new byte[0] }, {MediaType.APPLICATION_JSON, baseZnode + "/s-t3", "utf8", ClientResponse.Status.OK, new ZStat(baseZnode + "/s-t3", null, null), "foobar".getBytes() }, {MediaType.APPLICATION_JSON, baseZnode + "/s-t4", "base64", ClientResponse.Status.OK, new ZStat(baseZnode + "/s-t4", null, null), null }, {MediaType.APPLICATION_JSON, baseZnode + "/s-t5", "base64", ClientResponse.Status.OK, new ZStat(baseZnode + "/s-t5", null, null), new byte[0] }, {MediaType.APPLICATION_JSON, baseZnode + "/s-t6", "base64", ClientResponse.Status.OK, new ZStat(baseZnode + "/s-t6", null, null), "foobar".getBytes() }, {MediaType.APPLICATION_JSON, baseZnode + "/dkdkdkd", "utf8", ClientResponse.Status.NOT_FOUND, null, null }, {MediaType.APPLICATION_JSON, baseZnode + "/dkdkdkd", "base64", ClientResponse.Status.NOT_FOUND, null, null }, }); }
public SetTest(String accept, String path, String encoding, ClientResponse.Status status, ZStat expectedStat, byte[] data) { this.accept = accept; this.path = path; this.encoding = encoding; this.expectedStatus = status; this.expectedStat = expectedStat; this.data = data; }
@Parameters public static Collection<Object[]> data() throws Exception { String baseZnode = Base.createBaseZNode(); return Arrays.asList(new Object[][] { {MediaType.APPLICATION_JSON, baseZnode, "utf8", ClientResponse.Status.OK, new ZStat(baseZnode, null, null) }, {MediaType.APPLICATION_JSON, baseZnode, "utf8", ClientResponse.Status.OK, new ZStat(baseZnode, null, "") }, {MediaType.APPLICATION_JSON, baseZnode, "utf8", ClientResponse.Status.OK, new ZStat(baseZnode, null, "foo") }, {MediaType.APPLICATION_JSON, baseZnode, "base64", ClientResponse.Status.OK, new ZStat(baseZnode, null, null) }, {MediaType.APPLICATION_JSON, baseZnode, "base64", ClientResponse.Status.OK, new ZStat(baseZnode, "".getBytes(), null) }, {MediaType.APPLICATION_JSON, baseZnode, "base64", ClientResponse.Status.OK, new ZStat(baseZnode, "".getBytes(), null) }, {MediaType.APPLICATION_JSON, baseZnode, "base64", ClientResponse.Status.OK, new ZStat(baseZnode, "foo".getBytes(), null) }, {MediaType.APPLICATION_JSON, baseZnode + "abaddkdk", "utf8", ClientResponse.Status.NOT_FOUND, null }, {MediaType.APPLICATION_JSON, baseZnode + "abaddkdk", "base64", ClientResponse.Status.NOT_FOUND, null }, {MediaType.APPLICATION_XML, baseZnode, "utf8", ClientResponse.Status.OK, new ZStat(baseZnode, null, "foo") }, {MediaType.APPLICATION_XML, baseZnode, "base64", ClientResponse.Status.OK, new ZStat(baseZnode, "foo".getBytes(), null) }, {MediaType.APPLICATION_XML, baseZnode + "abaddkdk", "utf8", ClientResponse.Status.NOT_FOUND, null }, {MediaType.APPLICATION_XML, baseZnode + "abaddkdk", "base64", ClientResponse.Status.NOT_FOUND, null } }); }
public GetTest(String accept, String path, String encoding, ClientResponse.Status status, ZStat stat) { this.accept = accept; this.path = path; this.encoding = encoding; this.expectedStatus = status; this.expectedStat = stat; }