/
InlineHintModelQueryTest.java
261 lines (229 loc) · 10 KB
/
InlineHintModelQueryTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
package org.jboss.windup.reporting;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.forge.arquillian.AddonDependency;
import org.jboss.forge.arquillian.Dependencies;
import org.jboss.forge.arquillian.archive.ForgeArchive;
import org.jboss.forge.furnace.repositories.AddonDependencyEntry;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.windup.config.GraphRewrite;
import org.jboss.windup.graph.GraphContext;
import org.jboss.windup.graph.GraphContextFactory;
import org.jboss.windup.graph.model.WindupVertexFrame;
import org.jboss.windup.graph.model.resource.FileModel;
import org.jboss.windup.reporting.model.ClassificationModel;
import org.jboss.windup.reporting.model.InlineHintModel;
import org.jboss.windup.reporting.model.TechnologyTagLevel;
import org.jboss.windup.reporting.query.FindSourceReportFilesGremlinCriterion;
import org.jboss.windup.reporting.query.FindFilesNotClassifiedOrHintedGremlinCriterion;
import org.jboss.windup.reporting.service.TechnologyTagService;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.gremlin.java.GremlinPipeline;
@RunWith(Arquillian.class)
public class InlineHintModelQueryTest
{
@Deployment
@Dependencies({
@AddonDependency(name = "org.jboss.windup.config:windup-config"),
@AddonDependency(name = "org.jboss.windup.graph:windup-graph"),
@AddonDependency(name = "org.jboss.windup.reporting:windup-reporting"),
@AddonDependency(name = "org.jboss.forge.furnace.container:cdi")
})
public static ForgeArchive getDeployment()
{
ForgeArchive archive = ShrinkWrap.create(ForgeArchive.class)
.addBeansXML()
.addAsResource(new File("src/test/resources/reports"))
.addAsAddonDependencies(
AddonDependencyEntry.create("org.jboss.windup.config:windup-config"),
AddonDependencyEntry.create("org.jboss.windup.graph:windup-graph"),
AddonDependencyEntry.create("org.jboss.windup.reporting:windup-reporting"),
AddonDependencyEntry.create("org.jboss.forge.furnace.container:cdi")
);
return archive;
}
@Inject
private GraphContextFactory factory;
private GraphContext context;
@Before
public void beforeTest() throws Exception
{
context = factory.create();
}
@After
public void afterTest() throws Exception
{
context.close();
context.clear();
}
@Test
public void testFindingClassifiedFiles() throws Exception
{
FileModel f1 = context.getFramed().addVertex(null, FileModel.class);
f1.setFilePath("/f1");
FileModel f2 = context.getFramed().addVertex(null, FileModel.class);
f2.setFilePath("/f2");
FileModel f3 = context.getFramed().addVertex(null, FileModel.class);
f3.setFilePath("/f3");
FileModel f4 = context.getFramed().addVertex(null, FileModel.class);
f4.setFilePath("/f4");
FileModel f5 = context.getFramed().addVertex(null, FileModel.class);
f5.setFilePath("/f5");
FileModel f6 = context.getFramed().addVertex(null, FileModel.class);
f6.setFilePath("/f6");
FileModel f7 = context.getFramed().addVertex(null, FileModel.class);
f7.setFilePath("/f7");
InlineHintModel b1 = context.getFramed().addVertex(null, InlineHintModel.class);
InlineHintModel b1b = context.getFramed().addVertex(null, InlineHintModel.class);
b1.setFile(f1);
b1b.setFile(f1);
InlineHintModel b2 = context.getFramed().addVertex(null, InlineHintModel.class);
b2.setFile(f2);
ClassificationModel c1 = context.getFramed().addVertex(null, ClassificationModel.class);
ClassificationModel c1b = context.getFramed().addVertex(null, ClassificationModel.class);
c1.addFileModel(f1);
c1b.addFileModel(f1);
ClassificationModel c2 = context.getFramed().addVertex(null, ClassificationModel.class);
c2.addFileModel(f3);
TechnologyTagService techTagService = new TechnologyTagService(context);
techTagService.addTagToFileModel(f4, "TestTag", TechnologyTagLevel.IMPORTANT);
List<Vertex> vertexList = new ArrayList<>();
for (Vertex v : context.getQuery().type(FileModel.class).vertices())
{
vertexList.add(v);
}
GremlinPipeline<Vertex, Vertex> pipeline = new GremlinPipeline<>(context.getQuery().type(FileModel.class)
.vertices());
GraphRewrite event = new GraphRewrite(context);
// manually execute this criterion (this just adds things to the pipeline)
new FindSourceReportFilesGremlinCriterion().query(event, pipeline);
List<FileModel> fileModels = new ArrayList<>();
for (Vertex v : pipeline)
{
// Explicit cast here insures that the frame returned was actually a FileModel. If it is not, a
// ClassCastException will
// occur and the test will fail.
//
// If we called frame(v, FileModel.class) directly, frames would happily force it to be a FileModel
// even if the underlying query were returning invalid results.
FileModel fm = (FileModel) context.getFramed().frame(v, WindupVertexFrame.class);
fileModels.add(fm);
}
boolean foundF1 = false;
boolean foundF2 = false;
boolean foundF3 = false;
boolean foundF4 = false;
Assert.assertEquals(4, fileModels.size());
for (FileModel fm : fileModels)
{
if (fm.getFilePath().equals(f1.getFilePath()))
{
foundF1 = true;
}
else if (fm.getFilePath().equals(f2.getFilePath()))
{
foundF2 = true;
}
else if (fm.getFilePath().equals(f3.getFilePath()))
{
foundF3 = true;
}
else if (fm.getFilePath().equals(f4.getFilePath()))
{
foundF4 = true;
}
}
Assert.assertTrue(foundF1);
Assert.assertTrue(foundF2);
Assert.assertTrue(foundF3);
Assert.assertTrue(foundF4);
}
@Test
public void testFindingNonClassifiedFiles() throws Exception
{
FileModel f1 = context.getFramed().addVertex(null, FileModel.class);
f1.setFilePath("/f1");
FileModel f2 = context.getFramed().addVertex(null, FileModel.class);
f2.setFilePath("/f2");
FileModel f3 = context.getFramed().addVertex(null, FileModel.class);
f3.setFilePath("/f3");
FileModel f4 = context.getFramed().addVertex(null, FileModel.class);
f4.setFilePath("/f4");
FileModel f5 = context.getFramed().addVertex(null, FileModel.class);
f5.setFilePath("/f5");
FileModel f6 = context.getFramed().addVertex(null, FileModel.class);
f6.setFilePath("/f6");
FileModel f7 = context.getFramed().addVertex(null, FileModel.class);
f7.setFilePath("/f7");
InlineHintModel b1 = context.getFramed().addVertex(null, InlineHintModel.class);
InlineHintModel b1b = context.getFramed().addVertex(null, InlineHintModel.class);
b1.setFile(f1);
b1b.setFile(f1);
InlineHintModel b2 = context.getFramed().addVertex(null, InlineHintModel.class);
b2.setFile(f2);
ClassificationModel c1 = context.getFramed().addVertex(null, ClassificationModel.class);
ClassificationModel c1b = context.getFramed().addVertex(null, ClassificationModel.class);
c1.addFileModel(f1);
c1b.addFileModel(f1);
ClassificationModel c2 = context.getFramed().addVertex(null, ClassificationModel.class);
c2.addFileModel(f3);
List<Vertex> vertexList = new ArrayList<>();
for (Vertex v : context.getQuery().type(FileModel.class).vertices())
{
vertexList.add(v);
}
// manually execute this criterion (this just adds things to the pipeline)
Iterable<Vertex> allFMVertices = context.getQuery().type(FileModel.class).vertices();
Iterable<Vertex> fileModelIterable = new FindFilesNotClassifiedOrHintedGremlinCriterion()
.query(context, allFMVertices);
List<FileModel> fileModels = new ArrayList<>();
for (Vertex v : fileModelIterable)
{
// Explicit cast here insures that the frame returned was actually a FileModel. If it is not, a
// ClassCastException will
// occur and the test will fail.
//
// If we called frame(v, FileModel.class) directly, frames would happily force it to be a FileModel
// even if the underlying query were returning invalid results.
FileModel fm = (FileModel) context.getFramed().frame(v, WindupVertexFrame.class);
fileModels.add(fm);
}
boolean foundF4 = false;
boolean foundF5 = false;
boolean foundF6 = false;
boolean foundF7 = false;
Assert.assertEquals(4, fileModels.size());
for (FileModel fm : fileModels)
{
if (fm.getFilePath().equals(f4.getFilePath()))
{
foundF4 = true;
}
else if (fm.getFilePath().equals(f5.getFilePath()))
{
foundF5 = true;
}
else if (fm.getFilePath().equals(f6.getFilePath()))
{
foundF6 = true;
}
else if (fm.getFilePath().equals(f7.getFilePath()))
{
foundF7 = true;
}
}
Assert.assertTrue(foundF4);
Assert.assertTrue(foundF5);
Assert.assertTrue(foundF6);
Assert.assertTrue(foundF7);
}
}