Skip to content

Commit

Permalink
TSK-1183: Update to Spring Boot 2.2.6
Browse files Browse the repository at this point in the history
  • Loading branch information
holgerhagen committed Apr 13, 2020
1 parent e8433ab commit 646583f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public SampleDataGenerator(DataSource dataSource, String schema, ZonedDateTime n
}

public void generateSampleData() {
LOGGER.debug("entry to generateSampleData()");
runScripts(
(runner) -> {
clearDb();
Expand All @@ -63,31 +64,40 @@ public void generateSampleData() {
scripts = SampleDataProvider.getScriptsWithEvents();
cacheKey = CACHED_EVENTSAMPLE;
} else {
scripts = SampleDataProvider.getDefaultScripts();
scripts = SampleDataProvider.getSampleDataCreationScripts();
cacheKey = CACHED_SAMPLE;
}
executeAndCacheScripts(scripts, cacheKey);
});
LOGGER.debug("exit from generateSampleData()");
}

public void generateTestData() {
LOGGER.debug("entry to generateTestData()");
Stream<String> scripts = SampleDataProvider.getTestDataScripts();
executeAndCacheScripts(scripts, CACHED_TEST);
LOGGER.debug("exit from generateTestData()");
}

public void generateMonitorData() {
LOGGER.debug("entry to generateMonitorData()");
Stream<String> scripts = SampleDataProvider.getMonitorDataScripts();
executeAndCacheScripts(scripts, CACHED_MONITOR);
LOGGER.debug("exit from generateMonitorData()");
}

public void clearDb() {
LOGGER.debug("entry to clearDb()");
Stream<String> scripts = SampleDataProvider.getScriptsToClearDatabase();
executeAndCacheScripts(scripts, CACHED_CLEARDB);
LOGGER.debug("exit from clearDb()");
}

public void dropDb() {
LOGGER.debug("entry to dropDb()");
Stream<String> scripts = SampleDataProvider.getScriptsToDropDatabase();
executeAndCacheScripts(scripts, CACHED_DROPDB);
LOGGER.debug("exit from dropDb()");
}

boolean tableExists(String table) {
Expand Down Expand Up @@ -139,13 +149,15 @@ private void runScripts(Consumer<ScriptRunner> consumer) {
}

private void executeAndCacheScripts(Stream<String> scripts, String cacheKey) {
LOGGER.debug("entry to executeAndCacheScripts(scripts = {}, cacheKey = {})", scripts, cacheKey);
runScripts(
runner ->
cachedScripts.computeIfAbsent(cacheKey, key -> parseScripts(scripts)).stream()
.map(s -> s.getBytes(StandardCharsets.UTF_8))
.map(ByteArrayInputStream::new)
.map(s -> new InputStreamReader(s, StandardCharsets.UTF_8))
.forEach(runner::runScript));
LOGGER.debug("exit from executeAndCacheScripts()");
}

private ScriptRunner getScriptRunner(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public final class SampleDataProvider {

private SampleDataProvider() {}

static Stream<String> getDefaultScripts() {
static Stream<String> getSampleDataCreationScripts() {
return Stream.of(
SAMPLE_WORKBASKET,
SAMPLE_DISTRIBUTION_TARGETS,
Expand All @@ -44,15 +44,16 @@ static Stream<String> getDefaultScripts() {
}

static Stream<String> getScriptsWithEvents() {
return Stream.concat(getDefaultScripts(), Stream.of(CLEAR_HISTORY_EVENTS, HISTORY_EVENT));
return Stream.concat(
getSampleDataCreationScripts(), Stream.of(CLEAR_HISTORY_EVENTS, HISTORY_EVENT));
}

static Stream<String> getScriptsToClearDatabase() {
return Stream.concat(getDefaultScripts(), Stream.of(DB_CLEAR_TABLES_SCRIPT));
return Stream.of(DB_CLEAR_TABLES_SCRIPT);
}

static Stream<String> getScriptsToDropDatabase() {
return Stream.concat(getDefaultScripts(), Stream.of(DB_DROP_TABLES_SCRIPT));
return Stream.of(DB_DROP_TABLES_SCRIPT);
}

static Stream<String> getTestDataScripts() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ class SampleDataProviderTest {

@Test
void getScriptsNotNull() {
assertThat(SampleDataProvider.getDefaultScripts()).isNotNull();
assertThat(SampleDataProvider.getSampleDataCreationScripts()).isNotNull();
assertThat(SampleDataProvider.getScriptsWithEvents()).isNotNull();
}

@Test
void getScriptsNotEmpty() {
assertThat(SampleDataProvider.getDefaultScripts().count() > 0).isTrue();
assertThat(SampleDataProvider.getSampleDataCreationScripts().count() > 0).isTrue();
assertThat(SampleDataProvider.getScriptsWithEvents().count() > 0).isTrue();
}

@Test
void getScriptsFileExists() {
SampleDataProvider.getDefaultScripts()
SampleDataProvider.getSampleDataCreationScripts()
.map(SqlReplacer::getScriptBufferedStream)
.forEach(Assertions::assertNotNull);
}
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<version.spring>5.2.5.RELEASE</version.spring>
<version.spring.security>5.3.1.RELEASE</version.spring.security>
<version.spring.core>2.0.0.RELEASE</version.spring.core>
<version.spring.boot>2.2.5.RELEASE</version.spring.boot>
<version.spring.boot>2.2.6.RELEASE</version.spring.boot>
<version.spring.restdocs>2.0.4.RELEASE</version.spring.restdocs>
<version.spring.mybatis>2.0.4</version.spring.mybatis>
<version.spring.hateos>0.24.0.RELEASE</version.spring.hateos>
Expand Down

0 comments on commit 646583f

Please sign in to comment.