Skip to content
Snippets Groups Projects
Commit 519f7a08 authored by Nils Christian Ehmke's avatar Nils Christian Ehmke
Browse files

Added some code for call tree generation

parent 0b171313
No related branches found
No related tags found
No related merge requests found
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
package kieker.diagnosis.domain; package kieker.diagnosis.domain;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Deque;
import java.util.LinkedList;
import java.util.List; import java.util.List;
/** /**
...@@ -176,4 +178,28 @@ public abstract class AbstractOperationCall<T extends AbstractOperationCall<T>> ...@@ -176,4 +178,28 @@ public abstract class AbstractOperationCall<T extends AbstractOperationCall<T>>
return true; return true;
} }
public final String toDotForCallTree() {
final Deque<AbstractOperationCall<T>> stack = new LinkedList<>();
final StringBuilder sb = new StringBuilder();
sb.append("digraph G {");
sb.append("rankdir = TB;");
sb.append("node [shape = none];");
stack.push(this);
while (!stack.isEmpty()) {
final AbstractOperationCall<T> call = stack.pop();
sb.append(call.operation).append(';');
for (final AbstractOperationCall<T> child : call.children) {
sb.append(call.operation).append(" -> ").append(child.operation).append(';');
stack.push(child);
}
}
sb.append("}");
return sb.toString();
}
} }
...@@ -20,7 +20,6 @@ import static org.hamcrest.core.Is.is; ...@@ -20,7 +20,6 @@ import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsEqual.equalTo; import static org.hamcrest.core.IsEqual.equalTo;
import static org.hamcrest.core.IsNot.not; import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import kieker.diagnosis.domain.AbstractOperationCall;
import org.junit.Test; import org.junit.Test;
...@@ -98,4 +97,14 @@ public abstract class AbstractOperationCallTest<T extends AbstractOperationCall< ...@@ -98,4 +97,14 @@ public abstract class AbstractOperationCallTest<T extends AbstractOperationCall<
assertThat(fstCall, is(not(equalTo(sndCall)))); assertThat(fstCall, is(not(equalTo(sndCall))));
} }
@Test
public void toDotForCallTreeShouldWorkForSimpleCase() {
final T call = this.createOperationCall("container", "component", "operation");
call.addChild(this.createOperationCall("container1", "component1", "operation1"));
call.addChild(this.createOperationCall("container2", "component2", "operation2"));
assertThat(call.toDotForCallTree(), is("digraph G {rankdir = TB;node [shape = none];operation;operation -> operation1;operation -> operation2;operation2;operation1;}"));
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment