Fix failing unit test

This commit is contained in:
James Agnew 2015-05-07 12:02:54 -04:00
parent 9658cafdfc
commit ce9a2da0e8
1 changed files with 19 additions and 11 deletions

View File

@ -3,12 +3,14 @@ package ca.uhn.fhir.jpa.provider;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.Socket; import java.net.Socket;
import java.net.SocketAddress; import java.net.SocketAddress;
import java.net.SocketTimeoutException;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
@ -270,7 +272,7 @@ public class ResourceProviderDstu2Test {
Patient pt = new Patient(); Patient pt = new Patient();
pt.addName().addFamily(methodName); pt.addName().addFamily(methodName);
pt.addIdentifier().setSystem("http://ghh.org/patient").setValue("555-44-4444"); pt.addIdentifier().setSystem("http://ghh.org/patient").setValue(methodName);
String resource = ourFhirCtx.newXmlParser().encodeResourceToString(pt); String resource = ourFhirCtx.newXmlParser().encodeResourceToString(pt);
HttpPost post = new HttpPost(ourServerBase + "/Patient"); HttpPost post = new HttpPost(ourServerBase + "/Patient");
@ -291,26 +293,32 @@ public class ResourceProviderDstu2Test {
* but we want to make sure that works too.. * but we want to make sure that works too..
*/ */
Socket sock = new Socket(); Socket sock = new Socket();
sock.setSoTimeout(3000);
try { try {
sock.connect(new InetSocketAddress("localhost", ourPort)); sock.connect(new InetSocketAddress("localhost", ourPort));
sock.getOutputStream().write(("DELETE " + "/fhir/context/Patient?identifier=" + ("http://ghh.org/patient|555-44-4444")).getBytes("UTF-8")); sock.getOutputStream().write(("DELETE /fhir/context/Patient?identifier=http://ghh.org/patient|" + methodName + " HTTP/1.1\n").getBytes("UTF-8"));
sock.getOutputStream().write("\n\n".getBytes("UTF-8")); sock.getOutputStream().write("Host: localhost\n".getBytes("UTF-8"));
sock.getOutputStream().flush(); sock.getOutputStream().write("\n".getBytes("UTF-8"));
InputStream inputStream = sock.getInputStream(); BufferedReader socketInput = new BufferedReader(new InputStreamReader(sock.getInputStream()));
byte[] buf = new byte[10000]; //String response = "";
int count; StringBuilder b = new StringBuilder();
StringBuilder b = new StringBuilder(); char[] buf = new char[1000];
while ((count = inputStream.read(buf)) != -1) { while(socketInput.read(buf) != -1){
b.append(new String(buf, 0, count, Charset.forName("UTF-8"))); b.append(buf);
} }
String resp = b.toString(); String resp = b.toString();
ourLog.info("Resp: {}", resp); ourLog.info("Resp: {}", resp);
} catch (SocketTimeoutException e) {
e.printStackTrace();
} finally { } finally {
sock.close(); sock.close();
} }
Thread.sleep(1000);
HttpGet read = new HttpGet(ourServerBase + "/Patient/" + id.getIdPart()); HttpGet read = new HttpGet(ourServerBase + "/Patient/" + id.getIdPart());
response = ourHttpClient.execute(read); response = ourHttpClient.execute(read);
try { try {