From c5f48b6b47754db0310de376fab6e5ab6012c21d Mon Sep 17 00:00:00 2001 From: James Agnew Date: Tue, 29 Oct 2019 13:24:43 -0400 Subject: [PATCH] Add tests --- .../dao/r4/SearchParamExtractorR4Test.java | 132 ++++++++++-------- 1 file changed, 74 insertions(+), 58 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/SearchParamExtractorR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/SearchParamExtractorR4Test.java index 36720d8b241..10f7cf59452 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/SearchParamExtractorR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/SearchParamExtractorR4Test.java @@ -37,64 +37,7 @@ public class SearchParamExtractorR4Test { @Before public void before() { - mySearchParamRegistry = new ISearchParamRegistry() { - @Override - public void forceRefresh() { - // nothing - } - - @Override - public RuntimeSearchParam getActiveSearchParam(String theResourceName, String theParamName) { - return getActiveSearchParams(theResourceName).get(theParamName); - } - - @Override - public boolean refreshCacheIfNecessary() { - // nothing - return false; - } - - @Override - public Map> getActiveSearchParams() { - throw new UnsupportedOperationException(); - } - - @Override - public Map getActiveSearchParams(String theResourceName) { - Map sps = new HashMap<>(); - RuntimeResourceDefinition nextResDef = ourCtx.getResourceDefinition(theResourceName); - for (RuntimeSearchParam nextSp : nextResDef.getSearchParams()) { - sps.put(nextSp.getName(), nextSp); - } - - return sps; - } - - @Override - public List getActiveUniqueSearchParams(String theResourceName, Set theParamNames) { - throw new UnsupportedOperationException(); - } - - @Override - public List getActiveUniqueSearchParams(String theResourceName) { - throw new UnsupportedOperationException(); - } - - @Override - public void requestRefresh() { - // nothing - } - - @Override - public RuntimeSearchParam getSearchParamByName(RuntimeResourceDefinition theResourceDef, String theParamName) { - return null; - } - - @Override - public Collection getSearchParamsByResourceType(RuntimeResourceDefinition theResourceDef) { - return null; - } - }; + mySearchParamRegistry = new MySearchParamRegistry(); } @@ -112,6 +55,20 @@ public class SearchParamExtractorR4Test { assertEquals("CODE", token.getValue()); } + @Test + public void testTokenOnSearchParamContext() { + SearchParameter sp = new SearchParameter(); + sp.addUseContext().setCode(new Coding().setSystem("http://system").setCode("code")); + + SearchParamExtractorR4 extractor = new SearchParamExtractorR4(new ModelConfig(), ourCtx, ourValidationSupport, mySearchParamRegistry); + Set tokens = extractor.extractSearchParamTokens(sp); + assertEquals(1, tokens.size()); + ResourceIndexedSearchParamToken token = (ResourceIndexedSearchParamToken) tokens.iterator().next(); + assertEquals("context-type", token.getParamName()); + assertEquals("http://system", token.getSystem()); + assertEquals("code", token.getValue()); + } + @Test public void testReferenceWithResolve() { Encounter enc = new Encounter(); @@ -171,6 +128,65 @@ public class SearchParamExtractorR4Test { assertEquals(4, links.size()); } + private static class MySearchParamRegistry implements ISearchParamRegistry { + @Override + public void forceRefresh() { + // nothing + } + + @Override + public RuntimeSearchParam getActiveSearchParam(String theResourceName, String theParamName) { + return getActiveSearchParams(theResourceName).get(theParamName); + } + + @Override + public boolean refreshCacheIfNecessary() { + // nothing + return false; + } + + @Override + public Map> getActiveSearchParams() { + throw new UnsupportedOperationException(); + } + + @Override + public Map getActiveSearchParams(String theResourceName) { + Map sps = new HashMap<>(); + RuntimeResourceDefinition nextResDef = ourCtx.getResourceDefinition(theResourceName); + for (RuntimeSearchParam nextSp : nextResDef.getSearchParams()) { + sps.put(nextSp.getName(), nextSp); + } + + return sps; + } + + @Override + public List getActiveUniqueSearchParams(String theResourceName, Set theParamNames) { + throw new UnsupportedOperationException(); + } + + @Override + public List getActiveUniqueSearchParams(String theResourceName) { + throw new UnsupportedOperationException(); + } + + @Override + public void requestRefresh() { + // nothing + } + + @Override + public RuntimeSearchParam getSearchParamByName(RuntimeResourceDefinition theResourceDef, String theParamName) { + return null; + } + + @Override + public Collection getSearchParamsByResourceType(RuntimeResourceDefinition theResourceDef) { + return null; + } + } + @AfterClass public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest();