I claimed the issue FM-172 which requires tests to be added for RadiologyHandler. The test for getFHIRDiagnosticReportBySubjectName() in RadiologyHandler is throwing the following error:
java.lang.NullPointerException
at java.lang.StringBuilder.<init>(StringBuilder.java:112)
at ca.uhn.fhir.rest.client.apache.ApacheRestfulClientFactory.getHttpClient(ApacheRestfulClientFactory.java:72)
at ca.uhn.fhir.rest.client.apache.ApacheRestfulClientFactory.getHttpClient(ApacheRestfulClientFactory.java:48)
at ca.uhn.fhir.rest.client.RestfulClientFactory.newGenericClient(RestfulClientFactory.java:190)
at ca.uhn.fhir.context.FhirContext.newRestfulGenericClient(FhirContext.java:554)
at org.openmrs.module.fhir.api.util.FHIRRESTfulGenericClient.searchWhereReferenceAndToken(FHIRRESTfulGenericClient.java:62)
at org.openmrs.module.fhir.api.diagnosticreport.handler.RadiologyHandler.getFHIRDiagnosticReportBySubjectName(RadiologyHandler.java:78)
at org.openmrs.module.fhir.api.diagnosticreport.handler.RadiologyHandlerTest.getFHIRDiagnosticReportBySubjectName_retrunListOfDiagnosticReports(RadiologyHandlerTest.java:199)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:365)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:273)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:238)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:159)
at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:384)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:345)
at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:126)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:418)
On exploring, I found out that the variable serverBase in RadiologyHandler was returning null which was causing the exception. The result of FHIRUtils.getDiagnosticReportRadiologyBaseServerURL() is assigned to the serverBase variable and suspect the problem to be with the return of getDiagnosticReportRadiologyBaseServerURL() in FHIRUtils
@haripriya, am not exactly understanding the exact problem.
because am seeing a PR and the same time a you need a solution.
What does your Pr do ?? and for what problem do you need a solution . please make for me some clarification
The issue was to create a test file for RadiologyHander.java . Test for getFHIRDiagnosticReportBySubjectName() is the one added by me. The error is being caused because the variable serverBase is being set to null as getDiagnosticReportRadiologyBaseServerURL() in FHIRUtils file is returning null value (Previously written code) which is causing the exception in the test function.
Now @haripriya, since we don’t not include any dummy data when writing classes, thats the right expected behaviour .
What i mean , is whenever you write a test , ensure all associated variables to whichever method your writing a test for , have been assigned some values. So you just have to find a way of assigning some value to the variable serverBase for your testing-use-case otherwise , it would be expected to throw a nullPointerException
@haripriya whenever u call a method on a variable that has been declared as null it automatically throws a nullPointerException
Thanks @mozzy for your guidance on this
thats is just a crue , try to look at the suitable GlobalProperty method , and see which one can work best for you. in otherwords , when you asign a value to that GP in your tests , the variable servebaseurl will now be assigned a value…
java.lang.IllegalArgumentException: When using the client with HL7.org structures, you must specify the bundle return type for the client by adding ".returnBundle(org.hl7.fhir.instance.model.Bundle.class)" to your search method call before the ".execute()" method
at ca.uhn.fhir.rest.client.GenericClient$SearchInternal.execute(GenericClient.java:2110)
at ca.uhn.fhir.rest.client.GenericClient$SearchInternal.execute(GenericClient.java:1956)
at org.openmrs.module.fhir.api.util.FHIRRESTfulGenericClient.searchWhereReferenceAndToken(FHIRRESTfulGenericClient.java:67)
at org.openmrs.module.fhir.api.diagnosticreport.handler.RadiologyHandler.getFHIRDiagnosticReportBySubjectName(RadiologyHandler.java:77)
at org.openmrs.module.fhir.api.diagnosticreport.handler.RadiologyHandlerTest.getFHIRDiagnosticReportBySubjectName_retrunListOfDiagnosticReports(RadiologyHandlerTest.java:203)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:365)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:273)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:238)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:159)
at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:384)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:345)
at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:126)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:418)
This is what I’m getting when I set the global property
you must have made some mistake some where, passing an inapropriate or null parameter to this method.RadiologyHandlerTest.getFHIRDiagnosticReportBySubjectName_retrunListOfDiagnosticReports , that error is thrown when the method has been passed an illegal or inappropriate argument or null argument.