-
Notifications
You must be signed in to change notification settings - Fork 39
feat(scala-sdk): Integration test template #565
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
8942fc5
5f53aae
244123a
6661791
f6dc0b9
f6c9bc8
1175894
8beb5ba
6655a98
9e241c2
1e5dc9f
dce78fc
9571329
133dcd6
2cf37c1
9168f10
b2eaee1
a071073
364a3c9
abcd7bf
a66eb26
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -164,6 +164,61 @@ class ValueEntityTestKitGeneratorSuite extends munit.FunSuite { | |
| assertNoDiff(sourceCode, expected) | ||
| } | ||
|
|
||
| test("it can generate an specific integrationtest stub for the entity") { | ||
|
raboof marked this conversation as resolved.
Outdated
|
||
| val entity = createShoppingCartEntity() | ||
| val service = createShoppingCartService(entity) | ||
| val main = FullyQualifiedName("Main", packageNaming) | ||
|
|
||
| assertEquals( | ||
| ValueEntityTestKitGenerator.integrationTest(main, entity, service).content, | ||
| """package com.example.shoppingcart.api | ||
|
|
||
| import com.akkaserverless.scalasdk.testkit.AkkaServerlessTestkit | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we moving out of using the I don't mind. Maybe be even easier to read. Soon I will be write codegen for the replicated entity. I will use that new style then.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, this was not particularly intentional, I'm fine with either
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe be easier if we remove the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since we have mostly used |
||
| import com.akkaserverless.scalasdk.testkit.ValueEntityResult | ||
| import com.akkaserverless.scalasdk.valueentity.ValueEntity | ||
| import com.example.shoppingcart.domain | ||
| import com.google.protobuf.Empty | ||
| import org.scalatest.BeforeAndAfterAll | ||
| import org.scalatest.concurrent.ScalaFutures | ||
| import org.scalatest.matchers.should.Matchers | ||
| import org.scalatest.time.Millis | ||
| import org.scalatest.time.Seconds | ||
| import org.scalatest.time.Span | ||
| import org.scalatest.wordspec.AnyWordSpec | ||
| import undefined.Main | ||
|
|
||
| class ShoppingCartServiceIntegrationSpec | ||
| extends AnyWordSpec | ||
| with Matchers | ||
| with BeforeAndAfterAll | ||
| with ScalaFutures { | ||
|
|
||
| implicit val patience: PatienceConfig = | ||
| PatienceConfig(Span(5, Seconds), Span(500, Millis)) | ||
|
|
||
| val testkit = AkkaServerlessTestkit(Main.createAkkaServerless()) | ||
| testkit.start() | ||
| implicit val system = testkit.system | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is that needed for running streaming calls, or something else? wonder if we should not include it since it exposes a bit too much low level Akka? btw, if it's for streams we should have it as Materializer since that is what we have in the contexts
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's used for creating the Akka gRPC client
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah, we could have a grpcClient utility method similar to what we provide in the context. That would become more unified. Can be a separate ticket.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I created issue #568 for this idea |
||
|
|
||
| "ShoppingCartService" must { | ||
| val client: ShoppingCartServiceClient = | ||
| ShoppingCartServiceClient(testkit.grpcClientSettings) | ||
|
|
||
| "have example test that can be removed" in { | ||
| // use the gRPC client to send requests to the | ||
| // proxy and verify the results | ||
| } | ||
|
|
||
| } | ||
|
|
||
| override def afterAll() = { | ||
| testkit.stop() | ||
| super.afterAll() | ||
| } | ||
| } | ||
| """.stripMargin) | ||
| } | ||
|
|
||
| def createShoppingCartEntity(): ModelBuilder.ValueEntity = { | ||
|
|
||
| val domainProto = { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /* | ||
| * Copyright 2021 Lightbend Inc. | ||
| * | ||
| * 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. | ||
| */ | ||
|
|
||
| package com.akkaserverless.scalasdk.testkit | ||
|
|
||
| import akka.grpc.GrpcClientSettings | ||
| import com.akkaserverless.scalasdk.AkkaServerless | ||
| import com.akkaserverless.javasdk.testkit.{ AkkaServerlessTestkit => JTestKit } | ||
|
|
||
| /** | ||
| * Testkit for running Akka Serverless services locally. | ||
| * | ||
| * <p>Requires Docker for starting a local instance of the Akka Serverless proxy. | ||
| * | ||
| * <p>Create an AkkaServerlessTestkit with an {@link AkkaServerless} service descriptor, and then {@link #start} the | ||
| * testkit before testing the service with gRPC or HTTP clients. Call {@link #stop} after tests are complete. | ||
| */ | ||
| class AkkaServerlessTestkit(impl: JTestKit) { | ||
| def start() = impl.start() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpicking: We have been using |
||
|
|
||
| /** | ||
| * Get {@link GrpcClientSettings} for creating Akka gRPC clients. | ||
| * | ||
| * @return | ||
| * test gRPC client settings | ||
| */ | ||
| def grpcClientSettings: GrpcClientSettings = impl.getGrpcClientSettings() | ||
|
|
||
| def system = impl.getActorSystem() | ||
|
|
||
| def stop() = impl.stop() | ||
| } | ||
| object AkkaServerlessTestkit { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we have this at the top, since that is the starting point for using it? |
||
| def apply(main: AkkaServerless): AkkaServerlessTestkit = | ||
| new AkkaServerlessTestkit(new JTestKit(main.impl)) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we have these in test scope I wonder if there is a way to run all unit tests without these?
Thinking about
testOnly **Specbut that would include IntegrationSpec too. Shall we name the othersUnitSpecso thattestOnly **UnitSpecwould work?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*UnitSpeccould work, though it's a bit unfortunate when ideally you'd want to have many unit tests and few integration tests. The only alternative I can think of is using ScalaTest tagging, though that's a bit obscure.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created issue #571 for this thought