@Test public void postGroupAsXmlPartial_shouldEnforcePipelineGroupAdminPermissionsForPipelineTemplates() throws Exception { String md5 = setUpPipelineGroupsWithAdminPermissions(); ConfigElementImplementationRegistry registry = ConfigElementImplementationRegistryMother.withNoPlugins(); XmlUtils.validate( new FileInputStream(configHelper.getConfigFile()), GoConfigSchema.getCurrentSchema(), new XsdErrorTranslator(), new SAXBuilder(), registry.xsds()); controller.postGroupAsXmlPartial( TemplatesConfig.PIPELINE_TEMPLATES_FAKE_GROUP_NAME, NEW_TEMPLATES, md5, response); assertThat(response.getStatus(), is(SC_UNAUTHORIZED)); XmlUtils.validate( new FileInputStream(configHelper.getConfigFile()), GoConfigSchema.getCurrentSchema(), new XsdErrorTranslator(), new SAXBuilder(), registry.xsds()); setCurrentUser("admin"); controller.postGroupAsXmlPartial( TemplatesConfig.PIPELINE_TEMPLATES_FAKE_GROUP_NAME, NEW_TEMPLATES, md5, response); assertThat(response.getStatus(), is(SC_OK)); }
/** * Create an Archival Unit * * @return true If successful */ private boolean createAu() { Configuration config = getAuConfigFromForm(); AuProxy au; Element element; try { au = getRemoteApi().createAndSaveAuConfiguration(getPlugin(), config); } catch (ArchivalUnit.ConfigurationException exception) { return error("Configuration failed: " + exception.getMessage()); } catch (IOException exception) { return error("Unable to save configuration: " + exception.getMessage()); } /* * Successful creation - add the AU name and ID to the response document */ element = getXmlUtils().createElement(getResponseRoot(), AP_E_AU); XmlUtils.addText(element, au.getName()); element = getXmlUtils().createElement(getResponseRoot(), AP_E_AUID); XmlUtils.addText(element, au.getAuId()); return true; }
public static int getIndexClosingTag(String tag, String text, int start) { String open = "<" + tag; String close = "</" + tag + ">"; // System.err.println("OPEN: "+open); // System.err.println("CLOSE: "+close); int closeSz = close.length(); int nextCloseIdx = text.indexOf(close, start); // System.err.println("first close: "+nextCloseIdx); if (nextCloseIdx == -1) { return -1; } int count = XmlUtils.countMatches(text.substring(start, nextCloseIdx), open); // System.err.println("count: "+count); if (count == 0) { return -1; // tag is never opened } int expected = 1; while (count != expected) { nextCloseIdx = text.indexOf(close, nextCloseIdx + closeSz); if (nextCloseIdx == -1) { return -1; } count = XmlUtils.countMatches(text.substring(start, nextCloseIdx), open); expected++; } return nextCloseIdx; }
public void testParseDocument() throws Exception { String xml = "" + "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n" + " android:layout_width=\"match_parent\"\n" + " android:layout_height=\"wrap_content\"\n" + " android:orientation=\"vertical\" >\n" + "\n" + " <Button\n" + " android:id=\"@+id/button1\"\n" + " android:layout_width=\"wrap_content\"\n" + " android:layout_height=\"wrap_content\"\n" + " android:text=\"Button\" />\n" + " some text\n" + "\n" + "</LinearLayout>\n"; Document document = XmlUtils.parseDocument(xml, true); assertNotNull(document); assertNotNull(document.getDocumentElement()); assertEquals("LinearLayout", document.getDocumentElement().getTagName()); // Add BOM xml = '\uFEFF' + xml; document = XmlUtils.parseDocument(xml, true); assertNotNull(document); assertNotNull(document.getDocumentElement()); assertEquals("LinearLayout", document.getDocumentElement().getTagName()); }
private ViewDefinition readViewDefinition(Element element) { String name = element.getAttribute("name"); Assert.ifEmpty(name, "can`t read view without name"); String extend = element.getAttribute("extend"); String file = element.getAttribute("file"); if (isNoneEmpty(file)) file = fileScope.getRelativePath(file); ViewDefinition viewDef = new ViewDefinition(name, file); viewDef.setExtend(extend); fragmentRefExpressions.forEach( x -> { XmlUtils.iterateSubElements( element, x, e -> viewDef.addFragment(readFragmentReference(e))); }); resourcesRefExpressions.forEach( x -> { XmlUtils.iterateSubElements( element, x, e -> viewDef.addResources(readResourcesReference(e))); }); return viewDef; }
private SoapVersion11() { try { XmlOptions options = new XmlOptions(); options.setCompileNoValidation(); options.setCompileNoPvrRule(); options.setCompileDownloadUrls(); options.setCompileNoUpaRule(); options.setValidateTreatLaxAsSkip(); URL soapSchemaXmlResource = ResourceUtils.getResourceWithAbsolutePackagePath( getClass(), "/xsds/", "soapEnvelope.xsd"); soapSchemaXml = XmlUtils.createXmlObject(soapSchemaXmlResource, options); soapSchema = XmlBeans.loadXsd(new XmlObject[] {soapSchemaXml}); soapEnvelopeType = soapSchema.findDocumentType(envelopeQName); soapFaultType = soapSchema.findDocumentType(faultQName); URL soapEncodingXmlResource = ResourceUtils.getResourceWithAbsolutePackagePath( getClass(), "/xsds/", "soapEncoding.xsd"); soapEncodingXml = XmlUtils.createXmlObject(soapEncodingXmlResource, options); } catch (XmlException ex) { throw new SoapBuilderException(ex); } }
public static String getContent(String tag, String text) { int idx = XmlUtils.getIndexOpeningTag(tag, text); if (idx == -1) { return ""; } text = text.substring(idx); int end = XmlUtils.getIndexClosingTag(tag, text); idx = text.indexOf('>'); if (idx == -1) { return ""; } return text.substring(idx + 1, end); }
private void readFragmentInnerContent(Element element, FragmentDef fragmentDef) { fragmentRefExpressions.forEach( x -> { XmlUtils.iterateSubElements( element, x, e -> fragmentDef.addInnerFragment(readFragmentReference(e))); }); resourcesRefExpressions.forEach( x -> { XmlUtils.iterateSubElements( element, x, e -> fragmentDef.addResources(readResourcesReference(e))); }); }
@Test(groups = {"webserviceSmoke"}) public void testRequisitionStatusUsingCommTrackUserForExportOrderFlagFalse() throws IOException, SQLException, ParserConfigurationException, SAXException { HttpClient client = new HttpClient(); client.createContext(); submitRnRThroughApi("V10", "HIV", "P10", 1, 10, 1, 0, 0, 2); Long id = (long) dbWrapper.getMaxRnrID(); ResponseEntity responseEntity = client.SendJSON("", URL + "recent", "GET", "", ""); assertEquals(200, responseEntity.getStatus()); assertEquals(StringUtils.countMatches(responseEntity.getResponse(), ":"), 41); List<String> feedJSONList = XmlUtils.getNodeValues(responseEntity.getResponse(), "content"); checkRequisitionStatusOnFeed("INITIATED", feedJSONList.get(0), id); checkRequisitionStatusOnFeed("SUBMITTED", feedJSONList.get(1), id); checkRequisitionStatusOnFeed("AUTHORIZED", feedJSONList.get(2), id); dbWrapper.setExportOrdersFlagInSupplyLinesTable(false, "F10"); approveRequisition(id, 65); dbWrapper.updateRestrictLogin("commTrack", false); convertToOrder("commTrack", "Admin123"); dbWrapper.updateRestrictLogin("commTrack", true); responseEntity = client.SendJSON("", URL + "1", "GET", "", ""); assertEquals(200, responseEntity.getStatus()); feedJSONList = XmlUtils.getNodeValues(responseEntity.getResponse(), "content"); checkRequisitionStatusOnFeed("APPROVED", feedJSONList.get(3), id); checkRequisitionStatusOnFeed("RELEASED", feedJSONList.get(4), id); responseEntity = client.SendJSON("", URL + "recent", "GET", "", ""); assertEquals(200, responseEntity.getStatus()); feedJSONList = XmlUtils.getNodeValues(responseEntity.getResponse(), "content"); checkOrderStatusOnFeed("READY_TO_PACK", feedJSONList.get(0), id); dbWrapper.assignRight("store in-charge", "MANAGE_POD"); OrderPOD OrderPODFromJson = JsonUtility.readObjectFromFile(FULL_JSON_POD_TXT_FILE_NAME, OrderPOD.class); OrderPODFromJson.getPodLineItems().get(0).setQuantityReceived(65); OrderPODFromJson.getPodLineItems().get(0).setProductCode("P10"); client.SendJSON( getJsonStringFor(OrderPODFromJson), format(POD_URL, id), "POST", "commTrack", "Admin123"); responseEntity = client.SendJSON("", URL + "recent", "GET", "", ""); assertEquals(200, responseEntity.getStatus()); feedJSONList = XmlUtils.getNodeValues(responseEntity.getResponse(), "content"); checkOrderStatusOnFeed("RECEIVED", feedJSONList.get(1), id); }
public void testFormatFloatValue() throws Exception { assertEquals("1", XmlUtils.formatFloatAttribute(1.0f)); assertEquals("2", XmlUtils.formatFloatAttribute(2.0f)); assertEquals("1.50", XmlUtils.formatFloatAttribute(1.5f)); assertEquals("1.50", XmlUtils.formatFloatAttribute(1.50f)); assertEquals("1.51", XmlUtils.formatFloatAttribute(1.51f)); assertEquals("1.51", XmlUtils.formatFloatAttribute(1.514542f)); assertEquals("1.52", XmlUtils.formatFloatAttribute(1.516542f)); assertEquals("-1.51", XmlUtils.formatFloatAttribute(-1.51f)); assertEquals("-1", XmlUtils.formatFloatAttribute(-1f)); }
public void testFromXmlAttributeValue() throws Exception { assertEquals("", XmlUtils.fromXmlAttributeValue("")); assertEquals("foo", XmlUtils.fromXmlAttributeValue("foo")); assertEquals("foo<bar", XmlUtils.fromXmlAttributeValue("foo<bar")); assertEquals("foo<bar<bar>foo", XmlUtils.fromXmlAttributeValue("foo<bar<bar>foo")); assertEquals("foo>bar", XmlUtils.fromXmlAttributeValue("foo>bar")); assertEquals("\"", XmlUtils.fromXmlAttributeValue(""")); assertEquals("'", XmlUtils.fromXmlAttributeValue("'")); assertEquals("foo\"b''ar", XmlUtils.fromXmlAttributeValue("foo"b''ar")); assertEquals("<\"'>&", XmlUtils.fromXmlAttributeValue("<"'>&")); }
public RegistrationData GetRegistrationDetail(String registrationId) throws Exception { ServiceRequest sr = new ServiceRequest(configuration); sr.getParameters().add("regid", registrationId); Document xmlDoc = sr.callService("rustici.registration.getRegistrationDetail"); return RegistrationData.parseFromXmlElement( XmlUtils.getFirstChildByTagName(xmlDoc.getDocumentElement(), "registration")); }
@Test public void testPersonListFormEmptyElement() { // XStream xstream = new XStream(new DomDriver()); XStream xstream = new XStream(); xstream.processAnnotations(TestPersonAnnotationList.class); xstream.processAnnotations(TestPersonAnnotation.class); xstream.processAnnotations(TestPerson.class); // xstream.registerConverter(new EmptyTestPersonAnnotationConverter()); TestPersonAnnotation hh = new TestPersonAnnotation(); hh.setUserName("hanhan"); hh.setAge(30); TestPerson parent = new TestPerson(); // parent.setAge(11); hh.setParent(null); TestPersonAnnotationList list = new TestPersonAnnotationList(); list.list.add(hh); String xmlStr = xstream.toXML(list); /*StringWriter sw = new StringWriter(); PrettyPrintWriter writer = new CompactWriter(sw); xstream.marshal(list, writer); String xmlStr = sw.toString();*/ System.out.println("testPersonListFormEmptyElement xml:\n " + xmlStr); xmlStr = XmlUtils.toXML( Lists.newArrayList(hh), "list", ArrayList.class, "person", TestPersonAnnotation.class); System.out.println("testPersonListFormEmptyElement xml22:\n " + xmlStr); }
public void testToXml6() throws Exception { // Check CDATA String xml = "" + "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<resources>\n" + " <string \n" + " name=\"description_search\">Search</string>\n" + " <string name=\"map_at\">At %1$s:<![CDATA[<br><b>%2$s</b>]]></string>\n" + " <string name=\"map_now_playing\">Now playing:\n" + "<![CDATA[\n" + "<br><b>%1$s</b>\n" + "]]></string>\n" + "</resources>"; Document doc = parse(xml); String formatted = XmlUtils.toXml(doc, true); assertEquals( "" + "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<resources>\n" + " <string name=\"description_search\">Search</string>\n" + " <string name=\"map_at\">At %1$s:<![CDATA[<br><b>%2$s</b>]]></string>\n" + " <string name=\"map_now_playing\">Now playing:\n" + "<![CDATA[\n" + "<br><b>%1$s</b>\n" + "]]></string>\n" + "</resources>", formatted); }
public void testToXml2() throws Exception { String xml = "" + "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<resources>\n" + " <string \n" + " name=\"description_search\">Search</string>\n" + " <string \n" + " name=\"description_map\">Map</string>\n" + " <string\n" + " name=\"description_refresh\">Refresh</string>\n" + " <string \n" + " name=\"description_share\">Share</string>\n" + "</resources>"; Document doc = parse(xml); String formatted = XmlUtils.toXml(doc, true); assertEquals( "" + "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<resources>\n" + " <string name=\"description_search\">Search</string>\n" + " <string name=\"description_map\">Map</string>\n" + " <string name=\"description_refresh\">Refresh</string>\n" + " <string name=\"description_share\">Share</string>\n" + "</resources>", formatted); }
public String toXml(String indent) { XMLStringBuffer xsb = new XMLStringBuffer(indent); Properties prop = new Properties(); prop.setProperty("name", getName()); boolean hasMethods = !m_includedMethods.isEmpty() || !m_excludedMethods.isEmpty(); boolean hasParameters = !m_parameters.isEmpty(); if (hasParameters || hasMethods) { xsb.push("class", prop); XmlUtils.dumpParameters(xsb, m_parameters); if (hasMethods) { xsb.push("methods"); for (XmlInclude m : getIncludedMethods()) { xsb.getStringBuffer().append(m.toXml(indent + " ")); } for (String m : getExcludedMethods()) { Properties p = new Properties(); p.setProperty("name", m); xsb.addEmptyElement("exclude", p); } xsb.pop("methods"); } xsb.pop("class"); } else { xsb.addEmptyElement("class", prop); } return xsb.toXML(); }
public void testHasChildren() throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); factory.setValidating(false); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.newDocument(); assertFalse(XmlUtils.hasElementChildren(document)); document.appendChild(document.createElement("A")); Element a = document.getDocumentElement(); assertFalse(XmlUtils.hasElementChildren(a)); a.appendChild(document.createTextNode("foo")); assertFalse(XmlUtils.hasElementChildren(a)); Element b = document.createElement("B"); a.appendChild(b); assertTrue(XmlUtils.hasElementChildren(a)); assertFalse(XmlUtils.hasElementChildren(b)); }
@Test public void testPerson() { TestPerson hh = new TestPerson(); hh.setUserName("hanhan"); hh.setAge(30); TestPerson parent = new TestPerson(); parent.setUserName("hanrenjun"); parent.setAge(60); hh.setParent(parent); String xmlStr = XmlUtils.toXML(hh, "person", TestPerson.class).trim(); System.out.println("testPerson xml:\n " + xmlStr); TestPerson newHH = XmlUtils.toBean(xmlStr, "person", TestPerson.class); Assert.assertEquals(hh.getUserName(), newHH.getUserName()); }
public static Iq parse(XmlPullParser parser) throws XmlPullParserException, java.io.IOException { Iq iq = new Iq(); iq.parseStanza(parser); while (parser.next() == XmlPullParser.START_TAG) { final String xmlns = parser.getNamespace(); if (xmlns != null) { ChildElement child = Stanza.parseChild(xmlns, parser); if (child != null) { iq.addChild(child); } else { XmlUtils.skip(parser); } } else { XmlUtils.skip(parser); } } return iq; }
// Depth first public void walkJAXBElements(Object parent) { List children = getChildren(parent); if (children != null) { for (Object o : children) { // if its wrapped in javax.xml.bind.JAXBElement, get its // value; this is ok, provided the results of the Callback // won't be marshalled o = XmlUtils.unwrap(o); // workaround for broken getParent (since 3.0.0) if (o instanceof Child) { if (parent instanceof SdtBlock) { ((Child) o).setParent(((SdtBlock) parent).getSdtContent()); /* * getParent on eg a P in a SdtBlock should return SdtContentBlock, as * illustrated by the following code: * SdtBlock sdtBloc = Context.getWmlObjectFactory().createSdtBlock(); SdtContentBlock sdtContentBloc = Context.getWmlObjectFactory().createSdtContentBlock(); sdtBloc.setSdtContent(sdtContentBloc); P p = Context.getWmlObjectFactory().createP(); sdtContentBloc.getContent().add(p); String result = XmlUtils.marshaltoString(sdtBloc, true); System.out.println(result); SdtBlock rtp = (SdtBlock)XmlUtils.unmarshalString(result, Context.jc, SdtBlock.class); P rtr = (P)rtp.getSdtContent().getContent().get(0); System.out.println(rtr.getParent().getClass().getName() ); * * Similarly, P is the parent of R; the p.getContent() list is not the parent * P p = Context.getWmlObjectFactory().createP(); R r = Context.getWmlObjectFactory().createR(); p.getContent().add(r); String result = XmlUtils.marshaltoString(p, true); P rtp = (P)XmlUtils.unmarshalString(result); R rtr = (R)rtp.getContent().get(0); System.out.println(rtr.getParent().getClass().getName() ); */ // TODO: other corrections } else { ((Child) o).setParent(parent); } } this.apply(o); if (this.shouldTraverse(o)) { walkJAXBElements(o); } } } }
@Test public void testRead() { String xmlFile = System.getProperty("user.dir") + "/config.xml"; try { String text = XmlUtils.getNodeText(xmlFile, "iqq/version"); System.out.println(text); Assert.assertNotNull(text); } catch (DocumentException e) { e.printStackTrace(); } }
private ResponseEntity waitForOrderStatusUpdatedOrTimeOut(int index) throws ParserConfigurationException, SAXException, InterruptedException { HttpClient client = new HttpClient(); client.createContext(); ResponseEntity responseEntity; responseEntity = client.SendJSON("", URL + "recent", "GET", "", ""); List<String> feedJSONList = XmlUtils.getNodeValues(responseEntity.getResponse(), "content"); int time = 0; while (time <= 5000) { if (feedJSONList.size() == index + 1) { break; } responseEntity = client.SendJSON("", URL + "recent", "GET", "", ""); feedJSONList = XmlUtils.getNodeValues(responseEntity.getResponse(), "content"); time += 500; Thread.sleep(500); } return responseEntity; }
@Test public void test2Bean() { String path = this.getClass().getResource("test.xml").getFile(); System.out.println("path: " + path); String xml = FileUtils.readAsString(path); System.out.println("xml: " + xml); TestPerson person = XmlUtils.toBean(xml, "person", TestPerson.class); // System.out.println("person:" + LangUtils.toString(person)); Assert.assertEquals(30, person.getAge()); path = this.getClass().getResource("test_list.xml").getFile(); System.out.println("path: " + path); xml = FileUtils.readAsString(path); System.out.println("xml: " + xml); Collection<TestPerson> list = XmlUtils.toBean(xml, "personlist", List.class, "person", TestPerson.class); // System.out.println("person:" + LangUtils.toString(person)); Assert.assertEquals(30, list.iterator().next().getAge()); }
public void testlookupNamespacePrefix() throws Exception { // Setup DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); factory.setValidating(false); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.newDocument(); Element rootElement = document.createElement("root"); Attr attr = document.createAttributeNS(SdkConstants.XMLNS_URI, "xmlns:customPrefix"); attr.setValue(SdkConstants.ANDROID_URI); rootElement.getAttributes().setNamedItemNS(attr); document.appendChild(rootElement); Element root = document.getDocumentElement(); root.appendChild(document.createTextNode(" ")); Element foo = document.createElement("foo"); root.appendChild(foo); root.appendChild(document.createTextNode(" ")); Element bar = document.createElement("bar"); root.appendChild(bar); Element baz = document.createElement("baz"); root.appendChild(baz); String prefix = XmlUtils.lookupNamespacePrefix(baz, SdkConstants.ANDROID_URI); assertEquals("customPrefix", prefix); prefix = XmlUtils.lookupNamespacePrefix(baz, "http://schemas.android.com/tools", "tools", false); assertEquals("tools", prefix); prefix = XmlUtils.lookupNamespacePrefix( baz, "http://schemas.android.com/apk/res/my/pkg", "app", false); assertEquals("app", prefix); assertFalse(declaresNamespace(document, "http://schemas.android.com/apk/res/my/pkg")); prefix = XmlUtils.lookupNamespacePrefix( baz, "http://schemas.android.com/apk/res/my/pkg", "app", true /*create*/); assertEquals("app", prefix); assertTrue(declaresNamespace(document, "http://schemas.android.com/apk/res/my/pkg")); }
public void testToXml5() throws Exception { String xml = "" + "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<root>\n" + " <!-- <&'>\" -->\n" + "</root>"; Document doc = parse(xml); String formatted = XmlUtils.toXml(doc, true); assertEquals(xml, formatted); }
public Document getXmlDocument() { Document doc = XmlUtils.createDom("jobSize"); Element jobSizeElm = doc.getDocumentElement(); addElementData(size, jobSizeElm); // for debugging only // if (!XmlValidator.validate(doc, XmlValidator.JOBSIZE_SCHEMA_URL)) { // logger.error("INVALID XML:\n" + XmlUtils.DOMToString(doc)); // } return doc; }
public PageManifestDef read(FileScope fileScope, Document document, PageManifestDef pmd) throws XPathExpressionException { this.fileScope = fileScope; XmlUtils.iterateSubElements( document, resourcesExpr, e -> pmd.addResourceSet(readResourcesDefinition(e))); XmlUtils.iterateSubElements( document, fragmentsExpr, e -> pmd.addFragments(readFragmentDefinition(e))); XmlUtils.iterateSubElements(document, viewsExpr, e -> pmd.addView(readViewDefinition(e))); List<String> imports = XmlUtils.getSingleAttrNodes( document, importsExpr, "file", "import tag must contain file attribute"); imports .stream() .forEach( i -> XMLPageManifestLoader.this.readPageDefinitionFile( fileScope.getRelativePath(i), pmd)); return pmd; }
@Test(groups = {"webservice"}) public void testRequisitionStatusUsingCommTrackUserForExportOrderFlagTrueAndFtpDetailsValid() throws IOException, SQLException, ParserConfigurationException, SAXException, InterruptedException { HttpClient client = new HttpClient(); client.createContext(); submitRnRThroughApi("V10", "HIV", "P10", 1, 10, 1, 0, 0, 2); Long id = (long) dbWrapper.getMaxRnrID(); ResponseEntity responseEntity = client.SendJSON("", URL + "recent", "GET", "", ""); assertEquals(200, responseEntity.getStatus()); List<String> feedJSONList = XmlUtils.getNodeValues(responseEntity.getResponse(), "content"); checkRequisitionStatusOnFeed("INITIATED", feedJSONList.get(0), id); checkRequisitionStatusOnFeed("SUBMITTED", feedJSONList.get(1), id); checkRequisitionStatusOnFeed("AUTHORIZED", feedJSONList.get(2), id); dbWrapper.setExportOrdersFlagInSupplyLinesTable(true, "F10"); dbWrapper.enterValidDetailsInFacilityFtpDetailsTable("F10"); approveRequisition(id, 65); dbWrapper.updateRestrictLogin("commTrack", false); convertToOrder("commTrack", "Admin123"); dbWrapper.updateRestrictLogin("commTrack", true); responseEntity = client.SendJSON("", URL + "1", "GET", "", ""); assertEquals(200, responseEntity.getStatus()); feedJSONList = XmlUtils.getNodeValues(responseEntity.getResponse(), "content"); checkRequisitionStatusOnFeed("APPROVED", feedJSONList.get(3), id); checkRequisitionStatusOnFeed("RELEASED", feedJSONList.get(4), id); responseEntity = client.SendJSON("", URL + "recent", "GET", "", ""); assertEquals(200, responseEntity.getStatus()); feedJSONList = XmlUtils.getNodeValues(responseEntity.getResponse(), "content"); checkOrderStatusOnFeed("IN_ROUTE", feedJSONList.get(0), id); responseEntity = waitForOrderStatusUpdatedOrTimeOut(1); assertEquals(200, responseEntity.getStatus()); feedJSONList = XmlUtils.getNodeValues(responseEntity.getResponse(), "content"); checkOrderStatusOnFeed("RELEASED", feedJSONList.get(1), id); }
@Test public void testPersonList() { TestPerson hh = new TestPerson(); hh.setUserName("hanhan"); hh.setAge(30); TestPerson parent = new TestPerson(); parent.setUserName("hanrenjun"); parent.setAge(60); hh.setParent(parent); Collection<TestPerson> lists = CUtils.newHashSet(); lists.add(hh); String xmlStr = XmlUtils.toXML(lists, "personlist", Set.class, "person", TestPerson.class); System.out.println("testPersonList xml:\n " + xmlStr); Collection<TestPerson> list = XmlUtils.toBean(xmlStr, "personlist", List.class, "person", TestPerson.class); Assert.assertEquals(hh.getUserName(), list.iterator().next().getUserName()); }
@Nullable private static Document parse(String xml) throws Exception { if (true) { return XmlUtils.parseDocumentSilently(xml, true); } DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); factory.setValidating(false); factory.setExpandEntityReferences(false); factory.setXIncludeAware(false); factory.setIgnoringComments(false); factory.setCoalescing(false); DocumentBuilder builder; builder = factory.newDocumentBuilder(); return builder.parse(new InputSource(new StringReader(xml))); }