diff --git a/codegen/core/src/main/scala/com/lightbend/akkasls/codegen/Packaging.scala b/codegen/core/src/main/scala/com/lightbend/akkasls/codegen/Packaging.scala index 11ca32660b..c1ecbaf30b 100644 --- a/codegen/core/src/main/scala/com/lightbend/akkasls/codegen/Packaging.scala +++ b/codegen/core/src/main/scala/com/lightbend/akkasls/codegen/Packaging.scala @@ -56,31 +56,16 @@ case class PackageNaming( protoFileName: String, name: String, pkg: String, - goPackage: Option[String], + goPackageOption: Option[String], javaPackageOption: Option[String], - javaOuterClassname: String, + javaOuterClassnameOption: Option[String], javaMultipleFiles: Boolean) { lazy val javaPackage: String = javaPackageOption.getOrElse(pkg) - lazy val scalaPackage: String = javaPackage + def scalaPackage: String = javaPackage + def javaOuterClassname: String = javaOuterClassnameOption.getOrElse(name) } object PackageNaming { - def apply( - protoFileName: String, - name: String, - pkg: String, - goPackage: Option[String], - javaPackageOption: Option[String], - javaOuterClassnameOption: Option[String], - javaMultipleFiles: Boolean): PackageNaming = - PackageNaming( - protoFileName, - name, - pkg, - goPackage, - javaPackageOption, - javaOuterClassnameOption.getOrElse(name), - javaMultipleFiles) def from(descriptor: Descriptors.FileDescriptor): PackageNaming = { val name = @@ -126,7 +111,7 @@ object PackageNaming { descriptor.getPackage, goPackage, javaPackage, - javaOuterClassname, + Some(javaOuterClassname), javaMultipleFiles) } } diff --git a/codegen/core/src/main/scala/com/lightbend/akkasls/codegen/SourceGeneratorUtils.scala b/codegen/core/src/main/scala/com/lightbend/akkasls/codegen/SourceGeneratorUtils.scala index beeb9fd82c..2beacce36e 100644 --- a/codegen/core/src/main/scala/com/lightbend/akkasls/codegen/SourceGeneratorUtils.scala +++ b/codegen/core/src/main/scala/com/lightbend/akkasls/codegen/SourceGeneratorUtils.scala @@ -80,7 +80,7 @@ object SourceGeneratorUtils { def typeImport(fullyQualifiedName: FullyQualifiedName): String = { val name = if (fullyQualifiedName.parent.javaMultipleFiles) fullyQualifiedName.name - else if (fullyQualifiedName.parent.javaOuterClassname.nonEmpty) fullyQualifiedName.parent.javaOuterClassname + else if (fullyQualifiedName.parent.javaOuterClassnameOption.nonEmpty) fullyQualifiedName.parent.javaOuterClassname else fullyQualifiedName.name s"${fullyQualifiedName.parent.javaPackage}.$name" } diff --git a/codegen/core/src/test/scala/com/lightbend/akkasls/codegen/PackagingSuite.scala b/codegen/core/src/test/scala/com/lightbend/akkasls/codegen/PackagingSuite.scala index bdaf71ab61..ed76c9da5d 100644 --- a/codegen/core/src/test/scala/com/lightbend/akkasls/codegen/PackagingSuite.scala +++ b/codegen/core/src/test/scala/com/lightbend/akkasls/codegen/PackagingSuite.scala @@ -17,8 +17,10 @@ package com.lightbend.akkasls.codegen class PackagingSuite extends munit.FunSuite { + private val testData = TestData() + test("fqn should be able to produce filenames") { - val parent = TestData.domainProto() + val parent = testData.domainProto() val fqn = FullyQualifiedName("MyClass", parent) assertNoDiff(fqn.fileBasename + ".scala", "com/example/service/domain/MyClass.scala") diff --git a/codegen/core/src/test/scala/com/lightbend/akkasls/codegen/TestData.scala b/codegen/core/src/test/scala/com/lightbend/akkasls/codegen/TestData.scala index 7d003cd6f2..7426ebb171 100644 --- a/codegen/core/src/test/scala/com/lightbend/akkasls/codegen/TestData.scala +++ b/codegen/core/src/test/scala/com/lightbend/akkasls/codegen/TestData.scala @@ -16,10 +16,30 @@ package com.lightbend.akkasls.codegen +object TestData { + val defaultPackageNamingTemplate: PackageNaming = + PackageNaming( + "undefined.proto", + "Undefined", + "undefined", + None, + None, + Some("UndefinedOuterClass"), + javaMultipleFiles = false) + + def apply(): TestData = + apply(defaultPackageNamingTemplate) + + def apply(packageNamingTemplate: PackageNaming): TestData = { + new TestData(packageNamingTemplate) + } +} + /** * Used by java and scala codegen projects for their tests */ -object TestData { +class TestData(packageNamingTemplate: PackageNaming) { + def simple(): ModelBuilder.Model = { val service = simpleEntityService() val entity = valueEntity() @@ -29,24 +49,18 @@ object TestData { } def serviceProto(suffix: String = ""): PackageNaming = - PackageNaming( + packageNamingTemplate.copy( "my_service.proto", s"MyService$suffix", "com.example.service", - None, - None, - Some(s"ServiceOuterClass$suffix"), - javaMultipleFiles = false) + javaOuterClassnameOption = packageNamingTemplate.javaOuterClassnameOption.map(_ => s"ServiceOuterClass$suffix")) def domainProto(suffix: String = ""): PackageNaming = - PackageNaming( + packageNamingTemplate.copy( "domain.proto", s"Domain$suffix", "com.example.service.domain", - None, - None, - Some(s"EntityOuterClass$suffix"), - javaMultipleFiles = false) + javaOuterClassnameOption = packageNamingTemplate.javaOuterClassnameOption.map(_ => s"EntityOuterClass$suffix")) val externalProto: PackageNaming = PackageNaming("external_domain.proto", "ExternalDomain", "com.external", None, None, None, javaMultipleFiles = true) @@ -68,7 +82,7 @@ object TestData { streamedInput: Boolean = false, streamedOutput: Boolean = false, inFromTopic: Boolean = false, - outToTopic: Boolean = false) = + outToTopic: Boolean = false): ModelBuilder.Command = ModelBuilder.Command(name, inputType, outputType, streamedInput, streamedOutput, inFromTopic, outToTopic) def simpleEntityService(proto: PackageNaming = serviceProto(), suffix: String = ""): ModelBuilder.EntityService = diff --git a/codegen/java-gen/src/test/scala/com/lightbend/akkasls/codegen/java/ActionServiceSourceGeneratorSuite.scala b/codegen/java-gen/src/test/scala/com/lightbend/akkasls/codegen/java/ActionServiceSourceGeneratorSuite.scala index eee2f3d9c8..a7bb8328d2 100644 --- a/codegen/java-gen/src/test/scala/com/lightbend/akkasls/codegen/java/ActionServiceSourceGeneratorSuite.scala +++ b/codegen/java-gen/src/test/scala/com/lightbend/akkasls/codegen/java/ActionServiceSourceGeneratorSuite.scala @@ -17,13 +17,12 @@ package com.lightbend.akkasls.codegen package java -import com.lightbend.akkasls.codegen.TestData.serviceProto - class ActionServiceSourceGeneratorSuite extends munit.FunSuite { + private val testData = TestData() test("Action source generation") { - val service = TestData.simpleActionService() + val service = testData.simpleActionService() val generatedSrc = ActionServiceSourceGenerator.actionSource(service) @@ -75,8 +74,8 @@ class ActionServiceSourceGeneratorSuite extends munit.FunSuite { test("Action source generation with 'Action' in the name") { - val packageNaming = serviceProto().copy(name = "MyServiceAction") - val service = TestData.simpleActionService(packageNaming) + val packageNaming = testData.serviceProto().copy(name = "MyServiceAction") + val service = testData.simpleActionService(packageNaming) val generatedSrc = ActionServiceSourceGenerator.actionSource(service) @@ -127,7 +126,7 @@ class ActionServiceSourceGeneratorSuite extends munit.FunSuite { } test("Action abstract class source generation") { - val service = TestData.simpleActionService() + val service = testData.simpleActionService() val generatedSrc = ActionServiceSourceGenerator.abstractActionSource(service) @@ -166,8 +165,8 @@ class ActionServiceSourceGeneratorSuite extends munit.FunSuite { /** confirms that the generated abstract class doesn't get a 'Impl' in the name */ test("Action abstract class source generation with 'Action' in the name") { - val packageNaming = serviceProto().copy(name = "MyServiceAction") - val service = TestData.simpleActionService(packageNaming) + val packageNaming = testData.serviceProto().copy(name = "MyServiceAction") + val service = testData.simpleActionService(packageNaming) val generatedSrc = ActionServiceSourceGenerator.abstractActionSource(service) @@ -204,7 +203,7 @@ class ActionServiceSourceGeneratorSuite extends munit.FunSuite { } test("Action Handler source generation") { - val service = TestData.simpleActionService() + val service = testData.simpleActionService() val generatedSrc = ActionServiceSourceGenerator.actionHandler(service) @@ -279,8 +278,8 @@ class ActionServiceSourceGeneratorSuite extends munit.FunSuite { test("Action Handler source generation 'Action' in the name") { - val packageNaming = serviceProto().copy(name = "MyServiceAction") - val service = TestData.simpleActionService(packageNaming) + val packageNaming = testData.serviceProto().copy(name = "MyServiceAction") + val service = testData.simpleActionService(packageNaming) val generatedSrc = ActionServiceSourceGenerator.actionHandler(service) @@ -354,7 +353,7 @@ class ActionServiceSourceGeneratorSuite extends munit.FunSuite { } test("Action Provider source generation") { - val service = TestData.simpleActionService() + val service = testData.simpleActionService() val generatedSrc = ActionServiceSourceGenerator.actionProvider(service) @@ -431,8 +430,8 @@ class ActionServiceSourceGeneratorSuite extends munit.FunSuite { test("Action Provider source generation 'Action' in the name") { - val packageNaming = serviceProto().copy(name = "MyServiceAction") - val service = TestData.simpleActionService(packageNaming) + val packageNaming = testData.serviceProto().copy(name = "MyServiceAction") + val service = testData.simpleActionService(packageNaming) val generatedSrc = ActionServiceSourceGenerator.actionProvider(service) @@ -509,7 +508,7 @@ class ActionServiceSourceGeneratorSuite extends munit.FunSuite { test("Action with pub/sub source generation") { - val service = TestData.simpleJsonPubSubActionService() + val service = testData.simpleJsonPubSubActionService() val generatedSrc = ActionServiceSourceGenerator.actionSource(service) diff --git a/codegen/java-gen/src/test/scala/com/lightbend/akkasls/codegen/java/EventSourcedEntitySourceGeneratorSuite.scala b/codegen/java-gen/src/test/scala/com/lightbend/akkasls/codegen/java/EventSourcedEntitySourceGeneratorSuite.scala index 695f5a411b..87d4981cf7 100644 --- a/codegen/java-gen/src/test/scala/com/lightbend/akkasls/codegen/java/EventSourcedEntitySourceGeneratorSuite.scala +++ b/codegen/java-gen/src/test/scala/com/lightbend/akkasls/codegen/java/EventSourcedEntitySourceGeneratorSuite.scala @@ -18,11 +18,12 @@ package com.lightbend.akkasls.codegen package java class EventSourcedEntitySourceGeneratorSuite extends munit.FunSuite { + private val testData = TestData() test("EventSourcedEntity source") { - val entity = TestData.eventSourcedEntity() - val service = TestData.simpleEntityService() + val entity = testData.eventSourcedEntity() + val service = testData.simpleEntityService() val packageName = "com.example.service" val className = "MyServiceEntity" @@ -80,8 +81,8 @@ class EventSourcedEntitySourceGeneratorSuite extends munit.FunSuite { } test("Abstract EventSourcedEntity baseclass source") { - val service = TestData.simpleEntityService() - val entity = TestData.eventSourcedEntity() + val service = testData.simpleEntityService() + val entity = testData.eventSourcedEntity() val packageName = "com.example.service" val className = "MyServiceEntity" @@ -116,8 +117,8 @@ class EventSourcedEntitySourceGeneratorSuite extends munit.FunSuite { } test("EventSourcedEntity generated handler") { - val service = TestData.simpleEntityService() - val entity = TestData.eventSourcedEntity() + val service = testData.simpleEntityService() + val entity = testData.eventSourcedEntity() val packageName = "com.example.service" val className = "MyServiceEntity" @@ -177,8 +178,8 @@ class EventSourcedEntitySourceGeneratorSuite extends munit.FunSuite { } test("EventSourcedEntity Provider") { - val service = TestData.simpleEntityService() - val entity = TestData.eventSourcedEntity() + val service = testData.simpleEntityService() + val entity = testData.eventSourcedEntity() val packageName = "com.example.service" val className = "MyService" @@ -267,8 +268,8 @@ class EventSourcedEntitySourceGeneratorSuite extends munit.FunSuite { val mainPackageName = "com.example.service" val mainClassName = "SomeMain" - val service = TestData.simpleEntityService() - val entity = TestData.eventSourcedEntity() + val service = testData.simpleEntityService() + val entity = testData.eventSourcedEntity() val packageName = "com.example.service" val integrationTestClassName = "MyServiceEntityIntegrationTest" diff --git a/codegen/java-gen/src/test/scala/com/lightbend/akkasls/codegen/java/EventSourcedEntityTestKitGeneratorSuite.scala b/codegen/java-gen/src/test/scala/com/lightbend/akkasls/codegen/java/EventSourcedEntityTestKitGeneratorSuite.scala index 41e0ed6aba..1f188a10fd 100644 --- a/codegen/java-gen/src/test/scala/com/lightbend/akkasls/codegen/java/EventSourcedEntityTestKitGeneratorSuite.scala +++ b/codegen/java-gen/src/test/scala/com/lightbend/akkasls/codegen/java/EventSourcedEntityTestKitGeneratorSuite.scala @@ -17,10 +17,8 @@ package com.lightbend.akkasls.codegen package java -import com.lightbend.akkasls.codegen.TestData.command -import com.lightbend.akkasls.codegen.TestData.externalProto - class EventSourcedEntityTestKitGeneratorSuite extends munit.FunSuite { + private val testData = TestData() test( "it can generate an specific TestKit for the proto files " + @@ -269,15 +267,15 @@ class EventSourcedEntityTestKitGeneratorSuite extends munit.FunSuite { ModelBuilder.EntityService( FullyQualifiedName("ShoppingCartService", shoppingCartProto), List( - command( + testData.command( "AddItem", FullyQualifiedName("AddLineItem", shoppingCartProto), FullyQualifiedName("Empty", googleEmptyProto)), - command( + testData.command( "RemoveItem", FullyQualifiedName("RemoveLineItem", shoppingCartProto), FullyQualifiedName("Empty", googleEmptyProto)), - command( + testData.command( "GetCart", FullyQualifiedName("GetShoppingCart", shoppingCartProto), FullyQualifiedName("Cart", shoppingCartProto))), diff --git a/codegen/java-gen/src/test/scala/com/lightbend/akkasls/codegen/java/ReplicatedEntitySourceGeneratorSuite.scala b/codegen/java-gen/src/test/scala/com/lightbend/akkasls/codegen/java/ReplicatedEntitySourceGeneratorSuite.scala index 73945e91d9..83549f6126 100644 --- a/codegen/java-gen/src/test/scala/com/lightbend/akkasls/codegen/java/ReplicatedEntitySourceGeneratorSuite.scala +++ b/codegen/java-gen/src/test/scala/com/lightbend/akkasls/codegen/java/ReplicatedEntitySourceGeneratorSuite.scala @@ -29,6 +29,7 @@ import com.lightbend.akkasls.codegen.ModelBuilder.ReplicatedVote import com.lightbend.akkasls.codegen.ModelBuilder.TypeArgument class ReplicatedEntitySourceGeneratorSuite extends munit.FunSuite { + private val testData = TestData() def testEntityServiceImplementation( testName: String, @@ -39,8 +40,8 @@ class ReplicatedEntitySourceGeneratorSuite extends munit.FunSuite { test(s"Generated replicated entity service implementation - $testName") { assertNoDiff( ReplicatedEntitySourceGenerator.replicatedEntitySource( - service = TestData.simpleEntityService(), - entity = TestData.replicatedEntity(replicatedData), + service = testData.simpleEntityService(), + entity = testData.replicatedEntity(replicatedData), packageName = "com.example.service", className = "MyService"), s"""|/* This code was generated by Akka Serverless tooling. @@ -73,7 +74,7 @@ class ReplicatedEntitySourceGeneratorSuite extends munit.FunSuite { |""".stripMargin) } - def domainType(name: String): TypeArgument = TypeArgument(name, TestData.domainProto()) + def domainType(name: String): TypeArgument = TypeArgument(name, testData.domainProto()) testEntityServiceImplementation( "ReplicatedCounter", @@ -230,8 +231,8 @@ class ReplicatedEntitySourceGeneratorSuite extends munit.FunSuite { test(s"Generated abstract replicated entity service - ${replicatedData.name}") { assertNoDiff( EntityServiceSourceGenerator.interfaceSource( - service = TestData.simpleEntityService(), - entity = TestData.replicatedEntity(replicatedData), + service = testData.simpleEntityService(), + entity = testData.replicatedEntity(replicatedData), packageName = "com.example.service", className = "MyService"), s"""|/* This code is managed by Akka Serverless tooling. @@ -331,8 +332,8 @@ class ReplicatedEntitySourceGeneratorSuite extends munit.FunSuite { test(s"Generated replicated entity handler - ${replicatedData.name}") { assertNoDiff( ReplicatedEntitySourceGenerator.replicatedEntityHandler( - service = TestData.simpleEntityService(), - entity = TestData.replicatedEntity(replicatedData), + service = testData.simpleEntityService(), + entity = testData.replicatedEntity(replicatedData), packageName = "com.example.service", className = "MyService"), s"""|/* This code is managed by Akka Serverless tooling. @@ -446,8 +447,8 @@ class ReplicatedEntitySourceGeneratorSuite extends munit.FunSuite { test(s"Generated replicated entity provider - ${replicatedData.name}") { assertNoDiff( ReplicatedEntitySourceGenerator.replicatedEntityProvider( - service = TestData.simpleEntityService(), - entity = TestData.replicatedEntity(replicatedData), + service = testData.simpleEntityService(), + entity = testData.replicatedEntity(replicatedData), packageName = "com.example.service", className = "MyService"), s"""|/* This code is managed by Akka Serverless tooling. diff --git a/codegen/java-gen/src/test/scala/com/lightbend/akkasls/codegen/java/SourceGeneratorSuite.scala b/codegen/java-gen/src/test/scala/com/lightbend/akkasls/codegen/java/SourceGeneratorSuite.scala index 631aa5dfb7..fa688c0dcf 100644 --- a/codegen/java-gen/src/test/scala/com/lightbend/akkasls/codegen/java/SourceGeneratorSuite.scala +++ b/codegen/java-gen/src/test/scala/com/lightbend/akkasls/codegen/java/SourceGeneratorSuite.scala @@ -22,7 +22,6 @@ import org.slf4j.LoggerFactory import _root_.java.nio.file.Files import _root_.java.nio.file.Path -import scala.util.Try class SourceGeneratorSuite extends munit.FunSuite { val log = LoggerFactory.getLogger(getClass) @@ -31,8 +30,10 @@ class SourceGeneratorSuite extends munit.FunSuite { override def info(message: String): Unit = log.info(message) } + private val testData = TestData() + def domainType(name: String): ModelBuilder.TypeArgument = - ModelBuilder.TypeArgument(name, TestData.domainProto()) + ModelBuilder.TypeArgument(name, testData.domainProto()) test("generate") { val sourceDirectory = Files.createTempDirectory("source-generator-test") @@ -76,27 +77,27 @@ class SourceGeneratorSuite extends munit.FunSuite { FileUtils.touch(implSourceFile1) FileUtils.touch(implSourceFile2) - val service1Proto = TestData.serviceProto("1") - val service2Proto = TestData.serviceProto("2") + val service1Proto = testData.serviceProto("1") + val service2Proto = testData.serviceProto("2") val service3Proto = - TestData.serviceProto("3").copy(pkg = "com.example.service.something") - val service4Proto = TestData.serviceProto("4") - val service5Proto = TestData.serviceProto("5") - val service6Proto = TestData.serviceProto("6") + testData.serviceProto("3").copy(pkg = "com.example.service.something") + val service4Proto = testData.serviceProto("4") + val service5Proto = testData.serviceProto("5") + val service6Proto = testData.serviceProto("6") val services = Map( - "com.example.Service1" -> TestData.simpleEntityService(service1Proto, "1"), - "com.example.Service2" -> TestData.simpleEntityService(service2Proto, "2"), - "com.example.Service3" -> TestData.simpleEntityService(service3Proto, "3"), - "com.example.Service4" -> TestData.simpleViewService(service4Proto, "4"), - "com.example.Service5" -> TestData.simpleActionService(service5Proto), - "com.example.Service6" -> TestData.simpleEntityService(service6Proto, "6")) + "com.example.Service1" -> testData.simpleEntityService(service1Proto, "1"), + "com.example.Service2" -> testData.simpleEntityService(service2Proto, "2"), + "com.example.Service3" -> testData.simpleEntityService(service3Proto, "3"), + "com.example.Service4" -> testData.simpleViewService(service4Proto, "4"), + "com.example.Service5" -> testData.simpleActionService(service5Proto), + "com.example.Service6" -> testData.simpleEntityService(service6Proto, "6")) val entities = Map( - "com.example.Entity1" -> TestData.eventSourcedEntity(suffix = "1"), - "com.example.Entity2" -> TestData.valueEntity(suffix = "2"), - "com.example.Entity3" -> TestData.eventSourcedEntity(suffix = "3"), - "com.example.Entity6" -> TestData.replicatedEntity( + "com.example.Entity1" -> testData.eventSourcedEntity(suffix = "1"), + "com.example.Entity2" -> testData.valueEntity(suffix = "2"), + "com.example.Entity3" -> testData.eventSourcedEntity(suffix = "3"), + "com.example.Entity6" -> testData.replicatedEntity( ModelBuilder.ReplicatedSet(domainType("SomeElement")), suffix = "6")) @@ -169,26 +170,26 @@ class SourceGeneratorSuite extends munit.FunSuite { } test("generated component registration source") { - val service1Proto = TestData.serviceProto("1") - val service2Proto = TestData.serviceProto("2") - val service3Proto = TestData.serviceProto("3").copy(pkg = "com.example.service.something") - val service4Proto = TestData.serviceProto("4").copy(pkg = "com.example.service.view") - val service5Proto = TestData.serviceProto("5") - val service6Proto = TestData.serviceProto("6") + val service1Proto = testData.serviceProto("1") + val service2Proto = testData.serviceProto("2") + val service3Proto = testData.serviceProto("3").copy(pkg = "com.example.service.something") + val service4Proto = testData.serviceProto("4").copy(pkg = "com.example.service.view") + val service5Proto = testData.serviceProto("5") + val service6Proto = testData.serviceProto("6") val services = Map( - "com.example.Service1" -> TestData.simpleEntityService(service1Proto, "1"), - "com.example.Service2" -> TestData.simpleEntityService(service2Proto, "2"), - "com.example.Service3" -> TestData.simpleEntityService(service3Proto, "3"), - "com.example.Service4" -> TestData.simpleViewService(service4Proto, "4"), - "com.example.Service5" -> TestData.simpleActionService(service5Proto), - "com.example.Service6" -> TestData.simpleEntityService(service6Proto, "6")) + "com.example.Service1" -> testData.simpleEntityService(service1Proto, "1"), + "com.example.Service2" -> testData.simpleEntityService(service2Proto, "2"), + "com.example.Service3" -> testData.simpleEntityService(service3Proto, "3"), + "com.example.Service4" -> testData.simpleViewService(service4Proto, "4"), + "com.example.Service5" -> testData.simpleActionService(service5Proto), + "com.example.Service6" -> testData.simpleEntityService(service6Proto, "6")) val entities = Map( - "com.example.Entity1" -> TestData.eventSourcedEntity(suffix = "1"), - "com.example.Entity2" -> TestData.valueEntity(suffix = "2"), - "com.example.Entity3" -> TestData.eventSourcedEntity(suffix = "3"), - "com.example.Entity6" -> TestData.replicatedEntity( + "com.example.Entity1" -> testData.eventSourcedEntity(suffix = "1"), + "com.example.Entity2" -> testData.valueEntity(suffix = "2"), + "com.example.Entity3" -> testData.eventSourcedEntity(suffix = "3"), + "com.example.Entity6" -> testData.replicatedEntity( ModelBuilder.ReplicatedSet(domainType("SomeElement")), suffix = "6")) @@ -255,9 +256,9 @@ class SourceGeneratorSuite extends munit.FunSuite { } test("generated component registration source for a view without update handlers") { - val serviceProto = TestData.serviceProto().copy(pkg = "com.example.service.view") + val serviceProto = testData.serviceProto().copy(pkg = "com.example.service.view") - val services = Map("com.example.Service" -> TestData.simpleViewService(serviceProto).copy(transformedUpdates = Nil)) + val services = Map("com.example.Service" -> testData.simpleViewService(serviceProto).copy(transformedUpdates = Nil)) val entities = Map.empty[String, ModelBuilder.Entity] @@ -300,14 +301,14 @@ class SourceGeneratorSuite extends munit.FunSuite { val mainClassName = "SomeMain" val entities = Map( - "com.example.Entity1" -> TestData.eventSourcedEntity(suffix = "1"), - "com.example.Entity2" -> TestData.valueEntity(suffix = "2"), - "com.example.Entity3" -> TestData.eventSourcedEntity(suffix = "3"), - "com.example.Entity6" -> TestData.replicatedEntity( + "com.example.Entity1" -> testData.eventSourcedEntity(suffix = "1"), + "com.example.Entity2" -> testData.valueEntity(suffix = "2"), + "com.example.Entity3" -> testData.eventSourcedEntity(suffix = "3"), + "com.example.Entity6" -> testData.replicatedEntity( ModelBuilder.ReplicatedSet(domainType("SomeElement")), suffix = "6")) - val services = Map("com.example.Service1" -> TestData.simpleActionService()) + val services = Map("com.example.Service1" -> testData.simpleActionService()) val generatedSrc = SourceGenerator.mainSource(mainPackageName, mainClassName, entities, services) assertNoDiff( diff --git a/codegen/java-gen/src/test/scala/com/lightbend/akkasls/codegen/java/ValueEntitySourceGeneratorSuite.scala b/codegen/java-gen/src/test/scala/com/lightbend/akkasls/codegen/java/ValueEntitySourceGeneratorSuite.scala index 3d817662db..1675b6f06a 100644 --- a/codegen/java-gen/src/test/scala/com/lightbend/akkasls/codegen/java/ValueEntitySourceGeneratorSuite.scala +++ b/codegen/java-gen/src/test/scala/com/lightbend/akkasls/codegen/java/ValueEntitySourceGeneratorSuite.scala @@ -21,11 +21,12 @@ import com.lightbend.akkasls.codegen.TestData import munit.Location class ValueEntitySourceGeneratorSuite extends munit.FunSuite { + private val testData = TestData() test("ValueEntity source") { - val service = TestData.simpleEntityService() - val entity = TestData.valueEntity() + val service = testData.simpleEntityService() + val entity = testData.valueEntity() val packageName = "com.example.service" val className = "MyService" @@ -73,8 +74,8 @@ class ValueEntitySourceGeneratorSuite extends munit.FunSuite { } test("Abstract ValueEntity source") { - val service = TestData.simpleEntityService() - val entity = TestData.valueEntity() + val service = testData.simpleEntityService() + val entity = testData.valueEntity() val packageName = "com.example.service" val className = "MyService" @@ -106,8 +107,8 @@ class ValueEntitySourceGeneratorSuite extends munit.FunSuite { } test("ValueEntity generated handler") { - val service = TestData.simpleEntityService() - val entity = TestData.valueEntity() + val service = testData.simpleEntityService() + val entity = testData.valueEntity() val packageName = "com.example.service" val className = "MyService" @@ -158,8 +159,8 @@ class ValueEntitySourceGeneratorSuite extends munit.FunSuite { } test("ValueEntity Provider") { - val service = TestData.simpleEntityService() - val entity = TestData.valueEntity() + val service = testData.simpleEntityService() + val entity = testData.valueEntity() val packageName = "com.example.service" val className = "MyService" diff --git a/codegen/java-gen/src/test/scala/com/lightbend/akkasls/codegen/java/ValueEntityTestKitGeneratorSuite.scala b/codegen/java-gen/src/test/scala/com/lightbend/akkasls/codegen/java/ValueEntityTestKitGeneratorSuite.scala index df715447f8..12f5b8f7ef 100644 --- a/codegen/java-gen/src/test/scala/com/lightbend/akkasls/codegen/java/ValueEntityTestKitGeneratorSuite.scala +++ b/codegen/java-gen/src/test/scala/com/lightbend/akkasls/codegen/java/ValueEntityTestKitGeneratorSuite.scala @@ -19,9 +19,10 @@ package com.lightbend.akkasls.codegen.java import com.lightbend.akkasls.codegen.FullyQualifiedName import com.lightbend.akkasls.codegen.ModelBuilder import com.lightbend.akkasls.codegen.PackageNaming -import com.lightbend.akkasls.codegen.TestData.command +import com.lightbend.akkasls.codegen.TestData class ValueEntityTestKitGeneratorSuite extends munit.FunSuite { + private val testData = TestData() test( "it can generate an specific TestKit for the proto files " + @@ -243,15 +244,15 @@ class ValueEntityTestKitGeneratorSuite extends munit.FunSuite { ModelBuilder.EntityService( FullyQualifiedName("ShoppingCartService", shoppingCartProto), List( - command( + testData.command( "AddItem", FullyQualifiedName("AddLineItem", shoppingCartProto), FullyQualifiedName("Empty", googleEmptyProto)), - command( + testData.command( "RemoveItem", FullyQualifiedName("RemoveLineItem", shoppingCartProto), FullyQualifiedName("Empty", googleEmptyProto)), - command( + testData.command( "GetCart", FullyQualifiedName("GetShoppingCart", shoppingCartProto), FullyQualifiedName("Cart", shoppingCartProto))), diff --git a/codegen/java-gen/src/test/scala/com/lightbend/akkasls/codegen/java/ViewServiceSourceGeneratorSuite.scala b/codegen/java-gen/src/test/scala/com/lightbend/akkasls/codegen/java/ViewServiceSourceGeneratorSuite.scala index 39e6bde477..c83c5ef151 100644 --- a/codegen/java-gen/src/test/scala/com/lightbend/akkasls/codegen/java/ViewServiceSourceGeneratorSuite.scala +++ b/codegen/java-gen/src/test/scala/com/lightbend/akkasls/codegen/java/ViewServiceSourceGeneratorSuite.scala @@ -18,9 +18,10 @@ package com.lightbend.akkasls.codegen package java class ViewServiceSourceGeneratorSuite extends munit.FunSuite { + private val testData = TestData() test("source, transform_updates=true") { - val service = TestData.simpleViewService() + val service = testData.simpleViewService() val packageName = "com.example.service" val generatedSrc = @@ -60,7 +61,7 @@ class ViewServiceSourceGeneratorSuite extends munit.FunSuite { } test("source, transform_updates=false") { - val service = TestData.simpleViewService().copy(transformedUpdates = Nil) + val service = testData.simpleViewService().copy(transformedUpdates = Nil) val packageName = "com.example.service" val generatedSrc = @@ -86,7 +87,7 @@ class ViewServiceSourceGeneratorSuite extends munit.FunSuite { } test("abstract source, transform_updates=true") { - val service = TestData.simpleViewService() + val service = testData.simpleViewService() val packageName = "com.example.service" val generatedSrc = @@ -113,7 +114,7 @@ class ViewServiceSourceGeneratorSuite extends munit.FunSuite { } test("abstract source, transform_updates=false") { - val service = TestData.simpleViewService().copy(transformedUpdates = Nil) + val service = testData.simpleViewService().copy(transformedUpdates = Nil) val packageName = "com.example.service" val generatedSrc = @@ -142,7 +143,7 @@ class ViewServiceSourceGeneratorSuite extends munit.FunSuite { } test("handler source") { - val service = TestData.simpleViewService() + val service = testData.simpleViewService() val packageName = "com.example.service" val generatedSrc = @@ -195,7 +196,7 @@ class ViewServiceSourceGeneratorSuite extends munit.FunSuite { } test("provider source") { - val service = TestData.simpleViewService() + val service = testData.simpleViewService() val packageName = "com.example.service" val generatedSrc = diff --git a/codegen/scala-gen/src/main/scala/com/akkaserverless/codegen/scalasdk/impl/ViewServiceSourceGenerator.scala b/codegen/scala-gen/src/main/scala/com/akkaserverless/codegen/scalasdk/impl/ViewServiceSourceGenerator.scala index 242f6080d7..03464cfed5 100644 --- a/codegen/scala-gen/src/main/scala/com/akkaserverless/codegen/scalasdk/impl/ViewServiceSourceGenerator.scala +++ b/codegen/scala-gen/src/main/scala/com/akkaserverless/codegen/scalasdk/impl/ViewServiceSourceGenerator.scala @@ -35,7 +35,7 @@ object ViewServiceSourceGenerator { val packageName = service.fqn.parent.scalaPackage val packagePath = packageAsPath(packageName) - generatedSources += File(s"$packagePath/${service.className}.scala", viewSource(service, packageName)) + generatedSources += File(s"$packagePath/${service.className}.scala", viewSource(service)) generatedSources.result() } @@ -49,46 +49,47 @@ object ViewServiceSourceGenerator { val packageName = service.fqn.parent.scalaPackage val packagePath = packageAsPath(packageName) - generatedSources += File(s"$packagePath/${service.abstractViewName}.scala", abstractView(service, packageName)) - generatedSources += File(s"$packagePath/${service.handlerName}.scala", viewHandler(service, packageName)) - generatedSources += File(s"$packagePath/${service.providerName}.scala", viewProvider(service, packageName)) + generatedSources += File(s"$packagePath/${service.abstractViewName}.scala", abstractView(service)) + generatedSources += File(s"$packagePath/${service.handlerName}.scala", viewHandler(service)) + generatedSources += File(s"$packagePath/${service.providerName}.scala", viewProvider(service)) generatedSources.result() } - private[codegen] def viewHandler(view: ModelBuilder.ViewService, packageName: String): String = { - val imports = generateCommandImports( - view.commands, - view.state, - packageName, - otherImports = Seq( - "com.akkaserverless.javasdk.impl.view.UpdateHandlerNotFound", - "com.akkaserverless.scalasdk.impl.view.ViewHandler", - "com.akkaserverless.scalasdk.view.View"), - semi = false) + private[codegen] def viewHandler(view: ModelBuilder.ViewService): String = { + implicit val imports = + generateImports( + Seq(view.state.fqn) ++ view.commandTypes, + view.fqn.parent.scalaPackage, + otherImports = Seq( + "com.akkaserverless.javasdk.impl.view.UpdateHandlerNotFound", + "com.akkaserverless.scalasdk.impl.view.ViewHandler", + "com.akkaserverless.scalasdk.view.View"), + packageImports = Nil, + semi = false) val cases = view.transformedUpdates .map { cmd => val methodName = cmd.name - val inputType = qualifiedType(cmd.inputType) s"""|case "$methodName" => | view.${lowerFirst(methodName)}( | state, - | event.asInstanceOf[$inputType]) + | event.asInstanceOf[${typeName(cmd.inputType)}]) |""".stripMargin } - s"""|package $packageName + s"""|package ${view.fqn.parent.scalaPackage} | |$imports | |/** A view handler */ - |class ${view.handlerName}(view: ${view.className}) extends ViewHandler[${qualifiedType(view.state.fqn)}, ${view.className}](view) { + |class ${view.handlerName}(view: ${view.className}) + | extends ViewHandler[${typeName(view.state.fqn)}, ${view.className}](view) { | | override def handleUpdate( | eventName: String, - | state: ${qualifiedType(view.state.fqn)}, - | event: Any): View.UpdateEffect[${qualifiedType(view.state.fqn)}] = { + | state: ${typeName(view.state.fqn)}, + | event: Any): View.UpdateEffect[${typeName(view.state.fqn)}] = { | | eventName match { | ${Format.indent(cases, 6)} @@ -102,24 +103,25 @@ object ViewServiceSourceGenerator { |""".stripMargin } - private[codegen] def viewProvider(view: ModelBuilder.ViewService, packageName: String): String = { - val imports = generateCommandImports( - Nil, - view.state, - packageName, - otherImports = Seq( - "com.akkaserverless.javasdk.impl.view.UpdateHandlerNotFound", - "com.akkaserverless.scalasdk.impl.view.ViewHandler", - "com.akkaserverless.scalasdk.view.ViewProvider", - "com.akkaserverless.scalasdk.view.ViewCreationContext", - "com.akkaserverless.scalasdk.view.View", - view.classNameQualified, - "com.google.protobuf.Descriptors", - "com.google.protobuf.EmptyProto", - "scala.collection.immutable"), - semi = false) - - s"""|package $packageName + private[codegen] def viewProvider(view: ModelBuilder.ViewService): String = { + implicit val imports = + generateImports( + Seq(view.state.fqn), + view.fqn.parent.scalaPackage, + otherImports = Seq( + "com.akkaserverless.javasdk.impl.view.UpdateHandlerNotFound", + "com.akkaserverless.scalasdk.impl.view.ViewHandler", + "com.akkaserverless.scalasdk.view.ViewProvider", + "com.akkaserverless.scalasdk.view.ViewCreationContext", + "com.akkaserverless.scalasdk.view.View", + view.classNameQualified, + "com.google.protobuf.Descriptors", + "com.google.protobuf.EmptyProto", + "scala.collection.immutable"), + packageImports = Nil, + semi = false) + + s"""|package ${view.fqn.parent.scalaPackage} | |$imports | @@ -130,7 +132,7 @@ object ViewServiceSourceGenerator { | |class ${view.providerName} private(viewFactory: Function[ViewCreationContext, ${view.className}], | override val viewId: String) - | extends ViewProvider[${qualifiedType(view.state.fqn)}, ${view.className}] { + | extends ViewProvider[${typeName(view.state.fqn)}, ${view.className}] { | | /** | * Use a custom view identifier. By default, the viewId is the same as the proto service name. @@ -140,44 +142,45 @@ object ViewServiceSourceGenerator { | new ${view.providerName}(viewFactory, viewId) | | override final def serviceDescriptor: Descriptors.ServiceDescriptor = - | ${view.fqn.parent.javaOuterClassname}.getDescriptor().findServiceByName("${view.fqn.protoName}") + | ${view.fqn.parent.name}Proto.javaDescriptor.findServiceByName("${view.fqn.protoName}") | | override final def newHandler(context: ViewCreationContext): ${view.handlerName} = | new ${view.handlerName}(viewFactory(context)) | | override final def additionalDescriptors: immutable.Seq[Descriptors.FileDescriptor] = - | ${view.fqn.parent.javaOuterClassname}.getDescriptor() :: + | ${view.fqn.parent.name}Proto.javaDescriptor :: | Nil |} |""".stripMargin } - private[codegen] def viewSource(view: ModelBuilder.ViewService, packageName: String): String = { - - val imports = + private[codegen] def viewSource(view: ModelBuilder.ViewService): String = { + implicit val imports = generateImports( - view.commandTypes, - packageName, - Seq("com.akkaserverless.scalasdk.view.View.UpdateEffect", "com.akkaserverless.scalasdk.view.ViewContext"), + Seq(view.state.fqn) ++ view.commandTypes, + view.fqn.parent.scalaPackage, + otherImports = + Seq("com.akkaserverless.scalasdk.view.View.UpdateEffect", "com.akkaserverless.scalasdk.view.ViewContext"), + packageImports = Nil, semi = false) val emptyState = if (view.transformedUpdates.isEmpty) "" else - s"""| override def emptyState: ${qualifiedType(view.state.fqn)} = + s"""| override def emptyState: ${typeName(view.state.fqn)} = | throw new UnsupportedOperationException("Not implemented yet, replace with your empty view state") |""".stripMargin val handlers = view.transformedUpdates.map { update => - val stateType = qualifiedType(update.outputType) + val stateType = typeName(update.outputType) s"""override def ${lowerFirst(update.name)}( - | state: $stateType, ${lowerFirst(update.inputType.name)}: ${qualifiedType(update.inputType)}): UpdateEffect[$stateType] = + | state: $stateType, ${lowerFirst(update.inputType.name)}: ${typeName(update.inputType)}): UpdateEffect[$stateType] = | throw new UnsupportedOperationException("Update handler for '${update.name}' not implemented yet") |""".stripMargin } - s"""|package $packageName + s"""|package ${view.fqn.parent.scalaPackage} | |$imports | @@ -189,31 +192,36 @@ object ViewServiceSourceGenerator { |""".stripMargin } - private[codegen] def abstractView(view: ModelBuilder.ViewService, packageName: String): String = { - val imports = - generateImports(view.commandTypes, packageName, Seq("com.akkaserverless.scalasdk.view.View"), semi = false) + private[codegen] def abstractView(view: ModelBuilder.ViewService): String = { + implicit val imports = + generateImports( + Seq(view.state.fqn) ++ view.commandTypes, + view.fqn.parent.scalaPackage, + otherImports = Seq("com.akkaserverless.scalasdk.view.View"), + packageImports = Nil, + semi = false) val emptyState = if (view.transformedUpdates.isEmpty) - s"""| override def emptyState: ${qualifiedType(view.state.fqn)} = + s"""| override def emptyState: ${typeName(view.state.fqn)} = | null // emptyState is only used with transform_updates=true |""".stripMargin else "" val handlers = view.transformedUpdates.map { update => - val stateType = qualifiedType(update.outputType) + val stateType = typeName(update.outputType) s"""def ${lowerFirst(update.name)}( - | state: $stateType, ${lowerFirst(update.inputType.name)}: ${qualifiedType( + | state: $stateType, ${lowerFirst(update.inputType.name)}: ${typeName( update.inputType)}): View.UpdateEffect[$stateType]""".stripMargin } - s"""|package $packageName + s"""|package ${view.fqn.parent.scalaPackage} | |$imports | - |abstract class ${view.abstractViewName} extends View[${qualifiedType(view.state.fqn)}] { + |abstract class ${view.abstractViewName} extends View[${typeName(view.state.fqn)}] { | |$emptyState | ${Format.indent(handlers, 2)} diff --git a/codegen/scala-gen/src/test/scala/com/akkaserverless/codegen/scalasdk/SourceGeneratorSuite.scala b/codegen/scala-gen/src/test/scala/com/akkaserverless/codegen/scalasdk/SourceGeneratorSuite.scala index cf48ecedaf..2458f544fa 100644 --- a/codegen/scala-gen/src/test/scala/com/akkaserverless/codegen/scalasdk/SourceGeneratorSuite.scala +++ b/codegen/scala-gen/src/test/scala/com/akkaserverless/codegen/scalasdk/SourceGeneratorSuite.scala @@ -22,8 +22,10 @@ class SourceGeneratorSuite extends munit.FunSuite { import com.akkaserverless.codegen.scalasdk.impl.SourceGenerator._ import com.lightbend.akkasls.codegen.SourceGeneratorUtils._ + private val testData = TestData() + test("it can generate a simple 'main'") { - val main = generateMain(TestData.simple()) + val main = generateMain(testData.simple()) assertNoDiff(main.name, "com/example/Main.scala") assertNoDiff( main.content, diff --git a/codegen/scala-gen/src/test/scala/com/akkaserverless/codegen/scalasdk/ValueEntitySourceGeneratorSuite.scala b/codegen/scala-gen/src/test/scala/com/akkaserverless/codegen/scalasdk/ValueEntitySourceGeneratorSuite.scala index 65f3e2418c..f38487002f 100644 --- a/codegen/scala-gen/src/test/scala/com/akkaserverless/codegen/scalasdk/ValueEntitySourceGeneratorSuite.scala +++ b/codegen/scala-gen/src/test/scala/com/akkaserverless/codegen/scalasdk/ValueEntitySourceGeneratorSuite.scala @@ -24,12 +24,14 @@ import scalapb.compiler.{ DescriptorImplicits, GeneratorParams } class ValueEntitySourceGeneratorSuite extends munit.FunSuite { import com.akkaserverless.codegen.scalasdk.impl.ValueEntitySourceGenerator._ + private val testData = TestData() + val domainParent = PackageNaming("domain.proto", "", "com.example.service.domain", None, None, None, false) val apiParent = PackageNaming("api.proto", "", "com.example.service", None, None, None, false) test("it can generate a value entity implementation skeleton") { val file = - generateImplementationSkeleton(TestData.valueEntity(domainParent), TestData.simpleEntityService(apiParent)) + generateImplementationSkeleton(testData.valueEntity(domainParent), testData.simpleEntityService(apiParent)) assertNoDiff( file.content, s"""package com.example.service.domain diff --git a/codegen/scala-gen/src/test/scala/com/akkaserverless/codegen/scalasdk/ViewServiceSourceGeneratorSuite.scala b/codegen/scala-gen/src/test/scala/com/akkaserverless/codegen/scalasdk/ViewServiceSourceGeneratorSuite.scala index 4c0f8f6504..4bda3f9cee 100644 --- a/codegen/scala-gen/src/test/scala/com/akkaserverless/codegen/scalasdk/ViewServiceSourceGeneratorSuite.scala +++ b/codegen/scala-gen/src/test/scala/com/akkaserverless/codegen/scalasdk/ViewServiceSourceGeneratorSuite.scala @@ -20,50 +20,49 @@ import com.akkaserverless.codegen.scalasdk.impl.ViewServiceSourceGenerator import com.lightbend.akkasls.codegen.TestData class ViewServiceSourceGeneratorSuite extends munit.FunSuite { + private val testData = TestData(TestData.defaultPackageNamingTemplate.copy(javaOuterClassnameOption = None)) test("source, transform_updates=true") { - val service = TestData.simpleViewService() + val service = testData.simpleViewService() - val packageName = "com.example.service" - val generatedSrc = - ViewServiceSourceGenerator.viewSource(service, packageName) + val generatedSrc = ViewServiceSourceGenerator.viewSource(service) assertNoDiff( generatedSrc, """|package com.example.service | |import com.akkaserverless.scalasdk.view.View.UpdateEffect |import com.akkaserverless.scalasdk.view.ViewContext - |import com.example.service.domain.EntityOuterClass + |import com.example.service.domain.EntityCreated + |import com.example.service.domain.EntityUpdated | |class MyServiceViewImpl(context: ViewContext) extends AbstractMyServiceView { | - | override def emptyState: ServiceOuterClass.ViewState = + | override def emptyState: ViewState = | throw new UnsupportedOperationException("Not implemented yet, replace with your empty view state") | | override def created( - | state: ServiceOuterClass.ViewState, entityCreated: EntityOuterClass.EntityCreated): UpdateEffect[ServiceOuterClass.ViewState] = + | state: ViewState, entityCreated: EntityCreated): UpdateEffect[ViewState] = | throw new UnsupportedOperationException("Update handler for 'Created' not implemented yet") | | override def updated( - | state: ServiceOuterClass.ViewState, entityUpdated: EntityOuterClass.EntityUpdated): UpdateEffect[ServiceOuterClass.ViewState] = + | state: ViewState, entityUpdated: EntityUpdated): UpdateEffect[ViewState] = | throw new UnsupportedOperationException("Update handler for 'Updated' not implemented yet") |} |""".stripMargin) } test("source, transform_updates=false") { - val service = TestData.simpleViewService().copy(transformedUpdates = Nil) + val service = testData.simpleViewService().copy(transformedUpdates = Nil) - val packageName = "com.example.service" - val generatedSrc = - ViewServiceSourceGenerator.viewSource(service, packageName) + val generatedSrc = ViewServiceSourceGenerator.viewSource(service) assertNoDiff( generatedSrc, """|package com.example.service | |import com.akkaserverless.scalasdk.view.View.UpdateEffect |import com.akkaserverless.scalasdk.view.ViewContext - |import com.example.service.domain.EntityOuterClass + |import com.example.service.domain.EntityCreated + |import com.example.service.domain.EntityUpdated | |class MyServiceViewImpl(context: ViewContext) extends AbstractMyServiceView { | @@ -74,45 +73,43 @@ class ViewServiceSourceGeneratorSuite extends munit.FunSuite { } test("abstract source, transform_updates=true") { - val service = TestData.simpleViewService() - val packageName = "com.example.service" + val service = testData.simpleViewService() - val generatedSrc = - ViewServiceSourceGenerator.abstractView(service, packageName) + val generatedSrc = ViewServiceSourceGenerator.abstractView(service) assertNoDiff( generatedSrc, """|package com.example.service | |import com.akkaserverless.scalasdk.view.View - |import com.example.service.domain.EntityOuterClass + |import com.example.service.domain.EntityCreated + |import com.example.service.domain.EntityUpdated | - |abstract class AbstractMyServiceView extends View[ServiceOuterClass.ViewState] { + |abstract class AbstractMyServiceView extends View[ViewState] { | | | def created( - | state: ServiceOuterClass.ViewState, entityCreated: EntityOuterClass.EntityCreated): View.UpdateEffect[ServiceOuterClass.ViewState] + | state: ViewState, entityCreated: EntityCreated): View.UpdateEffect[ViewState] | def updated( - | state: ServiceOuterClass.ViewState, entityUpdated: EntityOuterClass.EntityUpdated): View.UpdateEffect[ServiceOuterClass.ViewState] + | state: ViewState, entityUpdated: EntityUpdated): View.UpdateEffect[ViewState] |} |""".stripMargin) } test("abstract source, transform_updates=false") { - val service = TestData.simpleViewService().copy(transformedUpdates = Nil) - val packageName = "com.example.service" + val service = testData.simpleViewService().copy(transformedUpdates = Nil) - val generatedSrc = - ViewServiceSourceGenerator.abstractView(service, packageName) + val generatedSrc = ViewServiceSourceGenerator.abstractView(service) assertNoDiff( generatedSrc, """|package com.example.service | |import com.akkaserverless.scalasdk.view.View - |import com.example.service.domain.EntityOuterClass + |import com.example.service.domain.EntityCreated + |import com.example.service.domain.EntityUpdated | - |abstract class AbstractMyServiceView extends View[ServiceOuterClass.ViewState] { + |abstract class AbstractMyServiceView extends View[ViewState] { | - | override def emptyState: ServiceOuterClass.ViewState = + | override def emptyState: ViewState = | null // emptyState is only used with transform_updates=true | | @@ -121,11 +118,9 @@ class ViewServiceSourceGeneratorSuite extends munit.FunSuite { } test("handler source") { - val service = TestData.simpleViewService() - val packageName = "com.example.service" + val service = testData.simpleViewService() - val generatedSrc = - ViewServiceSourceGenerator.viewHandler(service, packageName) + val generatedSrc = ViewServiceSourceGenerator.viewHandler(service) assertNoDiff( generatedSrc, @@ -134,26 +129,28 @@ class ViewServiceSourceGeneratorSuite extends munit.FunSuite { |import com.akkaserverless.javasdk.impl.view.UpdateHandlerNotFound |import com.akkaserverless.scalasdk.impl.view.ViewHandler |import com.akkaserverless.scalasdk.view.View - |import com.example.service.domain.EntityOuterClass + |import com.example.service.domain.EntityCreated + |import com.example.service.domain.EntityUpdated | |/** A view handler */ - |class MyServiceViewHandler(view: MyServiceViewImpl) extends ViewHandler[ServiceOuterClass.ViewState, MyServiceViewImpl](view) { + |class MyServiceViewHandler(view: MyServiceViewImpl) + | extends ViewHandler[ViewState, MyServiceViewImpl](view) { | | override def handleUpdate( | eventName: String, - | state: ServiceOuterClass.ViewState, - | event: Any): View.UpdateEffect[ServiceOuterClass.ViewState] = { + | state: ViewState, + | event: Any): View.UpdateEffect[ViewState] = { | | eventName match { | case "Created" => | view.created( | state, - | event.asInstanceOf[EntityOuterClass.EntityCreated]) + | event.asInstanceOf[EntityCreated]) | | case "Updated" => | view.updated( | state, - | event.asInstanceOf[EntityOuterClass.EntityUpdated]) + | event.asInstanceOf[EntityUpdated]) | | case _ => | throw new UpdateHandlerNotFound(eventName) @@ -165,11 +162,9 @@ class ViewServiceSourceGeneratorSuite extends munit.FunSuite { } test("provider source") { - val service = TestData.simpleViewService() - val packageName = "com.example.service" + val service = testData.simpleViewService() - val generatedSrc = - ViewServiceSourceGenerator.viewProvider(service, packageName) + val generatedSrc = ViewServiceSourceGenerator.viewProvider(service) assertNoDiff( generatedSrc, @@ -192,7 +187,7 @@ class ViewServiceSourceGeneratorSuite extends munit.FunSuite { | |class MyServiceViewProvider private(viewFactory: Function[ViewCreationContext, MyServiceViewImpl], | override val viewId: String) - | extends ViewProvider[ServiceOuterClass.ViewState, MyServiceViewImpl] { + | extends ViewProvider[ViewState, MyServiceViewImpl] { | | /** | * Use a custom view identifier. By default, the viewId is the same as the proto service name. @@ -202,13 +197,13 @@ class ViewServiceSourceGeneratorSuite extends munit.FunSuite { | new MyServiceViewProvider(viewFactory, viewId) | | override final def serviceDescriptor: Descriptors.ServiceDescriptor = - | ServiceOuterClass.getDescriptor().findServiceByName("MyService") + | MyServiceProto.javaDescriptor.findServiceByName("MyService") | | override final def newHandler(context: ViewCreationContext): MyServiceViewHandler = | new MyServiceViewHandler(viewFactory(context)) | | override final def additionalDescriptors: immutable.Seq[Descriptors.FileDescriptor] = - | ServiceOuterClass.getDescriptor() :: + | MyServiceProto.javaDescriptor :: | Nil |} |""".stripMargin) diff --git a/samples/scala-value-entity-customer-registry/src/main/proto/customer/action/customer_action.proto b/samples/scala-value-entity-customer-registry/src/main/proto/customer/action/customer_action.proto index f5084841e8..ab6ae4c88d 100644 --- a/samples/scala-value-entity-customer-registry/src/main/proto/customer/action/customer_action.proto +++ b/samples/scala-value-entity-customer-registry/src/main/proto/customer/action/customer_action.proto @@ -16,8 +16,6 @@ syntax = "proto3"; package customer.action; -option java_outer_classname = "CustomerActionModel"; - import "google/protobuf/empty.proto"; import "akkaserverless/annotations.proto"; import "customer/api/customer_api.proto"; @@ -29,4 +27,4 @@ service CustomerAction { }; rpc Create(api.Customer) returns (google.protobuf.Empty) { } -} \ No newline at end of file +} diff --git a/samples/scala-value-entity-customer-registry/src/main/proto/customer/api/customer_api.proto b/samples/scala-value-entity-customer-registry/src/main/proto/customer/api/customer_api.proto index ce5c0e5bc4..4f8f7177db 100644 --- a/samples/scala-value-entity-customer-registry/src/main/proto/customer/api/customer_api.proto +++ b/samples/scala-value-entity-customer-registry/src/main/proto/customer/api/customer_api.proto @@ -16,8 +16,6 @@ syntax = "proto3"; package customer.api; -option java_outer_classname = "CustomerApi"; - import "google/protobuf/empty.proto"; import "akkaserverless/annotations.proto"; diff --git a/samples/scala-value-entity-customer-registry/src/main/proto/customer/domain/customer_domain.proto b/samples/scala-value-entity-customer-registry/src/main/proto/customer/domain/customer_domain.proto index 2982f2c02c..c6dad6bc33 100644 --- a/samples/scala-value-entity-customer-registry/src/main/proto/customer/domain/customer_domain.proto +++ b/samples/scala-value-entity-customer-registry/src/main/proto/customer/domain/customer_domain.proto @@ -17,8 +17,6 @@ syntax = "proto3"; package customer.domain; -option java_outer_classname = "CustomerDomain"; - //end::declarations[] // tag::domain[] diff --git a/samples/scala-value-entity-customer-registry/src/main/proto/customer/view/customer_view.proto b/samples/scala-value-entity-customer-registry/src/main/proto/customer/view/customer_view.proto index f9b1427de7..9b75e41171 100644 --- a/samples/scala-value-entity-customer-registry/src/main/proto/customer/view/customer_view.proto +++ b/samples/scala-value-entity-customer-registry/src/main/proto/customer/view/customer_view.proto @@ -17,8 +17,6 @@ syntax = "proto3"; package customer.view; -option java_outer_classname = "CustomerViewModel"; - import "customer/domain/customer_domain.proto"; import "akkaserverless/annotations.proto"; import "google/protobuf/any.proto";