### Question:
Glue2Mapper { public QueryResult toQueryResult(JSONArray jo) throws JSONToGlue2MappingException { eu.eu_emi.emiregistry.ObjectFactory o = new eu.eu_emi.emiregistry.ObjectFactory(); QueryResult qr = o.createQueryResult(); List<ServiceT> l = qr.getService(); JAXBElement<ServiceT>[] j = toGlue2Service(jo); if (j.length == 0) { return qr; } int size = j.length; try { JSONObject ref = jo.getJSONObject(jo.length() - 1); if (!ref.isNull("ref")) { qr.setRef(ref.getString("ref")); size = j.length - 1; } } catch (JSONException e) { throw new JSONToGlue2MappingException(e); } for (int i = 0; i < size; i++) { l.add(j[i].getValue()); } qr.setCount(new BigInteger("" + (size))); return qr; } Glue2Mapper(); QueryResult toQueryResult(JSONArray jo); JAXBElement<ServiceT>[] toGlue2Service(JSONArray jo); JAXBElement<ServiceT> toGlue2XML(JSONObject jo);  }### Answer:
@Test public void testToQueryResultMultipleXML() throws Exception { Glue2Mapper gm = new Glue2Mapper(); JSONArray ja = new JSONArray(); ja.put(jo); ja.put(jo); QueryResult qr = gm.toQueryResult(ja); assertNotNull(qr.getService().get(0).getName()); assertEquals(new BigInteger("" + 2), qr.getCount()); StringWriter sw = new StringWriter(); JAXB.marshal(qr, sw); System.out.println(sw); }
@Test public void testExtensions() throws JSONException, DatatypeConfigurationException, ParseException, JSONToGlue2MappingException { Glue2Mapper gm = new Glue2Mapper(); JSONArray ja = new JSONArray(); jo.put("myextension1", "value1"); jo.put("myextension2", "value2"); ja.put(jo); QueryResult qr = gm.toQueryResult(ja); assertNotNull(qr.getService().get(0).getName()); assertEquals("myextension1", qr.getService().get(0).getExtensions().getExtension().get(0).getKey()); StringWriter sw = new StringWriter(); JAXB.marshal(qr, sw); System.out.println(sw); }
@Test public void testIfWrongArray() throws JSONToGlue2MappingException, JSONException{ Glue2Mapper gm = new Glue2Mapper(); JSONArray ja = new JSONArray(); ja.put(jo); jo.put(ServiceBasicAttributeNames.SERVICE_ENDPOINT_URL.toString(), "http: jo.put(ServiceBasicAttributeNames.SERVICE_ENDPOINT_CAPABILITY.toString(), "cap1"); jo.put("1", "1"); jo.put("2", "2"); JSONObject j = TestValueConstants.getJSONWithMandatoryAttributes(); ja.put(j); QueryResult qr = gm.toQueryResult(ja); assertNotNull(qr.getService().get(0).getName()); assertEquals(new BigInteger("" + 2), qr.getCount()); StringWriter sw = new StringWriter(); JAXB.marshal(qr, sw); System.out.println(sw); }