### Question:
JaxRsMethodBindings { public BaseMethodBinding<?> getBinding(RestOperationTypeEnum operationType, String theBindingKey) { String bindingKey = StringUtils.defaultIfBlank(theBindingKey, DEFAULT_METHOD_KEY); ConcurrentHashMap<String, BaseMethodBinding<?>> map = getMapForOperation(operationType); if(map == null || !map.containsKey(bindingKey)) { throw new NotImplementedOperationException("Operation not implemented"); } else { return map.get(bindingKey); } } JaxRsMethodBindings(AbstractJaxRsProvider theProvider, Class<? extends AbstractJaxRsProvider> theProviderClass); BaseMethodBinding<?> getBinding(RestOperationTypeEnum operationType, String theBindingKey); static JaxRsMethodBindings getMethodBindings(AbstractJaxRsProvider theProvider, Class<? extends AbstractJaxRsProvider> theProviderClass); static final String DEFAULT_METHOD_KEY; }### Answer:
@Test public void testFindMethodsForProviderNotDefinedMappingMethods() { assertThrows(NotImplementedOperationException.class, () -> { new TestJaxRsDummyPatientProvider().getBindings().getBinding(RestOperationTypeEnum.UPDATE, ""); }); }
@Test public void testFindMethodsForProviderWithMethods() { class TestFindPatientProvider extends TestJaxRsDummyPatientProvider { @Search public List<Patient> search(@RequiredParam(name = Patient.SP_NAME) final StringParam name) { return null; } } new TestFindPatientProvider(); assertEquals(TestFindPatientProvider.class, new TestFindPatientProvider().getBindings().getBinding(RestOperationTypeEnum.SEARCH_TYPE, "").getMethod().getDeclaringClass()); }
@Test public void testFindMethodsFor2ProvidersWithMethods() { class TestFindPatientProvider extends TestJaxRsDummyPatientProvider { @Search public List<Patient> search(@RequiredParam(name = Patient.SP_NAME) final StringParam name) { return null; } } class TestUpdatePatientProvider extends TestJaxRsDummyPatientProvider { @Update public MethodOutcome update(@IdParam final IdDt theId, @ResourceParam final Patient patient) { return null; } } assertEquals(TestFindPatientProvider.class, new TestFindPatientProvider().getBindings().getBinding(RestOperationTypeEnum.SEARCH_TYPE, "").getMethod().getDeclaringClass()); assertEquals(TestUpdatePatientProvider.class, new TestUpdatePatientProvider().getBindings().getBinding(RestOperationTypeEnum.UPDATE, "").getMethod().getDeclaringClass()); }
@Test public void testFindMethodsWithMultipleMethods() { class TestFindPatientProvider extends TestJaxRsDummyPatientProvider { @Search public List<Patient> search(@RequiredParam(name = Patient.SP_NAME) final StringParam name) { return null; } @Update public MethodOutcome update(@IdParam final IdDt theId, @ResourceParam final Patient patient) { return null; } @Operation(name = "firstMethod", idempotent = true, returnParameters = {@OperationParam(name = "return", type = StringDt.class)}) public Parameters firstMethod(@OperationParam(name = "dummy") StringDt dummyInput) { return null; } @Operation(name = "secondMethod", returnParameters = {@OperationParam(name = "return", type = StringDt.class)}) public Parameters secondMethod(@OperationParam(name = "dummy") StringDt dummyInput) { return null; } } JaxRsMethodBindings bindings = new TestFindPatientProvider().getBindings(); assertEquals("search", bindings.getBinding(RestOperationTypeEnum.SEARCH_TYPE, "").getMethod().getName()); assertEquals("update", bindings.getBinding(RestOperationTypeEnum.UPDATE, "").getMethod().getName()); assertEquals("firstMethod", bindings.getBinding(RestOperationTypeEnum.EXTENDED_OPERATION_TYPE, "$firstMethod").getMethod().getName()); assertEquals("secondMethod", bindings.getBinding(RestOperationTypeEnum.EXTENDED_OPERATION_TYPE, "$secondMethod").getMethod().getName()); try { bindings.getBinding(RestOperationTypeEnum.EXTENDED_OPERATION_TYPE, "$thirdMethod"); fail(); } catch (NotImplementedOperationException e) { } }