├── .gitignore ├── LICENSE ├── README.md ├── bluezone.png ├── bzw1.png ├── bzw2.png ├── bzw3.png ├── pom.xml ├── scripts ├── build.sh ├── ports-adapters.properties └── run_bluezone.sh └── src ├── bluezone-adapter-forobtainingrates-stub ├── pom.xml └── src │ └── main │ └── bluezone.adapter.forobtainingrates.stub │ ├── io │ └── github │ │ └── jmgarridopaz │ │ └── bluezone │ │ └── adapter │ │ └── forobtainingrates │ │ └── stub │ │ └── StubRateProviderAdapter.java │ └── module-info.java ├── bluezone-adapter-forparkingcars-webui ├── pom.xml └── src │ └── main │ ├── bluezone.adapter.forparkingcars.webui │ ├── io │ │ └── github │ │ │ └── jmgarridopaz │ │ │ └── bluezone │ │ │ └── adapter │ │ │ └── forparkingcars │ │ │ └── webui │ │ │ ├── ForParkingCarsWebUIDriver.java │ │ │ ├── GetTicketController.java │ │ │ ├── GlobalExceptionHandler.java │ │ │ ├── MainController.java │ │ │ ├── PurchaseTicketController.java │ │ │ └── WebUISpringBootApp.java │ └── module-info.java │ └── resources │ ├── application.properties │ ├── static │ └── css │ │ └── main.css │ └── templates │ ├── error.html │ ├── getTicketOut.html │ ├── index.html │ ├── mainlayout.html │ ├── purchaseTicketIn.html │ └── purchaseTicketOut.html ├── bluezone-adapter-forpaying-spy ├── pom.xml └── src │ └── main │ └── bluezone.adapter.forpaying.spy │ ├── io │ └── github │ │ └── jmgarridopaz │ │ └── bluezone │ │ └── adapter │ │ └── forpaying │ │ └── spy │ │ └── SpyPaymentServiceAdapter.java │ └── module-info.java ├── bluezone-adapter-forstoringtickets-fake ├── pom.xml └── src │ └── main │ └── bluezone.adapter.forstoringtickets.fake │ ├── io │ └── github │ │ └── jmgarridopaz │ │ └── bluezone │ │ └── adapter │ │ └── forstoringtickets │ │ └── fake │ │ └── FakeTicketStoreAdapter.java │ └── module-info.java ├── bluezone-driver-forcheckingcars-test ├── pom.xml └── src │ └── main │ └── bluezone.driver.forcheckingcars.test │ ├── io │ └── github │ │ └── jmgarridopaz │ │ └── bluezone │ │ └── driver │ │ └── forcheckingcars │ │ └── test │ │ ├── ForCheckingCarsTestDriver.java │ │ ├── SystemUnderTest.java │ │ └── illegallyparkedcar │ │ ├── AllTicketsExpired.java │ │ └── AtLeastOneValidTicket.java │ └── module-info.java ├── bluezone-driver-forparkingcars-test ├── pom.xml └── src │ └── main │ ├── bluezone.driver.forparkingcars.test │ ├── io │ │ └── github │ │ │ └── jmgarridopaz │ │ │ └── bluezone │ │ │ └── driver │ │ │ └── forparkingcars │ │ │ └── test │ │ │ ├── ForParkingCarsTestDriver.java │ │ │ └── stepdefs │ │ │ ├── PaymentStepDefs.java │ │ │ ├── RateStepDefs.java │ │ │ ├── ScenarioContext.java │ │ │ └── TicketStepDefs.java │ └── module-info.java │ └── resources │ └── testcases │ ├── getAllRatesByName.feature │ ├── getTicket.feature │ └── purchaseTicket.feature ├── bluezone-hexagon ├── pom.xml └── src │ └── main │ └── bluezone.hexagon │ ├── io │ └── github │ │ └── jmgarridopaz │ │ └── bluezone │ │ └── hexagon │ │ ├── AppConfigurator.java │ │ ├── AppFromDrivenSide.java │ │ ├── CarChecker.java │ │ ├── CarParker.java │ │ ├── RateCalculator.java │ │ ├── factory │ │ └── BlueZoneApp.java │ │ └── ports │ │ ├── driven │ │ ├── forobtainingrates │ │ │ ├── ForObtainingRates.java │ │ │ └── Rate.java │ │ ├── forpaying │ │ │ ├── ForPaying.java │ │ │ ├── PayErrorException.java │ │ │ └── PayRequest.java │ │ └── forstoringtickets │ │ │ ├── ForStoringTickets.java │ │ │ └── Ticket.java │ │ └── driving │ │ ├── forcheckingcars │ │ └── ForCheckingCars.java │ │ ├── forconfiguringapp │ │ └── ForConfiguringApp.java │ │ └── forparkingcars │ │ ├── ForParkingCars.java │ │ └── PurchaseTicketRequest.java │ └── module-info.java ├── bluezone-parent └── pom.xml └── bluezone-startup ├── pom.xml └── src └── main └── bluezone.startup ├── io └── github │ └── jmgarridopaz │ └── bluezone │ └── startup │ ├── AdapterSelector.java │ ├── BlueZoneInitializer.java │ ├── BlueZoneRunner.java │ └── DependencyConfigurator.java └── module-info.java /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | .settings/ 3 | .project 4 | .classpath 5 | .idea/ 6 | 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BlueZone 2 | ## An example application implementing Hexagonal Architecture 3 | 4 | See the article series: [https://jmgarridopaz.github.io/content/hexagonalarchitecture-ig/intro.html] 5 | 6 | ![BlueZone: Hexagonal Application Figure](bluezone.png) 7 | 8 | __BlueZone__ allows car drivers to pay remotely for parking cars at zones in a city, instead of paying with coins using parking meters. 9 | 10 | - Users (driver actors) of the application are _car drivers_ and _parking inspectors_. 11 | 12 | - Car drivers will access the application using a Web UI (User Interface), and they can do the following: 13 | 14 | - Query all the available rates in the city, in order to choose the one of the zone he wants to park the at. 15 | - Purchase a parking ticket, paying an amount of money for parking a car at a zone, during a period of time. This period starts at current date-time. The ending date-time is calculated from the paid amount, according to the rate of the zone. 16 | 17 | - Parking inspectors will access the application using a terminal with a CLI (Command Line Interface), and they can do the following: 18 | 19 | - Check whether a car is illegally parked at a zone. This will happen if there is no valid ticket for the car and the rate of the zone. A ticket is valid if current date-time is between the starting and ending date-time of the ticket period. 20 | 21 | - Driven actors needed by the application are: a rate repository, a ticket repository, and a payment service. 22 | 23 | ### Development environment: 24 | 25 | - Java 11 (version "11.0.15.1" 2022-04-22 LTS) 26 | 27 | - Maven 3.8.6 28 | 29 | - IntelliJ IDEA 2021.3.3 (Community Edition) 30 | 31 | - Ubuntu 20.04.4 LTS (Linux 5.13.0-40-generic) 32 | 33 | ### Instructions: 34 | 35 | - Download and extract this github repo to a local directory on your computer ( `` ) 36 | 37 | - Compile all modules (you need to do this just the first time before running): 38 | 39 | ~~~ 40 | cd 41 | ./scripts/build.sh 42 | ~~~ 43 | 44 | - Select the adapters to be plugged-in at each port, editing the "ports-adapters.properties" file, located in the "/scripts" directory. 45 | 46 | 47 | - Run the entry point to the app: 48 | 49 | ~~~ 50 | cd 51 | ./scripts/run_bluezone.sh 52 | ~~~ 53 | -------------------------------------------------------------------------------- /bluezone.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jmgarridopaz/bluezone/4d0e36c9d9fcb6bbc5d3a4b9346a4f47077c953f/bluezone.png -------------------------------------------------------------------------------- /bzw1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jmgarridopaz/bluezone/4d0e36c9d9fcb6bbc5d3a4b9346a4f47077c953f/bzw1.png -------------------------------------------------------------------------------- /bzw2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jmgarridopaz/bluezone/4d0e36c9d9fcb6bbc5d3a4b9346a4f47077c953f/bzw2.png -------------------------------------------------------------------------------- /bzw3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jmgarridopaz/bluezone/4d0e36c9d9fcb6bbc5d3a4b9346a4f47077c953f/bzw3.png -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 4.0.0 7 | 8 | io.github.jmgarridopaz.bluezone 9 | bluezone 10 | 1.0.0 11 | 12 | pom 13 | 14 | BlueZone Aggregate Project 15 | 16 | 17 | src/bluezone-parent 18 | src/bluezone-startup 19 | src/bluezone-hexagon 20 | src/bluezone-driver-forparkingcars-test 21 | src/bluezone-adapter-forparkingcars-webui 22 | src/bluezone-driver-forcheckingcars-test 23 | src/bluezone-adapter-forobtainingrates-stub 24 | src/bluezone-adapter-forstoringtickets-fake 25 | src/bluezone-adapter-forpaying-spy 26 | 27 | 28 | 29 | 30 | 31 | local-repo 32 | Local Repository 33 | file://${project.build.directory}/localrepo 34 | default 35 | false 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /scripts/build.sh: -------------------------------------------------------------------------------- 1 | mvn clean verify 2 | 3 | -------------------------------------------------------------------------------- /scripts/ports-adapters.properties: -------------------------------------------------------------------------------- 1 | # test-cases 2 | # web-ui 3 | ForParkingCars = web-ui 4 | 5 | # test-cases 6 | # cli 7 | ForCheckingCars = test-cases 8 | 9 | # test-double 10 | # file 11 | ForObtainingRates = test-double 12 | 13 | # test-double 14 | # database 15 | ForStoringTickets = test-double 16 | 17 | # test-double 18 | # NONE 19 | ForPaying = test-double 20 | -------------------------------------------------------------------------------- /scripts/run_bluezone.sh: -------------------------------------------------------------------------------- 1 | java -p ./src/bluezone-startup/target/bzmodulepath --add-modules ALL-SYSTEM -m bluezone.startup/io.github.jmgarridopaz.bluezone.startup.BlueZoneRunner ./scripts/ports-adapters.properties 2 | -------------------------------------------------------------------------------- /src/bluezone-adapter-forobtainingrates-stub/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | io.github.jmgarridopaz.bluezone 9 | bluezone-parent 10 | 1.0.0 11 | ../bluezone-parent 12 | 13 | 14 | bluezone-adapter-forobtainingrates-stub 15 | 16 | jar 17 | 18 | BlueZone - ForObtainingRates Stub Adapter 19 | 20 | 21 | 22 | io.github.jmgarridopaz.bluezone 23 | bluezone-hexagon 24 | 25 | 26 | io.github.jmgarridopaz.lib.portsadapters 27 | lib-portsadapters 28 | 29 | 30 | 31 | 32 | src/main/bluezone.adapter.forobtainingrates.stub 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /src/bluezone-adapter-forobtainingrates-stub/src/main/bluezone.adapter.forobtainingrates.stub/io/github/jmgarridopaz/bluezone/adapter/forobtainingrates/stub/StubRateProviderAdapter.java: -------------------------------------------------------------------------------- 1 | package io.github.jmgarridopaz.bluezone.adapter.forobtainingrates.stub; 2 | 3 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forobtainingrates.ForObtainingRates; 4 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forobtainingrates.Rate; 5 | import io.github.jmgarridopaz.lib.portsadapters.Adapter; 6 | 7 | import java.util.HashSet; 8 | import java.util.Set; 9 | 10 | /** 11 | * Driven adapter that implements "forobtainingrates" port with a stub test double. 12 | */ 13 | @Adapter(name="test-double") 14 | public class StubRateProviderAdapter implements ForObtainingRates { 15 | 16 | private Set rates; 17 | 18 | public StubRateProviderAdapter() { 19 | this.rates = new HashSet(); 20 | } 21 | 22 | @Override 23 | public Set findAll() { 24 | return this.rates; 25 | } 26 | 27 | @Override 28 | public Rate findByName ( String rateName ) { 29 | int occurrences = 0; 30 | Rate rateFound = null; 31 | for ( Rate rate : this.rates ) { 32 | if ( rate.getName().equals(rateName) ) { 33 | rateFound = rate; 34 | occurrences++; 35 | } 36 | } 37 | if ( occurrences==0 ) { 38 | return null; 39 | } 40 | if ( occurrences>1 ) { 41 | throw new RuntimeException("Multiple rates found with name = "+rateName); 42 | } 43 | return rateFound; 44 | } 45 | 46 | @Override 47 | public void addRate(Rate rate) { 48 | if ( exists(rate.getName()) ) { 49 | throw new RuntimeException("Cannot add rate to repository. Rate name '"+rate.getName()+"' already exists."); 50 | } 51 | this.rates.add(rate); 52 | } 53 | 54 | @Override 55 | public boolean exists ( String rateName ) { 56 | return ( findByName(rateName) != null ); 57 | } 58 | 59 | @Override 60 | public void empty() { 61 | this.rates = new HashSet(); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/bluezone-adapter-forobtainingrates-stub/src/main/bluezone.adapter.forobtainingrates.stub/module-info.java: -------------------------------------------------------------------------------- 1 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forobtainingrates.ForObtainingRates; 2 | 3 | module bluezone.adapter.forobtainingrates.stub { 4 | 5 | // DEPENDS ON 6 | requires bluezone.hexagon; 7 | requires io.github.jmgarridopaz.lib.portsadapters; 8 | 9 | // PUBLISHES 10 | exports io.github.jmgarridopaz.bluezone.adapter.forobtainingrates.stub; 11 | 12 | // SERVICES 13 | provides ForObtainingRates 14 | with io.github.jmgarridopaz.bluezone.adapter.forobtainingrates.stub.StubRateProviderAdapter; 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/bluezone-adapter-forparkingcars-webui/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | io.github.jmgarridopaz.bluezone 9 | bluezone-parent 10 | 1.0.0 11 | ../bluezone-parent 12 | 13 | 14 | bluezone-adapter-forparkingcars-webui 15 | 16 | jar 17 | 18 | BlueZone - ForParkingCars WewbUI Adapter 19 | 20 | 21 | io.github.jmgarridopaz.bluezone.adapter.forparkingcars.webui.WebUISpringBootApp 22 | 5.0.2 23 | 24 | 25 | 26 | 27 | io.github.jmgarridopaz.bluezone 28 | bluezone-hexagon 29 | 30 | 31 | io.github.jmgarridopaz.lib.portsadapters 32 | lib-portsadapters 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-web 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-thymeleaf 41 | 42 | 43 | org.thymeleaf.extras 44 | thymeleaf-extras-java8time 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | org.webjars 54 | bootstrap 55 | ${bootstrap.version} 56 | 57 | 58 | 59 | 60 | src/main/bluezone.adapter.forparkingcars.webui 61 | 62 | 63 | org.springframework.boot 64 | spring-boot-maven-plugin 65 | 66 | true 67 | 68 | 69 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /src/bluezone-adapter-forparkingcars-webui/src/main/bluezone.adapter.forparkingcars.webui/io/github/jmgarridopaz/bluezone/adapter/forparkingcars/webui/ForParkingCarsWebUIDriver.java: -------------------------------------------------------------------------------- 1 | package io.github.jmgarridopaz.bluezone.adapter.forparkingcars.webui; 2 | 3 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driving.forparkingcars.ForParkingCars; 4 | import io.github.jmgarridopaz.lib.portsadapters.Driver; 5 | 6 | 7 | public class ForParkingCarsWebUIDriver implements Driver { 8 | 9 | private static ForParkingCars carParker; 10 | 11 | public ForParkingCarsWebUIDriver ( ForParkingCars carParker ) { 12 | ForParkingCarsWebUIDriver.carParker = carParker; 13 | } 14 | 15 | public static ForParkingCars carParker() { 16 | return ForParkingCarsWebUIDriver.carParker; 17 | } 18 | 19 | @Override 20 | public void run(String... args) { 21 | WebUISpringBootApp.main(args); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/bluezone-adapter-forparkingcars-webui/src/main/bluezone.adapter.forparkingcars.webui/io/github/jmgarridopaz/bluezone/adapter/forparkingcars/webui/GetTicketController.java: -------------------------------------------------------------------------------- 1 | package io.github.jmgarridopaz.bluezone.adapter.forparkingcars.webui; 2 | 3 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driving.forparkingcars.ForParkingCars; 4 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forobtainingrates.Rate; 5 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forstoringtickets.Ticket; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Controller; 8 | import org.springframework.ui.Model; 9 | import org.springframework.web.bind.annotation.PostMapping; 10 | import org.springframework.web.bind.annotation.RequestParam; 11 | 12 | 13 | @Controller 14 | public class GetTicketController { 15 | 16 | private final ForParkingCars carParker; 17 | 18 | @Autowired 19 | public GetTicketController(ForParkingCars carParker ) { 20 | this.carParker = carParker; 21 | } 22 | 23 | @PostMapping("/getTicket") 24 | public String submitForm ( Model model, @RequestParam("ticketCode") String ticketCode ) { 25 | Ticket ticket = this.carParker.getTicket(ticketCode); 26 | model.addAttribute("ticket", ticket ); 27 | Rate ticketRate = this.carParker.getAllRatesByName().get(ticket.getRateName()); 28 | model.addAttribute( "ticketRate", ticketRate ); 29 | return "getTicketOut"; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/bluezone-adapter-forparkingcars-webui/src/main/bluezone.adapter.forparkingcars.webui/io/github/jmgarridopaz/bluezone/adapter/forparkingcars/webui/GlobalExceptionHandler.java: -------------------------------------------------------------------------------- 1 | //package io.github.jmgarridopaz.bluezone.adapter.forparkingcars.webui; 2 | // 3 | //import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forpaying.PayErrorException; 4 | //import org.springframework.beans.factory.annotation.Autowired; 5 | //import org.springframework.core.env.Environment; 6 | //import org.springframework.http.HttpStatus; 7 | //import org.springframework.ui.Model; 8 | //import org.springframework.web.bind.annotation.ControllerAdvice; 9 | //import org.springframework.web.bind.annotation.ExceptionHandler; 10 | // 11 | //import javax.servlet.RequestDispatcher; 12 | //import javax.servlet.http.HttpServletRequest; 13 | // 14 | // 15 | //@ControllerAdvice 16 | //public class GlobalExceptionHandler { 17 | // 18 | // @Autowired 19 | // private Environment environment; 20 | // 21 | // 22 | // @ExceptionHandler(Exception.class) 23 | // public String handleException (Model model, Exception exception ) { 24 | // String exceptionName = exception.getClass().getSimpleName(); 25 | // String errorMessage = exceptionMessageToShow ( exceptionName ); 26 | // model.addAttribute ("errorMessage", errorMessage ); 27 | // return "error"; 28 | // } 29 | // 30 | // private String exceptionMessageToShow ( String exceptionName ) { 31 | // String exceptionMessage = this.environment.getProperty ( exceptionName ); 32 | // if ( exceptionMessage==null ) { 33 | // return "An unexpected error occurred. Contact the application administrator"; 34 | // } 35 | // return exceptionMessage; 36 | // } 37 | // 38 | //}a -------------------------------------------------------------------------------- /src/bluezone-adapter-forparkingcars-webui/src/main/bluezone.adapter.forparkingcars.webui/io/github/jmgarridopaz/bluezone/adapter/forparkingcars/webui/MainController.java: -------------------------------------------------------------------------------- 1 | package io.github.jmgarridopaz.bluezone.adapter.forparkingcars.webui; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.ui.Model; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | 7 | 8 | @Controller 9 | public class MainController { 10 | 11 | @GetMapping( {"/","/index"} ) 12 | public String showWelcome() { 13 | return "index"; 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/bluezone-adapter-forparkingcars-webui/src/main/bluezone.adapter.forparkingcars.webui/io/github/jmgarridopaz/bluezone/adapter/forparkingcars/webui/PurchaseTicketController.java: -------------------------------------------------------------------------------- 1 | package io.github.jmgarridopaz.bluezone.adapter.forparkingcars.webui; 2 | 3 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driving.forparkingcars.ForParkingCars; 4 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driving.forparkingcars.PurchaseTicketRequest; 5 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forobtainingrates.Rate; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Controller; 8 | import org.springframework.ui.Model; 9 | import org.springframework.web.bind.annotation.GetMapping; 10 | import org.springframework.web.bind.annotation.ModelAttribute; 11 | import org.springframework.web.bind.annotation.PostMapping; 12 | 13 | import java.time.Clock; 14 | import java.util.Collection; 15 | import java.util.Map; 16 | 17 | 18 | @Controller 19 | public class PurchaseTicketController { 20 | 21 | private final ForParkingCars carParker; 22 | 23 | @Autowired 24 | public PurchaseTicketController(ForParkingCars carParker ) { 25 | this.carParker = carParker; 26 | } 27 | 28 | @GetMapping("/purchaseTicket") 29 | public String showForm ( Model model ) { 30 | Map ratesByName = this.carParker.getAllRatesByName(); 31 | Collection rates = ratesByName.values(); 32 | model.addAttribute("rates", rates); 33 | model.addAttribute("purchaseTicketRequest", new PurchaseTicketRequest() ); 34 | return "purchaseTicketIn"; 35 | } 36 | 37 | @PostMapping("/purchaseTicket") 38 | public String submitForm ( Model model, @ModelAttribute("purchaseTicketRequest") PurchaseTicketRequest purchaseTicketRequest ) { 39 | purchaseTicketRequest.setClock ( Clock.systemDefaultZone() ); 40 | String ticketCode = this.carParker.purchaseTicket(purchaseTicketRequest); 41 | model.addAttribute("ticketCode", ticketCode); 42 | return "purchaseTicketOut"; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/bluezone-adapter-forparkingcars-webui/src/main/bluezone.adapter.forparkingcars.webui/io/github/jmgarridopaz/bluezone/adapter/forparkingcars/webui/WebUISpringBootApp.java: -------------------------------------------------------------------------------- 1 | package io.github.jmgarridopaz.bluezone.adapter.forparkingcars.webui; 2 | 3 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driving.forparkingcars.ForParkingCars; 4 | import org.springframework.boot.WebApplicationType; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.boot.builder.SpringApplicationBuilder; 7 | import org.springframework.context.annotation.Bean; 8 | 9 | 10 | @SpringBootApplication 11 | public class WebUISpringBootApp { 12 | 13 | public static void main(String[] args) { 14 | new SpringApplicationBuilder(WebUISpringBootApp.class).web(WebApplicationType.SERVLET).run(args); 15 | } 16 | 17 | @Bean 18 | public ForParkingCars carParker() { 19 | return ForParkingCarsWebUIDriver.carParker(); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/bluezone-adapter-forparkingcars-webui/src/main/bluezone.adapter.forparkingcars.webui/module-info.java: -------------------------------------------------------------------------------- 1 | open module bluezone.adapter.forparkingcars.webui { 2 | // Opened because Thymeleaf needs access to templates resources at runtime 3 | 4 | // DEPENDS ON 5 | requires bluezone.hexagon; 6 | requires io.github.jmgarridopaz.lib.portsadapters; 7 | requires spring.boot.starter.web; 8 | requires spring.boot.starter.thymeleaf; 9 | requires bootstrap; 10 | requires spring.boot; 11 | requires spring.boot.autoconfigure; 12 | requires spring.context; 13 | requires spring.beans; 14 | requires spring.web; 15 | requires org.apache.tomcat.embed.core; 16 | requires thymeleaf; 17 | requires thymeleaf.spring5; 18 | requires thymeleaf.extras.java8time; 19 | requires spring.webmvc; 20 | requires spring.core; 21 | 22 | // PUBLISHES 23 | exports io.github.jmgarridopaz.bluezone.adapter.forparkingcars.webui; 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/bluezone-adapter-forparkingcars-webui/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.servlet.context-path=/bluezone 2 | spring.thymeleaf.cache=false 3 | server.error.whitelabel.enabled=false 4 | PayErrorException = Payment not made. An error occurred when paying the amount of the ticket with the card. 5 | -------------------------------------------------------------------------------- /src/bluezone-adapter-forparkingcars-webui/src/main/resources/static/css/main.css: -------------------------------------------------------------------------------- 1 | body { 2 | padding-top: 5rem; 3 | } 4 | 5 | .starter-template { 6 | padding: 3rem 1.5rem; 7 | text-align: center; 8 | } 9 | 10 | h1 { 11 | color:#0000FF; 12 | } 13 | 14 | h2 { 15 | color:#FF0000; 16 | } 17 | 18 | nav { 19 | padding-left: 0.5rem; 20 | } 21 | 22 | footer, footer a { 23 | padding: 0.5rem; 24 | color:#FFFFFF; 25 | } 26 | -------------------------------------------------------------------------------- /src/bluezone-adapter-forparkingcars-webui/src/main/resources/templates/error.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | BlueZone Application - Error Page 7 | 8 | 9 | 10 | 11 | 14 |
15 |
16 |

