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..bc52c3c 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,9 @@ * @author Aliaksei Bialiauski (abialiauski.dev@gmail.com) * @since 0.0.0 */ -public interface State extends Scalar { - +public interface State extends Scalar { + // @todo #37:2hr/DEV Find several designs for States implementations @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..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. * @@ -68,12 +66,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 15ae13b..bc9216c 100644 --- a/src/main/java/io/github/eocqrs/cmig/sha/Sha.java +++ b/src/main/java/io/github/eocqrs/cmig/sha/Sha.java @@ -43,10 +43,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 fafe9c0..0426b7a 100644 --- a/src/main/java/io/github/eocqrs/cmig/sha/StateChanges.java +++ b/src/main/java/io/github/eocqrs/cmig/sha/StateChanges.java @@ -23,9 +23,9 @@ 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 ru.l3r8y.UnixizedOf; import java.util.List; @@ -60,23 +60,29 @@ 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 UnixizedOf( - new ResourceOf( - "%s/%s" - .formatted( - this.cmig, - file - ) + return this.list.value() + .stream() + .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() - .asString(); - contents.add(content); - } - return contents; + ) + ) + .asText() + .asString(); } } 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" ) diff --git a/src/test/java/it/CassandraIntegration.java b/src/test/java/it/CassandraIntegration.java index 8db0004..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; @@ -40,16 +40,16 @@ 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(); } - @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/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..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.HOST, + CassandraIntegration.CASSANDRA.getMappedPort(9042) ).value(); MatcherAssert.assertThat( "Session is not null",