FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
ClearingResultTest.php
1 <?php
2 /*
3 Copyright (C) 2014-2018, Siemens AG
4 
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 version 2 as published by the Free Software Foundation.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18 
20 
23 use Mockery as M;
24 
25 class ClearingResultTest extends \PHPUnit\Framework\TestCase
26 {
27 
29  private $licenseRef;
31  private $clearingEvent;
33  private $agentClearingEvent1;
35  private $agentClearingEvent2;
37  private $licenseDecisionResult;
38 
39 
40  protected function setUp()
41  {
42  $this->licenseRef = M::mock(LicenseRef::class);
43  $this->clearingEvent = M::mock(ClearingEvent::class);
44 
45  $this->agentClearingEvent1 = M::mock(AgentClearingEvent::class);
46  $this->agentClearingEvent2 = M::mock(AgentClearingEvent::class);
47 
48  $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
49  }
50 
51  protected function tearDown()
52  {
53  $this->addToAssertionCount(\Hamcrest\MatcherAssert::getCount()-$this->assertCountBefore);
54  }
55 
56  public function testHasAgentDecisionEventIsTrue()
57  {
58  $this->licenseDecisionResult = new ClearingResult($this->clearingEvent, array($this->agentClearingEvent1, $this->agentClearingEvent2));
59  assertThat($this->licenseDecisionResult->hasAgentDecisionEvent(), is(true));
60  }
61 
62  public function testHasAgentDecisionEventIsFalse()
63  {
64  $this->licenseDecisionResult = new ClearingResult($this->clearingEvent);
65  assertThat($this->licenseDecisionResult->hasAgentDecisionEvent(), is(false));
66  }
67 
68  public function testHasDecisionEventIsTrue()
69  {
70  $this->licenseDecisionResult = new ClearingResult($this->clearingEvent, array($this->agentClearingEvent1, $this->agentClearingEvent2));
71  assertThat($this->licenseDecisionResult->hasClearingEvent(), is(true));
72  }
73 
74  public function testHasDecisionEventIsFalse()
75  {
76  $this->licenseDecisionResult = new ClearingResult(null, array($this->agentClearingEvent1));
77  assertThat($this->licenseDecisionResult->hasClearingEvent(), is(false));
78  }
79 
80  public function testGetLicenseRefFromClearingEvent()
81  {
82  $this->clearingEvent->shouldReceive("getLicenseRef")->once()->andReturn($this->licenseRef);
83  $this->licenseDecisionResult = new ClearingResult($this->clearingEvent, array($this->agentClearingEvent1));
84  assertThat($this->licenseDecisionResult->getLicenseRef(), is($this->licenseRef));
85  }
86 
87  public function testGetLicenseRefFromAgentEvents()
88  {
89  $this->agentClearingEvent1->shouldReceive("getLicenseRef")->once()->andReturn($this->licenseRef);
90  $this->licenseDecisionResult = new ClearingResult(null, array($this->agentClearingEvent1, $this->agentClearingEvent2));
91  assertThat($this->licenseDecisionResult->getLicenseRef(), is($this->licenseRef));
92  }
93 
94  public function testGetLicenseIdFromClearingEvent()
95  {
96  $licenseId = 123;
97  $this->clearingEvent->shouldReceive("getLicenseId")->once()->andReturn($licenseId);
98  $this->licenseDecisionResult = new ClearingResult($this->clearingEvent, array($this->agentClearingEvent1));
99  assertThat($this->licenseDecisionResult->getLicenseId(), is($licenseId));
100  }
101 
102 
103  public function testGetLicenseIdFromAgentEvent()
104  {
105  $licenseId = 123;
106  $this->agentClearingEvent1->shouldReceive("getLicenseId")->once()->andReturn($licenseId);
107  $this->licenseDecisionResult = new ClearingResult(null, array($this->agentClearingEvent1));
108  assertThat($this->licenseDecisionResult->getLicenseId(), is($licenseId));
109  }
110 
111  public function testGetLicenseShortName()
112  {
113  $licenseShortName = "<shortName>";
114  $this->licenseDecisionResult = new ClearingResult($this->clearingEvent, array($this->agentClearingEvent1));
115  $this->clearingEvent->shouldReceive("getLicenseShortName")->once()->andReturn($licenseShortName);
116  assertThat($this->licenseDecisionResult->getLicenseShortName(), is($licenseShortName));
117  }
118 
119  public function testGetLicenseFullName()
120  {
121  $licenseFullName = "<fullName>";
122  $this->clearingEvent->shouldReceive("getLicenseFullName")->once()->andReturn($licenseFullName);
123  $this->licenseDecisionResult = new ClearingResult($this->clearingEvent, array($this->agentClearingEvent1));
124  assertThat($this->licenseDecisionResult->getLicenseFullName(), is($licenseFullName));
125  }
126 
127  public function testGetCommentWithClearingEvent()
128  {
129  $comment = "<comment>";
130  $this->clearingEvent->shouldReceive("getComment")->once()->andReturn($comment);
131  $this->licenseDecisionResult = new ClearingResult($this->clearingEvent, array($this->agentClearingEvent1));
132  assertThat($this->licenseDecisionResult->getComment(), is($comment));
133  }
134 
135  public function testGetCommentWithoutClearingEvent()
136  {
137  $comment = "";
138  $this->licenseDecisionResult = new ClearingResult(null, array($this->agentClearingEvent1));
139  assertThat($this->licenseDecisionResult->getComment(), is($comment));
140  }
141 
142  public function testGetReportInfoWithClearingEvent()
143  {
144  $reportInfo = "<reportInfo>";
145  $this->clearingEvent->shouldReceive("getReportinfo")->once()->andReturn($reportInfo);
146  $this->licenseDecisionResult = new ClearingResult($this->clearingEvent, array($this->agentClearingEvent1));
147  assertThat($this->licenseDecisionResult->getReportinfo(), is($reportInfo));
148  }
149 
150 
151  public function testGetAcknowledgementWithClearingEvent()
152  {
153  $acknowledgement = "<acknowledgement>";
154  $this->clearingEvent->shouldReceive("getAcknowledgement")->once()->andReturn($acknowledgement);
155  $this->licenseDecisionResult = new ClearingResult($this->clearingEvent, array($this->agentClearingEvent1));
156  assertThat($this->licenseDecisionResult->getAcknowledgement(), is($acknowledgement));
157  }
158 
159  public function testGetReportInfoWithoutClearingEvent()
160  {
161  $reportInfo = "";
162  $this->licenseDecisionResult = new ClearingResult(null, array($this->agentClearingEvent1));
163  assertThat($this->licenseDecisionResult->getReportinfo(), is($reportInfo));
164  }
165 
166  public function testGetAcknowledgementWithoutClearingEvent()
167  {
168  $acknowledgement = "";
169  $this->licenseDecisionResult = new ClearingResult(null, array($this->agentClearingEvent1));
170  assertThat($this->licenseDecisionResult->getAcknowledgement(), is($acknowledgement));
171  }
172 
173  public function testIsRemoved()
174  {
175  $this->clearingEvent->shouldReceive("isRemoved")->once()->andReturn(true);
176  $this->licenseDecisionResult = new ClearingResult($this->clearingEvent, array($this->agentClearingEvent1));
177  assertThat($this->licenseDecisionResult->isRemoved(), is(true));
178  }
179 
180  public function testGetTimeStamp()
181  {
182  $ts = time();
183  $this->clearingEvent->shouldReceive("getTimeStamp")->once()->andReturn($ts);
184  $this->licenseDecisionResult = new ClearingResult($this->clearingEvent, array($this->agentClearingEvent1));
185  assertThat($this->licenseDecisionResult->getTimeStamp(), is($ts));
186  }
187 
188  public function testEventTypeWithClearingEvent()
189  {
190  $eventType = "<eventType>";
191  $this->clearingEvent->shouldReceive("getEventType")->once()->andReturn($eventType);
192  $this->licenseDecisionResult = new ClearingResult($this->clearingEvent, array($this->agentClearingEvent1));
193  assertThat($this->licenseDecisionResult->getEventType(), is($eventType));
194  }
195 
196  public function testEventTypeWithoutClearingEvent()
197  {
198  $eventType = "<eventType>";
199  $this->agentClearingEvent1->shouldReceive("getEventType")->once()->andReturn($eventType);
200  $this->licenseDecisionResult = new ClearingResult(null, array($this->agentClearingEvent1));
201  assertThat($this->licenseDecisionResult->getEventType(), is($eventType));
202  }
203 
204  public function testGetLicenseIdWithClearingEvent()
205  {
206  $licenseId = 123;
207  $this->clearingEvent->shouldReceive("getLicenseId")->once()->andReturn($licenseId);
208  $this->licenseDecisionResult = new ClearingResult($this->clearingEvent, array($this->agentClearingEvent1));
209  assertThat($this->licenseDecisionResult->getLicenseId(), is($licenseId));
210  }
211 
212  public function testGetLicenseIdWithoutClearingEvent()
213  {
214  $licenseId = 123;
215  $this->agentClearingEvent1->shouldReceive("getLicenseId")->once()->andReturn($licenseId);
216  $this->licenseDecisionResult = new ClearingResult(null, array($this->agentClearingEvent1));
217  assertThat($this->licenseDecisionResult->getLicenseId(), is($licenseId));
218  }
219 
220  public function testGetClearingEvent()
221  {
222  $this->licenseDecisionResult = new ClearingResult($this->clearingEvent, array($this->agentClearingEvent1));
223  assertThat($this->licenseDecisionResult->getClearingEvent(), is($this->clearingEvent));
224  }
225 
226  public function testGetAgentClearingEvents()
227  {
228  $this->licenseDecisionResult = new ClearingResult($this->clearingEvent, array($this->agentClearingEvent1, $this->agentClearingEvent2));
229  assertThat($this->licenseDecisionResult->getAgentDecisionEvents(), is(array(
230  $this->agentClearingEvent1, $this->agentClearingEvent2)));
231  }
232 
238  {
239  new ClearingResult(null);
240  }
241 }