17 |

18 |

19 | 20 | Go To BlueZone Home Page 21 |
22 |
23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/bluezone-adapter-forparkingcars-webui/src/main/resources/templates/getTicketOut.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |

Ticket successfully purchased

5 |
6 |

You've just purchased the following ticket for parking your car

7 |
8 |
Ticket code:
9 |
10 |
11 |
12 |
Car plate:
13 |
14 |
15 |
16 |
Rate:
17 |
18 |
19 |
20 |
Starting date-time:
21 |
22 |
23 |
24 |
Ending date-time:
25 |
26 |
27 |
28 |
Price (€):
29 |
30 |
31 |
32 | 35 |
36 |
37 | -------------------------------------------------------------------------------- /src/bluezone-adapter-forparkingcars-webui/src/main/resources/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |

Welcome to BlueZone Application

5 |
6 |

A Hexagonal Architecture implementation example

7 |
8 |

BlueZone allows you to pay remotely for parking your car at regulated zones in the city

9 |
10 | 11 | -------------------------------------------------------------------------------- /src/bluezone-adapter-forparkingcars-webui/src/main/resources/templates/mainlayout.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | BlueZone Application 7 | 8 | 9 | 10 | 11 | 15 |
16 |
17 |
18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/bluezone-adapter-forparkingcars-webui/src/main/resources/templates/purchaseTicketIn.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |

Park a car

5 |
6 |
7 |
8 | 9 |
10 |
11 | 12 |
13 |
14 |
15 |
16 | 17 |
18 |
19 | 23 |
24 |
25 |
26 |
27 | 28 |
29 |
30 | 31 |
32 |
33 |
34 |
35 | 36 |
37 |
38 | 39 |
40 |
41 |
42 |
43 | 44 |
45 |
46 |
47 |
48 | 49 | -------------------------------------------------------------------------------- /src/bluezone-adapter-forparkingcars-webui/src/main/resources/templates/purchaseTicketOut.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |

Ticket successfully purchased

5 |
6 |

Your ticket code is

7 |
8 |

Click on the button below to view ticket details

