FOSSology  4.7.1
Open Source License Compliance by Open Source Software
ClearingDecisionProcessorTest.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2014-2015 Siemens AG
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
9 
23 use Mockery as M;
24 
25 function ReportCachePurgeAll()
26 {
27 
28 }
29 
30 class ClearingDecisionProcessorTest extends \PHPUnit\Framework\TestCase
31 {
32  public $assertCountBefore;
33  public $pfileId;
34 
35  const MATCH_ID = 231;
36  const PERCENTAGE = 315;
38  private $uploadTreeId;
40  private $userId;
42  private $groupId;
44  private $agentLicenseEventProcessor;
46  private $dbManager;
48  private $clearingDao;
50  private $itemTreeBounds;
52  private $clearingDecisionProcessor;
54  private $clearingEventProcessor;
56  private $timestamp;
58  private $includeSubFolders;
59 
60  protected function setUp() : void
61  {
62  $this->uploadTreeId = 432;
63  $this->pfileId = 32;
64  $this->userId = 12;
65  $this->groupId = 5;
66  $this->timestamp = time();
67  $this->includeSubFolders = false;
68 
69  $this->clearingDao = M::mock(ClearingDao::class);
70  $this->agentLicenseEventProcessor = M::mock(AgentLicenseEventProcessor::class);
71  $this->clearingEventProcessor = new ClearingEventProcessor();
72 
73  $this->itemTreeBounds = M::mock(ItemTreeBounds::class);
74  $this->itemTreeBounds->shouldReceive("getItemId")->withNoArgs()->andReturn($this->uploadTreeId);
75  $this->itemTreeBounds->shouldReceive("getPfileId")->withNoArgs()->andReturn($this->pfileId);
76 
77  $this->dbManager = M::mock(DbManager::class);
78  $this->dbManager->shouldReceive('begin')->withNoArgs();
79  $this->dbManager->shouldReceive('commit')->withNoArgs();
80 
81  $this->clearingDecisionProcessor = new ClearingDecisionProcessor(
82  $this->clearingDao, $this->agentLicenseEventProcessor, $this->clearingEventProcessor,
83  $this->dbManager);
84  $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
85  }
86 
87  protected function tearDown() : void
88  {
89  $this->addToAssertionCount(\Hamcrest\MatcherAssert::getCount()-$this->assertCountBefore);
90  M::close();
91  }
92 
93  public function testMakeDecisionFromLastEvents()
94  {
95  $isGlobal = DecisionScopes::ITEM;
96  $addedEvent = $this->createClearingEvent(123, $this->timestamp, 13, "licA", "License A");
97 
98  $this->clearingDao->shouldReceive("getRelevantClearingEvents")
99  ->with($this->itemTreeBounds, $this->groupId, $this->includeSubFolders)
100  ->andReturn(array($addedEvent));
101  $this->agentLicenseEventProcessor->shouldReceive("getScannerEvents")
102  ->with($this->itemTreeBounds)
103  ->andReturn(array());
104 
105  $clearingDecision = M::mock(ClearingDecision::class);
106  $clearingDecision->shouldReceive("getTimeStamp")->withNoArgs()->andReturn($this->timestamp-3600);
107  $clearingDecision->shouldReceive("getType")->withNoArgs()->andReturn(DecisionTypes::IDENTIFIED);
108  $clearingDecision->shouldReceive("getClearingEvents")->withNoArgs()->andReturn(array());
109 
110  $this->clearingDao->shouldReceive("getRelevantClearingDecision")
111  ->with($this->itemTreeBounds, $this->groupId)
112  ->andReturn($clearingDecision);
113 
114  $this->clearingDao->shouldReceive("createDecisionFromEvents")->once()
115  ->with($this->uploadTreeId, $this->userId, $this->groupId, DecisionTypes::IDENTIFIED, $isGlobal, is(arrayContainingInAnyOrder(123)));
116 
117  $this->clearingDecisionProcessor->makeDecisionFromLastEvents($this->itemTreeBounds, $this->userId, $this->groupId, DecisionTypes::IDENTIFIED, $isGlobal);
118  }
119 
120  public function testMakeDecisionFromLastEventsWithNoLicenseKnownTypeShouldNotCreateANewDecisionWhenNoLicensesShouldBeRemoved()
121  {
122  $isGlobal = DecisionScopes::REPO;
123  $addedEvent = $this->createClearingEvent(123, $this->timestamp, 13, "licA", "License A");
124 
125  $this->clearingDao->shouldReceive("getRelevantClearingEvents")
126  ->with($this->itemTreeBounds, $this->groupId, $this->includeSubFolders)
127  ->andReturn(array($addedEvent));
128  $this->agentLicenseEventProcessor->shouldReceive("getScannerEvents")
129  ->with($this->itemTreeBounds)->andReturn(array());
130 
131  $clearingDecision = M::mock(ClearingDecision::class);
132  $clearingDecision->shouldReceive("getTimeStamp")->withNoArgs()->andReturn($this->timestamp-3600);
133  $clearingDecision->shouldReceive("getType")->withNoArgs()->andReturn(DecisionTypes::IDENTIFIED);
134  $clearingDecision->shouldReceive("getScope")->withNoArgs()->andReturn(DecisionScopes::ITEM);
135  $clearingDecision->shouldReceive("getClearingEvents")->withNoArgs()->andReturn(array());
136 
137  $this->clearingDao->shouldReceive("getRelevantClearingDecision")
138  ->with($this->itemTreeBounds, $this->groupId)
139  ->andReturn($clearingDecision);
140  $eventId = 65;
141  $this->clearingDao->shouldReceive("insertClearingEvent")->with($this->itemTreeBounds->getItemId(), $this->userId, $this->groupId, $addedEvent->getLicenseId(), true)->andReturn($eventId);
142 
143  $this->clearingDao->shouldReceive("createDecisionFromEvents")->once()->with($this->uploadTreeId, $this->userId, $this->groupId, DecisionTypes::IDENTIFIED, $isGlobal, array($eventId));
144  $this->clearingDao->shouldReceive("removeWipClearingDecision")->never();
145 
146  $this->clearingDecisionProcessor->makeDecisionFromLastEvents($this->itemTreeBounds, $this->userId, $this->groupId, ClearingDecisionProcessor::NO_LICENSE_KNOWN_DECISION_TYPE, $isGlobal);
147  }
148 
149  public function testMakeDecisionFromLastEventsWithNoLicenseKnownTypeShouldNotCreateANewDecisionWhenNoLicensesShouldBeRemovedAndTheScopeDoesNotChange()
150  {
151  $isGlobal = DecisionScopes::REPO;
152  $addedEvent = $this->createClearingEvent(123, $this->timestamp, 13, "licA", "License A");
153 
154  $this->clearingDao->shouldReceive("getRelevantClearingEvents")
155  ->with($this->itemTreeBounds, $this->groupId, $this->includeSubFolders)
156  ->andReturn(array($addedEvent));
157  $this->agentLicenseEventProcessor->shouldReceive("getScannerEvents")
158  ->with($this->itemTreeBounds)->andReturn(array());
159 
160  $clearingDecision = M::mock(ClearingDecision::class);
161  $clearingDecision->shouldReceive("getTimeStamp")->withNoArgs()->andReturn($this->timestamp-3600);
162  $clearingDecision->shouldReceive("getType")->withNoArgs()->andReturn(DecisionTypes::IDENTIFIED);
163  $clearingDecision->shouldReceive("getScope")->withNoArgs()->andReturn($isGlobal);
164  $clearingDecision->shouldReceive("getClearingEvents")->withNoArgs()->andReturn(array());
165 
166  $this->clearingDao->shouldReceive("getRelevantClearingDecision")
167  ->with($this->itemTreeBounds, $this->groupId)
168  ->andReturn($clearingDecision);
169 
170  $eventId = 65;
171  $this->clearingDao->shouldReceive("insertClearingEvent")->with($this->itemTreeBounds->getItemId(), $this->userId, $this->groupId, $addedEvent->getLicenseId(), true)->andReturn($eventId);
172  $this->clearingDao->shouldReceive("createDecisionFromEvents")->once()->with($this->uploadTreeId, $this->userId, $this->groupId, DecisionTypes::IDENTIFIED, $isGlobal, array($eventId));
173  $this->clearingDao->shouldReceive("removeWipClearingDecision")->never();
174 
175  $this->clearingDecisionProcessor->makeDecisionFromLastEvents($this->itemTreeBounds, $this->userId, $this->groupId, ClearingDecisionProcessor::NO_LICENSE_KNOWN_DECISION_TYPE, $isGlobal);
176  }
177 
178  public function testMakeDecisionFromLastEventsWithNoLicenseKnownType()
179  {
180  $isGlobal = true;
181 
182  $this->agentLicenseEventProcessor->shouldReceive("getScannerEvents")
183  ->with($this->itemTreeBounds)->andReturn(array());
184 
185  $this->clearingDao->shouldReceive("getRelevantClearingEvents")
186  ->with($this->itemTreeBounds, $this->groupId, $this->includeSubFolders)
187  ->andReturn(array());
188 
189  $clearingDecision = M::mock(ClearingDecision::class);
190  $clearingDecision->shouldReceive("getTimeStamp")->withNoArgs()->andReturn($this->timestamp-3600);
191  $clearingDecision->shouldReceive("getType")->withNoArgs()->andReturn(DecisionTypes::IRRELEVANT);
192  $clearingDecision->shouldReceive("getClearingEvents")->withNoArgs()->andReturn(array());
193 
194  $this->clearingDao->shouldReceive("getRelevantClearingDecision")
195  ->with($this->itemTreeBounds, $this->groupId)
196  ->andReturn($clearingDecision);
197 
198  $this->clearingDao->shouldReceive("createDecisionFromEvents")->once()->with( $this->uploadTreeId, $this->userId, $this->groupId, DecisionTypes::IDENTIFIED, DecisionScopes::REPO, array());
199  $this->clearingDao->shouldReceive("removeWipClearingDecision")->never();
200 
201  $this->clearingDecisionProcessor->makeDecisionFromLastEvents($this->itemTreeBounds, $this->userId, $this->groupId, ClearingDecisionProcessor::NO_LICENSE_KNOWN_DECISION_TYPE, $isGlobal);
202  }
203 
204  public function testMakeDecisionFromLastEventsWithNoLicenseKnownTypeAndAnExistingAddingUserEvent()
205  {
207  list($scannerResults, $licenseRef) = $this->createScannerDetectedLicenses();
208  $addedEvent = $this->createClearingEvent(123, $this->timestamp, $licenseRef->getId(), $licenseRef->getShortName(), $licenseRef->getFullName(), ClearingEventTypes::USER, $isRemoved = false);
209 
210  $isGlobal = true;
211 
212  $this->agentLicenseEventProcessor->shouldReceive("getScannerEvents")
213  ->with($this->itemTreeBounds)->andReturn(array());
214 
215  $this->clearingDao->shouldReceive("getRelevantClearingEvents")
216  ->with($this->itemTreeBounds, $this->groupId, $this->includeSubFolders)
217  ->andReturn(array($licenseRef->getId() => $addedEvent));
218 
219  $clearingDecision = M::mock(ClearingDecision::class);
220  $clearingDecision->shouldReceive("getTimeStamp")->withNoArgs()->andReturn($this->timestamp-3600);
221  $clearingDecision->shouldReceive("getType")->withNoArgs()->andReturn(DecisionTypes::IRRELEVANT);
222  $clearingDecision->shouldReceive("getClearingEvents")->withNoArgs()->andReturn(array());
223 
224  $this->clearingDao->shouldReceive("getRelevantClearingDecision")
225  ->with($this->itemTreeBounds, $this->groupId)
226  ->andReturn($clearingDecision);
227 
228  $eventId = 65;
229  $this->clearingDao->shouldReceive("insertClearingEvent")->with($this->itemTreeBounds->getItemId(), $this->userId, $this->groupId, $addedEvent->getLicenseId(), true)->andReturn($eventId);
230  $this->clearingDao->shouldReceive("createDecisionFromEvents")->once()->with( $this->uploadTreeId, $this->userId, $this->groupId, DecisionTypes::IDENTIFIED, DecisionScopes::REPO, array($eventId));
231  $this->clearingDao->shouldReceive("removeWipClearingDecision")->never();
232 
233  $this->clearingDecisionProcessor->makeDecisionFromLastEvents($this->itemTreeBounds, $this->userId, $this->groupId, ClearingDecisionProcessor::NO_LICENSE_KNOWN_DECISION_TYPE, $isGlobal);
234  }
235 
236  public function testMakeDecisionFromLastEventsWithNoLicenseKnownTypeAndAnExistingRemovingUserEvent()
237  {
239  list($scannerResults, $licenseRef) = $this->createScannerDetectedLicenses();
240  $removedEvent = $this->createClearingEvent(123, $this->timestamp, $licenseRef->getId(), $licenseRef->getShortName(), $licenseRef->getFullName(), ClearingEventTypes::USER, $isRemoved = true);
241 
242  $isGlobal = true;
243 
244  $this->agentLicenseEventProcessor->shouldReceive("getScannerEvents")
245  ->with($this->itemTreeBounds)->andReturn(array());
246 
247  $this->clearingDao->shouldReceive("getRelevantClearingEvents")
248  ->with($this->itemTreeBounds, $this->groupId, $this->includeSubFolders)
249  ->andReturn(array($licenseRef->getId() => $removedEvent));
250 
251  $clearingDecision = M::mock(ClearingDecision::class);
252  $clearingDecision->shouldReceive("getTimeStamp")->withNoArgs()->andReturn($this->timestamp-3600);
253  $clearingDecision->shouldReceive("getType")->withNoArgs()->andReturn(DecisionTypes::IRRELEVANT);
254  $clearingDecision->shouldReceive("getClearingEvents")->withNoArgs()->andReturn(array());
255 
256  $this->clearingDao->shouldReceive("getRelevantClearingDecision")
257  ->with($this->itemTreeBounds, $this->groupId)
258  ->andReturn($clearingDecision);
259 
260  $this->clearingDao->shouldReceive("createDecisionFromEvents")->once()->with( $this->uploadTreeId, $this->userId, $this->groupId, DecisionTypes::IDENTIFIED, DecisionScopes::REPO, array());
261  $this->clearingDao->shouldReceive("removeWipClearingDecision")->never();
262 
263  $this->clearingDecisionProcessor->makeDecisionFromLastEvents($this->itemTreeBounds, $this->userId, $this->groupId, ClearingDecisionProcessor::NO_LICENSE_KNOWN_DECISION_TYPE, $isGlobal);
264  }
268  public function testMakeDecisionFromLastEventsWithDelayedScanner()
269  {
271  list($scannerResults, $licenseRef) = $this->createScannerDetectedLicenses();
272 
273  $isGlobal = false;
274  $removedEvent = $this->createClearingEvent(123, $this->timestamp, $licenseRef->getId(), $licenseRef->getShortName(), $licenseRef->getFullName(), ClearingEventTypes::USER, $isRemoved = true);
275 
276  $this->clearingDao->shouldReceive("getRelevantClearingEvents")
277  ->with($this->itemTreeBounds, $this->groupId, $this->includeSubFolders)
278  ->andReturn(array($licenseRef->getId() => $removedEvent));
279 
280  $this->agentLicenseEventProcessor->shouldReceive("getScannerEvents")
281  ->with($this->itemTreeBounds)->andReturn($scannerResults);
282 
283  $clearingDecision = M::mock(ClearingDecision::class);
284  $clearingDecision->shouldReceive("getTimeStamp")->withNoArgs()->andReturn($this->timestamp-3600);
285  $clearingDecision->shouldReceive("getType")->withNoArgs()->andReturn(DecisionTypes::IDENTIFIED);
286  $clearingDecision->shouldReceive("getClearingEvents")->withNoArgs()->andReturn(array());
287 
288  $this->clearingDao->shouldReceive("getRelevantClearingDecision")
289  ->with($this->itemTreeBounds,$this->groupId)
290  ->andReturn($clearingDecision);
291 
292  $this->clearingDao->shouldReceive("insertClearingEvent")
293  ->never();
294 
295  $this->clearingDao->shouldReceive("createDecisionFromEvents")
296  ->once()
297  ->with($this->uploadTreeId, $this->userId, $this->groupId, DecisionTypes::IDENTIFIED, DecisionScopes::ITEM,
298  is(arrayContainingInAnyOrder($removedEvent->getEventId())));
299  $this->clearingDao->shouldReceive("removeWipClearingDecision")->never();
300 
301  $this->clearingDecisionProcessor->makeDecisionFromLastEvents($this->itemTreeBounds, $this->userId, $this->groupId, DecisionTypes::IDENTIFIED, $isGlobal);
302  }
303 
304  public function testMakeDecisionFromLastEventsWithInvalidType()
305  {
306  $this->clearingDao->shouldReceive("getRelevantClearingEvents")->never();
307  $this->agentLicenseEventProcessor->shouldReceive("getScannerDetectedLicenses")->never();
308  $this->clearingDao->shouldReceive("getRelevantClearingDecision")->never();
309 
310  $this->clearingDao->shouldReceive("createDecisionFromEvents")->never();
311  $this->clearingDao->shouldReceive("removeWipClearingDecision")->never();
312 
313  $this->clearingDecisionProcessor->makeDecisionFromLastEvents($this->itemTreeBounds, $this->userId, $this->groupId, ClearingDecisionProcessor::NO_LICENSE_KNOWN_DECISION_TYPE - 1, false);
314  }
315 
316  public function testGetCurrentClearingsWithoutDecisions()
317  {
318  $this->agentLicenseEventProcessor->shouldReceive("getScannerEvents")
319  ->with($this->itemTreeBounds,LicenseMap::TRIVIAL)
320  ->andReturn(array());
321  $this->clearingDao->shouldReceive("getRelevantClearingEvents")->with($this->itemTreeBounds, $this->groupId)->andReturn(array());
322 
323  list($licenseDecisions, $removedClearings) = $this->clearingDecisionProcessor->getCurrentClearings($this->itemTreeBounds, $this->groupId);
324 
325  assertThat($licenseDecisions, is(emptyArray()));
326  assertThat($removedClearings, is(emptyArray()));
327  }
328 
329  public function testGetCurrentClearingsWithUserDecisionsOnly()
330  {
331  $addedEvent = $this->createClearingEvent(123, $this->timestamp, $licenseId=13, "licA", "License A");
332 
333  $this->agentLicenseEventProcessor->shouldReceive("getScannerEvents")
334  ->with($this->itemTreeBounds,LicenseMap::TRIVIAL)
335  ->andReturn(array());
336  $this->clearingDao->shouldReceive("getRelevantClearingEvents")
337  ->with($this->itemTreeBounds, $this->groupId)
338  ->andReturn(array($licenseId => $addedEvent));
339 
340  list($licenseDecisions, $removedClearings) = $this->clearingDecisionProcessor->getCurrentClearings($this->itemTreeBounds, $this->groupId);
341 
342  assertThat($licenseDecisions, is(arrayWithSize(1)));
343 
345  $result = $licenseDecisions[$addedEvent->getLicenseId()];
346  assertThat($result->getLicenseRef(), is($addedEvent->getLicenseRef()));
347  assertThat($result->getClearingEvent(), is($addedEvent));
348  assertThat($result->getAgentDecisionEvents(), is(emptyArray()));
349  assertThat($removedClearings, is(emptyArray()));
350  }
351 
352  public function testGetCurrentClearingsWithAgentDecisionsOnly()
353  {
354  list($scannerResults, $licenseRef) = $this->createScannerDetectedLicenses();
355 
356  $this->agentLicenseEventProcessor->shouldReceive("getScannerEvents")
357  ->with($this->itemTreeBounds,LicenseMap::TRIVIAL)
358  ->andReturn($scannerResults);
359  $this->clearingDao->shouldReceive("getRelevantClearingEvents")
360  ->with($this->itemTreeBounds, $this->groupId)
361  ->andReturn(array());
362 
363  list($licenseDecisions, $removedClearings) = $this->clearingDecisionProcessor->getCurrentClearings($this->itemTreeBounds, $this->groupId);
364 
365  assertThat($licenseDecisions, is(arrayWithSize(1)));
366 
368  $result = $licenseDecisions[$licenseRef->getId()];
369  assertThat($result->getLicenseRef(), is($licenseRef));
370  assertThat($result->getClearingEvent(), is(nullValue()));
371  assertThat($result->getAgentDecisionEvents(), is(arrayWithSize(1)));
372  assertThat($removedClearings, is(emptyArray()));
373  }
374 
375  public function testGetCurrentClearingsWithUserAndAgentDecision()
376  {
378  list($scannerResults, $licenseRef) = $this->createScannerDetectedLicenses();
379 
380  $this->agentLicenseEventProcessor->shouldReceive("getScannerEvents")
381  ->with($this->itemTreeBounds,LicenseMap::TRIVIAL)
382  ->andReturn($scannerResults);
383 
384  $licenseId = $licenseRef->getId();
385 
386  $addedEvent = $this->createClearingEvent(123, $this->timestamp, $licenseId, $licenseRef->getShortName(), $licenseRef->getFullName());
387  $this->clearingDao->shouldReceive("getRelevantClearingEvents")
388  ->with($this->itemTreeBounds, $this->groupId)
389  ->andReturn(array($licenseId => $addedEvent));
390 
391  list($licenseDecisions, $removedClearings) = $this->clearingDecisionProcessor->getCurrentClearings($this->itemTreeBounds, $this->groupId);
392 
393  assertThat($licenseDecisions, is(arrayWithSize(1)));
394 
396  $result = $licenseDecisions[$licenseRef->getId()];
397  assertThat($result->getLicenseRef(), is($licenseRef));
398  assertThat($result->getClearingEvent(), is($addedEvent));
399  assertThat($result->getAgentDecisionEvents(), is(arrayWithSize(1)));
400  assertThat($removedClearings, is(emptyArray()));
401  }
402 
403  public function testGetCurrentClearingsWithUserRemovedDecisionsOnly()
404  {
406  list($scannerResults, $licenseRef, $agentRef) = $this->createScannerDetectedLicenses();
407  $removedEvent = $this->createClearingEvent(123, $this->timestamp, $licenseRef->getId(), $licenseRef->getShortName(), $licenseRef->getFullName(), ClearingEventTypes::USER, true);
408 
409  $this->agentLicenseEventProcessor->shouldReceive("getScannerEvents")
410  ->with($this->itemTreeBounds,LicenseMap::TRIVIAL)->andReturn($scannerResults);
411 
412  $this->clearingDao->shouldReceive("getRelevantClearingEvents")
413  ->with($this->itemTreeBounds, $this->groupId)
414  ->andReturn(array($licenseRef->getId() => $removedEvent));
415 
416  list($licenseDecisions, $removedClearings) = $this->clearingDecisionProcessor->getCurrentClearings($this->itemTreeBounds, $this->groupId);
417 
418  assertThat($licenseDecisions, is(emptyArray()));
419  assertThat($removedClearings, is(arrayWithSize(1)));
420 
422  $result = $removedClearings[$removedEvent->getLicenseId()];
423  assertThat($result->getLicenseRef(), is($removedEvent->getLicenseRef()));
424  assertThat($result->getClearingEvent(), is($removedEvent));
425  $agentClearingEvents = $result->getAgentDecisionEvents();
426  assertThat($agentClearingEvents, is(arrayWithSize(1)));
427 
428  $agentEvent = $agentClearingEvents[0];
429 
430  assertThat($agentEvent->getAgentRef(), is($agentRef));
431  assertThat($agentEvent->getLicenseRef(), is($licenseRef));
432  assertThat($agentEvent->getMatchId(), is(self::MATCH_ID));
433  assertThat($agentEvent->getPercentage(), is(self::PERCENTAGE));
434  }
435 
436  public function testGetUnhandledScannerDetectedLicenses()
437  {
439  list($scannerResults, $licenseRef) = $this->createScannerDetectedLicenses();
440 
441  $this->clearingDao->shouldReceive("getRelevantClearingEvents")
442  ->with($this->itemTreeBounds, $this->groupId)
443  ->andReturn(array());
444  $this->agentLicenseEventProcessor->shouldReceive("getScannerEvents")
445  ->with($this->itemTreeBounds,LicenseMap::TRIVIAL)->andReturn($scannerResults);
446 
447  $hasUnhandledScannerDetectedLicenses = $this->clearingDecisionProcessor->hasUnhandledScannerDetectedLicenses($this->itemTreeBounds, $this->groupId);
448 
449  assertThat($hasUnhandledScannerDetectedLicenses);
450  }
451 
452  public function testGetUnhandledScannerDetectedLicensesWithMatch()
453  {
455  list($scannerResults, $licenseRef) = $this->createScannerDetectedLicenses();
456  $clearingEvent = $this->createClearingEvent(123, $this->timestamp, $licenseRef->getId(), $licenseRef->getShortName(), $licenseRef->getFullName());
457 
458  $this->clearingDao->shouldReceive("getRelevantClearingEvents")->once()
459  ->with($this->itemTreeBounds, $this->groupId)
460  ->andReturn(array($clearingEvent->getLicenseId()=>$clearingEvent));
461  $this->agentLicenseEventProcessor->shouldReceive("getScannerEvents")->once()
462  ->with($this->itemTreeBounds,LicenseMap::TRIVIAL)->andReturn($scannerResults);
463 
464  $hasUnhandledScannerDetectedLicenses = $this->clearingDecisionProcessor->hasUnhandledScannerDetectedLicenses($this->itemTreeBounds, $this->groupId);
465 
466  assertThat( $hasUnhandledScannerDetectedLicenses, is(False));
467  }
468 
469  public function testGetUnhandledScannerDetectedLicensesWithoutMatch()
470  {
472  list($scannerResults, $licenseRef) = $this->createScannerDetectedLicenses();
473  $offset = 23;
474  $clearingEvent = $this->createClearingEvent(123, $this->timestamp, $licenseRef->getId()+$offset, $licenseRef->getShortName(), $licenseRef->getFullName());
475 
476  $this->clearingDao->shouldReceive("getRelevantClearingEvents")
477  ->with($this->itemTreeBounds, $this->groupId)
478  ->andReturn(array($clearingEvent->getLicenseId()=>$clearingEvent));
479  $this->agentLicenseEventProcessor->shouldReceive("getScannerEvents")
480  ->with($this->itemTreeBounds,LicenseMap::TRIVIAL)->andReturn($scannerResults);
481 
482  $hasUnhandledScannerDetectedLicenses = $this->clearingDecisionProcessor->hasUnhandledScannerDetectedLicenses($this->itemTreeBounds, $this->groupId);
483 
484  assertThat($hasUnhandledScannerDetectedLicenses, is(True));
485  }
486 
487  public function testGetUnhandledScannerDetectedLicensesWithMappedMatch()
488  {
490  list($scannerResults, $licenseRef) = $this->createScannerDetectedLicenses();
491  $offset = 0;
492  $clearingEvent = $this->createClearingEvent($eventId=123, $this->timestamp, $licenseRef->getId()+$offset, $licenseRef->getShortName(), $licenseRef->getFullName());
493 
494  $this->clearingDao->shouldReceive("getRelevantClearingEvents")
495  ->with($this->itemTreeBounds, $this->groupId)
496  ->andReturn(array($clearingEvent->getLicenseId()=>$clearingEvent));
497  $this->agentLicenseEventProcessor->shouldReceive("getScannerEvents")
498  ->with($this->itemTreeBounds,LicenseMap::CONCLUSION)->andReturn($scannerResults);
499 
500  $licenseMap = M::mock(LicenseMap::class);
501  $licenseMap->shouldReceive('getProjectedId')->andReturnUsing(function($id) {
502  return $id;
503  });
504  $licenseMap->shouldReceive('getUsage')->andReturn(LicenseMap::CONCLUSION);
505 
506  $hasUnhandledScannerDetectedLicenses = $this->clearingDecisionProcessor->hasUnhandledScannerDetectedLicenses($this->itemTreeBounds, $this->groupId, array(), $licenseMap);
507 
508  assertThat( $hasUnhandledScannerDetectedLicenses, is(False) );
509  }
510 
523  private function createClearingEvent($eventId, $timestamp, $licenseId, $licenseShortName, $licenseFullName, $eventType = ClearingEventTypes::USER, $isRemoved = false, $reportInfo = "<reportInfo>", $comment = "<comment>")
524  {
525  $licenseRef = new LicenseRef($licenseId, $licenseShortName, $licenseFullName, $licenseShortName);
526  $clearingLicense = new ClearingLicense($licenseRef, $isRemoved, $reportInfo, $comment);
527  return new ClearingEvent($eventId, $this->uploadTreeId, $timestamp, $this->userId, $this->groupId, $eventType, $clearingLicense);
528  }
529 
533  protected function createScannerDetectedLicenses($licenseId = 13, $licenseShortname = "licA", $licenseFullName = "License-A")
534  {
535  $licenseRef = new LicenseRef($licenseId, $licenseShortname, $licenseFullName, $licenseShortname);
536 
537  $agentRef = M::mock(AgentRef::class);
538 
539  $scannerEvents = array(
540  $licenseId => array(new AgentClearingEvent($licenseRef, $agentRef, self::MATCH_ID, self::PERCENTAGE))
541  );
542 
543  return array($scannerEvents, $licenseRef, $agentRef);
544  }
545 }
createClearingEvent($eventId, $timestamp, $licenseId, $licenseShortName, $licenseFullName, $eventType=ClearingEventTypes::USER, $isRemoved=false, $reportInfo="<reportInfo>", $comment="<comment>")
createScannerDetectedLicenses($licenseId=13, $licenseShortname="licA", $licenseFullName="License-A")
Utility functions to process ClearingDecision.
fo_dbManager * dbManager
fo_dbManager object
Definition: process.c:16
Contains business rules for FOSSology.
list_t type structure used to keep various lists. (e.g. there are multiple lists).
Definition: nomos.h:308