From 7589650ed34872a7cad47e2958c8b40c11985662 Mon Sep 17 00:00:00 2001 From: l3r8yJ Date: Mon, 14 Aug 2023 10:52:27 +0300 Subject: [PATCH 1/7] refactor --- .gitignore | 3 +++ .../java/io/github/eocqrs/cmig/State.java | 10 +++---- .../io/github/eocqrs/cmig/meta/Author.java | 6 ++--- .../io/github/eocqrs/cmig/meta/Names.java | 2 +- .../io/github/eocqrs/cmig/meta/XpathList.java | 2 +- .../github/eocqrs/cmig/session/Cassandra.java | 2 +- .../io/github/eocqrs/cmig/session/Cql.java | 3 +-- .../io/github/eocqrs/cmig/session/InFile.java | 4 +-- .../io/github/eocqrs/cmig/session/Simple.java | 4 +-- .../java/io/github/eocqrs/cmig/sha/Sha.java | 2 ++ .../github/eocqrs/cmig/sha/StateChanges.java | 26 ++++++++----------- .../github/eocqrs/cmig/meta/AuthorTest.java | 2 +- 12 files changed, 32 insertions(+), 34 deletions(-) diff --git a/.gitignore b/.gitignore index 524f096..4c53d44 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,6 @@ # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* replay_pid* + +target +.idea diff --git a/src/main/java/io/github/eocqrs/cmig/State.java b/src/main/java/io/github/eocqrs/cmig/State.java index 35abb90..0146b3b 100644 --- a/src/main/java/io/github/eocqrs/cmig/State.java +++ b/src/main/java/io/github/eocqrs/cmig/State.java @@ -22,10 +22,8 @@ package io.github.eocqrs.cmig; +import io.github.eocqrs.cmig.sha.StateChanges; import org.cactoos.Scalar; -/* - * @todo #32:30m/DEV design State interface - */ /** * State. @@ -33,8 +31,8 @@ * @author Aliaksei Bialiauski (abialiauski.dev@gmail.com) * @since 0.0.0 */ -public interface State extends Scalar { - +public interface State extends Scalar { @Override - String value() throws Exception; + StateChanges value(); + } diff --git a/src/main/java/io/github/eocqrs/cmig/meta/Author.java b/src/main/java/io/github/eocqrs/cmig/meta/Author.java index f270e99..f4a5159 100644 --- a/src/main/java/io/github/eocqrs/cmig/meta/Author.java +++ b/src/main/java/io/github/eocqrs/cmig/meta/Author.java @@ -24,7 +24,7 @@ import com.jcabi.xml.XML; import com.jcabi.xml.XMLDocument; -import org.cactoos.Scalar; +import org.cactoos.Text; import org.cactoos.io.ResourceOf; /** @@ -33,7 +33,7 @@ * @author Aliaksei Bialiauski (abialiauski.dev@gmail.com) * @since 0.0.0 */ -public final class Author implements Scalar { +public final class Author implements Text { /** * XML. @@ -75,7 +75,7 @@ public Author(final String name, final String id) } @Override - public String value() throws Exception { + public String asString() { return this.xml.xpath( "/states/changeState[@id='%s']/@author" .formatted( diff --git a/src/main/java/io/github/eocqrs/cmig/meta/Names.java b/src/main/java/io/github/eocqrs/cmig/meta/Names.java index 346dc24..c771c15 100644 --- a/src/main/java/io/github/eocqrs/cmig/meta/Names.java +++ b/src/main/java/io/github/eocqrs/cmig/meta/Names.java @@ -76,7 +76,7 @@ public Names(final String name, final String id) } @Override - public List value() throws Exception { + public List value() { return this.xml.xpath( "/states/changeState[@id='%s']/files/file/@path" .formatted( diff --git a/src/main/java/io/github/eocqrs/cmig/meta/XpathList.java b/src/main/java/io/github/eocqrs/cmig/meta/XpathList.java index d2c1164..dec19c0 100644 --- a/src/main/java/io/github/eocqrs/cmig/meta/XpathList.java +++ b/src/main/java/io/github/eocqrs/cmig/meta/XpathList.java @@ -35,5 +35,5 @@ public interface XpathList extends Scalar> { @Override - List value() throws Exception; + List value(); } diff --git a/src/main/java/io/github/eocqrs/cmig/session/Cassandra.java b/src/main/java/io/github/eocqrs/cmig/session/Cassandra.java index e21a5ae..7f25a26 100644 --- a/src/main/java/io/github/eocqrs/cmig/session/Cassandra.java +++ b/src/main/java/io/github/eocqrs/cmig/session/Cassandra.java @@ -37,7 +37,7 @@ public interface Cassandra extends Scalar, Closeable { @Override - Session value() throws Exception; + Session value(); @Override void close() throws IOException; diff --git a/src/main/java/io/github/eocqrs/cmig/session/Cql.java b/src/main/java/io/github/eocqrs/cmig/session/Cql.java index b3b5676..4830e3b 100644 --- a/src/main/java/io/github/eocqrs/cmig/session/Cql.java +++ b/src/main/java/io/github/eocqrs/cmig/session/Cql.java @@ -33,7 +33,6 @@ public interface Cql { /** * Apply Query. * - * @throws Exception if something went wrong. */ - void apply() throws Exception; + void apply(); } diff --git a/src/main/java/io/github/eocqrs/cmig/session/InFile.java b/src/main/java/io/github/eocqrs/cmig/session/InFile.java index efd45b3..46eb019 100644 --- a/src/main/java/io/github/eocqrs/cmig/session/InFile.java +++ b/src/main/java/io/github/eocqrs/cmig/session/InFile.java @@ -57,12 +57,12 @@ public InFile( } @Override - public void apply() throws Exception { + public void apply() { this.cassandra.value() .execute( new TextOf( new ResourceOf(this.name) - ).asString() + ).toString() ); } } diff --git a/src/main/java/io/github/eocqrs/cmig/session/Simple.java b/src/main/java/io/github/eocqrs/cmig/session/Simple.java index d013052..b664cc6 100644 --- a/src/main/java/io/github/eocqrs/cmig/session/Simple.java +++ b/src/main/java/io/github/eocqrs/cmig/session/Simple.java @@ -68,12 +68,12 @@ public Simple( } @Override - public Session value() throws Exception { + public Session value() { return this.cluster.connect(); } @Override - public void close() throws IOException { + public void close() { this.cluster.close(); } } diff --git a/src/main/java/io/github/eocqrs/cmig/sha/Sha.java b/src/main/java/io/github/eocqrs/cmig/sha/Sha.java index d10ecb3..1db7e78 100644 --- a/src/main/java/io/github/eocqrs/cmig/sha/Sha.java +++ b/src/main/java/io/github/eocqrs/cmig/sha/Sha.java @@ -42,10 +42,12 @@ public final class Sha implements Text { * State ID. */ private final String id; + /** * Master file. */ private final String master; + /** * CMIG directory. */ diff --git a/src/main/java/io/github/eocqrs/cmig/sha/StateChanges.java b/src/main/java/io/github/eocqrs/cmig/sha/StateChanges.java index 36ac253..8325688 100644 --- a/src/main/java/io/github/eocqrs/cmig/sha/StateChanges.java +++ b/src/main/java/io/github/eocqrs/cmig/sha/StateChanges.java @@ -25,7 +25,6 @@ import io.github.eocqrs.cmig.meta.XpathList; import org.cactoos.Scalar; import org.cactoos.io.ResourceOf; -import org.cactoos.list.ListOf; import org.cactoos.text.TextOf; import java.util.List; @@ -42,6 +41,7 @@ public final class StateChanges implements Scalar> { * XPATH lists. */ private final XpathList list; + /** * CMIG directory. */ @@ -60,21 +60,17 @@ public StateChanges(final XpathList lst, final String cmg) { @Override public List value() throws Exception { - final List contents = new ListOf<>(); - final List files = this.list.value(); - for (final String file : files) { - final String content = - new TextOf( + return this.list.value() + .stream() + .map( + file -> new TextOf( new ResourceOf( - "%s/%s" - .formatted( - this.cmig, - file - ) + "%s/%s".formatted( + this.cmig, + file + ) ) - ).asString(); - contents.add(content); - } - return contents; + ).toString() + ).toList(); } } diff --git a/src/test/java/io/github/eocqrs/cmig/meta/AuthorTest.java b/src/test/java/io/github/eocqrs/cmig/meta/AuthorTest.java index a4ff89b..4f2eb29 100644 --- a/src/test/java/io/github/eocqrs/cmig/meta/AuthorTest.java +++ b/src/test/java/io/github/eocqrs/cmig/meta/AuthorTest.java @@ -41,7 +41,7 @@ void readsAuthorInfoInRightFormat() throws Exception { new Author( "cmig/master.xml", "1" - ).value(), + ).asString(), new IsEqual<>( "test" ) From 0065eacb81ac86eea27cb0ff7d576b6efa667eae Mon Sep 17 00:00:00 2001 From: l3r8yJ Date: Mon, 14 Aug 2023 11:04:22 +0300 Subject: [PATCH 2/7] import --- src/main/java/io/github/eocqrs/cmig/session/Simple.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/io/github/eocqrs/cmig/session/Simple.java b/src/main/java/io/github/eocqrs/cmig/session/Simple.java index b664cc6..27539bf 100644 --- a/src/main/java/io/github/eocqrs/cmig/session/Simple.java +++ b/src/main/java/io/github/eocqrs/cmig/session/Simple.java @@ -25,8 +25,6 @@ import com.datastax.driver.core.Cluster; import com.datastax.driver.core.Session; -import java.io.IOException; - /** * Simple Cassandra. * From b6f281114789c110bcd631589e3775b04a3c0f79 Mon Sep 17 00:00:00 2001 From: l3r8yJ Date: Mon, 14 Aug 2023 15:19:06 +0300 Subject: [PATCH 3/7] puzzle --- src/main/java/io/github/eocqrs/cmig/State.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/io/github/eocqrs/cmig/State.java b/src/main/java/io/github/eocqrs/cmig/State.java index 0146b3b..bc52c3c 100644 --- a/src/main/java/io/github/eocqrs/cmig/State.java +++ b/src/main/java/io/github/eocqrs/cmig/State.java @@ -32,6 +32,7 @@ * @since 0.0.0 */ public interface State extends Scalar { + // @todo #37:2hr/DEV Find several designs for States implementations @Override StateChanges value(); From 72ba2640bac1569bdd3a9e1ba25b45423a490777 Mon Sep 17 00:00:00 2001 From: l3r8yJ Date: Wed, 16 Aug 2023 00:12:35 +0300 Subject: [PATCH 4/7] puzzle --- .../github/eocqrs/cmig/sha/StateChanges.java | 37 ++++++++++++------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/src/main/java/io/github/eocqrs/cmig/sha/StateChanges.java b/src/main/java/io/github/eocqrs/cmig/sha/StateChanges.java index 04f2784..43cad18 100644 --- a/src/main/java/io/github/eocqrs/cmig/sha/StateChanges.java +++ b/src/main/java/io/github/eocqrs/cmig/sha/StateChanges.java @@ -23,10 +23,10 @@ package io.github.eocqrs.cmig.sha; import io.github.eocqrs.cmig.meta.XpathList; +import lombok.SneakyThrows; import org.cactoos.Scalar; import org.cactoos.io.ResourceOf; -import org.cactoos.list.ListOf; -import org.cactoos.text.TextOf; +import ru.l3r8y.UnixizedOf; import java.util.List; @@ -62,18 +62,27 @@ public StateChanges(final XpathList lst, final String cmg) { public List value() throws Exception { return this.list.value() .stream() - .map( - file -> new UnixizedOf( - new ResourceOf( - "%s/%s" - .formatted( - this.cmig, - file - ) + .map(this::contentOf) + .toList(); + } + + /** + * @todo #37:30min/DEV Move to separate class + * Create class ContentOf with tests. + * This puzzle might be moved into unixized library. + */ + @SneakyThrows + private String contentOf(final String file) { + return new UnixizedOf( + new ResourceOf( + "%s/%s" + .formatted( + this.cmig, + file ) - ) - .asText() - .toString() - ).toList(); + ) + ) + .asText() + .asString(); } } From 077cf7995b658641bf5214623b99f9c6ca8d33f7 Mon Sep 17 00:00:00 2001 From: l3r8yJ Date: Wed, 16 Aug 2023 00:13:14 +0300 Subject: [PATCH 5/7] none javadoc --- src/main/java/io/github/eocqrs/cmig/sha/StateChanges.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/github/eocqrs/cmig/sha/StateChanges.java b/src/main/java/io/github/eocqrs/cmig/sha/StateChanges.java index 43cad18..0426b7a 100644 --- a/src/main/java/io/github/eocqrs/cmig/sha/StateChanges.java +++ b/src/main/java/io/github/eocqrs/cmig/sha/StateChanges.java @@ -66,7 +66,7 @@ public List value() throws Exception { .toList(); } - /** + /* * @todo #37:30min/DEV Move to separate class * Create class ContentOf with tests. * This puzzle might be moved into unixized library. From 6b07387f5f5cb085d6ffd8417319b22800012c9c Mon Sep 17 00:00:00 2001 From: l3r8yJ Date: Wed, 16 Aug 2023 00:22:57 +0300 Subject: [PATCH 6/7] static host --- src/test/java/it/CassandraIntegration.java | 4 ++-- src/test/java/it/InFileIT.java | 4 ++-- src/test/java/it/SimpleIT.java | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/test/java/it/CassandraIntegration.java b/src/test/java/it/CassandraIntegration.java index 8db0004..9bcb3d7 100644 --- a/src/test/java/it/CassandraIntegration.java +++ b/src/test/java/it/CassandraIntegration.java @@ -40,12 +40,12 @@ public abstract class CassandraIntegration { new CassandraContainer<>( DockerImageName.parse("cassandra:3.11.15") ).withExposedPorts(9042); - protected static String host; + protected static String HOST; @BeforeAll static void beforeAll() { CassandraIntegration.CASSANDRA.start(); - CassandraIntegration.host = + CassandraIntegration.HOST = CassandraIntegration.CASSANDRA.getHost(); } diff --git a/src/test/java/it/InFileIT.java b/src/test/java/it/InFileIT.java index 96d309b..fcca308 100644 --- a/src/test/java/it/InFileIT.java +++ b/src/test/java/it/InFileIT.java @@ -41,8 +41,8 @@ void appliesInRightFormat() { () -> new InFile( new Simple( - CassandraIntegration.host, - CASSANDRA.getMappedPort(9042) + CassandraIntegration.HOST, + CassandraIntegration.CASSANDRA.getMappedPort(9042) ), "cmig/001-initial-keyspace.cql" ).apply(), diff --git a/src/test/java/it/SimpleIT.java b/src/test/java/it/SimpleIT.java index b6d9974..9965a76 100644 --- a/src/test/java/it/SimpleIT.java +++ b/src/test/java/it/SimpleIT.java @@ -39,7 +39,7 @@ final class SimpleIT extends CassandraIntegration { @Test void connectsSession() throws Exception { final Session session = new Simple( - CassandraIntegration.host, + CassandraIntegration.HOST, CASSANDRA.getMappedPort(9042) ).value(); MatcherAssert.assertThat( From cbbd1005ad1b5af4475af772a3425d5e5cd9751e Mon Sep 17 00:00:00 2001 From: l3r8yJ Date: Wed, 16 Aug 2023 00:28:13 +0300 Subject: [PATCH 7/7] junit5 --- src/test/java/it/CassandraIntegration.java | 4 ++-- src/test/java/it/CassandraRunsIT.java | 2 +- src/test/java/it/SimpleIT.java | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/test/java/it/CassandraIntegration.java b/src/test/java/it/CassandraIntegration.java index 9bcb3d7..cc56af5 100644 --- a/src/test/java/it/CassandraIntegration.java +++ b/src/test/java/it/CassandraIntegration.java @@ -22,7 +22,7 @@ package it; -import org.junit.AfterClass; +import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.testcontainers.containers.CassandraContainer; import org.testcontainers.utility.DockerImageName; @@ -49,7 +49,7 @@ static void beforeAll() { CassandraIntegration.CASSANDRA.getHost(); } - @AfterClass + @AfterAll public static void tearDown() { CassandraIntegration.CASSANDRA.stop(); } diff --git a/src/test/java/it/CassandraRunsIT.java b/src/test/java/it/CassandraRunsIT.java index 34cd3ad..22f8918 100644 --- a/src/test/java/it/CassandraRunsIT.java +++ b/src/test/java/it/CassandraRunsIT.java @@ -39,7 +39,7 @@ final class CassandraRunsIT extends CassandraIntegration { void runs() { MatcherAssert.assertThat( "Cassandra runs", - CASSANDRA.isRunning(), + CassandraIntegration.CASSANDRA.isRunning(), new IsEqual<>(true) ); } diff --git a/src/test/java/it/SimpleIT.java b/src/test/java/it/SimpleIT.java index 9965a76..6e8e1d2 100644 --- a/src/test/java/it/SimpleIT.java +++ b/src/test/java/it/SimpleIT.java @@ -37,10 +37,10 @@ final class SimpleIT extends CassandraIntegration { @Test - void connectsSession() throws Exception { + void connectsSession() { final Session session = new Simple( CassandraIntegration.HOST, - CASSANDRA.getMappedPort(9042) + CassandraIntegration.CASSANDRA.getMappedPort(9042) ).value(); MatcherAssert.assertThat( "Session is not null",