Revize 77453bcc
Přidáno uživatelem Martin Matas před téměř 6 roky(ů)
sources/imiger-dot-converter/src/main/java/cz/zcu/kiv/imiger/plugin/dot/BaseGraphFactory.java | ||
---|---|---|
17 | 17 |
*/ |
18 | 18 |
public abstract class BaseGraphFactory<V extends VertexDTO, E extends EdgeDTO> { |
19 | 19 |
|
20 |
/**
|
|
21 |
* List of vertex archetypes that must factory initialize.
|
|
22 |
*/
|
|
23 |
protected List<VertexArchetype> vertexArchetypes;
|
|
24 |
|
|
25 |
/**
|
|
26 |
* List of edge archetypes that must factory initialize.
|
|
27 |
*/
|
|
28 |
protected List<EdgeArchetype> edgeArchetypes;
|
|
29 |
|
|
30 |
/**
|
|
31 |
* List of defined attribute types retrieved from {@link BaseDOTLoader}.
|
|
32 |
*/
|
|
33 |
protected List<AttributeType> attributeTypes;
|
|
34 |
|
|
35 |
/**
|
|
36 |
* List of defined vertices retrieved from {@link BaseDOTLoader}. {@link VertexDTO} is
|
|
37 |
* specific vertex created with DOTLoader.
|
|
38 |
*/
|
|
39 |
protected List<VertexDTO> vertices;
|
|
40 |
|
|
41 |
/**
|
|
42 |
* List of defined edges retrieved from {@link BaseDOTLoader}. {@link EdgeDTO} is
|
|
43 |
* specific vertex created with DOTLoader.
|
|
44 |
*/
|
|
45 |
protected List<EdgeDTO> edges;
|
|
20 |
/**
|
|
21 |
* List of vertex archetypes that must factory initialize.
|
|
22 |
*/
|
|
23 |
protected List<VertexArchetype> vertexArchetypes;
|
|
24 |
|
|
25 |
/**
|
|
26 |
* List of edge archetypes that must factory initialize.
|
|
27 |
*/
|
|
28 |
protected List<EdgeArchetype> edgeArchetypes;
|
|
29 |
|
|
30 |
/**
|
|
31 |
* List of defined attribute types retrieved from {@link BaseDOTLoader}.
|
|
32 |
*/
|
|
33 |
protected List<AttributeType> attributeTypes;
|
|
34 |
|
|
35 |
/**
|
|
36 |
* List of defined vertices retrieved from {@link BaseDOTLoader}. {@link VertexDTO} is
|
|
37 |
* specific vertex created with DOTLoader.
|
|
38 |
*/
|
|
39 |
protected List<VertexDTO> vertices;
|
|
40 |
|
|
41 |
/**
|
|
42 |
* List of defined edges retrieved from {@link BaseDOTLoader}. {@link EdgeDTO} is
|
|
43 |
* specific vertex created with DOTLoader.
|
|
44 |
*/
|
|
45 |
protected List<EdgeDTO> edges;
|
|
46 | 46 |
|
47 | 47 |
/** |
48 | 48 |
* Map of possible enum values that must factory initialize. |
49 | 49 |
*/ |
50 |
protected Map<Integer, List<String>> possibleEnumValues;
|
|
50 |
protected Map<Integer, List<String>> possibleEnumValues;
|
|
51 | 51 |
|
52 | 52 |
/** |
53 | 53 |
* List of groups that must factory initialize. |
54 | 54 |
*/ |
55 |
protected List<Group> groups;
|
|
55 |
protected List<Group> groups;
|
|
56 | 56 |
|
57 | 57 |
/** |
58 | 58 |
* List of sidebars that must factory initialize. |
59 | 59 |
*/ |
60 |
protected List<SideBar> sideBar;
|
|
60 |
protected List<SideBar> sideBar;
|
|
61 | 61 |
|
62 | 62 |
/** |
63 | 63 |
* Edge that will be highlighted when graph loads. GraphFactory must initialize. |
64 | 64 |
*/ |
65 |
protected String highlightedEdge;
|
|
65 |
protected String highlightedEdge;
|
|
66 | 66 |
|
67 | 67 |
/** |
68 | 68 |
* Vertex that will be highlighted when graph loads. GraphFactory must initialize. |
69 | 69 |
*/ |
70 |
protected String highlightedVertex;
|
|
71 |
|
|
72 |
/**
|
|
73 |
* Constructor initialize data that can be retrieved from {@link BaseDOTLoader}, the rest of
|
|
74 |
* necessary attributes for creating graph must be initialized in children of this abstract class.
|
|
75 |
*
|
|
76 |
* @param dotLoader - instance of {@link BaseDOTLoader} which provides parsed data from DOT file
|
|
77 |
*/
|
|
78 |
protected BaseGraphFactory(BaseDOTLoader<V, E> dotLoader) {
|
|
79 |
vertices = new ArrayList<>();
|
|
80 |
edges = new ArrayList<>();
|
|
81 |
attributeTypes = new ArrayList<>();
|
|
82 |
loadData(dotLoader);
|
|
83 |
}
|
|
84 |
|
|
85 |
/**
|
|
86 |
* Must initialize necessary attributes for creating graph from data provided by {@link BaseDOTLoader}.
|
|
87 |
*
|
|
88 |
* @param dotLoader - instance of {@link BaseDOTLoader} which provides parsed data from DOT file
|
|
89 |
*/
|
|
90 |
protected abstract void loadData(BaseDOTLoader<V, E> dotLoader);
|
|
91 |
|
|
92 |
/**
|
|
93 |
* Must create instance of {@link Graph} from created and retrieved data.
|
|
94 |
*
|
|
95 |
* @return - new graph created from prepared data
|
|
96 |
*/
|
|
97 |
public abstract Graph createGraph();
|
|
70 |
protected String highlightedVertex;
|
|
71 |
|
|
72 |
/**
|
|
73 |
* Constructor initialize data that can be retrieved from {@link BaseDOTLoader}, the rest of
|
|
74 |
* necessary attributes for creating graph must be initialized in children of this abstract class.
|
|
75 |
*
|
|
76 |
* @param dotLoader - instance of {@link BaseDOTLoader} which provides parsed data from DOT file
|
|
77 |
*/
|
|
78 |
protected BaseGraphFactory(BaseDOTLoader<V, E> dotLoader) {
|
|
79 |
vertices = new ArrayList<>();
|
|
80 |
edges = new ArrayList<>();
|
|
81 |
attributeTypes = new ArrayList<>();
|
|
82 |
loadData(dotLoader);
|
|
83 |
}
|
|
84 |
|
|
85 |
/**
|
|
86 |
* Must initialize necessary attributes for creating graph from data provided by {@link BaseDOTLoader}.
|
|
87 |
*
|
|
88 |
* @param dotLoader - instance of {@link BaseDOTLoader} which provides parsed data from DOT file
|
|
89 |
*/
|
|
90 |
protected abstract void loadData(BaseDOTLoader<V, E> dotLoader);
|
|
91 |
|
|
92 |
/**
|
|
93 |
* Must create instance of {@link Graph} from created and retrieved data.
|
|
94 |
*
|
|
95 |
* @return - new graph created from prepared data
|
|
96 |
*/
|
|
97 |
public abstract Graph createGraph();
|
|
98 | 98 |
|
99 | 99 |
} |
sources/imiger-dot-converter/src/main/java/cz/zcu/kiv/imiger/plugin/dot/GraphFactory.java | ||
---|---|---|
16 | 16 |
*/ |
17 | 17 |
public class GraphFactory extends BaseGraphFactory<VertexDTO, EdgeDTO> { |
18 | 18 |
|
19 |
/**
|
|
20 |
* Name of default edge archetype name field.
|
|
21 |
*/
|
|
22 |
private static final String EDGE_ARCHETYPE_NAME = "Edge";
|
|
23 |
|
|
24 |
/**
|
|
25 |
* Name of default vertex archetype name field.
|
|
26 |
*/
|
|
27 |
private static final String VERTEX_ARCHETYPE_NAME = "Vertex";
|
|
28 |
|
|
29 |
/**
|
|
30 |
* Value of default archetype text field.
|
|
31 |
*/
|
|
32 |
private static final String ARCHETYPE_TEXT = "";
|
|
33 |
|
|
34 |
/**
|
|
35 |
* Index of default archetype in created archetype list.
|
|
36 |
*/
|
|
37 |
private static final int DEFAULT_ARCHETYPE_INDEX = 0;
|
|
38 |
|
|
39 |
/**
|
|
40 |
* Retrieves data from {@link BaseDOTLoader} and defines archetypes for vertices and edges.
|
|
41 |
*
|
|
42 |
* @param dotLoader - instance of {@link BaseDOTLoader} which provides parsed data from DOT file
|
|
43 |
*/
|
|
44 |
public GraphFactory(BaseDOTLoader<VertexDTO,EdgeDTO> dotLoader) {
|
|
45 |
super(dotLoader);
|
|
46 |
prepareEdgeArchetypes();
|
|
47 |
prepareVertexArchetypes();
|
|
48 |
preparePossibleEnumValues();
|
|
49 |
prepareGroups();
|
|
50 |
prepareSideBar();
|
|
51 |
defineHighlightedVertex();
|
|
19 |
/**
|
|
20 |
* Name of default edge archetype name field.
|
|
21 |
*/
|
|
22 |
private static final String EDGE_ARCHETYPE_NAME = "Edge";
|
|
23 |
|
|
24 |
/**
|
|
25 |
* Name of default vertex archetype name field.
|
|
26 |
*/
|
|
27 |
private static final String VERTEX_ARCHETYPE_NAME = "Vertex";
|
|
28 |
|
|
29 |
/**
|
|
30 |
* Value of default archetype text field.
|
|
31 |
*/
|
|
32 |
private static final String ARCHETYPE_TEXT = "";
|
|
33 |
|
|
34 |
/**
|
|
35 |
* Index of default archetype in created archetype list.
|
|
36 |
*/
|
|
37 |
private static final int DEFAULT_ARCHETYPE_INDEX = 0;
|
|
38 |
|
|
39 |
/**
|
|
40 |
* Retrieves data from {@link BaseDOTLoader} and defines archetypes for vertices and edges.
|
|
41 |
*
|
|
42 |
* @param dotLoader - instance of {@link BaseDOTLoader} which provides parsed data from DOT file
|
|
43 |
*/
|
|
44 |
public GraphFactory(BaseDOTLoader<VertexDTO,EdgeDTO> dotLoader) {
|
|
45 |
super(dotLoader);
|
|
46 |
prepareEdgeArchetypes();
|
|
47 |
prepareVertexArchetypes();
|
|
48 |
preparePossibleEnumValues();
|
|
49 |
prepareGroups();
|
|
50 |
prepareSideBar();
|
|
51 |
defineHighlightedVertex();
|
|
52 | 52 |
defineHighlightedEdge(); |
53 |
}
|
|
54 |
|
|
55 |
/**
|
|
56 |
* Initialize attributes that can be filled with data from {@link BaseDOTLoader}. In case when
|
|
57 |
* DOTLoader returns uninitialized lists, attributes will be initialized empty.
|
|
58 |
*
|
|
59 |
* @param dotLoader - instance of {@link BaseDOTLoader} which provides parsed data from DOT file
|
|
60 |
*/
|
|
61 |
@Override
|
|
62 |
protected void loadData(BaseDOTLoader<VertexDTO,EdgeDTO> dotLoader) {
|
|
63 |
List<VertexDTO> loadedVertices = dotLoader.getVertices();
|
|
64 |
List<EdgeDTO> loadedEdges = dotLoader.getEdges();
|
|
65 |
Set<AttributeType> loadedAttributeTypes = dotLoader.getAttributeTypes();
|
|
66 |
|
|
67 |
if (loadedVertices != null) {
|
|
68 |
vertices = new ArrayList<>(loadedVertices);
|
|
69 |
}
|
|
70 |
|
|
71 |
if (loadedEdges != null) {
|
|
72 |
edges = new ArrayList<>(loadedEdges);
|
|
73 |
}
|
|
74 |
|
|
75 |
if (loadedAttributeTypes != null) {
|
|
76 |
attributeTypes = new ArrayList<>(loadedAttributeTypes);
|
|
77 |
}
|
|
78 |
}
|
|
79 |
|
|
80 |
/**
|
|
81 |
* Creates new graph from data which were prepared when instance was created.
|
|
82 |
*
|
|
83 |
* @return - new instance of graph
|
|
84 |
*/
|
|
85 |
@Override
|
|
86 |
public Graph createGraph() {
|
|
87 |
Graph graph = new Graph();
|
|
88 |
|
|
89 |
graph.setEdgeArchetypes(edgeArchetypes);
|
|
90 |
graph.setVertexArchetypes(vertexArchetypes);
|
|
91 |
graph.setAttributeTypes(attributeTypes);
|
|
92 |
graph.setPossibleEnumValues(possibleEnumValues);
|
|
93 |
graph.setGroups(groups);
|
|
94 |
graph.setSideBar(sideBar);
|
|
95 |
graph.setHighlightedEdge(highlightedEdge);
|
|
96 |
graph.setHighlightedVertex(highlightedVertex);
|
|
97 |
addEdgesToGraph(graph, edges);
|
|
98 |
addVerticesToGraph(graph, vertices);
|
|
99 |
|
|
100 |
return graph;
|
|
101 |
}
|
|
102 |
|
|
103 |
/**
|
|
104 |
* Iterates through the list of vertices retrieved from {@link BaseDOTLoader} and for each of them
|
|
105 |
* creates new graph vertex.
|
|
106 |
*
|
|
107 |
* @param graph - reference to the instance of new graph
|
|
108 |
* @param vertices - vertices retrieved from {@link BaseDOTLoader}
|
|
109 |
*/
|
|
110 |
private void addVerticesToGraph(Graph graph, List<VertexDTO> vertices) {
|
|
111 |
for (VertexDTO v : vertices) {
|
|
112 |
|
|
113 |
List<String[]> attributes = checkAttributes(v.getAttributes(), attributeTypes);
|
|
114 |
Vertex vertex = new Vertex(v.getId(), v.getName(), DEFAULT_ARCHETYPE_INDEX, "", attributes);
|
|
115 |
graph.getVertices().add(vertex);
|
|
116 |
}
|
|
117 |
}
|
|
118 |
|
|
119 |
/**
|
|
120 |
* Iterates through the list of edges retrieved from {@link BaseDOTLoader} and for each of them
|
|
121 |
* creates new graph edge.
|
|
122 |
*
|
|
123 |
* @param graph - reference to the instance of new graph
|
|
124 |
* @param edges - edges retrieved from {@link BaseDOTLoader}
|
|
125 |
*/
|
|
126 |
private void addEdgesToGraph(Graph graph, List<EdgeDTO> edges) {
|
|
127 |
for (EdgeDTO e : edges) {
|
|
128 |
|
|
129 |
List<String[]> attributes = checkAttributes(e.getAttributes(), attributeTypes);
|
|
130 |
SubedgeInfo subedgeInfo = new SubedgeInfo(e.getId(), DEFAULT_ARCHETYPE_INDEX, attributes);
|
|
131 |
|
|
132 |
List<SubedgeInfo> subedgeInfos = new ArrayList<>();
|
|
133 |
subedgeInfos.add(subedgeInfo);
|
|
134 |
|
|
135 |
Edge edge = new Edge(e.getId(), e.getIdFrom(), e.getIdTo(), e.getName(), subedgeInfos);
|
|
136 |
graph.getEdges().add(edge);
|
|
137 |
}
|
|
138 |
}
|
|
139 |
|
|
140 |
/**
|
|
141 |
* Iterates through the list of attributes and for each of them checks if the attribute type exists. Then for the
|
|
142 |
* attribute creates key-value pair using {@link String[]}, where key is the attribute type and value is the
|
|
143 |
* value of attribute.
|
|
144 |
*
|
|
145 |
* @param uncheckedAttributes - map of attributes retrieved from {@link BaseDOTLoader}, where key is unchecked
|
|
146 |
* attribute type and value is the value of attribute
|
|
147 |
* @param attributeTypes - list of attribute types retrieved from {@link BaseDOTLoader} against which will be unchecked
|
|
148 |
* attributes validated
|
|
149 |
* @return - list of checked attributes
|
|
150 |
*/
|
|
151 |
private List<String[]> checkAttributes(Map<String, String> uncheckedAttributes, List<AttributeType> attributeTypes) {
|
|
152 |
List<String[]> attributes = new ArrayList<>();
|
|
153 |
Set<String> attributesHashSet = new HashSet<>();
|
|
154 |
|
|
155 |
attributeTypes.forEach(t -> attributesHashSet.add(t.getName()));
|
|
156 |
|
|
157 |
for (Map.Entry<String, String> e: uncheckedAttributes.entrySet()) {
|
|
158 |
if (attributesHashSet.contains(e.getKey())) {
|
|
159 |
attributes.add(new String[]{e.getKey(), e.getValue()});
|
|
160 |
}
|
|
161 |
}
|
|
162 |
|
|
163 |
return attributes;
|
|
164 |
}
|
|
165 |
|
|
166 |
/**
|
|
167 |
* Defines default edge archetype for edges.
|
|
168 |
*/
|
|
169 |
private void prepareEdgeArchetypes() {
|
|
170 |
edgeArchetypes = new ArrayList<>();
|
|
171 |
edgeArchetypes.add(new EdgeArchetype(EDGE_ARCHETYPE_NAME, ARCHETYPE_TEXT));
|
|
172 |
}
|
|
173 |
|
|
174 |
/**
|
|
175 |
* Defines default vertex archetypes for vertices.
|
|
176 |
*/
|
|
177 |
private void prepareVertexArchetypes() {
|
|
178 |
vertexArchetypes = new ArrayList<>();
|
|
179 |
vertexArchetypes.add(new VertexArchetype(VERTEX_ARCHETYPE_NAME, ARCHETYPE_TEXT));
|
|
180 |
}
|
|
53 |
}
|
|
54 |
|
|
55 |
/**
|
|
56 |
* Initialize attributes that can be filled with data from {@link BaseDOTLoader}. In case when
|
|
57 |
* DOTLoader returns uninitialized lists, attributes will be initialized empty.
|
|
58 |
*
|
|
59 |
* @param dotLoader - instance of {@link BaseDOTLoader} which provides parsed data from DOT file
|
|
60 |
*/
|
|
61 |
@Override
|
|
62 |
protected void loadData(BaseDOTLoader<VertexDTO,EdgeDTO> dotLoader) {
|
|
63 |
List<VertexDTO> loadedVertices = dotLoader.getVertices();
|
|
64 |
List<EdgeDTO> loadedEdges = dotLoader.getEdges();
|
|
65 |
Set<AttributeType> loadedAttributeTypes = dotLoader.getAttributeTypes();
|
|
66 |
|
|
67 |
if (loadedVertices != null) {
|
|
68 |
vertices = new ArrayList<>(loadedVertices);
|
|
69 |
}
|
|
70 |
|
|
71 |
if (loadedEdges != null) {
|
|
72 |
edges = new ArrayList<>(loadedEdges);
|
|
73 |
}
|
|
74 |
|
|
75 |
if (loadedAttributeTypes != null) {
|
|
76 |
attributeTypes = new ArrayList<>(loadedAttributeTypes);
|
|
77 |
}
|
|
78 |
}
|
|
79 |
|
|
80 |
/**
|
|
81 |
* Creates new graph from data which were prepared when instance was created.
|
|
82 |
*
|
|
83 |
* @return - new instance of graph
|
|
84 |
*/
|
|
85 |
@Override
|
|
86 |
public Graph createGraph() {
|
|
87 |
Graph graph = new Graph();
|
|
88 |
|
|
89 |
graph.setEdgeArchetypes(edgeArchetypes);
|
|
90 |
graph.setVertexArchetypes(vertexArchetypes);
|
|
91 |
graph.setAttributeTypes(attributeTypes);
|
|
92 |
graph.setPossibleEnumValues(possibleEnumValues);
|
|
93 |
graph.setGroups(groups);
|
|
94 |
graph.setSideBar(sideBar);
|
|
95 |
graph.setHighlightedEdge(highlightedEdge);
|
|
96 |
graph.setHighlightedVertex(highlightedVertex);
|
|
97 |
addEdgesToGraph(graph, edges);
|
|
98 |
addVerticesToGraph(graph, vertices);
|
|
99 |
|
|
100 |
return graph;
|
|
101 |
}
|
|
102 |
|
|
103 |
/**
|
|
104 |
* Iterates through the list of vertices retrieved from {@link BaseDOTLoader} and for each of them
|
|
105 |
* creates new graph vertex.
|
|
106 |
*
|
|
107 |
* @param graph - reference to the instance of new graph
|
|
108 |
* @param vertices - vertices retrieved from {@link BaseDOTLoader}
|
|
109 |
*/
|
|
110 |
private void addVerticesToGraph(Graph graph, List<VertexDTO> vertices) {
|
|
111 |
for (VertexDTO v : vertices) {
|
|
112 |
|
|
113 |
List<String[]> attributes = checkAttributes(v.getAttributes(), attributeTypes);
|
|
114 |
Vertex vertex = new Vertex(v.getId(), v.getName(), DEFAULT_ARCHETYPE_INDEX, "", attributes);
|
|
115 |
graph.getVertices().add(vertex);
|
|
116 |
}
|
|
117 |
}
|
|
118 |
|
|
119 |
/**
|
|
120 |
* Iterates through the list of edges retrieved from {@link BaseDOTLoader} and for each of them
|
|
121 |
* creates new graph edge.
|
|
122 |
*
|
|
123 |
* @param graph - reference to the instance of new graph
|
|
124 |
* @param edges - edges retrieved from {@link BaseDOTLoader}
|
|
125 |
*/
|
|
126 |
private void addEdgesToGraph(Graph graph, List<EdgeDTO> edges) {
|
|
127 |
for (EdgeDTO e : edges) {
|
|
128 |
|
|
129 |
List<String[]> attributes = checkAttributes(e.getAttributes(), attributeTypes);
|
|
130 |
SubedgeInfo subedgeInfo = new SubedgeInfo(e.getId(), DEFAULT_ARCHETYPE_INDEX, attributes);
|
|
131 |
|
|
132 |
List<SubedgeInfo> subedgeInfos = new ArrayList<>();
|
|
133 |
subedgeInfos.add(subedgeInfo);
|
|
134 |
|
|
135 |
Edge edge = new Edge(e.getId(), e.getIdFrom(), e.getIdTo(), e.getName(), subedgeInfos);
|
|
136 |
graph.getEdges().add(edge);
|
|
137 |
}
|
|
138 |
}
|
|
139 |
|
|
140 |
/**
|
|
141 |
* Iterates through the list of attributes and for each of them checks if the attribute type exists. Then for the
|
|
142 |
* attribute creates key-value pair using {@link String[]}, where key is the attribute type and value is the
|
|
143 |
* value of attribute.
|
|
144 |
*
|
|
145 |
* @param uncheckedAttributes - map of attributes retrieved from {@link BaseDOTLoader}, where key is unchecked
|
|
146 |
* attribute type and value is the value of attribute
|
|
147 |
* @param attributeTypes - list of attribute types retrieved from {@link BaseDOTLoader} against which will be unchecked
|
|
148 |
* attributes validated
|
|
149 |
* @return - list of checked attributes
|
|
150 |
*/
|
|
151 |
private List<String[]> checkAttributes(Map<String, String> uncheckedAttributes, List<AttributeType> attributeTypes) {
|
|
152 |
List<String[]> attributes = new ArrayList<>();
|
|
153 |
Set<String> attributesHashSet = new HashSet<>();
|
|
154 |
|
|
155 |
attributeTypes.forEach(t -> attributesHashSet.add(t.getName()));
|
|
156 |
|
|
157 |
for (Map.Entry<String, String> e: uncheckedAttributes.entrySet()) {
|
|
158 |
if (attributesHashSet.contains(e.getKey())) {
|
|
159 |
attributes.add(new String[]{e.getKey(), e.getValue()});
|
|
160 |
}
|
|
161 |
}
|
|
162 |
|
|
163 |
return attributes;
|
|
164 |
}
|
|
165 |
|
|
166 |
/**
|
|
167 |
* Defines default edge archetype for edges.
|
|
168 |
*/
|
|
169 |
private void prepareEdgeArchetypes() {
|
|
170 |
edgeArchetypes = new ArrayList<>();
|
|
171 |
edgeArchetypes.add(new EdgeArchetype(EDGE_ARCHETYPE_NAME, ARCHETYPE_TEXT));
|
|
172 |
}
|
|
173 |
|
|
174 |
/**
|
|
175 |
* Defines default vertex archetypes for vertices.
|
|
176 |
*/
|
|
177 |
private void prepareVertexArchetypes() {
|
|
178 |
vertexArchetypes = new ArrayList<>();
|
|
179 |
vertexArchetypes.add(new VertexArchetype(VERTEX_ARCHETYPE_NAME, ARCHETYPE_TEXT));
|
|
180 |
}
|
|
181 | 181 |
|
182 | 182 |
/** |
183 | 183 |
* Defines default map of possible enum values. |
184 | 184 |
*/ |
185 |
private void preparePossibleEnumValues() {
|
|
186 |
possibleEnumValues = new HashMap<>();
|
|
187 |
}
|
|
185 |
private void preparePossibleEnumValues() {
|
|
186 |
possibleEnumValues = new HashMap<>();
|
|
187 |
}
|
|
188 | 188 |
|
189 | 189 |
|
190 | 190 |
/** |
191 | 191 |
* Defines default list fo groups. |
192 | 192 |
*/ |
193 |
private void prepareGroups() {
|
|
194 |
groups = new ArrayList<>();
|
|
195 |
}
|
|
193 |
private void prepareGroups() {
|
|
194 |
groups = new ArrayList<>();
|
|
195 |
}
|
|
196 | 196 |
|
197 | 197 |
|
198 | 198 |
/** |
199 | 199 |
* Defines default list of sidebars. |
200 | 200 |
*/ |
201 |
private void prepareSideBar() {
|
|
202 |
sideBar = new ArrayList<>();
|
|
203 |
}
|
|
201 |
private void prepareSideBar() {
|
|
202 |
sideBar = new ArrayList<>();
|
|
203 |
}
|
|
204 | 204 |
|
205 | 205 |
|
206 | 206 |
/** |
207 | 207 |
* Defines default highlighted edge. Empty string means that no edge will be highlighted |
208 | 208 |
* when graph loads. |
209 | 209 |
*/ |
210 |
private void defineHighlightedEdge() {
|
|
211 |
highlightedEdge = "";
|
|
212 |
}
|
|
210 |
private void defineHighlightedEdge() {
|
|
211 |
highlightedEdge = "";
|
|
212 |
}
|
|
213 | 213 |
|
214 | 214 |
/** |
215 | 215 |
* Defines default highlighted vertex. Empty string means that no vertex will be highlighted |
216 | 216 |
* when graph loads. |
217 | 217 |
*/ |
218 |
private void defineHighlightedVertex() {
|
|
219 |
highlightedVertex = "";
|
|
220 |
}
|
|
218 |
private void defineHighlightedVertex() {
|
|
219 |
highlightedVertex = "";
|
|
220 |
}
|
|
221 | 221 |
|
222 | 222 |
} |
sources/imiger-dot-converter/src/test/java/cz/zcu/kiv/imiger/plugin/dot/GraphFactoryTest.java | ||
---|---|---|
29 | 29 |
@RunWith(MockitoJUnitRunner.class) |
30 | 30 |
public class GraphFactoryTest { |
31 | 31 |
|
32 |
/** Name of attribute type */
|
|
33 |
private static final String ATTR_TYPE_NAME = "test";
|
|
34 |
|
|
35 |
/** Text of attribute type */
|
|
36 |
private static final String ATTR_TYPE_TEXT = "test attribute type";
|
|
37 |
|
|
38 |
/** List index / Attribute identifier */
|
|
39 |
private static final int ATTR_TYPE_ID = 0;
|
|
40 |
|
|
41 |
/** Vertex / Edge attribute value */
|
|
42 |
private static final String ATTR_VALUE = "test value";
|
|
43 |
|
|
44 |
/** Vertices names */
|
|
45 |
private static final String VERTEX_A = "A";
|
|
46 |
private static final String VERTEX_B = "B";
|
|
47 |
|
|
48 |
/** Lists indexes / Vertices identifiers */
|
|
49 |
private static final int VERTEX_A_ID = 0;
|
|
50 |
private static final int VERTEX_B_ID = 1;
|
|
51 |
|
|
52 |
/** Edge name */
|
|
53 |
private static final String EDGE_AB = "A-B";
|
|
54 |
|
|
55 |
/** Edge identifier */
|
|
56 |
private static final int EDGE_AB_ID = 0;
|
|
57 |
|
|
58 |
/** Archetypes names */
|
|
59 |
private static final String EDGE_ARCHETYPE = "Edge";
|
|
60 |
private static final String VERTEX_ARCHETYPE = "Vertex";
|
|
61 |
|
|
62 |
private static final boolean EMPTY_UNUSED_CLASS_ATTR = true;
|
|
63 |
|
|
64 |
/**
|
|
65 |
* Mock object of {@link BaseDOTLoader}.
|
|
66 |
*/
|
|
67 |
@Mock
|
|
68 |
private BaseDOTLoader<VertexDTO, EdgeDTO> loaderMock;
|
|
69 |
|
|
70 |
/**
|
|
71 |
* Expects that retrieves correct non-empty data from DOTLoader.
|
|
72 |
*/
|
|
73 |
@Test
|
|
74 |
public void loadDataFromCorrectLoader() {
|
|
75 |
final int expectedAttributeTypeSize = 1, expectedEdgesSize = 1, expectedVerticesSize = 2;
|
|
76 |
|
|
77 |
initCorrectLoader();
|
|
78 |
BaseGraphFactory<VertexDTO, EdgeDTO> factory = new GraphFactory(loaderMock);
|
|
79 |
|
|
80 |
// test method logic
|
|
81 |
verify(loaderMock).getAttributeTypes();
|
|
82 |
verify(loaderMock).getEdges();
|
|
83 |
verify(loaderMock).getVertices();
|
|
84 |
// test attributes initialization
|
|
85 |
assertThat(factory.attributeTypes.size(), is(expectedAttributeTypeSize));
|
|
86 |
assertThat(factory.edges.size(), is(expectedEdgesSize));
|
|
87 |
assertThat(factory.vertices.size(), is(expectedVerticesSize));
|
|
88 |
assertThat(factory.edgeArchetypes, is(not(nullValue())));
|
|
89 |
assertThat(factory.vertexArchetypes, is(not(nullValue())));
|
|
90 |
assertThat(factory.possibleEnumValues, is(not(nullValue())));
|
|
91 |
assertThat(factory.groups, is(not(nullValue())));
|
|
92 |
assertThat(factory.sideBar, is(not(nullValue())));
|
|
93 |
assertThat(factory.highlightedEdge, is(not(nullValue())));
|
|
94 |
assertThat(factory.highlightedVertex, is(not(nullValue())));
|
|
95 |
// test attribute type
|
|
96 |
assertThat(factory.attributeTypes.get(ATTR_TYPE_ID).getName(), is(equalTo(ATTR_TYPE_NAME)));
|
|
97 |
assertThat(factory.attributeTypes.get(ATTR_TYPE_ID).getText(), is(equalTo(ATTR_TYPE_TEXT)));
|
|
98 |
// test vertices
|
|
99 |
assertThat(factory.vertices.get(VERTEX_A_ID).getName(), is(equalTo(VERTEX_A)));
|
|
100 |
assertThat(factory.vertices.get(VERTEX_A_ID).getAttributes().get(ATTR_TYPE_NAME), is(equalTo(ATTR_VALUE)));
|
|
101 |
assertThat(factory.vertices.get(VERTEX_B_ID).getName(), is(equalTo(VERTEX_B)));
|
|
102 |
assertThat(factory.vertices.get(VERTEX_B_ID).getAttributes().get(ATTR_TYPE_NAME), is(equalTo(ATTR_VALUE)));
|
|
103 |
// test edges
|
|
104 |
assertThat(factory.edges.get(EDGE_AB_ID).getName(), is(equalTo(EDGE_AB)));
|
|
105 |
// test archetypes
|
|
106 |
assertThat(factory.edgeArchetypes.get(0).getName(), is(equalTo(EDGE_ARCHETYPE)));
|
|
107 |
assertThat(factory.vertexArchetypes.get(0).getName(), is(equalTo(VERTEX_ARCHETYPE)));
|
|
108 |
// the rest of required but unused attributes
|
|
109 |
assertThat(factory.possibleEnumValues.isEmpty(), is(equalTo(EMPTY_UNUSED_CLASS_ATTR)));
|
|
110 |
assertThat(factory.groups.isEmpty(), is(equalTo(EMPTY_UNUSED_CLASS_ATTR)));
|
|
111 |
assertThat(factory.sideBar.isEmpty(), is(equalTo(EMPTY_UNUSED_CLASS_ATTR)));
|
|
112 |
assertThat(factory.highlightedEdge.isEmpty(), is(equalTo(EMPTY_UNUSED_CLASS_ATTR)));
|
|
113 |
assertThat(factory.highlightedVertex.isEmpty(), is(equalTo(EMPTY_UNUSED_CLASS_ATTR)));
|
|
114 |
}
|
|
115 |
|
|
116 |
/**
|
|
117 |
* Expects that retrieves empty data from DOTLoader. In that case all factory attributes
|
|
118 |
* will empty except archetypes that will be created in factory.
|
|
119 |
*/
|
|
120 |
@Test
|
|
121 |
public void loadDataFromEmptyLoader() {
|
|
122 |
final int expectedAttributeTypeSize = 0, expectedEdgesSize = 0, expectedVerticesSize = 0;
|
|
123 |
|
|
124 |
initEmptyLoader();
|
|
125 |
BaseGraphFactory<VertexDTO, EdgeDTO> factory = new GraphFactory(loaderMock);
|
|
126 |
|
|
127 |
verify(loaderMock).getAttributeTypes();
|
|
128 |
verify(loaderMock).getEdges();
|
|
129 |
verify(loaderMock).getVertices();
|
|
130 |
|
|
131 |
assertThat(factory.attributeTypes.size(), is(expectedAttributeTypeSize));
|
|
132 |
assertThat(factory.edges.size(), is(expectedEdgesSize));
|
|
133 |
assertThat(factory.vertices.size(), is(expectedVerticesSize));
|
|
134 |
assertThat(factory.edgeArchetypes, is(not(nullValue())));
|
|
135 |
assertThat(factory.vertexArchetypes, is(not(nullValue())));
|
|
136 |
assertThat(factory.possibleEnumValues, is(not(nullValue())));
|
|
137 |
assertThat(factory.groups, is(not(nullValue())));
|
|
138 |
assertThat(factory.sideBar, is(not(nullValue())));
|
|
139 |
assertThat(factory.highlightedEdge, is(not(nullValue())));
|
|
140 |
assertThat(factory.highlightedVertex, is(not(nullValue())));
|
|
141 |
}
|
|
142 |
|
|
143 |
/**
|
|
144 |
* Expects that retrieves uninitialized data from DOTLoader. In that case all factory attributes
|
|
145 |
* will be initialized empty except archetypes that will be created in factory.
|
|
146 |
*/
|
|
147 |
@Test
|
|
148 |
public void loadDataFromIncorrectLoader() {
|
|
149 |
final int expectedAttributeTypeSize = 0, expectedEdgesSize = 0, expectedVerticesSize = 0;
|
|
150 |
|
|
151 |
initNullValueLoader();
|
|
152 |
BaseGraphFactory<VertexDTO, EdgeDTO> factory = new GraphFactory(loaderMock);
|
|
153 |
|
|
154 |
verify(loaderMock).getAttributeTypes();
|
|
155 |
verify(loaderMock).getEdges();
|
|
156 |
verify(loaderMock).getVertices();
|
|
157 |
|
|
158 |
assertThat(factory.attributeTypes.size(), is(expectedAttributeTypeSize));
|
|
159 |
assertThat(factory.edges.size(), is(expectedEdgesSize));
|
|
160 |
assertThat(factory.vertices.size(), is(expectedVerticesSize));
|
|
161 |
assertThat(factory.edgeArchetypes, is(not(nullValue())));
|
|
162 |
assertThat(factory.vertexArchetypes, is(not(nullValue())));
|
|
163 |
assertThat(factory.possibleEnumValues, is(not(nullValue())));
|
|
164 |
assertThat(factory.groups, is(not(nullValue())));
|
|
165 |
assertThat(factory.sideBar, is(not(nullValue())));
|
|
166 |
assertThat(factory.highlightedEdge, is(not(nullValue())));
|
|
167 |
assertThat(factory.highlightedVertex, is(not(nullValue())));
|
|
168 |
}
|
|
169 |
|
|
170 |
/**
|
|
171 |
* Tests correct creation of the graph instance. Especially vertex's and edge's attributes must be in
|
|
172 |
* correct form.
|
|
173 |
*/
|
|
174 |
@Test
|
|
175 |
public void createGraph() {
|
|
176 |
final int expectedAttributeTypeSize = 1, expectedEdgesSize = 1, expectedVerticesSize = 2;
|
|
177 |
|
|
178 |
// correct loader initialized
|
|
179 |
initCorrectLoader();
|
|
180 |
// loaded data from loader
|
|
181 |
BaseGraphFactory<VertexDTO, EdgeDTO> factory = new GraphFactory(loaderMock);
|
|
182 |
|
|
183 |
// final graph
|
|
184 |
Graph graph = factory.createGraph();
|
|
185 |
|
|
186 |
assertThat(graph, is(not(nullValue())));
|
|
187 |
assertThat(graph.getAttributeTypes().size(), is(expectedAttributeTypeSize));
|
|
188 |
assertThat(graph.getEdges().size(), is(expectedEdgesSize));
|
|
189 |
assertThat(graph.getVertices().size(), is(expectedVerticesSize));
|
|
190 |
assertThat(graph.getEdgeArchetypes(), is(not(nullValue())));
|
|
191 |
assertThat(graph.getVertexArchetypes(), is(not(nullValue())));
|
|
192 |
// test attribute type
|
|
193 |
assertThat(graph.getAttributeTypes().get(ATTR_TYPE_ID).getName(), is(equalTo(ATTR_TYPE_NAME)));
|
|
194 |
assertThat(graph.getAttributeTypes().get(ATTR_TYPE_ID).getText(), is(equalTo(ATTR_TYPE_TEXT)));
|
|
195 |
// test vertices
|
|
196 |
Iterator<Vertex> iterator = graph.getVertices().iterator();
|
|
197 |
Vertex a = iterator.next();
|
|
198 |
Vertex b = iterator.next();
|
|
199 |
assertThat(a.getName(), is(equalTo(VERTEX_A)));
|
|
200 |
assertThat(a.getAttributes().get(0)[0], is(equalTo(ATTR_TYPE_NAME)));
|
|
201 |
assertThat(a.getAttributes().get(0)[1], is(equalTo(ATTR_VALUE)));
|
|
202 |
assertThat(b.getName(), is(equalTo(VERTEX_B)));
|
|
203 |
assertThat(b.getAttributes().get(0)[0], is(equalTo(ATTR_TYPE_NAME)));
|
|
204 |
assertThat(b.getAttributes().get(0)[1], is(equalTo(ATTR_VALUE)));
|
|
205 |
// test edges
|
|
206 |
assertThat(graph.getEdges().get(EDGE_AB_ID).getText(), is(equalTo(EDGE_AB)));
|
|
207 |
assertThat(graph.getEdges().get(EDGE_AB_ID).getSubedgeInfo().get(0).getAttributes().get(0)[0], is(equalTo(ATTR_TYPE_NAME)));
|
|
208 |
assertThat(graph.getEdges().get(EDGE_AB_ID).getSubedgeInfo().get(0).getAttributes().get(0)[1], is(equalTo(ATTR_VALUE)));
|
|
209 |
// test archetypes
|
|
210 |
assertThat(graph.getEdgeArchetypes().get(0).getName(), is(equalTo(EDGE_ARCHETYPE)));
|
|
211 |
assertThat(graph.getVertexArchetypes().get(0).getName(), is(equalTo(VERTEX_ARCHETYPE)));
|
|
212 |
// the rest of required but unused attributes
|
|
213 |
assertThat(graph.getPossibleEnumValues().isEmpty(), is(equalTo(EMPTY_UNUSED_CLASS_ATTR)));
|
|
214 |
assertThat(graph.getGroups().isEmpty(), is(equalTo(EMPTY_UNUSED_CLASS_ATTR)));
|
|
215 |
assertThat(graph.getSideBar().isEmpty(), is(equalTo(EMPTY_UNUSED_CLASS_ATTR)));
|
|
216 |
assertThat(graph.getHighlightedEdge().isEmpty(), is(equalTo(EMPTY_UNUSED_CLASS_ATTR)));
|
|
217 |
assertThat(graph.getHighlightedVertex().isEmpty(), is(equalTo(EMPTY_UNUSED_CLASS_ATTR)));
|
|
218 |
}
|
|
219 |
|
|
220 |
/**
|
|
221 |
* Initializes loader with correct data.
|
|
222 |
*/
|
|
223 |
private void initCorrectLoader() {
|
|
224 |
HashMap<String, String> map = new HashMap<>();
|
|
225 |
map.put(ATTR_TYPE_NAME, ATTR_VALUE);
|
|
226 |
|
|
227 |
Set<AttributeType> attributeTypes = new HashSet<>();
|
|
228 |
attributeTypes.add(new AttributeType(ATTR_TYPE_NAME, AttributeDataType.STRING, ATTR_TYPE_TEXT));
|
|
229 |
|
|
230 |
List<VertexDTO> vertices = new ArrayList<>();
|
|
231 |
vertices.add(new VertexDTO(VERTEX_A, VERTEX_A_ID, map));
|
|
232 |
vertices.add(new VertexDTO(VERTEX_B, VERTEX_B_ID, map));
|
|
233 |
|
|
234 |
List<EdgeDTO> edges = new ArrayList<>();
|
|
235 |
edges.add(new EdgeDTO(EDGE_AB, VERTEX_A_ID, VERTEX_B_ID, EDGE_AB_ID, map));
|
|
236 |
|
|
237 |
when(loaderMock.getAttributeTypes()).thenReturn(attributeTypes);
|
|
238 |
when(loaderMock.getVertices()).thenReturn(vertices);
|
|
239 |
when(loaderMock.getEdges()).thenReturn(edges);
|
|
240 |
}
|
|
241 |
|
|
242 |
/**
|
|
243 |
* Initializes loader for returning empty data.
|
|
244 |
*/
|
|
245 |
private void initEmptyLoader() {
|
|
246 |
Set<AttributeType> attributeTypes = new HashSet<>();
|
|
247 |
List<VertexDTO> vertices = new ArrayList<>();
|
|
248 |
List<EdgeDTO> edges = new ArrayList<>();
|
|
249 |
|
|
250 |
when(loaderMock.getAttributeTypes()).thenReturn(attributeTypes);
|
|
251 |
when(loaderMock.getVertices()).thenReturn(vertices);
|
|
252 |
when(loaderMock.getEdges()).thenReturn(edges);
|
|
253 |
}
|
|
254 |
|
|
255 |
/**
|
|
256 |
* Initializes loader for returning uninitialized data.
|
|
257 |
*/
|
|
258 |
private void initNullValueLoader() {
|
|
259 |
when(loaderMock.getAttributeTypes()).thenReturn(null);
|
|
260 |
when(loaderMock.getVertices()).thenReturn(null);
|
|
261 |
when(loaderMock.getEdges()).thenReturn(null);
|
|
262 |
}
|
|
32 |
/** Name of attribute type */
|
|
33 |
private static final String ATTR_TYPE_NAME = "test";
|
|
34 |
|
|
35 |
/** Text of attribute type */
|
|
36 |
private static final String ATTR_TYPE_TEXT = "test attribute type";
|
|
37 |
|
|
38 |
/** List index / Attribute identifier */
|
|
39 |
private static final int ATTR_TYPE_ID = 0;
|
|
40 |
|
|
41 |
/** Vertex / Edge attribute value */
|
|
42 |
private static final String ATTR_VALUE = "test value";
|
|
43 |
|
|
44 |
/** Vertices names */
|
|
45 |
private static final String VERTEX_A = "A";
|
|
46 |
private static final String VERTEX_B = "B";
|
|
47 |
|
|
48 |
/** Lists indexes / Vertices identifiers */
|
|
49 |
private static final int VERTEX_A_ID = 0;
|
|
50 |
private static final int VERTEX_B_ID = 1;
|
|
51 |
|
|
52 |
/** Edge name */
|
|
53 |
private static final String EDGE_AB = "A-B";
|
|
54 |
|
|
55 |
/** Edge identifier */
|
|
56 |
private static final int EDGE_AB_ID = 0;
|
|
57 |
|
|
58 |
/** Archetypes names */
|
|
59 |
private static final String EDGE_ARCHETYPE = "Edge";
|
|
60 |
private static final String VERTEX_ARCHETYPE = "Vertex";
|
|
61 |
|
|
62 |
private static final boolean EMPTY_UNUSED_CLASS_ATTR = true;
|
|
63 |
|
|
64 |
/**
|
|
65 |
* Mock object of {@link BaseDOTLoader}.
|
|
66 |
*/
|
|
67 |
@Mock
|
|
68 |
private BaseDOTLoader<VertexDTO, EdgeDTO> loaderMock;
|
|
69 |
|
|
70 |
/**
|
|
71 |
* Expects that retrieves correct non-empty data from DOTLoader.
|
|
72 |
*/
|
|
73 |
@Test
|
|
74 |
public void loadDataFromCorrectLoader() {
|
|
75 |
final int expectedAttributeTypeSize = 1, expectedEdgesSize = 1, expectedVerticesSize = 2;
|
|
76 |
|
|
77 |
initCorrectLoader();
|
|
78 |
BaseGraphFactory<VertexDTO, EdgeDTO> factory = new GraphFactory(loaderMock);
|
|
79 |
|
|
80 |
// test method logic
|
|
81 |
verify(loaderMock).getAttributeTypes();
|
|
82 |
verify(loaderMock).getEdges();
|
|
83 |
verify(loaderMock).getVertices();
|
|
84 |
// test attributes initialization
|
|
85 |
assertThat(factory.attributeTypes.size(), is(expectedAttributeTypeSize));
|
|
86 |
assertThat(factory.edges.size(), is(expectedEdgesSize));
|
|
87 |
assertThat(factory.vertices.size(), is(expectedVerticesSize));
|
|
88 |
assertThat(factory.edgeArchetypes, is(not(nullValue())));
|
|
89 |
assertThat(factory.vertexArchetypes, is(not(nullValue())));
|
|
90 |
assertThat(factory.possibleEnumValues, is(not(nullValue())));
|
|
91 |
assertThat(factory.groups, is(not(nullValue())));
|
|
92 |
assertThat(factory.sideBar, is(not(nullValue())));
|
|
93 |
assertThat(factory.highlightedEdge, is(not(nullValue())));
|
|
94 |
assertThat(factory.highlightedVertex, is(not(nullValue())));
|
|
95 |
// test attribute type
|
|
96 |
assertThat(factory.attributeTypes.get(ATTR_TYPE_ID).getName(), is(equalTo(ATTR_TYPE_NAME)));
|
|
97 |
assertThat(factory.attributeTypes.get(ATTR_TYPE_ID).getText(), is(equalTo(ATTR_TYPE_TEXT)));
|
|
98 |
// test vertices
|
|
99 |
assertThat(factory.vertices.get(VERTEX_A_ID).getName(), is(equalTo(VERTEX_A)));
|
|
100 |
assertThat(factory.vertices.get(VERTEX_A_ID).getAttributes().get(ATTR_TYPE_NAME), is(equalTo(ATTR_VALUE)));
|
|
101 |
assertThat(factory.vertices.get(VERTEX_B_ID).getName(), is(equalTo(VERTEX_B)));
|
|
102 |
assertThat(factory.vertices.get(VERTEX_B_ID).getAttributes().get(ATTR_TYPE_NAME), is(equalTo(ATTR_VALUE)));
|
|
103 |
// test edges
|
|
104 |
assertThat(factory.edges.get(EDGE_AB_ID).getName(), is(equalTo(EDGE_AB)));
|
|
105 |
// test archetypes
|
|
106 |
assertThat(factory.edgeArchetypes.get(0).getName(), is(equalTo(EDGE_ARCHETYPE)));
|
|
107 |
assertThat(factory.vertexArchetypes.get(0).getName(), is(equalTo(VERTEX_ARCHETYPE)));
|
|
108 |
// the rest of required but unused attributes
|
|
109 |
assertThat(factory.possibleEnumValues.isEmpty(), is(equalTo(EMPTY_UNUSED_CLASS_ATTR)));
|
|
110 |
assertThat(factory.groups.isEmpty(), is(equalTo(EMPTY_UNUSED_CLASS_ATTR)));
|
|
111 |
assertThat(factory.sideBar.isEmpty(), is(equalTo(EMPTY_UNUSED_CLASS_ATTR)));
|
|
112 |
assertThat(factory.highlightedEdge.isEmpty(), is(equalTo(EMPTY_UNUSED_CLASS_ATTR)));
|
|
113 |
assertThat(factory.highlightedVertex.isEmpty(), is(equalTo(EMPTY_UNUSED_CLASS_ATTR)));
|
|
114 |
}
|
|
115 |
|
|
116 |
/**
|
|
117 |
* Expects that retrieves empty data from DOTLoader. In that case all factory attributes
|
|
118 |
* will empty except archetypes that will be created in factory.
|
|
119 |
*/
|
|
120 |
@Test
|
|
121 |
public void loadDataFromEmptyLoader() {
|
|
122 |
final int expectedAttributeTypeSize = 0, expectedEdgesSize = 0, expectedVerticesSize = 0;
|
|
123 |
|
|
124 |
initEmptyLoader();
|
|
125 |
BaseGraphFactory<VertexDTO, EdgeDTO> factory = new GraphFactory(loaderMock);
|
|
126 |
|
|
127 |
verify(loaderMock).getAttributeTypes();
|
|
128 |
verify(loaderMock).getEdges();
|
|
129 |
verify(loaderMock).getVertices();
|
|
130 |
|
|
131 |
assertThat(factory.attributeTypes.size(), is(expectedAttributeTypeSize));
|
|
132 |
assertThat(factory.edges.size(), is(expectedEdgesSize));
|
|
133 |
assertThat(factory.vertices.size(), is(expectedVerticesSize));
|
|
134 |
assertThat(factory.edgeArchetypes, is(not(nullValue())));
|
|
135 |
assertThat(factory.vertexArchetypes, is(not(nullValue())));
|
|
136 |
assertThat(factory.possibleEnumValues, is(not(nullValue())));
|
|
137 |
assertThat(factory.groups, is(not(nullValue())));
|
|
138 |
assertThat(factory.sideBar, is(not(nullValue())));
|
|
139 |
assertThat(factory.highlightedEdge, is(not(nullValue())));
|
|
140 |
assertThat(factory.highlightedVertex, is(not(nullValue())));
|
|
141 |
}
|
|
142 |
|
|
143 |
/**
|
|
144 |
* Expects that retrieves uninitialized data from DOTLoader. In that case all factory attributes
|
|
145 |
* will be initialized empty except archetypes that will be created in factory.
|
|
146 |
*/
|
|
147 |
@Test
|
|
148 |
public void loadDataFromIncorrectLoader() {
|
|
149 |
final int expectedAttributeTypeSize = 0, expectedEdgesSize = 0, expectedVerticesSize = 0;
|
|
150 |
|
|
151 |
initNullValueLoader();
|
|
152 |
BaseGraphFactory<VertexDTO, EdgeDTO> factory = new GraphFactory(loaderMock);
|
|
153 |
|
|
154 |
verify(loaderMock).getAttributeTypes();
|
|
155 |
verify(loaderMock).getEdges();
|
|
156 |
verify(loaderMock).getVertices();
|
|
157 |
|
|
158 |
assertThat(factory.attributeTypes.size(), is(expectedAttributeTypeSize));
|
|
159 |
assertThat(factory.edges.size(), is(expectedEdgesSize));
|
|
160 |
assertThat(factory.vertices.size(), is(expectedVerticesSize));
|
|
161 |
assertThat(factory.edgeArchetypes, is(not(nullValue())));
|
|
162 |
assertThat(factory.vertexArchetypes, is(not(nullValue())));
|
|
163 |
assertThat(factory.possibleEnumValues, is(not(nullValue())));
|
|
164 |
assertThat(factory.groups, is(not(nullValue())));
|
|
165 |
assertThat(factory.sideBar, is(not(nullValue())));
|
|
166 |
assertThat(factory.highlightedEdge, is(not(nullValue())));
|
|
167 |
assertThat(factory.highlightedVertex, is(not(nullValue())));
|
|
168 |
}
|
|
169 |
|
|
170 |
/**
|
|
171 |
* Tests correct creation of the graph instance. Especially vertex's and edge's attributes must be in
|
|
172 |
* correct form.
|
|
173 |
*/
|
|
174 |
@Test
|
|
175 |
public void createGraph() {
|
|
176 |
final int expectedAttributeTypeSize = 1, expectedEdgesSize = 1, expectedVerticesSize = 2;
|
|
177 |
|
|
178 |
// correct loader initialized
|
|
179 |
initCorrectLoader();
|
|
180 |
// loaded data from loader
|
|
181 |
BaseGraphFactory<VertexDTO, EdgeDTO> factory = new GraphFactory(loaderMock);
|
|
182 |
|
|
183 |
// final graph
|
|
184 |
Graph graph = factory.createGraph();
|
|
185 |
|
|
186 |
assertThat(graph, is(not(nullValue())));
|
|
187 |
assertThat(graph.getAttributeTypes().size(), is(expectedAttributeTypeSize));
|
|
188 |
assertThat(graph.getEdges().size(), is(expectedEdgesSize));
|
|
189 |
assertThat(graph.getVertices().size(), is(expectedVerticesSize));
|
|
190 |
assertThat(graph.getEdgeArchetypes(), is(not(nullValue())));
|
|
191 |
assertThat(graph.getVertexArchetypes(), is(not(nullValue())));
|
|
192 |
// test attribute type
|
|
193 |
assertThat(graph.getAttributeTypes().get(ATTR_TYPE_ID).getName(), is(equalTo(ATTR_TYPE_NAME)));
|
|
194 |
assertThat(graph.getAttributeTypes().get(ATTR_TYPE_ID).getText(), is(equalTo(ATTR_TYPE_TEXT)));
|
|
195 |
// test vertices
|
|
196 |
Iterator<Vertex> iterator = graph.getVertices().iterator();
|
|
197 |
Vertex a = iterator.next();
|
|
198 |
Vertex b = iterator.next();
|
|
199 |
assertThat(a.getName(), is(equalTo(VERTEX_A)));
|
|
200 |
assertThat(a.getAttributes().get(0)[0], is(equalTo(ATTR_TYPE_NAME)));
|
|
201 |
assertThat(a.getAttributes().get(0)[1], is(equalTo(ATTR_VALUE)));
|
|
202 |
assertThat(b.getName(), is(equalTo(VERTEX_B)));
|
|
203 |
assertThat(b.getAttributes().get(0)[0], is(equalTo(ATTR_TYPE_NAME)));
|
|
204 |
assertThat(b.getAttributes().get(0)[1], is(equalTo(ATTR_VALUE)));
|
|
205 |
// test edges
|
|
206 |
assertThat(graph.getEdges().get(EDGE_AB_ID).getText(), is(equalTo(EDGE_AB)));
|
|
207 |
assertThat(graph.getEdges().get(EDGE_AB_ID).getSubedgeInfo().get(0).getAttributes().get(0)[0], is(equalTo(ATTR_TYPE_NAME)));
|
|
208 |
assertThat(graph.getEdges().get(EDGE_AB_ID).getSubedgeInfo().get(0).getAttributes().get(0)[1], is(equalTo(ATTR_VALUE)));
|
|
209 |
// test archetypes
|
|
210 |
assertThat(graph.getEdgeArchetypes().get(0).getName(), is(equalTo(EDGE_ARCHETYPE)));
|
|
211 |
assertThat(graph.getVertexArchetypes().get(0).getName(), is(equalTo(VERTEX_ARCHETYPE)));
|
|
212 |
// the rest of required but unused attributes
|
|
213 |
assertThat(graph.getPossibleEnumValues().isEmpty(), is(equalTo(EMPTY_UNUSED_CLASS_ATTR)));
|
|
214 |
assertThat(graph.getGroups().isEmpty(), is(equalTo(EMPTY_UNUSED_CLASS_ATTR)));
|
|
215 |
assertThat(graph.getSideBar().isEmpty(), is(equalTo(EMPTY_UNUSED_CLASS_ATTR)));
|
|
216 |
assertThat(graph.getHighlightedEdge().isEmpty(), is(equalTo(EMPTY_UNUSED_CLASS_ATTR)));
|
|
217 |
assertThat(graph.getHighlightedVertex().isEmpty(), is(equalTo(EMPTY_UNUSED_CLASS_ATTR)));
|
|
218 |
}
|
|
219 |
|
|
220 |
/**
|
|
221 |
* Initializes loader with correct data.
|
|
222 |
*/
|
|
223 |
private void initCorrectLoader() {
|
|
224 |
HashMap<String, String> map = new HashMap<>();
|
|
225 |
map.put(ATTR_TYPE_NAME, ATTR_VALUE);
|
|
226 |
|
|
227 |
Set<AttributeType> attributeTypes = new HashSet<>();
|
|
228 |
attributeTypes.add(new AttributeType(ATTR_TYPE_NAME, AttributeDataType.STRING, ATTR_TYPE_TEXT));
|
|
229 |
|
|
230 |
List<VertexDTO> vertices = new ArrayList<>();
|
|
231 |
vertices.add(new VertexDTO(VERTEX_A, VERTEX_A_ID, map));
|
|
232 |
vertices.add(new VertexDTO(VERTEX_B, VERTEX_B_ID, map));
|
|
233 |
|
|
234 |
List<EdgeDTO> edges = new ArrayList<>();
|
|
235 |
edges.add(new EdgeDTO(EDGE_AB, VERTEX_A_ID, VERTEX_B_ID, EDGE_AB_ID, map));
|
|
236 |
|
|
237 |
when(loaderMock.getAttributeTypes()).thenReturn(attributeTypes);
|
|
238 |
when(loaderMock.getVertices()).thenReturn(vertices);
|
|
239 |
when(loaderMock.getEdges()).thenReturn(edges);
|
|
240 |
}
|
|
241 |
|
|
242 |
/**
|
|
243 |
* Initializes loader for returning empty data.
|
|
244 |
*/
|
|
245 |
private void initEmptyLoader() {
|
|
246 |
Set<AttributeType> attributeTypes = new HashSet<>();
|
|
247 |
List<VertexDTO> vertices = new ArrayList<>();
|
|
248 |
List<EdgeDTO> edges = new ArrayList<>();
|
|
249 |
|
|
250 |
when(loaderMock.getAttributeTypes()).thenReturn(attributeTypes);
|
|
251 |
when(loaderMock.getVertices()).thenReturn(vertices);
|
|
252 |
when(loaderMock.getEdges()).thenReturn(edges);
|
|
253 |
}
|
|
254 |
|
|
255 |
/**
|
|
256 |
* Initializes loader for returning uninitialized data.
|
|
257 |
*/
|
|
258 |
private void initNullValueLoader() {
|
|
259 |
when(loaderMock.getAttributeTypes()).thenReturn(null);
|
|
260 |
when(loaderMock.getVertices()).thenReturn(null);
|
|
261 |
when(loaderMock.getEdges()).thenReturn(null);
|
|
262 |
}
|
|
263 | 263 |
|
264 | 264 |
} |
Také k dispozici: Unified diff
Indentation correction