From fb8b0f91d2cea127dcbedcafd37e72405736fac2 Mon Sep 17 00:00:00 2001 From: Dmitrii Naumenko Date: Thu, 9 Jan 2025 16:45:53 +0100 Subject: [PATCH 1/2] [internal] fix attaching sources for intellij test classes and plugins, update sbt-idea-plugin with related fix --- build.sbt | 2 ++ project/plugins.sbt | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index 32521b64c79..5e656381b51 100644 --- a/build.sbt +++ b/build.sbt @@ -37,6 +37,8 @@ ThisBuild / libraryDependencySchemes += "org.scala-lang.modules" %% "scala-xml" (Global / scalacOptions) := globalScalacOptions +Global / intellijAttachSources := true + // Muted lint warnings for keys used by the IDE, but not by sbt (coming from sbt-ide-settings) Global / excludeLintKeys ++= Set(idePackagePrefix, ideSkipProject, ideExcludedDirectories, ideaConfigOptions) diff --git a/project/plugins.sbt b/project/plugins.sbt index 2dff5dce2de..a4c4825c5f8 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -2,7 +2,7 @@ ThisBuild / libraryDependencySchemes += "org.scala-lang.modules" %% "scala-xml" //NOTE: KEEP VERSIONS IN SYNC WITH ultimate/project/plugins.sbt addSbtPlugin("org.jetbrains.scala" % "sbt-ide-settings" % "1.1.2") -addSbtPlugin("org.jetbrains" % "sbt-idea-plugin" % "4.0.2") +addSbtPlugin("org.jetbrains" % "sbt-idea-plugin" % "4.0.3") addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.11.0") addSbtPlugin("org.jetbrains.scala" % "sbt-kotlin-plugin" % "3.1.4") addSbtPlugin("com.github.sbt.junit" % "sbt-jupiter-interface" % "0.13.3") From 5e65f5b0b6242ea9c67facb76c75f7b61b2e2290 Mon Sep 17 00:00:00 2001 From: Dmitrii Naumenko Date: Thu, 9 Jan 2025 14:14:59 +0100 Subject: [PATCH 2/2] [tests] replace ScalaPetStoreTest (local) with ScalaPetStoreProjectHighlightingTest (github-based) Use the latest project from https://github.com/pauljamescleary/scala-pet-store. The locally-stored project was pretty old and had issues with importing so the test failed frequently on TC (and locally) --- ...ScalaPetStoreProjectHighlightingTest.scala | 12 ++ .../local/ScalaPetStoreTest.scala | 11 - .../local/scala-pet-store/.gitignore | 8 - .../local/scala-pet-store/.scalafmt.conf | 13 -- .../local/scala-pet-store/.travis.yml | 18 -- .../local/scala-pet-store/LICENSE | 201 ------------------ .../local/scala-pet-store/README.md | 85 -------- .../local/scala-pet-store/build.sbt | 93 -------- .../local/scala-pet-store/build.sh | 52 ----- .../functional_test/bootstrap.sh | 14 -- .../functional_test/live_tests/conftest.py | 28 --- .../functional_test/live_tests/orders_test.py | 18 -- .../functional_test/live_tests/pets_test.py | 98 --------- .../functional_test/pet_store_client.py | 112 ---------- .../functional_test/pytest.ini | 3 - .../functional_test/requirements.txt | 11 - .../scala-pet-store/functional_test/run.py | 26 --- .../local/scala-pet-store/pet.json | 8 - .../local/scala-pet-store/post-pet.sh | 15 -- .../scala-pet-store/project/build.properties | 1 - .../local/scala-pet-store/project/plugins.sbt | 13 -- .../db/migration/V1__InitialDatabaseSetup.sql | 17 -- .../src/main/resources/logback.xml | 16 -- .../src/main/resources/reference.conf | 8 - .../pauljamescleary/petstore/Server.scala | 40 ---- .../petstore/config/DatabaseConfig.scala | 32 --- .../petstore/config/PetStoreConfig.scala | 21 -- .../petstore/endpoint/OrderEndpoints.scala | 49 ----- .../petstore/endpoint/PetEndpoints.scala | 150 ------------- .../petstore/model/Order.scala | 11 - .../petstore/model/OrderStatus.scala | 20 -- .../pauljamescleary/petstore/model/Pet.scala | 11 - .../petstore/model/PetStatus.scala | 20 -- .../DoobieOrderRepositoryInterpreter.scala | 55 ----- .../DoobiePetRepositoryInterpreter.scala | 84 -------- .../repository/OrderRepositoryAlgebra.scala | 14 -- .../OrderRepositoryInMemoryInterpreter.scala | 35 --- .../repository/PetRepositoryAlgebra.scala | 23 -- .../PetRepositoryInMemoryInterpreter.scala | 47 ---- .../petstore/service/OrderService.scala | 17 -- .../petstore/service/PetService.scala | 63 ------ .../validation/PetValidationAlgebra.scala | 19 -- .../validation/PetValidationInterpreter.scala | 42 ---- .../petstore/Arbitraries.scala | 53 ----- .../petstore/endpoint/OrderEndointsSpec.scala | 51 ----- .../petstore/endpoint/PetEndpointsSpec.scala | 82 ------- 46 files changed, 12 insertions(+), 1808 deletions(-) create mode 100644 sbt/sbt-impl/test/org/jetbrains/plugins/scala/projectHighlighting/downloaded/ScalaPetStoreProjectHighlightingTest.scala delete mode 100644 sbt/sbt-impl/test/org/jetbrains/plugins/scala/projectHighlighting/local/ScalaPetStoreTest.scala delete mode 100644 scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/.gitignore delete mode 100644 scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/.scalafmt.conf delete mode 100644 scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/.travis.yml delete mode 100644 scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/LICENSE delete mode 100644 scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/README.md delete mode 100644 scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/build.sbt delete mode 100644 scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/build.sh delete mode 100644 scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/functional_test/bootstrap.sh delete mode 100644 scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/functional_test/live_tests/conftest.py delete mode 100644 scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/functional_test/live_tests/orders_test.py delete mode 100644 scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/functional_test/live_tests/pets_test.py delete mode 100644 scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/functional_test/pet_store_client.py delete mode 100644 scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/functional_test/pytest.ini delete mode 100644 scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/functional_test/requirements.txt delete mode 100644 scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/functional_test/run.py delete mode 100644 scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/pet.json delete mode 100644 scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/post-pet.sh delete mode 100644 scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/project/build.properties delete mode 100644 scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/project/plugins.sbt delete mode 100644 scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/resources/db/migration/V1__InitialDatabaseSetup.sql delete mode 100644 scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/resources/logback.xml delete mode 100644 scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/resources/reference.conf delete mode 100644 scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/Server.scala delete mode 100644 scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/config/DatabaseConfig.scala delete mode 100644 scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/config/PetStoreConfig.scala delete mode 100644 scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/endpoint/OrderEndpoints.scala delete mode 100644 scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/endpoint/PetEndpoints.scala delete mode 100644 scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/model/Order.scala delete mode 100644 scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/model/OrderStatus.scala delete mode 100644 scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/model/Pet.scala delete mode 100644 scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/model/PetStatus.scala delete mode 100644 scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/repository/DoobieOrderRepositoryInterpreter.scala delete mode 100644 scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/repository/DoobiePetRepositoryInterpreter.scala delete mode 100644 scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/repository/OrderRepositoryAlgebra.scala delete mode 100644 scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/repository/OrderRepositoryInMemoryInterpreter.scala delete mode 100644 scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/repository/PetRepositoryAlgebra.scala delete mode 100644 scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/repository/PetRepositoryInMemoryInterpreter.scala delete mode 100644 scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/service/OrderService.scala delete mode 100644 scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/service/PetService.scala delete mode 100644 scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/validation/PetValidationAlgebra.scala delete mode 100644 scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/validation/PetValidationInterpreter.scala delete mode 100644 scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/test/scala/io/github/pauljamescleary/petstore/Arbitraries.scala delete mode 100644 scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/test/scala/io/github/pauljamescleary/petstore/endpoint/OrderEndointsSpec.scala delete mode 100644 scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/test/scala/io/github/pauljamescleary/petstore/endpoint/PetEndpointsSpec.scala diff --git a/sbt/sbt-impl/test/org/jetbrains/plugins/scala/projectHighlighting/downloaded/ScalaPetStoreProjectHighlightingTest.scala b/sbt/sbt-impl/test/org/jetbrains/plugins/scala/projectHighlighting/downloaded/ScalaPetStoreProjectHighlightingTest.scala new file mode 100644 index 00000000000..ce9368b3122 --- /dev/null +++ b/sbt/sbt-impl/test/org/jetbrains/plugins/scala/projectHighlighting/downloaded/ScalaPetStoreProjectHighlightingTest.scala @@ -0,0 +1,12 @@ +package org.jetbrains.plugins.scala.projectHighlighting.downloaded + +import com.intellij.pom.java.LanguageLevel +import org.jetbrains.plugins.scala.projectHighlighting.base.{GithubRepositoryWithRevision, SbtProjectHighlightingLocalProjectsTestBase} + +class ScalaPetStoreProjectHighlightingTest extends GithubSbtAllProjectHighlightingTest { + + override def projectJdkLanguageLevel: LanguageLevel = LanguageLevel.JDK_1_8 + + def githubRepositoryWithRevision: GithubRepositoryWithRevision = + GithubRepositoryWithRevision("pauljamescleary", "scala-pet-store", "a4391027771146daaa4b5a6599d36e6462d645b3") +} diff --git a/sbt/sbt-impl/test/org/jetbrains/plugins/scala/projectHighlighting/local/ScalaPetStoreTest.scala b/sbt/sbt-impl/test/org/jetbrains/plugins/scala/projectHighlighting/local/ScalaPetStoreTest.scala deleted file mode 100644 index dfef1b78f00..00000000000 --- a/sbt/sbt-impl/test/org/jetbrains/plugins/scala/projectHighlighting/local/ScalaPetStoreTest.scala +++ /dev/null @@ -1,11 +0,0 @@ -package org.jetbrains.plugins.scala.projectHighlighting.local - -import com.intellij.pom.java.LanguageLevel -import org.jetbrains.plugins.scala.projectHighlighting.base.SbtProjectHighlightingLocalProjectsTestBase - -class ScalaPetStoreTest extends SbtProjectHighlightingLocalProjectsTestBase { - - override def projectJdkLanguageLevel: LanguageLevel = LanguageLevel.JDK_1_8 - - override def projectName = "scala-pet-store" -} diff --git a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/.gitignore b/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/.gitignore deleted file mode 100644 index 6a037541325..00000000000 --- a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -*.class -*.log -.idea -target -project/target -.virtualenv -__pycache__ -*.pyc diff --git a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/.scalafmt.conf b/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/.scalafmt.conf deleted file mode 100644 index aee4770f9e1..00000000000 --- a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/.scalafmt.conf +++ /dev/null @@ -1,13 +0,0 @@ -style = default - -maxColumn = 100 - -align = none - -rewrite.rules = [ - AvoidInfix - RedundantBraces - RedundantParens - AsciiSortImports - PreferCurlyFors -] diff --git a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/.travis.yml b/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/.travis.yml deleted file mode 100644 index 4406035c7ee..00000000000 --- a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/.travis.yml +++ /dev/null @@ -1,18 +0,0 @@ -language: scala - -scala: - - 2.12.3 - -python: - - "2.7" - -jobs: - include: - - stage: verify - - before_script: - - sbt stage - - script: - - sbt ++$TRAVIS_SCALA_VERSION test - - ./build.sh diff --git a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/LICENSE b/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/LICENSE deleted file mode 100644 index 8dada3edaf5..00000000000 --- a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "{}" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright {yyyy} {name of copyright owner} - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/README.md b/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/README.md deleted file mode 100644 index b98b3800eec..00000000000 --- a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/README.md +++ /dev/null @@ -1,85 +0,0 @@ -# Scala Pet Store -An implementation of the java pet store using FP techniques in scala. - -# Status -I have stood up a few endpoints, with something like tagless final services and repositories. Repositories developed in Doobie. - -Updated to the latest of all of the things as I begin to abstract away the effect type. - -I am still exploring tagless final and how to fit all of the pieces together. Hoping to get into a more complete -functional example, as well as a UI and some business rules / validations. - -# Want to help out? -I could use some help with Scalacheck and a UI if people feel compelled to jump in. - -Also, if you have general feedback on how things could be better, feel free to post an issue / gist or -open a PR! - - -## Why you doing this? -The goal for this project is to demonstrate how to build an application using FP techniques in Scala. -When starting out in Scala coming from a Java background, it was extremely difficult to piece together all of the little -bits in order to make a cohesive whole application. - -## How are you building it? -As the goal of the project is to help Java / Spring folks understand how to build an application in Scala, I will -not be looking to employ the more esoteric features in Scala like Type Classes and Category Theory. Those things will -be present, but I hope to obscure them in parts the purpose of allowing the reader to understand what is going on in the code. - -I will reach out to Java developers along the way, to see if techniques that I use are too confusing, or have a low -enough barrier to entry to pick up quickly. - -## What is your stack? -I am going to work with the TypeLevel stack initially and see how far I can go with it. I believe that framing the -concepts in code in an easy to understand way should be possible with Typelevel. - -- [HTTP4S](http://http4s.org/) as the web server. I could have gone with finch, twitter server, or akka-http here as well, but I have been -interested in learning http4s. -- [Circe](https://circe.github.io/circe/) for json serialization. -- Tagless Final for my core domain. -- [Doobie](https://github.com/tpolecat/doobie) for database access - -## Getting Started - -Start up sbt: - -``` -> sbt -``` - -Once sbt has loaded, you can start up the application - -``` -> ~reStart -``` - -This uses revolver, which is a great way to develop and test the application. Doing things this way the application -will be automatically rebuilt when you make code changes - -To stop the app in sbt, hit the `Enter` key and then type: - -``` -> reStop -``` - -## Testing -Building out a test suite using Python. The reason is that typically we want to run tests against a live environment -when we deploy our code in order to make sure that everything is running properly in the target environment. It -is reassuring to know that your code works across clients. - -In order to run the functional tests, your machine will need to have Python 2.7 and pip, and virtualenv. - -1. To install pip on a Mac, run `sudo easy_install pip` -2. Then install virutalenv `sudo pip install virtualenv` - -To test out the app, first start it up following the directions above and doing `re-start` - -Then, in a separate terminal, run the test suite: - -``` -> cd functional_test -> ./run.py live_tests -v -``` - - - diff --git a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/build.sbt b/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/build.sbt deleted file mode 100644 index 4b134fd4556..00000000000 --- a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/build.sbt +++ /dev/null @@ -1,93 +0,0 @@ -organization := "io.github.pauljamescleary" -name := "scala-pet-store" -version := "0.0.1-SNAPSHOT" -scalaVersion := "2.12.3" - -resolvers += Resolver.sonatypeRepo("snapshots") - -val CatsVersion = "1.0.0-RC1" -val CirceVersion = "0.9.0-M2" -val DoobieVersion = "0.5.0-M9" -val H2Version = "1.4.196" -val Http4sVersion = "0.18.0-M5" -val LogbackVersion = "1.2.3" -val ScalaCheckVersion = "1.13.5" -val ScalaTestVersion = "3.0.4" -val FlywayVersion = "4.2.0" -val PureConfigVersion = "0.8.0" - -libraryDependencies ++= Seq( - "org.typelevel" %% "cats-core" % CatsVersion, - "io.circe" %% "circe-generic" % CirceVersion, - "io.circe" %% "circe-literal" % CirceVersion, - "io.circe" %% "circe-generic-extras" % CirceVersion, - "io.circe" %% "circe-optics" % CirceVersion, - "io.circe" %% "circe-parser" % CirceVersion, - "io.circe" %% "circe-java8" % CirceVersion, - "org.tpolecat" %% "doobie-core" % DoobieVersion, - "org.tpolecat" %% "doobie-h2" % DoobieVersion, - "org.tpolecat" %% "doobie-scalatest" % DoobieVersion, - "org.tpolecat" %% "doobie-hikari" % DoobieVersion, - "com.h2database" % "h2" % H2Version, - "org.http4s" %% "http4s-blaze-server" % Http4sVersion, - "org.http4s" %% "http4s-circe" % Http4sVersion, - "org.http4s" %% "http4s-dsl" % Http4sVersion, - "ch.qos.logback" % "logback-classic" % LogbackVersion, - "org.flywaydb" % "flyway-core" % FlywayVersion, - "com.github.pureconfig" %% "pureconfig" % PureConfigVersion, - "org.scalacheck" %% "scalacheck" % ScalaCheckVersion % Test, - "org.scalatest" %% "scalatest" % ScalaTestVersion % Test -) - - -scalacOptions ++= Seq( - // format: off - "-deprecation", // Emit warning and location for usages of deprecated APIs. - "-encoding", "utf-8", // Specify character encoding used by source files. - "-explaintypes", // Explain type errors in more detail. - "-feature", // Emit warning and location for usages of features that should be imported explicitly. - "-language:existentials", // Existential types (besides wildcard types) can be written and inferred - "-language:experimental.macros", // Allow macro definition (besides implementation and application) - "-language:higherKinds", // Allow higher-kinded types - "-language:implicitConversions", // Allow definition of implicit functions called views - "-unchecked", // Enable additional warnings where generated code depends on assumptions. - "-Xcheckinit", // Wrap field accessors to throw an exception on uninitialized access. - "-Xfatal-warnings", // Fail the compilation if there are any warnings. - "-Xfuture", // Turn on future language features. - "-Xlint:adapted-args", // Warn if an argument list is modified to match the receiver. - "-Xlint:by-name-right-associative", // By-name parameter of right associative operator. - "-Xlint:constant", // Evaluation of a constant arithmetic expression results in an error. - "-Xlint:delayedinit-select", // Selecting member of DelayedInit. - "-Xlint:doc-detached", // A Scaladoc comment appears to be detached from its element. - "-Xlint:inaccessible", // Warn about inaccessible types in method signatures. - "-Xlint:infer-any", // Warn when a type argument is inferred to be `Any`. - "-Xlint:missing-interpolator", // A string literal appears to be missing an interpolator id. - "-Xlint:nullary-override", // Warn when non-nullary `def f()' overrides nullary `def f'. - "-Xlint:nullary-unit", // Warn when nullary methods return Unit. - "-Xlint:option-implicit", // Option.apply used implicit view. - "-Xlint:package-object-classes", // Class or object defined in package object. - "-Xlint:poly-implicit-overload", // Parameterized overloaded implicit methods are not visible as view bounds. - "-Xlint:private-shadow", // A private field (or class parameter) shadows a superclass field. - "-Xlint:stars-align", // Pattern sequence wildcard must align with sequence component. - "-Xlint:type-parameter-shadow", // A local type parameter shadows a type already in scope. - "-Xlint:unsound-match", // Pattern match may not be typesafe. - "-Yno-adapted-args", // Do not adapt an argument list (either by inserting () or creating a tuple) to match the receiver. - "-Ypartial-unification", // Enable partial unification in type constructor inference - "-Ywarn-dead-code", // Warn when dead code is identified. - "-Ywarn-extra-implicit", // Warn when more than one implicit parameter section is defined. - "-Ywarn-inaccessible", // Warn about inaccessible types in method signatures. - "-Ywarn-infer-any", // Warn when a type argument is inferred to be `Any`. - "-Ywarn-nullary-unit", // Warn when nullary methods return Unit. - "-Ywarn-nullary-override", // Warn when non-nullary `def f()' overrides nullary `def f'. - "-Ywarn-numeric-widen", // Warn when numerics are widened. - "-Ywarn-unused:implicits", // Warn if an implicit parameter is unused. - "-Ywarn-unused:imports", // Warn if an import selector is not referenced. - "-Ywarn-unused:locals", // Warn if a local definition is unused. - // "-Ywarn-unused:params", // Warn if a value parameter is unused. - "-Ywarn-unused:patvars", // Warn if a variable bound in a pattern is unused. - "-Ywarn-unused:privates", // Warn if a private member is unused. - "-Ywarn-value-discard" // Warn when non-Unit expression results are unused. - // format: on -) - -enablePlugins(JavaAppPackaging) diff --git a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/build.sh b/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/build.sh deleted file mode 100644 index 589ce32be38..00000000000 --- a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/build.sh +++ /dev/null @@ -1,52 +0,0 @@ -#!/bin/bash -echo "Running verify" -sbt test - -echo "Running func tests" -echo "Starting server" - -trap 'kill -TERM $SERVER_PID' TERM INT -./target/universal/stage/bin/scala-pet-store & - -SERVER_PID=$! -PARENT_PID=$$ - -echo "Waiting for app to start...server pid is $SERVER_PID; parent pid is $PARENT_PID" -DATA="" -RETRY=30 - -while [ $RETRY -gt 0 ] -do - DATA=$(nc -v -z localhost 8080) - if [ $? -eq 0 ] - then - break - else - echo "Retrying Again" >&2 - - let RETRY-=1 - sleep 1 - - if [ $RETRY -eq 0 ] - then - echo "Exceeded retries waiting for app to be ready, failing" - exit 1 - fi - fi -done - -echo "Server started, running func tests" -cd functional_test -./run.py live_tests -v -FUNC_TEST_RESULT=$! - -echo "Functional tests completed with satus $FUNC_TEST_RESULT, stopping server with PID $SERVER_PID, PPID $PARENT_PID" - -kill $SERVER_PID -wait $SERVER_PID -trap - TERM INT -wait $SERVER_PID -# kill -9 $PARENT_PID - -echo "DONE!" -exit 0 diff --git a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/functional_test/bootstrap.sh b/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/functional_test/bootstrap.sh deleted file mode 100644 index df8f18831dd..00000000000 --- a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/functional_test/bootstrap.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash -e - -if [ ! -d "./.virtualenv" ]; then - echo "Creating virtualenv..." - virtualenv --clear --python="$(which python2.7)" ./.virtualenv -fi - -if ! diff ./requirements.txt ./.virtualenv/requirements.txt &> /dev/null; then - - echo "Installing dependencies..." - ./.virtualenv/bin/python ./.virtualenv/bin/pip install --index-url https://pypi.python.org/simple/ -r ./requirements.txt - - cp ./requirements.txt ./.virtualenv/ -fi diff --git a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/functional_test/live_tests/conftest.py b/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/functional_test/live_tests/conftest.py deleted file mode 100644 index 88fbf8ac2d6..00000000000 --- a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/functional_test/live_tests/conftest.py +++ /dev/null @@ -1,28 +0,0 @@ -import pytest -from pet_store_client import PetStoreClient - -@pytest.fixture(scope="session") -def pet_store_client(request): - return PetStoreClient() - - -@pytest.fixture(scope="session") -def pet_context(request, pet_store_client): - pet = { - "name": "Harry", - "category": "Cat", - "bio": "I am fuzzy", - "status": "Available", - "tags": [], - "photoUrls": [] - } - - response = pet_store_client.create_pet(pet) - saved_pet = response.json() - - def fin(): - pet_store_client.delete_pet(saved_pet['id']) - - request.addfinalizer(fin) - - return saved_pet \ No newline at end of file diff --git a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/functional_test/live_tests/orders_test.py b/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/functional_test/live_tests/orders_test.py deleted file mode 100644 index 2706124d21c..00000000000 --- a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/functional_test/live_tests/orders_test.py +++ /dev/null @@ -1,18 +0,0 @@ -import pytest -from hamcrest import * -from pet_store_client import PetStoreClient - - -def test_place_order(pet_context, pet_store_client): - order = { - "petId": pet_context['id'], - "status": "Placed", - "complete": False - } - response = pet_store_client.place_order(order) - - order = response.json() - assert_that(order['status'], is_('Placed')) - assert_that(order['complete'], is_(False)) - assert_that(order['id'], is_(not_none())) - assert_that(order['shipDate'], is_(none())) \ No newline at end of file diff --git a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/functional_test/live_tests/pets_test.py b/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/functional_test/live_tests/pets_test.py deleted file mode 100644 index d6b4a7aa559..00000000000 --- a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/functional_test/live_tests/pets_test.py +++ /dev/null @@ -1,98 +0,0 @@ -import pytest -from hamcrest import * -from pet_store_client import PetStoreClient - -def test_get_pet(pet_context, pet_store_client): - response = pet_store_client.get_pet(pet_context['id']) - - pet = response.json() - assert_that(pet['name'], is_('Harry')) - assert_that(pet['category'], is_('Cat')) - assert_that(pet['bio'], is_('I am fuzzy')) - assert_that(pet['id'], is_(pet_context['id'])) - - -def test_list_pets(pet_context, pet_store_client): - response = pet_store_client.list_pets() - - pets = response.json() - assert_that(pets, has_length(1)) - - assert_that(pets[0]['name'], is_('Harry')) - - -def test_find_pets_by_status(pet_context, pet_store_client): - response = pet_store_client.find_pets_by_status(['Available', 'Pending']) - - pets = response.json() - assert_that(pets, has_length(1)) - - assert_that(pets[0]['name'], is_('Harry')) - -def test_find_pets_by_tags(pet_context, pet_store_client): - # No Pets with "Amphibian" tags exist yet - response = pet_store_client.find_pets_by_tag(['Amphibian']) - pets = response.json() - assert_that(pets, has_length(0)) - - # Add a pet - pet = { - "name": "Nancy", - "category": "Frog", - "bio": "R-r-ribbit!", - "status": "Pending", - "tags": ["Green", "Amphibian", "Croaker"], - "photoUrls": [] - } - pet_store_client.create_pet(pet) - - # Grab all pets - response = pet_store_client.find_pets_by_tag(['']) - pets = response.json() - assert_that(pets, has_length(2)) - assert_that(pets[0]['name'], is_('Harry')) - - # Retry "Amphibian" tag - there should be exactly one now - response = pet_store_client.find_pets_by_tag(['Amphibian']) - pets = response.json() - assert_that(pets, has_length(1)) - assert_that(pets[0]['name'],is_('Nancy')) - -def test_update_pet(pet_store_client): - pet = { - "name": "JohnnyUpdate", - "category": "Cat", - "bio": "I am fuzzy", - "status": "Available", - "tags": ["Cat","Fuzzy","Fur ball"], - "photoUrls": [] - } - - saved_pet = None - - try: - response = pet_store_client.create_pet(pet) - saved_pet = response.json() - saved_pet['bio'] = "Not so fuzzy" - - response = pet_store_client.update_pet(saved_pet) - updated_pet = response.json() - - assert_that(updated_pet['bio'], is_('Not so fuzzy')) - finally: - if saved_pet: - pet_store_client.delete_pet(saved_pet['id']) - - -def test_update_pet_not_found(pet_store_client): - pet = { - "id": 99999999, - "name": "NotFound", - "category": "Cat", - "bio": "I am fuzzy", - "status": "Available", - "tags": [], - "photoUrls": [] - } - response = pet_store_client.update_pet(pet) - assert_that(response.status_code, is_(404)) diff --git a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/functional_test/pet_store_client.py b/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/functional_test/pet_store_client.py deleted file mode 100644 index 8167741fd50..00000000000 --- a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/functional_test/pet_store_client.py +++ /dev/null @@ -1,112 +0,0 @@ -import json -import requests -import urllib -from requests.adapters import HTTPAdapter -from requests.packages.urllib3.util.retry import Retry - -from urlparse import urljoin -from urlparse import urlparse -from urlparse import parse_qs -from urlparse import urlsplit - -class PetStoreClient(object): - def __init__(self, url='http://localhost:8080'): - self.index_url = url - self.headers = { - 'Accept': 'application/json, text/plain', - 'Content-Type': 'application/json' - } - - self.session = requests.Session() - - def make_request(self, url, method='GET', headers={}, body_string=None, **kw): - - response = self.session.request(method, url, data=body_string, headers=headers, **kw) - return response.status_code, response.json() - - def create_pet(self, pet): - """ - Creates a pet, returning the created pet response - :param pet: - :return: - """ - url = urljoin(self.index_url, '/pets') - - return self.session.request('POST', url, self.headers, json.dumps(pet)) - - def update_pet(self, pet): - """ - Updates a pet, returning the updated pet response - :param pet: - :return: - """ - url = urljoin(self.index_url, '/pets') - - return self.session.request('PUT', url, self.headers, json.dumps(pet)) - - def get_pet(self, pet_id): - """ - Returns the pet for the given id - :param pet_id: - :return: - """ - url = urljoin(self.index_url, "/pets?id={0}".format(pet_id)) - - return self.session.request('GET', url, self.headers) - - def list_pets(self, page_size=10, offset=0): - """ - Returns a list of pets - :return: - """ - url = urljoin(self.index_url, "/pets?pageSize={0}&offset={1}".format(page_size, offset)) - - return self.session.request('GET', url, self.headers) - - def find_pets_by_status(self, statuses): - """ - Returns a list of pets that match the statuses provided - :param statuses: A list of valid Pet statuses - :return: - """ - status_kv_pairs = map(lambda x: "status={0}".format(x), statuses) - params = "&".join(status_kv_pairs) - url = urljoin(self.index_url, "/pets/findByStatus?{0}".format(params)) - return self.session.request('GET', url, self.headers) - - def find_pets_by_tag(self, tags): - """ - Returns a list of pets which match the tags provided. - - Note: The current implementation of Pet stores the tags in a comma-delimited string. An inherent - shortcoming of how tags are stored means that: 1. the most accurate method of finding matches is through using - the LIKE operator, and 2. an unintended result is that an input containing substrings and commas can pass, despite - not being a full tag itself. (eg. given tags "foo" and "bar" to create tag string "foo,bar", "o,b" would pass) - - :param tags: A list of valid tags. - :return: - """ - tags_kv_pairs = map(lambda x: "tags={0}".format(x), tags) - params = "&".join(tags_kv_pairs) - url = urljoin(self.index_url, "/pets/findByTags?{0}".format(params)) - return self.session.request('GET', url, self.headers) - - def delete_pet(self, pet_id): - """ - Deletes a pet - :return: - """ - url = urljoin(self.index_url, "/pets?id={0}".format(pet_id)) - - return self.session.request('DELETE', url, self.headers) - - def place_order(self, order): - """ - Places an order for a pet - """ - url = urljoin(self.index_url, '/orders') - - return self.session.request('POST', url, self.headers, json.dumps(order)) - - - diff --git a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/functional_test/pytest.ini b/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/functional_test/pytest.ini deleted file mode 100644 index c041cbc494a..00000000000 --- a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/functional_test/pytest.ini +++ /dev/null @@ -1,3 +0,0 @@ -[pytest] -norecursedirs=.virtualenv -addopts = -rfesxX --capture=sys --junitxml=../target/pytest_reports/pytest.xml --durations=30 diff --git a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/functional_test/requirements.txt b/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/functional_test/requirements.txt deleted file mode 100644 index a5e200d3dc5..00000000000 --- a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/functional_test/requirements.txt +++ /dev/null @@ -1,11 +0,0 @@ -# requirements.txt v1.0 -# --------------------- -# Add project specific python requirements to this file. -# Do not commit them in the project! - -pyhamcrest==1.8.0 -pytz>=2014 -pytest==2.6.4 -mock==1.0.1 -pyformance==0.3.2 -requests diff --git a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/functional_test/run.py b/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/functional_test/run.py deleted file mode 100644 index 74b8cb0f958..00000000000 --- a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/functional_test/run.py +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env python -import os -import sys - -basedir = os.path.dirname(os.path.realpath(__file__)) -vedir = os.path.join(basedir, '.virtualenv') -os.system('./bootstrap.sh') - -activate_virtualenv = os.path.join(vedir, 'bin', 'activate_this.py') -print('Activating virtualenv at ' + activate_virtualenv) - -report_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../target/pytest_reports') -if not os.path.exists(report_dir): - os.system('mkdir -p ' + report_dir) - -execfile(activate_virtualenv, dict(__file__=activate_virtualenv)) - -import pytest - -result = 1 - -result = pytest.main(list(sys.argv[1:])) - -sys.exit(result) - - diff --git a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/pet.json b/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/pet.json deleted file mode 100644 index 3c8046e8d2a..00000000000 --- a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/pet.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "category": "Cat", - "bio": "I am fuzzy", - "name": "Harry", - "tags": [], - "photoUrls": [], - "status": "Available" -} diff --git a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/post-pet.sh b/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/post-pet.sh deleted file mode 100644 index 9d5fff8b9ac..00000000000 --- a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/post-pet.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -echo "This will only work one time, then you have to restart!" - -echo "Creating pet..." -curl -X POST http://localhost:8080/pets -d @pet.json --header "Content-Type: application/json" - -echo "Getting created pet with id 1" -curl -X GET "http://localhost:8080/pets?id=1" - -echo "Listing pets..." -curl -X GET "http://localhost:8080/pets?pageSize=10&offset=0" - -echo "Deleting pet..." -curl -X DELETE "http://localhost:8080/pets?id=1" diff --git a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/project/build.properties b/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/project/build.properties deleted file mode 100644 index 22af2628c41..00000000000 --- a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/project/build.properties +++ /dev/null @@ -1 +0,0 @@ -sbt.version=1.7.1 diff --git a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/project/plugins.sbt b/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/project/plugins.sbt deleted file mode 100644 index ecca04d266a..00000000000 --- a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/project/plugins.sbt +++ /dev/null @@ -1,13 +0,0 @@ -// Makes our code tidy -//addSbtPlugin("com.geirsson" % "sbt-scalafmt" % "1.3.0") - -// Revolver allows us to use re-start and work a lot faster! -addSbtPlugin("io.spray" % "sbt-revolver" % "0.9.0") - -// Native Packager allows us to create standalone jar -addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.2.2") - -// Database migrations -addSbtPlugin("org.flywaydb" % "flyway-sbt" % "4.2.0") - -resolvers += "Flyway".at("https://davidmweber.github.io/flyway-sbt.repo") diff --git a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/resources/db/migration/V1__InitialDatabaseSetup.sql b/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/resources/db/migration/V1__InitialDatabaseSetup.sql deleted file mode 100644 index 73e2a69c11d..00000000000 --- a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/resources/db/migration/V1__InitialDatabaseSetup.sql +++ /dev/null @@ -1,17 +0,0 @@ -CREATE TABLE PET ( - ID SERIAL, - NAME VARCHAR NOT NULL, - CATEGORY VARCHAR NOT NULL, - BIO VARCHAR NOT NULL, - STATUS VARCHAR NOT NULL, - PHOTO_URLS VARCHAR NOT NULL, - TAGS VARCHAR NOT NULL -); - -CREATE TABLE ORDERS ( - ID SERIAL, - PET_ID INT8 NOT NULL, - SHIP_DATE TIMESTAMP NULL, - STATUS VARCHAR NOT NULL, - COMPLETE BOOLEAN NOT NULL -); diff --git a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/resources/logback.xml b/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/resources/logback.xml deleted file mode 100644 index 8ea8412ffac..00000000000 --- a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/resources/logback.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - true - - [%thread] %highlight(%-5level) %cyan(%logger{15}) - %msg %n - - - - - - diff --git a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/resources/reference.conf b/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/resources/reference.conf deleted file mode 100644 index 3b2b8f1825f..00000000000 --- a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/resources/reference.conf +++ /dev/null @@ -1,8 +0,0 @@ -petstore { - db { - url="jdbc:h2:mem:test;MODE=MySQL;DB_CLOSE_DELAY=-1" - user="sa" - password="" - driver="org.h2.Driver" - } -} diff --git a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/Server.scala b/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/Server.scala deleted file mode 100644 index 82c018145fa..00000000000 --- a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/Server.scala +++ /dev/null @@ -1,40 +0,0 @@ -package io.github.pauljamescleary.petstore - -import cats.effect._ -import cats.implicits._ -import fs2.Stream -import io.github.pauljamescleary.petstore.config.{DatabaseConfig, PetStoreConfig} -import io.github.pauljamescleary.petstore.endpoint.{OrderEndpoints, PetEndpoints} -import io.github.pauljamescleary.petstore.repository.{ - DoobieOrderRepositoryInterpreter, - DoobiePetRepositoryInterpreter -} -import io.github.pauljamescleary.petstore.service.{OrderService, PetService} -import io.github.pauljamescleary.petstore.validation.PetValidationInterpreter -import org.http4s.server.blaze.BlazeBuilder -import org.http4s.util.StreamApp -import org.http4s.util.ExitCode - -object Server extends StreamApp[IO] { - - override def stream(args: List[String], shutdown: IO[Unit]): Stream[IO, ExitCode] = - createStream[IO](args, shutdown) - - def createStream[F[_]](args: List[String], shutdown: F[Unit])( - implicit E: Effect[F]): Stream[F, ExitCode] = - for { - conf <- Stream.eval(PetStoreConfig.load[F]) - xa <- Stream.eval(DatabaseConfig.dbTransactor(conf.db)) - _ <- Stream.eval(DatabaseConfig.initializeDb(conf.db, xa)) - petRepo = DoobiePetRepositoryInterpreter[F](xa) - orderRepo = DoobieOrderRepositoryInterpreter[F](xa) - petValidation = PetValidationInterpreter[F](petRepo) - petService = PetService[F](petRepo, petValidation) - orderService = OrderService[F](orderRepo) - exitCode <- BlazeBuilder[F] - .bindHttp(8080, "localhost") - .mountService(PetEndpoints.endpoints[F](petService), "/") - .mountService(OrderEndpoints.endpoints[F](orderService), "/") - .serve - } yield exitCode -} diff --git a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/config/DatabaseConfig.scala b/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/config/DatabaseConfig.scala deleted file mode 100644 index d937b7bc2fa..00000000000 --- a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/config/DatabaseConfig.scala +++ /dev/null @@ -1,32 +0,0 @@ -package io.github.pauljamescleary.petstore.config - -import cats.effect.{Async, Sync} -import doobie.hikari.HikariTransactor -import org.flywaydb.core.Flyway - -case class DatabaseConfig(url: String, driver: String, user: String, password: String) - -object DatabaseConfig { - - def dbTransactor[F[_]: Async](dbConfig: DatabaseConfig): F[HikariTransactor[F]] = - HikariTransactor[F](dbConfig.driver, dbConfig.url, dbConfig.user, dbConfig.password) - - /** - * Runs the flyway migrations against the target database - * - * This only gets applied if the database is H2, our local in-memory database. Otherwise - * we skip this step - */ - def initializeDb[F[_]](dbConfig: DatabaseConfig, xa: HikariTransactor[F])( - implicit S: Sync[F]): F[Unit] = - if (dbConfig.url.contains(":h2:")) { - xa.configure { ds => - val fw = new Flyway() - fw.setDataSource(ds) - fw.migrate() - () - } - } else { - S.pure(()) - } -} diff --git a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/config/PetStoreConfig.scala b/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/config/PetStoreConfig.scala deleted file mode 100644 index 45b86a11364..00000000000 --- a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/config/PetStoreConfig.scala +++ /dev/null @@ -1,21 +0,0 @@ -package io.github.pauljamescleary.petstore.config - -import cats.effect.Effect -import pureconfig.error.ConfigReaderException - -case class PetStoreConfig(db: DatabaseConfig) - -object PetStoreConfig { - - import pureconfig._ - - /** - * Loads the pet store config using PureConfig. If configuration is invalid we will - * return an error. This should halt the application from starting up. - */ - def load[F[_]](implicit E: Effect[F]): F[PetStoreConfig] = - loadConfig[PetStoreConfig]("petstore") match { - case Right(ok) => E.pure(ok) - case Left(e) => E.raiseError(new ConfigReaderException[PetStoreConfig](e)) - } -} diff --git a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/endpoint/OrderEndpoints.scala b/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/endpoint/OrderEndpoints.scala deleted file mode 100644 index 6aaffeb60d5..00000000000 --- a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/endpoint/OrderEndpoints.scala +++ /dev/null @@ -1,49 +0,0 @@ -package io.github.pauljamescleary.petstore.endpoint - -import cats.effect.Effect -import io.circe._ -import io.circe.generic.auto._ -import io.circe.generic.extras.semiauto._ -import io.circe.syntax._ -import io.github.pauljamescleary.petstore.model.{Order, OrderStatus} -import io.github.pauljamescleary.petstore.service.OrderService -import org.http4s._ -import org.http4s.circe._ -import org.http4s.dsl.Http4sDsl - -import scala.language.higherKinds - -class OrderEndpoints[F[_]: Effect] extends Http4sDsl[F] { - - /* Need Instant Json Encoding */ - import io.circe.java8.time._ - - /* Needed for service composition via |+| */ - import cats.implicits._ - - /* We need to define an enum encoder and decoder since these do not come out of the box with generic derivation */ - implicit val statusDecoder: Decoder[OrderStatus] = deriveEnumerationDecoder - implicit val statusEncoder: Encoder[OrderStatus] = deriveEnumerationEncoder - - /* Needed to decode entities */ - implicit val orderDecoder = jsonOf[F, Order] - - def placeOrderEndpoint(orderService: OrderService[F]): HttpService[F] = - HttpService[F] { - case req @ POST -> Root / "orders" => { - for { - order <- req.as[Order] - saved <- orderService.placeOrder(order) - resp <- Ok(saved.asJson) - } yield resp - } - } - - def endpoints(orderService: OrderService[F]): HttpService[F] = - placeOrderEndpoint(orderService) -} - -object OrderEndpoints { - def endpoints[F[_]: Effect](orderService: OrderService[F]): HttpService[F] = - new OrderEndpoints[F].endpoints(orderService) -} diff --git a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/endpoint/PetEndpoints.scala b/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/endpoint/PetEndpoints.scala deleted file mode 100644 index 9d899138066..00000000000 --- a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/endpoint/PetEndpoints.scala +++ /dev/null @@ -1,150 +0,0 @@ -package io.github.pauljamescleary.petstore.endpoint - -import cats.data.Validated.Valid -import cats.data._ -import cats.effect.Effect -import cats.implicits._ -import io.circe._ -import io.circe.generic.auto._ -import io.circe.generic.extras.semiauto._ -import io.circe.syntax._ -import io.github.pauljamescleary.petstore.model.{Pet, PetStatus} -import io.github.pauljamescleary.petstore.service.PetService -import io.github.pauljamescleary.petstore.validation.{PetAlreadyExistsError, PetNotFoundError} -import org.http4s.circe._ -import org.http4s.dsl.Http4sDsl -import org.http4s.{EntityDecoder, HttpService, QueryParamDecoder} - -import scala.language.higherKinds - -class PetEndpoints[F[_]: Effect] extends Http4sDsl[F] { - - /* Necessary for decoding query parameters */ - import QueryParamDecoder._ - - /* Parses out the id query param */ - object IdMatcher extends QueryParamDecoderMatcher[Long]("id") - - /* Parses out the offset and page size params */ - object PageSizeMatcher extends QueryParamDecoderMatcher[Int]("pageSize") - object OffsetMatcher extends QueryParamDecoderMatcher[Int]("offset") - - /* Parses out status query param which could be multi param */ - implicit val statusQueryParamDecoder: QueryParamDecoder[PetStatus] = - QueryParamDecoder[String].map(PetStatus.apply) - - /* Relies on the statusQueryParamDecoder implicit, will parse out a possible multi-value query parameter */ - object StatusMatcher extends OptionalMultiQueryParamDecoderMatcher[PetStatus]("status") - - /* Parses out tag query param, which could be multi-value */ - object TagMatcher extends OptionalMultiQueryParamDecoderMatcher[String]("tags") - - /* We need to define an enum encoder and decoder since these do not come out of the box with generic derivation */ - implicit val statusDecoder: Decoder[PetStatus] = deriveEnumerationDecoder - implicit val statusEncoder: Encoder[PetStatus] = deriveEnumerationEncoder - implicit val petDecoder: EntityDecoder[F, Pet] = jsonOf[F, Pet] - - private def createPetEndpoint(petService: PetService[F]): HttpService[F] = - HttpService[F] { - case req @ POST -> Root / "pets" => - val action = for { - pet <- req.as[Pet] - result <- petService.create(pet).value - } yield result - - action.flatMap { - case Right(saved) => - Ok(saved.asJson) - case Left(PetAlreadyExistsError(existing)) => - Conflict(s"The pet ${existing.name} of category ${existing.category} already exists") - case Left(unexpected) => - InternalServerError(s"Unexpected error: $unexpected") - } - } - - private def updatePetEndpoint(petService: PetService[F]): HttpService[F] = - HttpService[F] { - case req @ PUT -> Root / "pets" => - val action = for { - pet <- req.as[Pet] - result <- petService.update(pet).value - } yield result - - action.flatMap { - case Right(saved) => Ok(saved.asJson) - case Left(PetNotFoundError) => NotFound("The pet was not found") - case Left(unexpected) => - InternalServerError(s"Unexpected error: $unexpected") - } - } - - private def getPetEndpoint(petService: PetService[F]): HttpService[F] = - HttpService[F] { - case GET -> Root / "pets" :? IdMatcher(id) => - petService.get(id).value.flatMap { - case Right(found) => Ok(found.asJson) - case Left(PetNotFoundError) => NotFound("The pet was not found") - case Left(unexpected) => - InternalServerError(s"Unexpected error: $unexpected") - } - } - - private def deletePetEndpoint(petService: PetService[F]): HttpService[F] = - HttpService[F] { - case DELETE -> Root / "pets" :? IdMatcher(id) => - for { - _ <- petService.delete(id) - resp <- Ok() - } yield resp - } - - private def listPetsEndpoint(petService: PetService[F]): HttpService[F] = - HttpService[F] { - case GET -> Root / "pets" :? PageSizeMatcher(pageSize) :? OffsetMatcher(offset) => - for { - retrieved <- petService.list(pageSize, offset) - resp <- Ok(retrieved.asJson) - } yield resp - } - - private def findPetsByStatusEndpoint(petService: PetService[F]): HttpService[F] = - HttpService[F] { - case GET -> Root / "pets" / "findByStatus" :? StatusMatcher(Valid(Nil)) => - // User did not specify any statuses - BadRequest("status parameter not specified") - - case GET -> Root / "pets" / "findByStatus" :? StatusMatcher(Valid(statuses)) => - // We have a list of valid statuses, find them and return - for { - retrieved <- petService.findByStatus(NonEmptyList.fromListUnsafe(statuses)) - resp <- Ok(retrieved.asJson) - } yield resp - } - - private def findPetsByTagEndpoint(petService: PetService[F]): HttpService[F] = - HttpService[F] { - case GET -> Root / "pets" / "findByTags" :? TagMatcher(Valid(Nil)) => - BadRequest("tag parameter not specified") - - case GET -> Root / "pets" / "findByTags" :? TagMatcher(Valid(tags)) => - for { - retrieved <- petService.findByTag(NonEmptyList.fromListUnsafe(tags)) - resp <- Ok(retrieved.asJson) - } yield resp - - } - - def endpoints(petService: PetService[F]): HttpService[F] = - createPetEndpoint(petService) <+> - getPetEndpoint(petService) <+> - deletePetEndpoint(petService) <+> - listPetsEndpoint(petService) <+> - findPetsByStatusEndpoint(petService) <+> - updatePetEndpoint(petService) <+> - findPetsByTagEndpoint(petService) -} - -object PetEndpoints { - def endpoints[F[_]: Effect](petService: PetService[F]): HttpService[F] = - new PetEndpoints[F].endpoints(petService) -} diff --git a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/model/Order.scala b/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/model/Order.scala deleted file mode 100644 index c98981b74b6..00000000000 --- a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/model/Order.scala +++ /dev/null @@ -1,11 +0,0 @@ -package io.github.pauljamescleary.petstore.model - -import java.time.Instant - -case class Order( - petId: Long, - shipDate: Option[Instant] = None, - status: OrderStatus = Placed, - complete: Boolean = false, - id: Option[Long] = None -) diff --git a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/model/OrderStatus.scala b/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/model/OrderStatus.scala deleted file mode 100644 index 1137e68a2e9..00000000000 --- a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/model/OrderStatus.scala +++ /dev/null @@ -1,20 +0,0 @@ -package io.github.pauljamescleary.petstore.model - -sealed trait OrderStatus extends Product with Serializable -case object Approved extends OrderStatus -case object Delivered extends OrderStatus -case object Placed extends OrderStatus - -object OrderStatus { - def apply(name: String): OrderStatus = name match { - case "Approved" => Approved - case "Delivered" => Delivered - case "Placed" => Placed - } - - def nameOf(status: OrderStatus): String = status match { - case Approved => "Approved" - case Delivered => "Delivered" - case Placed => "Placed" - } -} diff --git a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/model/Pet.scala b/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/model/Pet.scala deleted file mode 100644 index 5fcf0db930f..00000000000 --- a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/model/Pet.scala +++ /dev/null @@ -1,11 +0,0 @@ -package io.github.pauljamescleary.petstore.model - -case class Pet( - name: String, - category: String, - bio: String, - status: PetStatus = Available, - tags: Set[String] = Set.empty, - photoUrls: Set[String] = Set.empty, - id: Option[Long] = None -) diff --git a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/model/PetStatus.scala b/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/model/PetStatus.scala deleted file mode 100644 index 5334baa500f..00000000000 --- a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/model/PetStatus.scala +++ /dev/null @@ -1,20 +0,0 @@ -package io.github.pauljamescleary.petstore.model - -sealed trait PetStatus extends Product with Serializable -case object Available extends PetStatus -case object Pending extends PetStatus -case object Adopted extends PetStatus - -object PetStatus { - def apply(name: String): PetStatus = name match { - case "Available" => Available - case "Pending" => Pending - case "Adopted" => Adopted - } - - def nameOf(status: PetStatus): String = status match { - case Available => "Available" - case Pending => "Pending" - case Adopted => "Adopted" - } -} diff --git a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/repository/DoobieOrderRepositoryInterpreter.scala b/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/repository/DoobieOrderRepositoryInterpreter.scala deleted file mode 100644 index bbd825b0803..00000000000 --- a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/repository/DoobieOrderRepositoryInterpreter.scala +++ /dev/null @@ -1,55 +0,0 @@ -package io.github.pauljamescleary.petstore.repository - -import java.time.Instant - -import doobie._ -import doobie.implicits._ -import cats._ -import cats.implicits._ -import io.github.pauljamescleary.petstore.model.{Order, OrderStatus} - -class DoobieOrderRepositoryInterpreter[F[_]: Monad](val xa: Transactor[F]) - extends OrderRepositoryAlgebra[F] { - - /* We require type StatusMeta to handle our ADT Status */ - private implicit val StatusMeta: Meta[OrderStatus] = - Meta[String].xmap(OrderStatus.apply, OrderStatus.nameOf) - - /* We require conversion for date time */ - private implicit val DateTimeMeta: Meta[Instant] = - Meta[java.sql.Timestamp].xmap( - ts => ts.toInstant, - dt => java.sql.Timestamp.from(dt) - ) - - def put(order: Order): F[Order] = { - val insert: ConnectionIO[Order] = - for { - id <- sql"REPLACE INTO ORDERS (PET_ID, SHIP_DATE, STATUS, COMPLETE) values (${order.petId}, ${order.shipDate}, ${order.status}, ${order.complete})".update - .withUniqueGeneratedKeys[Long]("ID") - } yield order.copy(id = Some(id)) - insert.transact(xa) - } - - def get(orderId: Long): F[Option[Order]] = - sql""" - SELECT PET_ID, SHIP_DATE, STATUS, COMPLETE - FROM ORDERS - WHERE ID = $orderId - """.query[Order].option.transact(xa) - - def delete(orderId: Long): F[Option[Order]] = - get(orderId).flatMap { - case Some(order) => - sql"DELETE FROM ORDERS WHERE ID = $orderId".update.run - .transact(xa) - .map(_ => Some(order)) - case None => - none[Order].pure[F] - } -} - -object DoobieOrderRepositoryInterpreter { - def apply[F[_]: Monad](xa: Transactor[F]): DoobieOrderRepositoryInterpreter[F] = - new DoobieOrderRepositoryInterpreter(xa) -} diff --git a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/repository/DoobiePetRepositoryInterpreter.scala b/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/repository/DoobiePetRepositoryInterpreter.scala deleted file mode 100644 index 807ec13da6f..00000000000 --- a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/repository/DoobiePetRepositoryInterpreter.scala +++ /dev/null @@ -1,84 +0,0 @@ -package io.github.pauljamescleary.petstore.repository - -import io.github.pauljamescleary.petstore.model._ -import doobie._, doobie.implicits._ -import cats._, cats.data._, cats.implicits._ - -class DoobiePetRepositoryInterpreter[F[_]: Monad](val xa: Transactor[F]) - extends PetRepositoryAlgebra[F] { - - /* We require type StatusMeta to handle our ADT Status */ - private implicit val StatusMeta: Meta[PetStatus] = - Meta[String].xmap(PetStatus.apply, PetStatus.nameOf) - - /* This is used to marshal our sets of strings */ - private implicit val SetStringMeta: Meta[Set[String]] = Meta[String] - .xmap(str => str.split(',').toSet, strSet => strSet.mkString(",")) - - def put(pet: Pet): F[Pet] = { - val insert: ConnectionIO[Pet] = - for { - id <- sql"REPLACE INTO PET (NAME, CATEGORY, BIO, STATUS, TAGS, PHOTO_URLS) values (${pet.name}, ${pet.category}, ${pet.bio}, ${pet.status}, ${pet.tags}, ${pet.photoUrls})".update - .withUniqueGeneratedKeys[Long]("ID") - } yield pet.copy(id = Some(id)) - insert.transact(xa) - } - - def get(id: Long): F[Option[Pet]] = - sql""" - SELECT NAME, CATEGORY, BIO, STATUS, TAGS, PHOTO_URLS, ID - FROM PET - WHERE ID = $id - """.query[Pet].option.transact(xa) - - def delete(id: Long): F[Option[Pet]] = - get(id).flatMap { - case Some(pet) => - sql"DELETE FROM PET WHERE ID = $id".update.run - .transact(xa) - .map(_ => Some(pet)) - case None => - none[Pet].pure[F] - } - - def findByNameAndCategory(name: String, category: String): F[Set[Pet]] = - sql"""SELECT NAME, CATEGORY, BIO, STATUS, TAGS, PHOTO_URLS, ID - FROM PET - WHERE NAME = $name AND CATEGORY = $category - """.query[Pet].list.transact(xa).map(_.toSet) - - def list(pageSize: Int, offset: Int): F[List[Pet]] = - sql"""SELECT NAME, CATEGORY, BIO, STATUS, TAGS, PHOTO_URLS, ID - FROM PET - ORDER BY NAME LIMIT $offset,$pageSize""" - .query[Pet] - .list - .transact(xa) - - def findByStatus(statuses: NonEmptyList[PetStatus]): F[List[Pet]] = - (sql"""SELECT NAME, CATEGORY, BIO, STATUS, TAGS, PHOTO_URLS, ID - FROM PET - WHERE """ ++ Fragments.in(fr"STATUS", statuses)) - .query[Pet] - .list - .transact(xa) - - def findByTag(tags: NonEmptyList[String]): F[List[Pet]] = { - /* Handle dynamic construction of query based on multiple parameters */ - - /* To piggyback off of comment of above reference about tags implementation, findByTag uses LIKE for partial matching - since tags is (currently) implemented as a comma-delimited string */ - val tagLikeString: String = tags.toList.mkString("TAGS LIKE '%", "%' OR TAGS LIKE '%", "%'") - (sql"""SELECT NAME, CATEGORY, BIO, STATUS, TAGS, PHOTO_URLS, ID - FROM PET - WHERE """ ++ Fragment.const(tagLikeString)) - .query[Pet] - .list - .transact(xa) - } -} - -object DoobiePetRepositoryInterpreter { - def apply[F[_]: Monad](xa: Transactor[F]): DoobiePetRepositoryInterpreter[F] = - new DoobiePetRepositoryInterpreter(xa) -} diff --git a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/repository/OrderRepositoryAlgebra.scala b/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/repository/OrderRepositoryAlgebra.scala deleted file mode 100644 index 79ade4be1bb..00000000000 --- a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/repository/OrderRepositoryAlgebra.scala +++ /dev/null @@ -1,14 +0,0 @@ -package io.github.pauljamescleary.petstore.repository - -import io.github.pauljamescleary.petstore.model.Order - -import scala.language.higherKinds - -trait OrderRepositoryAlgebra[F[_]] { - - def put(order: Order): F[Order] - - def get(orderId: Long): F[Option[Order]] - - def delete(orderId: Long): F[Option[Order]] -} diff --git a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/repository/OrderRepositoryInMemoryInterpreter.scala b/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/repository/OrderRepositoryInMemoryInterpreter.scala deleted file mode 100644 index 30ca74003a1..00000000000 --- a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/repository/OrderRepositoryInMemoryInterpreter.scala +++ /dev/null @@ -1,35 +0,0 @@ -package io.github.pauljamescleary.petstore.repository - -import cats._ -import cats.implicits._ -import io.github.pauljamescleary.petstore.model.Order - -import scala.collection.concurrent.TrieMap -import scala.util.Random - -class OrderRepositoryInMemoryInterpreter[F[_]: Applicative] extends OrderRepositoryAlgebra[F] { - - private val cache = new TrieMap[Long, Order] - - private val random = new Random - - override def put(order: Order): F[Order] = { - val toSave = - if (order.id.isDefined) order - else order.copy(id = Some(random.nextLong)) - - toSave.id.foreach { cache.put(_, toSave) } - toSave.pure[F] - } - - override def get(orderId: Long): F[Option[Order]] = - cache.get(orderId).pure[F] - - override def delete(orderId: Long): F[Option[Order]] = - cache.remove(orderId).pure[F] - -} - -object OrderRepositoryInMemoryInterpreter { - def apply[F[_]: Applicative]() = new OrderRepositoryInMemoryInterpreter[F]() -} diff --git a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/repository/PetRepositoryAlgebra.scala b/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/repository/PetRepositoryAlgebra.scala deleted file mode 100644 index 0404569b27f..00000000000 --- a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/repository/PetRepositoryAlgebra.scala +++ /dev/null @@ -1,23 +0,0 @@ -package io.github.pauljamescleary.petstore.repository - -import cats.data.NonEmptyList -import io.github.pauljamescleary.petstore.model.{Pet, PetStatus} - -import scala.language.higherKinds - -trait PetRepositoryAlgebra[F[_]] { - - def put(pet: Pet): F[Pet] - - def get(id: Long): F[Option[Pet]] - - def delete(id: Long): F[Option[Pet]] - - def findByNameAndCategory(name: String, category: String): F[Set[Pet]] - - def list(pageSize: Int, offset: Int): F[List[Pet]] - - def findByStatus(status: NonEmptyList[PetStatus]): F[List[Pet]] - - def findByTag(tags: NonEmptyList[String]): F[List[Pet]] -} diff --git a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/repository/PetRepositoryInMemoryInterpreter.scala b/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/repository/PetRepositoryInMemoryInterpreter.scala deleted file mode 100644 index dd285a7ced5..00000000000 --- a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/repository/PetRepositoryInMemoryInterpreter.scala +++ /dev/null @@ -1,47 +0,0 @@ -package io.github.pauljamescleary.petstore.repository - -import cats._ -import cats.implicits._ -import cats.data.NonEmptyList -import io.github.pauljamescleary.petstore.model.{Pet, PetStatus} - -import scala.collection.concurrent.TrieMap -import scala.util.Random - -class PetRepositoryInMemoryInterpreter[F[_]: Applicative] extends PetRepositoryAlgebra[F] { - - private val cache = new TrieMap[Long, Pet] - - private val random = new Random - - def put(pet: Pet): F[Pet] = { - val toSave = - if (pet.id.isDefined) pet else pet.copy(id = Some(random.nextLong)) - - toSave.id.foreach { cache.put(_, toSave) } - toSave.pure[F] - } - - def get(id: Long): F[Option[Pet]] = cache.get(id).pure[F] - - def delete(id: Long): F[Option[Pet]] = cache.remove(id).pure[F] - - def findByNameAndCategory(name: String, category: String): F[Set[Pet]] = - cache.values - .filter(p => p.name == name && p.category == category) - .toSet - .pure[F] - - def list(pageSize: Int, offset: Int): F[List[Pet]] = - cache.values.toList.sortBy(_.name).slice(offset, offset + pageSize).pure[F] - - def findByStatus(statuses: NonEmptyList[PetStatus]): F[List[Pet]] = - cache.values.filter(p => statuses.exists(_ == p.status)).toList.pure[F] - - def findByTag(tags: NonEmptyList[String]): F[List[Pet]] = - cache.values.filter(p => tags.exists(_ == p.tags)).toList.pure[F] -} - -object PetRepositoryInMemoryInterpreter { - def apply[F[_]: Applicative]() = new PetRepositoryInMemoryInterpreter[F]() -} diff --git a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/service/OrderService.scala b/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/service/OrderService.scala deleted file mode 100644 index 73e9e16aba7..00000000000 --- a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/service/OrderService.scala +++ /dev/null @@ -1,17 +0,0 @@ -package io.github.pauljamescleary.petstore.service - -import io.github.pauljamescleary.petstore.model.Order -import io.github.pauljamescleary.petstore.repository.OrderRepositoryAlgebra - -import scala.language.higherKinds - -class OrderService[F[_]](orderRepo: OrderRepositoryAlgebra[F]) { - - def placeOrder(order: Order): F[Order] = orderRepo.put(order) - -} - -object OrderService { - def apply[F[_]](orderRepo: OrderRepositoryAlgebra[F]): OrderService[F] = - new OrderService(orderRepo) -} diff --git a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/service/PetService.scala b/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/service/PetService.scala deleted file mode 100644 index f01af11ca96..00000000000 --- a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/service/PetService.scala +++ /dev/null @@ -1,63 +0,0 @@ -package io.github.pauljamescleary.petstore.service - -import cats._ -import cats.data._ -import io.github.pauljamescleary.petstore.model.{Pet, PetStatus} -import io.github.pauljamescleary.petstore.repository.PetRepositoryAlgebra -import io.github.pauljamescleary.petstore.validation.{ - PetNotFoundError, - PetValidationAlgebra, - ValidationError -} - -import scala.language.higherKinds - -/** - * The entry point to our domain, works with repositories and validations to implement behavior - * @param repository where we get our data - * @param validation something that provides validations to the service - * @tparam F - this is the container for the things we work with, could be scala.concurrent.Future, Option, anything - * as long as it is a Monad - */ -class PetService[F[_]](repository: PetRepositoryAlgebra[F], validation: PetValidationAlgebra[F]) { - import cats.syntax.all._ - - def create(pet: Pet)(implicit M: Monad[F]): EitherT[F, ValidationError, Pet] = - for { - _ <- validation.doesNotExist(pet) - saved <- EitherT.liftF(repository.put(pet)) - } yield saved - - /* Could argue that we could make this idempotent on put and not check if the pet exists */ - def update(pet: Pet)(implicit M: Monad[F]): EitherT[F, ValidationError, Pet] = - for { - _ <- validation.exists(pet.id) - saved <- EitherT.liftF(repository.put(pet)) - } yield saved - - def get(id: Long)(implicit M: Monad[F]): EitherT[F, ValidationError, Pet] = - EitherT { - repository.get(id).map { - case None => Left(PetNotFoundError) - case Some(found) => Right(found) - } - } - - /* In some circumstances we may care if we actually delete the pet; here we are idempotent and do not care */ - def delete(id: Long)(implicit M: Monad[F]): F[Unit] = - repository.delete(id).map(_ => ()) - - def list(pageSize: Int, offset: Int): F[List[Pet]] = - repository.list(pageSize, offset) - - def findByStatus(statuses: NonEmptyList[PetStatus]): F[List[Pet]] = - repository.findByStatus(statuses) - - def findByTag(tags: NonEmptyList[String]): F[List[Pet]] = - repository.findByTag(tags) -} - -object PetService { - def apply[F[_]: Monad](repository: PetRepositoryAlgebra[F], validation: PetValidationAlgebra[F]) = - new PetService[F](repository, validation) -} diff --git a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/validation/PetValidationAlgebra.scala b/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/validation/PetValidationAlgebra.scala deleted file mode 100644 index cb7ff6a01d5..00000000000 --- a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/validation/PetValidationAlgebra.scala +++ /dev/null @@ -1,19 +0,0 @@ -package io.github.pauljamescleary.petstore.validation - -import cats.data.EitherT -import io.github.pauljamescleary.petstore.model.Pet - -import scala.language.higherKinds - -sealed trait ValidationError extends Product with Serializable -final case class PetAlreadyExistsError(pet: Pet) extends ValidationError -final case object PetNotFoundError extends ValidationError - -trait PetValidationAlgebra[F[_]] { - - /* Fails with a PetAlreadyExistsError */ - def doesNotExist(pet: Pet): EitherT[F, ValidationError, Unit] - - /* Fails with a PetNotFoundError if the pet id does not exist or if it is none */ - def exists(petId: Option[Long]): EitherT[F, ValidationError, Unit] -} diff --git a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/validation/PetValidationInterpreter.scala b/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/validation/PetValidationInterpreter.scala deleted file mode 100644 index e3fb5fa1086..00000000000 --- a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/main/scala/io/github/pauljamescleary/petstore/validation/PetValidationInterpreter.scala +++ /dev/null @@ -1,42 +0,0 @@ -package io.github.pauljamescleary.petstore.validation - -import cats._ -import cats.implicits._ -import cats.data.EitherT -import io.github.pauljamescleary.petstore.model.Pet -import io.github.pauljamescleary.petstore.repository.PetRepositoryAlgebra - -class PetValidationInterpreter[F[_]: Monad](repository: PetRepositoryAlgebra[F]) - extends PetValidationAlgebra[F] { - - def doesNotExist(pet: Pet): EitherT[F, ValidationError, Unit] = EitherT { - repository.findByNameAndCategory(pet.name, pet.category).map { matches => - if (matches.forall(possibleMatch => possibleMatch.bio != pet.bio)) { - Right(()) - } else { - Left(PetAlreadyExistsError(pet)) - } - } - } - - def exists(petId: Option[Long]): EitherT[F, ValidationError, Unit] = - EitherT { - petId match { - case Some(id) => - // Ensure is a little tough to follow, it says "make sure this condition is true, otherwise throw the error specified - // In this example, we make sure that the option returned has a value, otherwise the pet was not found - repository.get(id).map { - case Some(_) => Right(()) - case _ => Left(PetNotFoundError) - } - - case _ => - Either.left[ValidationError, Unit](PetNotFoundError).pure[F] - } - } -} - -object PetValidationInterpreter { - def apply[F[_]: Monad](repository: PetRepositoryAlgebra[F]) = - new PetValidationInterpreter[F](repository) -} diff --git a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/test/scala/io/github/pauljamescleary/petstore/Arbitraries.scala b/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/test/scala/io/github/pauljamescleary/petstore/Arbitraries.scala deleted file mode 100644 index 097541a63e9..00000000000 --- a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/test/scala/io/github/pauljamescleary/petstore/Arbitraries.scala +++ /dev/null @@ -1,53 +0,0 @@ -package io.github.pauljamescleary.petstore - -import java.time.Instant - -import org.scalacheck._ -import org.scalacheck.Arbitrary.arbitrary -import io.github.pauljamescleary.petstore.model._ - -trait PetStoreArbitraries { - - implicit val instant = Arbitrary[Instant] { - for { - millis <- Gen.posNum[Long] - } yield Instant.ofEpochMilli(millis) - } - - implicit val orderStatus = Arbitrary[OrderStatus] { - Gen.oneOf(Approved, Delivered, Placed) - } - - implicit val order = Arbitrary[Order] { - for { - petId <- Gen.posNum[Long] - shipDate <- Gen.option(instant.arbitrary) - status <- arbitrary[OrderStatus] - complete <- arbitrary[Boolean] - id <- Gen.option(Gen.posNum[Long]) - } yield Order(petId, shipDate, status, complete, id) - } - - implicit val petStatus = Arbitrary[PetStatus] { - Gen.oneOf(Available, Pending, Adopted) - } - - implicit val pet = Arbitrary[Pet] { - for { - name <- arbitrary[String] - category <- arbitrary[String] - bio <- arbitrary[String] - status <- arbitrary[PetStatus] - numTags <- Gen.choose(0, 10) - tags <- Gen.listOfN(numTags, Gen.alphaStr).map(_.toSet) - photoUrls <- Gen - .listOfN(numTags, Gen.alphaStr) - .map(_.map(x => s"http://${x}.com")) - .map(_.toSet) - id <- Gen.option(Gen.posNum[Long]) - } yield Pet(name, category, bio, status, tags, photoUrls, id) - } - -} - -object PetStoreArbitraries extends PetStoreArbitraries diff --git a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/test/scala/io/github/pauljamescleary/petstore/endpoint/OrderEndointsSpec.scala b/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/test/scala/io/github/pauljamescleary/petstore/endpoint/OrderEndointsSpec.scala deleted file mode 100644 index c8ad7cff986..00000000000 --- a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/test/scala/io/github/pauljamescleary/petstore/endpoint/OrderEndointsSpec.scala +++ /dev/null @@ -1,51 +0,0 @@ -package io.github.pauljamescleary.petstore -package endpoint - -import cats.effect._ -import io.circe._ -import io.circe.generic.auto._ -import io.circe.generic.extras.semiauto._ -import io.circe.java8.time._ -import io.circe.syntax._ -import org.http4s._ -import org.http4s.dsl._ -import org.http4s.circe._ -import org.scalatest._ -import org.scalatest.prop.PropertyChecks - -import model._ -import repository._ -import service._ - -class OrderEndpointsSpec - extends FunSuite - with Matchers - with PropertyChecks - with PetStoreArbitraries - with Http4sDsl[IO] { - - implicit val statusDecoder: Decoder[OrderStatus] = deriveEnumerationDecoder - implicit val statusEncoder: Encoder[OrderStatus] = deriveEnumerationEncoder - - test("place order") { - - val orderService = OrderService(OrderRepositoryInMemoryInterpreter[IO]) - val orderHttpService = OrderEndpoints.endpoints[IO](orderService) - - forAll { (order: Order) => - val placeOrderReq = - Request[IO](Method.POST, Uri.uri("/orders")).withBody(order.asJson) - - (for { - request <- placeOrderReq - response <- orderHttpService - .run(request) - .getOrElse(fail(s"Request was not handled: $request")) - } yield { - response.status shouldEqual Ok - }).unsafeRunSync - } - - } - -} diff --git a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/test/scala/io/github/pauljamescleary/petstore/endpoint/PetEndpointsSpec.scala b/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/test/scala/io/github/pauljamescleary/petstore/endpoint/PetEndpointsSpec.scala deleted file mode 100644 index ce0e195d5a9..00000000000 --- a/scala/scala-impl/testdata/projectsForHighlightingTests/local/scala-pet-store/src/test/scala/io/github/pauljamescleary/petstore/endpoint/PetEndpointsSpec.scala +++ /dev/null @@ -1,82 +0,0 @@ -package io.github.pauljamescleary.petstore -package endpoint - -import cats.effect._ -import io.circe._ -import io.circe.syntax._ -import io.circe.generic.auto._ -import io.circe.generic.extras.semiauto._ -import org.http4s._ -import org.http4s.dsl._ -import org.http4s.circe._ -import org.scalatest._ -import org.scalatest.prop.PropertyChecks - -import model._ -import repository._ -import service._ -import validation._ - -class PetEndpointsSpec - extends FunSuite - with Matchers - with PropertyChecks - with PetStoreArbitraries - with Http4sDsl[IO] { - - implicit val statusDecoder: Decoder[PetStatus] = deriveEnumerationDecoder - implicit val statusEncoder: Encoder[PetStatus] = deriveEnumerationEncoder - - test("create pet") { - - val petRepo = PetRepositoryInMemoryInterpreter[IO]() - val petValidation = PetValidationInterpreter[IO](petRepo) - val petService = PetService[IO](petRepo, petValidation) - val petHttpService = PetEndpoints.endpoints[IO](petService) - - forAll { (pet: Pet) => - (for { - request <- Request[IO](Method.POST, Uri.uri("/pets")) - .withBody(pet.asJson) - response <- petHttpService - .run(request) - .getOrElse(fail(s"Request was not handled: $request")) - } yield { - response.status shouldEqual Ok - }).unsafeRunSync - } - - } - - test("update pet") { - - val petRepo = PetRepositoryInMemoryInterpreter[IO]() - val petValidation = PetValidationInterpreter[IO](petRepo) - val petService = PetService[IO](petRepo, petValidation) - val petHttpService = PetEndpoints.endpoints[IO](petService) - - implicit val petDecoder = jsonOf[IO, Pet] - - forAll { (pet: Pet) => - (for { - createRequest <- Request[IO](Method.POST, Uri.uri("/pets")) - .withBody(pet.asJson) - createResponse <- petHttpService - .run(createRequest) - .getOrElse(fail(s"Request was not handled: $createRequest")) - createdPet <- createResponse.as[Pet] - petToUpdate = createdPet.copy(name = createdPet.name.reverse) - updateRequest <- Request[IO](Method.PUT, Uri.uri("/pets")) - .withBody(petToUpdate.asJson) - updateResponse <- petHttpService - .run(updateRequest) - .getOrElse(fail(s"Request was not handled: $updateRequest")) - updatedPet <- updateResponse.as[Pet] - } yield { - updatedPet.name shouldEqual pet.name.reverse - }).unsafeRunSync - } - - } - -}