Search in sources :

Example 1 with ScannerPluginRepository

use of com.buschmais.jqassistant.core.scanner.spi.ScannerPluginRepository in project jqa-core-framework by buschmais.

the class PluginRepositoryImplTest method getScannerPluginProperties.

private Map<String, Object> getScannerPluginProperties(PluginRepository pluginRepository, Map<String, Object> properties) {
    ScannerPluginRepository scannerPluginRepository = pluginRepository.getScannerPluginRepository();
    ScannerContext scannerContext = mock(ScannerContext.class);
    Map<String, ScannerPlugin<?, ?>> scannerPlugins = scannerPluginRepository.getScannerPlugins(scannerContext, properties);
    assertThat(scannerPlugins).isNotEmpty();
    for (ScannerPlugin<?, ?> scannerPlugin : scannerPlugins.values()) {
        if (scannerPlugin instanceof TestScannerPlugin) {
            return ((TestScannerPlugin) scannerPlugin).getProperties();
        }
    }
    return null;
}
Also used : TestScannerPlugin(com.buschmais.jqassistant.core.plugin.impl.plugin.TestScannerPlugin) ScannerPluginRepository(com.buschmais.jqassistant.core.scanner.spi.ScannerPluginRepository) TestScannerPlugin(com.buschmais.jqassistant.core.plugin.impl.plugin.TestScannerPlugin) ScannerPlugin(com.buschmais.jqassistant.core.scanner.api.ScannerPlugin) ScannerContext(com.buschmais.jqassistant.core.scanner.api.ScannerContext)

Example 2 with ScannerPluginRepository

use of com.buschmais.jqassistant.core.scanner.spi.ScannerPluginRepository in project jqa-core-framework by buschmais.

the class ScannerPluginRepositoryTest method scopes.

@Test
void scopes() {
    PluginConfigurationReader pluginConfigurationReader = new PluginConfigurationReaderImpl();
    ScannerPluginRepository repository = new ScannerPluginRepositoryImpl(pluginConfigurationReader);
    assertThat(repository.getScope("test:foo"), Matchers.equalTo(TestScope.FOO));
    assertThat(repository.getScope("Test:foo"), Matchers.equalTo(TestScope.FOO));
    assertThat(repository.getScope("test:Foo"), Matchers.equalTo(TestScope.FOO));
}
Also used : PluginConfigurationReader(com.buschmais.jqassistant.core.plugin.api.PluginConfigurationReader) ScannerPluginRepository(com.buschmais.jqassistant.core.scanner.spi.ScannerPluginRepository) Test(org.junit.jupiter.api.Test)

Example 3 with ScannerPluginRepository

use of com.buschmais.jqassistant.core.scanner.spi.ScannerPluginRepository in project jqa-core-framework by buschmais.

the class ScannerImplTest method pluginPipeline.

/**
 * Verifies correct execution of the pipeline for dependent and nested scanner
 * plugins:
 *
 * <ul>
 * <li>A {@link TestItem} is scanned initially by
 * {@link TestItemScannerPlugin}.</li>
 * <li>The created {@link TestItemDescriptor} is then passed to the
 * {@link DependentTestItemScannerPlugin}.</li>
 * <li>The {@link DependentTestItemScannerPlugin} triggers a separate scan using
 * the {@link TestScope} which activates the
 * {@link NestedTestItemScannerPlugin}.</li>
 * </ul>
 */
@Test
void pluginPipeline() {
    Store store = mock(Store.class);
    ScannerContext scannerContext = new ScannerContextImpl(store, OUTPUT_DIRECTORY);
    when(store.create(any(Class.class))).thenAnswer((Answer<Descriptor>) invocation -> {
        Class<? extends Descriptor> descriptorType = (Class<? extends Descriptor>) invocation.getArguments()[0];
        return mock(descriptorType);
    });
    when(store.addDescriptorType(any(Descriptor.class), any(Class.class))).thenAnswer((Answer<Descriptor>) invocation -> {
        Class<? extends Descriptor> descriptorType = (Class<? extends Descriptor>) invocation.getArguments()[1];
        return mock(descriptorType);
    });
    Map<String, ScannerPlugin<?, ?>> scannerPlugins = new HashMap<>();
    scannerPlugins.put("TestScanner", new TestItemScannerPlugin());
    scannerPlugins.put("DependentTestScanner", new DependentTestItemScannerPlugin());
    scannerPlugins.put("NestedTestScanner", new NestedTestItemScannerPlugin());
    doReturn(scannerPlugins).when(scannerPluginRepository).getScannerPlugins(scannerContext, emptyMap());
    Scanner scanner = new ScannerImpl(new ScannerConfiguration(), emptyMap(), scannerContext, scannerPluginRepository);
    Descriptor descriptor = scanner.scan(new TestItem(), "/", DefaultScope.NONE);
    assertThat(descriptor, instanceOf(DependentTestItemDescriptor.class));
    verify(store).create(eq(TestItemDescriptor.class));
    verify(store).addDescriptorType(any(TestItemDescriptor.class), eq(NestedTestItemDescriptor.class));
    verify(store).addDescriptorType(any(NestedTestItemDescriptor.class), eq(DependentTestItemDescriptor.class));
}
Also used : Strictness(org.mockito.quality.Strictness) BeforeEach(org.junit.jupiter.api.BeforeEach) Collections.emptyMap(java.util.Collections.emptyMap) CoreMatchers(org.hamcrest.CoreMatchers) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) Properties(java.util.Properties) MockitoSettings(org.mockito.junit.jupiter.MockitoSettings) ScannerPluginRepository(com.buschmais.jqassistant.core.scanner.spi.ScannerPluginRepository) Mock(org.mockito.Mock) IOException(java.io.IOException) HashMap(java.util.HashMap) File(java.io.File) Store(com.buschmais.jqassistant.core.store.api.Store) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) Answer(org.mockito.stubbing.Answer) com.buschmais.jqassistant.core.scanner.api(com.buschmais.jqassistant.core.scanner.api) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Map(java.util.Map) Descriptor(com.buschmais.jqassistant.core.store.api.model.Descriptor) Assert.fail(org.junit.Assert.fail) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assert(org.junit.Assert) Mockito.any(org.mockito.Mockito.any) HashMap(java.util.HashMap) Store(com.buschmais.jqassistant.core.store.api.Store) Descriptor(com.buschmais.jqassistant.core.store.api.model.Descriptor) Test(org.junit.jupiter.api.Test)

Aggregations

ScannerPluginRepository (com.buschmais.jqassistant.core.scanner.spi.ScannerPluginRepository)3 Test (org.junit.jupiter.api.Test)2 PluginConfigurationReader (com.buschmais.jqassistant.core.plugin.api.PluginConfigurationReader)1 TestScannerPlugin (com.buschmais.jqassistant.core.plugin.impl.plugin.TestScannerPlugin)1 com.buschmais.jqassistant.core.scanner.api (com.buschmais.jqassistant.core.scanner.api)1 ScannerContext (com.buschmais.jqassistant.core.scanner.api.ScannerContext)1 ScannerPlugin (com.buschmais.jqassistant.core.scanner.api.ScannerPlugin)1 Store (com.buschmais.jqassistant.core.store.api.Store)1 Descriptor (com.buschmais.jqassistant.core.store.api.model.Descriptor)1 File (java.io.File)1 IOException (java.io.IOException)1 Collections.emptyMap (java.util.Collections.emptyMap)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Properties (java.util.Properties)1 CoreMatchers (org.hamcrest.CoreMatchers)1 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)1 Assert (org.junit.Assert)1 Assert.fail (org.junit.Assert.fail)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1