/** @group Functional */ public function testRunMonkScan() { $this->setUpTables(); $this->setUpRepo(); list($output, $retCode) = $this->runMonk($uploadId = 1); $this->rmRepo(); $this->assertEquals($retCode, 0, 'monk failed: ' . $output); $this->assertEquals(6, $this->getHeartCount($output)); $bounds = $this->uploadDao->getParentItemBounds($uploadId); $matches = $this->licenseDao->getAgentFileLicenseMatches($bounds); $this->assertEquals($expected = 2, count($matches)); /** @var LicenseMatch */ $licenseMatch = $matches[0]; $this->assertEquals($expected = 4, $licenseMatch->getFileId()); /** @var LicenseRef */ $matchedLicense = $licenseMatch->getLicenseRef(); $this->assertEquals($matchedLicense->getShortName(), "GPL-3.0"); /** @var AgentRef */ $agentRef = $licenseMatch->getAgentRef(); $this->assertEquals($agentRef->getAgentName(), "monk"); $highlights = $this->highlightDao->getHighlightDiffs($this->uploadDao->getItemTreeBounds(7)); $expectedHighlight = new Highlight(18, 35825, Highlight::MATCH, 20, 35819); $expectedHighlight->setLicenseId($matchedLicense->getId()); $this->assertEquals(array($expectedHighlight), $highlights); $highlights = $this->highlightDao->getHighlightDiffs($this->uploadDao->getItemTreeBounds(11)); $expectedHighlights = array(); $expectedHighlights[] = new Highlight(18, 339, Highlight::MATCH, 20, 350); $expectedHighlights[] = new Highlight(340, 347, Highlight::CHANGED, 351, 357); $expectedHighlights[] = new Highlight(348, 35149, Highlight::MATCH, 358, 35819); foreach ($expectedHighlights as $expectedHighlight) { $expectedHighlight->setLicenseId($matchedLicense->getId()); } assertThat($highlights, containsInAnyOrder($expectedHighlights)); }
/** @group Functional */ public function testRunMonkBulkScanWithAnEmptySearchText() { $this->setUpTables(); $this->setUpRepo(); $userId = 2; $groupId = 2; $uploadTreeId = 1; $licenseId = 225; $removing = false; $refText = ""; $bulkId = $this->licenseDao->insertBulkLicense($userId, $groupId, $uploadTreeId, array($licenseId => $removing), $refText); $this->assertGreaterThan($expected = 0, $bulkId); $jobId = 64; list($output, $retCode) = $this->runBulkMonk($userId, $groupId, $jobId, $bulkId); $this->rmRepo(); $this->assertEquals($retCode, 0, 'monk bulk failed: ' . $output); $bounds6 = new ItemTreeBounds(6, 'uploadtree_a', 1, 17, 18); $bounds7 = new ItemTreeBounds(7, 'uploadtree_a', 1, 15, 16); $relevantDecisionsItem6 = $this->clearingDao->getRelevantClearingEvents($bounds6, $groupId); $relevantDecisionsItem7 = $this->clearingDao->getRelevantClearingEvents($bounds7, $groupId); assertThat(count($relevantDecisionsItem6), is(equalTo(0))); assertThat(count($relevantDecisionsItem7), is(equalTo(0))); $bulkHighlights = $this->highlightDao->getHighlightBulk(6); assertThat(count($bulkHighlights), is(equalTo(0))); }
/** * @param LicenseMatch[] * @return boolean */ private function areNomosMatchesInsideAMonkMatch($licenseMatches) { if (!array_key_exists("nomos", $licenseMatches)) { return false; } if (!array_key_exists("monk", $licenseMatches)) { return false; } foreach ($licenseMatches["nomos"] as $licenseMatch) { $matchId = $licenseMatch->getLicenseFileId(); $nomosRegion = $this->highlightDao->getHighlightRegion($matchId); $found = false; foreach ($licenseMatches["monk"] as $monkLicenseMatch) { $monkRegion = $this->highlightDao->getHighlightRegion($monkLicenseMatch->getLicenseFileId()); if ($this->isRegionIncluded($nomosRegion, $monkRegion)) { $found = true; break; } } if (!$found) { return false; } } return true; }
protected function setUp() { global $container; $this->highlightDao = M::mock(HighlightDao::classname()); $container->shouldReceive('get')->withArgs(array('dao.highlight'))->andReturn($this->highlightDao); $container->shouldReceive('get')->withArgs(array('dao.upload'))->andReturn(M::mock(UploadDao::classname())); $container->shouldReceive('get')->withArgs(array('dao.clearing'))->andReturn(M::mock(ClearingDao::classname())); $container->shouldReceive('get')->withArgs(array('decision.types'))->andReturn(M::mock(DecisionTypes::classname())); $container->shouldReceive('get')->withArgs(array('businessrules.clearing_decision_processor'))->andReturn(M::mock(ClearingDecisionProcessor::classname())); $container->shouldReceive('get')->withArgs(array('businessrules.agent_license_event_processor'))->andReturn(M::mock(AgentLicenseEventProcessor::classname())); $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount(); }
/** * @param ItemTreeBounds $itemTreeBounds * @param $licenseId * @param $selectedAgentId * @param $highlightId * @param int $clearingId * @param int $uploadId * @return Highlight[] */ private function getSelectedHighlighting(ItemTreeBounds $itemTreeBounds, $licenseId, $selectedAgentId, $highlightId, $clearingId, $uploadId) { $unmaskAgents = $selectedAgentId; if (empty($selectedAgentId)) { $scanJobProxy = new ScanJobProxy($this->agentsDao, $uploadId); $scanJobProxy->createAgentStatus(array('nomos', 'monk', 'ninka')); $unmaskAgents = $scanJobProxy->getLatestSuccessfulAgentIds(); } $highlightEntries = $this->highlightDao->getHighlightEntries($itemTreeBounds, $licenseId, $unmaskAgents, $highlightId, $clearingId); $groupId = Auth::getGroupId(); if ($selectedAgentId > 0 || $clearingId > 0) { $this->highlightProcessor->addReferenceTexts($highlightEntries, $groupId); } else { $this->highlightProcessor->flattenHighlights($highlightEntries, array("K", "K ")); } return $highlightEntries; }
public function testDeciderScanWithTwoEventAndNoAgentShouldMakeADecision() { $this->setUpTables(); $this->setUpRepo(); $dbManager = M::mock(DbManager::classname()); $agentDao = M::mock(AgentDao::classname()); $clearingDao = M::mock(ClearingDao::classname()); $uploadDao = M::mock(UploadDao::classname()); $highlightDao = M::mock(HighlightDao::classname()); $decisionProcessor = M::mock(ClearingDecisionProcessor::classname()); $agentLicenseEventProcessor = M::mock(AgentLicenseEventProcessor::classname()); $uploadId = 13243; /*mock for Agent class **/ $agentDao->shouldReceive('arsTableExists')->andReturn(true); $agentDao->shouldReceive('getCurrentAgentId')->andReturn($agentId = 24); $agentDao->shouldReceive('writeArsRecord')->with(anything(), $agentId, $uploadId)->andReturn($arsId = 2); $agentDao->shouldReceive('writeArsRecord')->with(anything(), $agentId, $uploadId, $arsId, true)->andReturn(0); $jobId = 42; $groupId = 6; $userId = 2; $itemIds = array(4343, 43); $bounds0 = M::mock(ItemTreeBounds::classname()); $bounds0->shouldReceive('getItemId')->andReturn($itemIds[0]); $bounds0->shouldReceive('containsFiles')->andReturn(false); $bounds1 = M::mock(ItemTreeBounds::classname()); $bounds1->shouldReceive('getItemId')->andReturn($itemIds[1]); $bounds1->shouldReceive('containsFiles')->andReturn(false); $bounds = array($bounds0, $bounds1); $uploadDao->shouldReceive('getItemTreeBounds')->with($itemIds[0])->andReturn($bounds[0]); $uploadDao->shouldReceive('getItemTreeBounds')->with($itemIds[1])->andReturn($bounds[1]); $clearingDao->shouldReceive('getEventIdsOfJob')->with($jobId)->andReturn(array($itemIds[0] => array(), $itemIds[1] => array())); $dbManager->shouldReceive('begin')->times(count($itemIds)); $dbManager->shouldReceive('commit')->times(count($itemIds)); /* dummy expectations needed for unmockable LicenseMap constructor */ $dbManager->shouldReceive('prepare'); $res = M::Mock(DbManager::classname()); $dbManager->shouldReceive('execute')->andReturn($res); $row1 = array('rf_fk' => 2334, 'parent_fk' => 1); $row2 = array('rf_fk' => 2333, 'parent_fk' => 1); $dbManager->shouldReceive('fetchArray')->with($res)->andReturn($row1, $row2, false); $dbManager->shouldReceive('freeResult')->with($res); /* /expectations for LicenseMap */ $decisionProcessor->shouldReceive('hasUnhandledScannerDetectedLicenses')->with($bounds0, $groupId, array(), anything())->andReturn(true); $clearingDao->shouldReceive('markDecisionAsWip')->with($itemIds[0], $userId, $groupId); $decisionProcessor->shouldReceive('hasUnhandledScannerDetectedLicenses')->with($bounds1, $groupId, array(), anything())->andReturn(false); $decisionProcessor->shouldReceive('makeDecisionFromLastEvents')->with($bounds1, $userId, $groupId, DecisionTypes::IDENTIFIED, false, array()); $runner = new SchedulerTestRunnerMock($dbManager, $agentDao, $clearingDao, $uploadDao, $highlightDao, $decisionProcessor, $agentLicenseEventProcessor); list($success, $output, $retCode) = $runner->run($uploadId, $userId, $groupId, $jobId, $args = ""); $this->assertTrue($success, 'cannot run decider'); $this->assertEquals($retCode, 0, 'decider failed: ' . $output); assertThat($this->getHeartCount($output), equalTo(count($itemIds))); $this->rmRepo(); }