Skip to content
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

Prepare for 1.4.1 #24

Merged
merged 9 commits into from
Feb 10, 2024
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 @@ -15,49 +15,28 @@
import io.zenwave360.sdk.plugins.ZDLToAsyncAPIPlugin;
import io.zenwave360.sdk.plugins.ZDLToOpenAPIPlugin;
import io.zenwave360.sdk.testutils.MavenCompiler;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class TestCustomerAddressRelationalProject {

private static String project = "customer-address-relational";
private static String sourceFolder = "src/test/resources/projects/" + project + "/";
private static String targetFolder = "target/projects/" + project + "/";
private String basePackage = "io.zenwave360.example";
private String zdlFile = targetFolder + "/customer-address-relational.zdl";

@BeforeAll
public static void beforeAll() throws Exception {
@ParameterizedTest
@ValueSource(strings = {"one-to-many", "one-to-one", "one-to-one-aggregates", "one-to-one-map-id", "many-to-one"})
public void testCustomerAddressRelational(String flavor) throws Exception {
String sourceFolder = "src/test/resources/projects/customer-address-relational/";
String targetFolder = "target/projects/customer-address-relational/" + flavor;
String zdlFile = targetFolder + "/customer-address-relational-" + flavor + ".zdl";

// copy whole dir from sourceFolder to targetFolder
FileUtils.deleteDirectory(new File(targetFolder));
FileUtils.forceMkdir(new File(targetFolder));
FileUtils.copyDirectory(new File(sourceFolder), new File(targetFolder));
Assertions.assertTrue(new File(targetFolder).exists());
}

// @Test
public void test() throws Exception {
Plugin plugin = new BackendApplicationDefaultPlugin()
.withSpecFile(zdlFile)
.withTargetFolder(targetFolder)
.withOption("basePackage", basePackage)
.withOption("persistence", PersistenceType.jpa)
.withOption("databaseType", DatabaseType.mariadb)
.withOption("style", ProgrammingStyle.imperative)
.withOption("useLombok", true)
.withOption("includeEmitEventsImplementation", true)
.withOption("forceOverwrite", true)
.withOption("haltOnFailFormatting", false);


new MainGenerator().generate(plugin);
// int exitCode = MavenCompiler.compile(new File(targetFolder));
// Assertions.assertEquals(0, exitCode);
}

@Order(1)
@Test
public void generateApis() throws Exception {
Plugin plugin = null;
int exitCode = 0;

plugin = new ZDLToOpenAPIPlugin()
.withSpecFile(zdlFile)
Expand All @@ -67,18 +46,18 @@ public void generateApis() throws Exception {
.withTargetFolder(targetFolder);
new MainGenerator().generate(plugin);

var replace = " - name: \"identifier\"\n" +
" in: path\n" +
" required: true\n" +
" schema:\n" +
" type: integer\n" +
" format: int64";
var replacement = " - name: \"identifier\"\n" +
" in: path\n" +
" required: true\n" +
" schema:\n" +
" type: string";
TextUtils.replaceInFile(new File(targetFolder + "/src/main/resources/apis/openapi.yml"), replace, replacement);
// var replace = " - name: \"identifier\"\n" +
// " in: path\n" +
// " required: true\n" +
// " schema:\n" +
// " type: integer\n" +
// " format: int64";
// var replacement = " - name: \"identifier\"\n" +
// " in: path\n" +
// " required: true\n" +
// " schema:\n" +
// " type: string";
// TextUtils.replaceInFile(new File(targetFolder + "/src/main/resources/apis/openapi.yml"), replace, replacement);

plugin = new ZDLToAsyncAPIPlugin()
.withSpecFile(zdlFile)
Expand All @@ -88,20 +67,6 @@ public void generateApis() throws Exception {
.withOption("targetFile", "/src/main/resources/apis/asyncapi.yml")
.withTargetFolder(targetFolder);
new MainGenerator().generate(plugin);
}

@Order(2)
@Test
public void generateSourceFromAPIs() throws Exception {
int exitCode = MavenCompiler.compile(new File(targetFolder));
Assertions.assertEquals(0, exitCode);
}

@Order(3)
@Test
public void generateModule() throws Exception {
Plugin plugin = null;
int exitCode = 0;

plugin = new BackendApplicationDefaultPlugin()
.withSpecFile(zdlFile)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ service CustomerService for (Customer) {
updateCustomer(id, Customer) Customer? withEvents CustomerEvent

/** Updates a the customer address identified by address.identifier */
@put("/{customerId}/address/{identifier}")
@put({path: "/{customerId}/address/{identifier}", params: {identifier: String}})
updateCustomerAddress(id, AddressInput) Customer? withEvents CustomerEvent CustomerAddressUpdated

@delete("/{customerId}")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/**
* Simple Event-Driven CRUD for Customer/Addresses.
*/
config {
title "ZenWave Playground Customer-Address MariaDB"
basePackage "io.zenwave360.example"
persistence jpa
databaseType mariadb
// haltOnFailFormatting false

plugins {

ZDLToOpenAPIPlugin {
idType integer
idTypeFormat int64
targetFile "src/main/resources/apis/openapi.yml"
}

ZDLToAsyncAPIPlugin {
asyncapiVersion v3
idType integer
idTypeFormat int64
targetFile "src/main/resources/apis/asyncapi.yml"
}

BackendApplicationDefaultPlugin {
useLombok true
includeEmitEventsImplementation true
// --force // overwite all files
}

OpenAPIControllersPlugin {
formatter google // comments in one line are better for demos
specFile "src/main/resources/apis/openapi.yml"
zdlFile "customer-address-relational.zdl"

// thse should match the values of openapi-generator-maven-plugin
openApiApiPackage "{{basePackage}}.adapters.web"
openApiModelPackage "{{basePackage}}.adapters.web.model"
openApiModelNameSuffix DTO
}
}
}


// == Entities =============================
/**
* Customer javadoc comment
*/
@aggregate
entity Customer {
username String required unique /** username javadoc comment */
email String required unique /** email javadoc comment */
}

entity Address {
street String required /** street javadoc comment */
city String /** city javadoc comment */
state String /** state javadoc comment */
zip String /** zip javadoc comment */
type AddressType required /** address type is an enum */
}

enum AddressType { HOME(1) /** home description */, WORK(1) /** work description */ }

relationship OneToMany {
Customer{addresses} to Address{customer}
}


// == Services =============================

@inline
input AddressInput {
identifier String required /** Description identifier for this Address */
address Address
}

/**
Service javadoc comment
*/
@rest("/customers")
service CustomerService for (Customer) {
/**
* Create customer javadoc comment
*/
@post
createCustomer(Customer) Customer withEvents CustomerEvent

@put("/{customerId}")
updateCustomer(id, Customer) Customer? withEvents CustomerEvent

/** Updates a the customer address identified by address.identifier */
@put({path: "/{customerId}/address/{identifier}", params: {identifier: String}})
updateCustomerAddress(id, AddressInput) Customer? withEvents CustomerEvent CustomerAddressUpdated

@delete("/{customerId}")
deleteCustomer(id) withEvents CustomerEvent

@get("/{customerId}")
getCustomer(id) Customer?

@get({params: {search: "string"}})
@paginated
listCustomers() Customer[]
}

// == Events =============================

@skip // skip generating this domain enum, it will genereate by asyncapi code generator.
enum EventType { CREATED(1) /** created description */, UPDATED(1) /** updated description */, DELETED(1) /** deleted description */ }

@asyncapi({channel: "CustomerEventsChannel", topic: "customer.events"})
event CustomerEvent {
customerId String
eventType EventType
customer Customer
}

@asyncapi({channel: "CustomerAddressEventsChannel", topic: "customer.address-events"})
event CustomerAddressUpdated {
customerId String
addressDescription String
originalAddress Address
newAddress Address
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/**
* Simple Event-Driven CRUD for Customer/Addresses.
*/
config {
title "ZenWave Playground Customer-Address MariaDB"
basePackage "io.zenwave360.example"
persistence jpa
databaseType mariadb
// haltOnFailFormatting false

plugins {

ZDLToOpenAPIPlugin {
idType integer
idTypeFormat int64
targetFile "src/main/resources/apis/openapi.yml"
}

ZDLToAsyncAPIPlugin {
asyncapiVersion v3
idType integer
idTypeFormat int64
targetFile "src/main/resources/apis/asyncapi.yml"
}

BackendApplicationDefaultPlugin {
useLombok true
includeEmitEventsImplementation true
// --force // overwite all files
}

OpenAPIControllersPlugin {
formatter google // comments in one line are better for demos
specFile "src/main/resources/apis/openapi.yml"
zdlFile "customer-address-relational.zdl"

// thse should match the values of openapi-generator-maven-plugin
openApiApiPackage "{{basePackage}}.adapters.web"
openApiModelPackage "{{basePackage}}.adapters.web.model"
openApiModelNameSuffix DTO
}
}
}


// == Entities =============================
/**
* Customer javadoc comment
*/
@aggregate
entity Customer {
username String required unique /** username javadoc comment */
email String required unique /** email javadoc comment */
}

@aggregate
entity Address {
street String required /** street javadoc comment */
city String /** city javadoc comment */
state String /** state javadoc comment */
zip String /** zip javadoc comment */
type AddressType required /** address type is an enum */
}

enum AddressType { HOME(1) /** home description */, WORK(1) /** work description */ }

relationship OneToOne {
Customer{address} to Address{customer}
}


// == Services =============================

@inline
input AddressInput {
identifier String required /** Description identifier for this Address */
address Address
}

/**
Service javadoc comment
*/
@rest("/customers")
service CustomerService for (Customer) {
/**
* Create customer javadoc comment
*/
@post
createCustomer(Customer) Customer withEvents CustomerEvent

@put("/{customerId}")
updateCustomer(id, Customer) Customer? withEvents CustomerEvent

/** Updates a the customer address identified by address.identifier */
@put({path: "/{customerId}/address/{identifier}", params: {identifier: String}})
updateCustomerAddress(id, AddressInput) Customer? withEvents CustomerEvent CustomerAddressUpdated

@delete("/{customerId}")
deleteCustomer(id) withEvents CustomerEvent

@get("/{customerId}")
getCustomer(id) Customer?

@get({params: {search: "string"}})
@paginated
listCustomers() Customer[]
}

// == Events =============================

@skip // skip generating this domain enum, it will genereate by asyncapi code generator.
enum EventType { CREATED(1) /** created description */, UPDATED(1) /** updated description */, DELETED(1) /** deleted description */ }

@asyncapi({channel: "CustomerEventsChannel", topic: "customer.events"})
event CustomerEvent {
customerId String
eventType EventType
customer Customer
}

@asyncapi({channel: "CustomerAddressEventsChannel", topic: "customer.address-events"})
event CustomerAddressUpdated {
customerId String
addressDescription String
originalAddress Address
newAddress Address
}
Loading
Loading