use of aQute.lib.json.JSONCodec in project bnd by bndtools.
the class PersistentResourceTest method testSimple.
public void testSimple() throws Exception {
ResourceBuilder rb = new ResourceBuilder();
rb.addCapability(new CapReqBuilder("test").addAttribute("double", 3.0).addAttribute("long", 3L).addAttribute("string", "3.0").addAttribute("version", new Version("3.0")).buildSyntheticCapability());
Resource r = rb.build();
PersistentResource pr = new PersistentResource(r);
String s = new JSONCodec().enc().put(pr).toString();
PersistentResource pr2 = new JSONCodec().dec().from(s).get(PersistentResource.class);
List<Capability> capabilities = pr.getResource().getCapabilities(null);
List<Requirement> requirements = pr.getResource().getRequirements(null);
assertEquals(1, capabilities.size());
assertEquals(0, requirements.size());
Capability capability = capabilities.get(0);
assertEquals("test", capability.getNamespace());
assertEquals(3.0, capability.getAttributes().get("double"));
assertEquals(3L, capability.getAttributes().get("long"));
assertEquals("3.0", capability.getAttributes().get("string"));
assertEquals(new Version("3.0"), capability.getAttributes().get("version"));
assertEquals(0, capability.getDirectives().size());
}
use of aQute.lib.json.JSONCodec in project bnd by bndtools.
the class HttpTestServerTest method get.
private <T> T get(HttpTestServer http, TypeReference<T> tref, String path) throws Exception {
URL uri = new URI(http.getBaseURI() + path).toURL();
HttpURLConnection connection = (HttpURLConnection) uri.openConnection();
String collect = IO.collect(connection.getInputStream());
return new JSONCodec().dec().from(collect).get(tref);
}
Aggregations