Пример #1
0
    def append(self, root_path):
        """Appends artifacts from the specified path to the underlying model."""

        log.info('Scanning path: %s', root_path)

        classes = 0
        with JavaScanner(self._process_class) as scanner:
            classes = scanner.scan(root_path)

        log.info('Scan finished. Found %d class files.', classes)
Пример #2
0
 def test_with_contract(self):
     with JavaScanner(callback=mock.MagicMock()) as s:
         self.assertTrue(s)
         self.assertTrue(os.path.isdir(s._work_dir))
     self.assertFalse(os.path.isdir(s._work_dir))
Пример #3
0
 def setUp(self):
     self.scanner = JavaScanner(callback=mock.MagicMock())
     self.assertTrue(os.path.isdir(self.scanner._work_dir))
Пример #4
0
class TestJavaScanner(unittest.TestCase):
    def setUp(self):
        self.scanner = JavaScanner(callback=mock.MagicMock())
        self.assertTrue(os.path.isdir(self.scanner._work_dir))

    def tearDown(self):
        self.scanner.dispose()
        self.assertFalse(os.path.isdir(self.scanner._work_dir))

    def test_supported_files(self):
        scanner = self.scanner

        def supported(name):
            with tempfile.NamedTemporaryFile(suffix=name) as f:
                return scanner.supported_file(f.name)

        self.assertTrue(supported('Test.class'))
        self.assertTrue(supported('test-1.0.jar'))
        self.assertTrue(supported('test-1.0.war'))
        self.assertTrue(supported('test-1.0.ear'))

        self.assertFalse(supported('build.properties'))
        self.assertFalse(supported('pom.xml'))
        self.assertFalse(supported('build.gradle'))
        self.assertFalse(supported('README'))
        self.assertFalse(supported('Test.java'))

    def test_scan_file(self):
        scanner = self.scanner

        with tempfile.NamedTemporaryFile(suffix='.xml') as not_supported_file:
            scanner.callback.reset_mock()
            self.assertEquals(scanner.scan(not_supported_file.name), 0)
            self.assertEquals(scanner.callback.call_count, 0)

        with tempfile.NamedTemporaryFile(suffix='.class') as class_file:
            self.assertEquals(scanner.scan(class_file.name), 1)
            self.assertEquals(scanner.callback.call_count, 1)
            scanner.callback.assert_any_call(class_file.name)

        with SampleJar() as exploded_jar:
            jar = exploded_jar.compress()
            scanner.callback.reset_mock()
            self.assertEquals(scanner.scan(jar), 2)
            self.assertEquals(scanner.callback.call_count, 2)

        with SampleWar() as exploded_war:
            war = exploded_war.compress()
            scanner.callback.reset_mock()
            self.assertEquals(scanner.scan(war), 6)
            self.assertEquals(scanner.callback.call_count, 6)

        with SampleEar() as exploded_ear:
            ear = exploded_ear.compress()
            scanner.callback.reset_mock()
            self.assertEquals(scanner.scan(ear), 7)
            self.assertEquals(scanner.callback.call_count, 7)

    def test_scan_directory(self):
        scanner = self.scanner

        with SampleJar() as exploded_jar:
            scanner.callback.reset_mock()
            self.assertEquals(scanner.scan(exploded_jar.root_path), 2)
            self.assertEquals(scanner.callback.call_count, 2)

        with SampleWar() as exploded_war:
            scanner.callback.reset_mock()
            self.assertEquals(scanner.scan(exploded_war.root_path), 6)
            self.assertEquals(scanner.callback.call_count, 6)

        with SampleEar() as exploded_ear:
            scanner.callback.reset_mock()
            self.assertEquals(scanner.scan(exploded_ear.root_path), 7)
            self.assertEquals(scanner.callback.call_count, 7)

    def test_with_contract(self):
        with JavaScanner(callback=mock.MagicMock()) as s:
            self.assertTrue(s)
            self.assertTrue(os.path.isdir(s._work_dir))
        self.assertFalse(os.path.isdir(s._work_dir))
Пример #5
0
 def setUp(self):
     self.scanner = JavaScanner(callback=mock.MagicMock())
     self.assertTrue(os.path.isdir(self.scanner._work_dir))
Пример #6
0
class TestJavaScanner(unittest.TestCase):

    def setUp(self):
        self.scanner = JavaScanner(callback=mock.MagicMock())
        self.assertTrue(os.path.isdir(self.scanner._work_dir))

    def tearDown(self):
        self.scanner.dispose()
        self.assertFalse(os.path.isdir(self.scanner._work_dir))

    def test_supported_files(self):
        scanner = self.scanner
        def supported(name):
            with tempfile.NamedTemporaryFile(suffix=name) as f:       
                return scanner.supported_file(f.name)

        self.assertTrue(supported('Test.class'))
        self.assertTrue(supported('test-1.0.jar'))
        self.assertTrue(supported('test-1.0.war'))
        self.assertTrue(supported('test-1.0.ear'))
       
        self.assertFalse(supported('build.properties')) 
        self.assertFalse(supported('pom.xml')) 
        self.assertFalse(supported('build.gradle')) 
        self.assertFalse(supported('README')) 
        self.assertFalse(supported('Test.java')) 
      
    def test_scan_file(self):
        scanner = self.scanner
         
        with tempfile.NamedTemporaryFile(suffix = '.xml') as not_supported_file:
            scanner.callback.reset_mock()
            self.assertEquals(scanner.scan(not_supported_file.name), 0) 
            self.assertEquals(scanner.callback.call_count, 0)
         
        with tempfile.NamedTemporaryFile(suffix = '.class') as class_file:
            self.assertEquals(scanner.scan(class_file.name), 1) 
            self.assertEquals(scanner.callback.call_count, 1)
            scanner.callback.assert_any_call(class_file.name)

        with SampleJar() as exploded_jar:
            jar = exploded_jar.compress()
            scanner.callback.reset_mock()
            self.assertEquals(scanner.scan(jar), 2)
            self.assertEquals(scanner.callback.call_count, 2)
        
        with SampleWar() as exploded_war:
            war = exploded_war.compress()
            scanner.callback.reset_mock()
            self.assertEquals(scanner.scan(war), 6)
            self.assertEquals(scanner.callback.call_count, 6)
        
        with SampleEar() as exploded_ear:
            ear = exploded_ear.compress()
            scanner.callback.reset_mock()
            self.assertEquals(scanner.scan(ear), 7)
            self.assertEquals(scanner.callback.call_count, 7)
    
    def test_scan_directory(self):
        scanner = self.scanner

        with SampleJar() as exploded_jar:
            scanner.callback.reset_mock()
            self.assertEquals(scanner.scan(exploded_jar.root_path), 2)
            self.assertEquals(scanner.callback.call_count, 2)
        
        with SampleWar() as exploded_war:
            scanner.callback.reset_mock()
            self.assertEquals(scanner.scan(exploded_war.root_path), 6)
            self.assertEquals(scanner.callback.call_count, 6)

        with SampleEar() as exploded_ear:
            scanner.callback.reset_mock()
            self.assertEquals(scanner.scan(exploded_ear.root_path), 7)
            self.assertEquals(scanner.callback.call_count, 7)
    
    def test_with_contract(self):
        with JavaScanner(callback=mock.MagicMock()) as s:
            self.assertTrue(s)
            self.assertTrue(os.path.isdir(s._work_dir))
        self.assertFalse(os.path.isdir(s._work_dir))