SignedPartsTestpublic class SignedPartsTest extends TestCase
Constructors Summary |
---|
public SignedPartsTest(String testName)
super(testName);
|
Methods Summary |
---|
private java.io.Reader | getResourceReader(java.lang.String resourceName)
return new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(resourceName));
| public boolean | isHeaderPresent(javax.xml.namespace.QName expected, java.util.Iterator headers)
while(headers.hasNext()){
Header header = (Header) headers.next();
if(expected.getLocalPart().equals(header.getLocalName())){
if(expected.getNamespaceURI().equals(header.getURI())){
return true;
}
}
}
return false;
| protected void | setUp()
| public static junit.framework.Test | suite()
TestSuite suite = new TestSuite(SignedPartsTest.class);
return suite;
| protected void | tearDown()
| public void | testSignParts1()
String fileName = "security/SignParts1.xml";
Policy policy = unmarshalPolicy(fileName);
assertNotNull(policy);
Iterator <AssertionSet> itr = policy.iterator();
if(itr.hasNext()){
AssertionSet as = itr.next();
for(PolicyAssertion assertion : as){
assertEquals("Invalid assertion","SignedParts",assertion.getName().getLocalPart());
SignedParts sp = (SignedParts)assertion;
assertEquals("Body not found ",true,sp.hasBody());
assertTrue(isHeaderPresent(new QName("http://schemas.xmlsoap.org/ws/2004/08/addressing","To"),sp.getHeaders()));
assertTrue(isHeaderPresent(new QName("http://schemas.xmlsoap.org/ws/2004/08/addressing","From"),sp.getHeaders()));
assertTrue(isHeaderPresent(new QName("http://schemas.xmlsoap.org/ws/2004/08/addressing","FaultTo"),sp.getHeaders()));
assertTrue(isHeaderPresent(new QName("http://schemas.xmlsoap.org/ws/2004/08/addressing","ReplyTo"),sp.getHeaders()));
assertTrue(isHeaderPresent(new QName("http://schemas.xmlsoap.org/ws/2004/08/addressing","MessageID"),sp.getHeaders()));
assertTrue(isHeaderPresent(new QName("http://schemas.xmlsoap.org/ws/2004/08/addressing","RelatesTo"),sp.getHeaders()));
assertTrue(isHeaderPresent(new QName("http://schemas.xmlsoap.org/ws/2004/08/addressing","Action"),sp.getHeaders()));
}
}else{
throw new Exception("No Assertions found!. Unmarshalling of "+fileName+"failed!");
}
| public void | testSignParts2()
String fileName = "security/SignParts2.xml";
Policy policy = unmarshalPolicy(fileName);
assertNotNull(policy);
Iterator <AssertionSet> itr = policy.iterator();
if(itr.hasNext()){
AssertionSet as = itr.next();
for(PolicyAssertion assertion : as){
assertEquals("Invalid assertion","SignedParts",assertion.getName().getLocalPart());
SignedParts sp = (SignedParts)assertion;
assertEquals("Body not found ",true,sp.hasBody());
// assertTrue("Header elements should not be present",sp.getHeaders().hasNext());
}
}else{
throw new Exception("No Assertions found!. Unmarshalling of "+fileName+"failed!");
}
| public void | testSignParts3()
String fileName = "security/SignParts3.xml";
Policy policy = unmarshalPolicy(fileName);
assertNotNull(policy);
Iterator <AssertionSet> itr = policy.iterator();
if(itr.hasNext()){
AssertionSet as = itr.next();
for(PolicyAssertion assertion : as){
assertEquals("Invalid assertion","SignedParts",assertion.getName().getLocalPart());
SignedParts sp = (SignedParts)assertion;
assertEquals("Body should not be present ",false,sp.hasBody());
assertTrue(isHeaderPresent(new QName("http://schemas.xmlsoap.org/ws/2004/08/addressing","To"),sp.getHeaders()));
assertTrue(isHeaderPresent(new QName("http://schemas.xmlsoap.org/ws/2004/08/addressing","From"),sp.getHeaders()));
assertTrue(isHeaderPresent(new QName("http://schemas.xmlsoap.org/ws/2004/08/addressing","FaultTo"),sp.getHeaders()));
assertTrue(isHeaderPresent(new QName("http://schemas.xmlsoap.org/ws/2004/08/addressing","ReplyTo"),sp.getHeaders()));
assertTrue(isHeaderPresent(new QName("http://schemas.xmlsoap.org/ws/2004/08/addressing","MessageID"),sp.getHeaders()));
assertTrue(isHeaderPresent(new QName("http://schemas.xmlsoap.org/ws/2004/08/addressing","RelatesTo"),sp.getHeaders()));
assertTrue(isHeaderPresent(new QName("http://schemas.xmlsoap.org/ws/2004/08/addressing","Action"),sp.getHeaders()));
}
}else{
throw new Exception("No Assertions found!. Unmarshalling of "+fileName+"failed!");
}
| public void | testSignParts4()
String fileName = "security/SignParts4.xml";
try{
Policy policy = unmarshalPolicy(fileName);
}catch(PolicyException ex){
//java.lang.reflect.InvocationTargetException for Namespace attribute is required under Header element
if(!"java.lang.reflect.InvocationTargetException".equals(ex.getMessage())){
System.out.println("Exception is different "+ex.getMessage());
throw ex;
}
}
| public void | testSignParts5()
String fileName = "security/SignParts5.xml";
Policy policy = unmarshalPolicy(fileName);
assertNotNull(policy);
Iterator <AssertionSet> itr = policy.iterator();
if(itr.hasNext()){
AssertionSet as = itr.next();
for(PolicyAssertion assertion : as){
assertEquals("Invalid assertion","SignedParts",assertion.getName().getLocalPart());
SignedParts sp = (SignedParts)assertion;
assertEquals("Body should not be present ",false,sp.hasBody());
assertTrue(isHeaderPresent(new QName("http://schemas.xmlsoap.org/ws/2004/08/addressing",""),sp.getHeaders()));
assertTrue(isHeaderPresent(new QName("http://schemas.xmlsoap.org/ws/2004/08/addressing","FaultTo"),sp.getHeaders()));
assertTrue(isHeaderPresent(new QName("http://schemas.xmlsoap.org/ws/2004/08/addressing","ReplyTo"),sp.getHeaders()));
assertTrue(isHeaderPresent(new QName("http://schemas.xmlsoap.org/ws/2004/08/addressing","MessageID"),sp.getHeaders()));
assertTrue(isHeaderPresent(new QName("http://schemas.xmlsoap.org/ws/2004/08/addressing","RelatesTo"),sp.getHeaders()));
assertTrue(isHeaderPresent(new QName("http://schemas.xmlsoap.org/ws/2004/08/addressing","Action"),sp.getHeaders()));
}
}else{
throw new Exception("No Assertions found!. Unmarshalling of "+fileName+"failed!");
}
| public void | testSignParts6()
String fileName = "security/SignParts6.xml";
Policy policy = unmarshalPolicy(fileName);
assertNotNull(policy);
Iterator <AssertionSet> itr = policy.iterator();
if(itr.hasNext()){
AssertionSet as = itr.next();
for(PolicyAssertion assertion : as){
assertEquals("Invalid assertion","SignedParts",assertion.getName().getLocalPart());
SignedParts sp = (SignedParts)assertion;
assertEquals("Body should not be present ",false,sp.hasBody());
assertFalse("Headers should not be present",sp.getHeaders().hasNext());
}
}else{
throw new Exception("No Assertions found!. Unmarshalling of "+fileName+"failed!");
}
| public com.sun.xml.ws.policy.Policy | unmarshalPolicy(java.lang.String xmlFile)
PolicySourceModel model = unmarshalPolicyResource(
xmlFile);
Policy mbp = PolicyModelTranslator.getTranslator().translate(model);
return mbp;
| private com.sun.xml.ws.policy.sourcemodel.PolicySourceModel | unmarshalPolicyResource(java.lang.String resource)
Reader reader = getResourceReader(resource);
PolicySourceModel model = PolicyModelUnmarshaller.getXmlUnmarshaller().unmarshalModel(reader);
reader.close();
return model;
|
|