34
34
import org .junit .Before ;
35
35
import org .junit .Test ;
36
36
37
+ import java .io .File ;
37
38
import java .nio .file .Files ;
38
39
import java .nio .file .Path ;
39
40
import java .nio .file .Paths ;
@@ -66,13 +67,7 @@ public void setUp() {
66
67
public void informTest () throws Exception {
67
68
Project project = qm .createProject ("Acme Example" , null , "1.0" , null , null , null , true , false );
68
69
69
- // The task will delete the input file after processing it,
70
- // so create a temporary copy to not impact other tests.
71
- final Path bomFilePath = Files .createTempFile (null , null );
72
- Files .copy (Paths .get (resourceToURL ("/bom-1.xml" ).toURI ()), bomFilePath , StandardCopyOption .REPLACE_EXISTING );
73
- final var bomFile = bomFilePath .toFile ();
74
-
75
- final var bomUploadEvent = new BomUploadEvent (qm .detach (Project .class , project .getId ()), bomFile );
70
+ final var bomUploadEvent = new BomUploadEvent (qm .detach (Project .class , project .getId ()), createTempBomFile ("bom-1.xml" ));
76
71
new BomUploadProcessingTask ().inform (bomUploadEvent );
77
72
assertConditionWithTimeout (() -> kafkaMockProducer .history ().size () >= 5 , Duration .ofSeconds (5 ));
78
73
assertThat (kafkaMockProducer .history ()).satisfiesExactly (
@@ -111,13 +106,7 @@ public void informTest() throws Exception {
111
106
public void informWithEmptyBomTest () throws Exception {
112
107
Project project = qm .createProject ("Acme Example" , null , "1.0" , null , null , null , true , false );
113
108
114
- // The task will delete the input file after processing it,
115
- // so create a temporary copy to not impact other tests.
116
- final Path bomFilePath = Files .createTempFile (null , null );
117
- Files .copy (Paths .get (resourceToURL ("/unit/bom-empty.json" ).toURI ()), bomFilePath , StandardCopyOption .REPLACE_EXISTING );
118
- final var bomFile = bomFilePath .toFile ();
119
-
120
- final var bomUploadEvent = new BomUploadEvent (qm .detach (Project .class , project .getId ()), bomFile );
109
+ final var bomUploadEvent = new BomUploadEvent (qm .detach (Project .class , project .getId ()), createTempBomFile ("bom-empty.json" ));
121
110
new BomUploadProcessingTask ().inform (bomUploadEvent );
122
111
assertConditionWithTimeout (() -> kafkaMockProducer .history ().size () >= 3 , Duration .ofSeconds (5 ));
123
112
assertThat (kafkaMockProducer .history ()).satisfiesExactly (
@@ -141,13 +130,7 @@ public void informWithEmptyBomTest() throws Exception {
141
130
public void informWithInvalidBomTest () throws Exception {
142
131
Project project = qm .createProject ("Acme Example" , null , "1.0" , null , null , null , true , false );
143
132
144
- // The task will delete the input file after processing it,
145
- // so create a temporary copy to not impact other tests.
146
- final Path bomFilePath = Files .createTempFile (null , null );
147
- Files .copy (Paths .get (resourceToURL ("/unit/bom-invalid.json" ).toURI ()), bomFilePath , StandardCopyOption .REPLACE_EXISTING );
148
- final var bomFile = bomFilePath .toFile ();
149
-
150
- new BomUploadProcessingTask ().inform (new BomUploadEvent (qm .detach (Project .class , project .getId ()), bomFile ));
133
+ new BomUploadProcessingTask ().inform (new BomUploadEvent (qm .detach (Project .class , project .getId ()), createTempBomFile ("bom-invalid.json" )));
151
134
assertConditionWithTimeout (() -> kafkaMockProducer .history ().size () >= 2 , Duration .ofSeconds (5 ));
152
135
assertThat (kafkaMockProducer .history ()).satisfiesExactly (
153
136
event -> assertThat (event .topic ()).isEqualTo (KafkaTopics .NOTIFICATION_PROJECT_CREATED .name ()),
@@ -184,13 +167,7 @@ public void informWithInvalidBomTest() throws Exception {
184
167
public void informWithBloatedBomTest () throws Exception {
185
168
final var project = qm .createProject ("Acme Example" , null , "1.0" , null , null , null , true , false );
186
169
187
- // The task will delete the input file after processing it,
188
- // so create a temporary copy to not impact other tests.
189
- final Path bomFilePath = Files .createTempFile (null , null );
190
- Files .copy (Paths .get (resourceToURL ("/unit/bloated.bom.json" ).toURI ()), bomFilePath , StandardCopyOption .REPLACE_EXISTING );
191
- final var bomFile = bomFilePath .toFile ();
192
-
193
- final var bomUploadEvent = new BomUploadEvent (qm .detach (Project .class , project .getId ()), bomFile );
170
+ final var bomUploadEvent = new BomUploadEvent (qm .detach (Project .class , project .getId ()), createTempBomFile ("bom-bloated.json" ));
194
171
new BomUploadProcessingTask ().inform (bomUploadEvent );
195
172
196
173
assertThat (kafkaMockProducer .history ())
@@ -276,4 +253,47 @@ public void informWithBloatedBomTest() throws Exception {
276
253
assertThat (repoMetaAnalysisCommandsSent ).isEqualTo (9056 );
277
254
}
278
255
256
+ @ Test // https://github.com/DependencyTrack/dependency-track/issues/2519
257
+ public void informIssue2519Test () throws Exception {
258
+ final var project = qm .createProject ("Acme Example" , null , "1.0" , null , null , null , true , false );
259
+
260
+ var bomUploadEvent = new BomUploadEvent (qm .detach (Project .class , project .getId ()), createTempBomFile ("bom-issue2519.xml" ));
261
+ new BomUploadProcessingTask ().inform (bomUploadEvent );
262
+
263
+ // Make sure processing did not fail.
264
+ assertThat (kafkaMockProducer .history ())
265
+ .noneSatisfy (record -> {
266
+ assertThat (record .topic ()).isEqualTo (KafkaTopics .NOTIFICATION_BOM .name ());
267
+ final Notification notification = deserializeValue (KafkaTopics .NOTIFICATION_BOM , record );
268
+ assertThat (notification .getGroup ()).isEqualTo (GROUP_BOM_PROCESSING_FAILED );
269
+ });
270
+
271
+ // Ensure the expected amount of components is present.
272
+ assertThat (qm .getAllComponents (project )).hasSize (1756 );
273
+
274
+ // Upload the same BOM again a few times.
275
+ // Ensure processing does not fail, and the number of components ingested doesn't change.
276
+ for (int i = 0 ; i < 3 ; i ++) {
277
+ bomUploadEvent = new BomUploadEvent (qm .detach (Project .class , project .getId ()), createTempBomFile ("bom-issue2519.xml" ));
278
+ new BomUploadProcessingTask ().inform (bomUploadEvent );
279
+
280
+ assertThat (kafkaMockProducer .history ())
281
+ .noneSatisfy (record -> {
282
+ assertThat (record .topic ()).isEqualTo (KafkaTopics .NOTIFICATION_BOM .name ());
283
+ final Notification notification = deserializeValue (KafkaTopics .NOTIFICATION_BOM , record );
284
+ assertThat (notification .getGroup ()).isEqualTo (GROUP_BOM_PROCESSING_FAILED );
285
+ });
286
+
287
+ assertThat (qm .getAllComponents (project )).hasSize (1756 );
288
+ }
289
+ }
290
+
291
+ private static File createTempBomFile (final String testFileName ) throws Exception {
292
+ // The task will delete the input file after processing it,
293
+ // so create a temporary copy to not impact other tests.
294
+ final Path bomFilePath = Files .createTempFile (null , null );
295
+ Files .copy (Paths .get (resourceToURL ("/unit/" + testFileName ).toURI ()), bomFilePath , StandardCopyOption .REPLACE_EXISTING );
296
+ return bomFilePath .toFile ();
297
+ }
298
+
279
299
}
0 commit comments