Add tests for operation method binding

This commit is contained in:
James Agnew 2018-10-30 15:22:39 -04:00
parent b66e01ce65
commit 6b1ea5b989
3 changed files with 54 additions and 5 deletions

View File

@ -202,6 +202,10 @@ public class OperationMethodBinding extends BaseResourceReturningMethodBinding {
@Override
public boolean incomingServerRequestMatchesMethod(RequestDetails theRequest) {
if (isBlank(theRequest.getOperation())) {
return false;
}
if (!myName.equals(theRequest.getOperation())) {
if (!myName.equals(WILDCARD_NAME)) {
return false;

View File

@ -1,10 +1,7 @@
package ca.uhn.fhir.rest.server;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.rest.annotation.IdParam;
import ca.uhn.fhir.rest.annotation.Operation;
import ca.uhn.fhir.rest.annotation.OperationParam;
import ca.uhn.fhir.rest.annotation.ResourceParam;
import ca.uhn.fhir.rest.annotation.*;
import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.util.PortUtil;
import ca.uhn.fhir.util.TestUtil;
@ -31,6 +28,7 @@ import org.junit.BeforeClass;
import org.junit.Test;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
@ -168,6 +166,22 @@ public class OperationGenericServerR4Test {
}
}
SmartScopeTranslationSvcImplTest @Test
public void testSearchGetsClassifiedAppropriately() throws Exception {
HttpGet httpPost = new HttpGet("http://localhost:" + ourPort + "/Patient");
CloseableHttpResponse status = ourClient.execute(httpPost);
try {
assertEquals(200, status.getStatusLine().getStatusCode());
status.getEntity().getContent().close();
} finally {
status.getEntity().getContent().close();
}
assertEquals("Patient/search", ourLastMethod);
}
@SuppressWarnings("unused")
public static class PatientProvider implements IResourceProvider {
@ -215,6 +229,12 @@ public class OperationGenericServerR4Test {
return retVal;
}
@Search
public List<IBaseResource> search() {
ourLastMethod = "Patient/search";
return new ArrayList<>();
}
}
@ -239,6 +259,13 @@ public class OperationGenericServerR4Test {
}
@Search
public List<IBaseResource> search() {
ourLastMethod = "/search";
return new ArrayList<>();
}
}
@AfterClass

View File

@ -194,6 +194,24 @@
<td style="background: #CEC;">3.0.1</td>
<td style="background: #EEB;">3.4.0-13732</td>
</tr>
<tr>
<td>HAPI FHIR 3.5.0</td>
<td>JDK8</td>
<td style="background: #DDD;"></td>
<td style="background: #CEC;">1.0.2</td>
<td style="background: #EEB;">1.4.0</td>
<td style="background: #CEC;">3.0.1</td>
<td style="background: #EEB;">3.4.0-13732</td>
</tr>
<tr>
<td>HAPI FHIR 3.4.0</td>
<td>JDK8</td>
<td style="background: #DDD;"></td>
<td style="background: #CEC;">1.0.2</td>
<td style="background: #EEB;">1.4.0</td>
<td style="background: #CEC;">3.0.1</td>
<td style="background: #EEB;">3.6.0-13732</td>
</tr>
</tbody>
</table>