Skip to content

Commit

Permalink
#491 Deleted @teststore annotation (#559)
Browse files Browse the repository at this point in the history
  • Loading branch information
yaseno2186 authored Jul 28, 2024
1 parent d95ec15 commit 7bec0d6
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@

import java.io.File;
import java.io.IOException;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Method;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLDecoder;
import java.nio.charset.Charset;
import java.util.*;
Expand Down Expand Up @@ -47,7 +41,6 @@
import com.buschmais.jqassistant.core.scanner.spi.ScannerPluginRepository;
import com.buschmais.jqassistant.core.store.api.Store;
import com.buschmais.jqassistant.core.store.api.StoreFactory;
import com.buschmais.jqassistant.core.store.api.configuration.Remote;
import com.buschmais.xo.api.Query;
import com.buschmais.xo.api.Query.Result.CompositeRowObject;

Expand Down Expand Up @@ -82,8 +75,6 @@ public abstract class AbstractPluginIT {

private File outputDirectory;

private TestStore testStore;

protected Store store;
protected InMemoryReportPlugin reportPlugin;
protected RuleSet ruleSet;
Expand All @@ -107,14 +98,13 @@ public static void destroyPluginRepository() {
public void beforeEach(TestInfo testInfo) throws IOException, RuleException {
Method method = testInfo.getTestMethod()
.orElseThrow(() -> new AssertionError("Unable to get the test method for test '" + testInfo.getDisplayName() + "'."));
testStore = method.getAnnotation(TestStore.class);
ConfigurationBuilder configurationBuilder = createConfigurationBuilder();
configure(configurationBuilder);
Configuration configuration = createConfiguration(configurationBuilder);
workingDirectory = new File(".");
outputDirectory = new File(workingDirectory, "target/jqassistant");
outputDirectory.mkdirs();
startStore(configuration.store(), testStore);
startStore(configuration.store());
initializeRuleSet(configuration);
initializeReportPlugin(configuration);
}
Expand All @@ -128,35 +118,6 @@ protected List<String> getConfigurationProfiles() {

private ConfigurationBuilder createConfigurationBuilder() {
ConfigurationBuilder configurationBuilder = new ConfigurationBuilder("ITConfigSource", 110);
TestStore.Type type = testStore != null ? testStore.type() : TestStore.Type.MEMORY;
switch (type) {
case FILE:
break;
case MEMORY:
try {
configurationBuilder.with(com.buschmais.jqassistant.core.store.api.configuration.Store.class,
com.buschmais.jqassistant.core.store.api.configuration.Store.URI, new URI(STORE_URI_MEMORY));
} catch (URISyntaxException e) {
throw new IllegalArgumentException("Cannot create store URI", e);
}
break;
case REMOTE:
try {
configurationBuilder.with(com.buschmais.jqassistant.core.store.api.configuration.Store.class,
com.buschmais.jqassistant.core.store.api.configuration.Store.URI, new URI(STORE_URI_REMOTE));
} catch (URISyntaxException e) {
throw new IllegalArgumentException("Cannot create store URI", e);
}
configurationBuilder.with(Remote.class, Remote.ENCRYPTION, "NONE");
configurationBuilder.with(Remote.class, Remote.USERNAME, "neo4j");
configurationBuilder.with(Remote.class, Remote.PASSWORD, "jqassistant");
Properties properties = new Properties();
properties.put("neo4j.remote.statement.log.level", "info");
configurationBuilder.with(Remote.class, Remote.PROPERTIES, properties);
break;
default:
throw new AssertionError("Test store type not supported: " + type);
}
configurationBuilder.with(Report.class, Report.PROPERTIES, getReportProperties());
return configurationBuilder;
}
Expand Down Expand Up @@ -239,13 +200,10 @@ protected Map<String, Object> getRuleInterpreterProperties() {
/**
* Initializes and resets the store.
*/
private void startStore(com.buschmais.jqassistant.core.store.api.configuration.Store storeConfiguration, TestStore testStore) {
private void startStore(com.buschmais.jqassistant.core.store.api.configuration.Store storeConfiguration) {
StoreFactory storeFactory = new StoreFactory(pluginRepository.getStorePluginRepository(), plugins -> emptyList());
store = storeFactory.getStore(storeConfiguration, () -> TEST_STORE_DIRECTORY);
store.start();
if (testStore == null || testStore.reset()) {
store.reset();
}
}

/**
Expand Down Expand Up @@ -435,21 +393,6 @@ protected void executeGroup(String id, Map<String, String> parameters) throws Ru
getAnalyzer(parameters).execute(ruleSet, ruleSelection);
}

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
protected @interface TestStore {

boolean reset() default true;

Type type() default Type.FILE;

enum Type {
FILE,
MEMORY,
REMOTE;
}
}

/**
* Represents a test result which allows fetching values by row or columns.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,15 @@ class JavaRuntimePT extends AbstractJavaPluginIT {
* variable java.home.
*/
@Test
@TestStore(type = TestStore.Type.FILE)
void javaRuntime01Scan() {
void javaRuntime01Scan() throws RuleException {
String javaHome = System.getProperty("java.home");
assumeNotNull("java.home is not set.", javaHome);
File runtimeJar = new File(javaHome + "/lib/rt.jar");
assumeTrue("Java Runtime JAR not found: " + runtimeJar.getAbsolutePath(), runtimeJar.exists());
store.beginTransaction();
getScanner().scan(runtimeJar, runtimeJar.getAbsolutePath(), null);
store.commitTransaction();
}

@Test
@TestStore(type = TestStore.Type.FILE, reset = false)
public void javaRuntime02VirtualDependsOn() throws RuleException {
applyConcept("java:VirtualDependsOn");
}

@Test
@TestStore(type = TestStore.Type.FILE, reset = false)
public void javaRuntime03VirtualInvokes() throws RuleException {
applyConcept("java:VirtualInvokes");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ void cypherAnchorOnSequenceItem() {
assertThat(result).hasSize(1);
}

@TestStore(type = TestStore.Type.MEMORY)
@Test
void cypherAnchorOnSequenceItemResultsInToSequences() {
readSourceDocument("/anchor/toplevel-sequence-anchor-on-sequence.yml");
Expand All @@ -151,7 +150,6 @@ void cypherAnchorOnSequenceItemResultsInToSequences() {
assertThat(sequences).hasSize(2);
}

@TestStore(type = TestStore.Type.MEMORY)
@Test
void cypherAnchorOnSequenceItemResultsInCorrectSettingOfFirstAndLand() {
readSourceDocument("/anchor/toplevel-sequence-anchor-on-sequence.yml");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

class GH5AnchorsInAComplexKeyIT extends AbstractYAMLPluginIT {

@TestStore(reset = false, type = TestStore.Type.MEMORY)
@Test
void anchorOnlyInAComplexKey() {
readSourceDocument("/anchorincomplexkey/anchor-only.yaml");
Expand All @@ -19,7 +18,6 @@ void anchorOnlyInAComplexKey() {
assertThat(testResult.getColumns()).containsKeys("n");
}

@TestStore(reset = false, type = TestStore.Type.MEMORY)
@Test
void anchorInKeyAndAliasAsValue() {
readSourceDocument("/anchorincomplexkey/anchor-and-alias.yaml");
Expand Down

0 comments on commit 7bec0d6

Please sign in to comment.