RestResourceEditor extends JTextField { static void scanForTemplateParameters(RestResource resource) { for (RestResource restResource : RestUtils.extractAncestorsParentFirst(resource)) { for (String p : RestUtils.extractTemplateParams(restResource.getPath())) { if (!resourceOrParentHasProperty(restResource, p)) { RestParamProperty property = restResource.addProperty(p); property.setStyle(RestParamsPropertyHolder.ParameterStyle.TEMPLATE); String value = UISupport.prompt("Specify default value for parameter [" + p + "]", "Add Parameter", ""); if (value != null) { property.setDefaultValue(value); property.setValue(value); } } } } } RestResourceEditor(final RestResource editingRestResource, MutableBoolean updating); void openPopup(RestResource focusedResource); static final String REST_RESOURCE_EDITOR_TEXT_FIELD; }
@Test public void addingPathWithTemplateParametersAddsParametersToResource() { dialogs.mockPromptWithReturnValue("value"); RestResourceEditor.scanForTemplateParameters(templateResource); assertThat(templateResource.getParams().get("param2").getValue(), is("value")); }
@Test public void existingParameterOnParentNotAddedToChildWithPathContainingThatParameter() { dialogs.mockPromptWithReturnValue("value"); RestResourceEditor.scanForTemplateParameters(childResource); assertThat(parentResource.getParams().get("param1"), parameterWithValue("value")); assertThat(parentResource.getParams().get("param2"), is(nullValue())); assertThat(parentResource.getParams().get("existingparam"), parameterWithValue("existingvalue")); assertThat(childResource.getParams().get("param1"), is(nullValue())); assertThat(childResource.getParams().get("param2"), parameterWithValue("value")); assertThat(childResource.getParams().get("existingparam"), is(nullValue())); }