8 namespace Fossology\Lib\Data\Clearing;
20 private $clearingEvent;
22 private $agentClearingEvent1;
24 private $agentClearingEvent2;
26 private $licenseDecisionResult;
29 protected function setUp() :
void
31 $this->licenseRef = M::mock(LicenseRef::class);
32 $this->clearingEvent = M::mock(ClearingEvent::class);
34 $this->agentClearingEvent1 = M::mock(AgentClearingEvent::class);
35 $this->agentClearingEvent2 = M::mock(AgentClearingEvent::class);
37 $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
40 protected function tearDown() :
void
42 $this->addToAssertionCount(\Hamcrest\MatcherAssert::getCount()-$this->assertCountBefore);
45 public function testHasAgentDecisionEventIsTrue()
47 $this->licenseDecisionResult =
new ClearingResult($this->clearingEvent, array($this->agentClearingEvent1, $this->agentClearingEvent2));
48 assertThat($this->licenseDecisionResult->hasAgentDecisionEvent(), is(
true));
51 public function testHasAgentDecisionEventIsFalse()
53 $this->licenseDecisionResult =
new ClearingResult($this->clearingEvent);
54 assertThat($this->licenseDecisionResult->hasAgentDecisionEvent(), is(
false));
57 public function testHasDecisionEventIsTrue()
59 $this->licenseDecisionResult =
new ClearingResult($this->clearingEvent, array($this->agentClearingEvent1, $this->agentClearingEvent2));
60 assertThat($this->licenseDecisionResult->hasClearingEvent(), is(
true));
63 public function testHasDecisionEventIsFalse()
65 $this->licenseDecisionResult =
new ClearingResult(
null, array($this->agentClearingEvent1));
66 assertThat($this->licenseDecisionResult->hasClearingEvent(), is(
false));
69 public function testGetLicenseRefFromClearingEvent()
71 $this->clearingEvent->shouldReceive(
"getLicenseRef")->once()->andReturn($this->licenseRef);
72 $this->licenseDecisionResult =
new ClearingResult($this->clearingEvent, array($this->agentClearingEvent1));
73 assertThat($this->licenseDecisionResult->getLicenseRef(), is($this->licenseRef));
76 public function testGetLicenseRefFromAgentEvents()
78 $this->agentClearingEvent1->shouldReceive(
"getLicenseRef")->once()->andReturn($this->licenseRef);
79 $this->licenseDecisionResult =
new ClearingResult(
null, array($this->agentClearingEvent1, $this->agentClearingEvent2));
80 assertThat($this->licenseDecisionResult->getLicenseRef(), is($this->licenseRef));
83 public function testGetLicenseIdFromClearingEvent()
86 $this->clearingEvent->shouldReceive(
"getLicenseId")->once()->andReturn($licenseId);
87 $this->licenseDecisionResult =
new ClearingResult($this->clearingEvent, array($this->agentClearingEvent1));
88 assertThat($this->licenseDecisionResult->getLicenseId(), is($licenseId));
92 public function testGetLicenseIdFromAgentEvent()
95 $this->agentClearingEvent1->shouldReceive(
"getLicenseId")->once()->andReturn($licenseId);
96 $this->licenseDecisionResult =
new ClearingResult(
null, array($this->agentClearingEvent1));
97 assertThat($this->licenseDecisionResult->getLicenseId(), is($licenseId));
100 public function testGetLicenseShortName()
102 $licenseShortName =
"<shortName>";
103 $this->licenseDecisionResult =
new ClearingResult($this->clearingEvent, array($this->agentClearingEvent1));
104 $this->clearingEvent->shouldReceive(
"getLicenseShortName")->once()->andReturn($licenseShortName);
105 assertThat($this->licenseDecisionResult->getLicenseShortName(), is($licenseShortName));
108 public function testGetLicenseFullName()
110 $licenseFullName =
"<fullName>";
111 $this->clearingEvent->shouldReceive(
"getLicenseFullName")->once()->andReturn($licenseFullName);
112 $this->licenseDecisionResult =
new ClearingResult($this->clearingEvent, array($this->agentClearingEvent1));
113 assertThat($this->licenseDecisionResult->getLicenseFullName(), is($licenseFullName));
116 public function testGetCommentWithClearingEvent()
118 $comment =
"<comment>";
119 $this->clearingEvent->shouldReceive(
"getComment")->once()->andReturn($comment);
120 $this->licenseDecisionResult =
new ClearingResult($this->clearingEvent, array($this->agentClearingEvent1));
121 assertThat($this->licenseDecisionResult->getComment(), is($comment));
124 public function testGetCommentWithoutClearingEvent()
127 $this->licenseDecisionResult =
new ClearingResult(
null, array($this->agentClearingEvent1));
128 assertThat($this->licenseDecisionResult->getComment(), is($comment));
131 public function testGetReportInfoWithClearingEvent()
133 $reportInfo =
"<reportInfo>";
134 $this->clearingEvent->shouldReceive(
"getReportinfo")->once()->andReturn($reportInfo);
135 $this->licenseDecisionResult =
new ClearingResult($this->clearingEvent, array($this->agentClearingEvent1));
136 assertThat($this->licenseDecisionResult->getReportinfo(), is($reportInfo));
140 public function testGetAcknowledgementWithClearingEvent()
142 $acknowledgement =
"<acknowledgement>";
143 $this->clearingEvent->shouldReceive(
"getAcknowledgement")->once()->andReturn($acknowledgement);
144 $this->licenseDecisionResult =
new ClearingResult($this->clearingEvent, array($this->agentClearingEvent1));
145 assertThat($this->licenseDecisionResult->getAcknowledgement(), is($acknowledgement));
148 public function testGetReportInfoWithoutClearingEvent()
151 $this->licenseDecisionResult =
new ClearingResult(
null, array($this->agentClearingEvent1));
152 assertThat($this->licenseDecisionResult->getReportinfo(), is($reportInfo));
155 public function testGetAcknowledgementWithoutClearingEvent()
157 $acknowledgement =
"";
158 $this->licenseDecisionResult =
new ClearingResult(
null, array($this->agentClearingEvent1));
159 assertThat($this->licenseDecisionResult->getAcknowledgement(), is($acknowledgement));
162 public function testIsRemoved()
164 $this->clearingEvent->shouldReceive(
"isRemoved")->once()->andReturn(
true);
165 $this->licenseDecisionResult =
new ClearingResult($this->clearingEvent, array($this->agentClearingEvent1));
166 assertThat($this->licenseDecisionResult->isRemoved(), is(
true));
169 public function testGetTimeStamp()
172 $this->clearingEvent->shouldReceive(
"getTimeStamp")->once()->andReturn($ts);
173 $this->licenseDecisionResult =
new ClearingResult($this->clearingEvent, array($this->agentClearingEvent1));
174 assertThat($this->licenseDecisionResult->getTimeStamp(), is($ts));
177 public function testEventTypeWithClearingEvent()
179 $eventType =
"<eventType>";
180 $this->clearingEvent->shouldReceive(
"getEventType")->once()->andReturn($eventType);
181 $this->licenseDecisionResult =
new ClearingResult($this->clearingEvent, array($this->agentClearingEvent1));
182 assertThat($this->licenseDecisionResult->getEventType(), is($eventType));
185 public function testEventTypeWithoutClearingEvent()
187 $eventType =
"<eventType>";
188 $this->agentClearingEvent1->shouldReceive(
"getEventType")->once()->andReturn($eventType);
189 $this->licenseDecisionResult =
new ClearingResult(
null, array($this->agentClearingEvent1));
190 assertThat($this->licenseDecisionResult->getEventType(), is($eventType));
193 public function testGetLicenseIdWithClearingEvent()
196 $this->clearingEvent->shouldReceive(
"getLicenseId")->once()->andReturn($licenseId);
197 $this->licenseDecisionResult =
new ClearingResult($this->clearingEvent, array($this->agentClearingEvent1));
198 assertThat($this->licenseDecisionResult->getLicenseId(), is($licenseId));
201 public function testGetLicenseIdWithoutClearingEvent()
204 $this->agentClearingEvent1->shouldReceive(
"getLicenseId")->once()->andReturn($licenseId);
205 $this->licenseDecisionResult =
new ClearingResult(
null, array($this->agentClearingEvent1));
206 assertThat($this->licenseDecisionResult->getLicenseId(), is($licenseId));
209 public function testGetClearingEvent()
211 $this->licenseDecisionResult =
new ClearingResult($this->clearingEvent, array($this->agentClearingEvent1));
212 assertThat($this->licenseDecisionResult->getClearingEvent(), is($this->clearingEvent));
215 public function testGetAgentClearingEvents()
217 $this->licenseDecisionResult =
new ClearingResult($this->clearingEvent, array($this->agentClearingEvent1, $this->agentClearingEvent2));
218 assertThat($this->licenseDecisionResult->getAgentDecisionEvents(), is(array(
219 $this->agentClearingEvent1, $this->agentClearingEvent2)));
222 public function testCreateClearingResultCreationFailsOfNoEventsWereFound()
224 $this->expectException(\Exception::class);
225 $this->expectExceptionMessage(
"cannot create ClearingEvent without any "
226 .
"event contained");