use of org.springframework.roo.addon.test.providers.TestCreatorProvider in project spring-roo by spring-projects.
the class TestOperationsImpl method createUnitTest.
@Override
public void createUnitTest(JavaType type) {
// 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 unit test dependencies
List<TestCreatorProvider> validTestCreators = getValidTestCreatorsForType(type);
if (!validTestCreators.isEmpty()) {
addUnitTestDependencies(type.getModule());
}
// 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 as an entity.");
} else {
for (TestCreatorProvider creator : validTestCreators) {
creator.createUnitTest(type);
}
}
}
use of org.springframework.roo.addon.test.providers.TestCreatorProvider in project spring-roo by spring-projects.
the class TestCommands method getClassPosibleValues.
@CliOptionAutocompleteIndicator(command = "test unit", help = "Option `--class` must " + "be a non-abstract valid type. Please, use auto-complete feature to select it.", param = "class")
public List<String> getClassPosibleValues(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.isUnitTestCreationAvailable()) {
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) && !typeCid.isAbstract()) {
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 getIntegrationTestCreationAvailable.
/**
* Checks all {@link TestCreatorProvider} implementations looking for any
* available for 'test integration' command.
*
* @return `true` if any of the implementations is available or
* `false` if none of the implementations are available.
*/
private boolean getIntegrationTestCreationAvailable() {
// 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 UnitTestCommands.");
return false;
}
}
for (TestCreatorProvider provider : this.testCreators) {
if (provider.isIntegrationTestCreationAvailable()) {
return true;
}
}
return false;
}
use of org.springframework.roo.addon.test.providers.TestCreatorProvider in project spring-roo by spring-projects.
the class TestOperationsImpl 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`.
*/
private 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 TestOperationsImpl.");
return null;
}
}
List<TestCreatorProvider> validTestCreators = new ArrayList<TestCreatorProvider>();
for (TestCreatorProvider provider : this.testCreators) {
if (provider.isValid(type)) {
validTestCreators.add(provider);
}
}
return validTestCreators;
}
Aggregations