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 @@ -48,17 +48,14 @@ object FullyQualifiedName {

}

/**
* The details of a package's naming, sufficient to construct fully qualified names in any target language
*/
case class PackageNaming(
protoFileName: String,
name: String,
pkg: String,
protoPackage: String,
javaPackageOption: Option[String],
javaOuterClassnameOption: Option[String],
javaMultipleFiles: Boolean) {
lazy val javaPackage: String = javaPackageOption.getOrElse(pkg)
lazy val javaPackage: String = javaPackageOption.getOrElse(protoPackage)
def scalaPackage: String = javaPackage
def javaOuterClassname: String = javaOuterClassnameOption.getOrElse(name)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class ModelBuilderSuite extends munit.FunSuite {
Some("EmptyProto"),
javaMultipleFiles = true)
val entity = ModelBuilder.ValueEntity(
domainProto.pkg + "." + "ShoppingCart",
domainProto.protoPackage + "." + "ShoppingCart",
FullyQualifiedName("ShoppingCart", domainProto),
"shopping-cart",
ModelBuilder.State(FullyQualifiedName("Cart", domainProto)))
Expand Down Expand Up @@ -330,7 +330,7 @@ class ModelBuilderSuite extends munit.FunSuite {
Some("EmptyProto"),
javaMultipleFiles = true)
val entity = ModelBuilder.ValueEntity(
domainProto.pkg + "." + "ShoppingCart",
domainProto.protoPackage + "." + "ShoppingCart",
FullyQualifiedName("ShoppingCart", domainProto),
"shopping-cart",
ModelBuilder.State(FullyQualifiedName("Cart", domainProto)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class TestData(packageNamingTemplate: PackageNaming) {
valueEntity(domainProto(suffix), suffix)
def valueEntity(parent: PackageNaming, suffix: String = ""): ModelBuilder.ValueEntity =
ModelBuilder.ValueEntity(
parent.pkg + s"MyValueEntity$suffix",
parent.protoPackage + s".MyValueEntity$suffix",
FullyQualifiedName(s"MyValueEntity$suffix", parent),
s"MyValueEntity$suffix",
ModelBuilder.State(FullyQualifiedName("MyState", parent)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ object EventSourcedEntityTestKitGenerator {
val testFilePath = testSourceDirectory.resolve(packagePath.resolve(className + "Test.java"))
if (!testFilePath.toFile.exists()) {
testFilePath.getParent.toFile.mkdirs()
Files.write(testFilePath, generateTestSources(service, entity, packageName).getBytes(Charsets.UTF_8))
Files.write(testFilePath, generateTestSources(service, entity).getBytes(Charsets.UTF_8))
generatedFiles :+= testFilePath
}

Expand Down Expand Up @@ -79,7 +79,7 @@ object EventSourcedEntityTestKitGenerator {
val testkitClassName = s"${entityClassName}TestKit"

s"""$managedComment
|package ${entity.fqn.parent.pkg};
|package ${entity.fqn.parent.javaPackage};
|
|$imports
|
Expand Down Expand Up @@ -198,10 +198,8 @@ object EventSourcedEntityTestKitGenerator {
top + middle.mkString("\n") + bottom
}

def generateTestSources(
service: ModelBuilder.EntityService,
entity: ModelBuilder.EventSourcedEntity,
packageName: String): String = {
def generateTestSources(service: ModelBuilder.EntityService, entity: ModelBuilder.EventSourcedEntity): String = {
val packageName = entity.fqn.parent.javaPackage
val imports = generateCommandImports(
service.commands,
entity.state,
Expand Down Expand Up @@ -231,7 +229,7 @@ object EventSourcedEntityTestKitGenerator {
}

s"""$unmanagedComment
|package ${entity.fqn.parent.pkg};
|package $packageName;
|
|$imports
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ object ValueEntityTestKitGenerator {
val testkitClassName = s"${entityClassName}TestKit"

s"""$managedComment
|package ${entity.fqn.parent.pkg};
|package ${entity.fqn.parent.javaPackage};
|
|$imports
|
Expand Down Expand Up @@ -197,7 +197,7 @@ object ValueEntityTestKitGenerator {
}

s"""$unmanagedComment
|package ${entity.fqn.parent.pkg};
|package ${entity.fqn.parent.javaPackage};
|
|$imports
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,10 @@ class EventSourcedEntityTestKitGeneratorSuite extends munit.FunSuite {

test("it can generate an specific Test stub for the entity") {

val packageName = "com.example.shoppingcart"
val entity = generateShoppingCartEntity
val service = generateShoppingCartService(entity)

val sourceCode = EventSourcedEntityTestKitGenerator.generateTestSources(service, entity, packageName)
val sourceCode = EventSourcedEntityTestKitGenerator.generateTestSources(service, entity)

val expected =
"""/* This code was generated by Akka Serverless tooling.
Expand All @@ -164,7 +163,7 @@ class EventSourcedEntityTestKitGeneratorSuite extends munit.FunSuite {
|import com.akkaserverless.javasdk.eventsourcedentity.EventSourcedEntity;
|import com.akkaserverless.javasdk.eventsourcedentity.EventSourcedEntityContext;
|import com.akkaserverless.javasdk.testkit.EventSourcedResult;
|import com.example.shoppingcart.domain.ShoppingCartDomain;
|import com.example.shoppingcart.ShoppingCartApi;
|import com.google.protobuf.Empty;
|import java.util.ArrayList;
|import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ class MainSourceGeneratorSuite 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 service3Proto = testData.serviceProto("3").copy(protoPackage = "com.example.service.something")
val service4Proto = testData.serviceProto("4").copy(protoPackage = "com.example.service.view")
val service5Proto = testData.serviceProto("5")
val service6Proto = testData.serviceProto("6")

Expand Down Expand Up @@ -167,7 +167,7 @@ class MainSourceGeneratorSuite 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(protoPackage = "com.example.service.view")

val services = Map("com.example.Service" -> testData.simpleViewService(serviceProto).copy(transformedUpdates = Nil))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class SourceGeneratorSuite extends munit.FunSuite {
val service1Proto = testData.serviceProto("1")
val service2Proto = testData.serviceProto("2")
val service3Proto =
testData.serviceProto("3").copy(pkg = "com.example.service.something")
testData.serviceProto("3").copy(protoPackage = "com.example.service.something")
val service4Proto = testData.serviceProto("4")
val service5Proto = testData.serviceProto("5")
val service6Proto = testData.serviceProto("6")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ class ValueEntityTestKitGeneratorSuite extends munit.FunSuite {
javaMultipleFiles = false)

ModelBuilder.ValueEntity(
domainProto.pkg + ".ShoppingCart",
domainProto.protoPackage + ".ShoppingCart",
FullyQualifiedName("ShoppingCart", domainProto),
"eventsourced-shopping-cart",
ModelBuilder.State(FullyQualifiedName("Cart", domainProto)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ class MainSourceGeneratorSuite 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 service3Proto = testData.serviceProto("3").copy(protoPackage = "com.example.service.something")
val service4Proto = testData.serviceProto("4").copy(protoPackage = "com.example.service.view")
val service5Proto = testData.serviceProto("5")
val service6Proto = testData.serviceProto("6")

Expand Down Expand Up @@ -147,7 +147,7 @@ class MainSourceGeneratorSuite 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(protoPackage = "com.example.service.view")

val services = Map("com.example.Service" -> testData.simpleViewService(serviceProto).copy(transformedUpdates = Nil))

Expand Down