|
21 | 21 | import junit.framework.TestCase; |
22 | 22 | import org.apache.commons.logging.Log; |
23 | 23 | import org.apache.commons.logging.LogFactory; |
| 24 | +import org.w3c.dom.Document; |
| 25 | +import org.w3c.dom.Node; |
24 | 26 | import org.wso2.balana.*; |
25 | 27 | import org.wso2.balana.ctx.ResponseCtx; |
| 28 | +import org.wso2.balana.ctx.Status; |
26 | 29 | import org.wso2.balana.finder.PolicyFinder; |
27 | 30 | import org.wso2.balana.finder.PolicyFinderModule; |
28 | 31 | import org.wso2.balana.finder.impl.FileBasedPolicyFinderModule; |
|
32 | 35 | import java.util.HashSet; |
33 | 36 | import java.util.Set; |
34 | 37 |
|
| 38 | +import javax.xml.parsers.DocumentBuilder; |
| 39 | +import javax.xml.parsers.DocumentBuilderFactory; |
| 40 | + |
35 | 41 | /** |
36 | 42 | * This XACML 3.0 basic polciy test. This would test a basic policy, basic policy with obligations and |
37 | 43 | * basic policy with advices. |
@@ -296,4 +302,29 @@ private static PDP getPDPNewInstance(Set<String> policies){ |
296 | 302 |
|
297 | 303 | } |
298 | 304 |
|
| 305 | + public void testParsesSimpleStatusDetail() throws Exception { |
| 306 | + String xml = |
| 307 | + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" |
| 308 | + + "<Status>" |
| 309 | + + " <StatusCode Value=\"test\">" |
| 310 | + + " </StatusCode>" |
| 311 | + + " <StatusMessage>Policy had a syntax issue</StatusMessage>" |
| 312 | + + " <StatusDetail>" |
| 313 | + + " <Problem>line=42; column=17</Problem>" |
| 314 | + + " </StatusDetail>" |
| 315 | + + "</Status>"; |
| 316 | + Node root = parseRoot(xml); |
| 317 | + Status status = Status.getInstance(root); |
| 318 | + assertNotNull(status.getDetail().toString(), "StatusDetail should not be null"); |
| 319 | + } |
| 320 | + |
| 321 | + |
| 322 | + private Node parseRoot(String xml) throws Exception { |
| 323 | + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); |
| 324 | + DocumentBuilder builder = factory.newDocumentBuilder(); |
| 325 | + Document doc = builder.parse(new java.io.ByteArrayInputStream(xml.getBytes("UTF-8"))); |
| 326 | + Node root = doc.getDocumentElement(); |
| 327 | + return root; |
| 328 | + } |
| 329 | + |
299 | 330 | } |
0 commit comments