use of org.example.contract.doubleit.DoubleItPortType in project cxf by apache.
the class PartsTest method testSignedParts.
@org.junit.Test
public void testSignedParts() throws Exception {
SpringBusFactory bf = new SpringBusFactory();
URL busFile = PartsTest.class.getResource("client.xml");
Bus bus = bf.createBus(busFile.toString());
BusFactory.setDefaultBus(bus);
BusFactory.setThreadDefaultBus(bus);
URL wsdl = PartsTest.class.getResource("DoubleItParts.wsdl");
Service service = Service.create(wsdl, SERVICE_QNAME);
// Successful invocation
QName portQName = new QName(NAMESPACE, "DoubleItSignedPartsPort");
DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class);
updateAddressPort(port, test.getPort());
if (test.isStreaming()) {
SecurityTestUtil.enableStreaming(port);
}
assertEquals(50, port.doubleIt(25));
// This should fail, as the service requires that the Body must be signed
portQName = new QName(NAMESPACE, "DoubleItSignedPartsPort2");
port = service.getPort(portQName, DoubleItPortType.class);
updateAddressPort(port, test.getPort());
if (test.isStreaming()) {
SecurityTestUtil.enableStreaming(port);
}
try {
port.doubleIt(25);
fail("Failure expected on a body which isn't signed");
} catch (javax.xml.ws.soap.SOAPFaultException ex) {
String error = "SignedParts";
assertTrue(ex.getMessage().contains(error) || ex.getMessage().contains("Body must be signed"));
}
// This should fail, as the service requires that the To header must be signed
portQName = new QName(NAMESPACE, "DoubleItSignedPartsPort3");
port = service.getPort(portQName, DoubleItPortType.class);
updateAddressPort(port, test.getPort());
if (test.isStreaming()) {
SecurityTestUtil.enableStreaming(port);
}
try {
port.doubleIt(25);
fail("Failure expected on a header which isn't signed");
} catch (javax.xml.ws.soap.SOAPFaultException ex) {
String error = "SignedParts";
assertTrue(ex.getMessage().contains(error) || ex.getMessage().contains("To must be signed"));
}
((java.io.Closeable) port).close();
bus.shutdown(true);
}
use of org.example.contract.doubleit.DoubleItPortType in project cxf by apache.
the class PartsTest method testRequiredElements.
@org.junit.Test
public void testRequiredElements() throws Exception {
SpringBusFactory bf = new SpringBusFactory();
URL busFile = PartsTest.class.getResource("client.xml");
Bus bus = bf.createBus(busFile.toString());
BusFactory.setDefaultBus(bus);
BusFactory.setThreadDefaultBus(bus);
URL wsdl = PartsTest.class.getResource("DoubleItParts.wsdl");
Service service = Service.create(wsdl, SERVICE_QNAME);
// Successful invocation
QName portQName = new QName(NAMESPACE, "DoubleItRequiredElementsPort");
DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class);
updateAddressPort(port, test.getPort());
if (test.isStreaming()) {
SecurityTestUtil.enableStreaming(port);
}
assertEquals(50, port.doubleIt(25));
// This should fail, as the service requires a (bad) header
portQName = new QName(NAMESPACE, "DoubleItRequiredElementsPort2");
port = service.getPort(portQName, DoubleItPortType.class);
updateAddressPort(port, test.getPort());
if (test.isStreaming()) {
SecurityTestUtil.enableStreaming(port);
}
try {
port.doubleIt(25);
fail("Failure expected on a required header which isn't present");
} catch (javax.xml.ws.soap.SOAPFaultException ex) {
String error = "RequiredElements: No header element";
assertTrue(ex.getMessage().contains(error) || ex.getMessage().contains("ToTo must be present"));
}
((java.io.Closeable) port).close();
bus.shutdown(true);
}
use of org.example.contract.doubleit.DoubleItPortType in project cxf by apache.
the class PolicyAlternativeTest method testNoSecurity.
/**
* The client uses no security - this should fail.
*/
@org.junit.Test
public void testNoSecurity() throws Exception {
SpringBusFactory bf = new SpringBusFactory();
URL busFile = PolicyAlternativeTest.class.getResource("client.xml");
Bus bus = bf.createBus(busFile.toString());
BusFactory.setDefaultBus(bus);
BusFactory.setThreadDefaultBus(bus);
URL wsdl = PolicyAlternativeTest.class.getResource("DoubleItPolicy.wsdl");
Service service = Service.create(wsdl, SERVICE_QNAME);
QName portQName = new QName(NAMESPACE, "DoubleItNoSecurityPort");
DoubleItPortType utPort = service.getPort(portQName, DoubleItPortType.class);
updateAddressPort(utPort, test.getPort());
if (test.isStreaming()) {
SecurityTestUtil.enableStreaming(utPort);
}
try {
utPort.doubleIt(25);
fail("Failure expected on no Security");
} catch (javax.xml.ws.soap.SOAPFaultException ex) {
// expected
}
((java.io.Closeable) utPort).close();
bus.shutdown(true);
}
use of org.example.contract.doubleit.DoubleItPortType in project cxf by apache.
the class PolicyAlternativeTest method testRequireClientCertToken.
/**
* The client does not require a client cert so invocation should fail
*
* @throws Exception
*/
@org.junit.Test
public void testRequireClientCertToken() throws Exception {
SpringBusFactory bf = new SpringBusFactory();
URL busFile = PolicyAlternativeTest.class.getResource("client.xml");
Bus bus = bf.createBus(busFile.toString());
BusFactory.setDefaultBus(bus);
BusFactory.setThreadDefaultBus(bus);
URL wsdl = PolicyAlternativeTest.class.getResource("DoubleItPolicy.wsdl");
Service service = Service.create(wsdl, SERVICE_QNAME);
QName portQName = new QName(NAMESPACE, "DoubleItClientCertPort");
DoubleItPortType utPort = service.getPort(portQName, DoubleItPortType.class);
updateAddressPort(utPort, PORT2);
if (test.isStreaming()) {
SecurityTestUtil.enableStreaming(utPort);
}
try {
utPort.doubleIt(25);
fail("Failure expected because no client certificate");
} catch (javax.xml.ws.soap.SOAPFaultException ex) {
if (!test.isStreaming()) {
assertTrue(ex.getMessage().contains("HttpsToken"));
}
}
((java.io.Closeable) utPort).close();
bus.shutdown(true);
}
use of org.example.contract.doubleit.DoubleItPortType in project cxf by apache.
the class PolicyAlternativeTest method testAsymmetric.
/**
* The client uses the Asymmetric policy - this should succeed.
*/
@org.junit.Test
public void testAsymmetric() throws Exception {
SpringBusFactory bf = new SpringBusFactory();
URL busFile = PolicyAlternativeTest.class.getResource("client.xml");
Bus bus = bf.createBus(busFile.toString());
BusFactory.setDefaultBus(bus);
BusFactory.setThreadDefaultBus(bus);
URL wsdl = PolicyAlternativeTest.class.getResource("DoubleItPolicy.wsdl");
Service service = Service.create(wsdl, SERVICE_QNAME);
QName portQName = new QName(NAMESPACE, "DoubleItAsymmetricPort");
DoubleItPortType utPort = service.getPort(portQName, DoubleItPortType.class);
updateAddressPort(utPort, test.getPort());
if (test.isStreaming()) {
SecurityTestUtil.enableStreaming(utPort);
}
utPort.doubleIt(25);
((java.io.Closeable) utPort).close();
bus.shutdown(true);
}
Aggregations