### Question:
SystemParameters { public void injectInto(DeploymentDescriptor descriptor) { for (Module module : descriptor.getModules()) { Map<String, Object> moduleSystemParameters = getModuleParameters(module); module.setParameters(MapUtil.merge(moduleSystemParameters, module.getParameters())); } for (Resource resource : descriptor.getResources()) { Map<String, Object> resourceSystemParameters = getResourceParameters(resource); resource.setParameters(MapUtil.merge(resourceSystemParameters, resource.getParameters())); } Map<String, Object> generalSystemParameters = getGeneralParameters(); descriptor.setParameters(MapUtil.merge(generalSystemParameters, descriptor.getParameters())); } SystemParameters(Builder builder); void injectInto(DeploymentDescriptor descriptor); static final int GENERATED_CREDENTIALS_LENGTH; static final String IDLE_HOST_SUFFIX; static final String ROUTE_PATH_PLACEHOLDER; static final String DEFAULT_HOST_BASED_IDLE_URI; static final String DEFAULT_HOST_BASED_URI; static final String DEFAULT_IDLE_URL; static final String DEFAULT_URL; }### Answer:
@Test void testDescriptorOverridesDefaults() throws Exception { SystemParameters testedClass = createSystemParameters(false); List<String> descriptorParameterFields = List.of(SupportedParameters.ORGANIZATION_NAME, SupportedParameters.SPACE_NAME, SupportedParameters.USER, SupportedParameters.DEFAULT_DOMAIN, SupportedParameters.CONTROLLER_URL, SupportedParameters.AUTHORIZATION_URL, SupportedParameters.DEPLOY_SERVICE_URL); DeploymentDescriptor descriptor = DeploymentDescriptor.createV3() .setParameters(createParametersMap(descriptorParameterFields)); testedClass.injectInto(descriptor); assertCustomValueMap(descriptorParameterFields, descriptor.getParameters()); }
@Test void testModuleParametersOverrideSystemParameters() throws Exception { SystemParameters testedClass = createSystemParameters(false); List<String> fields = List.of(SupportedParameters.PROTOCOL, SupportedParameters.TIMESTAMP, SupportedParameters.INSTANCES, SupportedParameters.APP_NAME, SupportedParameters.IDLE_DOMAIN, SupportedParameters.DOMAIN); Module moduleWithParameters = Module.createV3() .setName("first") .setParameters(createParametersMap(fields)); DeploymentDescriptor descriptor = DeploymentDescriptor.createV3() .setModules(List.of(moduleWithParameters)); testedClass.injectInto(descriptor); assertCustomValueMap(fields, descriptor.getModules() .get(0) .getParameters()); }
@Test void testResourceParameters() throws Exception { SystemParameters testedClass = createSystemParameters(false); Resource resourceOne = Resource.createV3() .setName("first"); Resource resourceTwo = Resource.createV3() .setName("second"); DeploymentDescriptor descriptor = DeploymentDescriptor.createV3() .setResources(List.of(resourceOne, resourceTwo)); testedClass.injectInto(descriptor); for (Resource resource : descriptor.getResources()) { verifyResourceParameters(resource.getName(), resource.getParameters()); } }
@Test void testResourceParametersOverrideSystemParameters() throws Exception { SystemParameters testedClass = createSystemParameters(false); List<String> fields = List.of(SupportedParameters.SERVICE_NAME, SupportedParameters.DEFAULT_CONTAINER_NAME, SupportedParameters.DEFAULT_XS_APP_NAME); Resource resourceWithParameters = Resource.createV3() .setName("first") .setParameters(createParametersMap(fields)); DeploymentDescriptor descriptor = DeploymentDescriptor.createV3() .setResources(List.of(resourceWithParameters)); testedClass.injectInto(descriptor); assertCustomValueMap(fields, descriptor.getResources() .get(0) .getParameters()); }