Skip to content

Commit 4dc2b34

Browse files
committed
Rewrite the test to simulate the D2D steps. #1854
Signed-off-by: Chin Yeung Li <[email protected]>
1 parent e1c8b5c commit 4dc2b34

File tree

3 files changed

+30
-41
lines changed

3 files changed

+30
-41
lines changed
187 Bytes
Binary file not shown.
552 Bytes
Binary file not shown.

scanpipe/tests/pipes/test_d2d.py

Lines changed: 30 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -394,57 +394,46 @@ def test_scanpipe_pipes_d2d_map_java_to_class(self):
394394
self.assertEqual("", to3.status)
395395

396396
def test_scanpipe_pipes_d2d_map_java_to_class_with_java_in_deploy(self):
397-
sha1 = "abcde"
398-
from1 = make_resource_file(
399-
self.project1,
400-
path="from/flume-ng-node-1.9.0-sources.jar-extract/org/apache/flume/node/"
401-
"AbstractConfigurationProvider.java",
402-
sha1=sha1,
403-
)
404-
to1 = make_resource_file(
405-
self.project1,
406-
path="to/flume-ng-node-1.9.0.jar-extract/org/apache/flume/node/"
407-
"AbstractConfigurationProvider.java",
408-
sha1=sha1,
409-
)
410-
to2 = make_resource_file(
411-
self.project1,
412-
path="to/flume-ng-node-1.9.0.jar-extract/org/apache/flume/node/"
413-
"AbstractConfigurationProvider.class",
414-
)
397+
input_dir = self.project1.input_path
398+
# "from-Baz.zip" contains Baz.java
399+
# "to-Baz.jar" contains Baz.java and Baz.class
400+
input_resources = [
401+
self.data / "d2d" / "find_java_packages" / "from-Baz.zip",
402+
self.data / "d2d" / "find_java_packages" / "to-Baz.jar",
403+
]
415404

405+
copy_inputs(input_resources, input_dir)
406+
self.from_files, self.to_files = d2d.get_inputs(self.project1)
407+
inputs_with_codebase_path_destination = [
408+
(self.from_files, self.project1.codebase_path / d2d.FROM),
409+
(self.to_files, self.project1.codebase_path / d2d.TO),
410+
]
411+
for input_files, codebase_path in inputs_with_codebase_path_destination:
412+
for input_file_path in input_files:
413+
scancode.extract_archive(input_file_path, codebase_path)
414+
415+
scancode.extract_archives(
416+
self.project1.codebase_path,
417+
recurse=True,
418+
)
419+
pipes.collect_and_create_codebase_resources(self.project1)
416420
buffer = io.StringIO()
417421

418-
# The pipeline will run map_checksum first
419-
d2d.map_checksum(self.project1, "sha1", logger=buffer.write)
420-
expected = "Mapping 1 to/ resources using sha1 against from/ codebase"
421-
self.assertEqual(expected, buffer.getvalue())
422-
self.assertEqual(1, to1.related_from.count())
423-
relation1 = to1.related_from.get()
424-
self.assertEqual("sha1", relation1.map_type)
425-
self.assertEqual(from1, relation1.from_resource)
426-
427-
# The "java_package" field in extra_data is required for mapping
428-
# Java packages to classes.
429-
# Simulate the "find_jvm_packages" call by updating extra_data in
430-
# the from1 resource
431-
# Note that "find_java_packages" is called before
432-
# "map_java_to_class"
433-
from1.update_extra_data({"java_package": "org.apache.flume.node"})
422+
d2d.map_checksum(
423+
project=self.project1, checksum_field="sha1", logger=buffer.write
424+
)
434425

426+
d2d.find_jvm_packages(
427+
self.project1, jvm_lang=jvm.JavaLanguage, logger=buffer.write
428+
)
429+
expected = "Finding java packages for 1 ('.java',) resources."
430+
self.assertIn(expected, buffer.getvalue())
435431
# Now run map_java_to_class
436432
d2d.map_jvm_to_class(
437433
self.project1, logger=buffer.write, jvm_lang=jvm.JavaLanguage
438434
)
439435
expected = "Mapping 1 .class resources to 1 ('.java',)"
440436
self.assertIn(expected, buffer.getvalue())
441-
self.assertEqual(2, self.project1.codebaserelations.count())
442-
relation2 = self.project1.codebaserelations.get(
443-
to_resource=to2, from_resource=from1
444-
)
445-
self.assertEqual("java_to_class", relation2.map_type)
446-
expected = {"from_source_root": "from/flume-ng-node-1.9.0-sources.jar-extract/"}
447-
self.assertEqual(expected, relation2.extra_data)
448437

449438
def test_scanpipe_pipes_d2d_map_java_to_class_no_java(self):
450439
make_resource_file(self.project1, path="to/Abstract.class")

0 commit comments

Comments
 (0)