use of org.springframework.roo.shell.Completion in project spring-roo by spring-projects.
the class PackagingProviderConverterTest method testGetAllPossibleValues.
@Test
public void testGetAllPossibleValues() {
// Set up
final PackagingProvider[] providers = { mockCoreJarPackaging, mockCustomJarPackaging, mockWarPackaging };
when(mockPackagingProviderRegistry.getAllPackagingProviders()).thenReturn(Arrays.asList(providers));
final List<Completion> expectedCompletions = new ArrayList<Completion>();
for (final PackagingProvider provider : providers) {
expectedCompletions.add(new Completion(provider.getId().toUpperCase()));
}
final List<Completion> completions = new ArrayList<Completion>();
// Invoke
final boolean addSpace = converter.getAllPossibleValues(completions, PackagingProvider.class, "ignored", null, null);
// Check
assertTrue(addSpace);
assertEquals(expectedCompletions.size(), completions.size());
assertTrue("Expected " + expectedCompletions + " but was " + completions, completions.containsAll(expectedCompletions));
}
use of org.springframework.roo.shell.Completion in project spring-roo by spring-projects.
the class JavaTypeConverterTest method testGetAllPossibleValuesInProjectWhenModulePrefixIsUsed.
@Test
public void testGetAllPossibleValuesInProjectWhenModulePrefixIsUsed() {
// Set up
@SuppressWarnings("unchecked") final List<Completion> mockCompletions = mock(List.class);
when(mockProjectOperations.isFocusedProjectAvailable()).thenReturn(true);
final String otherModuleName = "core";
final Pom mockOtherModule = mock(Pom.class);
when(mockOtherModule.getModuleName()).thenReturn(otherModuleName);
when(mockProjectOperations.getPomFromModuleName(otherModuleName)).thenReturn(mockOtherModule);
final String topLevelPackage = "com.example";
when(mockTypeLocationService.getTopLevelPackageForModule(mockOtherModule)).thenReturn(topLevelPackage);
final String focusedModuleName = "web";
when(mockProjectOperations.getModuleNames()).thenReturn(Arrays.asList(focusedModuleName, otherModuleName));
final String modulePath = "/path/to/it";
when(mockOtherModule.getPath()).thenReturn(modulePath);
final JavaType type1 = new JavaType("com.example.web.ShouldBeFound");
final JavaType type2 = new JavaType("com.example.foo.ShouldNotBeFound");
when(mockTypeLocationService.getTypesForModule(mockOtherModule)).thenReturn(Arrays.asList(type1, type2));
// Invoke
converter.getAllPossibleValues(mockCompletions, JavaType.class, otherModuleName + MODULE_PATH_SEPARATOR + "~.web", OptionContexts.PROJECT, null);
// Check
verify(mockCompletions).add(new Completion(focusedModuleName + MODULE_PATH_SEPARATOR, AnsiEscapeCode.decorate(focusedModuleName + MODULE_PATH_SEPARATOR, AnsiEscapeCode.FG_CYAN), "Modules", 0));
// prefix + topLevelPackage, formattedPrefix + topLevelPackage, heading
final String formattedPrefix = decorate(otherModuleName + MODULE_PATH_SEPARATOR, FG_CYAN);
final String prefix = otherModuleName + MODULE_PATH_SEPARATOR;
verify(mockCompletions).add(new Completion(prefix + topLevelPackage, formattedPrefix + topLevelPackage, "", 1));
verify(mockCompletions).add(new Completion(prefix + "~.web.ShouldBeFound", formattedPrefix + "~.web.ShouldBeFound", "", 1));
verifyNoMoreInteractions(mockCompletions);
}
use of org.springframework.roo.shell.Completion in project spring-roo by spring-projects.
the class JavaTypeConverterTest method testGetAllPossibleValuesInProjectWhenNoModulePrefixIsUsed.
@Test
public void testGetAllPossibleValuesInProjectWhenNoModulePrefixIsUsed() {
// Set up
@SuppressWarnings("unchecked") final List<Completion> mockCompletions = mock(List.class);
when(mockProjectOperations.isFocusedProjectAvailable()).thenReturn(true);
final Pom mockFocusedModule = mock(Pom.class);
when(mockProjectOperations.getFocusedModule()).thenReturn(mockFocusedModule);
final String topLevelPackage = "com.example";
when(mockTypeLocationService.getTopLevelPackageForModule(mockFocusedModule)).thenReturn(topLevelPackage);
final String focusedModuleName = "web";
when(mockFocusedModule.getModuleName()).thenReturn(focusedModuleName);
final String modulePath = "/path/to/it";
when(mockFocusedModule.getPath()).thenReturn(modulePath);
final String otherModuleName = "core";
when(mockProjectOperations.getModuleNames()).thenReturn(Arrays.asList(focusedModuleName, otherModuleName));
final JavaType type1 = new JavaType("com.example.Foo");
final JavaType type2 = new JavaType("com.example.sub.Bar");
when(mockTypeLocationService.getTypesForModule(mockFocusedModule)).thenReturn(Arrays.asList(type1, type2));
// Invoke
converter.getAllPossibleValues(mockCompletions, JavaType.class, "", OptionContexts.PROJECT, null);
// Check
verify(mockCompletions).add(new Completion(otherModuleName + MODULE_PATH_SEPARATOR, AnsiEscapeCode.decorate(otherModuleName + MODULE_PATH_SEPARATOR, AnsiEscapeCode.FG_CYAN), "Modules", 0));
verify(mockCompletions).add(new Completion(topLevelPackage, topLevelPackage, focusedModuleName, 1));
verify(mockCompletions).add(new Completion("~.Foo", "~.Foo", focusedModuleName, 1));
verify(mockCompletions).add(new Completion("~.sub.Bar", "~.sub.Bar", focusedModuleName, 1));
verifyNoMoreInteractions(mockCompletions);
}
use of org.springframework.roo.shell.Completion in project spring-roo by spring-projects.
the class FileConverter method populate.
protected void populate(final List<Completion> completions, final String adjustedUserInput, final String originalUserInput, final String directoryData) {
final File directory = new File(directoryData);
if (!directory.isDirectory()) {
return;
}
for (final File file : directory.listFiles()) {
if (adjustedUserInput == null || adjustedUserInput.length() == 0 || file.getName().toLowerCase().startsWith(adjustedUserInput.toLowerCase())) {
String completion = "";
if (directoryData.length() > 0) {
completion += directoryData;
}
completion += file.getName();
completion = convertCompletionBackIntoUserInputStyle(originalUserInput, completion);
if (file.isDirectory()) {
completions.add(new Completion(completion + File.separator));
} else {
completions.add(new Completion(completion));
}
}
}
}
use of org.springframework.roo.shell.Completion in project spring-roo by spring-projects.
the class JmsCommands method returnApplicationPackages.
@CliOptionAutocompleteIndicator(command = "jms receiver", param = "endpoint", validate = false, includeSpaceOnFinish = false, help = "--endpoint parameter parameter is the service where will be added the " + "support to send emails.")
public List<String> returnApplicationPackages(ShellContext shellContext) {
List<String> applicationPackages = new ArrayList<String>();
// Get only application modules
StringBuffer matcher = new StringBuffer("feature[");
matcher.append(ModuleFeatureName.APPLICATION).append("]");
JavaPackageConverter converter = (JavaPackageConverter) getJavaPackageConverterService().get(0);
List<Completion> completions = new ArrayList<Completion>();
converter.getAllPossibleValues(completions, String.class, shellContext.getParameters().get("endpoint"), matcher.toString(), null);
for (Completion completion : completions) {
applicationPackages.add(completion.getValue());
}
return applicationPackages;
}
Aggregations