1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.openehealth.ipf.platform.camel.ihe.xds.iti42;
17
18 import org.apache.cxf.Bus;
19 import org.apache.cxf.bus.spring.SpringBusFactory;
20 import org.apache.cxf.transport.servlet.CXFServlet;
21 import org.apache.cxf.ws.security.trust.STSClient;
22 import org.junit.Assert;
23 import org.junit.BeforeClass;
24 import org.junit.Ignore;
25 import org.junit.Test;
26 import org.openehealth.ipf.commons.ihe.ws.JaxWsClientFactory;
27 import org.openehealth.ipf.commons.ihe.ws.JaxWsRequestClientFactory;
28 import org.openehealth.ipf.commons.ihe.xds.core.audit.XdsAuditDataset;
29 import org.openehealth.ipf.commons.ihe.xds.core.stub.ebrs30.lcm.SubmitObjectsRequest;
30 import org.openehealth.ipf.commons.ihe.xds.iti42.Iti42PortType;
31 import org.openehealth.ipf.platform.camel.ihe.xds.XdsStandardTestContainer;
32
33 import javax.xml.ws.BindingProvider;
34 import javax.xml.ws.Service;
35 import javax.xml.ws.soap.SOAPFaultException;
36 import java.net.URL;
37 import java.util.Map;
38
39 import static org.openehealth.ipf.commons.ihe.xds.XDS.Interactions.ITI_42;
40
41 @Ignore
42 public class CxfFeatureTest extends XdsStandardTestContainer {
43
44 static private final String CONTEXT_DESCRIPTOR = "feature-test-resources/server-context.xml";
45
46 @BeforeClass
47 public static void setUp() {
48 startServer(new CXFServlet(), CONTEXT_DESCRIPTOR);
49 }
50
51 @Test
52 public void testFeatureEndpointWithoutPolicy() {
53 JaxWsClientFactory<? extends XdsAuditDataset> clientFactory = new JaxWsRequestClientFactory<>(
54 ITI_42.getWsTransactionConfiguration(),
55 "http://localhost:" + getPort() + "/xds-iti42",
56 null, null,
57 null, null, null, null);
58 Iti42PortType client = (Iti42PortType) clientFactory.getClient();
59 try {
60 client.documentRegistryRegisterDocumentSetB(new SubmitObjectsRequest());
61 Assert.fail("This line must be not reachable");
62 } catch (SOAPFaultException ex) {
63 Assert.assertTrue(ex.getMessage().contains("These policy alternatives can not be satisfied"));
64 }
65 }
66
67 @Test
68 public void testFeatureEndpointWithPolicy() {
69 SpringBusFactory bf = new SpringBusFactory();
70 Bus bus = bf.createBus("feature-test-resources/client-context.xml");
71 SpringBusFactory.setDefaultBus(bus);
72 SpringBusFactory.setThreadDefaultBus(bus);
73
74 Iti42PortType client =
75 getClient("feature-test-resources/iti42-with-policy.wsdl", "http://localhost:" + getPort() + "/xds-iti42");
76
77 Map<String, Object> requestContext = ((BindingProvider) client).getRequestContext();
78
79 STSClient stsClient = (STSClient) requestContext.get("ws-security.sts.client");
80 stsClient.setWsdlLocation("http://localhost:" + getPort() + "/X509?wsdl");
81
82 try {
83 client.documentRegistryRegisterDocumentSetB(new SubmitObjectsRequest());
84 } catch (SOAPFaultException ex) {
85
86 Assert.fail();
87 } finally {
88 SpringBusFactory.setThreadDefaultBus(null);
89 SpringBusFactory.setDefaultBus(null);
90 }
91 }
92
93 private Iti42PortType getClient(String wsdlLocation, String serviceURL) {
94 URL wsdlURL = getClass().getClassLoader().getResource(wsdlLocation);
95 Service service = Service.create(wsdlURL, ITI_42.getWsTransactionConfiguration().getServiceName());
96 Iti42PortType client = (Iti42PortType) service.getPort(ITI_42.getWsTransactionConfiguration().getSei());
97
98 BindingProvider bindingProvider = (BindingProvider) client;
99 Map<String, Object> reqContext = bindingProvider.getRequestContext();
100 reqContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, serviceURL);
101 return client;
102 }
103
104 }