Test updates
This commit is contained in:
parent
0cc53ca742
commit
00af19cea7
|
@ -2,7 +2,9 @@ package ca.uhn.fhir.rest.server;
|
|||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
@ -23,8 +25,8 @@ import ca.uhn.fhir.context.FhirContext;
|
|||
import ca.uhn.fhir.model.api.IResource;
|
||||
import ca.uhn.fhir.model.dstu2.resource.Bundle;
|
||||
import ca.uhn.fhir.model.dstu2.resource.Patient;
|
||||
import ca.uhn.fhir.narrative.DefaultThymeleafNarrativeGenerator;
|
||||
import ca.uhn.fhir.rest.annotation.Search;
|
||||
import ca.uhn.fhir.util.PatternMatcher;
|
||||
import ca.uhn.fhir.util.PortUtil;
|
||||
|
||||
/**
|
||||
|
@ -56,6 +58,18 @@ public class SearchDstu2Test {
|
|||
assertNull(status.getFirstHeader(Constants.HEADER_CONTENT_LOCATION));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResultBundleHasUuid() throws Exception {
|
||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=searchWithRef");
|
||||
HttpResponse status = ourClient.execute(httpGet);
|
||||
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
ourLog.info(responseContent);
|
||||
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
assertThat(responseContent, PatternMatcher.pattern("id value..[0-9a-f-]+\\\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeConvertsReferencesToRelativeJson() throws Exception {
|
||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=searchWithRef&_format=json");
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
package ca.uhn.fhir.util;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.hamcrest.Factory;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.hamcrest.TypeSafeMatcher;
|
||||
|
||||
/**
|
||||
* Tests if the argument is a {@link CharSequence} that matches a regular expression.
|
||||
*/
|
||||
public class PatternMatcher extends TypeSafeMatcher<CharSequence> {
|
||||
|
||||
/**
|
||||
* Creates a matcher that matches if the examined {@link CharSequence} matches the specified regular expression.
|
||||
* <p/>
|
||||
* For example:
|
||||
*
|
||||
* <pre>
|
||||
* assertThat("myStringOfNote", pattern("[0-9]+"))
|
||||
* </pre>
|
||||
*
|
||||
* @param regex
|
||||
* the regular expression that the returned matcher will use to match any examined {@link CharSequence}
|
||||
*/
|
||||
@Factory
|
||||
public static Matcher<CharSequence> pattern(String regex) {
|
||||
return pattern(Pattern.compile(regex));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a matcher that matches if the examined {@link CharSequence} matches the specified {@link Pattern}.
|
||||
* <p/>
|
||||
* For example:
|
||||
*
|
||||
* <pre>
|
||||
* assertThat("myStringOfNote", Pattern.compile("[0-9]+"))
|
||||
* </pre>
|
||||
*
|
||||
* @param pattern
|
||||
* the pattern that the returned matcher will use to match any examined {@link CharSequence}
|
||||
*/
|
||||
@Factory
|
||||
public static Matcher<CharSequence> pattern(Pattern pattern) {
|
||||
return new PatternMatcher(pattern);
|
||||
}
|
||||
|
||||
private final Pattern pattern;
|
||||
|
||||
public PatternMatcher(Pattern pattern) {
|
||||
this.pattern = pattern;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesSafely(CharSequence item) {
|
||||
return pattern.matcher(item).find();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void describeMismatchSafely(CharSequence item, org.hamcrest.Description mismatchDescription) {
|
||||
mismatchDescription.appendText("was \"").appendText(String.valueOf(item)).appendText("\"");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void describeTo(org.hamcrest.Description description) {
|
||||
description.appendText("a string with pattern \"").appendText(String.valueOf(pattern)).appendText("\"");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue