use of com.yahoo.slime.Slime in project vespa by vespa-engine.
the class ServiceApiResponseTest method testServiceViewResponse.
@Test
public void testServiceViewResponse() throws URISyntaxException, IOException {
ServiceApiResponse response = new ServiceApiResponse(ZoneId.from(Environment.prod, RegionName.from("us-west-1")), ApplicationId.from("tenant1", "application1", "default"), Collections.singletonList(new URI("config-server1")), new URI("http://server1:4080/request/path?foo=bar"));
ApplicationView applicationView = new ApplicationView();
ClusterView clusterView = new ClusterView();
clusterView.type = "container";
clusterView.name = "cluster1";
clusterView.url = "cluster-url";
ServiceView serviceView = new ServiceView();
serviceView.url = null;
serviceView.serviceType = "container";
serviceView.serviceName = "service1";
serviceView.configId = "configId1";
serviceView.host = "host1";
serviceView.legacyStatusPages = "legacyPages";
clusterView.services = Collections.singletonList(serviceView);
applicationView.clusters = Collections.singletonList(clusterView);
response.setResponse(applicationView);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
response.render(stream);
Slime responseSlime = SlimeUtils.jsonToSlime(stream.toByteArray());
Slime expectedSlime = SlimeUtils.jsonToSlime(IOUtils.readFile(new File(responseFiles + "service-api-response.json")).getBytes(StandardCharsets.UTF_8));
assertEquals("service-api-response.json", new String(SlimeUtils.toJsonBytes(expectedSlime), StandardCharsets.UTF_8), new String(SlimeUtils.toJsonBytes(responseSlime), StandardCharsets.UTF_8));
}
use of com.yahoo.slime.Slime in project vespa by vespa-engine.
the class NodeSerializer method toJson.
public byte[] toJson(Node node) {
try {
Slime slime = new Slime();
toSlime(node, slime.setObject());
return SlimeUtils.toJsonBytes(slime);
} catch (IOException e) {
throw new RuntimeException("Serialization of " + node + " to json failed", e);
}
}
use of com.yahoo.slime.Slime in project vespa by vespa-engine.
the class DocsumDefinitionTestCase method makeDocsum.
public static byte[] makeDocsum() {
Slime slime = new Slime();
Cursor docsum = slime.setObject();
docsum.setString("TOPIC", "Arts/Celebrities/Madonna");
docsum.setString("TITLE", "StudyOfMadonna.com - Interviews, Articles, Reviews, Quotes, Essays and more..");
docsum.setString("DYNTEASER", "dynamic teaser");
docsum.setLong("EXTINFOSOURCE", 1);
docsum.setLong("LANG1", 10);
docsum.setLong("WORDS", 352);
docsum.setLong("BYTES", 9190);
byte[] tmp = BinaryFormat.encode(slime);
ByteBuffer buf = ByteBuffer.allocate(tmp.length + 4);
buf.order(ByteOrder.LITTLE_ENDIAN);
buf.putInt(DocsumDefinitionSet.SLIME_MAGIC_ID);
buf.order(ByteOrder.BIG_ENDIAN);
buf.put(tmp);
return buf.array();
}
use of com.yahoo.slime.Slime in project vespa by vespa-engine.
the class JsonRendererTestCase method testJsonObjects.
@Test
public void testJsonObjects() throws InterruptedException, ExecutionException, IOException, JSONException {
String expected = "{\n" + " \"root\": {\n" + " \"children\": [\n" + " {\n" + " \"fields\": {\n" + " \"inspectable\": {\n" + " \"a\": \"b\"\n" + " },\n" + " \"jackson\": {\n" + " \"Nineteen-eighty-four\": 1984\n" + " },\n" + " \"json producer\": {\n" + " \"long in structured\": 7809531904\n" + " },\n" + " \"org.json array\": [\n" + " true,\n" + " true,\n" + " false\n" + " ],\n" + " \"org.json object\": {\n" + " \"forty-two\": 42\n" + " }\n" + " },\n" + " \"id\": \"json objects\",\n" + " \"relevance\": 1.0\n" + " }\n" + " ],\n" + " \"fields\": {\n" + " \"totalCount\": 0\n" + " },\n" + " \"id\": \"toplevel\",\n" + " \"relevance\": 1.0\n" + " }\n" + "}\n";
Result r = newEmptyResult();
Hit h = new Hit("json objects");
JSONObject o = new JSONObject();
JSONArray a = new JSONArray();
ObjectMapper mapper = new ObjectMapper();
JsonNode j = mapper.createObjectNode();
JSONString s = new JSONString("{\"a\": \"b\"}");
Slime slime = new Slime();
Cursor c = slime.setObject();
c.setLong("long in structured", 7809531904L);
SlimeAdapter slimeInit = new SlimeAdapter(slime.get());
StructuredData struct = new StructuredData(slimeInit);
((ObjectNode) j).put("Nineteen-eighty-four", 1984);
o.put("forty-two", 42);
a.put(true);
a.put(true);
a.put(false);
h.setField("inspectable", s);
h.setField("jackson", j);
h.setField("json producer", struct);
h.setField("org.json array", a);
h.setField("org.json object", o);
r.hits().add(h);
String summary = render(r);
assertEqualJson(expected, summary);
}
use of com.yahoo.slime.Slime in project vespa by vespa-engine.
the class BinaryFormat method decode.
public static Predicate decode(byte[] buf) {
Objects.requireNonNull(buf, "buf");
Slime slime = com.yahoo.slime.BinaryFormat.decode(buf);
return decode(slime.get());
}
Aggregations