9 |
10 | 11 | 12 |
13 |
14 | 15 | -------------------------------------------------------------------------------- /src/bluezone-adapter-forpaying-spy/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | io.github.jmgarridopaz.bluezone 9 | bluezone-parent 10 | 1.0.0 11 | ../bluezone-parent 12 | 13 | 14 | bluezone-adapter-forpaying-spy 15 | 16 | jar 17 | 18 | BlueZone - ForPaying Spy Adapter 19 | 20 | 21 | 22 | io.github.jmgarridopaz.bluezone 23 | bluezone-hexagon 24 | 25 | 26 | io.github.jmgarridopaz.lib.portsadapters 27 | lib-portsadapters 28 | 29 | 30 | 31 | 32 | src/main/bluezone.adapter.forpaying.spy 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /src/bluezone-adapter-forpaying-spy/src/main/bluezone.adapter.forpaying.spy/io/github/jmgarridopaz/bluezone/adapter/forpaying/spy/SpyPaymentServiceAdapter.java: -------------------------------------------------------------------------------- 1 | package io.github.jmgarridopaz.bluezone.adapter.forpaying.spy; 2 | 3 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forpaying.ForPaying; 4 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forpaying.PayErrorException; 5 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forpaying.PayRequest; 6 | import io.github.jmgarridopaz.lib.portsadapters.Adapter; 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | import java.util.Random; 10 | 11 | /** 12 | * Driven adapter that implements "forpaying" port with a "spy" test double. 13 | */ 14 | @Adapter(name="test-double") 15 | public class SpyPaymentServiceAdapter implements ForPaying { 16 | 17 | private List paymentSpool; 18 | private int payErrorGenerationPercentage; 19 | 20 | 21 | public SpyPaymentServiceAdapter() { 22 | this.paymentSpool = new ArrayList(); 23 | setPayErrorGenerationPercentage(0); 24 | } 25 | 26 | @Override 27 | public void setPayErrorGenerationPercentage ( int percent ) { 28 | this.payErrorGenerationPercentage = validatePercent(percent); 29 | } 30 | 31 | @Override 32 | public PayRequest lastPayRequest() { 33 | int spoolSize = this.paymentSpool.size(); 34 | if ( spoolSize == 0 ) { 35 | return null; 36 | } 37 | return this.paymentSpool.get(spoolSize-1); 38 | } 39 | 40 | @Override 41 | public void pay ( PayRequest payRequest ) throws PayErrorException { 42 | this.paymentSpool.add(payRequest); 43 | throwPayErrorExceptionRandomly(); 44 | } 45 | 46 | private void throwPayErrorExceptionRandomly() { 47 | int numberBetween1And100 = (new Random()).nextInt(100) + 1; 48 | if ( numberBetween1And100 <= this.payErrorGenerationPercentage ) { 49 | throw new PayErrorException("Payment failed"); 50 | } 51 | } 52 | 53 | private int validatePercent(int percent) { 54 | if ( percent < 0 ) { 55 | return 0; 56 | } 57 | if ( percent > 100 ) { 58 | return 100; 59 | } 60 | return percent; 61 | } 62 | 63 | } 64 | 65 | -------------------------------------------------------------------------------- /src/bluezone-adapter-forpaying-spy/src/main/bluezone.adapter.forpaying.spy/module-info.java: -------------------------------------------------------------------------------- 1 | import io.github.jmgarridopaz.bluezone.adapter.forpaying.spy.SpyPaymentServiceAdapter; 2 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forpaying.ForPaying; 3 | 4 | module bluezone.adapter.forpaying.spy { 5 | 6 | // DEPENDS ON 7 | requires bluezone.hexagon; 8 | requires io.github.jmgarridopaz.lib.portsadapters; 9 | 10 | // PUBLISHES 11 | exports io.github.jmgarridopaz.bluezone.adapter.forpaying.spy; 12 | 13 | // SERVICES 14 | provides ForPaying 15 | with SpyPaymentServiceAdapter; 16 | } 17 | -------------------------------------------------------------------------------- /src/bluezone-adapter-forstoringtickets-fake/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | io.github.jmgarridopaz.bluezone 9 | bluezone-parent 10 | 1.0.0 11 | ../bluezone-parent 12 | 13 | 14 | bluezone-adapter-forstoringtickets-fake 15 | 16 | jar 17 | 18 | BlueZone - ForStoringTickets Fake Adapter 19 | 20 | 21 | 22 | io.github.jmgarridopaz.bluezone 23 | bluezone-hexagon 24 | 25 | 26 | io.github.jmgarridopaz.lib.portsadapters 27 | lib-portsadapters 28 | 29 | 30 | 31 | 32 | src/main/bluezone.adapter.forstoringtickets.fake 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /src/bluezone-adapter-forstoringtickets-fake/src/main/bluezone.adapter.forstoringtickets.fake/io/github/jmgarridopaz/bluezone/adapter/forstoringtickets/fake/FakeTicketStoreAdapter.java: -------------------------------------------------------------------------------- 1 | package io.github.jmgarridopaz.bluezone.adapter.forstoringtickets.fake; 2 | 3 | import java.time.LocalDateTime; 4 | import java.util.*; 5 | import java.util.concurrent.atomic.AtomicLong; 6 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forstoringtickets.Ticket; 7 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forstoringtickets.ForStoringTickets; 8 | import io.github.jmgarridopaz.lib.portsadapters.Adapter; 9 | 10 | 11 | /** 12 | * Driven adapter that implements "forstoringtickets" port with a fake (in-memory db) test double. 13 | */ 14 | @Adapter(name="test-double") 15 | public class FakeTicketStoreAdapter implements ForStoringTickets { 16 | 17 | private static final int MAX_TICKET_CODE_LENGTH = 10; 18 | 19 | private Map ticketsByCode; 20 | private AtomicLong value; 21 | 22 | public FakeTicketStoreAdapter () { 23 | this.ticketsByCode = new HashMap(); 24 | setNextCode("1"); 25 | } 26 | 27 | @Override 28 | public String nextCode() { 29 | String currentTicketCodeAndIncrement = Long.toString(value.getAndIncrement()); 30 | return leftPaddedTicketCode ( currentTicketCodeAndIncrement ); 31 | } 32 | 33 | @Override 34 | public void setNextCode ( String ticketCode ) { 35 | if ( ticketCode.length() > MAX_TICKET_CODE_LENGTH ) { 36 | throw new RuntimeException("Ticket code overflow"); 37 | } 38 | long codeAsLong = Long.valueOf(ticketCode); 39 | this.value = new AtomicLong(codeAsLong); 40 | } 41 | 42 | @Override 43 | public String nextAvailableCode() { 44 | String currentTicketCode = Long.toString(value.get()); 45 | return leftPaddedTicketCode ( currentTicketCode ); 46 | } 47 | 48 | private String leftPaddedTicketCode ( String ticketCode ) { 49 | int numberOfZeroesToPad = MAX_TICKET_CODE_LENGTH - ticketCode.length(); 50 | if ( numberOfZeroesToPad < 0 ) { 51 | throw new RuntimeException("Ticket code overflow"); 52 | } 53 | for ( int counter = 0; counter < numberOfZeroesToPad; counter++ ) { 54 | ticketCode = "0" + ticketCode; 55 | } 56 | return ticketCode; 57 | } 58 | 59 | @Override 60 | public Ticket findByCode(String ticketCode) { 61 | if ( ! exists(ticketCode) ) { 62 | return null; 63 | } 64 | return this.ticketsByCode.get ( ticketCode ); 65 | } 66 | 67 | @Override 68 | public void store(Ticket ticket) { 69 | if ( exists(ticket.getCode()) ) { 70 | throw new RuntimeException("Cannot store ticket. Code '"+ticket.getCode()+"' already exists."); 71 | } 72 | this.ticketsByCode.put(ticket.getCode(),ticket); 73 | } 74 | 75 | @Override 76 | public List findByCarRateOrderByEndingDateTimeDesc ( String carPlate, String rateName ) { 77 | List ticketsOfCarAndRate = new ArrayList(); 78 | if ( this.ticketsByCode==null || this.ticketsByCode.isEmpty() ) { 79 | return ticketsOfCarAndRate; 80 | } 81 | for ( Ticket ticket : this.ticketsByCode.values() ) { 82 | if ( ticket.getCarPlate().equals(carPlate) && ticket.getRateName().equals(rateName) ) { 83 | ticketsOfCarAndRate.add(ticket); 84 | } 85 | } 86 | Comparator byEndingDateTimeDescTicketComparator = new Comparator() { 87 | @Override 88 | public int compare(Ticket ticket1, Ticket ticket2) { 89 | LocalDateTime endingDateTime1 = ticket1.getEndingDateTime(); 90 | LocalDateTime endingDateTime2 = ticket2.getEndingDateTime(); 91 | if ( endingDateTime1.isAfter(endingDateTime2) ) { 92 | return -1; 93 | } 94 | if ( endingDateTime1.isBefore(endingDateTime2) ) { 95 | return 1; 96 | } 97 | return 0; 98 | } 99 | }; 100 | ticketsOfCarAndRate.sort(byEndingDateTimeDescTicketComparator); 101 | return ticketsOfCarAndRate; 102 | } 103 | 104 | @Override 105 | public void delete ( String ticketCode ) { 106 | if ( ! exists(ticketCode) ) { 107 | throw new RuntimeException("Cannot delete ticket. Code '"+ticketCode+"' does not exist."); 108 | } 109 | this.ticketsByCode.remove ( ticketCode ); 110 | } 111 | 112 | @Override 113 | public boolean exists ( String ticketCode ) { 114 | return ( this.ticketsByCode.get(ticketCode) != null ); 115 | } 116 | 117 | 118 | } 119 | -------------------------------------------------------------------------------- /src/bluezone-adapter-forstoringtickets-fake/src/main/bluezone.adapter.forstoringtickets.fake/module-info.java: -------------------------------------------------------------------------------- 1 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forstoringtickets.ForStoringTickets; 2 | 3 | module bluezone.adapter.forstoringtickets.fake { 4 | 5 | // DEPENDS ON 6 | requires bluezone.hexagon; 7 | requires io.github.jmgarridopaz.lib.portsadapters; 8 | 9 | // PUBLISHES 10 | exports io.github.jmgarridopaz.bluezone.adapter.forstoringtickets.fake; 11 | 12 | // SERVICES 13 | provides ForStoringTickets 14 | with io.github.jmgarridopaz.bluezone.adapter.forstoringtickets.fake.FakeTicketStoreAdapter; 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/bluezone-driver-forcheckingcars-test/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | io.github.jmgarridopaz.bluezone 9 | bluezone-parent 10 | 1.0.0 11 | ../bluezone-parent 12 | 13 | 14 | bluezone-driver-forcheckingcars-test 15 | 16 | jar 17 | 18 | BlueZone - ForCheckingCars Test Driver 19 | 20 | 21 | 7.7.0 22 | 2.2 23 | 24 | 25 | 26 | 27 | io.github.jmgarridopaz.bluezone 28 | bluezone-hexagon 29 | 30 | 31 | io.github.jmgarridopaz.lib.portsadapters 32 | lib-portsadapters 33 | 34 | 35 | org.testng 36 | testng 37 | ${testng.version} 38 | 39 | 40 | org.hamcrest 41 | hamcrest 42 | ${hamcrest.version} 43 | 44 | 45 | 46 | 47 | src/main/bluezone.driver.forcheckingcars.test 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /src/bluezone-driver-forcheckingcars-test/src/main/bluezone.driver.forcheckingcars.test/io/github/jmgarridopaz/bluezone/driver/forcheckingcars/test/ForCheckingCarsTestDriver.java: -------------------------------------------------------------------------------- 1 | package io.github.jmgarridopaz.bluezone.driver.forcheckingcars.test; 2 | 3 | import io.github.jmgarridopaz.lib.portsadapters.Driver; 4 | import org.testng.TestNG; 5 | import org.testng.xml.*; 6 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driving.forcheckingcars.ForCheckingCars; 7 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driving.forconfiguringapp.ForConfiguringApp; 8 | import java.util.ArrayList; 9 | import java.util.Arrays; 10 | import java.util.List; 11 | 12 | /** 13 | * Driver (primary actor). 14 | * Test cases for the methods of "forcheckingcars" port. 15 | * It uses TestNG framework. 16 | */ 17 | public class ForCheckingCarsTestDriver implements Driver { 18 | 19 | private static final String REPORTS_DIRECTORY = 20 | System.getProperty("user.home") + 21 | System.getProperty("file.separator") + 22 | ".testng" + 23 | System.getProperty("file.separator") + 24 | "reports"; 25 | 26 | private final ForCheckingCars carChecker; 27 | private final ForConfiguringApp appConfigurator; 28 | 29 | /** 30 | * The driver has a configurable dependency on two ports: 31 | * @param carChecker Port to be tested. 32 | * @param appConfigurator Port with the API for setting-up the driven side through the application. 33 | */ 34 | public ForCheckingCarsTestDriver ( ForCheckingCars carChecker, ForConfiguringApp appConfigurator) { 35 | this.carChecker = carChecker; 36 | this.appConfigurator = appConfigurator; 37 | } 38 | 39 | /** 40 | * Launches TestNG. 41 | * TestNG suite ==> test ==> test class ==> test method. 42 | * Generates HTML report in the 'path-to-user-home-directory/.testng/reports' directory. 43 | */ 44 | @Override 45 | public void run ( String... args ) { 46 | 47 | // Set the 2 driver ports as the system under test 48 | SystemUnderTest.instance().setCarChecker( this.carChecker ); 49 | SystemUnderTest.instance().setAppConfigurator( this.appConfigurator ); 50 | 51 | // Run TestNG with a XML virtual file 52 | XmlSuite suite = new XmlSuite(); 53 | suite.setName("ForCheckingCars_Test_Suite"); 54 | 55 | XmlTest test = new XmlTest(suite); 56 | test.setName("IllegallyParkedCar_Test"); 57 | 58 | XmlPackage xmlPackage = new XmlPackage ( "io.github.jmgarridopaz.bluezone.driver.forcheckingcars.test.illegallyparkedcar.*" ); 59 | test.setPackages( Arrays.asList(new XmlPackage[]{xmlPackage})); 60 | 61 | List suites = new ArrayList(); 62 | suites.add(suite); 63 | 64 | TestNG testng = new TestNG(); 65 | 66 | testng.setXmlSuites(suites); 67 | 68 | testng.setOutputDirectory (REPORTS_DIRECTORY); 69 | 70 | System.out.println(); 71 | System.out.println("====="); 72 | System.out.println("Reports will be generated in the following output directory:"); 73 | System.out.println( testng.getOutputDirectory() ); 74 | System.out.println("====="); 75 | System.out.println(); 76 | 77 | testng.run(); 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /src/bluezone-driver-forcheckingcars-test/src/main/bluezone.driver.forcheckingcars.test/io/github/jmgarridopaz/bluezone/driver/forcheckingcars/test/SystemUnderTest.java: -------------------------------------------------------------------------------- 1 | package io.github.jmgarridopaz.bluezone.driver.forcheckingcars.test; 2 | 3 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driving.forcheckingcars.ForCheckingCars; 4 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driving.forconfiguringapp.ForConfiguringApp; 5 | 6 | 7 | public enum SystemUnderTest { 8 | 9 | INSTANCE; 10 | 11 | private ForCheckingCars carChecker; 12 | private ForConfiguringApp appConfigurator; 13 | 14 | public static SystemUnderTest instance() { 15 | return SystemUnderTest.INSTANCE; 16 | } 17 | 18 | public void setCarChecker(ForCheckingCars carChecker) { 19 | this.carChecker = carChecker; 20 | } 21 | 22 | public void setAppConfigurator(ForConfiguringApp appConfigurator ) { 23 | this.appConfigurator = appConfigurator; 24 | } 25 | 26 | public ForConfiguringApp appConfigurator() { 27 | return this.appConfigurator; 28 | } 29 | 30 | public ForCheckingCars carChecker() { 31 | return this.carChecker; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/bluezone-driver-forcheckingcars-test/src/main/bluezone.driver.forcheckingcars.test/io/github/jmgarridopaz/bluezone/driver/forcheckingcars/test/illegallyparkedcar/AllTicketsExpired.java: -------------------------------------------------------------------------------- 1 | package io.github.jmgarridopaz.bluezone.driver.forcheckingcars.test.illegallyparkedcar; 2 | 3 | import io.github.jmgarridopaz.bluezone.driver.forcheckingcars.test.SystemUnderTest; 4 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forstoringtickets.Ticket; 5 | import org.testng.Reporter; 6 | import org.testng.annotations.DataProvider; 7 | import org.testng.annotations.Test; 8 | import java.math.BigDecimal; 9 | import java.time.Clock; 10 | import java.time.LocalDateTime; 11 | import java.time.Month; 12 | import java.time.ZoneOffset; 13 | import java.util.List; 14 | import static org.hamcrest.MatcherAssert.assertThat; 15 | import static org.hamcrest.Matchers.is; 16 | 17 | /* 18 | SCENARIO: All tickets expired 19 | ----------------------------- 20 | 21 | GIVEN 22 | these tickets at repository: 23 | | code | carPlate | rateName | startingDateTime | endingDateTime | price | 24 | | 0000000658 | 6989JJH | BLUE_ZONE | 2022/06/11 08:30 | 2022/06/11 09:00 | 0.40 | 25 | | 0000000659 | 6989JJH | BLUE_ZONE | 2022/06/11 09:15 | 2022/06/11 10:15 | 0.80 | 26 | | 0000000660 | 1365MDS | BLUE_ZONE | 2022/06/11 09:30 | 2022/06/11 11:00 | 1.20 | 27 | | 0000000661 | 6989JJH | GREEN_ZONE | 2022/06/11 10:00 | 2022/06/11 10:30 | 0.60 | 28 | WHEN 29 | I check at "2022/06/11 10:16" car "6989JJH" parked in an area with rate "BLUE_ZONE" 30 | THEN 31 | illegally parked car should be "true" 32 | */ 33 | public class AllTicketsExpired { 34 | 35 | // SystemUnderTest Outcome 36 | private boolean illegallyParkedCar; 37 | 38 | @Test ( dataProvider = "all-tickets-expired" ) 39 | public void carShouldBeIllegallyParkedWhenAllTicketsExpired ( List tickets, LocalDateTime currentDateTime, String carPlate, String rateName, boolean expectedIllegallyParkedCar ) { 40 | givenTheseTicketsAtRepository ( tickets ); 41 | whenICheckAtCurrentDateTimeCarParkedInAreaWithRate ( currentDateTime, carPlate, rateName ); 42 | thenIllegallyParkedCarShouldBe ( expectedIllegallyParkedCar ); 43 | } 44 | 45 | private void givenTheseTicketsAtRepository ( List tickets ) { 46 | Reporter.log ("GIVEN these tickets at repository:" + tickets ); 47 | for ( Ticket ticket : tickets ) { 48 | SystemUnderTest.instance().appConfigurator().createTicket(ticket); 49 | } 50 | } 51 | 52 | private void whenICheckAtCurrentDateTimeCarParkedInAreaWithRate ( LocalDateTime currentDateTime, String carPlate, String rateName ) { 53 | Reporter.log ("WHEN I check at '" + currentDateTime + "' car '" + carPlate + "' parked in an area with rate '" + rateName + "'" ); 54 | Clock clock = Clock.fixed(currentDateTime.toInstant(ZoneOffset.UTC),ZoneOffset.UTC); 55 | this.illegallyParkedCar = SystemUnderTest.instance().carChecker().illegallyParkedCar(clock,carPlate,rateName); 56 | } 57 | 58 | private void thenIllegallyParkedCarShouldBe ( boolean expectedIllegallyParkedCar ) { 59 | Reporter.log ("THEN illegally parked car ('" + this.illegallyParkedCar + "') should be '" + expectedIllegallyParkedCar + "'" ); 60 | assertThat ( this.illegallyParkedCar, is(expectedIllegallyParkedCar) ); 61 | } 62 | 63 | @DataProvider ( name = "all-tickets-expired") 64 | public Object[][] allTicketsExpiredData() { 65 | Ticket ticket1 = new Ticket("0000000658","6989JJH","BLUE_ZONE",LocalDateTime.of(2022, Month.JUNE, 11, 8, 30),LocalDateTime.of(2022, Month.JUNE, 11, 9, 0),new BigDecimal("0.40")); 66 | Ticket ticket2 = new Ticket("0000000659","6989JJH","BLUE_ZONE",LocalDateTime.of(2022, Month.JUNE, 11, 9, 15),LocalDateTime.of(2022, Month.JUNE, 11, 10, 15),new BigDecimal("0.80")); 67 | Ticket ticket3 = new Ticket("0000000660","1365MDS","BLUE_ZONE",LocalDateTime.of(2022, Month.JUNE, 11, 9, 30),LocalDateTime.of(2022, Month.JUNE, 11, 11, 0),new BigDecimal("1.20")); 68 | Ticket ticket4 = new Ticket("0000000661","6989JJH","GREEN_ZONE",LocalDateTime.of(2022, Month.JUNE, 11, 10, 0),LocalDateTime.of(2022, Month.JUNE, 11, 10, 30),new BigDecimal("0.60")); 69 | List expiredTickets = List.of ( ticket1, ticket2, ticket3, ticket4 ); 70 | LocalDateTime currentDateTime = ticket2.getEndingDateTime().plusMinutes(1); 71 | String carPlate = ticket2.getCarPlate(); 72 | String rateName = ticket2.getRateName(); 73 | boolean expectedIllegallyParkedCar = true; 74 | return new Object[][] { 75 | { expiredTickets, currentDateTime, carPlate, rateName, expectedIllegallyParkedCar }, 76 | }; 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /src/bluezone-driver-forcheckingcars-test/src/main/bluezone.driver.forcheckingcars.test/io/github/jmgarridopaz/bluezone/driver/forcheckingcars/test/illegallyparkedcar/AtLeastOneValidTicket.java: -------------------------------------------------------------------------------- 1 | package io.github.jmgarridopaz.bluezone.driver.forcheckingcars.test.illegallyparkedcar; 2 | 3 | import io.github.jmgarridopaz.bluezone.driver.forcheckingcars.test.SystemUnderTest; 4 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forstoringtickets.Ticket; 5 | import org.testng.Reporter; 6 | import org.testng.annotations.DataProvider; 7 | import org.testng.annotations.Test; 8 | import java.math.BigDecimal; 9 | import java.time.*; 10 | import static org.hamcrest.MatcherAssert.assertThat; 11 | import static org.hamcrest.Matchers.is; 12 | 13 | /* 14 | SCENARIO: At least one valid ticket 15 | ----------------------------------- 16 | 17 | GIVEN 18 | this ticket at repository: 19 | | code | carPlate | rateName | startingDateTime | endingDateTime | price | 20 | | 0000001155 | 1365MDS | GREEN_ZONE | 2022/06/17 12:15 | 2022/06/17 12:45 | 0.60 | 21 | WHEN 22 | I check at "2022/06/17 12:30" car "1365MDS" parked in an area with rate "GREEN_ZONE" 23 | THEN 24 | illegally parked car should be "false" 25 | */ 26 | public class AtLeastOneValidTicket { 27 | 28 | // SystemUnderTest Outcome 29 | private boolean illegallyParkedCar; 30 | 31 | @Test ( dataProvider = "one-valid-ticket" ) 32 | public void carShouldNotBeIllegallyParkedWhenAtLeastOneValidTicket ( Ticket ticket, LocalDateTime currentDateTime, String carPlate, String rateName, boolean expectedIllegallyParkedCar ) { 33 | givenThisTicketAtRepository ( ticket ); 34 | whenICheckAtCurrentDateTimeCarParkedInAreaWithRate ( currentDateTime, carPlate, rateName ); 35 | thenIllegallyParkedCarShouldBe ( expectedIllegallyParkedCar ); 36 | } 37 | 38 | private void givenThisTicketAtRepository ( Ticket ticket ) { 39 | Reporter.log ("GIVEN this ticket at repository:" + ticket ); 40 | SystemUnderTest.instance().appConfigurator().createTicket(ticket); 41 | } 42 | 43 | private void whenICheckAtCurrentDateTimeCarParkedInAreaWithRate ( LocalDateTime currentDateTime, String carPlate, String rateName ) { 44 | Reporter.log ("WHEN I check at '" + currentDateTime + "' car '" + carPlate + "' parked in an area with rate '" + rateName + "'" ); 45 | Clock clock = Clock.fixed(currentDateTime.toInstant(ZoneOffset.UTC),ZoneOffset.UTC); 46 | this.illegallyParkedCar = SystemUnderTest.instance().carChecker().illegallyParkedCar(clock,carPlate,rateName); 47 | } 48 | 49 | private void thenIllegallyParkedCarShouldBe ( boolean expectedIllegallyParkedCar ) { 50 | Reporter.log ("THEN illegally parked car ('" + this.illegallyParkedCar + "') should be '" + expectedIllegallyParkedCar + "'" ); 51 | assertThat ( this.illegallyParkedCar, is(expectedIllegallyParkedCar) ); 52 | } 53 | 54 | @DataProvider ( name = "one-valid-ticket") 55 | public Object[][] allTicketsExpiredData() { 56 | Ticket ticket = new Ticket("0000001155","1365MDS","GREEN_ZONE",LocalDateTime.of(2022, Month.JUNE, 17, 12, 15),LocalDateTime.of(2022, Month.JUNE, 17, 12, 45),new BigDecimal("0.60")); 57 | long minutesOfTicket = Duration.between(ticket.getStartingDateTime(),ticket.getEndingDateTime()).toMinutes(); 58 | LocalDateTime currentDateTime = ticket.getStartingDateTime().plusMinutes( minutesOfTicket/2 ); 59 | String carPlate = ticket.getCarPlate(); 60 | String rateName = ticket.getRateName(); 61 | boolean expectedIllegallyParkedCar = false; 62 | return new Object[][] { 63 | { ticket, currentDateTime, carPlate, rateName, expectedIllegallyParkedCar }, 64 | }; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/bluezone-driver-forcheckingcars-test/src/main/bluezone.driver.forcheckingcars.test/module-info.java: -------------------------------------------------------------------------------- 1 | module bluezone.driver.forcheckingcars.test { 2 | 3 | // DEPENDS ON 4 | requires bluezone.hexagon; 5 | requires io.github.jmgarridopaz.lib.portsadapters; 6 | requires org.testng; 7 | requires org.hamcrest; 8 | 9 | // PUBLISHES 10 | exports io.github.jmgarridopaz.bluezone.driver.forcheckingcars.test; 11 | exports io.github.jmgarridopaz.bluezone.driver.forcheckingcars.test.illegallyparkedcar 12 | to org.testng; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/bluezone-driver-forparkingcars-test/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | io.github.jmgarridopaz.bluezone 9 | bluezone-parent 10 | 1.0.0 11 | ../bluezone-parent 12 | 13 | 14 | bluezone-driver-forparkingcars-test 15 | 16 | jar 17 | 18 | BlueZone - ForParkingCars Test Driver 19 | 20 | 21 | 6.10.1 22 | 2.2 23 | 24 | 25 | 26 | 27 | io.github.jmgarridopaz.bluezone 28 | bluezone-hexagon 29 | 30 | 31 | io.github.jmgarridopaz.lib.portsadapters 32 | lib-portsadapters 33 | 34 | 35 | io.cucumber 36 | cucumber-java 37 | ${cucumber.version} 38 | 39 | 40 | org.hamcrest 41 | hamcrest 42 | ${hamcrest.version} 43 | 44 | 45 | io.cucumber 46 | cucumber-picocontainer 47 | ${cucumber.version} 48 | 49 | 50 | 51 | 52 | src/main/bluezone.driver.forparkingcars.test 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /src/bluezone-driver-forparkingcars-test/src/main/bluezone.driver.forparkingcars.test/io/github/jmgarridopaz/bluezone/driver/forparkingcars/test/ForParkingCarsTestDriver.java: -------------------------------------------------------------------------------- 1 | package io.github.jmgarridopaz.bluezone.driver.forparkingcars.test; 2 | 3 | import io.github.jmgarridopaz.bluezone.driver.forparkingcars.test.stepdefs.ScenarioContext; 4 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driving.forconfiguringapp.ForConfiguringApp; 5 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driving.forparkingcars.ForParkingCars; 6 | import io.github.jmgarridopaz.lib.portsadapters.Driver; 7 | 8 | /** 9 | * 10 | * Driver that runs "forparkingcars" port test cases. 11 | * 12 | * It uses Cucumber testing automation tool 13 | * 14 | * Test cases are scenarios described in feature files using Gherkin language. 15 | * 16 | * There will be a feature file for each use case, containing scenarios as acceptance tests for the use case. 17 | * 18 | * The feature is written using the "role-goal-benefit" template 19 | * ( "AS a role I WANT some goal SO THAT some benefit" ). 20 | * 21 | * Scenarios are written using the "given-when-then" template 22 | * ( "GIVEN some context WHEN some action is carried out THEN a set of consequences should be obtained" ). 23 | * 24 | */ 25 | public class ForParkingCarsTestDriver implements Driver { 26 | 27 | public static ForParkingCars CAR_PARKER; 28 | public static ForConfiguringApp APP_CONFIGURATOR; 29 | 30 | public ForParkingCarsTestDriver (ForParkingCars carParker, ForConfiguringApp appConfigurator ) { 31 | CAR_PARKER = carParker; 32 | APP_CONFIGURATOR = appConfigurator; 33 | } 34 | 35 | /** 36 | * Launches Cucumber to run feature files at "src/main/resources/testcases/" 37 | * Creates a html report at the URL given in the console output 38 | */ 39 | @Override 40 | public void run ( String... args) { 41 | 42 | // Calling Cucumber with command line args 43 | String[] cucumberArgs = new String[] 44 | { 45 | "classpath:testcases", 46 | "--glue", ScenarioContext.class.getPackageName(), 47 | "--snippets", "camelcase", 48 | "--plugin", "pretty", 49 | "--publish" 50 | }; 51 | io.cucumber.core.cli.Main.main ( cucumberArgs ); 52 | 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/bluezone-driver-forparkingcars-test/src/main/bluezone.driver.forparkingcars.test/io/github/jmgarridopaz/bluezone/driver/forparkingcars/test/stepdefs/PaymentStepDefs.java: -------------------------------------------------------------------------------- 1 | package io.github.jmgarridopaz.bluezone.driver.forparkingcars.test.stepdefs; 2 | 3 | import io.cucumber.java.DataTableType; 4 | import io.cucumber.java.en.Given; 5 | import io.cucumber.java.en.Then; 6 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forpaying.PayRequest; 7 | import java.math.BigDecimal; 8 | import java.util.Map; 9 | import static org.hamcrest.MatcherAssert.assertThat; 10 | import static org.hamcrest.Matchers.*; 11 | 12 | 13 | public class PaymentStepDefs { 14 | 15 | private final ScenarioContext scenarioContext; 16 | 17 | public PaymentStepDefs(ScenarioContext scenarioContext ) { 18 | this.scenarioContext = scenarioContext; 19 | } 20 | 21 | @DataTableType 22 | public PayRequest payRequestEntry ( Map row ) { 23 | String ticketCode = row.get("ticketCode"); 24 | String paymentCard = row.get("paymentCard"); 25 | BigDecimal amount = new BigDecimal(row.get("amount")); 26 | return new PayRequest ( ticketCode, paymentCard, amount ); 27 | } 28 | 29 | @Given("the payment is not valid") 30 | public void thePaymentIsNotValid() { 31 | this.scenarioContext.appConfigurator().setPaymentErrorPercentage(100); 32 | } 33 | 34 | @Given("the payment is valid") 35 | public void thePaymentIsValid() { 36 | this.scenarioContext.appConfigurator().setPaymentErrorPercentage(0); 37 | } 38 | 39 | @Then("the following pay request should have been done to payment service:") 40 | public void theFollowingPayRequestShouldHaveBeenDoneToPaymentService ( PayRequest expectedPayRequest ) { 41 | PayRequest lastPayRequest = this.scenarioContext.appConfigurator().getLastPayRequestDone(); 42 | assertThat(lastPayRequest,is(expectedPayRequest)); 43 | } 44 | 45 | @Then("a PayErrorException should have been thrown") 46 | public void aPayErrorExceptionShouldHaveBeenThrown() { 47 | assertThat(this.scenarioContext.payErrorException(),is(notNullValue())); 48 | } 49 | 50 | @Then("no PayErrorException should have been thrown") 51 | public void noPayErrorExceptionShouldHaveBeenThrown() { 52 | assertThat(this.scenarioContext.payErrorException(),is(nullValue())); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/bluezone-driver-forparkingcars-test/src/main/bluezone.driver.forparkingcars.test/io/github/jmgarridopaz/bluezone/driver/forparkingcars/test/stepdefs/RateStepDefs.java: -------------------------------------------------------------------------------- 1 | package io.github.jmgarridopaz.bluezone.driver.forparkingcars.test.stepdefs; 2 | 3 | import io.cucumber.java.DataTableType; 4 | import io.cucumber.java.en.Given; 5 | import io.cucumber.java.en.Then; 6 | import io.cucumber.java.en.When; 7 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forobtainingrates.Rate; 8 | import java.math.BigDecimal; 9 | import java.util.List; 10 | import java.util.Map; 11 | import static org.hamcrest.MatcherAssert.assertThat; 12 | import static org.hamcrest.Matchers.is; 13 | 14 | 15 | public class RateStepDefs { 16 | 17 | private final ScenarioContext scenarioContext; 18 | 19 | public RateStepDefs(ScenarioContext scenarioContext) { 20 | this.scenarioContext = scenarioContext; 21 | } 22 | 23 | @DataTableType 24 | public Rate rateEntry(Map row) { 25 | String name = row.get("name"); 26 | BigDecimal amountPerHour = new BigDecimal(row.get("amountPerHour")); 27 | return new Rate(name, amountPerHour); 28 | } 29 | 30 | @Given("there are the following rates at rate repository:") 31 | public void thereAreTheFollowingRatesAtRateRepository(List rates) { 32 | this.scenarioContext.appConfigurator().initRateProviderWith(rates); 33 | } 34 | 35 | @When("I ask for getting all rates by name") 36 | public void iAskForGettingAllRatesByName() { 37 | Map ratesByName = this.scenarioContext.carParker().getAllRatesByName(); 38 | this.scenarioContext.setCurrentRatesByName(ratesByName); 39 | } 40 | 41 | @Then("I should obtain the following rates indexed by name:") 42 | public void iShouldObtainTheFollowingRatesIndexedByName(Map expectedRatesByName) { 43 | assertThat(this.scenarioContext.currentRatesByName(), is(expectedRatesByName)); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/bluezone-driver-forparkingcars-test/src/main/bluezone.driver.forparkingcars.test/io/github/jmgarridopaz/bluezone/driver/forparkingcars/test/stepdefs/ScenarioContext.java: -------------------------------------------------------------------------------- 1 | package io.github.jmgarridopaz.bluezone.driver.forparkingcars.test.stepdefs; 2 | 3 | import io.github.jmgarridopaz.bluezone.driver.forparkingcars.test.ForParkingCarsTestDriver; 4 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forobtainingrates.Rate; 5 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forpaying.PayErrorException; 6 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forstoringtickets.Ticket; 7 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driving.forconfiguringapp.ForConfiguringApp; 8 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driving.forparkingcars.ForParkingCars; 9 | 10 | import java.util.Map; 11 | 12 | /** 13 | * Class for sharing state between different steps files in one scenario. 14 | * 15 | * It is instantiated and injected into the stepdefs by PicoContainer (DI framework). 16 | * 17 | * Put this class in stepdefs package to be recreated for every scenario. 18 | * 19 | * So that there won't be state leakage between scenarios. 20 | */ 21 | public class ScenarioContext { 22 | 23 | private final ForParkingCars carParker; 24 | private final ForConfiguringApp appConfigurator; 25 | private Map currentRatesByName; 26 | private Ticket currentTicketWithCode; 27 | private String purchasedTicketCode; 28 | private PayErrorException payErrorException; 29 | 30 | public ScenarioContext() { 31 | this.carParker = ForParkingCarsTestDriver.CAR_PARKER; 32 | this.appConfigurator = ForParkingCarsTestDriver.APP_CONFIGURATOR; 33 | } 34 | 35 | public ForParkingCars carParker() { return this.carParker; } 36 | 37 | public ForConfiguringApp appConfigurator() { 38 | return this.appConfigurator; 39 | } 40 | 41 | public Map currentRatesByName() { 42 | return this.currentRatesByName; 43 | } 44 | 45 | public void setCurrentRatesByName(Map ratesByName) { 46 | this.currentRatesByName = ratesByName; 47 | } 48 | 49 | public Ticket currentTicketWithCode() { 50 | return this.currentTicketWithCode; 51 | } 52 | 53 | public void setCurrentTicketWithCode ( Ticket ticket ) { 54 | this.currentTicketWithCode = ticket; 55 | } 56 | 57 | public String purchasedTicketCode() { 58 | return this.purchasedTicketCode; 59 | } 60 | 61 | public void setPurchasedTicketCode ( String ticketCode) { 62 | this.purchasedTicketCode = ticketCode; 63 | } 64 | 65 | public PayErrorException payErrorException() { 66 | return this.payErrorException; 67 | } 68 | 69 | public void setPayErrorException(PayErrorException payErrorException) { 70 | this.payErrorException = payErrorException; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/bluezone-driver-forparkingcars-test/src/main/bluezone.driver.forparkingcars.test/io/github/jmgarridopaz/bluezone/driver/forparkingcars/test/stepdefs/TicketStepDefs.java: -------------------------------------------------------------------------------- 1 | package io.github.jmgarridopaz.bluezone.driver.forparkingcars.test.stepdefs; 2 | 3 | import io.cucumber.java.DataTableType; 4 | import io.cucumber.java.en.Given; 5 | import io.cucumber.java.en.Then; 6 | import io.cucumber.java.en.When; 7 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forpaying.PayErrorException; 8 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forstoringtickets.Ticket; 9 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driving.forparkingcars.PurchaseTicketRequest; 10 | 11 | import java.math.BigDecimal; 12 | import java.time.Clock; 13 | import java.time.LocalDateTime; 14 | import java.time.ZoneOffset; 15 | import java.time.format.DateTimeFormatter; 16 | import java.util.List; 17 | import java.util.Map; 18 | import static org.hamcrest.MatcherAssert.assertThat; 19 | import static org.hamcrest.Matchers.*; 20 | 21 | 22 | public class TicketStepDefs { 23 | 24 | private final ScenarioContext scenarioContext; 25 | 26 | public TicketStepDefs(ScenarioContext scenarioContext ) { 27 | this.scenarioContext = scenarioContext; 28 | } 29 | 30 | @DataTableType 31 | public Ticket ticketEntry (Map row ) { 32 | String code = row.get("code"); 33 | String carPlate = row.get("carPlate"); 34 | String rateName = row.get("rateName"); 35 | LocalDateTime startingDateTime = LocalDateTime.parse ( row.get("startingDateTime"), DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm") ); 36 | LocalDateTime endingDateTime = LocalDateTime.parse ( row.get("endingDateTime"), DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm") ); 37 | BigDecimal price = new BigDecimal(row.get("price")); 38 | return new Ticket(code,carPlate,rateName,startingDateTime,endingDateTime,price); 39 | } 40 | 41 | @DataTableType 42 | public PurchaseTicketRequest purchaseTicketRequestEntry ( Map row ) { 43 | String carPlate = row.get("carPlate"); 44 | String rateName = row.get("rateName"); 45 | LocalDateTime currentDateTime = LocalDateTime.parse ( row.get("clock"), DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm") ); 46 | Clock clock = Clock.fixed(currentDateTime.toInstant(ZoneOffset.UTC),ZoneOffset.UTC); 47 | BigDecimal amount = new BigDecimal(row.get("amount")); 48 | String paymentCard = row.get("paymentCard"); 49 | return new PurchaseTicketRequest( carPlate, rateName, clock, amount, paymentCard ); 50 | } 51 | 52 | @Given("there is the following ticket at ticket repository:") 53 | public void thereIsTheFollowingTicketAtTicketRepository ( List tickets ) { 54 | Ticket ticket = tickets.get(0); 55 | this.scenarioContext.appConfigurator().createTicket(ticket); 56 | } 57 | 58 | @Given("there is no ticket with code {string} at ticket repository") 59 | public void thereIsNoTicketWithCodeAtTicketRepository ( String ticketCode ) { 60 | this.scenarioContext.appConfigurator().eraseTicket(ticketCode); 61 | } 62 | 63 | @Given("next available ticket code is {string}") 64 | public void nextAvailableTicketCodeIs(String ticketCode) { 65 | this.scenarioContext.appConfigurator().setNextTicketCodeToReturn(ticketCode); 66 | } 67 | 68 | @When("I ask for getting the ticket with code {string}") 69 | public void iAskForGettingTheTicketWithCode(String ticketCode) { 70 | Ticket ticket = this.scenarioContext.carParker().getTicket(ticketCode); 71 | this.scenarioContext.setCurrentTicketWithCode ( ticket ); 72 | } 73 | 74 | @When("I do the following purchase ticket request:") 75 | public void iDoTheFollowingPurchaseTicketRequest ( PurchaseTicketRequest purchaseTicketRequest ) { 76 | try { 77 | String ticketCode = this.scenarioContext.carParker().purchaseTicket(purchaseTicketRequest); 78 | this.scenarioContext.setPurchasedTicketCode(ticketCode); 79 | } catch ( PayErrorException payErrorException ) { 80 | this.scenarioContext.setPayErrorException(payErrorException); 81 | } 82 | } 83 | 84 | @Then("I should obtain the following ticket:") 85 | public void iShouldObtainTheFollowingTicket ( List tickets ) { 86 | Ticket expectedTicketWithCode = tickets.get(0); 87 | assertThat( this.scenarioContext.currentTicketWithCode(), is(expectedTicketWithCode) ); 88 | } 89 | 90 | @Then("I should obtain no ticket") 91 | public void iShouldObtainNoTicket() { 92 | assertThat ( this.scenarioContext.currentTicketWithCode(),is(nullValue()) ); 93 | } 94 | 95 | @Then("I should obtain the ticket code {string}") 96 | public void iShouldObtainTheTicketCode(String expectedPurchasedTicketCode) { 97 | assertThat(this.scenarioContext.purchasedTicketCode(),is(expectedPurchasedTicketCode)); 98 | } 99 | 100 | @Then("there should be the following ticket at ticket repository:") 101 | public void thereShouldBeTheFollowingTicketAtTicketRepository ( Ticket expectedPurchasedTicket ) { 102 | Ticket ticketAtRepo = this.scenarioContext.carParker().getTicket(expectedPurchasedTicket.getCode()); 103 | assertThat(ticketAtRepo,is(expectedPurchasedTicket)); 104 | } 105 | 106 | @Then("next available ticket code should be {string}") 107 | public void nextAvailableTicketCodeShouldBe(String expectedNextTicketCode) { 108 | String currentNextTicketCode = this.scenarioContext.appConfigurator().getNextTicketCodeToReturn(); 109 | assertThat(currentNextTicketCode,is(expectedNextTicketCode)); 110 | } 111 | 112 | @Then("I should obtain no ticket code") 113 | public void iShouldObtainNoTicketCode() { 114 | assertThat(this.scenarioContext.purchasedTicketCode(),is(nullValue())); 115 | } 116 | 117 | @Then("there should be no ticket with code {string} at ticket repository") 118 | public void thereShouldBeNoTicketWithCodeAtTicketRepository(String ticketCode) { 119 | Ticket ticketAtRepo = this.scenarioContext.carParker().getTicket(ticketCode); 120 | assertThat(ticketAtRepo,is(nullValue())); 121 | } 122 | 123 | } 124 | -------------------------------------------------------------------------------- /src/bluezone-driver-forparkingcars-test/src/main/bluezone.driver.forparkingcars.test/module-info.java: -------------------------------------------------------------------------------- 1 | module bluezone.driver.forparkingcars.test { 2 | 3 | // DEPENDS ON 4 | requires bluezone.hexagon; 5 | requires io.github.jmgarridopaz.lib.portsadapters; 6 | requires io.cucumber.java; 7 | requires io.cucumber.datatable; 8 | requires io.cucumber.core; 9 | requires org.hamcrest; 10 | 11 | // PUBLISHES 12 | exports io.github.jmgarridopaz.bluezone.driver.forparkingcars.test; 13 | opens io.github.jmgarridopaz.bluezone.driver.forparkingcars.test.stepdefs 14 | to io.cucumber.java, 15 | picocontainer; 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/bluezone-driver-forparkingcars-test/src/main/resources/testcases/getAllRatesByName.feature: -------------------------------------------------------------------------------- 1 | Feature: Get all rates by name 2 | 3 | AS 4 | a car driver 5 | 6 | I WANT TO 7 | get the available rates in the city indexed by name 8 | 9 | SO THAT 10 | I can choose the rate name of the zone I want to park the car at 11 | 12 | 13 | Scenario: BLUE, GREEN and ORANGE rates 14 | 15 | Given there are the following rates at rate repository: 16 | | name | amountPerHour | 17 | | BLUE_ZONE | 0.80 | 18 | | ORANGE_ZONE | 0.95 | 19 | | GREEN_ZONE | 1.20 | 20 | 21 | When I ask for getting all rates by name 22 | 23 | Then I should obtain the following rates indexed by name: 24 | | | name | amountPerHour | 25 | | BLUE_ZONE | BLUE_ZONE | 0.80 | 26 | | GREEN_ZONE | GREEN_ZONE | 1.20 | 27 | | ORANGE_ZONE | ORANGE_ZONE | 0.95 | 28 | -------------------------------------------------------------------------------- /src/bluezone-driver-forparkingcars-test/src/main/resources/testcases/getTicket.feature: -------------------------------------------------------------------------------- 1 | Feature: Get ticket 2 | 3 | AS 4 | a car driver 5 | 6 | I WANT TO 7 | get the ticket from its code 8 | 9 | SO THAT 10 | I can see the whole ticket data after purchasing it 11 | 12 | 13 | Scenario: Can get an existing ticket 14 | 15 | Given there is the following ticket at ticket repository: 16 | | code | carPlate | rateName | startingDateTime | endingDateTime | price | 17 | | 0000000019 | 7607KWH | GREEN_ZONE | 2022/05/19 17:00 | 2022/05/19 17:30 | 0.60 | 18 | 19 | When I ask for getting the ticket with code "0000000019" 20 | 21 | Then I should obtain the following ticket: 22 | | code | carPlate | rateName | startingDateTime | endingDateTime | price | 23 | | 0000000019 | 7607KWH | GREEN_ZONE | 2022/05/19 17:00 | 2022/05/19 17:30 | 0.60 | 24 | 25 | 26 | 27 | Scenario: The ticket code doesn't exist 28 | 29 | Given there is no ticket with code "0000000052" at ticket repository 30 | 31 | When I ask for getting the ticket with code "0000000052" 32 | 33 | Then I should obtain no ticket 34 | -------------------------------------------------------------------------------- /src/bluezone-driver-forparkingcars-test/src/main/resources/testcases/purchaseTicket.feature: -------------------------------------------------------------------------------- 1 | Feature: Purchase ticket 2 | 3 | AS 4 | a car driver 5 | 6 | I WANT TO 7 | purchase a ticket for parking the car at a zone during a period of time 8 | 9 | SO THAT 10 | I can park the car without being fined 11 | 12 | 13 | Scenario: At orange zone paying for 2 hours 14 | 15 | Given there are the following rates at rate repository: 16 | | name | amountPerHour | 17 | | ORANGE_ZONE | 0.95 | 18 | 19 | And next available ticket code is "0000000001" 20 | 21 | And there is no ticket with code "0000000001" at ticket repository 22 | 23 | And the payment is valid 24 | 25 | When I do the following purchase ticket request: 26 | | carPlate | rateName | clock | amount | paymentCard | 27 | | 6989JJH | ORANGE_ZONE | 2022/05/11 10:00 | 1.90 | 5200828282828210 | 28 | 29 | Then I should obtain the ticket code "0000000001" 30 | 31 | And there should be the following ticket at ticket repository: 32 | | code | carPlate | rateName | startingDateTime | endingDateTime | price | 33 | | 0000000001 | 6989JJH | ORANGE_ZONE | 2022/05/11 10:00 | 2022/05/11 12:00 | 1.90 | 34 | 35 | And next available ticket code should be "0000000002" 36 | 37 | And the following pay request should have been done to payment service: 38 | | ticketCode | paymentCard | amount | 39 | | 0000000001 | 5200828282828210 | 1.90 | 40 | 41 | And no PayErrorException should have been thrown 42 | 43 | 44 | Scenario: Generic pay error 45 | 46 | Given there are the following rates at rate repository: 47 | | name | amountPerHour | 48 | | BLUE_ZONE | 0.80 | 49 | 50 | And next available ticket code is "0000000010" 51 | 52 | And there is no ticket with code "0000000010" at ticket repository 53 | 54 | And the payment is not valid 55 | 56 | When I do the following purchase ticket request: 57 | | carPlate | rateName | clock | amount | paymentCard | 58 | | 8149GRH | BLUE_ZONE | 2022/05/12 07:00 | 1.20 | 4000000000000002 | 59 | 60 | Then I should obtain no ticket code 61 | 62 | And there should be no ticket with code "0000000010" at ticket repository 63 | 64 | And next available ticket code should be "0000000011" 65 | 66 | And the following pay request should have been done to payment service: 67 | | ticketCode | paymentCard | amount | 68 | | 0000000010 | 4000000000000002 | 1.20 | 69 | 70 | And a PayErrorException should have been thrown 71 | -------------------------------------------------------------------------------- /src/bluezone-hexagon/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | io.github.jmgarridopaz.bluezone 9 | bluezone-parent 10 | 1.0.0 11 | ../bluezone-parent 12 | 13 | 14 | bluezone-hexagon 15 | 16 | jar 17 | 18 | BlueZone Hexagon 19 | 20 | 21 | 22 | org.projectlombok 23 | lombok 24 | 25 | 26 | io.github.jmgarridopaz.lib.javalangutils 27 | lib-javalangutils 28 | 29 | 30 | 31 | 32 | src/main/bluezone.hexagon 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /src/bluezone-hexagon/src/main/bluezone.hexagon/io/github/jmgarridopaz/bluezone/hexagon/AppConfigurator.java: -------------------------------------------------------------------------------- 1 | package io.github.jmgarridopaz.bluezone.hexagon; 2 | 3 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forobtainingrates.ForObtainingRates; 4 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forobtainingrates.Rate; 5 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forpaying.ForPaying; 6 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forpaying.PayRequest; 7 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forstoringtickets.ForStoringTickets; 8 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forstoringtickets.Ticket; 9 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driving.forconfiguringapp.ForConfiguringApp; 10 | 11 | import java.util.List; 12 | 13 | 14 | public class AppConfigurator implements ForConfiguringApp { 15 | 16 | private final ForObtainingRates rateProvider; 17 | private final ForStoringTickets ticketStore; 18 | private final ForPaying paymentService; 19 | 20 | public AppConfigurator(ForObtainingRates rateProvider, ForStoringTickets ticketStore, ForPaying paymentService) { 21 | this.rateProvider = rateProvider; 22 | this.ticketStore = ticketStore; 23 | this.paymentService = paymentService; 24 | } 25 | 26 | @Override 27 | public void initRateProviderWith(List rates ) { 28 | this.rateProvider.empty(); 29 | for ( Rate rate : rates ) { 30 | if ( ! this.rateProvider.exists(rate.getName()) ) { 31 | this.rateProvider.addRate ( rate ); 32 | } 33 | } 34 | } 35 | 36 | @Override 37 | public void createTicket ( Ticket ticket ) { 38 | if ( ! this.ticketStore.exists(ticket.getCode()) ) { 39 | this.ticketStore.store ( ticket ); 40 | } 41 | } 42 | 43 | @Override 44 | public void eraseTicket ( String ticketCode ) { 45 | if ( this.ticketStore.exists(ticketCode) ) { 46 | this.ticketStore.delete(ticketCode); 47 | } 48 | } 49 | 50 | @Override 51 | public void setNextTicketCodeToReturn(String ticketCode) { 52 | this.ticketStore.setNextCode(ticketCode); 53 | } 54 | 55 | @Override 56 | public String getNextTicketCodeToReturn() { 57 | return this.ticketStore.nextAvailableCode(); 58 | } 59 | 60 | @Override 61 | public PayRequest getLastPayRequestDone() { 62 | return this.paymentService.lastPayRequest(); 63 | } 64 | 65 | @Override 66 | public void setPaymentErrorPercentage(int percent) { 67 | this.paymentService.setPayErrorGenerationPercentage(percent); 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/bluezone-hexagon/src/main/bluezone.hexagon/io/github/jmgarridopaz/bluezone/hexagon/AppFromDrivenSide.java: -------------------------------------------------------------------------------- 1 | package io.github.jmgarridopaz.bluezone.hexagon; 2 | 3 | import io.github.jmgarridopaz.bluezone.hexagon.factory.BlueZoneApp; 4 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forobtainingrates.ForObtainingRates; 5 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forpaying.ForPaying; 6 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forstoringtickets.ForStoringTickets; 7 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driving.forcheckingcars.ForCheckingCars; 8 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driving.forconfiguringapp.ForConfiguringApp; 9 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driving.forparkingcars.ForParkingCars; 10 | 11 | /** 12 | * Application 13 | * Offers driver ports as API. 14 | * Has a configurable dependency on driven ports as RI (required interface). 15 | */ 16 | public class AppFromDrivenSide implements BlueZoneApp { 17 | 18 | // Driver ports 19 | private ForParkingCars carParker; 20 | private ForCheckingCars carChecker; 21 | private ForConfiguringApp appConfigurator; 22 | // Driven ports 23 | private final ForObtainingRates rateProvider; 24 | private final ForStoringTickets ticketStore; 25 | private final ForPaying paymentService; 26 | 27 | public AppFromDrivenSide(ForObtainingRates rateProvider, ForStoringTickets ticketStore, ForPaying paymentService ) { 28 | this.rateProvider = rateProvider; 29 | this.ticketStore = ticketStore; 30 | this.paymentService = paymentService; 31 | } 32 | 33 | @Override 34 | public ForParkingCars carParker() { 35 | if ( this.carParker == null ) { 36 | this.carParker = new CarParker(this.rateProvider, this.ticketStore, this.paymentService); 37 | } 38 | return this.carParker; 39 | } 40 | 41 | @Override 42 | public ForCheckingCars carChecker() { 43 | if ( this.carChecker == null ) { 44 | this.carChecker = new CarChecker(this.ticketStore); 45 | } 46 | return this.carChecker; 47 | } 48 | 49 | @Override 50 | public ForConfiguringApp appConfigurator() { 51 | if ( this.appConfigurator == null ) { 52 | this.appConfigurator = new AppConfigurator(this.rateProvider,this.ticketStore,this.paymentService); 53 | } 54 | return this.appConfigurator; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/bluezone-hexagon/src/main/bluezone.hexagon/io/github/jmgarridopaz/bluezone/hexagon/CarChecker.java: -------------------------------------------------------------------------------- 1 | package io.github.jmgarridopaz.bluezone.hexagon; 2 | 3 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forstoringtickets.ForStoringTickets; 4 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forstoringtickets.Ticket; 5 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driving.forcheckingcars.ForCheckingCars; 6 | 7 | import java.time.Clock; 8 | import java.time.LocalDateTime; 9 | import java.util.List; 10 | 11 | 12 | public class CarChecker implements ForCheckingCars { 13 | 14 | private final ForStoringTickets ticketStore; 15 | 16 | public CarChecker ( ForStoringTickets ticketStore) { 17 | this.ticketStore = ticketStore; 18 | } 19 | 20 | @Override 21 | public boolean illegallyParkedCar(Clock clock, String carPlate, String rateName) { 22 | List ticketsOfCarAndRate = this.ticketStore.findByCarRateOrderByEndingDateTimeDesc ( carPlate, rateName ); 23 | if ( ticketsOfCarAndRate==null || ticketsOfCarAndRate.isEmpty() ) { 24 | return true; 25 | } 26 | LocalDateTime currentDateTime = LocalDateTime.now(clock); 27 | LocalDateTime latestEndingDateTime = ticketsOfCarAndRate.get(0).getEndingDateTime(); 28 | return currentDateTime.isAfter(latestEndingDateTime); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/bluezone-hexagon/src/main/bluezone.hexagon/io/github/jmgarridopaz/bluezone/hexagon/CarParker.java: -------------------------------------------------------------------------------- 1 | package io.github.jmgarridopaz.bluezone.hexagon; 2 | 3 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forobtainingrates.ForObtainingRates; 4 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forobtainingrates.Rate; 5 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forpaying.ForPaying; 6 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forpaying.PayRequest; 7 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forstoringtickets.ForStoringTickets; 8 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forstoringtickets.Ticket; 9 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driving.forparkingcars.ForParkingCars; 10 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driving.forparkingcars.PurchaseTicketRequest; 11 | 12 | import java.math.BigDecimal; 13 | import java.time.Clock; 14 | import java.time.LocalDateTime; 15 | import java.util.*; 16 | 17 | 18 | public class CarParker implements ForParkingCars { 19 | 20 | private final ForObtainingRates rateProvider; 21 | private final ForStoringTickets ticketStore; 22 | private final ForPaying paymentService; 23 | 24 | public CarParker(ForObtainingRates rateProvider, ForStoringTickets ticketStore, ForPaying eWalletService) { 25 | this.rateProvider = rateProvider; 26 | this.ticketStore = ticketStore; 27 | this.paymentService = eWalletService; 28 | } 29 | 30 | @Override 31 | public Map getAllRatesByName() { 32 | Map allRatesByName = new HashMap(); 33 | Set allRates = this.rateProvider.findAll(); 34 | Iterator ratesIterator = allRates.iterator(); 35 | while (ratesIterator.hasNext()) { 36 | Rate rate = ratesIterator.next(); 37 | allRatesByName.put ( rate.getName(), rate ); 38 | } 39 | return allRatesByName; 40 | } 41 | 42 | @Override 43 | public String purchaseTicket ( PurchaseTicketRequest purchaseTicketRequest ) { 44 | // Pay 45 | String ticketCode = this.ticketStore.nextCode(); 46 | String paymentCard = purchaseTicketRequest.getPaymentCard(); 47 | BigDecimal moneyToPay = purchaseTicketRequest.getAmount(); 48 | PayRequest payRequest = new PayRequest ( ticketCode, paymentCard, moneyToPay ); 49 | this.paymentService.pay ( payRequest ); 50 | // Calc ending date-time 51 | String rateName = purchaseTicketRequest.getRateName(); 52 | Rate rate = this.rateProvider.findByName(rateName); 53 | RateCalculator rateCalculator = new RateCalculator(rate); 54 | Clock clock = purchaseTicketRequest.getClock(); 55 | LocalDateTime starting = LocalDateTime.now(clock); 56 | LocalDateTime ending = rateCalculator.getUntilGivenAmount ( starting, moneyToPay ); 57 | // Store 58 | String carPlate = purchaseTicketRequest.getCarPlate(); 59 | Ticket ticket = new Ticket(ticketCode,carPlate,rateName,starting,ending,moneyToPay); 60 | this.ticketStore.store(ticket); 61 | return ticketCode; 62 | } 63 | 64 | @Override 65 | public Ticket getTicket (String ticketCode ) { 66 | return this.ticketStore.findByCode ( ticketCode); 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/bluezone-hexagon/src/main/bluezone.hexagon/io/github/jmgarridopaz/bluezone/hexagon/RateCalculator.java: -------------------------------------------------------------------------------- 1 | package io.github.jmgarridopaz.bluezone.hexagon; 2 | 3 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forobtainingrates.Rate; 4 | 5 | import java.math.BigDecimal; 6 | import java.time.LocalDateTime; 7 | 8 | 9 | public class RateCalculator { 10 | 11 | private final Rate rate; 12 | 13 | public RateCalculator ( Rate rate ) { 14 | this.rate = rate; 15 | } 16 | 17 | public LocalDateTime getUntilGivenAmount ( LocalDateTime from, BigDecimal amount ) { 18 | // minutes = (amount*60)/amountPerHour 19 | int minutes = (int) ((amount.doubleValue()*60.0) / this.rate.getAmountPerHour().doubleValue()); 20 | return from.plusMinutes(minutes); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/bluezone-hexagon/src/main/bluezone.hexagon/io/github/jmgarridopaz/bluezone/hexagon/factory/BlueZoneApp.java: -------------------------------------------------------------------------------- 1 | package io.github.jmgarridopaz.bluezone.hexagon.factory; 2 | 3 | import io.github.jmgarridopaz.bluezone.hexagon.AppFromDrivenSide; 4 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forobtainingrates.ForObtainingRates; 5 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forpaying.ForPaying; 6 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forstoringtickets.ForStoringTickets; 7 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driving.forcheckingcars.ForCheckingCars; 8 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driving.forconfiguringapp.ForConfiguringApp; 9 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driving.forparkingcars.ForParkingCars; 10 | 11 | /** 12 | * API 13 | * Driver ports 14 | */ 15 | public interface BlueZoneApp { 16 | 17 | public static BlueZoneApp getInstance (ForObtainingRates rateProvider, ForStoringTickets ticketStore, ForPaying paymentService ) { 18 | return new AppFromDrivenSide(rateProvider,ticketStore,paymentService); 19 | } 20 | public ForParkingCars carParker(); 21 | public ForCheckingCars carChecker(); 22 | public ForConfiguringApp appConfigurator(); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/bluezone-hexagon/src/main/bluezone.hexagon/io/github/jmgarridopaz/bluezone/hexagon/ports/driven/forobtainingrates/ForObtainingRates.java: -------------------------------------------------------------------------------- 1 | package io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forobtainingrates; 2 | 3 | import java.util.Set; 4 | 5 | /** 6 | * DRIVEN PORT 7 | */ 8 | public interface ForObtainingRates { 9 | 10 | public Set findAll(); 11 | 12 | public Rate findByName (String rateName ); 13 | 14 | public void addRate ( Rate rate ); 15 | 16 | public boolean exists ( String rateName ); 17 | 18 | public void empty(); 19 | } 20 | -------------------------------------------------------------------------------- /src/bluezone-hexagon/src/main/bluezone.hexagon/io/github/jmgarridopaz/bluezone/hexagon/ports/driven/forobtainingrates/Rate.java: -------------------------------------------------------------------------------- 1 | package io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forobtainingrates; 2 | 3 | import java.math.BigDecimal; 4 | import lombok.*; 5 | 6 | /** 7 | * DTO with data of a rate: 8 | * name Rate name. Unique. Two uppercase words separated by _ 9 | * amountPerHour Cost in euros of parking the car during one hour 10 | */ 11 | @NoArgsConstructor 12 | @AllArgsConstructor 13 | @Getter 14 | @Setter 15 | @EqualsAndHashCode 16 | public class Rate { 17 | 18 | private String name; 19 | private BigDecimal amountPerHour; 20 | 21 | 22 | 23 | 24 | @Override 25 | public String toString() { 26 | return this.name + " ( " + this.amountPerHour + "€ / hour )"; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/bluezone-hexagon/src/main/bluezone.hexagon/io/github/jmgarridopaz/bluezone/hexagon/ports/driven/forpaying/ForPaying.java: -------------------------------------------------------------------------------- 1 | package io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forpaying; 2 | 3 | /** 4 | * DRIVEN PORT 5 | */ 6 | public interface ForPaying { 7 | 8 | public void pay ( PayRequest payRequest ) throws PayErrorException; 9 | 10 | public PayRequest lastPayRequest(); 11 | 12 | public void setPayErrorGenerationPercentage(int percent); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/bluezone-hexagon/src/main/bluezone.hexagon/io/github/jmgarridopaz/bluezone/hexagon/ports/driven/forpaying/PayErrorException.java: -------------------------------------------------------------------------------- 1 | package io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forpaying; 2 | 3 | /** 4 | * Exception thrown by the pay method in the "for paying" port, 5 | * when it has been any error and the payment didn't take place. 6 | */ 7 | public class PayErrorException extends RuntimeException { 8 | 9 | public PayErrorException ( String errorMessage ) { 10 | super(errorMessage); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/bluezone-hexagon/src/main/bluezone.hexagon/io/github/jmgarridopaz/bluezone/hexagon/ports/driven/forpaying/PayRequest.java: -------------------------------------------------------------------------------- 1 | package io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forpaying; 2 | 3 | import lombok.*; 4 | import java.math.BigDecimal; 5 | 6 | 7 | @NoArgsConstructor 8 | @AllArgsConstructor 9 | @Getter 10 | @Setter 11 | @EqualsAndHashCode 12 | @ToString 13 | public class PayRequest { 14 | 15 | private String ticketCode; 16 | private String paymentCard; 17 | private BigDecimal amount; 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/bluezone-hexagon/src/main/bluezone.hexagon/io/github/jmgarridopaz/bluezone/hexagon/ports/driven/forstoringtickets/ForStoringTickets.java: -------------------------------------------------------------------------------- 1 | package io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forstoringtickets; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * DRIVEN PORT 7 | */ 8 | public interface ForStoringTickets { 9 | 10 | public String nextCode(); 11 | 12 | public Ticket findByCode ( String ticketCode ); 13 | 14 | public void store ( Ticket ticket ); 15 | 16 | public List findByCarRateOrderByEndingDateTimeDesc(String carPlate, String rateName); 17 | 18 | public void delete ( String ticketCode ); 19 | 20 | public boolean exists ( String ticketCode ); 21 | 22 | public void setNextCode ( String ticketCode ); 23 | 24 | public String nextAvailableCode(); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/bluezone-hexagon/src/main/bluezone.hexagon/io/github/jmgarridopaz/bluezone/hexagon/ports/driven/forstoringtickets/Ticket.java: -------------------------------------------------------------------------------- 1 | package io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forstoringtickets; 2 | 3 | import java.math.BigDecimal; 4 | import java.time.LocalDateTime; 5 | import lombok.*; 6 | 7 | /** 8 | * DTO with the data of a parking ticket: 9 | * code Unique identifier of the ticket 10 | * carPlate Plate of the car that has been parked 11 | * rateName Rate name of the zone where the car is parked at 12 | * startingDateTime When the parking period begins 13 | * endingDateTime When the parking period expires 14 | * price Amount of money paid for the ticket 15 | * paymentId Id of the ticket purchasing transaction in the payment service 16 | */ 17 | @NoArgsConstructor 18 | @AllArgsConstructor 19 | @Getter 20 | @Setter 21 | @EqualsAndHashCode 22 | @ToString 23 | public class Ticket { 24 | 25 | private String code; 26 | private String carPlate; 27 | private String rateName; 28 | private LocalDateTime startingDateTime; 29 | private LocalDateTime endingDateTime; 30 | private BigDecimal price; 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/bluezone-hexagon/src/main/bluezone.hexagon/io/github/jmgarridopaz/bluezone/hexagon/ports/driving/forcheckingcars/ForCheckingCars.java: -------------------------------------------------------------------------------- 1 | package io.github.jmgarridopaz.bluezone.hexagon.ports.driving.forcheckingcars; 2 | 3 | import java.time.Clock; 4 | 5 | /** 6 | * DRIVER PORT 7 | */ 8 | public interface ForCheckingCars { 9 | 10 | /** 11 | * A car is illegally parked at a zone, if the car does not have any valid ticket for the zone rate at the current date-time. 12 | * A ticket is valid if the given date-time is between the starting and ending date-time of the ticket. 13 | * 14 | * @param clock Clock to get current date-time from 15 | * @param carPlate Plate of the car that we want to check 16 | * @param rateName Rate name of the zone where the car to check is parked at 17 | * @return "true" if the car has no valid ticket for the rate at current date-time, 18 | * "false" otherwise. 19 | */ 20 | public boolean illegallyParkedCar ( Clock clock, String carPlate, String rateName ); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/bluezone-hexagon/src/main/bluezone.hexagon/io/github/jmgarridopaz/bluezone/hexagon/ports/driving/forconfiguringapp/ForConfiguringApp.java: -------------------------------------------------------------------------------- 1 | package io.github.jmgarridopaz.bluezone.hexagon.ports.driving.forconfiguringapp; 2 | 3 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forobtainingrates.Rate; 4 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forpaying.PayRequest; 5 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forstoringtickets.Ticket; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * DRIVER PORT 11 | */ 12 | public interface ForConfiguringApp { 13 | 14 | public void initRateProviderWith(List rates ); 15 | 16 | public void createTicket ( Ticket ticket ); 17 | 18 | public void eraseTicket ( String ticketCode ); 19 | 20 | public void setNextTicketCodeToReturn ( String ticketCode ); 21 | 22 | public String getNextTicketCodeToReturn(); 23 | 24 | public PayRequest getLastPayRequestDone(); 25 | 26 | public void setPaymentErrorPercentage(int percent); 27 | } 28 | -------------------------------------------------------------------------------- /src/bluezone-hexagon/src/main/bluezone.hexagon/io/github/jmgarridopaz/bluezone/hexagon/ports/driving/forparkingcars/ForParkingCars.java: -------------------------------------------------------------------------------- 1 | package io.github.jmgarridopaz.bluezone.hexagon.ports.driving.forparkingcars; 2 | 3 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forobtainingrates.Rate; 4 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forpaying.PayErrorException; 5 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forstoringtickets.Ticket; 6 | 7 | import java.util.Map; 8 | 9 | /** 10 | * DRIVER PORT 11 | */ 12 | public interface ForParkingCars { 13 | 14 | /** 15 | * Returns the available rates in the city, indexed by name. 16 | * 17 | * @return a map of Rate objects, with the rate name as the key. 18 | * @see Rate 19 | */ 20 | public Map getAllRatesByName(); 21 | 22 | 23 | /** 24 | * It pays for a parking ticket, which will be valid for the following period of time: 25 | * - Starting: Current date-time. 26 | * - Ending: Date-time calculated from the payment amount, according to the rate of the zone the car is parked at. 27 | * The payment is done by charging the amount to the card given in the purchase ticket request. 28 | * 29 | * @param purchaseTicketRequest Data needed for purchasing a parking ticket. 30 | * @return The code of the purchased ticket, useful for retrieving the whole ticket data later on. 31 | * @throws PayErrorException 32 | * When any error occur paying the amount with the card. 33 | * @see PurchaseTicketRequest 34 | * @see Ticket 35 | * @see PayErrorException 36 | */ 37 | public String purchaseTicket ( PurchaseTicketRequest purchaseTicketRequest ) throws PayErrorException; 38 | 39 | 40 | /** 41 | * Given the code of a previously purchased ticket, returns the whole data of the ticket. 42 | * 43 | * @param ticketCode Code of a purchased ticket. 44 | * @return The ticket with the given ticket code, 45 | * or null if it doesn't exist any ticket with such a code. 46 | */ 47 | public Ticket getTicket (String ticketCode ); 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/bluezone-hexagon/src/main/bluezone.hexagon/io/github/jmgarridopaz/bluezone/hexagon/ports/driving/forparkingcars/PurchaseTicketRequest.java: -------------------------------------------------------------------------------- 1 | package io.github.jmgarridopaz.bluezone.hexagon.ports.driving.forparkingcars; 2 | 3 | import java.math.BigDecimal; 4 | import java.time.Clock; 5 | import lombok.*; 6 | 7 | /** 8 | * DTO with the data needed for purchasing a parking ticket: 9 | * carPlate Plate of the car to be parked 10 | * rateName Rate name of the zone where the car will be parked at 11 | * clock A clock to get current date-time from, since it will be the starting date-time of the ticket period 12 | * amount Money (euros) to be paid for the parking ticket 13 | * paymentCard Number of the card where the amount will be charged 14 | */ 15 | @NoArgsConstructor 16 | @AllArgsConstructor 17 | @Getter 18 | @Setter 19 | @EqualsAndHashCode 20 | @ToString 21 | public class PurchaseTicketRequest { 22 | 23 | private String carPlate; 24 | private String rateName; 25 | private Clock clock; 26 | private BigDecimal amount; 27 | private String paymentCard; 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/bluezone-hexagon/src/main/bluezone.hexagon/module-info.java: -------------------------------------------------------------------------------- 1 | 2 | module bluezone.hexagon { 3 | 4 | // DEPENDS ON 5 | // a tool to avoid boilerplate code writing 6 | requires static lombok; 7 | // utils of Java language 8 | requires io.github.jmgarridopaz.lib.javalangutils; 9 | 10 | // PUBLISHES 11 | // driving ports 12 | exports io.github.jmgarridopaz.bluezone.hexagon.ports.driving.forparkingcars; 13 | exports io.github.jmgarridopaz.bluezone.hexagon.ports.driving.forcheckingcars; 14 | exports io.github.jmgarridopaz.bluezone.hexagon.ports.driving.forconfiguringapp; 15 | // driven ports 16 | exports io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forobtainingrates; 17 | exports io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forstoringtickets; 18 | exports io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forpaying; 19 | 20 | exports io.github.jmgarridopaz.bluezone.hexagon.factory; 21 | } 22 | -------------------------------------------------------------------------------- /src/bluezone-parent/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 4.0.0 7 | 8 | 9 | io.github.jmgarridopaz.bluezone 10 | bluezone-parent 11 | 1.0.0 12 | 13 | pom 14 | 15 | BlueZone Parent Project 16 | 17 | 18 | 19 | UTF-8 20 | ${project.encoding} 21 | ${project.encoding} 22 | 23 | 11 24 | 25 | 3.8.1 26 | 27 | 1.0.0 28 | 1.0.0 29 | 1.0.0 30 | 1.0.0 31 | 1.0.0 32 | 1.0.0 33 | 1.0.0 34 | 35 | 1.1.0 36 | 1.1.0 37 | 1.18.20 38 | 2.7.1 39 | 40 | 41 | 42 | 43 | 44 | 45 | org.springframework.boot 46 | spring-boot-dependencies 47 | ${spring.boot.version} 48 | pom 49 | import 50 | 51 | 52 | 53 | io.github.jmgarridopaz.lib.javalangutils 54 | lib-javalangutils 55 | ${lib.javalangutils.version} 56 | 57 | 58 | 59 | io.github.jmgarridopaz.lib.portsadapters 60 | lib-portsadapters 61 | ${lib.portsadapters.version} 62 | 63 | 64 | org.projectlombok 65 | lombok 66 | ${lombok.version} 67 | provided 68 | 69 | 70 | 71 | io.github.jmgarridopaz.bluezone 72 | bluezone-hexagon 73 | ${bluezone.hexagon.version} 74 | 75 | 76 | io.github.jmgarridopaz.bluezone 77 | bluezone-driver-forparkingcars-test 78 | ${bluezone.driver.forparkingcars.test.version} 79 | 80 | 81 | io.github.jmgarridopaz.bluezone 82 | bluezone-adapter-forparkingcars-webui 83 | ${bluezone.adapter.forparkingcars.webui.version} 84 | 85 | 86 | io.github.jmgarridopaz.bluezone 87 | bluezone-driver-forcheckingcars-test 88 | ${bluezone.driver.forcheckingcars.test.version} 89 | 90 | 91 | io.github.jmgarridopaz.bluezone 92 | bluezone-adapter-forobtainingrates-stub 93 | ${bluezone.adapter.forobtainingrates.stub.version} 94 | 95 | 96 | io.github.jmgarridopaz.bluezone 97 | bluezone-adapter-forstoringtickets-fake 98 | ${bluezone.adapter.forstoringtickets.fake.version} 99 | 100 | 101 | io.github.jmgarridopaz.bluezone 102 | bluezone-adapter-forpaying-spy 103 | ${bluezone.adapter.forpaying.spy.version} 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | org.apache.maven.plugins 113 | maven-compiler-plugin 114 | ${mavenCompilerPlugin.version} 115 | 116 | ${java.version} 117 | ${java.version} 118 | ${project.build.sourceEncoding} 119 | false 120 | true 121 | true 122 | true 123 | 124 | 125 | org.projectlombok 126 | lombok 127 | ${lombok.version} 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | github-repo 139 | Github Repository 140 | https://raw.githubusercontent.com/jmgarridopaz/jmgarridopaz.github.io/mavenrepo/ 141 | default 142 | 143 | true 144 | always 145 | fail 146 | 147 | 148 | true 149 | always 150 | fail 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | local-repo 159 | Local Repository 160 | file://${project.build.directory}/localrepo 161 | default 162 | false 163 | 164 | 165 | 166 | 167 | -------------------------------------------------------------------------------- /src/bluezone-startup/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | io.github.jmgarridopaz.bluezone 9 | bluezone-parent 10 | 1.0.0 11 | ../bluezone-parent 12 | 13 | 14 | bluezone-startup 15 | 16 | jar 17 | 18 | BlueZone Startup 19 | 20 | 21 | 3.1.1 22 | ${project.build.directory}/bzmodulepath 23 | 24 | 25 | 26 | 27 | io.github.jmgarridopaz.lib.javalangutils 28 | lib-javalangutils 29 | 30 | 31 | io.github.jmgarridopaz.bluezone 32 | bluezone-hexagon 33 | 34 | 35 | io.github.jmgarridopaz.bluezone 36 | bluezone-driver-forparkingcars-test 37 | 38 | 39 | io.github.jmgarridopaz.bluezone 40 | bluezone-adapter-forparkingcars-webui 41 | 42 | 43 | io.github.jmgarridopaz.bluezone 44 | bluezone-driver-forcheckingcars-test 45 | 46 | 47 | io.github.jmgarridopaz.bluezone 48 | bluezone-adapter-forobtainingrates-stub 49 | 50 | 51 | io.github.jmgarridopaz.bluezone 52 | bluezone-adapter-forstoringtickets-fake 53 | 54 | 55 | io.github.jmgarridopaz.bluezone 56 | bluezone-adapter-forpaying-spy 57 | 58 | 59 | 60 | 61 | src/main/bluezone.startup 62 | 63 | 64 | org.apache.maven.plugins 65 | maven-dependency-plugin 66 | ${mavenDependencyPlugin.version} 67 | 68 | 69 | 73 | copy-to-modulepath 74 | verify 75 | 76 | copy-dependencies 77 | 78 | 79 | ${bluezone.mp} 80 | false 81 | false 82 | true 83 | false 84 | aopalliance 85 | 86 | 87 | 91 | 92 | copy-startup-to-modulepath 93 | verify 94 | 95 | copy 96 | 97 | 98 | 99 | 100 | ${bluezone.mp} 101 | ${project.groupId} 102 | ${project.artifactId} 103 | ${project.version} 104 | jar 105 | true 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | -------------------------------------------------------------------------------- /src/bluezone-startup/src/main/bluezone.startup/io/github/jmgarridopaz/bluezone/startup/AdapterSelector.java: -------------------------------------------------------------------------------- 1 | package io.github.jmgarridopaz.bluezone.startup; 2 | 3 | import io.github.jmgarridopaz.lib.javalangutils.FileUtils; 4 | import java.nio.file.Paths; 5 | import java.util.Properties; 6 | 7 | 8 | public class AdapterSelector { 9 | 10 | public static final String TEST_CASES = "test-cases"; 11 | public static final String WEB_UI = "web-ui"; 12 | 13 | private final Properties adaptersToSelect; 14 | 15 | private AdapterSelector(Properties adaptersToSelect) { 16 | this.adaptersToSelect = adaptersToSelect; 17 | } 18 | 19 | public static AdapterSelector fromFile ( String fileWithPath ) { 20 | Properties adaptersToSelectForPorts = FileUtils.propertiesFromFile ( Paths.get(fileWithPath) ); 21 | return new AdapterSelector ( adaptersToSelectForPorts ); 22 | } 23 | 24 | public String adapterNameForPort(Class portType) { 25 | return adaptersToSelect.getProperty(portType.getSimpleName()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/bluezone-startup/src/main/bluezone.startup/io/github/jmgarridopaz/bluezone/startup/BlueZoneInitializer.java: -------------------------------------------------------------------------------- 1 | package io.github.jmgarridopaz.bluezone.startup; 2 | 3 | import io.github.jmgarridopaz.bluezone.hexagon.factory.BlueZoneApp; 4 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forobtainingrates.Rate; 5 | import java.math.BigDecimal; 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | 10 | public class BlueZoneInitializer { 11 | 12 | public static void init(BlueZoneApp eParkingMeter) { 13 | // rate provider 14 | List initialRates = new ArrayList(); 15 | initialRates.add(new Rate("BLUE_ZONE", new BigDecimal("0.80"))); 16 | initialRates.add(new Rate("ORANGE_ZONE", new BigDecimal("0.95"))); 17 | initialRates.add(new Rate("GREEN_ZONE", new BigDecimal("1.20"))); 18 | eParkingMeter.appConfigurator().initRateProviderWith(initialRates); 19 | // payment service 20 | eParkingMeter.appConfigurator().setPaymentErrorPercentage(10); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/bluezone-startup/src/main/bluezone.startup/io/github/jmgarridopaz/bluezone/startup/BlueZoneRunner.java: -------------------------------------------------------------------------------- 1 | package io.github.jmgarridopaz.bluezone.startup; 2 | 3 | import io.github.jmgarridopaz.bluezone.hexagon.factory.BlueZoneApp; 4 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forobtainingrates.ForObtainingRates; 5 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forpaying.ForPaying; 6 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forstoringtickets.ForStoringTickets; 7 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driving.forcheckingcars.ForCheckingCars; 8 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driving.forparkingcars.ForParkingCars; 9 | import io.github.jmgarridopaz.lib.javalangutils.StringUtils; 10 | import io.github.jmgarridopaz.lib.portsadapters.Driver; 11 | 12 | /** 13 | * Entry point to the application. 14 | * It selects and plugs-in an adapter on every port. 15 | * It runs the drivers. 16 | */ 17 | public class BlueZoneRunner { 18 | 19 | public static void main ( String[] args ) { 20 | // Check args 21 | if ( args==null || args.length!=1 || StringUtils.isBlank(args[0]) ) { 22 | System.out.println("Wrong arguments. Usage: "+BlueZoneRunner.class.getSimpleName()+" path_to_file_with_ports_adapters"); 23 | return; 24 | } 25 | // Dependency configurator with adapters to select 26 | AdapterSelector adapterSelector = AdapterSelector.fromFile(args[0]); 27 | DependencyConfigurator dependencyConfigurator = new DependencyConfigurator(adapterSelector); 28 | 29 | // driven side 30 | ForObtainingRates rateProvider = dependencyConfigurator.lookupDrivenPort(ForObtainingRates.class); 31 | ForStoringTickets ticketStore = dependencyConfigurator.lookupDrivenPort(ForStoringTickets.class); 32 | ForPaying paymentService = dependencyConfigurator.lookupDrivenPort(ForPaying.class); 33 | 34 | // application 35 | BlueZoneApp eParkingMeter = dependencyConfigurator.buildApplication(rateProvider, ticketStore, paymentService); 36 | 37 | // init application 38 | BlueZoneInitializer.init ( eParkingMeter ); 39 | 40 | // driver side 41 | Driver forCheckingCarsDriver = dependencyConfigurator.lookupDriver ( ForCheckingCars.class, eParkingMeter ); 42 | forCheckingCarsDriver.run(); 43 | Driver forParkingCarsDriver = dependencyConfigurator.lookupDriver ( ForParkingCars.class, eParkingMeter ); 44 | forParkingCarsDriver.run(); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/bluezone-startup/src/main/bluezone.startup/io/github/jmgarridopaz/bluezone/startup/DependencyConfigurator.java: -------------------------------------------------------------------------------- 1 | package io.github.jmgarridopaz.bluezone.startup; 2 | 3 | import io.github.jmgarridopaz.bluezone.adapter.forparkingcars.webui.ForParkingCarsWebUIDriver; 4 | import io.github.jmgarridopaz.bluezone.driver.forcheckingcars.test.ForCheckingCarsTestDriver; 5 | import io.github.jmgarridopaz.bluezone.driver.forparkingcars.test.ForParkingCarsTestDriver; 6 | import io.github.jmgarridopaz.bluezone.hexagon.factory.BlueZoneApp; 7 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forobtainingrates.ForObtainingRates; 8 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forpaying.ForPaying; 9 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forstoringtickets.ForStoringTickets; 10 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driving.forcheckingcars.ForCheckingCars; 11 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driving.forparkingcars.ForParkingCars; 12 | import io.github.jmgarridopaz.lib.javalangutils.StringUtils; 13 | import io.github.jmgarridopaz.lib.portsadapters.Adapter; 14 | import io.github.jmgarridopaz.lib.portsadapters.Driver; 15 | import java.util.List; 16 | import java.util.ServiceLoader; 17 | import java.util.ServiceLoader.Provider; 18 | import java.util.stream.Collectors; 19 | 20 | 21 | public class DependencyConfigurator { 22 | 23 | private final AdapterSelector adapterSelector; 24 | 25 | public DependencyConfigurator (AdapterSelector adapterSelector ) { 26 | this.adapterSelector = adapterSelector; 27 | } 28 | 29 | 30 | public T lookupDrivenPort ( Class drivenPortType ) { 31 | String adapterName = adapterSelector.adapterNameForPort(drivenPortType); 32 | if (StringUtils.isBlank(adapterName)) { 33 | return null; 34 | } 35 | List> adapters = ServiceLoader.load(drivenPortType).stream().filter(p -> isDrivenAdapterOfName(p.type(), adapterName)).collect(Collectors.toList()); 36 | if (adapters == null || adapters.isEmpty()) { 37 | throw new RuntimeException("No adapter with name '" + adapterName + "' found for driven port '" + drivenPortType.getSimpleName() + "'"); 38 | } 39 | if (adapters.size() > 1) { 40 | throw new RuntimeException("Many adapters with name '" + adapterName + "' found for driven port '" + drivenPortType.getSimpleName() + "'"); 41 | } 42 | return adapters.get(0).get(); 43 | } 44 | 45 | private static boolean isDrivenAdapterOfName(Class adapterType, String adapterName) { 46 | Adapter adapterAnnotation = adapterType.getAnnotation(Adapter.class); 47 | if ((adapterAnnotation == null) || (adapterAnnotation.name() == null)) { 48 | return false; 49 | } 50 | return StringUtils.equalsIgnoreCaseTrimmed ( adapterAnnotation.name(), adapterName ); 51 | } 52 | 53 | public BlueZoneApp buildApplication(ForObtainingRates rateProvider, ForStoringTickets ticketStore, ForPaying paymentService) { 54 | return BlueZoneApp.getInstance(rateProvider,ticketStore,paymentService); 55 | } 56 | 57 | public Driver lookupDriver ( Class driverPortType, BlueZoneApp blueZoneApp ) { 58 | String adapterName = adapterSelector.adapterNameForPort(driverPortType); 59 | if (driverPortType.getSimpleName().equals(ForParkingCars.class.getSimpleName())) { 60 | if (AdapterSelector.TEST_CASES.equals(adapterName)) { 61 | return new ForParkingCarsTestDriver(blueZoneApp.carParker(), blueZoneApp.appConfigurator()); 62 | } 63 | if (AdapterSelector.WEB_UI.equals(adapterName)) { 64 | return new ForParkingCarsWebUIDriver(blueZoneApp.carParker()); 65 | } 66 | throw new RuntimeException("No driver with name '" + adapterName + "' found for driver port '" + driverPortType.getSimpleName() + "'"); 67 | } 68 | if (driverPortType.getSimpleName().equals(ForCheckingCars.class.getSimpleName())) { 69 | if (AdapterSelector.TEST_CASES.equals(adapterName)) { 70 | return new ForCheckingCarsTestDriver(blueZoneApp.carChecker(), blueZoneApp.appConfigurator()); 71 | } 72 | throw new RuntimeException("No driver with name '" + adapterName + "' found for driver port '" + driverPortType.getSimpleName() + "'"); 73 | } 74 | throw new RuntimeException("No driver found for driver port '" + driverPortType.getSimpleName() + "'"); 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /src/bluezone-startup/src/main/bluezone.startup/module-info.java: -------------------------------------------------------------------------------- 1 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forobtainingrates.ForObtainingRates; 2 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forpaying.ForPaying; 3 | import io.github.jmgarridopaz.bluezone.hexagon.ports.driven.forstoringtickets.ForStoringTickets; 4 | 5 | module bluezone.startup { 6 | 7 | // DEPENDS ON 8 | // all the other modules 9 | requires bluezone.hexagon; 10 | requires bluezone.driver.forparkingcars.test; 11 | requires bluezone.driver.forcheckingcars.test; 12 | requires bluezone.adapter.forparkingcars.webui; 13 | requires bluezone.adapter.forobtainingrates.stub; 14 | requires bluezone.adapter.forstoringtickets.fake; 15 | requires bluezone.adapter.forpaying.spy; 16 | requires io.github.jmgarridopaz.lib.portsadapters; 17 | requires io.github.jmgarridopaz.lib.javalangutils; 18 | 19 | // SERVICES 20 | uses ForObtainingRates; 21 | uses ForStoringTickets; 22 | uses ForPaying; 23 | 24 | } 25 | --------------------------------------------------------------------------------