Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

refactor #40

Merged
merged 8 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 5 additions & 6 deletions src/main/java/io/github/eocqrs/cmig/State.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,18 @@

package io.github.eocqrs.cmig;

import io.github.eocqrs.cmig.sha.StateChanges;
import org.cactoos.Scalar;
/*
* @todo #32:30m/DEV design State interface
*/

/**
* State.
*
* @author Aliaksei Bialiauski ([email protected])
* @since 0.0.0
*/
public interface State extends Scalar<String> {

public interface State extends Scalar<StateChanges> {
l3r8yJ marked this conversation as resolved.
Show resolved Hide resolved
// @todo #37:2hr/DEV Find several designs for States implementations
@Override
String value() throws Exception;
StateChanges value();

}
6 changes: 3 additions & 3 deletions src/main/java/io/github/eocqrs/cmig/meta/Author.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -33,7 +33,7 @@
* @author Aliaksei Bialiauski ([email protected])
* @since 0.0.0
*/
public final class Author implements Scalar<String> {
public final class Author implements Text {

/**
* XML.
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/github/eocqrs/cmig/meta/Names.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public Names(final String name, final String id)
}

@Override
public List<String> value() throws Exception {
public List<String> value() {
return this.xml.xpath(
"/states/changeState[@id='%s']/files/file/@path"
.formatted(
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/github/eocqrs/cmig/meta/XpathList.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@
public interface XpathList extends Scalar<List<String>> {

@Override
List<String> value() throws Exception;
List<String> value();
}
2 changes: 1 addition & 1 deletion src/main/java/io/github/eocqrs/cmig/session/Cassandra.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
public interface Cassandra extends Scalar<Session>, Closeable {

@Override
Session value() throws Exception;
Session value();

@Override
void close() throws IOException;
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/io/github/eocqrs/cmig/session/Cql.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public interface Cql {
/**
* Apply Query.
*
* @throws Exception if something went wrong.
*/
void apply() throws Exception;
void apply();
}
4 changes: 2 additions & 2 deletions src/main/java/io/github/eocqrs/cmig/session/InFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@
}

@Override
public void apply() throws Exception {
public void apply() {
this.cassandra.value()
.execute(
new TextOf(
new ResourceOf(this.name)
).asString()
).toString()

Check warning on line 65 in src/main/java/io/github/eocqrs/cmig/session/InFile.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/github/eocqrs/cmig/session/InFile.java#L65

Added line #L65 was not covered by tests
);
}
}
6 changes: 2 additions & 4 deletions src/main/java/io/github/eocqrs/cmig/session/Simple.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.Session;

import java.io.IOException;

/**
* Simple Cassandra.
*
Expand Down Expand Up @@ -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();
}
}
2 changes: 2 additions & 0 deletions src/main/java/io/github/eocqrs/cmig/sha/Sha.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@ public final class Sha implements Text {
* State ID.
*/
private final String id;

/**
* Master file.
*/
private final String master;

/**
* CMIG directory.
*/
Expand Down
42 changes: 24 additions & 18 deletions src/main/java/io/github/eocqrs/cmig/sha/StateChanges.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -60,23 +60,29 @@

@Override
public List<String> value() throws Exception {
final List<String> contents = new ListOf<>();
final List<String> 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

Check warning on line 74 in src/main/java/io/github/eocqrs/cmig/sha/StateChanges.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/github/eocqrs/cmig/sha/StateChanges.java#L74

Added line #L74 was not covered by tests
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();
}
}
2 changes: 1 addition & 1 deletion src/test/java/io/github/eocqrs/cmig/meta/AuthorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void readsAuthorInfoInRightFormat() throws Exception {
new Author(
"cmig/master.xml",
"1"
).value(),
).asString(),
new IsEqual<>(
"test"
)
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/it/CassandraIntegration.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/it/CassandraRunsIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ final class CassandraRunsIT extends CassandraIntegration {
void runs() {
MatcherAssert.assertThat(
"Cassandra runs",
CASSANDRA.isRunning(),
CassandraIntegration.CASSANDRA.isRunning(),
new IsEqual<>(true)
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/it/InFileIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/it/SimpleIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down