This will show how to create a boilerplate GraphWalker project using the maven archetype.

Download and install the dependencies

  • Install the Java JDK, 7 or 8 will do
  • Install the Maven
  • Install the yEd editor

Create a boilerplate project

From the command line, run:

mvn archetype:generate -B -DarchetypeGroupId=org.graphwalker -DarchetypeArtifactId=graphwalker-maven-archetype -DgroupId=com.company -DartifactId=myProject

Move into the myProject folder, and test the project:

cd myProject

Open pom.xml and add plugin section, so it looks like below. It’s a bug, which will be fixed in next release.

     <build>
         <plugins>
             <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
            <plugin>
                 <groupId>org.graphwalker</groupId>
                 <artifactId>graphwalker-maven-plugin</artifactId>
                 <version>${graphwalker.version}</version>

Now, run a test:

mvn graphwalker:test

You now have a complete GraphWalker 3 project, and you also ran the test.

About auto-generated sources

The maven command above generated an interface SmallTest, from the model SmallTest.graphml. This feature helps the developer to keep the code in sync with the model(s). The requirement is that the graphml file needs to be in folder path, which is the same (package) path as for the java project, but under resource path instead.

Folder paths
The source code layout after the auto source code generation is done.

The interface will be generated, named and placed into the folder: target/generated-sources/graphwalker/com/company/SmallTest.java

// Generated by GraphWalker (http://www.graphwalker.org)
package com.company;

import org.graphwalker.java.annotation.Model;
import org.graphwalker.java.annotation.Vertex;
import org.graphwalker.java.annotation.Edge;

@Model(file = "com/company/SmallTest.graphml")
public interface SmallTest {

    @Edge()
    void e_SomeAction();

    @Vertex()
    void v_VerifySomeOtherAction();

    @Edge()
    void e_FirstAction();

    @Vertex()
    void v_VerifySomeAction();

    @Edge()
    void e_AnotherAction();

    @Edge()
    void e_SomeOtherAction();
}

The model

The test is itself quite simple. When opened in the yEd editor, it will look like below.

Small test model
The model SmallTest.graphml that is used for this test.

The test automation code

The class SomeSmallTest implements the interface SmallTest. The annotation @GraphWalker(value = "random(edge_coverage(100))", start = "e_FirstAction") tells GraphWalker to start the test at the edge e_FirstAction, using a random path generator with 100% edge coverage.

package com.company;

import org.graphwalker.core.machine.ExecutionContext;
import org.graphwalker.java.annotation.GraphWalker;

@GraphWalker(value = "random(edge_coverage(100))", start = "e_FirstAction")
public class SomeSmallTest extends ExecutionContext implements SmallTest {

    @Override
    public void e_FirstAction() {
        System.out.println("Running: e_FirstAction");
    }

    @Override
    public void e_AnotherAction() {
        System.out.println("Running: e_AnotherAction");
    }

    @Override
    public void e_SomeAction() {
        System.out.println("Running: e_SomeAction");
    }

    @Override
    public void e_SomeOtherAction() {
        System.out.println("Running: e_SomeOtherAction");
    }

    @Override
    public void v_VerifySomeAction() {
        System.out.println("Running: v_VerifySomeAction");
    }

    @Override
    public void v_VerifySomeOtherAction() {
        System.out.println("Running: v_VerifySomeOtherAction");
    }
}

Running the test

When running the the test the output might look something like this:

mvn graphwalker:test
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building GraphWalker Example 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] >>> graphwalker-maven-plugin:3.4.2:test (default-cli) @ myProject >>>
[INFO] 
[INFO] --- graphwalker-maven-plugin:3.4.2:validate-models (default-cli) @ myProject ---
[INFO] 
[INFO] --- graphwalker-maven-plugin:3.4.2:generate-sources (default-cli) @ myProject ---
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
[INFO] 
[INFO] --- maven-resources-plugin:2.3:resources (default-resources) @ myProject ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ myProject ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to /home/krikar/Downloads/tmp/myProject/target/classes
[INFO] 
[INFO] --- graphwalker-maven-plugin:3.4.2:generate-test-sources (generate-test-sources) @ myProject ---
[INFO] 
[INFO] --- graphwalker-maven-plugin:3.4.2:validate-test-models (default-cli) @ myProject ---
[INFO] 
[INFO] --- graphwalker-maven-plugin:3.4.2:generate-test-sources (default-cli) @ myProject ---
[INFO] 
[INFO] --- maven-resources-plugin:2.3:testResources (default-testResources) @ myProject ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/krikar/Downloads/tmp/myProject/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ myProject ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] <<< graphwalker-maven-plugin:3.4.2:test (default-cli) @ myProject <<<
[INFO] 
[INFO] --- graphwalker-maven-plugin:3.4.2:test (default-cli) @ myProject ---
[INFO] ------------------------------------------------------------------------
[INFO]   _____             _   _ _ _     _ _                                   
[INFO]  |   __|___ ___ ___| |_| | | |___| | |_ ___ ___                         
[INFO]  |  |  |  _| .'| . |   | | | | .'| | '_| -_|  _|                        
[INFO]  |_____|_| |__,|  _|_|_|_____|__,|_|_,_|___|_|                          
[INFO]                |_|         (3.4.2)                            
[INFO] ------------------------------------------------------------------------
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
[INFO] Configuration:
[INFO]     Include = [*]
[INFO]     Exclude = []
[INFO]      Groups = [*]
[INFO] 
[INFO] Tests:
[INFO]     SomeSmallTest(RandomPath, VertexCoverage, 100)
[INFO] 
[INFO] ------------------------------------------------------------------------
SLF4J: Failed to load class "org.slf4j.impl.StaticMDCBinder".
SLF4J: Defaulting to no-operation MDCAdapter implementation.
SLF4J: See http://www.slf4j.org/codes.html#no_static_mdc_binder for further details.
Running: e_FirstAction
Running: v_VerifySomeAction
Running: e_AnotherAction
Running: v_VerifySomeOtherAction
Running: e_SomeOtherAction
Running: v_VerifySomeOtherAction
Running: e_SomeOtherAction
Running: v_VerifySomeOtherAction
Running: e_SomeOtherAction
Running: v_VerifySomeOtherAction
Running: e_SomeAction
Running: v_VerifySomeAction
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] Result :
[INFO] 
[INFO] Tests: 1, Completed: 1, Incomplete: 0, Failed: 0, Not Executed: 0
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.013s
[INFO] Finished at: Tue May 12 13:36:06 CEST 2015
[INFO] Final Memory: 30M/552M
[INFO] ------------------------------------------------------------------------
Tags: example