Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Florent Biville committed May 10, 2016
1 parent 04a9e50 commit 1de95c6
Show file tree
Hide file tree
Showing 13 changed files with 477 additions and 3 deletions.
1 change: 0 additions & 1 deletion liquigraph-cli/pom.xml
Expand Up @@ -59,7 +59,6 @@
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<configuration>
<descriptor>src/assembly/assembly.xml</descriptor>
<tarLongFileMode>posix</tarLongFileMode>
Expand Down
2 changes: 0 additions & 2 deletions liquigraph-core/pom.xml
Expand Up @@ -46,7 +46,6 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -58,7 +57,6 @@
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>2.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
90 changes: 90 additions & 0 deletions liquigraph-documentation/pom.xml
@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<properties>
<jgiven.version>0.11.3</jgiven.version>
</properties>

<parent>
<groupId>org.liquigraph</groupId>
<artifactId>liquigraph-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<artifactId>liquigraph-documentation</artifactId>
<packaging>jar</packaging>

<dependencies>
<dependency>
<groupId>org.liquigraph</groupId>
<artifactId>liquigraph-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.liquigraph</groupId>
<artifactId>liquigraph-cli</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.liquigraph</groupId>
<artifactId>liquigraph-maven-plugin</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.tngtech.jgiven</groupId>
<artifactId>jgiven-junit</artifactId>
<version>${jgiven.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>com.tngtech.jgiven</groupId>
<artifactId>jgiven-maven-plugin</artifactId>
<version>${jgiven.version}</version>
<executions>
<execution>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
<configuration>
<format>html</format>
<outputDirectory>${project.build.directory}/documentation</outputDirectory>
<title>Liquigraph documentation - Version ${project.version}</title>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptor>src/assembly/assembly.xml</descriptor>
<tarLongFileMode>posix</tarLongFileMode>
</configuration>
<executions>
<execution>
<id>create-archive</id>
<phase>verify</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
19 changes: 19 additions & 0 deletions liquigraph-documentation/src/assembly/assembly.xml
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">

<id>doc</id>
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>${project.build.directory}/documentation</directory>
<outputDirectory/>
<includes>
<include>*</include>
</includes>
</fileSet>
</fileSets>
</assembly>
@@ -0,0 +1,25 @@
/**
* Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.liquigraph.core.documentation;

/**
* Created by f.biville on 10/05/2016.
*/
public class ChangesetExecutionTest {

//TODO: publish test-jar of Liquigraph-core
//TODO: transactionality, run always, run on change
}
@@ -0,0 +1,26 @@
/**
* Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.liquigraph.core.documentation;

import com.tngtech.jgiven.annotation.IsTag;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@IsTag(description = "Core concepts of Liquigraph")
@Retention( RetentionPolicy.RUNTIME )
public @interface GettingStarted {
}
@@ -0,0 +1,144 @@
/**
* Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.liquigraph.core.documentation;

import com.google.common.base.Charsets;
import com.tngtech.jgiven.junit.SimpleScenarioTest;
import org.junit.Test;
import org.liquigraph.core.configuration.ConfigurationBuilder;
import org.liquigraph.core.documentation.xml.XmlMarshaller;
import org.liquigraph.core.model.Changeset;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;

import static java.nio.file.Files.readAllBytes;
import static org.assertj.core.api.Assertions.assertThat;

public class GettingStartedTest extends SimpleScenarioTest<GettingStartedTest.FundamentalsSteps> {

@Test @GettingStarted
public void _1__a_changeset_is_a_migration_defined_in_Cypher() throws Exception {
given().a_Cypher_migration("MATCH (n:Hello) SET n.contents = 'World' RETURN n");

when().defined_with_Liquigraph();

then().it_is_written_as_such(
"<changeset author=\"author\" contexts=\"\" id=\"id\" run-always=\"false\" run-on-change=\"false\">\n" +
" <query>MATCH (n:Hello) SET n.contents = 'World' RETURN n</query>\n" +
"</changeset>");
}

@Test @GettingStarted
public void _2__a_changeset_can_define_several_queries() throws Exception {
given().several_Cypher_migrations(
"MATCH (n:Bonjour) SET n.contents = 'Monde' RETURN n",
"MATCH (n:Hello) SET n.contents = 'World' RETURN n"
);

when().defined_with_Liquigraph();

then().it_is_written_as_such(
"<changeset author=\"author\" contexts=\"\" id=\"id\" run-always=\"false\" run-on-change=\"false\">\n" +
" <query>MATCH (n:Bonjour) SET n.contents = 'Monde' RETURN n</query>\n" +
" <query>MATCH (n:Hello) SET n.contents = 'World' RETURN n</query>\n" +
"</changeset>");
}

@Test @GettingStarted
public void _3__a_changelog_file_is_Liquigraph_entry_point_and_contains_changesets() throws Exception {
given().a_changelog_file("getting_started/changelog.xml");

when().it_contains(
"<changelog>\n" +
" <changeset id=\"id\" author=\"author\">\n" +
" <query>MATCH (n:Hello) SET n.contents = 'World' RETURN n</query>\n" +
" </changeset>\n" +
"</changelog>");

then().it_can_be_run_by_Liquigraph();
}

//TODO: schema

public static class FundamentalsSteps {

private final XmlMarshaller marshaller = new XmlMarshaller();
private Collection<String> queries;
private Changeset changeset;
private String changelogPath;
private File changelogFile;

public FundamentalsSteps a_Cypher_migration(String query) {
this.queries = Collections.singletonList(query);
return this;
}

public FundamentalsSteps several_Cypher_migrations(String... queries) {
this.queries = Arrays.asList(queries);
return this;
}

public FundamentalsSteps defined_with_Liquigraph() {
changeset = new Changeset();
changeset.setId("id");
changeset.setAuthor("author");
changeset.setQueries(queries);
return this;
}

public void it_is_written_as_such(String expectedChangesetXml) throws Exception {
String output = marshaller.serialize(changeset, "changeset", false);

assertThat(output).isXmlEqualTo(expectedChangesetXml);
}

public void a_changelog_file(String changelogPath) throws URISyntaxException {
this.changelogPath = changelogPath;
}

public void it_contains(String contents) throws URISyntaxException, IOException {
changelogFile = new File(this.getClass().getResource("/" + changelogPath).toURI());
String fileContents = new String(readAllBytes(changelogFile.toPath()), Charsets.UTF_8);

assertThat(fileContents).contains(contents);
}

public void it_can_be_run_by_Liquigraph() throws IOException {
new ConfigurationBuilder()
.withClassLoader(changelogClassloader())
.withMasterChangelogLocation(changelogPath)
.withDryRunMode(Files.createTempDirectory("liquigraph-doc"))
.withUsername("neo4j")
.withPassword("secret")
.withUri("jdbc:neo4j://localhost:7474")
.build();
}

private URLClassLoader changelogClassloader() throws MalformedURLException {
return new URLClassLoader(new URL[]{changelogFile.toURI().toURL()}, this.getClass().getClassLoader());
}
}
}
@@ -0,0 +1,24 @@
/**
* Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.liquigraph.core.documentation;

/**
* Created by f.biville on 10/05/2016.
*/
public class LiquigraphCliTest {

// TODO: run Liquigraph CLI (Unix, Windows)
}
@@ -0,0 +1,24 @@
/**
* Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.liquigraph.core.documentation;

/**
* Created by f.biville on 10/05/2016.
*/
public class LiquigraphCoreTest {

// TODO: run Liquigraph core directly
}

0 comments on commit 1de95c6

Please sign in to comment.