Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}

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 =
Expand Down Expand Up @@ -126,7 +111,7 @@ object PackageNaming {
descriptor.getPackage,
goPackage,
javaPackage,
javaOuterClassname,
Some(javaOuterClassname),
javaMultipleFiles)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
package com.lightbend.akkasls.codegen

class PackagingSuite extends munit.FunSuite {
private val testData = TestData()
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestData became a class (instead of object) so that it can be initialized with defaults (especially the difference between javaOuterClassName for Java vs Scala)


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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand All @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 " +
Expand Down Expand Up @@ -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))),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
Loading