use of org.springframework.roo.addon.test.providers.TestCreatorProvider in project spring-roo by spring-projects.
the class TestCommands method getAllEntities.
@CliOptionAutocompleteIndicator(command = "test integration", param = "class", help = "Option `--class` must " + "be a non-abstract valid type. Please, use auto-complete feature to select it.")
public List<String> getAllEntities(ShellContext shellContext) {
// Get current value of class
String currentText = shellContext.getParameters().get("class");
// Create results to return
List<String> results = new ArrayList<String>();
// Look for all valid types for all available test creators
for (TestCreatorProvider creator : getAllTestCreators()) {
if (creator.isIntegrationTestCreationAvailable()) {
for (JavaType annotationType : creator.getValidTypes()) {
// Look for types with this annotation type
Set<ClassOrInterfaceTypeDetails> types = typeLocationService.findClassesOrInterfaceDetailsWithAnnotation(annotationType);
for (ClassOrInterfaceTypeDetails typeCid : types) {
String name = replaceTopLevelPackageString(typeCid.getType(), currentText);
if (!results.contains(name)) {
results.add(name);
}
}
}
}
}
return results;
}
use of org.springframework.roo.addon.test.providers.TestCreatorProvider in project spring-roo by spring-projects.
the class TestCommands method getValidTestCreatorsForType.
/**
* Gets all the valid implementations of TestCreatorProvider for a JavaType.
*
* @param type the JavaType to get the valid implementations.
* @return a `List` with the {@link TestCreatorProvider} valid
* implementations. Never `null`.
*/
public List<TestCreatorProvider> getValidTestCreatorsForType(JavaType type) {
// Get all Services implement TestCreatorProvider interface
if (this.testCreators.isEmpty()) {
try {
ServiceReference<?>[] references = this.context.getAllServiceReferences(TestCreatorProvider.class.getName(), null);
for (ServiceReference<?> ref : references) {
TestCreatorProvider testCreatorProvider = (TestCreatorProvider) this.context.getService(ref);
this.testCreators.add(testCreatorProvider);
}
} catch (InvalidSyntaxException e) {
LOGGER.warning("Cannot load TestCreatorProvider on TestCommands.");
return null;
}
}
List<TestCreatorProvider> validTestCreators = new ArrayList<TestCreatorProvider>();
for (TestCreatorProvider provider : this.testCreators) {
if (provider.isValid(type)) {
validTestCreators.add(provider);
}
}
return validTestCreators;
}
use of org.springframework.roo.addon.test.providers.TestCreatorProvider in project spring-roo by spring-projects.
the class TestCommands method getAllTestCreators.
/**
* Gets all the implementations of TestCreatorProvider
*
* @param type the JavaType to get the valid implementations.
* @return a `List` with the {@link TestCreatorProvider} valid
* implementations. Never `null`.
*/
public List<TestCreatorProvider> getAllTestCreators() {
// Get all Services implement TestCreatorProvider interface
if (this.testCreators.isEmpty()) {
try {
ServiceReference<?>[] references = this.context.getAllServiceReferences(TestCreatorProvider.class.getName(), null);
for (ServiceReference<?> ref : references) {
TestCreatorProvider testCreatorProvider = (TestCreatorProvider) this.context.getService(ref);
this.testCreators.add(testCreatorProvider);
}
} catch (InvalidSyntaxException e) {
LOGGER.warning("Cannot load TestCreatorProvider on TestCommands.");
return null;
}
}
return this.testCreators;
}
use of org.springframework.roo.addon.test.providers.TestCreatorProvider in project spring-roo by spring-projects.
the class TestCommands method getUnitTestCreationAvailable.
/**
* Checks all {@link TestCreatorProvider} implementations looking for any
* available for 'test unit' command.
*
* @return `true` if any of the implementations is available or
* `false` if none of the implementations are available.
*/
private boolean getUnitTestCreationAvailable() {
// Get all Services implement TestCreatorProvider interface
if (this.testCreators.isEmpty()) {
try {
ServiceReference<?>[] references = this.context.getAllServiceReferences(TestCreatorProvider.class.getName(), null);
for (ServiceReference<?> ref : references) {
TestCreatorProvider testCreatorProvider = (TestCreatorProvider) this.context.getService(ref);
this.testCreators.add(testCreatorProvider);
}
} catch (InvalidSyntaxException e) {
LOGGER.warning("Cannot load TestCreatorProvider on TestCommands.");
return false;
}
}
for (TestCreatorProvider provider : this.testCreators) {
if (provider.isUnitTestCreationAvailable()) {
return true;
}
}
return false;
}
use of org.springframework.roo.addon.test.providers.TestCreatorProvider in project spring-roo by spring-projects.
the class TestOperationsImpl method createIntegrationTest.
@Override
public void createIntegrationTest(JavaType type, Pom module) {
// Check if specified type exists in the project
String physicalTypeIdentifier = typeLocationService.getPhysicalTypeIdentifier(type);
if (physicalTypeIdentifier == null) {
throw new IllegalArgumentException(String.format("The class '%s' doesn't exists in the project. Please, specify an existing class", type));
}
// Adding integration test dependencies
List<TestCreatorProvider> validTestCreators = getValidTestCreatorsForType(type);
if (!validTestCreators.isEmpty()) {
addIntegrationTestDependencies(module.getModuleName());
}
// Creating tests
if (validTestCreators.isEmpty()) {
throw new IllegalArgumentException("Unable to find a valid test creator for this type of class. " + "Please, select another type of class to generate the test, such a repository.");
} else {
for (TestCreatorProvider creator : validTestCreators) {
creator.createIntegrationTest(type, module);
}
}
}
Aggregations