Search in sources :

Example 1 with TestCreatorProvider

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;
}
Also used : JavaType(org.springframework.roo.model.JavaType) ArrayList(java.util.ArrayList) TestCreatorProvider(org.springframework.roo.addon.test.providers.TestCreatorProvider) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails) CliOptionAutocompleteIndicator(org.springframework.roo.shell.CliOptionAutocompleteIndicator)

Example 2 with TestCreatorProvider

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;
}
Also used : ArrayList(java.util.ArrayList) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) TestCreatorProvider(org.springframework.roo.addon.test.providers.TestCreatorProvider) ServiceReference(org.osgi.framework.ServiceReference)

Example 3 with TestCreatorProvider

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;
}
Also used : InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) TestCreatorProvider(org.springframework.roo.addon.test.providers.TestCreatorProvider) ServiceReference(org.osgi.framework.ServiceReference)

Example 4 with TestCreatorProvider

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;
}
Also used : InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) TestCreatorProvider(org.springframework.roo.addon.test.providers.TestCreatorProvider) ServiceReference(org.osgi.framework.ServiceReference)

Example 5 with TestCreatorProvider

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);
        }
    }
}
Also used : TestCreatorProvider(org.springframework.roo.addon.test.providers.TestCreatorProvider)

Aggregations

TestCreatorProvider (org.springframework.roo.addon.test.providers.TestCreatorProvider)9 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)5 ServiceReference (org.osgi.framework.ServiceReference)5 ArrayList (java.util.ArrayList)4 ClassOrInterfaceTypeDetails (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)2 JavaType (org.springframework.roo.model.JavaType)2 CliOptionAutocompleteIndicator (org.springframework.roo.shell.CliOptionAutocompleteIndicator)2