Skip to content

Commit

Permalink
Fixed issue #21
Browse files Browse the repository at this point in the history
  • Loading branch information
KristianKarl-zz committed Nov 24, 2015
1 parent 5221bea commit 36fc9cb
Show file tree
Hide file tree
Showing 6 changed files with 524 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,51 +42,6 @@ public class ConvertFilesTest extends CLITestRoot {
@Rule
public TemporaryFolder testFolder = new TemporaryFolder();

@Test
public void convertJsonToJson() throws IOException {
File tempFile = testFolder.newFile("example.json");
String args[] = {"convert", "--input", "json/example.json", tempFile.getPath()};
Result result = runCommand(args);
Assert.assertThat(result.getError(), is(""));
Assert.assertTrue(tempFile.length() > 0);
}

@Test
public void convertJsonToGraphml() throws IOException {
File tempFile = testFolder.newFile("example.graphml");
String args[] = {"convert", "--input", "json/example.json", tempFile.getPath()};
Result result = runCommand(args);
Assert.assertThat(result.getError(), is(""));
Assert.assertTrue(tempFile.length() > 0);
}

@Test
public void convertJsonToJava() throws IOException {
File tempFile = testFolder.newFile("example.java");
String args[] = {"convert", "--input", "json/example.json", tempFile.getPath()};
Result result = runCommand(args);
Assert.assertThat(result.getError(), is(""));
Assert.assertTrue(tempFile.length() > 0);
}

@Test
public void convertJsonToDot() throws IOException {
File tempFile = testFolder.newFile("example.dot");
String args[] = {"convert", "--input", "json/example.json", tempFile.getPath()};
Result result = runCommand(args);
Assert.assertThat(result.getError(), is(""));
Assert.assertTrue(tempFile.length() > 0);
}

@Test
public void convertGraphmlToGraphml() throws IOException {
File tempFile = testFolder.newFile("UC01_GW2.graphml");
String args[] = {"convert", "--input", "graphml/UC01_GW2.graphml", tempFile.getPath()};
Result result = runCommand(args);
Assert.assertThat(result.getError(), is(""));
Assert.assertTrue(tempFile.length() > 0);
}

/**
* The java file generated, can be compiled with the cli jar, like:
* java -jar graphwalker-cli.jar convert -i UC01.graphml UC01.java
Expand All @@ -103,67 +58,4 @@ public void convertGraphmlToJava() throws IOException {
Assert.assertThat(result.getError(), is(""));
Assert.assertTrue(tempFile.length() > 0);
}

@Test
public void convertGraphmlToDot() throws IOException {
File tempFile = testFolder.newFile("UC01_GW2.dot");
String args[] = {"convert", "--input", "graphml/UC01_GW2.graphml", tempFile.getPath()};
Result result = runCommand(args);
Assert.assertThat(result.getError(), is(""));
Assert.assertTrue(tempFile.length() > 0);
}

@Test
public void convertGraphmlToJson() throws IOException {
File tempFile = testFolder.newFile("UC01_GW2.json");
String args[] = {"convert", "--input", "graphml/UC01_GW2.graphml", tempFile.getPath()};
Result result = runCommand(args);
Assert.assertThat(result.getError(), is(""));
Assert.assertTrue(tempFile.length() > 0);
}

@Test
public void convertDotToDot() throws IOException {
File tempFile = testFolder.newFile("SimpleGW.dot");
String args[] = {"convert", "--input", "dot/SimpleGW.dot", tempFile.getPath()};
Result result = runCommand(args);
Assert.assertThat(result.getError(), is(""));
Assert.assertTrue(tempFile.length() > 0);
}

@Test
public void convertDotToJava() throws IOException {
File tempFile = testFolder.newFile("SimpleGW.java");
String args[] = {"convert", "--input", "dot/SimpleGW.dot", tempFile.getPath()};
Result result = runCommand(args);
Assert.assertThat(result.getError(), is(""));
Assert.assertTrue(tempFile.length() > 0);
}

@Test
public void convertDotToGraphml() throws IOException {
File tempFile = testFolder.newFile("SimpleGW.graphml");
String args[] = {"convert", "--input", "dot/SimpleGW.dot", tempFile.getPath()};
Result result = runCommand(args);
Assert.assertThat(result.getError(), is(""));
Assert.assertTrue(tempFile.length() > 0);
}

@Test
public void convertDotToJson() throws IOException {
File tempFile = testFolder.newFile("SimpleGW.json");
String args[] = {"convert", "--input", "dot/SimpleGW.dot", tempFile.getPath()};
Result result = runCommand(args);
Assert.assertThat(result.getError(), is(""));
Assert.assertTrue(tempFile.length() > 0);
}

@Test
public void convertJavaToDot() throws IOException {
File tempFile = testFolder.newFile("SimpleGW.dot");
String args[] = {"convert", "--input", "dot/SimpleGW.java", tempFile.getPath()};
Result result = runCommand(args);
Assert.assertTrue(result.getError().contains("Creating a model from Java is not supported"));
Assert.assertTrue(tempFile.length() == 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
*/

import org.graphwalker.core.machine.Context;
import org.graphwalker.io.factory.dot.DotContextFactory;
import org.graphwalker.io.factory.gw3.GW3ContextFactory;
import org.graphwalker.io.factory.java.JavaContextFactory;
import org.graphwalker.io.factory.json.JsonContextFactory;
import org.graphwalker.io.factory.yed.YEdContextFactory;
import org.junit.Assert;
Expand All @@ -53,43 +55,205 @@ public class ConvertionContextFactoryTest {
public TemporaryFolder testFolder = new TemporaryFolder();

@Test
public void PetClinicSharedStateGraphml2Json() throws IOException {
public void graphml2Gw3() throws IOException {
Context yedContext = new YEdContextFactory().create(Paths.get("graphml/Login.graphml"));
Assert.assertNotNull(yedContext);

File tempFile = testFolder.newFile("test.gw3");
Context gw3WriteContext = new GW3ContextFactory().write(yedContext, tempFile.toPath());
Assert.assertNotNull(gw3WriteContext);

Context gw3ReadContext = new GW3ContextFactory().create(tempFile.toPath());
Assert.assertNotNull(gw3ReadContext);

Assert.assertThat(yedContext.getModel().getEdges().size(), is(gw3WriteContext.getModel().getEdges().size()));
Assert.assertThat(yedContext.getModel().getVertices().size(), is(gw3WriteContext.getModel().getVertices().size()));
}

@Test
public void convertJsonToJson() throws IOException {
Context jsonContext = new JsonContextFactory().create(Paths.get("json/example.json"));
Assert.assertNotNull(jsonContext);

File tempFile = testFolder.newFile("test.json");
Context jsonWriteContext = new JsonContextFactory().write(jsonContext, tempFile.toPath());
Assert.assertNotNull(jsonWriteContext);

Context jsonReadContext = new JsonContextFactory().create(tempFile.toPath());
Assert.assertNotNull(jsonReadContext);

Assert.assertThat(jsonContext.getModel().getEdges().size(), is(jsonReadContext.getModel().getEdges().size()));
Assert.assertThat(jsonContext.getModel().getVertices().size(), is(jsonReadContext.getModel().getVertices().size()));
}

@Test
public void convertJsonToGraphml() throws IOException {
Context jsonContext = new JsonContextFactory().create(Paths.get("json/example.json"));
Assert.assertNotNull(jsonContext);

File tempFile = testFolder.newFile("test.graphml");
Context yedWriteContext = new YEdContextFactory().write(jsonContext, tempFile.toPath());
Assert.assertNotNull(yedWriteContext);

Context yedReadContext = new YEdContextFactory().create(tempFile.toPath());
Assert.assertNotNull(yedReadContext);

// Since edges without source vertex is not allowed in yed/graphml, the yedReadContext will be one edge short
Assert.assertThat(jsonContext.getModel().getEdges().size(), is(yedReadContext.getModel().getEdges().size() + 1));
Assert.assertThat(jsonContext.getModel().getVertices().size(), is(yedReadContext.getModel().getVertices().size()));
}

@Test
public void convertJsonToJava() throws IOException {
Context jsonContext = new JsonContextFactory().create(Paths.get("json/example.json"));
Assert.assertNotNull(jsonContext);

File tempFile = testFolder.newFile("test.java");
Context javaWriteContext = new JavaContextFactory().write(jsonContext, tempFile.toPath());
Assert.assertNotNull(javaWriteContext);

Assert.assertThat(jsonContext.getModel().getEdges().size(), is(javaWriteContext.getModel().getEdges().size()));
Assert.assertThat(jsonContext.getModel().getVertices().size(), is(javaWriteContext.getModel().getVertices().size()));
}

@Test
public void convertJsonToDot() throws IOException {
Context jsonContext = new JsonContextFactory().create(Paths.get("json/example.json"));
Assert.assertNotNull(jsonContext);

File tempFile = testFolder.newFile("test.dot");
Context dotWriteContext = new DotContextFactory().write(jsonContext, tempFile.toPath());
Assert.assertNotNull(dotWriteContext);

Context dotReadContext = new DotContextFactory().create(tempFile.toPath());
Assert.assertNotNull(dotReadContext);

Assert.assertThat(jsonContext.getModel().getEdges().size(), is(dotReadContext.getModel().getEdges().size()));
Assert.assertThat(jsonContext.getModel().getVertices().size(), is(dotReadContext.getModel().getVertices().size()));
}

@Test
public void convertGraphmlToGraphml() throws IOException {
Context yEdContext = new YEdContextFactory().create(Paths.get("graphml/UC01_GW2.graphml"));
Assert.assertNotNull(yEdContext);

File tempFile = testFolder.newFile("test.graphml");
Context yedWriteContext = new YEdContextFactory().write(yEdContext, tempFile.toPath());
Assert.assertNotNull(yedWriteContext);

Context yedReadContext = new YEdContextFactory().create(tempFile.toPath());
Assert.assertNotNull(yedReadContext);

// Since edges without source vertex is not allowed in yed/graphml, the yedReadContext will be one edge short
Assert.assertThat(yEdContext.getModel().getEdges().size(), is(yedReadContext.getModel().getEdges().size() + 1));
Assert.assertThat(yEdContext.getModel().getVertices().size(), is(yedReadContext.getModel().getVertices().size()));
}


@Test
public void convertGraphmlToDot() throws IOException {
Context yEdContext = new YEdContextFactory().create(Paths.get("graphml/UC01_GW2.graphml"));
Assert.assertNotNull(yEdContext);

File tempFile = testFolder.newFile("test.dot");
Context dotWriteContext = new DotContextFactory().write(yEdContext, tempFile.toPath());
Assert.assertNotNull(dotWriteContext);

Context dotReadContext = new DotContextFactory().create(tempFile.toPath());
Assert.assertNotNull(dotReadContext);

Assert.assertThat(yEdContext.getModel().getEdges().size(), is(dotReadContext.getModel().getEdges().size()));
Assert.assertThat(yEdContext.getModel().getVertices().size(), is(dotReadContext.getModel().getVertices().size()));
}

@Test
public void convertGraphmlToJava() throws IOException {
Context yEdContext = new YEdContextFactory().create(Paths.get("graphml/UC01_GW2.graphml"));
Assert.assertNotNull(yEdContext);

File tempFile = testFolder.newFile("test.java");
Context javaWriteContext = new JavaContextFactory().write(yEdContext, tempFile.toPath());
Assert.assertNotNull(javaWriteContext);

Assert.assertThat(yEdContext.getModel().getEdges().size(), is(javaWriteContext.getModel().getEdges().size()));
Assert.assertThat(yEdContext.getModel().getVertices().size(), is(javaWriteContext.getModel().getVertices().size()));
}

@Test
public void graphml2Json() throws IOException {
Context yedContext = new YEdContextFactory().create(Paths.get("graphml/PetClinicSharedState.graphml"));
Assert.assertNotNull(yedContext);

File testFile = testFolder.newFile("PetClinicSharedState.json");
File testFile = testFolder.newFile("test.json");
Context jsonWriteContext = new JsonContextFactory().write(yedContext, testFile.toPath());
Assert.assertNotNull(jsonWriteContext);

Context jsonReadContext = new JsonContextFactory().create(testFile.toPath());
Assert.assertNotNull(jsonReadContext);

Assert.assertThat(yedContext.getNextElement().getId(), is(jsonWriteContext.getNextElement().getId()));
Assert.assertThat(yedContext.getModel().getEdges().size(), is(jsonWriteContext.getModel().getEdges().size()));
Assert.assertThat(yedContext.getModel().getVertices().size(), is(jsonWriteContext.getModel().getVertices().size()));
Assert.assertThat(yedContext.getNextElement().getId(), is(jsonReadContext.getNextElement().getId()));
Assert.assertThat(yedContext.getModel().getEdges().size(), is(jsonReadContext.getModel().getEdges().size()));
Assert.assertThat(yedContext.getModel().getVertices().size(), is(jsonReadContext.getModel().getVertices().size()));
}

@Test
public void LoginGraphml2Gw3() throws IOException {
Context yedContext = new YEdContextFactory().create(Paths.get("graphml/Login.graphml"));
Assert.assertNotNull(yedContext);
public void convertDotToDot() throws IOException {
Context dotContext = new DotContextFactory().create(Paths.get("dot/Login.dot"));
Assert.assertNotNull(dotContext);

File testFile = testFolder.newFile("Login.gw3");
Context gw3WriteContext = new GW3ContextFactory().write(yedContext, testFile.toPath());
Assert.assertNotNull(gw3WriteContext);
File tempFile = testFolder.newFile("test.dot");
Context dotWriteContext = new DotContextFactory().write(dotContext, tempFile.toPath());
Assert.assertNotNull(dotWriteContext);

Context gw3ReadContext = new GW3ContextFactory().create(testFile.toPath());
Assert.assertNotNull(gw3ReadContext);
Context dotReadContext = new DotContextFactory().create(tempFile.toPath());
Assert.assertNotNull(dotReadContext);

Assert.assertThat(yedContext.getNextElement().getId(), is(gw3WriteContext.getNextElement().getId()));
Assert.assertThat(yedContext.getModel().getEdges().size(), is(gw3WriteContext.getModel().getEdges().size()));
Assert.assertThat(yedContext.getModel().getVertices().size(), is(gw3WriteContext.getModel().getVertices().size()));
Assert.assertThat(yedContext.getNextElement().getId(), is(gw3ReadContext.getNextElement().getId()));
Assert.assertThat(yedContext.getModel().getEdges().size(), is(gw3ReadContext.getModel().getEdges().size()));
Assert.assertThat(yedContext.getModel().getVertices().size(), is(gw3ReadContext.getModel().getVertices().size()));
Assert.assertThat(dotContext.getModel().getEdges().size(), is(dotReadContext.getModel().getEdges().size()));
Assert.assertThat(dotContext.getModel().getVertices().size(), is(dotReadContext.getModel().getVertices().size()));
}

@Test
public void convertDotToJava() throws IOException {
Context dotContext = new DotContextFactory().create(Paths.get("dot/Login.dot"));
Assert.assertNotNull(dotContext);

File tempFile = testFolder.newFile("test.java");
Context javaWriteContext = new JavaContextFactory().write(dotContext, tempFile.toPath());
Assert.assertNotNull(javaWriteContext);

Assert.assertThat(dotContext.getModel().getEdges().size(), is(javaWriteContext.getModel().getEdges().size()));
Assert.assertThat(dotContext.getModel().getVertices().size(), is(javaWriteContext.getModel().getVertices().size()));
}

@Test
public void convertDotToGraphml() throws IOException {
Context dotContext = new DotContextFactory().create(Paths.get("dot/Login.dot"));
Assert.assertNotNull(dotContext);

File tempFile = testFolder.newFile("test.graphml");
Context yedWriteContext = new YEdContextFactory().write(dotContext, tempFile.toPath());
Assert.assertNotNull(yedWriteContext);

Context yedReadContext = new YEdContextFactory().create(tempFile.toPath());
Assert.assertNotNull(yedReadContext);

// Since edges without source vertex is not allowed in yed/graphml, the yedReadContext will be one edge short
Assert.assertThat(dotContext.getModel().getEdges().size(), is(yedReadContext.getModel().getEdges().size() + 1));
Assert.assertThat(dotContext.getModel().getVertices().size(), is(yedReadContext.getModel().getVertices().size()));
}

@Test
public void convertDotToJson() throws IOException {
Context dotContext = new DotContextFactory().create(Paths.get("dot/Login.dot"));
Assert.assertNotNull(dotContext);

File testFile = testFolder.newFile("test.json");
Context jsonWriteContext = new JsonContextFactory().write(dotContext, testFile.toPath());
Assert.assertNotNull(jsonWriteContext);

Context jsonReadContext = new JsonContextFactory().create(testFile.toPath());
Assert.assertNotNull(jsonReadContext);

Assert.assertThat(dotContext.getModel().getEdges().size(), is(jsonWriteContext.getModel().getEdges().size()));
Assert.assertThat(dotContext.getModel().getVertices().size(), is(jsonWriteContext.getModel().getVertices().size()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public void SimpleGWGraph() {

@Test
public void GW_Login() {
Context context = new DotContextFactory().create(Paths.get("dot/gw/Login.dot"));
Context context = new DotContextFactory().create(Paths.get("dot/Login.dot"));
Assert.assertThat(context.getModel().getVertices().size(), is(3));
Assert.assertThat(context.getModel().getEdges().size(), is(9));
}
Expand Down
Loading

0 comments on commit 36fc9cb

Please sign in to comment.