Skip to content

Commit dd5aa2f

Browse files
committed
Add sample test case
1 parent 7691d25 commit dd5aa2f

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

modules/balana-core/src/test/java/org/wso2/balana/basic/BasicTestV3.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@
2121
import junit.framework.TestCase;
2222
import org.apache.commons.logging.Log;
2323
import org.apache.commons.logging.LogFactory;
24+
import org.w3c.dom.Document;
25+
import org.w3c.dom.Node;
2426
import org.wso2.balana.*;
2527
import org.wso2.balana.ctx.ResponseCtx;
28+
import org.wso2.balana.ctx.Status;
2629
import org.wso2.balana.finder.PolicyFinder;
2730
import org.wso2.balana.finder.PolicyFinderModule;
2831
import org.wso2.balana.finder.impl.FileBasedPolicyFinderModule;
@@ -32,6 +35,9 @@
3235
import java.util.HashSet;
3336
import java.util.Set;
3437

38+
import javax.xml.parsers.DocumentBuilder;
39+
import javax.xml.parsers.DocumentBuilderFactory;
40+
3541
/**
3642
* This XACML 3.0 basic polciy test. This would test a basic policy, basic policy with obligations and
3743
* basic policy with advices.
@@ -296,4 +302,29 @@ private static PDP getPDPNewInstance(Set<String> policies){
296302

297303
}
298304

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+
299330
}

0 commit comments

Comments
 (0)