/**
* Copyright (c) 2009-2010 Misys Open Source Solutions (MOSS) and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
* Contributors:
* Misys Open Source Solutions - initial API and implementation
* -
*/
package org.openhealthtools.openxds.integrationtests;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.io.InputStream;
import java.util.Properties;
import javax.xml.namespace.QName;
import org.apache.axiom.om.OMAttribute;
import org.apache.axiom.om.OMElement;
import org.apache.axis2.client.ServiceClient;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openhealthtools.common.utils.OMUtil;
/**
* This class is an temporary convenient test for IHE transaction ITI-18, namely,
* RegistryStoredQuery. It is used for developers for some debugging purpose.
*
* <p>
* Before running this test case, be sure to configure the following:
* <ul>
* <li>Both the XDS Repository and Registry servers have to be configured and started.</li>
* <li>The repositoryUrl and registryUrl needs be to set.</li>
* </ul>
*
* @author <a href="mailto:wenzhi.li@misys.com">Wenzhi Li</a>
*/
public class QueryTest extends XdsTest {
/**
* @throws java.lang.Exception
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception {
InputStream is = XdsTest.class.getClassLoader().getResourceAsStream("test.properties");
if (is == null) {
throw new Exception("Cannot load test.propertises");
}
Properties properties = new java.util.Properties();
try {
properties.load(is);
}
catch (Exception e) {
throw new Exception("Cannot load test.properties", e);
}
hostName = properties.getProperty("pixRegistryHostName");
repositoryUrl = properties.getProperty("repositoryUrl");
registryUrl = properties.getProperty("registryUrl");
pixRegistryPort = Integer.parseInt(properties.getProperty("pixRegistryPort"));
patientId = properties.getProperty("patientId");
assigningAuthority = properties.getProperty("assigningAuthority");
}
/**
* @throws java.lang.Exception
*/
@AfterClass
public static void tearDownAfterClass() throws Exception {
}
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
}
/**
* @throws java.lang.Exception
*/
@After
public void tearDown() throws Exception {
}
@Test
public void testFindDocuments_MultipleStatus() throws Exception {
//Generate StoredQuery request message
patientId = XdsTest.patientId;
String message = findDocumentsQuery(patientId);
OMElement request = OMUtil.xmlStringToOM(message);
System.out.println("Request:\n" +request);
//3. Send a StoredQuery
ServiceClient sender = getRegistryServiceClient();
OMElement response = sender.sendReceive( request );
assertNotNull(response);
//4. Verify the response is correct
OMAttribute status = response.getAttribute(new QName("status"));
assertEquals("urn:oasis:names:tc:ebxml-regrep:ResponseStatusType:Success", status.getAttributeValue());
String result = response.toString();
System.out.println("Result:\n" +result);
}
public String findDocumentsQuery(String patientId){
String request = "<query:AdhocQueryRequest xsi:schemaLocation=\"urn:oasis:names:tc:ebxml-regrep:xsd:query:3.0 ../schema/ebRS/query.xsd\" xmlns:query=\"urn:oasis:names:tc:ebxml-regrep:xsd:query:3.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:rim=\"urn:oasis:names:tc:ebxml-regrep:xsd:rim:3.0\" xmlns:rs=\"urn:oasis:names:tc:ebxml-regrep:xsd:rs:3.0\">\n"+
" <query:ResponseOption returnComposedObjects=\"true\" returnType=\"ObjectRef\"/>\n"+
" <rim:AdhocQuery id=\"urn:uuid:14d4debf-8f97-4251-9a74-a90016b0af0d\">\n";
if (patientId != null) {
request += " <rim:Slot name=\"$XDSDocumentEntryPatientId\">\n"+
" <rim:ValueList>\n" +
" <rim:Value>'"+patientId+"'</rim:Value>\n" +
" </rim:ValueList>\n"+
" </rim:Slot>\n";
}
request += " <rim:Slot name=\"$XDSDocumentEntryStatus\">\n" +
" <rim:ValueList>\n" +
" <rim:Value>('urn:oasis:names:tc:ebxml-regrep:StatusType:Approved', 'urn:oasis:names:tc:ebxml-regrep:StatusType:Deprecated')</rim:Value>\n" +
" </rim:ValueList>\n" +
" </rim:Slot>\n";
request += " </rim:AdhocQuery>\n" +
"</query:AdhocQueryRequest>";
return request;
}
}