### Question:
PackageInstallerSvcImpl implements IPackageInstallerSvc { boolean validForUpload(IBaseResource theResource) { String resourceType = myFhirContext.getResourceType(theResource); if ("SearchParameter".equals(resourceType)) { String code = SearchParameterUtil.getCode(myFhirContext, theResource); if (defaultString(code).startsWith("_")) { return false; } String expression = SearchParameterUtil.getExpression(myFhirContext, theResource); if (isBlank(expression)) { return false; } if (SearchParameterUtil.getBaseAsStrings(myFhirContext, theResource).isEmpty()) { return false; } } List<IPrimitiveType> statusTypes = myFhirContext.newFhirPath().evaluate(theResource, "status", IPrimitiveType.class); if (statusTypes.size() > 0) { if (!statusTypes.get(0).getValueAsString().equals("active")) { return false; } } return true; } PackageInstallerSvcImpl(); @PostConstruct void initialize(); @SuppressWarnings("ConstantConditions") @Override PackageInstallOutcomeJson install(PackageInstallationSpec theInstallationSpec); static List<String> DEFAULT_INSTALL_TYPES; }### Answer:
@Test public void testValidForUpload_SearchParameterWithMetaParam() { SearchParameter sp = new SearchParameter(); sp.setCode("_id"); assertFalse(mySvc.validForUpload(sp)); }
@Test public void testValidForUpload_SearchParameterWithNoBase() { SearchParameter sp = new SearchParameter(); sp.setCode("name"); sp.setExpression("Patient.name"); sp.setStatus(Enumerations.PublicationStatus.ACTIVE); assertFalse(mySvc.validForUpload(sp)); }
@Test public void testValidForUpload_SearchParameterWithNoExpression() { SearchParameter sp = new SearchParameter(); sp.setCode("name"); sp.addBase("Patient"); sp.setStatus(Enumerations.PublicationStatus.ACTIVE); assertFalse(mySvc.validForUpload(sp)); }
@Test public void testValidForUpload_GoodSearchParameter() { SearchParameter sp = new SearchParameter(); sp.setCode("name"); sp.addBase("Patient"); sp.setExpression("Patient.name"); sp.setStatus(Enumerations.PublicationStatus.ACTIVE); assertTrue(mySvc.validForUpload(sp)); }