@Test public void testTwoSchemasSameNs() throws Exception { WadlGenerator wg = new WadlGenerator(); wg.setApplicationTitle("My Application"); wg.setNamespacePrefix("ns"); ClassResourceInfo cri = ResourceUtils.createClassResourceInfo(TestResource.class, TestResource.class, true, true); Message m = mockMessage("http://localhost:8080/baz", "/", WadlGenerator.WADL_QUERY, cri); Response r = handleRequest(wg, m); checkResponse(r); Document doc = StaxUtils.read(new StringReader(r.getEntity().toString())); checkDocs(doc.getDocumentElement(), "My Application", "", ""); List<Element> grammarEls = DOMUtils.getChildrenWithName(doc.getDocumentElement(), WadlGenerator.WADL_NS, "grammars"); assertEquals(1, grammarEls.size()); List<Element> schemasEls = DOMUtils.getChildrenWithName(grammarEls.get(0), Constants.URI_2001_SCHEMA_XSD, "schema"); assertEquals(2, schemasEls.size()); assertEquals("http://example.com/test", schemasEls.get(0).getAttribute("targetNamespace")); assertEquals("http://example.com/test", schemasEls.get(1).getAttribute("targetNamespace")); List<Element> reps = DOMUtils.findAllElementsByTagNameNS( doc.getDocumentElement(), WadlGenerator.WADL_NS, "representation"); assertEquals(2, reps.size()); assertEquals("ns1:testCompositeObject", reps.get(0).getAttribute("element")); assertEquals("ns1:testCompositeObject", reps.get(1).getAttribute("element")); }
@Test public void testSingleRootResource() throws Exception { WadlGenerator wg = new WadlGenerator(); wg.setApplicationTitle("My Application"); wg.setNamespacePrefix("ns"); ClassResourceInfo cri = ResourceUtils.createClassResourceInfo(BookStore.class, BookStore.class, true, true); Message m = mockMessage("http://localhost:8080/baz", "/bookstore/1", WadlGenerator.WADL_QUERY, cri); Response r = handleRequest(wg, m); checkResponse(r); Document doc = StaxUtils.read(new StringReader(r.getEntity().toString())); checkDocs(doc.getDocumentElement(), "My Application", "", ""); checkGrammars( doc.getDocumentElement(), "thebook", "books", "thebook2s", "thebook2", "thechapter"); List<Element> els = getWadlResourcesInfo(doc, "http://localhost:8080/baz", 1); checkBookStoreInfo(els.get(0), "ns1:thebook", "ns1:thebook2", "ns1:thechapter", "ns1:books"); }