From 0bc6d9fcdaa87daa039e5dcb046a2997d6818f3b Mon Sep 17 00:00:00 2001 From: Dixit Date: Tue, 1 Dec 2020 06:50:33 +0530 Subject: [PATCH 01/43] devon4j mannual correction --- documentation/architecture.asciidoc | 20 +++++----- documentation/coding-conventions.asciidoc | 30 +++++++-------- documentation/guide-batch-layer.asciidoc | 38 +++++++++---------- documentation/guide-component-facade.asciidoc | 6 +-- documentation/guide-component.asciidoc | 8 ++-- documentation/guide-dataaccess-layer.asciidoc | 2 +- documentation/guide-logic-layer.asciidoc | 20 +++++----- documentation/guide-service-layer.asciidoc | 8 ++-- .../guide-service-versioning.asciidoc | 38 +++++++++---------- documentation/guide-usecase.asciidoc | 28 +++++++------- 10 files changed, 100 insertions(+), 98 deletions(-) diff --git a/documentation/architecture.asciidoc b/documentation/architecture.asciidoc index 1a6f1587..bee7a2cf 100644 --- a/documentation/architecture.asciidoc +++ b/documentation/architecture.asciidoc @@ -3,7 +3,7 @@ toc::[] :idprefix: :idseparator: - -There are many different views on what is summarized by the term _architecture_. First we introduce the xref:key-principles[key principles] and xref:architecture-principles[architecture principles] of devonfw. Then we go into details of the the xref:application-architecture[architecture of an application]. +There are many different views that are summarized by the term _architecture_. First, we will introduce the xref:key-principles[key principles] and xref:architecture-principles[architecture principles] of devonfw. Then, we will go into details of the the xref:application-architecture[architecture of an application]. == Key Principles For devonfw we follow these fundamental key principles for all decisions about architecture, design, or choosing standards, libraries, and frameworks: @@ -25,9 +25,9 @@ We follow a strictly component oriented design to address the following sub-prin ** http://en.wikipedia.org/wiki/Separation_of_concerns[Separation of Concerns] ** http://en.wikipedia.org/wiki/Reusability[Reusability] and avoiding http://en.wikipedia.org/wiki/Redundant_code[redundant code] ** http://en.wikipedia.org/wiki/Information_hiding[Information Hiding] via component API and its exchangeable implementation treated as secret. -** _Design by Contract_ for self-contained, descriptive, and stable component APIs. +** _Design by Contract_ for self-contained, descriptive, and stable component APIs. ** xref:technical-architecture[Layering] as well as separation of business logic from technical code for better maintenance. -** _Data Sovereignty_ (and _high cohesion with low coupling_) says that a component is responsible for its data and changes to this data shall only happen via the component. Otherwise maintenance problems will arise to ensure that data remains consistent. Therefore interfaces of a component that may be used by other components are designed _call-by-value_ and not _call-by-reference_. +** _Data Sovereignty_ (and _high cohesion with low coupling_) says that a component is responsible for its data and changes to this data shall only happen via the component. Otherwise, maintenance problems will arise to ensure that data remains consistent. Therefore, interfaces of a component that may be used by other components are designed _call-by-value_ and not _call-by-reference_. * *Homogeneity* + Solve similar problems in similar ways and establish a uniform link:coding-conventions.asciidoc[code-style]. @@ -40,24 +40,24 @@ For the architecture of an application we distinguish the following views: * The Infrastructure Architecture describes an application from the operational infrastructure perspective. It defines the nodes used to run the application including clustering, load-balancing and networking. This view is not explored further in this guide. === Business Architecture -The _business architecture_ divides the application into _business components_. A business component has a well-defined responsibility that it encapsulates. All aspects related to that responsibility have to be implemented within that business component. Further the business architecture defines the dependencies between the business components. These dependencies need to be free of cycles. A business component exports his functionality via well-defined interfaces as a self-contained API. A business component may use another business component via its API and compliant with the dependencies defined by the business architecture. +The _business architecture_ divides the application into _business components_. A business component has a well-defined responsibility that it encapsulates. All aspects related to that responsibility have to be implemented within that business component. Further, the business architecture defines the dependencies between the business components. These dependencies need to be free of cycles. A business component exports its functionality via well-defined interfaces as a self-contained API. A business component may use another business component via its API and compliant with the dependencies defined by the business architecture. As the business domain and logic of an application can be totally different, the devonfw can not define a standardized business architecture. Depending on the business domain it has to be defined from scratch or from a domain reference architecture template. For very small systems it may be suitable to define just a single business component containing all the code. === Technical Architecture -The _technical architecture_ divides the application into technical _layers_ based on the http://en.wikipedia.org/wiki/Multilayered_architecture[multilayered architecture]. A layer is a unit of code with the same category such as service or presentation logic. A layer is therefore often supported by a technical framework. Each business component can therefore be split into _component parts_ for each layer. However, a business component may not have component parts for every layer (e.g. only a presentation part that utilized logic from other components). +The _technical architecture_ divides the application into technical _layers_ based on the http://en.wikipedia.org/wiki/Multilayered_architecture[multilayered architecture]. A layer is a unit of code with the same category such as a service or presentation logic. So, a layer is often supported by a technical framework. Each business component can therefore be split into _component parts_ for each layer. However, a business component may not have component parts for every layer (e.g. only a presentation part that utilized logic from other components). An overview of the technical reference architecture of the devonfw is given by xref:img-t-architecture[figure "Technical Reference Architecture"]. It defines the following layers visualized as horizontal boxes: * link:guide-client-layer.asciidoc[client layer] for the front-end (GUI). -* link:guide-service-layer.asciidoc[service layer] for the services used to expose functionality of the +* link:guide-service-layer.asciidoc[service layer] for the services used to expose functionality of the back-end to the client or other consumers. * link:guide-batch-layer.asciidoc[batch layer] for exposing functionality in batch-processes (e.g. mass imports). * link:guide-logic-layer.asciidoc[logic layer] for the business logic. * link:guide-dataaccess-layer.asciidoc[data-access layer] for the data access (esp. persistence). -Also you can see the (business) components as vertical boxes (e.g. _A_ and _X_) and how they are composed out of component parts each one assigned to one of the technical layers. +Also, you can see the (business) components as vertical boxes (e.g. _A_ and _X_) and how they are composed out of component parts each one assigned to one of the technical layers. Further, there are technical components for cross-cutting aspects grouped by the gray box on the left. Here is a complete list: @@ -80,11 +80,11 @@ developers a sound orientation within the project. Further, the architecture diagram shows the allowed dependencies illustrated by the dark green connectors. Within a business component a component part can call the next component part on the layer directly below via a dependency on its API (vertical connectors). -While this is natural and obvious it is generally forbidden to have dependencies upwards the layers +While this is natural and obvious, it is generally forbidden to have dependencies upwards the layers or to skip a layer by a direct dependency on a component part two or more layers below. The general dependencies allowed between business components are defined by the xref:business-architecture[business architecture]. In our reference architecture diagram we assume that the business component `A1` is allowed to depend -on component `A2`. Therefore a use-case within the logic component part of `A1` is allowed to call a +on component `A2`. Therefore, a use-case within the logic component part of `A1` is allowed to call a use-case from `A2` via a dependency on the component API. The same applies for dialogs on the client layer. This is illustrated by the horizontal connectors. Please note that link:guide-jpa.asciidoc#entity[persistence entities] are part of the API of the data-access component part so only the logic component part of the same business component may depend on them. @@ -94,7 +94,7 @@ The technical architecture has to address non-functional requirements: * *scalability* + is established by keeping state in the client and making the server state-less (except for login session). Via load-balancers new server nodes can be added to improve performance (horizontal scaling). * *availability* and *reliability* + -are addressed by clustering with redundant nodes avoiding any single-point-of failure. If one node fails the system is still available. Further the software has to be robust so there are no dead-locks or other bad effects that can make the system unavailable or not reliable. +are addressed by clustering with redundant nodes avoiding any single-point-of failure. If one node fails the system is still available. Further, the software has to be robust so there are no dead-locks or other bad effects that can make the system unavailable or not reliable. * *security* + is archived in the devonfw by the right templates and best-practices that avoid vulnerabilities. See link:guide-security.asciidoc[security guidelines] for further details. * *performance* + diff --git a/documentation/coding-conventions.asciidoc b/documentation/coding-conventions.asciidoc index 57c6d0f8..a65b7885 100644 --- a/documentation/coding-conventions.asciidoc +++ b/documentation/coding-conventions.asciidoc @@ -15,7 +15,7 @@ Besides general Java naming conventions, we follow the additional rules listed h * Names of Generics should be easy to understand. Where suitable follow the common rule `E=Element`, `T=Type`, `K=Key`, `V=Value` but feel free to use longer names for more specific cases such as `ID`, `DTO` or `ENTITY`. The capitalized naming helps to distinguish a generic type from a regular class. == Packages -Java Packages are the most important element to structure your code. We use a strict packaging convention to map technical layers and business components (slices) to the code (See link:architecture.asciidoc#technical-architecture[technical architecture] for further details). By using the same names in documentation and code we create a strong link that gives orientation and makes it easy to find from business requirements, specifications or story tickets into the code and back. +Java Packages are the most important element to structure your code. We use a strict packaging convention to map technical layers and business components (slices) to the code (See link:architecture.asciidoc#technical-architecture[technical architecture] for further details). By using the same names in documentation and code we create a strong link that gives orientation and makes it easy to find from business requirements, specifications or story tickets into the code and back. For an devon4j based application we use the following Java-Package schema: [source] @@ -40,7 +40,7 @@ Please note that for library modules where we use `com.devonfw.module` as `«bas We combine the above naming and packaging conventions to map the entire architecture to the code. This also allows tools such as https://github.com/devonfw/cobigen[CobiGen] or https://github.com/devonfw/sonar-devon4j-plugin/[sonar-devon4j-plugin] to "understand" the code. -Also this helps developers going from one devon4j project to the next to quickly understand the code-base. +Also this helps developers going from one devon4j project to the next one to quickly understand the code-base. If every developer knows where to find what, the project gets more efficient. A long time ago maven standardized the project structure with `src/main/java`, etc. and turned chaos into structure. With devonfw we experienced the same for the codebase (what is inside `src/main/java`). @@ -131,7 +131,7 @@ With devonfw we experienced the same for the codebase (what is inside `src/main/ ---- == Code Tasks -Code spots that need some rework can be marked with the following tasks tags. These are already properly pre-configured in your development environment for auto completion and to view tasks you are responsible for. It is important to keep the number of code tasks low. Therefore every member of the team should be responsible for the overall code quality. So if you change a piece of code and hit a code task that you can resolve in a reliable way do this as part of your change and remove the according tag. +Code spots that need some rework can be marked with the following tasks tags. These are already properly pre-configured in your development environment for auto completion and to view tasks you are responsible for. It is important to keep the number of code tasks low. Therefore, every member of the team should be responsible for the overall code quality. So if you change a piece of code and hit a code task that you can resolve in a reliable way, please do this as part of your change and remove the according tag. === TODO Used to mark a piece of code that is not yet complete (typically because it can not be completed due to a dependency on something that is not ready). @@ -154,7 +154,7 @@ A FIXME tag is added by the author of the code or someone who found a bug he can A REVIEW tag is added by a reviewer during a code review. Here the original author of the code is responsible to resolve the REVIEW tag and the reviewer is assigning this task to him. This is important for feedback and learning and has to be aligned with a review "process" where people talk to each other and get into discussion. In smaller or local teams a peer-review is preferable but this does not scale for large or even distributed teams. == Code-Documentation -As a general goal the code should be easy to read and understand. Besides clear naming the documentation is important. We follow these rules: +As a general goal, the code should be easy to read and understand. Besides, clear naming the documentation is important. We follow these rules: * APIs (especially component interfaces) are properly documented with JavaDoc. * JavaDoc shall provide actual value - we do not write JavaDoc to satisfy tools such as checkstyle but to express information not already available in the signature. @@ -167,10 +167,10 @@ As a general goal the code should be easy to read and understand. Besides clear This section gives you best practices to write better code and avoid pitfalls and mistakes. === BLOBs -Avoid using `byte[]` for BLOBs as this will load them entirely into your memory. This will cause performance issues or out of memory errors. Instead use streams when dealing with BLOBs. For further details see link:guide-blob-support.asciidoc[BLOB support]. +Avoid using `byte[]` for BLOBs as this will load them entirely into your memory. This will cause performance issues or out of memory errors. Instead, use streams when dealing with BLOBs. For further details see link:guide-blob-support.asciidoc[BLOB support]. === Closing Resources -Resources such as streams (`InputStream`, `OutputStream`, `Reader`, `Writer`) or transactions need to be handled properly. Therefore it is important to follow these rules: +Resources such as streams (`InputStream`, `OutputStream`, `Reader`, `Writer`) or transactions need to be handled properly. Therefore, it is important to follow these rules: * Each resource has to be closed properly, otherwise you will get out of file handles, TX sessions, memory leaks or the like * Where possible avoid to deal with such resources manually. That is why we are recommending `@Transactional` for transactions in devonfw (see link:guide-transactions.asciidoc[Transaction Handling]). @@ -191,7 +191,7 @@ try { The code above is wrong as in case of an `IOException` the `InputStream` is not properly closed. In a server application such mistakes can cause severe errors that typically will only occur in production. As such resources implement the `AutoCloseable` interface you can use the `try-with-resource` syntax to write correct code. The following code shows a correct version of the example: [source,java] ---- -try (InputStream in = new FileInputStream(file)) { +try (InputStream in = new FileInputStream(file)) { readData(in); } catch (IOException e) { throw new IllegalStateException("Failed to read data.", e); @@ -209,10 +209,10 @@ When catching exceptions always ensure the following: === Lambdas and Streams With Java8 you have cool new features like lambdas and monads like (`Stream`, `CompletableFuture`, `Optional`, etc.). -However, these new features can also be misused or lead to code that is hard to read or debug. To avoid pain, we give you the following best practices: +However, these new features can also be misused or led to code that is hard to read or debug. To avoid pain, we give you the following best practices: -. Learn how to use the new features properly before using. Often developers are keen on using cool new features. When you do your first experiments in your project code you will cause deep pain and might be ashamed afterwards. Please study the features properly. Even Java8 experts still write for loops to iterate over collections, so only use these features where it really makes sense. -. Streams shall only be used in fluent API calls as a Stream can not be forked or reused. +. Learn how to use the new features properly before using. Developers are often keen on using cool new features. When you do your first experiments in your project code you will cause deep pain and might be ashamed afterwards. Please study the features properly. Even Java8 experts still write for loops to iterate over collections, so only use these features where it really makes sense. +. Streams shall only be used in fluent API calls as a Stream can not be forked or reused. . Each stream has to have exactly one terminal operation. . Do not write multiple statements into lambda code: + @@ -225,7 +225,7 @@ return foo; }).collect(Collectors.toList()); ---- + -This style makes the code hard to read and debug. Never do that! Instead extract the lambda body to a private method with a meaningful name: +This style makes the code hard to read and debug. Never do that! Instead, extract the lambda body to a private method with a meaningful name: + [source,java] ---- @@ -246,7 +246,7 @@ set.stream().flatMap(x -> x.getChildren().stream()).filter(this::isSpecial).coll set.stream().collect(Collectors.toList()).forEach(...) // bad set.stream().peek(...).collect(Collectors.toList()) // fine ---- -. Lambda parameters with Types inference +. Lambda parameters with Types inference + [source,java] ---- @@ -314,12 +314,12 @@ id = Optional.ofNullable(fooCto).map(FooCto::getBar).map(BarCto::getBar).map(Bar === Encoding Encoding (esp. Unicode with combining characters and surrogates) is a complex topic. Please study this topic if you have to deal with encodings and processing of special characters. For the basics follow these recommendations: -* When you have explicitly decide for an encoding always prefer Unicode (UTF-8 or better). This especially impacts your databases and has to be defined upfront as it typically can not be changed (easily) afterwards. +* When you have explicitly decided for an encoding always prefer Unicode (UTF-8 or better). This especially impacts your databases and has to be defined upfront as it typically can not be changed (easily) afterwards. * Do not cast from `byte` to `char` (Unicode characters can be composed of multiple bytes, such cast may only work for ASCII characters) -* Never convert the case of a String using the default locale (esp. when writing generic code like in devonfw). E.g. if you do `"HI".toLowerCase()` and your system locale is Turkish, then the output will be "hı" instead of "hi" what can lead to wrong assumptions and serious problems. If you want to do a "universal" case conversion always use explicitly an according western locale (e.g. `toLowerCase(Locale.US)`). Consider using a library (https://github.com/m-m-m/util/blob/master/core/src/main/java/net/sf/mmm/util/lang/api/BasicHelper.java) or create your own little static utility for that in your project. +* Never convert the case of a String using the default locale (esp. when writing generic code like in devonfw). E.g. if you do `"HI".toLowerCase()` and your system locale is Turkish, then the output will be "hı" instead of "hi", which can lead to wrong assumptions and serious problems. If you want to do a "universal" case conversion always use explicitly an according western locale (e.g. `toLowerCase(Locale.US)`). Consider using a library (https://github.com/m-m-m/util/blob/master/core/src/main/java/net/sf/mmm/util/lang/api/BasicHelper.java) or create your own little static utility for that in your project. * Write your code independent from the default encoding (system property `file.encoding`) - this will most likely differ in JUnit from production environment ** Always provide an encoding when you create a `String` from `byte[]`: `new String(bytes, encoding)` -** Always provide an encoding when you create a `Reader` or `Writer` : `new InputStreamReader(inStream, encoding)` +** Always provide an encoding when you create a `Reader` or `Writer` : `new InputStreamReader(inStream, encoding)` === Prefer general API Avoid unnecessary strong bindings: diff --git a/documentation/guide-batch-layer.asciidoc b/documentation/guide-batch-layer.asciidoc index f3e95a06..057892fe 100644 --- a/documentation/guide-batch-layer.asciidoc +++ b/documentation/guide-batch-layer.asciidoc @@ -3,30 +3,30 @@ toc::[] = Batch Layer -We understand batch processing as bulk-oriented, non-interactive, typically long running execution of tasks. For simplicity we use the term batch or batch job for such tasks in the following documentation. +We understand batch processing as a bulk-oriented, non-interactive, typically long running execution of tasks. For simplicity, we use the term "batch" or "batch job" for such tasks in the following documentation. -devonfw uses link:http://projects.spring.io/spring-batch/[Spring Batch] as batch framework. +devonfw uses link:http://projects.spring.io/spring-batch/[Spring Batch] as a batch framework. -This guide explains how Spring Batch is used in devonfw applications. It focuses on aspects which are special to devonfw if you want to learn about spring-batch you should adhere to springs references documentation. +This guide explains how Spring Batch is used in devonfw applications. It focuses on aspects which are special to devonfw. If you want to learn about spring-batch you should adhere to springs references documentation. -There is an example of simple batch implementation in the https://github.com/devonfw/my-thai-star/tree/develop/java/mtsj/batch[my-thai-star batch module]. +There is an example of a simple batch implementation in the https://github.com/devonfw/my-thai-star/tree/develop/java/mtsj/batch[my-thai-star batch module]. -In this chapter we will describe the overall architecture (especially concerning layering) and how to administer batches. +In this chapter, we will describe the overall architecture (especially concerning layering) and how to administer batches. == Layering -Batches are implemented in the batch layer. The batch layer is responsible for batch processes, whereas the business logic is implemented in the logic layer. Compared to the link:guide-service-layer.asciidoc[service layer] you may understand the batch layer just as a different way of accessing the business logic. -From a component point of view each batch is implemented as a subcomponent in the corresponding business component. +Batches are implemented in the batch layer. The batch layer is responsible for batch processes, whereas the business logic is implemented in the logic layer. Compared to the link:guide-service-layer.asciidoc[service layer], you may understand the batch layer just as a different way of accessing the business logic. +From a component point of view, each batch is implemented as a subcomponent in the corresponding business component. The business component is defined by the link:architecture.asciidoc[business architecture]. Let's make an example for that. The sample application implements a batch for exporting ingredients. This ingredientExportJob belongs to the dishmanagement business component. So the ingredientExportJob is implemented in the following package: -//Example doesn't exist anymore and I didn't find any other used batches. +//Example doesn't exist anymore and I didn't find any other used batches. [source] .dishmanagement.batch.impl.* -Batches should invoke use cases in the logic layer for doing their work. +Batches should invoke use cases in the logic layer for doing their work. Only "batch specific" technical aspects should be implemented in the batch layer. ========================== @@ -37,16 +37,16 @@ The batch calls the use case "create product" in the logic layer for actually cr === Directly accessing data access layer -In practice it is not always appropriate to create use cases for every bit of work a batch should do. Instead, the data access layer can be used directly. +In practice, it is not always appropriate to create use cases for every bit of work a batch should do. Instead, the data access layer can be used directly. An example for that is a typical batch for data retention which deletes out-of-time data. -Often deleting out-dated data is done by invoking a single SQL statement. It is appropriate to implement that SQL in a link:guide-repository.asciidoc[Repository] or link:guide-dao.asciidoc[DAO] method and call this method directly from the batch. -But be careful that this pattern is a simplification which could lead to business logic cluttered in different layers which reduces maintainability of your application. -It is a typical design decision you have to take when designing your specific batches. +Often deleting, out-dated data is done by invoking a single SQL statement. It is appropriate to implement that SQL in a link:guide-repository.asciidoc[Repository] or link:guide-dao.asciidoc[DAO] method and call this method directly from the batch. +But be careful: this pattern is a simplification which could lead to business logic cluttered in different layers, which reduces the maintainability of your application. +It is a typical design decision you have to make when designing your specific batches. == Project structure and packaging -Batches will be implemented in a separate Maven module to keep the application core free of batch dependencies. The batch module includes a dependency to the application core-module to allow reuse of the use cases, DAOs etc. -Additionally the batch module has dependencies to the required spring batch jars: +Batches will be implemented in a separate Maven module to keep the application core free of batch dependencies. The batch module includes a dependency on the application core-module to allow the reuse of the use cases, DAOs etc. +Additionally the batch module has dependencies on the required spring batch jars: [source,xml] ---- @@ -96,7 +96,7 @@ To allow an easy xref:start-batch[start of the batches] from the command line it com.devonfw.application.mtsj.SpringBootApp bootified - + @@ -126,7 +126,7 @@ java -jar -batch--bootified.jar --spring.main.web-application-type [%header] |=== |Parameter |Explanation -|`--spring.main.web-application-type=none`| This disables the web app (e.g. Tomcat) +|`--spring.main.web-application-type=none`| This disables the web app (e.g. Tomcat) |`--spring.batch.job.names=`| This specifies the name of the job to run. If you leave this out ALL jobs will be executed. Which probably does not make to much sense. |``| (Optional) additional parameters which are passed to your job |=== @@ -145,7 +145,7 @@ In real world scheduling of batches is not as simple as it first might look like For devonfw we propose the batches themselves should not mess around with details of scheduling. Likewise your application should not do so. This complexity should be externalized to a dedicated batch administration service or scheduler. This service could be a complex product or a simple tool like cron. We propose link:http://rundeck.org[Rundeck] as an open source job scheduler. - + This gives full control to operations to choose the solution which fits best into existing administration procedures. == Handling restarts @@ -241,7 +241,7 @@ public class SimpleAuthenticationTasklet implements Tasklet { } ---- -The username and password have to be supplied via two cli parameters `-username` and `-password`. This implementation creates an "authenticated" `Authentication` and sets in the Spring Security context. This is just for demonstration normally you should not provide passwords via command line. The actual authentication will be done automatically via Spring Security as in your "normal" application. +The username and password have to be supplied via two cli parameters `-username` and `-password`. This implementation creates an "authenticated" `Authentication` and sets in the Spring Security context. This is just for demonstration normally you should not provide passwords via command line. The actual authentication will be done automatically via Spring Security as in your "normal" application. If you have a more complex authentication mechanism in your application e.g. via OpenID connect just call this in the tasklet. Naturally you may read authentication parameters (e.g. secrets) from the command line or more securely from a configuration file. In your Job Configuration set this tasklet as the first step: diff --git a/documentation/guide-component-facade.asciidoc b/documentation/guide-component-facade.asciidoc index 0711123f..3b1c4918 100644 --- a/documentation/guide-component-facade.asciidoc +++ b/documentation/guide-component-facade.asciidoc @@ -3,7 +3,7 @@ toc::[] = Component Facade -For each component of the application the link:guide-logic-layer.asciidoc[logic layer] defines a component facade. +For each component of the application, the link:guide-logic-layer.asciidoc[logic layer] defines a component facade. This is an interface defining all business operations of the component. It carries the name of the component (`«Component»`) and has an implementation named `«Component»Impl` (see xref:implementation[implementation]). @@ -22,7 +22,7 @@ public interface Bookingmanagement { BookingCto findBookingCto(Long id); Page findBookingEtos(BookingSearchCriteriaTo criteria); - + void approveBooking(BookingEto booking); } @@ -31,7 +31,7 @@ public interface Bookingmanagement { == Implementation The implementation of an interface from the link:guide-logic-layer.asciidoc[logic layer] (a component facade or a link:guide-usecase.asciidoc[use-case]) carries the name of that interface with the suffix `Impl` and is annotated with `@Named`. An implementation typically needs access to the persistent data. -This is done by link:guide-dependency-injection.asciidoc[injecting] the corresponding link:guide-repository.asciidoc[repository] (or link:guide-dao.asciidoc[DAO]). +This is done by link:guide-dependency-injection.asciidoc[injecting] the corresponding link:guide-repository.asciidoc[repository] (or link:guide-dao.asciidoc[DAO]). According to link:architecture.asciidoc#architecture-principles[data-sovereignty], only repositories of the same business component may be accessed directly. For accessing data from other components the implementation has to use the corresponding API of the logic layer (the component facade). Further, it shall not expose persistent entities from the link:guide-dataaccess-layer.asciidoc[dataaccess layer] and has to map them to link:guide-transferobject.asciidoc[transfer objects] using the link:guide-beanmapping.asciidoc[bean-mapper]. diff --git a/documentation/guide-component.asciidoc b/documentation/guide-component.asciidoc index 1a790081..b4e82be5 100644 --- a/documentation/guide-component.asciidoc +++ b/documentation/guide-component.asciidoc @@ -20,13 +20,13 @@ Cross-cutting aspects belong to the implicit component `general`. It contains te == Business Component The link:architecture.asciidoc#business-architecture[business-architecture] defines the business components with their allowed dependencies. A small application (microservice) may just have one component and no dependencies making it simple while the same architecture can scale up to large and complex applications (from bigger microservice up to modulith). Tailoring an business domain into applications and applications into components is a tricky task that needs the skills of an experienced architect. -Also the tailoring should follow the business and not split by technical reasons or only by size. +Also, the tailoring should follow the business and not split by technical reasons or only by size. Size is only an indicator but not a driver of tailoring. -Whatever hypes like microservices are telling you, never get mislead in this regard: +Whatever hypes like microservices are telling you, never get misled in this regard: If your system grows and reaches `MAX+1` lines of code, it is not the right motivation to split it into two microservices of `~MAX/2` lines of code - such approaches will waste huge amounts of money and lead to chaos. == App Component -Only in case you need cross-cutting code that aggregates other component you may introduce the component `app`. +Only in case you need cross-cutting code that aggregates another component you may introduce the component `app`. It is allowed to depend on all other components but no other component may depend on it. With the modularity and flexibility of spring you typically do not need this. However, when you need to have a class that registers all services or component-facades using direct code dependencies, you can introduce this component. @@ -36,4 +36,4 @@ The following class diagram illustrates an example of the business component `St image::images/guide-logic-layer.png["logic layer component pattern",scaledwidth="80%",align="center"] -Here you can see the structure and flow from the link:guide-service-layer.asciidoc[service-layer] (REST service call) via the link:guide-logic-layer.asciidoc[logic-layer] to the link:guide-dataaccess-layer.asciidoc[dataaccess-layer] (and back). \ No newline at end of file +In this scheme, you can see the structure and flow from the link:guide-service-layer.asciidoc[service-layer] (REST service call) via the link:guide-logic-layer.asciidoc[logic-layer] to the link:guide-dataaccess-layer.asciidoc[dataaccess-layer] (and back). \ No newline at end of file diff --git a/documentation/guide-dataaccess-layer.asciidoc b/documentation/guide-dataaccess-layer.asciidoc index 20a1af7b..fe8de8d4 100644 --- a/documentation/guide-dataaccess-layer.asciidoc +++ b/documentation/guide-dataaccess-layer.asciidoc @@ -9,4 +9,4 @@ The data-access layer is responsible for all outgoing connections to access and You need to make your choice for a database. Options are documented https://github.com/devonfw/devonfw-guide/blob/master/general/db/guide-database.asciidoc[here]. -The classical approach is to use a Relational Database Management System (RDMS). In such case we strongly recommend to follow our link:guide-jpa.asciidoc[JPA Guide]. Some NoSQL databases are supported by https://spring.io/projects/spring-data[spring-data] so you can consider the link:guide-repository.asciidoc[repository guide]. \ No newline at end of file +The classical approach is to use a Relational Database Management System (RDMS). In such a case, we strongly recommend to follow our link:guide-jpa.asciidoc[JPA Guide]. Some NoSQL databases are supported by https://spring.io/projects/spring-data[spring-data] so you can consider the link:guide-repository.asciidoc[repository guide]. \ No newline at end of file diff --git a/documentation/guide-logic-layer.asciidoc b/documentation/guide-logic-layer.asciidoc index 5ceafe91..6ce21c5f 100644 --- a/documentation/guide-logic-layer.asciidoc +++ b/documentation/guide-logic-layer.asciidoc @@ -4,29 +4,29 @@ toc::[] = Logic Layer The logic layer is the heart of the application and contains the main business logic. -According to our link:architecture.asciidoc#business-architecture[business architecture] we divide an application into link:guide-component.asciidoc[components]. -For each component the logic layer defines a link:guide-component-facade.asciidoc[component-facade]. -According to the complexity you can further divide this into individual link:guide-usecase.asciidoc[use-cases]. +According to our link:architecture.asciidoc#business-architecture[business architecture], we divide an application into link:guide-component.asciidoc[components]. +For each component, the logic layer defines a link:guide-component-facade.asciidoc[component-facade]. +According to the complexity, you can further divide this into individual link:guide-usecase.asciidoc[use-cases]. It is very important that you follow the links to understand the concept of component-facade and use-case in order to properly implement your business logic. == Responsibility -The logic layer is responsible for implementation the business logic according to the specified functional demands and requirements. -It therefore creates the actual value of the application. -The following additional aspects are also in its responsibility: +The logic layer is responsible to implement the business logic according to the specified functional demands and requirements. +Therefore, it creates the actual value of the application. +The following additional aspects are also included in its responsibility: * link:guide-validation.asciidoc[validation] * link:guide-access-control.asciidoc#authorization[authorization] * link:guide-transactions.asciidoc[transaction-handling] (in addition to link:guide-service-layer.asciidoc[service layer]). == Security -The logic layer is the heart of the application. It is also responsible for authorization and hence security is important here. Every method exposed in an interface needs to be annotated with an authorization check, stating what role(s) a caller must provide in order to be allowed to make the call. The authorization concept is described link:guide-security.asciidoc#authorization[here]. +The logic layer is the heart of the application. It is also responsible for authorization and hence security is important in this current case. Every method exposed in an interface needs to be annotated with an authorization check, stating what role(s) a caller must provide in order to be allowed to make the call. The authorization concept is described link:guide-security.asciidoc#authorization[here]. === Direct Object References A security threat are https://www.owasp.org/index.php/Top_10_2013-A4-Insecure_Direct_Object_References[Insecure Direct Object References]. This simply gives you two options: -* avoid direct object references at all +* avoid direct object references * ensure that direct object references are secure -Especially when using REST, direct object references via technical IDs are common sense. This implies that you have a proper xref:authorization[authorization] in place. This is especially tricky when your authorization does not only rely on the type of the data and according static permissions but also on the data itself. Vulnerabilities for this threat can easily happen by design flaws and inadvertence. Here is an example from our sample application: +Especially when using REST, direct object references via technical IDs are common sense. This implies that you have a proper xref:authorization[authorization] in place. This is especially tricky when your authorization does not only rely on the type of the data and according to static permissions but also on the data itself. Vulnerabilities for this threat can easily happen by design flaws and inadvertence. Here is an example from our sample application: -We have a generic use-case to manage BLOBs. In the first place it makes sense to write a generic REST service to load and save these BLOBs. However, the permission to read or even update such BLOB depend on the business object hosting the BLOB. Therefore, such a generic REST service would open the door for this OWASP A4 vulnerability. To solve this in a secure way, you need individual services for each hosting business object to manage the linked BLOB and have to check permissions based on the parent business object. In this example the ID of the BLOB would be the direct object reference and the ID of the business object (and a BLOB property indicator) would be the indirect object reference. +We have a generic use-case to manage BLOBs. In the first place, it makes sense to write a generic REST service to load and save these BLOBs. However, the permission to read or even update such BLOB depends on the business object hosting the BLOB. Therefore, such a generic REST service would open the door for this OWASP A4 vulnerability. To solve this in a secure way, you need individual services for each hosting business object to manage the linked BLOB and have to check permissions based on the parent business object. In this example the ID of the BLOB would be the direct object reference and the ID of the business object (and a BLOB property indicator) would be the indirect object reference. diff --git a/documentation/guide-service-layer.asciidoc b/documentation/guide-service-layer.asciidoc index cf463964..0fd78753 100644 --- a/documentation/guide-service-layer.asciidoc +++ b/documentation/guide-service-layer.asciidoc @@ -13,7 +13,7 @@ are used for communication between different companies, vendors, or partners. * *Internal Services* + are used for communication between different applications in the same application landscape of the same vendor. ** *Back-end Services* + -are internal services between Java back-end components typically with different release and deployment cycles (if not Java consider this as external service). +are internal services between Java back-end components typically with different release and deployment cycles (if not Java consider this as an external service). ** *JS-Client Services* + are internal services provided by the Java back-end for JavaScript clients (GUI). ** *Java-Client Services* + @@ -52,15 +52,15 @@ E.g. creation of the same master-data entity has no effect (no error) * *loosely coupled* + Service consumers have minimum knowledge and dependencies on the service provider. * *normalized* + -complete, no redundancy, minimal +Complete, no redundancy, minimal * *coarse-grained* + Service provides rather large operations (save entire entity or set of entities rather than individual attributes) * *atomic* + Process individual entities (for processing large sets of data, use a link:guide-batch-layer.asciidoc[batch] instead of a service) * *simplicity* + -avoid polymorphism, RPC methods with unique name per signature and no overloading, avoid attachments (consider separate download service), etc. +Avoid polymorphism, RPC methods with unique name per signature and no overloading, avoid attachments (consider separate download service), etc. == Security -Your services are the major entry point to your application. Hence security considerations are important here. +Your services are the major entry point to your application. Hence, security considerations are important here. See link:guide-rest.asciidoc#security[REST Security]. \ No newline at end of file diff --git a/documentation/guide-service-versioning.asciidoc b/documentation/guide-service-versioning.asciidoc index 74a4cfab..0d269652 100644 --- a/documentation/guide-service-versioning.asciidoc +++ b/documentation/guide-service-versioning.asciidoc @@ -6,7 +6,7 @@ toc::[] This guide describes the aspect and details about versioning of link:guide-service-layer.asciidoc[services] == Motivation -Why versioning of services? First of all you should only care about this topic if you really have to. Service versioning is complex and requires effort (time and budget). The best way to avoid this is to be smart in the first place when designing the service API. +Why versioning of services? First of all, you should only care about this topic if you really have to. Service versioning is complex and requires effort (time and budget). The best way to avoid this is to be smart in the first place when designing the service API. Further, if you are creating services where the only consumer is e.g. the web-client that you deploy together with the consumed services then you can change your service without the overhead to create new service versions and keeping old service versions for compatibility. However, if the following indicators are given you typically need to do service versioning: @@ -17,11 +17,11 @@ However, if the following indicators are given you typically need to do service What are incompatible changes? -* Almost any change when link:guide-soap.asciidoc[SOAP] is used (as it changes the WSDL and breaks the contract). Therefore we recommend to use link:guide-rest.asciidoc[REST] instead. Then only the following changes are critical. +* Almost any change when link:guide-soap.asciidoc[SOAP] is used (as it changes the WSDL and breaks the contract). Therefore, we recommend to use link:guide-rest.asciidoc[REST] instead. Then, only the following changes are critical. * A change where existing properties (attributes) have to change their name * A change where existing features (properties, operations, etc.) have to change their semantics (meaning) -Which changes do not cause incompatibilities? +What changes do not cause incompatibilities? * Adding new service operations is entirely uncritical with link:guide-rest.asciidoc[REST]. * Adding new properties is only a problem in the following cases: @@ -48,9 +48,9 @@ The procedure when rolling out incompatible changes is illustrated by the follow +----------------+ ---- -So here we see a simple example where `App3` provides a Service `S` in Version `v1` that is consumed both by `App1` and `App2`. +So, here we see a simple example where `App3` provides a Service `S` in Version `v1` that is consumed both by `App1` and `App2`. -Now for some reason the service `S` has to be changed in an incompatible way to make it proof for future demands. However, upgrading all 3 applications at the same time is not possible here for whatever reason. Therefore service versioning is applied for the changes of `S`. +Now for some reason the service `S` has to be changed in an incompatible way to make it future-proof for demands. However, upgrading all 3 applications at the same time is not possible in this case for whatever reason. Therefore, service versioning is applied for the changes of `S`. [source] ---- @@ -67,7 +67,7 @@ Now for some reason the service `S` has to be changed in an incompatible way to +----------------+ ---- -Now, `App3` has been upgraded and the new release was deployed. A new version `v2` of `S` has been added while still `v1` is kept for compatibility reasons and that version is still used by `App1` and `App2`. +Now, `App3` has been upgraded and the new release was deployed. A new version `v2` of `S` has been added while `v1` is still kept for compatibility reasons and that version is still used by `App1` and `App2`. [source] ---- @@ -84,7 +84,7 @@ Now, `App3` has been upgraded and the new release was deployed. A new version `v +----------------+ ---- -Now, `App2` has been updated and deployed that is using the new version `v2` of `S`. +Now, `App2` has been updated and deployed and it is using the new version `v2` of `S`. [source] ---- @@ -101,7 +101,7 @@ Now, `App2` has been updated and deployed that is using the new version `v2` of +----------------+ ---- -Now, also `App1` has been updated and deployed that is using the new version `v2` of `S`. The version `v1` of `S` is not used anymore. This can be verified via logging and monitoring. +Now, also `App1` has been updated and deployed and it is using the new version `v2` of `S`. The version `v1` of `S` is not used anymore. This can be verified via logging and monitoring. [source] ---- @@ -118,7 +118,7 @@ Now, also `App1` has been updated and deployed that is using the new version `v2 +----------------+ ---- -Finally version `v1` of the service `S` was removed from `App3` and the new release has been deployed. +Finally, version `v1` of the service `S` was removed from `App3` and the new release has been deployed. == Versioning Schema In general anything can be used to differentiate versions of a service. Possibilities are: @@ -128,15 +128,15 @@ In general anything can be used to differentiate versions of a service. Possibil * Sequential version numbers (e.g. `v1`, `v2`, `v3`) * Composed version numbers (e.g. `1.0.48-pre-alpha-3-20171231-235959-Strawberry`) -As we are following the KISS principle (see link:architecture.asciidoc#key-principles[key principles]) we propose to use sequential version numbers. These are short, clear, and easy while still allowing to see what version is after another one. Especially composed version numbers (even `1.1` vs. `2.0`) lead to decisions and discussions that easily waste more time than adding value. It is still very easy to maintain an excel sheet or release-notes document that is explaining the changes for each version (`v1`, `v2`, `v3`) of a particular service. +As we are following the KISS principle (see link:architecture.asciidoc#key-principles[key principles]) we propose to use sequential version numbers. These are short, clear, and easy while still allowing to see what version is after another one. Especially composed version numbers (even `1.1` vs. `2.0`) lead to decisions and discussions that easily waste more time than adding value. It is still very easy to maintain an Excel sheet or release-notes document that is explaining the changes for each version (`v1`, `v2`, `v3`) of a particular service. We suggest to always add the version schema to the service URL to be prepared for service versioning even if service versioning is not (yet) actively used. For simplicity it is explicitly stated that you may even do incompatible changes to the current version (typically `v1`) of your service if you can update the according consumers within the same deployment. == Practice -So assuming you know that you have to do service versioning the question is how to do it practically in the code. -The approach is as following for your devon4j project in case of code-first: +So assuming you know that you have to do service versioning, the question is how to do it practically in the code. +The approach for your devon4j project in case of code-first should be as described below: -* Determine which types in the code need to be changed. That is for sure the API and implementation of the according service but most likely also impacts transfer objects and potentially even datatypes. +* Determine which types in the code need to be changed. It is likely to be the API and implementation of the according service but it may also impact transfer objects and potentially even datatypes. * Create new packages for all these concerned types containing the current version number (e.g. `v1`). * Copy all these types to that new packages. * Rename these copies so they carry the version number as suffix (e.g. `V1`). @@ -144,15 +144,15 @@ The approach is as following for your devon4j project in case of code-first: * Now you have two versions of the same service (e.g. `v1` and `v2`) but so far they behave exactly the same. * You start with your actual changes and modify the original files that have been copied before. * You will also ensure the links (import statements) of the copied types point to the copies with the version number -* This will cause incompatibilities (and compile errors) in the copied service. Therefore you need to fix that service implementation to map from the old API to the new API and behavior. In some cases this may be easy (e.g. mapping `x.y.z.v1.FooTo` to `x.y.z.FooTo` using link:guide-beanmapping.asciidoc[bean-mapping] with some custom mapping for the incompatible change), in other cases this can get very complex. Be aware of this complexity from the start before you make your decision about service versioning. -* As far as possible this mapping should be done in the service-layer, to not pollute your business code in the core-layer with versioning-aspects. If there is no way to handle it in the service layer, e.g. you need some data from the persistence-layer, implement the "mapping" in the core-layer then, but don't forget to remove this code, when removing the old service version. -* Finally ensure that both the old service behaves as before as well as the new service works as planned. +* This will cause incompatibilities (and compile errors) in the copied service. Therefore, you need to fix that service implementation to map from the old API to the new API and behavior. In some casesc, this may be easy (e.g. mapping `x.y.z.v1.FooTo` to `x.y.z.FooTo` using link:guide-beanmapping.asciidoc[bean-mapping] with some custom mapping for the incompatible changes), in other cases this can get very complex. Be aware of this complexity from the start before you make your decision about service versioning. +* As far as possible this mapping should be done in the service-layer, not to pollute your business code in the core-layer with versioning-aspects. If there is no way to handle it in the service layer, e.g. you need some data from the persistence-layer, implement the "mapping" in the core-layer then, but don't forget to remove this code, when removing the old service version. +* Finally, ensure that both the old service behaves as before as well as the new service works as planned. === Modularization -For modularization we also follow the KISS principle (see link:architecture.asciidoc#key-principles[key principles]): -We suggest to have one `api` module per application that will contain the most recent version of your service and gets released with every release-version of the application. The compatibility code with the versioned packages will be added to the `core` module and is therefore not exposed via the `api` module (because it has already been exposed in the previous release of the app). This way you can always for sure determine which version of a service is used by another application just by its maven dependencies. +For modularization, we also follow the KISS principle (see link:architecture.asciidoc#key-principles[key principles]): +we suggest to have one `api` module per application that will contain the most recent version of your service and get released with every release-version of the application. The compatibility code with the versioned packages will be added to the `core` module and therefore is not exposed via the `api` module (because it has already been exposed in the previous release of the app). This way, you can always determine for sure which version of a service is used by another application just by its maven dependencies. -The KISS approach with only a single module that may contain multiple services (e.g. one for each business component) will cause problems when you want to have mixed usages of service versions: You can not use an old version of one service and a new version of another service from the same APP as then you would need to have its API module twice as dependency with different versions what is not possible. However, to avoid complicated overhead for exotic problems we still suggest to follow this easy approach. Only if you come to the point that you really need this complexity you can still solve it (even afterwards by publishing another maven artefact). As we are all on our way to build more but smaller applications (SOA, microservices, etc.) we should always start simple and only add complexity when really needed. +The KISS approach with only a single module that may contain multiple services (e.g. one for each business component) will cause problems when you want to have mixed usages of service versions: You can not use an old version of one service and a new version of another service from the same APP as then you would need to have its API module twice as a dependency on different versions, which is not possible. However, to avoid complicated overhead we always suggest to follow this easy approach. Only if you come to the point that you really need this complexity you can still solve it (even afterwards by publishing another maven artefact). As we are all on our way to build more but smaller applications (SOA, microservices, etc.) we should always start simple and only add complexity when really needed. The following example gives an idea of the structure: diff --git a/documentation/guide-usecase.asciidoc b/documentation/guide-usecase.asciidoc index 45ece640..fad76a0f 100644 --- a/documentation/guide-usecase.asciidoc +++ b/documentation/guide-usecase.asciidoc @@ -4,7 +4,7 @@ toc::[] = UseCase A use-case is a small unit of the link:guide-logic-layer.asciidoc[logic layer] responsible for an operation on a particular link:guide-jpa.asciidoc#entity[entity] (business object). It is defined by an interface (API) with its according implementation. -Following our link:coding-conventions.asciidoc#architecture-mapping[architecture-mapping] use-cases are named `Uc«Operation»«BusinessObject»[Impl]`. The prefix `Uc` stands for use-case and allows to easily find and identify them in your IDE. The `«Operation»` stands for a verb that is operated on the entity identified by `«BusinessObject»`. +Following our link:coding-conventions.asciidoc#architecture-mapping[architecture-mapping], use-cases are named `Uc«Operation»«BusinessObject»[Impl]`. The prefix `Uc` stands for use-case and allows to easily find and identify them in your IDE. The `«Operation»` stands for a verb that is operated on the entity identified by `«BusinessObject»`. For https://en.wikipedia.org/wiki/Create,_read,_update_and_delete[CRUD] we use the standard operations `Find` and `Manage` that can be generated by https://github.com/devonfw/cobigen[CobiGen]. This also separates read and write operations (e.g. if you want to do CQSR, or to configure read-only transactions for read operations). == Find @@ -41,7 +41,7 @@ public interface UcManageBooking { == Custom Any other non CRUD operation `Uc«Operation»«BusinessObject»` uses any other custom verb for `«Operation»`. -Typically such custom use-cases only define a single method. +Typically, such custom use-cases only define a single method. Here is an example: [source,java] ---- @@ -53,7 +53,9 @@ public interface UcApproveBooking { ---- == Implementation -For the implementation of a use-case the same rules apply that are described for the link:guide-component-facade.asciidoc#implementation[component-facade implementation]. +For the implementation of a use-cas, the same rules that are described for the link:guide-component-facade.asciidoc#implementation[component-facade implementation]. + + . However, when following the use-case approach, your component facade simply changes to: @@ -112,14 +114,14 @@ This approach is also illustrated by the following UML diagram: image::images/component-facade-with-use-cases.png["Component facade with use cases.",scaledwidth="80%",align="center"] == Internal use case -Sometimes a component with multiple related entities and many use-cases needs to reuse business logic internally. -Of course this can be exposed as official use-case API but this will imply using transfer-objects (ETOs) instead of entities. In some cases this is undesired e.g. for better performance to prevent unnecessary mapping of entire collections of entities. -In the first place you should try to use abstract base implementations providing reusable methods the actual use-case implementations can inherit from. -If your business logic is even more complex and you have multiple aspects of business logic to share and reuse but also run into multi-inheritance issues, you may also just create use-cases that have their interface located in the `impl` scope package right next to the implementation (or you may just skip the interface). In such case you may define methods that directly take or return entity objects. -To avoid confusion with regular use-cases we recommend to add the `Internal` suffix to the type name leading to `Uc«Operation»«BusinessObject»Internal[Impl]`. +Sometimes, a component with multiple related entities and many use-cases needs to reuse business logic internally. +Of course, this can be exposed as an official use-case API but this will imply using transfer-objects (ETOs) instead of entities. In some cases, this is undesired e.g. for better performance to prevent unnecessary mapping of entire collections of entities. +In the first place, you should try to use abstract base implementations providing reusable methods the actual use-case implementations can inherit from. +If your business logic is even more complex and you have multiple aspects of business logic to share and reuse but also run into multi-inheritance issues, you may also just create use-cases that have their interface located in the `impl` scope package right next to the implementation (or you may just skip the interface). In such a case, you may define methods that directly take or return entity objects. +To avoid confusion with regular use-cases, we recommend to add the `Internal` suffix to the type name leading to `Uc«Operation»«BusinessObject»Internal[Impl]`. == Injection issues -Technically now you have two implementations of your use-case: +Technically, now you have two implementations of your use-case: * the direct implementation of the use-case (`Uc*Impl`) * the component facade implementation (`«Component»Impl`) @@ -127,13 +129,13 @@ Technically now you have two implementations of your use-case: When injecting a use-case interface this could cause ambiguities. This is addressed as following: -* In the component facade implementation (`«Component»Impl`) spring is smart enough to resolve the ambiguity as it assumes that a spring bean never wants to inject itself (can already be access via `this`). -Therefore only the proper use-case implementation remains as candidate and injection works as expected. -* In all other places simply always inject the component facade interface instead of the use-case. +* In the component facade implementation (`«Component»Impl`) spring is smart enough to resolve the ambiguity as it assumes that a spring bean never wants to inject itself (it can already be an access via `this`). +Therefore, only the proper use-case implementation remains as a candidate and injection works as expected. +* In all other places, simply always inject the component facade interface instead of the use-case. In case you might have the lucky occasion to hit this nice exception: ``` org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'uc...Impl': Bean with name 'uc...Impl' has been injected into other beans [...Impl] in its raw version as part of a circular reference, but has eventually been wrapped. This means that said other beans do not use the final version of the bean. This is often the result of over-eager type matching - consider using 'getBeanNamesOfType' with the 'allowEagerInit' flag turned off, for example. ``` -To get rid of such error you need to annotate your according implementation also with `@Lazy` in addition to `@Named`. \ No newline at end of file +To get rid of such an error you need to annotate your according implementation also with `@Lazy` in addition to `@Named`. \ No newline at end of file From 2f66b7368f8b3d59c021c6425c15321ec3a5eb18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Hohwiller?= Date: Fri, 4 Dec 2020 10:18:51 +0100 Subject: [PATCH 02/43] fixed casesc -> cases --- documentation/guide-service-versioning.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/guide-service-versioning.asciidoc b/documentation/guide-service-versioning.asciidoc index 0d269652..ba0cdf0b 100644 --- a/documentation/guide-service-versioning.asciidoc +++ b/documentation/guide-service-versioning.asciidoc @@ -144,7 +144,7 @@ The approach for your devon4j project in case of code-first should be as describ * Now you have two versions of the same service (e.g. `v1` and `v2`) but so far they behave exactly the same. * You start with your actual changes and modify the original files that have been copied before. * You will also ensure the links (import statements) of the copied types point to the copies with the version number -* This will cause incompatibilities (and compile errors) in the copied service. Therefore, you need to fix that service implementation to map from the old API to the new API and behavior. In some casesc, this may be easy (e.g. mapping `x.y.z.v1.FooTo` to `x.y.z.FooTo` using link:guide-beanmapping.asciidoc[bean-mapping] with some custom mapping for the incompatible changes), in other cases this can get very complex. Be aware of this complexity from the start before you make your decision about service versioning. +* This will cause incompatibilities (and compile errors) in the copied service. Therefore, you need to fix that service implementation to map from the old API to the new API and behavior. In some cases, this may be easy (e.g. mapping `x.y.z.v1.FooTo` to `x.y.z.FooTo` using link:guide-beanmapping.asciidoc[bean-mapping] with some custom mapping for the incompatible changes), in other cases this can get very complex. Be aware of this complexity from the start before you make your decision about service versioning. * As far as possible this mapping should be done in the service-layer, not to pollute your business code in the core-layer with versioning-aspects. If there is no way to handle it in the service layer, e.g. you need some data from the persistence-layer, implement the "mapping" in the core-layer then, but don't forget to remove this code, when removing the old service version. * Finally, ensure that both the old service behaves as before as well as the new service works as planned. From 899e978c5901f23c4cc5ee9d0bc3ac1e8feca5b8 Mon Sep 17 00:00:00 2001 From: Dixit Date: Fri, 5 Feb 2021 09:52:28 +0530 Subject: [PATCH 03/43] changed configuration of flyway into liquibase --- .../archetype-resources/core/pom.xml | 520 +++++++++--------- .../src/main/resources/application.properties | 4 +- .../resources/config/application.properties | 5 +- .../db/changelog/changelog-master.xml | 9 + .../resources/db/changelog/changelog-v1.0.xml | 8 + 5 files changed, 284 insertions(+), 262 deletions(-) create mode 100644 templates/server/src/main/resources/archetype-resources/core/src/main/resources/db/changelog/changelog-master.xml create mode 100644 templates/server/src/main/resources/archetype-resources/core/src/main/resources/db/changelog/changelog-v1.0.xml diff --git a/templates/server/src/main/resources/archetype-resources/core/pom.xml b/templates/server/src/main/resources/archetype-resources/core/pom.xml index 5e1c614b..a94b57f6 100644 --- a/templates/server/src/main/resources/archetype-resources/core/pom.xml +++ b/templates/server/src/main/resources/archetype-resources/core/pom.xml @@ -1,258 +1,264 @@ - - - 4.0.0 - - ${groupId} - ${rootArtifactId} - ${version} - - ${rootArtifactId}-core - jar - ${project.artifactId} - Core of the server for the ${rootArtifactId} application - a simple example based on devon4j. - - - - ${project.groupId} - ${rootArtifactId}-api - ${project.version} - - - - - com.devonfw.java.modules - devon4j-beanmapping-orika - - - - - com.devonfw.java.starters - devon4j-starter-security - - - - com.devonfw.java.modules - devon4j-web - - - - - com.devonfw.java.starters - devon4j-starter-cxf-client-rest - - - - com.devonfw.java.starters - devon4j-starter-cxf-client-ws - - - - - com.devonfw.java.starters - devon4j-starter-cxf-server-rest - - - - com.devonfw.java.starters - devon4j-starter-cxf-server-ws - - - - - com.devonfw.java.starters - devon4j-starter-spring-data-jpa - - - - - org.springframework.boot - spring-boot-starter-jdbc - - - - - javax.persistence - javax.persistence-api - - - - - org.hibernate - hibernate-entitymanager - - - - - com.querydsl - querydsl-jpa - - - com.querydsl - querydsl-apt - provided - - - - - org.hibernate.validator - hibernate-validator - - - - - javax.servlet - javax.servlet-api - provided - - - - - javax.el - javax.el-api - - - - - org.springframework - spring-webmvc - - - - -#if ($dbType == 'h2') - com.h2database - h2 -#elseif ($dbType == 'hsqldb') - org.hsqldb - hsqldb - 2.4.0 -#elseif ($dbType == 'postgresql') - org.postgresql - postgresql - -#elseif ($dbType == 'mysql') - mysql - mysql-connector-java - 8.0.8-dmr -#elseif ($dbType == 'mariadb') - org.mariadb.jdbc - mariadb-java-client - 1.5.4 -#elseif ($dbType == 'hana') - com.sap.cloud.db.jdbc - ngdbc - 2.3.48 -#elseif ($dbType == 'oracle') - com.oracle.jdbc - ojdbc8 - 12.2.0.1 -#elseif ($dbType == 'mssql') - com.microsoft.sqlserver - mssql-jdbc - 6.4.0.jre8 -#else - $dbType - $dbType - TODO -#end - -#if ($dbType != 'h2') - - com.h2database - h2 - test - -#end - - - - org.flywaydb - flyway-core - - - - - org.apache.cxf - cxf-rt-rs-service-description - - - - - org.springframework.boot - spring-boot-starter-actuator - - - - - org.springframework - spring-aop - - - - - cglib - cglib - - - - - net.logstash.logback - logstash-logback-encoder - - - - - com.devonfw.java.modules - devon4j-test-jpa - test - - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-tomcat - - - org.springframework.boot - spring-boot-starter-validation - - - - - - - - embedded - - true - - - - org.springframework.boot - spring-boot-starter-tomcat - - - - - - - - - org.apache.maven.plugins - maven-jar-plugin - - - config/application.properties - - - - - - + + + 4.0.0 + + ${groupId} + ${rootArtifactId} + ${version} + + ${rootArtifactId}-core + jar + ${project.artifactId} + Core of the server for the ${rootArtifactId} application - a simple example based on devon4j. + + + + ${project.groupId} + ${rootArtifactId}-api + ${project.version} + + + + + com.devonfw.java.modules + devon4j-beanmapping-orika + + + + + com.devonfw.java.starters + devon4j-starter-security + + + + com.devonfw.java.modules + devon4j-web + + + + + com.devonfw.java.starters + devon4j-starter-cxf-client-rest + + + + com.devonfw.java.starters + devon4j-starter-cxf-client-ws + + + + + com.devonfw.java.starters + devon4j-starter-cxf-server-rest + + + + com.devonfw.java.starters + devon4j-starter-cxf-server-ws + + + + + com.devonfw.java.starters + devon4j-starter-spring-data-jpa + + + + + org.springframework.boot + spring-boot-starter-jdbc + + + + + javax.persistence + javax.persistence-api + + + + + org.hibernate + hibernate-entitymanager + + + + + com.querydsl + querydsl-jpa + + + com.querydsl + querydsl-apt + provided + + + + + org.hibernate.validator + hibernate-validator + + + + + javax.servlet + javax.servlet-api + provided + + + + + javax.el + javax.el-api + + + + + org.springframework + spring-webmvc + + + + +#if ($dbType == 'h2') + com.h2database + h2 +#elseif ($dbType == 'hsqldb') + org.hsqldb + hsqldb + 2.4.0 +#elseif ($dbType == 'postgresql') + org.postgresql + postgresql + +#elseif ($dbType == 'mysql') + mysql + mysql-connector-java + 8.0.8-dmr +#elseif ($dbType == 'mariadb') + org.mariadb.jdbc + mariadb-java-client + 1.5.4 +#elseif ($dbType == 'hana') + com.sap.cloud.db.jdbc + ngdbc + 2.3.48 +#elseif ($dbType == 'oracle') + com.oracle.jdbc + ojdbc8 + 12.2.0.1 +#elseif ($dbType == 'mssql') + com.microsoft.sqlserver + mssql-jdbc + 6.4.0.jre8 +#else + $dbType + $dbType + TODO +#end + +#if ($dbType != 'h2') + + com.h2database + h2 + test + +#end + + + org.liquibase + liquibase-core + + + + + org.apache.cxf + cxf-rt-rs-service-description + + + + + org.springframework.boot + spring-boot-starter-actuator + + + + + org.springframework + spring-aop + + + + + cglib + cglib + + + + + net.logstash.logback + logstash-logback-encoder + + + + + com.devonfw.java.modules + devon4j-test-jpa + test + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-tomcat + + + org.springframework.boot + spring-boot-starter-validation + + + + + + + + embedded + + true + + + + org.springframework.boot + spring-boot-starter-tomcat + + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + config/application.properties + + + + + org.liquibase + liquibase-maven-plugin + + src/main/resources/config/application.properties + true + + + + \ No newline at end of file diff --git a/templates/server/src/main/resources/archetype-resources/core/src/main/resources/application.properties b/templates/server/src/main/resources/archetype-resources/core/src/main/resources/application.properties index be1ebdc9..3c86bd92 100644 --- a/templates/server/src/main/resources/archetype-resources/core/src/main/resources/application.properties +++ b/templates/server/src/main/resources/archetype-resources/core/src/main/resources/application.properties @@ -69,5 +69,5 @@ spring.jpa.open-in-view=false # see http://stackoverflow.com/questions/22318907/how-to-stop-spring-batch-scheduled-jobs-from-running-at-first-time-when-executin spring.batch.job.enabled=false -# Flyway for Database Setup and Migrations -spring.flyway.locations=classpath:db/migration +# Liquibase for Database Setup and Migrations +spring.liquibase.change-log=classpath:db/changelog/changelog-master.xml diff --git a/templates/server/src/main/resources/archetype-resources/core/src/main/resources/config/application.properties b/templates/server/src/main/resources/archetype-resources/core/src/main/resources/config/application.properties index 04ce2939..6d289180 100644 --- a/templates/server/src/main/resources/archetype-resources/core/src/main/resources/config/application.properties +++ b/templates/server/src/main/resources/archetype-resources/core/src/main/resources/config/application.properties @@ -47,6 +47,5 @@ spring.jpa.properties.hibernate.format_sql=true # Enable JSON pretty printing spring.jackson.serialization.INDENT_OUTPUT=true -# Flyway for Database Setup and Migrations -spring.flyway.enabled=true -spring.flyway.clean-on-validation-error=true +# Liquibase configuration for DB migration +spring.liquibase.enabled=true diff --git a/templates/server/src/main/resources/archetype-resources/core/src/main/resources/db/changelog/changelog-master.xml b/templates/server/src/main/resources/archetype-resources/core/src/main/resources/db/changelog/changelog-master.xml new file mode 100644 index 00000000..c7f1737b --- /dev/null +++ b/templates/server/src/main/resources/archetype-resources/core/src/main/resources/db/changelog/changelog-master.xml @@ -0,0 +1,9 @@ + + + + + \ No newline at end of file diff --git a/templates/server/src/main/resources/archetype-resources/core/src/main/resources/db/changelog/changelog-v1.0.xml b/templates/server/src/main/resources/archetype-resources/core/src/main/resources/db/changelog/changelog-v1.0.xml new file mode 100644 index 00000000..50b8cbdb --- /dev/null +++ b/templates/server/src/main/resources/archetype-resources/core/src/main/resources/db/changelog/changelog-v1.0.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file From 7023dc661c7ac50e6cc41b20c6ec8267678a51a2 Mon Sep 17 00:00:00 2001 From: Dixit Date: Mon, 15 Feb 2021 17:46:39 +0530 Subject: [PATCH 04/43] added both flyway and liquibase configuration --- templates/pom.xml | 62 ++++-- .../META-INF/maven/archetype-metadata.xml | 184 +++++++++--------- .../base/test/SpringBatchIntegrationTest.java | 53 ----- .../archetype-resources/core/pom.xml | 18 +- .../src/main/resources/application.properties | 8 +- .../resources/config/application.properties | 8 +- .../projects/basic/archetype.properties | 3 +- .../projects/batch/archetype.properties | 3 +- .../projects/enterprise/archetype.properties | 3 +- 9 files changed, 170 insertions(+), 172 deletions(-) delete mode 100644 templates/server/src/main/resources/archetype-resources/__batch__/src/test/java/__packageInPathFormat__/general/batch/base/test/SpringBatchIntegrationTest.java diff --git a/templates/pom.xml b/templates/pom.xml index 157b7e4d..43e0f835 100644 --- a/templates/pom.xml +++ b/templates/pom.xml @@ -1,19 +1,43 @@ - - - 4.0.0 - - com.devonfw.java.dev - devon4j - dev-SNAPSHOT - - devon4j-templates - pom - ${project.artifactId} - Templates (maven archetypes) of devon4j. - - - server - - - + + + + + 4.0.0 + + + + + + com.devonfw.java.dev + + + devon4j + + + dev-SNAPSHOT + + + + + + devon4j-templates + + + pom + + + ${project.artifactId} + + + Templates (maven archetypes) of devon4j. + + + + + + server + + + + + diff --git a/templates/server/src/main/resources/META-INF/maven/archetype-metadata.xml b/templates/server/src/main/resources/META-INF/maven/archetype-metadata.xml index d8b04ca1..f7491930 100644 --- a/templates/server/src/main/resources/META-INF/maven/archetype-metadata.xml +++ b/templates/server/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -1,90 +1,94 @@ - - - devon4j-template-server - - - - . - - - h2 - - - - . - batch|[.] - - - - - - - api - - **/*.* - - - - core - - **/*.* - - - - __earProjectName__ - - **/*.* - - - - - __batch__ - - **/*.* - - - - - - .gitignore - - - - - - - - src/main/java - - - src/main/resources - - - src/test/java - - - src/test/resources - - - src/main/webapp - - - - - + + + devon4j-template-server + + + + . + + + h2 + + + + flyway + + + + . + batch|[.] + + + + + + + api + + **/*.* + + + + core + + **/*.* + + + + __earProjectName__ + + **/*.* + + + + + __batch__ + + **/*.* + + + + + + .gitignore + + + + + + + + src/main/java + + + src/main/resources + + + src/test/java + + + src/test/resources + + + src/main/webapp + + + + + diff --git a/templates/server/src/main/resources/archetype-resources/__batch__/src/test/java/__packageInPathFormat__/general/batch/base/test/SpringBatchIntegrationTest.java b/templates/server/src/main/resources/archetype-resources/__batch__/src/test/java/__packageInPathFormat__/general/batch/base/test/SpringBatchIntegrationTest.java deleted file mode 100644 index 6bea2912..00000000 --- a/templates/server/src/main/resources/archetype-resources/__batch__/src/test/java/__packageInPathFormat__/general/batch/base/test/SpringBatchIntegrationTest.java +++ /dev/null @@ -1,53 +0,0 @@ -package ${package}.general.batch.base.test; - -import javax.inject.Inject; - -import org.flywaydb.core.Flyway; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.batch.core.Job; -import org.springframework.batch.core.launch.JobLauncher; -import org.springframework.batch.test.JobLauncherTestUtils; - -import ${package}.general.common.base.test.TestUtil; -import com.devonfw.module.test.common.base.ComponentTest; - -/** - * Base class for all spring batch integration tests. It helps to do End-to-End job tests. - */ -public abstract class SpringBatchIntegrationTest extends ComponentTest { - - @Inject - private JobLauncher jobLauncher; - - @Inject - private Flyway flyway; - - @Override - protected void doSetUp() { - - super.doSetUp(); - this.flyway.clean(); - this.flyway.migrate(); - } - - @Override - protected void doTearDown() { - - super.doTearDown(); - TestUtil.logout(); - } - - /** - * @param job job to configure - * @return jobLauncherTestUtils - */ - public JobLauncherTestUtils getJobLauncherTestUtils(Job job) { - - JobLauncherTestUtils jobLauncherTestUtils = new JobLauncherTestUtils(); - jobLauncherTestUtils.setJob(job); - jobLauncherTestUtils.setJobLauncher(this.jobLauncher); - - return jobLauncherTestUtils; - } -} diff --git a/templates/server/src/main/resources/archetype-resources/core/pom.xml b/templates/server/src/main/resources/archetype-resources/core/pom.xml index a94b57f6..f974d3bf 100644 --- a/templates/server/src/main/resources/archetype-resources/core/pom.xml +++ b/templates/server/src/main/resources/archetype-resources/core/pom.xml @@ -166,12 +166,20 @@ test #end - - - org.liquibase - liquibase-core - + + +#if ($dbMigration == 'flyway') + + org.flywaydb + flyway-core + +#else + + org.liquibase + liquibase-core + +#end org.apache.cxf diff --git a/templates/server/src/main/resources/archetype-resources/core/src/main/resources/application.properties b/templates/server/src/main/resources/archetype-resources/core/src/main/resources/application.properties index 3c86bd92..bc0a35ee 100644 --- a/templates/server/src/main/resources/archetype-resources/core/src/main/resources/application.properties +++ b/templates/server/src/main/resources/archetype-resources/core/src/main/resources/application.properties @@ -69,5 +69,11 @@ spring.jpa.open-in-view=false # see http://stackoverflow.com/questions/22318907/how-to-stop-spring-batch-scheduled-jobs-from-running-at-first-time-when-executin spring.batch.job.enabled=false -# Liquibase for Database Setup and Migrations + + +# Configuration for Database Setup and Migrations +#if ($dbMigration == 'flyway') +spring.flyway.locations=classpath:db/migration +#else spring.liquibase.change-log=classpath:db/changelog/changelog-master.xml +#end diff --git a/templates/server/src/main/resources/archetype-resources/core/src/main/resources/config/application.properties b/templates/server/src/main/resources/archetype-resources/core/src/main/resources/config/application.properties index 6d289180..ccfa335c 100644 --- a/templates/server/src/main/resources/archetype-resources/core/src/main/resources/config/application.properties +++ b/templates/server/src/main/resources/archetype-resources/core/src/main/resources/config/application.properties @@ -47,5 +47,11 @@ spring.jpa.properties.hibernate.format_sql=true # Enable JSON pretty printing spring.jackson.serialization.INDENT_OUTPUT=true -# Liquibase configuration for DB migration +# Configuration for Database Setup and Migrations +#if ($dbMigration == 'flyway') +spring.flyway.enabled=true +spring.flyway.clean-on-validation-error=true +#else spring.liquibase.enabled=true +#end + diff --git a/templates/server/src/test/resources/projects/basic/archetype.properties b/templates/server/src/test/resources/projects/basic/archetype.properties index 013232af..5af903a8 100644 --- a/templates/server/src/test/resources/projects/basic/archetype.properties +++ b/templates/server/src/test/resources/projects/basic/archetype.properties @@ -5,4 +5,5 @@ groupId=archetype.it artifactId=basic earProjectName=. batch=. -dbType=h2 \ No newline at end of file +dbType=h2 +dbMigration=flyway \ No newline at end of file diff --git a/templates/server/src/test/resources/projects/batch/archetype.properties b/templates/server/src/test/resources/projects/batch/archetype.properties index 552b794c..f30b83ec 100644 --- a/templates/server/src/test/resources/projects/batch/archetype.properties +++ b/templates/server/src/test/resources/projects/batch/archetype.properties @@ -5,4 +5,5 @@ groupId=archetype.it artifactId=app-with-batch earProjectName=. batch=batch -dbType=mysql \ No newline at end of file +dbType=mysql +dbMigration=flyway \ No newline at end of file diff --git a/templates/server/src/test/resources/projects/enterprise/archetype.properties b/templates/server/src/test/resources/projects/enterprise/archetype.properties index a8e0f5ed..9a75406b 100644 --- a/templates/server/src/test/resources/projects/enterprise/archetype.properties +++ b/templates/server/src/test/resources/projects/enterprise/archetype.properties @@ -5,4 +5,5 @@ groupId=archetype.it artifactId=enterprise earProjectName=${artifactId}-ear batch=. -dbType=postgresql \ No newline at end of file +dbType=postgresql +dbMigration=flyway \ No newline at end of file From 1c9b7f8c74aa3033708b05c69b1e35a28a53b29c Mon Sep 17 00:00:00 2001 From: dixyushi Date: Mon, 12 Apr 2021 13:20:31 +0530 Subject: [PATCH 05/43] resolved testcleanerplugin issue --- modules/test-jpa/pom.xml | 23 ++++++++++ .../clean/TestCleanerPluginLiquibase.java | 45 +++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginLiquibase.java diff --git a/modules/test-jpa/pom.xml b/modules/test-jpa/pom.xml index 7030098c..2674eb69 100644 --- a/modules/test-jpa/pom.xml +++ b/modules/test-jpa/pom.xml @@ -25,5 +25,28 @@ org.flywaydb flyway-core + + org.liquibase + liquibase-core + + + + + org.flywaydb + flyway-maven-plugin + + /devon4j-test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginFlyway.java + + + + org.liquibase + liquibase-maven-plugin + + /devon4j-test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginLiquibase.java + + + + + \ No newline at end of file diff --git a/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginLiquibase.java b/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginLiquibase.java new file mode 100644 index 00000000..c9104da4 --- /dev/null +++ b/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginLiquibase.java @@ -0,0 +1,45 @@ +package com.devonfw.module.test.common.base.clean; + +import javax.inject.Inject; +import liquibase.Liquibase; + +/** + * @author ayudixit + * + */ +public class TestCleanerPluginLiquibase implements TestCleanerPlugin { + + @Inject + private Liquibase liquibase; + + /** + * The constructor. + */ + public TestCleanerPluginLiquibase() { + + super(); + } + + /** + * The constructor. + * + * @param liquibase the {@link Liquibase} instance. + */ + public TestCleanerPluginLiquibase(Liquibase liquibase) { + + super(); + this.liquibase = liquibase; + } + + @Override + public void cleanup() { + + try { + this.liquibase.dropAll(); + } catch (Exception e) { + e.printStackTrace(); + } + + } + +} From 2a797ae4712eb6ef94d801a7283946cd3e4c4e2f Mon Sep 17 00:00:00 2001 From: dixyushi Date: Wed, 14 Apr 2021 01:51:34 +0530 Subject: [PATCH 06/43] resolved conflicts --- .../META-INF/maven/archetype-metadata.xml | 18 ++++++++++++------ .../resources/archetype-resources/core/pom.xml | 11 +++++++---- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/templates/server/src/main/resources/META-INF/maven/archetype-metadata.xml b/templates/server/src/main/resources/META-INF/maven/archetype-metadata.xml index f7491930..47874b1a 100644 --- a/templates/server/src/main/resources/META-INF/maven/archetype-metadata.xml +++ b/templates/server/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -13,13 +13,13 @@ h2 - - flyway - + + flyway + . - batch|[.] + batch|[.] @@ -69,7 +69,13 @@ .gitignore - + + .mvn + + **/*.* + + + @@ -91,4 +97,4 @@ - + \ No newline at end of file diff --git a/templates/server/src/main/resources/archetype-resources/core/pom.xml b/templates/server/src/main/resources/archetype-resources/core/pom.xml index f974d3bf..83cdf7d2 100644 --- a/templates/server/src/main/resources/archetype-resources/core/pom.xml +++ b/templates/server/src/main/resources/archetype-resources/core/pom.xml @@ -1,11 +1,11 @@ - + 4.0.0 ${groupId} ${rootArtifactId} - ${version} + ${app.version} ${rootArtifactId}-core jar @@ -167,8 +167,8 @@ #end + - #if ($dbMigration == 'flyway') org.flywaydb @@ -243,6 +243,8 @@ org.springframework.boot spring-boot-starter-tomcat + + ${spring.boot.version} @@ -259,7 +261,7 @@ - + org.liquibase liquibase-maven-plugin @@ -269,4 +271,5 @@ + \ No newline at end of file From b461dfb170753bf42602018b203c4403bf0dc06f Mon Sep 17 00:00:00 2001 From: dixyushi Date: Wed, 21 Apr 2021 01:56:57 +0530 Subject: [PATCH 07/43] added conditions for dbMigration in testDBConfig --- modules/test-jpa/pom.xml | 21 ++----------------- .../archetype-resources/core/pom.xml | 3 --- .../common/impl/config/TestDbConfig.java | 13 ++++++++++-- 3 files changed, 13 insertions(+), 24 deletions(-) diff --git a/modules/test-jpa/pom.xml b/modules/test-jpa/pom.xml index 2674eb69..e1e430d1 100644 --- a/modules/test-jpa/pom.xml +++ b/modules/test-jpa/pom.xml @@ -24,29 +24,12 @@ org.flywaydb flyway-core + true org.liquibase liquibase-core + true - - - - org.flywaydb - flyway-maven-plugin - - /devon4j-test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginFlyway.java - - - - org.liquibase - liquibase-maven-plugin - - /devon4j-test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginLiquibase.java - - - - - \ No newline at end of file diff --git a/templates/server/src/main/resources/archetype-resources/core/pom.xml b/templates/server/src/main/resources/archetype-resources/core/pom.xml index 83cdf7d2..37ef24c6 100644 --- a/templates/server/src/main/resources/archetype-resources/core/pom.xml +++ b/templates/server/src/main/resources/archetype-resources/core/pom.xml @@ -64,9 +64,6 @@ devon4j-starter-spring-data-jpa - org.springframework.boot spring-boot-starter-jdbc diff --git a/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/impl/config/TestDbConfig.java b/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/impl/config/TestDbConfig.java index 5f33fcf9..371bb2dd 100644 --- a/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/impl/config/TestDbConfig.java +++ b/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/impl/config/TestDbConfig.java @@ -7,6 +7,7 @@ import com.devonfw.module.test.common.base.clean.TestCleanerImpl; import com.devonfw.module.test.common.base.clean.TestCleanerPlugin; import com.devonfw.module.test.common.base.clean.TestCleanerPluginFlyway; +import com.devonfw.module.test.common.base.clean.TestCleanerPluginLiquibase; /** * {@link Configuration} for Database in JUnit tests. @@ -27,9 +28,17 @@ public TestCleaner testCleaner() { * @return the {@link TestCleanerPluginFlyway}. */ @Bean - public TestCleanerPlugin testCleanerPluginFlyway() { + public TestCleanerPlugin testCleanerPlugin() { + + String dbMigrationValue = System.getenv($dbMigration); + + if(dbMigrationValue==null) + { return new TestCleanerPluginFlyway(); + + }else if(dbMigrationValue=="liquibase") { + return new TestCleanerPluginLiquibase(); } - } +} \ No newline at end of file From 8f704fd4e72a29bfd26fbbd3171db92c8a5fd3ba Mon Sep 17 00:00:00 2001 From: dixyushi Date: Wed, 19 May 2021 12:14:59 +0530 Subject: [PATCH 08/43] All required configurations and changes are done to implement --- modules/test/src/main/resources/logback.xml | 1 + pom.xml | 971 ++++++++++++++++-- templates/server/flywayy/pom.xml | 491 +++++++++ .../archetype-resources/core/pom.xml | 76 +- .../common/base/test/DbTestHelper.java | 86 +- .../common/impl/config/TestDbConfig.java | 45 +- .../impl/config/TestWebSecurityConfig.java | 1 + .../resources/config/application.properties | 14 +- .../db/changelog/changelog-master.xml | 9 + .../resources/db/changelog/changelog-v1.0.xml | 8 + .../resources/archetype-resources/pom.xml | 3 +- 11 files changed, 1562 insertions(+), 143 deletions(-) create mode 100644 templates/server/flywayy/pom.xml create mode 100644 templates/server/src/main/resources/archetype-resources/core/src/test/resources/db/changelog/changelog-master.xml create mode 100644 templates/server/src/main/resources/archetype-resources/core/src/test/resources/db/changelog/changelog-v1.0.xml diff --git a/modules/test/src/main/resources/logback.xml b/modules/test/src/main/resources/logback.xml index d4b83a52..d042e45d 100644 --- a/modules/test/src/main/resources/logback.xml +++ b/modules/test/src/main/resources/logback.xml @@ -16,6 +16,7 @@ + diff --git a/pom.xml b/pom.xml index 065357be..0308d799 100644 --- a/pom.xml +++ b/pom.xml @@ -1,67 +1,904 @@ - - - 4.0.0 - - com.devonfw - maven-parent - 6 - - com.devonfw.java.dev - devon4j - dev-SNAPSHOT - pom - ${project.artifactId} - Java stack of devonfw.com (devon4j): develop Java apps standardized, faster and with less risk. - 2014 - - - boms - modules - starters - templates - documentation - - - - dev-SNAPSHOT - devon4j - ${revision} - 2.4.4 - - 2020.0.0 - 2.12.2 - 30.1.1-jre - 5.7.1 - 3.4.3 - 8.7.0 - 1.7.30 - https://sonarcloud.io - devonfw - - - - - - - - org.apache.maven.plugins - maven-war-plugin - - WEB-INF/classes/config/application.properties,*.jsp - ${project.artifactId} - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - ${spring.boot.version} - - - - - + + + + + + + + + + + + + + + + + 4.0.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + com.devonfw + + + + + + + + + + + + + + + maven-parent + + + + + + + + + + + + + + + 6 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + com.devonfw.java.dev + + + + + + + + + + + + + + + devon4j + + + + + + + + + + + + + + + dev-SNAPSHOT + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + pom + + + + + + + + + + + + + + + ${project.artifactId} + + + + + + + + + + + + + + + Java stack of devonfw.com (devon4j): develop Java apps standardized, faster and with less risk. + + + + + + + + + + + + + + + 2014 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + boms + + + + + + + + + + + + + + + modules + + + + + + + + + + + + + + + starters + + + + + + + + + + + + + + + templates + + + + + + + + + + + + + + + documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + dev-SNAPSHOT + + + + + + + + + + + + + + + devon4j + + + + + + + + + + + + + + + ${revision} + + + + + + + + + + + + + + + 2.4.4 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 2020.0.0 + + + + + + + + + + + + + + + 2.12.2 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 30.1.1-jre + + + + + + + + + + + + + + + 5.7.1 + + + + + + + + + + + + + + + 3.4.3 + + + + + + + + + + + + + + + 8.7.0 + + + + + + + + + + + + + + + 1.7.30 + + + + + + + + + + + + + + + https://sonarcloud.io + + + + + + + + + + + + + + + devonfw + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + org.apache.maven.plugins + + + + + + + + + + + + + + + maven-war-plugin + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + WEB-INF/classes/config/application.properties,*.jsp + + + + + + + + + + + + + + + ${project.artifactId} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + org.springframework.boot + + + + + + + + + + + + + + + spring-boot-maven-plugin + + + + + + + + + + + + + + + ${spring.boot.version} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/templates/server/flywayy/pom.xml b/templates/server/flywayy/pom.xml new file mode 100644 index 00000000..2d9b9ad3 --- /dev/null +++ b/templates/server/flywayy/pom.xml @@ -0,0 +1,491 @@ + + + 4.0.0 + flywayy + com.flywayy + ${app.version} + pom + ${project.artifactId} + Application based on the devon4j. + + + 2.4.4 + 2021.04.001-SNAPSHOT + 1.8 + 5.7.1 + UTF-8 + UTF-8 + 2.12.2 + 30.1.1-jre + system + ${revision} + + + + api + core + server + + + + + + + com.fasterxml.jackson + jackson-bom + ${jackson.version} + pom + import + + + + org.junit + junit-bom + ${junit.version} + pom + import + + + + com.google.guava + guava + ${guava.version} + + + + org.springframework.boot + spring-boot-dependencies + ${spring.boot.version} + pom + import + + + + com.devonfw.java.boms + devon4j-bom + ${devon4j.version} + pom + import + + + + + + + org.slf4j + slf4j-api + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + ${project.build.sourceEncoding} + ${java.version} + ${java.version} + + + + + maven-surefire-plugin + + ${devonfw.test.excluded.groups} + true + + + + + + org.jacoco + jacoco-maven-plugin + + + default-prepare-agent + + prepare-agent + + + + default-report + + report + + + + + + + + + org.apache.maven.plugins + maven-resources-plugin + 3.1.0 + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + + org.apache.maven.plugins + maven-install-plugin + 2.5.2 + + + org.apache.maven.plugins + maven-deploy-plugin + 2.8.2 + + + org.apache.maven.plugins + maven-clean-plugin + 3.1.0 + + + org.apache.maven.plugins + maven-jar-plugin + 3.1.2 + + + org.apache.maven.plugins + maven-source-plugin + 3.1.0 + + + org.apache.maven.plugins + maven-site-plugin + 3.7.1 + + + org.apache.maven.plugins + maven-checkstyle-plugin + 3.1.0 + + + org.apache.maven.plugins + maven-changes-plugin + 2.12.1 + + + org.apache.maven.plugins + maven-changelog-plugin + 2.3 + + + org.apache.maven.plugins + maven-project-info-reports-plugin + 3.0.0 + + + org.apache.maven.plugins + maven-jxr-plugin + 3.0.0 + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.1.1 + + + + true + protected + ${project.reporting.outputEncoding} + ${project.build.sourceEncoding} + true + ${user.dir}/src/main/javadoc/stylesheet.css + none + ${java.version} + JavaDocs for ${project.name} ${project.version} + JavaDocs for ${project.name} ${project.version} + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.2 + + + ${basedir} + + + + org.apache.maven.plugins + maven-surefire-report-plugin + 2.22.2 + + + org.apache.maven.plugins + maven-pmd-plugin + 3.9.0 + + ${java.version} + + + + org.apache.maven.plugins + maven-war-plugin + 3.2.3 + + + org.apache.maven.plugins + maven-antrun-plugin + 1.8 + + + org.apache.maven.plugins + maven-help-plugin + 3.2.0 + + + org.apache.maven.plugins + maven-gpg-plugin + 1.6 + + + org.apache.maven.plugins + maven-archetype-plugin + 3.1.2 + + + org.apache.maven.archetype + archetype-packaging + 3.1.2 + + + org.codehaus.mojo + taglist-maven-plugin + 2.4 + + + org.codehaus.mojo + cobertura-maven-plugin + 2.7 + + + org.codehaus.mojo + flatten-maven-plugin + 1.2.2 + + + org.codehaus.mojo + license-maven-plugin + 1.20 + + ${project.build.directory}/generated-resources + true + true + true + true + + Apache Software License, Version 2.0|The Apache Software License, Version 2.0|Apache + 2.0|Apache License, Version 2.0 + + + + + org.codehaus.mojo + servicedocgen-maven-plugin + 1.0.0-beta-3 + + + org.sonarsource.scanner.maven + sonar-maven-plugin + 3.7.0.1746 + + + org.jacoco + jacoco-maven-plugin + 0.8.5 + + + org.owasp + dependency-check-maven + 5.3.2 + + + com.github.spotbugs + spotbugs-maven-plugin + 3.1.12.2 + + + org.springframework.boot + spring-boot-maven-plugin + ${spring.boot.version} + + + + + + + + moduletest + + component,subsystem,system + + + + componenttest + + subsystem,system + + + + subsystemtest + + system + + + + systemtest + + none + + + + security + + + + org.owasp + dependency-check-maven + + 8 + + + + + check + + + + + + + + + licenses + + + + org.codehaus.mojo + license-maven-plugin + + + aggregate-add-third-party + generate-resources + + aggregate-add-third-party + + + + + aggregate-download-licenses + generate-resources + + aggregate-download-licenses + + + + + + + + + + eclipse + + + eclipse.application + + + + eclipse-target + + + + + + + + org.apache.maven.plugins + maven-project-info-reports-plugin + + false + + + + org.apache.maven.plugins + maven-jxr-plugin + + + org.apache.maven.plugins + maven-javadoc-plugin + + + org.codehaus.mojo + taglist-maven-plugin + + + TODO + @todo + FIXME + @deprecated + REVIEW + + + + + org.owasp + dependency-check-maven + + false + + + + + aggregate + check + + + + + + org.codehaus.mojo + servicedocgen-maven-plugin + + + + ${servicedoc.info.title} + ${servicedoc.info.description} + + ${servicedoc.host} + ${servicedoc.port} + ${servicedoc.basePath} + + http + + + + + + org.codehaus.mojo + license-maven-plugin + + + + third-party-report + aggregate-third-party-report + + + + + + + + diff --git a/templates/server/src/main/resources/archetype-resources/core/pom.xml b/templates/server/src/main/resources/archetype-resources/core/pom.xml index d6b1c121..78a8a98a 100644 --- a/templates/server/src/main/resources/archetype-resources/core/pom.xml +++ b/templates/server/src/main/resources/archetype-resources/core/pom.xml @@ -5,7 +5,7 @@ ${groupId} ${rootArtifactId} - ${app.version} + ${app.version} ${rootArtifactId}-core jar @@ -66,7 +66,7 @@ + --> org.springframework.boot spring-boot-starter-jdbc @@ -122,63 +122,65 @@ -#if ($dbType == 'h2') + #if ($dbType == 'h2') com.h2database h2 -#elseif ($dbType == 'hsqldb') + #elseif ($dbType == 'hsqldb') org.hsqldb hsqldb 2.4.0 -#elseif ($dbType == 'postgresql') + #elseif ($dbType == 'postgresql') org.postgresql postgresql - -#elseif ($dbType == 'mysql') + + #elseif ($dbType == 'mysql') mysql mysql-connector-java 8.0.8-dmr -#elseif ($dbType == 'mariadb') + #elseif ($dbType == 'mariadb') org.mariadb.jdbc mariadb-java-client 1.5.4 -#elseif ($dbType == 'hana') + #elseif ($dbType == 'hana') com.sap.cloud.db.jdbc ngdbc 2.3.48 -#elseif ($dbType == 'oracle') + #elseif ($dbType == 'oracle') com.oracle.jdbc ojdbc8 12.2.0.1 -#elseif ($dbType == 'mssql') + #elseif ($dbType == 'mssql') com.microsoft.sqlserver mssql-jdbc 6.4.0.jre8 -#else + #else $dbType $dbType TODO -#end + #end -#if ($dbType != 'h2') + #if ($dbType != 'h2') com.h2database h2 test -#end + #end - -#if ($dbMigration == 'flyway') - - org.flywaydb - flyway-core - -#else - - org.liquibase - liquibase-core - -#end + + #if ($dbMigration == 'flyway') + + org.flywaydb + flyway-core + + #end + + #if ($dbMigration == 'liquibase') + + org.liquibase + liquibase-core + + #end @@ -237,14 +239,14 @@ embedded - true + true org.springframework.boot spring-boot-starter-tomcat - ${spring.boot.version} + ${spring.boot.version} @@ -261,14 +263,18 @@ + + #if($dbMigration == 'liquibase') - org.liquibase - liquibase-maven-plugin - - src/main/resources/config/application.properties - true - + org.liquibase + liquibase-maven-plugin + + + liquibase + + + #end \ No newline at end of file diff --git a/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/base/test/DbTestHelper.java b/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/base/test/DbTestHelper.java index 65ca1e44..3e0dca55 100644 --- a/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/base/test/DbTestHelper.java +++ b/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/base/test/DbTestHelper.java @@ -1,44 +1,88 @@ package ${package}.general.common.base.test; +import javax.inject.Inject; import javax.inject.Named; - +#if ($dbMigration == 'liquibase') + import liquibase.Liquibase; +#else import org.flywaydb.core.Flyway; - +#end /** * This class provides methods for handling the database during testing where resets (and other operations) may be * necessary. */ @Named public class DbTestHelper { + #if ($dbMigration == 'liquibase') + private Liquibase liquibase; + #else + private Flyway flyway; + #end + + #if ($dbMigration == 'liquibase') + /** + * The constructor. + * + * @param liquibase an instance of type {@link Liquibase}. + */ + public DbTestHelper( Liquibase liquibase) { + super(); + this.liquibase = liquibase; + } + #else + /** + * The constructor. + * + * @param flyway an instance of type {@link Flyway}. + */ + public DbTestHelper( Flyway flyway) { + super(); + this.flyway = flyway; + } + #end + + +// public DbTestHelper(#if ($dbMigration == 'liquibase') Liquibase liquibase #else Flyway flyway #end) { +// super(); +// #if ($dbMigration == 'liquibase') +// this.liquibase = liquibase; +// #else +// this.flyway = flyway; +// #end +// } - private Flyway flyway; - + + #if ($dbMigration == 'flyway') /** - * The constructor. - * - * @param flyway an instance of type {@link Flyway}. + * Calls {@link #dropDatabase()} internally, and migrates to the highest available migration (default) or to the + * {@code migrationVersion} specified by {@link #setMigrationVersion(String)}. */ - public DbTestHelper(Flyway flyway) { - super(); - this.flyway = flyway; + public void resetDatabase() { + + this.flyway.migrate(); } + #end +#if ($dbMigration == 'liquibase') /** * Drops the whole database. */ - public void dropDatabase() { + public void cleanup() { - this.flyway.clean(); - } - - /** - * Calls {@link #dropDatabase()} internally, and migrates to the highest available migration (default) or to the - * {@code migrationVersion} specified by {@link #setMigrationVersion(String)}. - */ - public void resetDatabase() { + try { + this.liquibase.dropAll(); + } catch (Exception e) { + e.printStackTrace(); + } - dropDatabase(); - this.flyway.migrate(); } + #else + /** + * Drops the whole database. + */ + public void dropDatabase() { + this.flyway.clean(); + } +#end } diff --git a/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/impl/config/TestDbConfig.java b/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/impl/config/TestDbConfig.java index 371bb2dd..6fafe2e6 100644 --- a/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/impl/config/TestDbConfig.java +++ b/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/impl/config/TestDbConfig.java @@ -6,15 +6,20 @@ import com.devonfw.module.test.common.base.clean.TestCleaner; import com.devonfw.module.test.common.base.clean.TestCleanerImpl; import com.devonfw.module.test.common.base.clean.TestCleanerPlugin; -import com.devonfw.module.test.common.base.clean.TestCleanerPluginFlyway; +#if ($dbMigration == 'liquibase') import com.devonfw.module.test.common.base.clean.TestCleanerPluginLiquibase; +#else +import com.devonfw.module.test.common.base.clean.TestCleanerPluginFlyway; +#end + + /** * {@link Configuration} for Database in JUnit tests. */ @Configuration public class TestDbConfig { - + /** * @return the {@link TestCleaner}. */ @@ -24,21 +29,25 @@ public TestCleaner testCleaner() { return new TestCleanerImpl(); } - /** - * @return the {@link TestCleanerPluginFlyway}. - */ - @Bean - public TestCleanerPlugin testCleanerPlugin() { - - - String dbMigrationValue = System.getenv($dbMigration); + #if ($dbMigration == 'liquibase') + /** + * @return the {@link TestCleanerPluginLiquibase}. + */ + @Bean + public TestCleanerPlugin testCleanerPluginLiquibase() { + + return new TestCleanerPluginLiquibase(); + } + + #else + /** + * @return the {@link TestCleanerPluginFlyway}. + */ + @Bean + public TestCleanerPlugin testCleanerPluginFlyway() { + + return new TestCleanerPluginFlyway(); + } + #end - if(dbMigrationValue==null) - { - return new TestCleanerPluginFlyway(); - - }else if(dbMigrationValue=="liquibase") { - return new TestCleanerPluginLiquibase(); - } -} } \ No newline at end of file diff --git a/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/impl/config/TestWebSecurityConfig.java b/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/impl/config/TestWebSecurityConfig.java index 927c50e0..1438572a 100644 --- a/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/impl/config/TestWebSecurityConfig.java +++ b/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/impl/config/TestWebSecurityConfig.java @@ -24,6 +24,7 @@ public class TestWebSecurityConfig extends BaseWebSecurityConfig { private static Logger LOG = LoggerFactory.getLogger(TestWebSecurityConfig.class); + /** * Configure spring security to enable a simple webform-login + a simple rest login. */ diff --git a/templates/server/src/main/resources/archetype-resources/core/src/test/resources/config/application.properties b/templates/server/src/main/resources/archetype-resources/core/src/test/resources/config/application.properties index c6836bab..edd6b742 100644 --- a/templates/server/src/main/resources/archetype-resources/core/src/test/resources/config/application.properties +++ b/templates/server/src/main/resources/archetype-resources/core/src/test/resources/config/application.properties @@ -8,10 +8,22 @@ spring.datasource.password= spring.datasource.username=sa spring.jpa.hibernate.ddl-auto=none -# Flyway for Database Setup and Migrations + +# Configuration for Database Setup and Migrations + +#if ($dbMigration == 'flyway') spring.flyway.enabled=true #if ($dbType == 'h2') spring.flyway.locations=classpath:db/migration #else spring.flyway.locations=classpath:db/test #end +#end +#if ($dbMigration == 'liquibase') +spring.liquibase.enabled=true +#if ($dbType == 'h2') +spring.liquibase.locations=classpath:db/changelog/changelog-master.xml +#else +spring.liquibase.locations=classpath:db/test +#end +#end \ No newline at end of file diff --git a/templates/server/src/main/resources/archetype-resources/core/src/test/resources/db/changelog/changelog-master.xml b/templates/server/src/main/resources/archetype-resources/core/src/test/resources/db/changelog/changelog-master.xml new file mode 100644 index 00000000..c7f1737b --- /dev/null +++ b/templates/server/src/main/resources/archetype-resources/core/src/test/resources/db/changelog/changelog-master.xml @@ -0,0 +1,9 @@ + + + + + \ No newline at end of file diff --git a/templates/server/src/main/resources/archetype-resources/core/src/test/resources/db/changelog/changelog-v1.0.xml b/templates/server/src/main/resources/archetype-resources/core/src/test/resources/db/changelog/changelog-v1.0.xml new file mode 100644 index 00000000..50b8cbdb --- /dev/null +++ b/templates/server/src/main/resources/archetype-resources/core/src/test/resources/db/changelog/changelog-v1.0.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/templates/server/src/main/resources/archetype-resources/pom.xml b/templates/server/src/main/resources/archetype-resources/pom.xml index a0980b8e..0069058f 100644 --- a/templates/server/src/main/resources/archetype-resources/pom.xml +++ b/templates/server/src/main/resources/archetype-resources/pom.xml @@ -74,7 +74,7 @@ pom import - + @@ -101,6 +101,7 @@ maven-surefire-plugin ${devonfw.test.excluded.groups} + true From db79005acf545779ec8ae7ac78b3ca306f7e588f Mon Sep 17 00:00:00 2001 From: dixyushi Date: Thu, 20 May 2021 10:01:15 +0530 Subject: [PATCH 09/43] fixed review comments --- pom.xml | 753 ++---------------- templates/pom.xml | 34 +- templates/server/flywayy/pom.xml | 491 ------------ .../test/SpringBatchIntegrationTest .java | 73 ++ .../archetype-resources/core/pom.xml | 35 +- .../src/main/resources/application.properties | 2 - .../common/base/test/DbTestHelper.java | 11 - .../impl/config/TestWebSecurityConfig.java | 1 - .../resources/config/application.properties | 2 - .../resources/archetype-resources/pom.xml | 5 +- 10 files changed, 146 insertions(+), 1261 deletions(-) delete mode 100644 templates/server/flywayy/pom.xml create mode 100644 templates/server/src/main/resources/archetype-resources/__batch__/src/test/java/__packageInPathFormat__/general/batch/base/test/SpringBatchIntegrationTest .java diff --git a/pom.xml b/pom.xml index 0308d799..5f73d94b 100644 --- a/pom.xml +++ b/pom.xml @@ -1,637 +1,50 @@ - + - - - - - - - - - - - - - 4.0.0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - com.devonfw - - - - - - - - - - - - - - - maven-parent - - - - - - - - - - - - - - - 6 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - com.devonfw.java.dev - - - - - - - - - - - - - - - devon4j - - - - - - - - - - - - - - - dev-SNAPSHOT - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - pom - - - - - - - - - - - - - - - ${project.artifactId} - - - - - - - - - - - - - - - Java stack of devonfw.com (devon4j): develop Java apps standardized, faster and with less risk. - - - - - - - - - - - - - - - 2014 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - boms - - - - - - - - - - - - - - - modules - - - - - - - - - - - - - - - starters - - - - - - - - - - - - - - - templates - - - - - - - - - - - - - - - documentation - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - dev-SNAPSHOT - - - - - - - - - - - - - - - devon4j - - - - - - - - - - - - - - - ${revision} - - - - - - - - - - - - - - - 2.4.4 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 2020.0.0 - - - - - - - - - - - - - - - 2.12.2 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 30.1.1-jre - - - - - - - - - - - - - - - 5.7.1 - - - - - - - - - - - - - - - 3.4.3 - - - - - - - - - - - - - - - 8.7.0 - - - - - - - - - - - - - - - 1.7.30 - - - - - - - - - - - - - - - https://sonarcloud.io - - - - - - - - - - - - - - - devonfw - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - org.apache.maven.plugins + 4.0.0 + + com.devonfw + maven-parent + 6 + + com.devonfw.java.dev + devon4j + dev-SNAPSHOT + +pom + ${project.artifactId} +Java stack of devonfw.com (devon4j): develop Java apps standardized, faster and with less risk. + 2014 + +boms + modules + starters +templates +documentation + + + dev-SNAPSHOT + devon4j + ${revision} +2.4.4 + +2020.0.0 +2.12.2 + + 30.1.1-jre + 5.7.1 +3.4.3 + 8.7.0 +1.7.30 +https://sonarcloud.io + devonfw + + + + + +org.apache.maven.plugins @@ -827,78 +240,8 @@ ${spring.boot.version} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + diff --git a/templates/pom.xml b/templates/pom.xml index 43e0f835..d3a57f1e 100644 --- a/templates/pom.xml +++ b/templates/pom.xml @@ -1,43 +1,19 @@ - - - - + + 4.0.0 - - - - com.devonfw.java.dev - - devon4j - - dev-SNAPSHOT - - - - devon4j-templates - - pom - - ${project.artifactId} - - Templates (maven archetypes) of devon4j. - - + - - server - - - + \ No newline at end of file diff --git a/templates/server/flywayy/pom.xml b/templates/server/flywayy/pom.xml deleted file mode 100644 index 2d9b9ad3..00000000 --- a/templates/server/flywayy/pom.xml +++ /dev/null @@ -1,491 +0,0 @@ - - - 4.0.0 - flywayy - com.flywayy - ${app.version} - pom - ${project.artifactId} - Application based on the devon4j. - - - 2.4.4 - 2021.04.001-SNAPSHOT - 1.8 - 5.7.1 - UTF-8 - UTF-8 - 2.12.2 - 30.1.1-jre - system - ${revision} - - - - api - core - server - - - - - - - com.fasterxml.jackson - jackson-bom - ${jackson.version} - pom - import - - - - org.junit - junit-bom - ${junit.version} - pom - import - - - - com.google.guava - guava - ${guava.version} - - - - org.springframework.boot - spring-boot-dependencies - ${spring.boot.version} - pom - import - - - - com.devonfw.java.boms - devon4j-bom - ${devon4j.version} - pom - import - - - - - - - org.slf4j - slf4j-api - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - ${project.build.sourceEncoding} - ${java.version} - ${java.version} - - - - - maven-surefire-plugin - - ${devonfw.test.excluded.groups} - true - - - - - - org.jacoco - jacoco-maven-plugin - - - default-prepare-agent - - prepare-agent - - - - default-report - - report - - - - - - - - - org.apache.maven.plugins - maven-resources-plugin - 3.1.0 - - - org.apache.maven.plugins - maven-compiler-plugin - 3.8.1 - - - org.apache.maven.plugins - maven-install-plugin - 2.5.2 - - - org.apache.maven.plugins - maven-deploy-plugin - 2.8.2 - - - org.apache.maven.plugins - maven-clean-plugin - 3.1.0 - - - org.apache.maven.plugins - maven-jar-plugin - 3.1.2 - - - org.apache.maven.plugins - maven-source-plugin - 3.1.0 - - - org.apache.maven.plugins - maven-site-plugin - 3.7.1 - - - org.apache.maven.plugins - maven-checkstyle-plugin - 3.1.0 - - - org.apache.maven.plugins - maven-changes-plugin - 2.12.1 - - - org.apache.maven.plugins - maven-changelog-plugin - 2.3 - - - org.apache.maven.plugins - maven-project-info-reports-plugin - 3.0.0 - - - org.apache.maven.plugins - maven-jxr-plugin - 3.0.0 - - - org.apache.maven.plugins - maven-javadoc-plugin - 3.1.1 - - - - true - protected - ${project.reporting.outputEncoding} - ${project.build.sourceEncoding} - true - ${user.dir}/src/main/javadoc/stylesheet.css - none - ${java.version} - JavaDocs for ${project.name} ${project.version} - JavaDocs for ${project.name} ${project.version} - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.22.2 - - - ${basedir} - - - - org.apache.maven.plugins - maven-surefire-report-plugin - 2.22.2 - - - org.apache.maven.plugins - maven-pmd-plugin - 3.9.0 - - ${java.version} - - - - org.apache.maven.plugins - maven-war-plugin - 3.2.3 - - - org.apache.maven.plugins - maven-antrun-plugin - 1.8 - - - org.apache.maven.plugins - maven-help-plugin - 3.2.0 - - - org.apache.maven.plugins - maven-gpg-plugin - 1.6 - - - org.apache.maven.plugins - maven-archetype-plugin - 3.1.2 - - - org.apache.maven.archetype - archetype-packaging - 3.1.2 - - - org.codehaus.mojo - taglist-maven-plugin - 2.4 - - - org.codehaus.mojo - cobertura-maven-plugin - 2.7 - - - org.codehaus.mojo - flatten-maven-plugin - 1.2.2 - - - org.codehaus.mojo - license-maven-plugin - 1.20 - - ${project.build.directory}/generated-resources - true - true - true - true - - Apache Software License, Version 2.0|The Apache Software License, Version 2.0|Apache - 2.0|Apache License, Version 2.0 - - - - - org.codehaus.mojo - servicedocgen-maven-plugin - 1.0.0-beta-3 - - - org.sonarsource.scanner.maven - sonar-maven-plugin - 3.7.0.1746 - - - org.jacoco - jacoco-maven-plugin - 0.8.5 - - - org.owasp - dependency-check-maven - 5.3.2 - - - com.github.spotbugs - spotbugs-maven-plugin - 3.1.12.2 - - - org.springframework.boot - spring-boot-maven-plugin - ${spring.boot.version} - - - - - - - - moduletest - - component,subsystem,system - - - - componenttest - - subsystem,system - - - - subsystemtest - - system - - - - systemtest - - none - - - - security - - - - org.owasp - dependency-check-maven - - 8 - - - - - check - - - - - - - - - licenses - - - - org.codehaus.mojo - license-maven-plugin - - - aggregate-add-third-party - generate-resources - - aggregate-add-third-party - - - - - aggregate-download-licenses - generate-resources - - aggregate-download-licenses - - - - - - - - - - eclipse - - - eclipse.application - - - - eclipse-target - - - - - - - - org.apache.maven.plugins - maven-project-info-reports-plugin - - false - - - - org.apache.maven.plugins - maven-jxr-plugin - - - org.apache.maven.plugins - maven-javadoc-plugin - - - org.codehaus.mojo - taglist-maven-plugin - - - TODO - @todo - FIXME - @deprecated - REVIEW - - - - - org.owasp - dependency-check-maven - - false - - - - - aggregate - check - - - - - - org.codehaus.mojo - servicedocgen-maven-plugin - - - - ${servicedoc.info.title} - ${servicedoc.info.description} - - ${servicedoc.host} - ${servicedoc.port} - ${servicedoc.basePath} - - http - - - - - - org.codehaus.mojo - license-maven-plugin - - - - third-party-report - aggregate-third-party-report - - - - - - - - diff --git a/templates/server/src/main/resources/archetype-resources/__batch__/src/test/java/__packageInPathFormat__/general/batch/base/test/SpringBatchIntegrationTest .java b/templates/server/src/main/resources/archetype-resources/__batch__/src/test/java/__packageInPathFormat__/general/batch/base/test/SpringBatchIntegrationTest .java new file mode 100644 index 00000000..94842e72 --- /dev/null +++ b/templates/server/src/main/resources/archetype-resources/__batch__/src/test/java/__packageInPathFormat__/general/batch/base/test/SpringBatchIntegrationTest .java @@ -0,0 +1,73 @@ +package ${package}.general.batch.base.test; + +import javax.inject.Inject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.batch.core.Job; +import org.springframework.batch.core.launch.JobLauncher; +import org.springframework.batch.test.JobLauncherTestUtils; +import ${package}.general.common.base.test.TestUtil; +import com.devonfw.module.test.common.base.ComponentTest; +#if ($dbMigration == 'liquibase') + import liquibase.Liquibase; +#else + import org.flywaydb.core.Flyway; +#end + +/** + * Base class for all spring batch integration tests. It helps to do End-to-End job tests. + */ +public abstract class SpringBatchIntegrationTest extends ComponentTest { + + @Inject + private JobLauncher jobLauncher; + + #if ($dbMigration == 'liquibase') + @Inject + private Liquibase liquibase; + #else + @Inject + private Flyway flyway; + #end + + #if ($dbMigration == 'liquibase') + @Override + protected void doSetUp() { + super.doSetUp(); + try { + this.liquibase.dropAll(); + } catch (Exception e) { + e.printStackTrace(); + } + } + #else + @Override + protected void doSetUp() { + + super.doSetUp(); + this.flyway.clean(); + this.flyway.migrate(); + } + #end + + + @Override + protected void doTearDown() { + + super.doTearDown(); + TestUtil.logout(); + } + + /** + * @param job job to configure + * @return jobLauncherTestUtils + */ + public JobLauncherTestUtils getJobLauncherTestUtils(Job job) { + + JobLauncherTestUtils jobLauncherTestUtils = new JobLauncherTestUtils(); + jobLauncherTestUtils.setJob(job); + jobLauncherTestUtils.setJobLauncher(this.jobLauncher); + + return jobLauncherTestUtils; + } +} \ No newline at end of file diff --git a/templates/server/src/main/resources/archetype-resources/core/pom.xml b/templates/server/src/main/resources/archetype-resources/core/pom.xml index 78a8a98a..02d33aaa 100644 --- a/templates/server/src/main/resources/archetype-resources/core/pom.xml +++ b/templates/server/src/main/resources/archetype-resources/core/pom.xml @@ -5,7 +5,7 @@ ${groupId} ${rootArtifactId} - ${app.version} + ${revision} ${rootArtifactId}-core jar @@ -122,65 +122,65 @@ - #if ($dbType == 'h2') +#if ($dbType == 'h2') com.h2database h2 - #elseif ($dbType == 'hsqldb') +#elseif ($dbType == 'hsqldb') org.hsqldb hsqldb 2.4.0 - #elseif ($dbType == 'postgresql') +#elseif ($dbType == 'postgresql') org.postgresql postgresql - #elseif ($dbType == 'mysql') +#elseif ($dbType == 'mysql') mysql mysql-connector-java 8.0.8-dmr - #elseif ($dbType == 'mariadb') +#elseif ($dbType == 'mariadb') org.mariadb.jdbc mariadb-java-client 1.5.4 - #elseif ($dbType == 'hana') +#elseif ($dbType == 'hana') com.sap.cloud.db.jdbc ngdbc 2.3.48 - #elseif ($dbType == 'oracle') +#elseif ($dbType == 'oracle') com.oracle.jdbc ojdbc8 12.2.0.1 - #elseif ($dbType == 'mssql') +#elseif ($dbType == 'mssql') com.microsoft.sqlserver mssql-jdbc 6.4.0.jre8 - #else +#else $dbType $dbType TODO - #end +#end - #if ($dbType != 'h2') +#if ($dbType != 'h2') com.h2database h2 test - #end +#end - #if ($dbMigration == 'flyway') +#if ($dbMigration == 'flyway') org.flywaydb flyway-core - #end +#end - #if ($dbMigration == 'liquibase') +#if ($dbMigration == 'liquibase') org.liquibase liquibase-core - #end +#end @@ -277,4 +277,5 @@ #end + \ No newline at end of file diff --git a/templates/server/src/main/resources/archetype-resources/core/src/main/resources/application.properties b/templates/server/src/main/resources/archetype-resources/core/src/main/resources/application.properties index bc0a35ee..e27bc1f9 100644 --- a/templates/server/src/main/resources/archetype-resources/core/src/main/resources/application.properties +++ b/templates/server/src/main/resources/archetype-resources/core/src/main/resources/application.properties @@ -69,8 +69,6 @@ spring.jpa.open-in-view=false # see http://stackoverflow.com/questions/22318907/how-to-stop-spring-batch-scheduled-jobs-from-running-at-first-time-when-executin spring.batch.job.enabled=false - - # Configuration for Database Setup and Migrations #if ($dbMigration == 'flyway') spring.flyway.locations=classpath:db/migration diff --git a/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/base/test/DbTestHelper.java b/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/base/test/DbTestHelper.java index 3e0dca55..02dc1359 100644 --- a/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/base/test/DbTestHelper.java +++ b/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/base/test/DbTestHelper.java @@ -41,17 +41,6 @@ public DbTestHelper( Flyway flyway) { } #end - -// public DbTestHelper(#if ($dbMigration == 'liquibase') Liquibase liquibase #else Flyway flyway #end) { -// super(); -// #if ($dbMigration == 'liquibase') -// this.liquibase = liquibase; -// #else -// this.flyway = flyway; -// #end -// } - - #if ($dbMigration == 'flyway') /** * Calls {@link #dropDatabase()} internally, and migrates to the highest available migration (default) or to the diff --git a/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/impl/config/TestWebSecurityConfig.java b/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/impl/config/TestWebSecurityConfig.java index 1438572a..652ab5dc 100644 --- a/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/impl/config/TestWebSecurityConfig.java +++ b/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/impl/config/TestWebSecurityConfig.java @@ -23,7 +23,6 @@ @Profile(SpringProfileConstants.JUNIT) public class TestWebSecurityConfig extends BaseWebSecurityConfig { private static Logger LOG = LoggerFactory.getLogger(TestWebSecurityConfig.class); - /** * Configure spring security to enable a simple webform-login + a simple rest login. diff --git a/templates/server/src/main/resources/archetype-resources/core/src/test/resources/config/application.properties b/templates/server/src/main/resources/archetype-resources/core/src/test/resources/config/application.properties index edd6b742..6ba36f33 100644 --- a/templates/server/src/main/resources/archetype-resources/core/src/test/resources/config/application.properties +++ b/templates/server/src/main/resources/archetype-resources/core/src/test/resources/config/application.properties @@ -8,9 +8,7 @@ spring.datasource.password= spring.datasource.username=sa spring.jpa.hibernate.ddl-auto=none - # Configuration for Database Setup and Migrations - #if ($dbMigration == 'flyway') spring.flyway.enabled=true #if ($dbType == 'h2') diff --git a/templates/server/src/main/resources/archetype-resources/pom.xml b/templates/server/src/main/resources/archetype-resources/pom.xml index 0069058f..6fecf38b 100644 --- a/templates/server/src/main/resources/archetype-resources/pom.xml +++ b/templates/server/src/main/resources/archetype-resources/pom.xml @@ -4,7 +4,7 @@ 4.0.0 ${artifactId} ${groupId} - ${app.version} + ${revision} pom ${project.artifactId} Application based on the devon4j. @@ -74,7 +74,7 @@ pom import - + @@ -101,7 +101,6 @@ maven-surefire-plugin ${devonfw.test.excluded.groups} - true From cae564a303363f4dd9832e2dfabc9f77dace9121 Mon Sep 17 00:00:00 2001 From: dixyushi <72491437+dixyushi@users.noreply.github.com> Date: Thu, 20 May 2021 19:26:54 +0530 Subject: [PATCH 10/43] Update pom.xml --- pom.xml | 208 ++++---------------------------------------------------- 1 file changed, 13 insertions(+), 195 deletions(-) diff --git a/pom.xml b/pom.xml index 5f73d94b..9b1649dc 100644 --- a/pom.xml +++ b/pom.xml @@ -45,201 +45,19 @@ org.apache.maven.plugins - - - - - - - - - - - - - - - maven-war-plugin - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - WEB-INF/classes/config/application.properties,*.jsp - - - - - - - - - - - - - - - ${project.artifactId} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - org.springframework.boot - - - - - - - - - - - - - - - spring-boot-maven-plugin - - - - - - - - - - - - - - - ${spring.boot.version} + maven-war-plugin + +WEB-INF/classes/config/application.properties,*.jsp + ${project.artifactId} + + + + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring.boot.version} From e49273e74fa21c492b72a99dfcd8dc5d076987f1 Mon Sep 17 00:00:00 2001 From: dixyushi Date: Thu, 20 May 2021 19:29:52 +0530 Subject: [PATCH 11/43] fixed the existing error of SpringBatchIntegrationTes file --- pom.xml | 345 +++++++++++++++--- ... .java => SpringBatchIntegrationTest.java} | 0 .../common/base/test/DbTestHelper.java | 1 - 3 files changed, 295 insertions(+), 51 deletions(-) rename templates/server/src/main/resources/archetype-resources/__batch__/src/test/java/__packageInPathFormat__/general/batch/base/test/{SpringBatchIntegrationTest .java => SpringBatchIntegrationTest.java} (100%) diff --git a/pom.xml b/pom.xml index 5f73d94b..955551b7 100644 --- a/pom.xml +++ b/pom.xml @@ -1,51 +1,228 @@ - + + + + + 4.0.0 + + + + + + + + com.devonfw + + + + maven-parent - 6 + + + + + 6 + + + + + + + + + com.devonfw.java.dev - devon4j + + + + + devon4j + + + + dev-SNAPSHOT + + + + -pom + + + + + pom + + + + ${project.artifactId} -Java stack of devonfw.com (devon4j): develop Java apps standardized, faster and with less risk. - 2014 + + + + + Java stack of devonfw.com (devon4j): develop Java apps standardized, faster and with less risk. + + + + + 2014 + + + + -boms - modules - starters -templates -documentation + + + + + boms + + + + + modules + + + + + starters + + + + + templates + + + + + documentation + + + + - - dev-SNAPSHOT - devon4j - ${revision} -2.4.4 - -2020.0.0 -2.12.2 - - 30.1.1-jre - 5.7.1 -3.4.3 - 8.7.0 -1.7.30 -https://sonarcloud.io - devonfw - - - - - -org.apache.maven.plugins - + + + + + + + + + + dev-SNAPSHOT + + + + + devon4j + + + + + ${revision} + + + + + 2.4.4 + + + + + + + + + + 2020.0.0 + + + + + 2.12.2 + + + + + + + + + + 30.1.1-jre + + + + + 5.7.1 + + + + + 3.4.3 + + + + + 8.7.0 + + + + + 1.7.30 + + + + + https://sonarcloud.io + + + + + devonfw + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + org.apache.maven.plugins + + + + + @@ -60,7 +237,11 @@ maven-war-plugin - + + + + + @@ -75,7 +256,11 @@ - + + + + + @@ -90,7 +275,11 @@ WEB-INF/classes/config/application.properties,*.jsp - + + + + + @@ -105,7 +294,11 @@ ${project.artifactId} - + + + + + @@ -120,7 +313,11 @@ - + + + + + @@ -135,7 +332,11 @@ - + + + + + @@ -150,7 +351,11 @@ - + + + + + @@ -165,7 +370,11 @@ - + + + + + @@ -180,7 +389,11 @@ - + + + + + @@ -195,7 +408,11 @@ - + + + + + @@ -210,7 +427,11 @@ org.springframework.boot - + + + + + @@ -225,7 +446,11 @@ spring-boot-maven-plugin - + + + + + @@ -240,8 +465,28 @@ ${spring.boot.version} - - - - + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/templates/server/src/main/resources/archetype-resources/__batch__/src/test/java/__packageInPathFormat__/general/batch/base/test/SpringBatchIntegrationTest .java b/templates/server/src/main/resources/archetype-resources/__batch__/src/test/java/__packageInPathFormat__/general/batch/base/test/SpringBatchIntegrationTest.java similarity index 100% rename from templates/server/src/main/resources/archetype-resources/__batch__/src/test/java/__packageInPathFormat__/general/batch/base/test/SpringBatchIntegrationTest .java rename to templates/server/src/main/resources/archetype-resources/__batch__/src/test/java/__packageInPathFormat__/general/batch/base/test/SpringBatchIntegrationTest.java diff --git a/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/base/test/DbTestHelper.java b/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/base/test/DbTestHelper.java index 02dc1359..4229cd9d 100644 --- a/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/base/test/DbTestHelper.java +++ b/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/base/test/DbTestHelper.java @@ -1,6 +1,5 @@ package ${package}.general.common.base.test; -import javax.inject.Inject; import javax.inject.Named; #if ($dbMigration == 'liquibase') import liquibase.Liquibase; From b2f1dd8996ac68aa09ff05c0aa18c033f8dc472f Mon Sep 17 00:00:00 2001 From: dixyushi Date: Fri, 21 May 2021 08:55:16 +0530 Subject: [PATCH 12/43] Code after review comments implementation --- verifyDefaultFlyway/core/.gitignore | 1 - 1 file changed, 1 deletion(-) delete mode 100644 verifyDefaultFlyway/core/.gitignore diff --git a/verifyDefaultFlyway/core/.gitignore b/verifyDefaultFlyway/core/.gitignore deleted file mode 100644 index ae3c1726..00000000 --- a/verifyDefaultFlyway/core/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/bin/ From ee7f6a5729224ac0304c404b95983a3364b9f3f0 Mon Sep 17 00:00:00 2001 From: dixyushi <72491437+dixyushi@users.noreply.github.com> Date: Fri, 21 May 2021 17:58:12 +0530 Subject: [PATCH 13/43] Update TestWebSecurityConfig.java --- .../general/common/impl/config/TestWebSecurityConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/impl/config/TestWebSecurityConfig.java b/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/impl/config/TestWebSecurityConfig.java index 652ab5dc..927c50e0 100644 --- a/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/impl/config/TestWebSecurityConfig.java +++ b/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/impl/config/TestWebSecurityConfig.java @@ -23,7 +23,7 @@ @Profile(SpringProfileConstants.JUNIT) public class TestWebSecurityConfig extends BaseWebSecurityConfig { private static Logger LOG = LoggerFactory.getLogger(TestWebSecurityConfig.class); - + /** * Configure spring security to enable a simple webform-login + a simple rest login. */ From d2d0e0e590f5ea1212b457dc412a2c802ec68d90 Mon Sep 17 00:00:00 2001 From: dixyushi Date: Mon, 24 May 2021 11:20:36 +0530 Subject: [PATCH 14/43] fixed review comments --- .../test/common/base/clean/TestCleanerPluginLiquibase.java | 7 +++++-- .../batch/base/test/SpringBatchIntegrationTest.java | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginLiquibase.java b/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginLiquibase.java index c9104da4..8244ffa4 100644 --- a/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginLiquibase.java +++ b/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginLiquibase.java @@ -1,11 +1,14 @@ package com.devonfw.module.test.common.base.clean; import javax.inject.Inject; + +import org.flywaydb.core.Flyway; + import liquibase.Liquibase; /** - * @author ayudixit - * + * Implementation of {@link TestCleanerPlugin} base on {@link Liquibase}. It will {@link Liquibase#dropAll() clean} + * on {@link #cleanup()}. Therefore after {@link #cleanup()} it will drop all database objects. */ public class TestCleanerPluginLiquibase implements TestCleanerPlugin { diff --git a/templates/server/src/main/resources/archetype-resources/__batch__/src/test/java/__packageInPathFormat__/general/batch/base/test/SpringBatchIntegrationTest.java b/templates/server/src/main/resources/archetype-resources/__batch__/src/test/java/__packageInPathFormat__/general/batch/base/test/SpringBatchIntegrationTest.java index 94842e72..ef0f537d 100644 --- a/templates/server/src/main/resources/archetype-resources/__batch__/src/test/java/__packageInPathFormat__/general/batch/base/test/SpringBatchIntegrationTest.java +++ b/templates/server/src/main/resources/archetype-resources/__batch__/src/test/java/__packageInPathFormat__/general/batch/base/test/SpringBatchIntegrationTest.java @@ -9,9 +9,9 @@ import ${package}.general.common.base.test.TestUtil; import com.devonfw.module.test.common.base.ComponentTest; #if ($dbMigration == 'liquibase') - import liquibase.Liquibase; +import liquibase.Liquibase; #else - import org.flywaydb.core.Flyway; +import org.flywaydb.core.Flyway; #end /** From 80641d8b534882c3b82cfcba8e5e53b6367eaed1 Mon Sep 17 00:00:00 2001 From: dixyushi Date: Mon, 31 May 2021 14:18:08 +0530 Subject: [PATCH 15/43] Implemented review comments --- .../clean/TestCleanerPluginLiquibase.java | 26 ++++++---- .../META-INF/archetype-post-generate.groovy | 21 ++++++++ .../archetype-resources/__batch__/pom.xml | 6 +++ .../base/test/SpringBatchIntegrationTest.java | 48 ++++++------------- 4 files changed, 57 insertions(+), 44 deletions(-) create mode 100644 templates/server/src/main/resources/META-INF/archetype-post-generate.groovy diff --git a/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginLiquibase.java b/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginLiquibase.java index 8244ffa4..4ec83455 100644 --- a/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginLiquibase.java +++ b/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginLiquibase.java @@ -3,15 +3,22 @@ import javax.inject.Inject; import org.flywaydb.core.Flyway; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import liquibase.Liquibase; +import liquibase.exception.DatabaseException; /** - * Implementation of {@link TestCleanerPlugin} base on {@link Liquibase}. It will {@link Liquibase#dropAll() clean} - * on {@link #cleanup()}. Therefore after {@link #cleanup()} it will drop all database objects. + * Implementation of {@link TestCleanerPlugin} base on {@link Liquibase}. It will {@link Liquibase#dropAll() clean} on + * {@link #cleanup()}. Therefore after {@link #cleanup()} it will drop all database objects. */ public class TestCleanerPluginLiquibase implements TestCleanerPlugin { + + private static final Logger LOG = LoggerFactory.getLogger(TestCleanerPluginLiquibase.class); + @Inject private Liquibase liquibase; @@ -35,14 +42,13 @@ public TestCleanerPluginLiquibase(Liquibase liquibase) { } @Override - public void cleanup() { - - try { - this.liquibase.dropAll(); - } catch (Exception e) { - e.printStackTrace(); - } - + public void cleanup() { + try { + this.liquibase.dropAll(); + }catch(DatabaseException databaseException) { + LOG.error("Database exception occurred!", new DatabaseException()); + } + } } diff --git a/templates/server/src/main/resources/META-INF/archetype-post-generate.groovy b/templates/server/src/main/resources/META-INF/archetype-post-generate.groovy new file mode 100644 index 00000000..0c30f96b --- /dev/null +++ b/templates/server/src/main/resources/META-INF/archetype-post-generate.groovy @@ -0,0 +1,21 @@ +import java.nio.file.Files +import java.nio.file.Path +import java.nio.file.Paths + +// the path where the project got generated +File rootDir = new File(request.outputDirectory + "/" + request.artifactId) + +// the properties available to the archetype +Properties properties = request.properties + +// dbMigration is either liquibase or flyway +String dbMigration = properties.get("dbMigration") + + +if(dbMigration == "flyway") { + // delete the changelog folder as it is not required for flyway + new File(rootDir, "src/main/resources/db/changelog").deleteDir() +}else if(dbMigration == "liquibase") { + // delete the changelog folder as it is not required for flyway + new File(rootDir, "src/main/resources/db/migration").deleteDir() + } \ No newline at end of file diff --git a/templates/server/src/main/resources/archetype-resources/__batch__/pom.xml b/templates/server/src/main/resources/archetype-resources/__batch__/pom.xml index bf27e0bb..9f460c63 100644 --- a/templates/server/src/main/resources/archetype-resources/__batch__/pom.xml +++ b/templates/server/src/main/resources/archetype-resources/__batch__/pom.xml @@ -36,6 +36,12 @@ devon4j-test test + + + com.devonfw.java.modules + devon4j-test-jpa + test + diff --git a/templates/server/src/main/resources/archetype-resources/__batch__/src/test/java/__packageInPathFormat__/general/batch/base/test/SpringBatchIntegrationTest.java b/templates/server/src/main/resources/archetype-resources/__batch__/src/test/java/__packageInPathFormat__/general/batch/base/test/SpringBatchIntegrationTest.java index ef0f537d..bf7d95a8 100644 --- a/templates/server/src/main/resources/archetype-resources/__batch__/src/test/java/__packageInPathFormat__/general/batch/base/test/SpringBatchIntegrationTest.java +++ b/templates/server/src/main/resources/archetype-resources/__batch__/src/test/java/__packageInPathFormat__/general/batch/base/test/SpringBatchIntegrationTest.java @@ -8,12 +8,8 @@ import org.springframework.batch.test.JobLauncherTestUtils; import ${package}.general.common.base.test.TestUtil; import com.devonfw.module.test.common.base.ComponentTest; -#if ($dbMigration == 'liquibase') -import liquibase.Liquibase; -#else -import org.flywaydb.core.Flyway; -#end - +import com.devonfw.module.test.common.base.clean.TestCleanerPlugin; +import com.devonfw.module.test.common.base.clean.TestCleanerPluginFlyway; /** * Base class for all spring batch integration tests. It helps to do End-to-End job tests. */ @@ -22,36 +18,20 @@ public abstract class SpringBatchIntegrationTest extends ComponentTest { @Inject private JobLauncher jobLauncher; - #if ($dbMigration == 'liquibase') - @Inject - private Liquibase liquibase; - #else - @Inject - private Flyway flyway; - #end - - #if ($dbMigration == 'liquibase') - @Override - protected void doSetUp() { - super.doSetUp(); - try { - this.liquibase.dropAll(); - } catch (Exception e) { - e.printStackTrace(); - } - } - #else - @Override - protected void doSetUp() { - - super.doSetUp(); - this.flyway.clean(); - this.flyway.migrate(); - } - #end - + @Inject + private TestCleanerPlugin testCleanerPlugin; @Override + protected void doSetUp() { + super.doSetUp(); +#if($dbMigration == 'flyway') + testCleanerPlugin = new TestCleanerPluginFlyway(); +#else if($dbMigration == 'liquibase') + testCleanerPlugin = new TestCleanerPluginLiquibase(); +#end + testCleanerPlugin.cleanup(); + } + protected void doTearDown() { super.doTearDown(); From 7610cb1c8cef5a604812f662c1aa81a3f07c1e1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Hohwiller?= Date: Mon, 31 May 2021 14:51:04 +0200 Subject: [PATCH 16/43] fixed indendation --- .../main/resources/META-INF/archetype-post-generate.groovy | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/server/src/main/resources/META-INF/archetype-post-generate.groovy b/templates/server/src/main/resources/META-INF/archetype-post-generate.groovy index 0c30f96b..331b6adb 100644 --- a/templates/server/src/main/resources/META-INF/archetype-post-generate.groovy +++ b/templates/server/src/main/resources/META-INF/archetype-post-generate.groovy @@ -12,10 +12,10 @@ Properties properties = request.properties String dbMigration = properties.get("dbMigration") -if(dbMigration == "flyway") { +if (dbMigration == "flyway") { // delete the changelog folder as it is not required for flyway new File(rootDir, "src/main/resources/db/changelog").deleteDir() -}else if(dbMigration == "liquibase") { +} else if(dbMigration == "liquibase") { // delete the changelog folder as it is not required for flyway new File(rootDir, "src/main/resources/db/migration").deleteDir() - } \ No newline at end of file +} From cd8291b942e68c8064a05c42c832164422011fa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Hohwiller?= Date: Mon, 31 May 2021 15:02:36 +0200 Subject: [PATCH 17/43] fixed indendation --- .../common/base/test/DbTestHelper.java | 62 +++++++++---------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/base/test/DbTestHelper.java b/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/base/test/DbTestHelper.java index 4229cd9d..00442a0b 100644 --- a/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/base/test/DbTestHelper.java +++ b/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/base/test/DbTestHelper.java @@ -2,7 +2,7 @@ import javax.inject.Named; #if ($dbMigration == 'liquibase') - import liquibase.Liquibase; +import liquibase.Liquibase; #else import org.flywaydb.core.Flyway; #end @@ -12,44 +12,44 @@ */ @Named public class DbTestHelper { - #if ($dbMigration == 'liquibase') - private Liquibase liquibase; - #else - private Flyway flyway; - #end +#if ($dbMigration == 'liquibase') + private Liquibase liquibase; +#else + private Flyway flyway; +#end - #if ($dbMigration == 'liquibase') - /** - * The constructor. - * - * @param liquibase an instance of type {@link Liquibase}. - */ - public DbTestHelper( Liquibase liquibase) { - super(); - this.liquibase = liquibase; - } - #else - /** - * The constructor. - * - * @param flyway an instance of type {@link Flyway}. - */ - public DbTestHelper( Flyway flyway) { - super(); - this.flyway = flyway; - } - #end +#if ($dbMigration == 'liquibase') + /** + * The constructor. + * + * @param liquibase an instance of type {@link Liquibase}. + */ + public DbTestHelper( Liquibase liquibase) { + super(); + this.liquibase = liquibase; + } +#else + /** + * The constructor. + * + * @param flyway an instance of type {@link Flyway}. + */ + public DbTestHelper( Flyway flyway) { + super(); + this.flyway = flyway; + } +#end - #if ($dbMigration == 'flyway') +#if ($dbMigration == 'flyway') /** * Calls {@link #dropDatabase()} internally, and migrates to the highest available migration (default) or to the * {@code migrationVersion} specified by {@link #setMigrationVersion(String)}. */ public void resetDatabase() { - this.flyway.migrate(); + this.flyway.migrate(); } - #end +#end #if ($dbMigration == 'liquibase') /** @@ -69,7 +69,7 @@ public void cleanup() { * Drops the whole database. */ public void dropDatabase() { - this.flyway.clean(); + this.flyway.clean(); } #end From 5afd20acf9a40b0af40fc7f46fcd31dc75225fb9 Mon Sep 17 00:00:00 2001 From: dixyushi Date: Wed, 2 Jun 2021 10:15:38 +0530 Subject: [PATCH 18/43] handled DatabaseException --- .../clean/TestCleanerPluginLiquibase.java | 3 +- .../META-INF/archetype-post-generate.groovy | 21 +- .../META-INF/maven/archetype-metadata.xml | 200 +++++++++--------- .../archetype-resources/core/pom.xml | 11 +- .../common/base/test/DbTestHelper.java | 82 ++----- .../resources/config/application.properties | 2 +- .../projects/basic/archetype.properties | 7 +- .../projects/batch/archetype.properties | 7 +- .../projects/enterprise/archetype.properties | 7 +- 9 files changed, 163 insertions(+), 177 deletions(-) diff --git a/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginLiquibase.java b/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginLiquibase.java index 4ec83455..a444987e 100644 --- a/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginLiquibase.java +++ b/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginLiquibase.java @@ -2,7 +2,6 @@ import javax.inject.Inject; -import org.flywaydb.core.Flyway; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -46,7 +45,7 @@ public void cleanup() { try { this.liquibase.dropAll(); }catch(DatabaseException databaseException) { - LOG.error("Database exception occurred!", new DatabaseException()); + LOG.error("Database exception occurred!", databaseException); } } diff --git a/templates/server/src/main/resources/META-INF/archetype-post-generate.groovy b/templates/server/src/main/resources/META-INF/archetype-post-generate.groovy index 0c30f96b..8d4e7ff8 100644 --- a/templates/server/src/main/resources/META-INF/archetype-post-generate.groovy +++ b/templates/server/src/main/resources/META-INF/archetype-post-generate.groovy @@ -3,19 +3,24 @@ import java.nio.file.Path import java.nio.file.Paths // the path where the project got generated -File rootDir = new File(request.outputDirectory + "/" + request.artifactId) +Path projectPath = Paths.get(request.outputDirectory, request.artifactId) // the properties available to the archetype Properties properties = request.properties -// dbMigration is either liquibase or flyway +// dbMigration is either flyway or liquibase String dbMigration = properties.get("dbMigration") - -if(dbMigration == "flyway") { +if (dbMigration == "flyway") { // delete the changelog folder as it is not required for flyway - new File(rootDir, "src/main/resources/db/changelog").deleteDir() -}else if(dbMigration == "liquibase") { + Files.deleteIfExists projectPath.resolve("src/main/resources/db/changelog/changelog-master.xml") + Files.deleteIfExists projectPath.resolve("src/main/resources/db/changelog/changelog-v1.0.xml") + Files.deleteIfExists projectPath.resolve("src/test/resources/db/changelog/changelog-master.xml") + Files.deleteIfExists projectPath.resolve("src/test/resources/db/changelog/changelog-v1.0.xml") + +} else if(dbMigration == "liquibase") { // delete the changelog folder as it is not required for flyway - new File(rootDir, "src/main/resources/db/migration").deleteDir() - } \ No newline at end of file + Files.deleteIfExists projectPath.resolve("src/main/resources/db/migration/1.0/V0001_Create_Sequence.sql") + Files.deleteIfExists projectPath.resolve("src/main/resources/db/test/V0001_InitDb.sql") +} + diff --git a/templates/server/src/main/resources/META-INF/maven/archetype-metadata.xml b/templates/server/src/main/resources/META-INF/maven/archetype-metadata.xml index cc33657d..2782a45c 100644 --- a/templates/server/src/main/resources/META-INF/maven/archetype-metadata.xml +++ b/templates/server/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -1,100 +1,100 @@ - - - devon4j-template-server - - - - . - - - h2 - - - - flyway - - - - . - batch|[.] - - - - - - - api - - **/*.* - - - - core - - **/*.* - - - - __earProjectName__ - - **/*.* - - - - - __batch__ - - **/*.* - - - - - - .gitignore - - - - .mvn - - **/*.* - - - - - - - - src/main/java - - - src/main/resources - - - src/test/java - - - src/test/resources - - - src/main/webapp - - - - - + + + devon4j-template-server + + + + . + + + h2 + + + + flyway + + + + . + batch|[.] + + + + + + + api + + **/*.* + + + + core + + **/*.* + + + + __earProjectName__ + + **/*.* + + + + + __batch__ + + **/*.* + + + + + + .gitignore + + + + .mvn + + **/*.* + + + + + + + + src/main/java + + + src/main/resources + + + src/test/java + + + src/test/resources + + + src/main/webapp + + + + + diff --git a/templates/server/src/main/resources/archetype-resources/core/pom.xml b/templates/server/src/main/resources/archetype-resources/core/pom.xml index 02d33aaa..9eb95866 100644 --- a/templates/server/src/main/resources/archetype-resources/core/pom.xml +++ b/templates/server/src/main/resources/archetype-resources/core/pom.xml @@ -36,6 +36,12 @@ devon4j-web + + com.devonfw.java.modules + devon4j-test-jpa + test + + com.devonfw.java.starters @@ -264,17 +270,18 @@ - #if($dbMigration == 'liquibase') +#if($dbMigration == 'liquibase') org.liquibase liquibase-maven-plugin + 3.8.0 liquibase - #end +#end diff --git a/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/base/test/DbTestHelper.java b/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/base/test/DbTestHelper.java index 4229cd9d..0106535a 100644 --- a/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/base/test/DbTestHelper.java +++ b/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/base/test/DbTestHelper.java @@ -1,76 +1,36 @@ package ${package}.general.common.base.test; import javax.inject.Named; -#if ($dbMigration == 'liquibase') - import liquibase.Liquibase; -#else -import org.flywaydb.core.Flyway; -#end +import com.devonfw.module.test.common.base.clean.TestCleanerPlugin; +import com.devonfw.module.test.common.base.clean.TestCleanerPluginLiquibase; +import com.devonfw.module.test.common.base.clean.TestCleanerPluginFlyway; /** * This class provides methods for handling the database during testing where resets (and other operations) may be * necessary. */ @Named -public class DbTestHelper { - #if ($dbMigration == 'liquibase') - private Liquibase liquibase; - #else - private Flyway flyway; - #end - - #if ($dbMigration == 'liquibase') - /** - * The constructor. - * - * @param liquibase an instance of type {@link Liquibase}. - */ - public DbTestHelper( Liquibase liquibase) { - super(); - this.liquibase = liquibase; - } - #else - /** - * The constructor. - * - * @param flyway an instance of type {@link Flyway}. - */ - public DbTestHelper( Flyway flyway) { - super(); - this.flyway = flyway; - } - #end - - #if ($dbMigration == 'flyway') - /** - * Calls {@link #dropDatabase()} internally, and migrates to the highest available migration (default) or to the - * {@code migrationVersion} specified by {@link #setMigrationVersion(String)}. - */ - public void resetDatabase() { - - this.flyway.migrate(); +public class DbTestHelper{ + + + private TestCleanerPlugin testCleanerPlugin; + + public DbTestHelper(TestCleanerPlugin testCleanerPlugin) { + + super(); + this.testCleanerPlugin = testCleanerPlugin; } - #end -#if ($dbMigration == 'liquibase') /** * Drops the whole database. */ - public void cleanup() { - - try { - this.liquibase.dropAll(); - } catch (Exception e) { - e.printStackTrace(); - } - - } - #else - /** - * Drops the whole database. - */ - public void dropDatabase() { - this.flyway.clean(); - } + public void dropDatabase() { +#if($dbMigration == 'liquibase') + testCleanerPlugin = new TestCleanerPluginLiquibase(); +#end +#if($dbMigration == 'flyway') + testCleanerPlugin = new TestCleanerPluginFlyway(); #end + testCleanerPlugin.cleanup(); + } -} +} \ No newline at end of file diff --git a/templates/server/src/main/resources/archetype-resources/core/src/test/resources/config/application.properties b/templates/server/src/main/resources/archetype-resources/core/src/test/resources/config/application.properties index 6ba36f33..9ffe674c 100644 --- a/templates/server/src/main/resources/archetype-resources/core/src/test/resources/config/application.properties +++ b/templates/server/src/main/resources/archetype-resources/core/src/test/resources/config/application.properties @@ -20,7 +20,7 @@ spring.flyway.locations=classpath:db/test #if ($dbMigration == 'liquibase') spring.liquibase.enabled=true #if ($dbType == 'h2') -spring.liquibase.locations=classpath:db/changelog/changelog-master.xml +spring.liquibase.locations=classpath:db/changelog/changelog-v1.0.xml #else spring.liquibase.locations=classpath:db/test #end diff --git a/templates/server/src/test/resources/projects/basic/archetype.properties b/templates/server/src/test/resources/projects/basic/archetype.properties index 5af903a8..f3631b2f 100644 --- a/templates/server/src/test/resources/projects/basic/archetype.properties +++ b/templates/server/src/test/resources/projects/basic/archetype.properties @@ -6,4 +6,9 @@ artifactId=basic earProjectName=. batch=. dbType=h2 -dbMigration=flyway \ No newline at end of file +#if($dbMigration == 'liquibase') +dbMigration=liquibase +#end +#if($dbMigration == 'flyway') +dbMigration=flyway +#end \ No newline at end of file diff --git a/templates/server/src/test/resources/projects/batch/archetype.properties b/templates/server/src/test/resources/projects/batch/archetype.properties index f30b83ec..8f10db0d 100644 --- a/templates/server/src/test/resources/projects/batch/archetype.properties +++ b/templates/server/src/test/resources/projects/batch/archetype.properties @@ -6,4 +6,9 @@ artifactId=app-with-batch earProjectName=. batch=batch dbType=mysql -dbMigration=flyway \ No newline at end of file +#if($dbMigration == 'liquibase') +dbMigration=liquibase +#end +#if($dbMigration == 'flyway') +dbMigration=flyway +#end \ No newline at end of file diff --git a/templates/server/src/test/resources/projects/enterprise/archetype.properties b/templates/server/src/test/resources/projects/enterprise/archetype.properties index 9a75406b..f551f6b7 100644 --- a/templates/server/src/test/resources/projects/enterprise/archetype.properties +++ b/templates/server/src/test/resources/projects/enterprise/archetype.properties @@ -6,4 +6,9 @@ artifactId=enterprise earProjectName=${artifactId}-ear batch=. dbType=postgresql -dbMigration=flyway \ No newline at end of file +#if($dbMigration == 'liquibase') +dbMigration=liquibase +#end +#if($dbMigration == 'flyway') +dbMigration=flyway +#end \ No newline at end of file From 9e0f3facf484b8563a3bb44ad80bcec23e26c40f Mon Sep 17 00:00:00 2001 From: Dixit Date: Fri, 5 Feb 2021 09:52:28 +0530 Subject: [PATCH 19/43] changed configuration of flyway into liquibase --- .../archetype-resources/core/pom.xml | 548 +++++++++--------- .../src/main/resources/application.properties | 4 +- .../resources/config/application.properties | 5 +- .../db/changelog/changelog-master.xml | 9 + .../resources/db/changelog/changelog-v1.0.xml | 8 + 5 files changed, 309 insertions(+), 265 deletions(-) create mode 100644 templates/server/src/main/resources/archetype-resources/core/src/main/resources/db/changelog/changelog-master.xml create mode 100644 templates/server/src/main/resources/archetype-resources/core/src/main/resources/db/changelog/changelog-v1.0.xml diff --git a/templates/server/src/main/resources/archetype-resources/core/pom.xml b/templates/server/src/main/resources/archetype-resources/core/pom.xml index de4b7c0d..6ac2b712 100644 --- a/templates/server/src/main/resources/archetype-resources/core/pom.xml +++ b/templates/server/src/main/resources/archetype-resources/core/pom.xml @@ -1,260 +1,288 @@ - - - 4.0.0 - - ${groupId} - ${rootArtifactId} - ${revision} - - ${rootArtifactId}-core - jar - ${project.artifactId} - Core of the server for the ${rootArtifactId} application - a simple example based on devon4j. - - - - ${project.groupId} - ${rootArtifactId}-api - ${project.version} - - - - - com.devonfw.java.modules - devon4j-beanmapping-orika - - - - - com.devonfw.java.starters - devon4j-starter-security - - - - com.devonfw.java.modules - devon4j-web - - - - - com.devonfw.java.starters - devon4j-starter-cxf-client-rest - - - - com.devonfw.java.starters - devon4j-starter-cxf-client-ws - - - - - com.devonfw.java.starters - devon4j-starter-cxf-server-rest - - - - com.devonfw.java.starters - devon4j-starter-cxf-server-ws - - - - - com.devonfw.java.starters - devon4j-starter-spring-data-jpa - - - - - org.springframework.boot - spring-boot-starter-jdbc - - - - - javax.persistence - javax.persistence-api - - - - - org.hibernate - hibernate-entitymanager - - - - - com.querydsl - querydsl-jpa - - - com.querydsl - querydsl-apt - provided - - - - - org.hibernate.validator - hibernate-validator - - - - - javax.servlet - javax.servlet-api - provided - - - - - javax.el - javax.el-api - - - - - org.springframework - spring-webmvc - - - - -#if ($dbType == 'h2') - com.h2database - h2 -#elseif ($dbType == 'hsqldb') - org.hsqldb - hsqldb - 2.4.0 -#elseif ($dbType == 'postgresql') - org.postgresql - postgresql - -#elseif ($dbType == 'mysql') - mysql - mysql-connector-java - 8.0.8-dmr -#elseif ($dbType == 'mariadb') - org.mariadb.jdbc - mariadb-java-client - 1.5.4 -#elseif ($dbType == 'hana') - com.sap.cloud.db.jdbc - ngdbc - 2.3.48 -#elseif ($dbType == 'oracle') - com.oracle.jdbc - ojdbc8 - 12.2.0.1 -#elseif ($dbType == 'mssql') - com.microsoft.sqlserver - mssql-jdbc - 6.4.0.jre8 -#else - $dbType - $dbType - TODO -#end - -#if ($dbType != 'h2') - - com.h2database - h2 - test - -#end - - - - org.flywaydb - flyway-core - - - - - org.apache.cxf - cxf-rt-rs-service-description - - - - - org.springframework.boot - spring-boot-starter-actuator - - - - - org.springframework - spring-aop - - - - - cglib - cglib - - - - - net.logstash.logback - logstash-logback-encoder - - - - - com.devonfw.java.modules - devon4j-test-jpa - test - - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-tomcat - - - org.springframework.boot - spring-boot-starter-validation - - - - - - - - embedded - - true - - - - org.springframework.boot - spring-boot-starter-tomcat - - ${spring.boot.version} - - - - - - - - - org.apache.maven.plugins - maven-jar-plugin - - - config/application.properties - - - - - - - + + + 4.0.0 + + ${groupId} + ${rootArtifactId} + ${revision} + + ${rootArtifactId}-core + jar + ${project.artifactId} + Core of the server for the ${rootArtifactId} application - a simple example based on devon4j. + + + + ${project.groupId} + ${rootArtifactId}-api + ${project.version} + + + + + com.devonfw.java.modules + devon4j-beanmapping-orika + + + + + com.devonfw.java.starters + devon4j-starter-security + + + + com.devonfw.java.modules + devon4j-web + + + + com.devonfw.java.modules + devon4j-test-jpa + test + + + + + com.devonfw.java.starters + devon4j-starter-cxf-client-rest + + + + com.devonfw.java.starters + devon4j-starter-cxf-client-ws + + + + + com.devonfw.java.starters + devon4j-starter-cxf-server-rest + + + + com.devonfw.java.starters + devon4j-starter-cxf-server-ws + + + + + com.devonfw.java.starters + devon4j-starter-spring-data-jpa + + + + + org.springframework.boot + spring-boot-starter-jdbc + + + + + javax.persistence + javax.persistence-api + + + + + org.hibernate + hibernate-entitymanager + + + + + com.querydsl + querydsl-jpa + + + com.querydsl + querydsl-apt + provided + + + + + org.hibernate.validator + hibernate-validator + + + + + javax.servlet + javax.servlet-api + provided + + + + + javax.el + javax.el-api + + + + + org.springframework + spring-webmvc + + + + +#if ($dbType == 'h2') + com.h2database + h2 +#elseif ($dbType == 'hsqldb') + org.hsqldb + hsqldb + 2.4.0 +#elseif ($dbType == 'postgresql') + org.postgresql + postgresql + +#elseif ($dbType == 'mysql') + mysql + mysql-connector-java + 8.0.8-dmr +#elseif ($dbType == 'mariadb') + org.mariadb.jdbc + mariadb-java-client + 1.5.4 +#elseif ($dbType == 'hana') + com.sap.cloud.db.jdbc + ngdbc + 2.3.48 +#elseif ($dbType == 'oracle') + com.oracle.jdbc + ojdbc8 + 12.2.0.1 +#elseif ($dbType == 'mssql') + com.microsoft.sqlserver + mssql-jdbc + 6.4.0.jre8 +#else + $dbType + $dbType + TODO +#end + +#if ($dbType != 'h2') + + com.h2database + h2 + test + +#end + + +#if ($dbMigration == 'flyway') + + org.flywaydb + flyway-core + +#end + +#if ($dbMigration == 'liquibase') + + org.liquibase + liquibase-core + +#end + + + + org.apache.cxf + cxf-rt-rs-service-description + + + + + org.springframework.boot + spring-boot-starter-actuator + + + + + org.springframework + spring-aop + + + + + cglib + cglib + + + + + net.logstash.logback + logstash-logback-encoder + + + + + com.devonfw.java.modules + devon4j-test-jpa + test + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-tomcat + + + org.springframework.boot + spring-boot-starter-validation + + + + + + + + embedded + + true + + + + org.springframework.boot + spring-boot-starter-tomcat + + ${spring.boot.version} + + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + config/application.properties + + + + +#if($dbMigration == 'liquibase') + + org.liquibase + liquibase-maven-plugin + 3.8.0 + + + liquibase + + + +#end + + + + diff --git a/templates/server/src/main/resources/archetype-resources/core/src/main/resources/application.properties b/templates/server/src/main/resources/archetype-resources/core/src/main/resources/application.properties index be1ebdc9..3c86bd92 100644 --- a/templates/server/src/main/resources/archetype-resources/core/src/main/resources/application.properties +++ b/templates/server/src/main/resources/archetype-resources/core/src/main/resources/application.properties @@ -69,5 +69,5 @@ spring.jpa.open-in-view=false # see http://stackoverflow.com/questions/22318907/how-to-stop-spring-batch-scheduled-jobs-from-running-at-first-time-when-executin spring.batch.job.enabled=false -# Flyway for Database Setup and Migrations -spring.flyway.locations=classpath:db/migration +# Liquibase for Database Setup and Migrations +spring.liquibase.change-log=classpath:db/changelog/changelog-master.xml diff --git a/templates/server/src/main/resources/archetype-resources/core/src/main/resources/config/application.properties b/templates/server/src/main/resources/archetype-resources/core/src/main/resources/config/application.properties index 04ce2939..6d289180 100644 --- a/templates/server/src/main/resources/archetype-resources/core/src/main/resources/config/application.properties +++ b/templates/server/src/main/resources/archetype-resources/core/src/main/resources/config/application.properties @@ -47,6 +47,5 @@ spring.jpa.properties.hibernate.format_sql=true # Enable JSON pretty printing spring.jackson.serialization.INDENT_OUTPUT=true -# Flyway for Database Setup and Migrations -spring.flyway.enabled=true -spring.flyway.clean-on-validation-error=true +# Liquibase configuration for DB migration +spring.liquibase.enabled=true diff --git a/templates/server/src/main/resources/archetype-resources/core/src/main/resources/db/changelog/changelog-master.xml b/templates/server/src/main/resources/archetype-resources/core/src/main/resources/db/changelog/changelog-master.xml new file mode 100644 index 00000000..c7f1737b --- /dev/null +++ b/templates/server/src/main/resources/archetype-resources/core/src/main/resources/db/changelog/changelog-master.xml @@ -0,0 +1,9 @@ + + + + + \ No newline at end of file diff --git a/templates/server/src/main/resources/archetype-resources/core/src/main/resources/db/changelog/changelog-v1.0.xml b/templates/server/src/main/resources/archetype-resources/core/src/main/resources/db/changelog/changelog-v1.0.xml new file mode 100644 index 00000000..50b8cbdb --- /dev/null +++ b/templates/server/src/main/resources/archetype-resources/core/src/main/resources/db/changelog/changelog-v1.0.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file From a46fad19f1990f7f13e09612f9aef0443a3b4dea Mon Sep 17 00:00:00 2001 From: Dixit Date: Mon, 15 Feb 2021 17:46:39 +0530 Subject: [PATCH 20/43] added both flyway and liquibase configuration --- templates/pom.xml | 62 ++++-- .../META-INF/maven/archetype-metadata.xml | 195 +++++++++--------- .../base/test/SpringBatchIntegrationTest.java | 106 +++++----- .../src/main/resources/application.properties | 8 +- .../resources/config/application.properties | 8 +- .../projects/basic/archetype.properties | 3 +- .../projects/batch/archetype.properties | 3 +- .../projects/enterprise/archetype.properties | 3 +- 8 files changed, 215 insertions(+), 173 deletions(-) diff --git a/templates/pom.xml b/templates/pom.xml index 157b7e4d..43e0f835 100644 --- a/templates/pom.xml +++ b/templates/pom.xml @@ -1,19 +1,43 @@ - - - 4.0.0 - - com.devonfw.java.dev - devon4j - dev-SNAPSHOT - - devon4j-templates - pom - ${project.artifactId} - Templates (maven archetypes) of devon4j. - - - server - - - + + + + + 4.0.0 + + + + + + com.devonfw.java.dev + + + devon4j + + + dev-SNAPSHOT + + + + + + devon4j-templates + + + pom + + + ${project.artifactId} + + + Templates (maven archetypes) of devon4j. + + + + + + server + + + + + diff --git a/templates/server/src/main/resources/META-INF/maven/archetype-metadata.xml b/templates/server/src/main/resources/META-INF/maven/archetype-metadata.xml index 04f42b9e..7901e6b9 100644 --- a/templates/server/src/main/resources/META-INF/maven/archetype-metadata.xml +++ b/templates/server/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -1,96 +1,99 @@ - - - devon4j-template-server - - - - . - - - h2 - - - - . - batch|[.] - - - - - - - api - - **/*.* - - - - core - - **/*.* - - - - __earProjectName__ - - **/*.* - - - - - __batch__ - - **/*.* - - - - - - .gitignore - - - - .mvn - - **/*.* - - - - - - - - src/main/java - - - src/main/resources - - - src/test/java - - - src/test/resources - - - src/main/webapp - - - - - + + + devon4j-template-server + + + + . + + + h2 + + + + flyway + + + . + batch|[.] + + + + + + + api + + **/*.* + + + + core + + **/*.* + + + + __earProjectName__ + + **/*.* + + + + + __batch__ + + **/*.* + + + + + + .gitignore + + + + .mvn + + **/*.* + + + + + + + + src/main/java + + + src/main/resources + + + src/test/java + + + src/test/resources + + + src/main/webapp + + + + + \ No newline at end of file diff --git a/templates/server/src/main/resources/archetype-resources/__batch__/src/test/java/__packageInPathFormat__/general/batch/base/test/SpringBatchIntegrationTest.java b/templates/server/src/main/resources/archetype-resources/__batch__/src/test/java/__packageInPathFormat__/general/batch/base/test/SpringBatchIntegrationTest.java index 6bea2912..bf7d95a8 100644 --- a/templates/server/src/main/resources/archetype-resources/__batch__/src/test/java/__packageInPathFormat__/general/batch/base/test/SpringBatchIntegrationTest.java +++ b/templates/server/src/main/resources/archetype-resources/__batch__/src/test/java/__packageInPathFormat__/general/batch/base/test/SpringBatchIntegrationTest.java @@ -1,53 +1,53 @@ -package ${package}.general.batch.base.test; - -import javax.inject.Inject; - -import org.flywaydb.core.Flyway; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.batch.core.Job; -import org.springframework.batch.core.launch.JobLauncher; -import org.springframework.batch.test.JobLauncherTestUtils; - -import ${package}.general.common.base.test.TestUtil; -import com.devonfw.module.test.common.base.ComponentTest; - -/** - * Base class for all spring batch integration tests. It helps to do End-to-End job tests. - */ -public abstract class SpringBatchIntegrationTest extends ComponentTest { - - @Inject - private JobLauncher jobLauncher; - - @Inject - private Flyway flyway; - - @Override - protected void doSetUp() { - - super.doSetUp(); - this.flyway.clean(); - this.flyway.migrate(); - } - - @Override - protected void doTearDown() { - - super.doTearDown(); - TestUtil.logout(); - } - - /** - * @param job job to configure - * @return jobLauncherTestUtils - */ - public JobLauncherTestUtils getJobLauncherTestUtils(Job job) { - - JobLauncherTestUtils jobLauncherTestUtils = new JobLauncherTestUtils(); - jobLauncherTestUtils.setJob(job); - jobLauncherTestUtils.setJobLauncher(this.jobLauncher); - - return jobLauncherTestUtils; - } -} +package ${package}.general.batch.base.test; + +import javax.inject.Inject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.batch.core.Job; +import org.springframework.batch.core.launch.JobLauncher; +import org.springframework.batch.test.JobLauncherTestUtils; +import ${package}.general.common.base.test.TestUtil; +import com.devonfw.module.test.common.base.ComponentTest; +import com.devonfw.module.test.common.base.clean.TestCleanerPlugin; +import com.devonfw.module.test.common.base.clean.TestCleanerPluginFlyway; +/** + * Base class for all spring batch integration tests. It helps to do End-to-End job tests. + */ +public abstract class SpringBatchIntegrationTest extends ComponentTest { + + @Inject + private JobLauncher jobLauncher; + + @Inject + private TestCleanerPlugin testCleanerPlugin; + + @Override + protected void doSetUp() { + super.doSetUp(); +#if($dbMigration == 'flyway') + testCleanerPlugin = new TestCleanerPluginFlyway(); +#else if($dbMigration == 'liquibase') + testCleanerPlugin = new TestCleanerPluginLiquibase(); +#end + testCleanerPlugin.cleanup(); + } + + protected void doTearDown() { + + super.doTearDown(); + TestUtil.logout(); + } + + /** + * @param job job to configure + * @return jobLauncherTestUtils + */ + public JobLauncherTestUtils getJobLauncherTestUtils(Job job) { + + JobLauncherTestUtils jobLauncherTestUtils = new JobLauncherTestUtils(); + jobLauncherTestUtils.setJob(job); + jobLauncherTestUtils.setJobLauncher(this.jobLauncher); + + return jobLauncherTestUtils; + } +} \ No newline at end of file diff --git a/templates/server/src/main/resources/archetype-resources/core/src/main/resources/application.properties b/templates/server/src/main/resources/archetype-resources/core/src/main/resources/application.properties index 3c86bd92..bc0a35ee 100644 --- a/templates/server/src/main/resources/archetype-resources/core/src/main/resources/application.properties +++ b/templates/server/src/main/resources/archetype-resources/core/src/main/resources/application.properties @@ -69,5 +69,11 @@ spring.jpa.open-in-view=false # see http://stackoverflow.com/questions/22318907/how-to-stop-spring-batch-scheduled-jobs-from-running-at-first-time-when-executin spring.batch.job.enabled=false -# Liquibase for Database Setup and Migrations + + +# Configuration for Database Setup and Migrations +#if ($dbMigration == 'flyway') +spring.flyway.locations=classpath:db/migration +#else spring.liquibase.change-log=classpath:db/changelog/changelog-master.xml +#end diff --git a/templates/server/src/main/resources/archetype-resources/core/src/main/resources/config/application.properties b/templates/server/src/main/resources/archetype-resources/core/src/main/resources/config/application.properties index 6d289180..ccfa335c 100644 --- a/templates/server/src/main/resources/archetype-resources/core/src/main/resources/config/application.properties +++ b/templates/server/src/main/resources/archetype-resources/core/src/main/resources/config/application.properties @@ -47,5 +47,11 @@ spring.jpa.properties.hibernate.format_sql=true # Enable JSON pretty printing spring.jackson.serialization.INDENT_OUTPUT=true -# Liquibase configuration for DB migration +# Configuration for Database Setup and Migrations +#if ($dbMigration == 'flyway') +spring.flyway.enabled=true +spring.flyway.clean-on-validation-error=true +#else spring.liquibase.enabled=true +#end + diff --git a/templates/server/src/test/resources/projects/basic/archetype.properties b/templates/server/src/test/resources/projects/basic/archetype.properties index 013232af..5af903a8 100644 --- a/templates/server/src/test/resources/projects/basic/archetype.properties +++ b/templates/server/src/test/resources/projects/basic/archetype.properties @@ -5,4 +5,5 @@ groupId=archetype.it artifactId=basic earProjectName=. batch=. -dbType=h2 \ No newline at end of file +dbType=h2 +dbMigration=flyway \ No newline at end of file diff --git a/templates/server/src/test/resources/projects/batch/archetype.properties b/templates/server/src/test/resources/projects/batch/archetype.properties index 552b794c..f30b83ec 100644 --- a/templates/server/src/test/resources/projects/batch/archetype.properties +++ b/templates/server/src/test/resources/projects/batch/archetype.properties @@ -5,4 +5,5 @@ groupId=archetype.it artifactId=app-with-batch earProjectName=. batch=batch -dbType=mysql \ No newline at end of file +dbType=mysql +dbMigration=flyway \ No newline at end of file diff --git a/templates/server/src/test/resources/projects/enterprise/archetype.properties b/templates/server/src/test/resources/projects/enterprise/archetype.properties index a8e0f5ed..9a75406b 100644 --- a/templates/server/src/test/resources/projects/enterprise/archetype.properties +++ b/templates/server/src/test/resources/projects/enterprise/archetype.properties @@ -5,4 +5,5 @@ groupId=archetype.it artifactId=enterprise earProjectName=${artifactId}-ear batch=. -dbType=postgresql \ No newline at end of file +dbType=postgresql +dbMigration=flyway \ No newline at end of file From 77f01612a2d1c816984d0ed9283fe860e46ade49 Mon Sep 17 00:00:00 2001 From: dixyushi Date: Mon, 12 Apr 2021 13:20:31 +0530 Subject: [PATCH 21/43] resolved testcleanerplugin issue --- modules/test-jpa/pom.xml | 23 ++++++++++ .../clean/TestCleanerPluginLiquibase.java | 45 +++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginLiquibase.java diff --git a/modules/test-jpa/pom.xml b/modules/test-jpa/pom.xml index 7030098c..2674eb69 100644 --- a/modules/test-jpa/pom.xml +++ b/modules/test-jpa/pom.xml @@ -25,5 +25,28 @@ org.flywaydb flyway-core + + org.liquibase + liquibase-core + + + + + org.flywaydb + flyway-maven-plugin + + /devon4j-test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginFlyway.java + + + + org.liquibase + liquibase-maven-plugin + + /devon4j-test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginLiquibase.java + + + + + \ No newline at end of file diff --git a/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginLiquibase.java b/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginLiquibase.java new file mode 100644 index 00000000..c9104da4 --- /dev/null +++ b/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginLiquibase.java @@ -0,0 +1,45 @@ +package com.devonfw.module.test.common.base.clean; + +import javax.inject.Inject; +import liquibase.Liquibase; + +/** + * @author ayudixit + * + */ +public class TestCleanerPluginLiquibase implements TestCleanerPlugin { + + @Inject + private Liquibase liquibase; + + /** + * The constructor. + */ + public TestCleanerPluginLiquibase() { + + super(); + } + + /** + * The constructor. + * + * @param liquibase the {@link Liquibase} instance. + */ + public TestCleanerPluginLiquibase(Liquibase liquibase) { + + super(); + this.liquibase = liquibase; + } + + @Override + public void cleanup() { + + try { + this.liquibase.dropAll(); + } catch (Exception e) { + e.printStackTrace(); + } + + } + +} From 49a7d714c65b68d403ac02cc12cf109d79459557 Mon Sep 17 00:00:00 2001 From: dixyushi Date: Wed, 14 Apr 2021 01:51:34 +0530 Subject: [PATCH 22/43] resolved conflicts --- .../META-INF/archetype-post-generate.groovy | 26 +++++++++++++++++++ .../META-INF/maven/archetype-metadata.xml | 11 ++++---- .../archetype-resources/core/pom.xml | 2 +- 3 files changed, 33 insertions(+), 6 deletions(-) create mode 100644 templates/server/src/main/resources/META-INF/archetype-post-generate.groovy diff --git a/templates/server/src/main/resources/META-INF/archetype-post-generate.groovy b/templates/server/src/main/resources/META-INF/archetype-post-generate.groovy new file mode 100644 index 00000000..8d4e7ff8 --- /dev/null +++ b/templates/server/src/main/resources/META-INF/archetype-post-generate.groovy @@ -0,0 +1,26 @@ +import java.nio.file.Files +import java.nio.file.Path +import java.nio.file.Paths + +// the path where the project got generated +Path projectPath = Paths.get(request.outputDirectory, request.artifactId) + +// the properties available to the archetype +Properties properties = request.properties + +// dbMigration is either flyway or liquibase +String dbMigration = properties.get("dbMigration") + +if (dbMigration == "flyway") { + // delete the changelog folder as it is not required for flyway + Files.deleteIfExists projectPath.resolve("src/main/resources/db/changelog/changelog-master.xml") + Files.deleteIfExists projectPath.resolve("src/main/resources/db/changelog/changelog-v1.0.xml") + Files.deleteIfExists projectPath.resolve("src/test/resources/db/changelog/changelog-master.xml") + Files.deleteIfExists projectPath.resolve("src/test/resources/db/changelog/changelog-v1.0.xml") + +} else if(dbMigration == "liquibase") { + // delete the changelog folder as it is not required for flyway + Files.deleteIfExists projectPath.resolve("src/main/resources/db/migration/1.0/V0001_Create_Sequence.sql") + Files.deleteIfExists projectPath.resolve("src/main/resources/db/test/V0001_InitDb.sql") +} + diff --git a/templates/server/src/main/resources/META-INF/maven/archetype-metadata.xml b/templates/server/src/main/resources/META-INF/maven/archetype-metadata.xml index 7901e6b9..47874b1a 100644 --- a/templates/server/src/main/resources/META-INF/maven/archetype-metadata.xml +++ b/templates/server/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -13,12 +13,13 @@ h2 - - flyway + + flyway + . - batch|[.] + batch|[.] @@ -68,13 +69,13 @@ .gitignore - + .mvn **/*.* - + diff --git a/templates/server/src/main/resources/archetype-resources/core/pom.xml b/templates/server/src/main/resources/archetype-resources/core/pom.xml index 6ac2b712..41617014 100644 --- a/templates/server/src/main/resources/archetype-resources/core/pom.xml +++ b/templates/server/src/main/resources/archetype-resources/core/pom.xml @@ -285,4 +285,4 @@ - + \ No newline at end of file From 50c91ae4efa0cd221981c1ad6098d81ab06c47d0 Mon Sep 17 00:00:00 2001 From: dixyushi Date: Wed, 21 Apr 2021 01:56:57 +0530 Subject: [PATCH 23/43] added conditions for dbMigration in testDBConfig --- modules/test-jpa/pom.xml | 21 ++----------------- .../archetype-resources/core/pom.xml | 1 + .../common/impl/config/TestDbConfig.java | 13 ++++++++++-- 3 files changed, 14 insertions(+), 21 deletions(-) diff --git a/modules/test-jpa/pom.xml b/modules/test-jpa/pom.xml index 2674eb69..e1e430d1 100644 --- a/modules/test-jpa/pom.xml +++ b/modules/test-jpa/pom.xml @@ -24,29 +24,12 @@ org.flywaydb flyway-core + true org.liquibase liquibase-core + true - - - - org.flywaydb - flyway-maven-plugin - - /devon4j-test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginFlyway.java - - - - org.liquibase - liquibase-maven-plugin - - /devon4j-test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginLiquibase.java - - - - - \ No newline at end of file diff --git a/templates/server/src/main/resources/archetype-resources/core/pom.xml b/templates/server/src/main/resources/archetype-resources/core/pom.xml index 41617014..746bcc02 100644 --- a/templates/server/src/main/resources/archetype-resources/core/pom.xml +++ b/templates/server/src/main/resources/archetype-resources/core/pom.xml @@ -70,6 +70,7 @@ devon4j-starter-spring-data-jpa + diff --git a/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/impl/config/TestDbConfig.java b/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/impl/config/TestDbConfig.java index 5f33fcf9..ab530c03 100644 --- a/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/impl/config/TestDbConfig.java +++ b/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/impl/config/TestDbConfig.java @@ -7,6 +7,7 @@ import com.devonfw.module.test.common.base.clean.TestCleanerImpl; import com.devonfw.module.test.common.base.clean.TestCleanerPlugin; import com.devonfw.module.test.common.base.clean.TestCleanerPluginFlyway; +import com.devonfw.module.test.common.base.clean.TestCleanerPluginLiquibase; /** * {@link Configuration} for Database in JUnit tests. @@ -27,9 +28,17 @@ public TestCleaner testCleaner() { * @return the {@link TestCleanerPluginFlyway}. */ @Bean - public TestCleanerPlugin testCleanerPluginFlyway() { + public TestCleanerPlugin testCleanerPlugin() { + + String dbMigrationValue = System.getenv($dbMigration); + + if(dbMigrationValue=="flyway") + { return new TestCleanerPluginFlyway(); + + }else if(dbMigrationValue=="liquibase") { + return new TestCleanerPluginLiquibase(); } - } +} \ No newline at end of file From 8233899f40bf2f90237f164d738f14ba9aef09a4 Mon Sep 17 00:00:00 2001 From: dixyushi Date: Wed, 19 May 2021 12:14:59 +0530 Subject: [PATCH 24/43] All required configurations and changes are done to implement --- modules/test/src/main/resources/logback.xml | 1 + pom.xml | 971 ++++++++++++++++-- templates/server/flywayy/pom.xml | 491 +++++++++ .../archetype-resources/core/pom.xml | 575 ++++++----- .../common/base/test/DbTestHelper.java | 86 +- .../common/impl/config/TestDbConfig.java | 45 +- .../impl/config/TestWebSecurityConfig.java | 1 + .../resources/config/application.properties | 14 +- .../db/changelog/changelog-master.xml | 9 + .../resources/db/changelog/changelog-v1.0.xml | 8 + .../resources/archetype-resources/pom.xml | 3 +- 11 files changed, 1808 insertions(+), 396 deletions(-) create mode 100644 templates/server/flywayy/pom.xml create mode 100644 templates/server/src/main/resources/archetype-resources/core/src/test/resources/db/changelog/changelog-master.xml create mode 100644 templates/server/src/main/resources/archetype-resources/core/src/test/resources/db/changelog/changelog-v1.0.xml diff --git a/modules/test/src/main/resources/logback.xml b/modules/test/src/main/resources/logback.xml index d4b83a52..d042e45d 100644 --- a/modules/test/src/main/resources/logback.xml +++ b/modules/test/src/main/resources/logback.xml @@ -16,6 +16,7 @@ + diff --git a/pom.xml b/pom.xml index 065357be..0308d799 100644 --- a/pom.xml +++ b/pom.xml @@ -1,67 +1,904 @@ - - - 4.0.0 - - com.devonfw - maven-parent - 6 - - com.devonfw.java.dev - devon4j - dev-SNAPSHOT - pom - ${project.artifactId} - Java stack of devonfw.com (devon4j): develop Java apps standardized, faster and with less risk. - 2014 - - - boms - modules - starters - templates - documentation - - - - dev-SNAPSHOT - devon4j - ${revision} - 2.4.4 - - 2020.0.0 - 2.12.2 - 30.1.1-jre - 5.7.1 - 3.4.3 - 8.7.0 - 1.7.30 - https://sonarcloud.io - devonfw - - - - - - - - org.apache.maven.plugins - maven-war-plugin - - WEB-INF/classes/config/application.properties,*.jsp - ${project.artifactId} - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - ${spring.boot.version} - - - - - + + + + + + + + + + + + + + + + + 4.0.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + com.devonfw + + + + + + + + + + + + + + + maven-parent + + + + + + + + + + + + + + + 6 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + com.devonfw.java.dev + + + + + + + + + + + + + + + devon4j + + + + + + + + + + + + + + + dev-SNAPSHOT + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + pom + + + + + + + + + + + + + + + ${project.artifactId} + + + + + + + + + + + + + + + Java stack of devonfw.com (devon4j): develop Java apps standardized, faster and with less risk. + + + + + + + + + + + + + + + 2014 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + boms + + + + + + + + + + + + + + + modules + + + + + + + + + + + + + + + starters + + + + + + + + + + + + + + + templates + + + + + + + + + + + + + + + documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + dev-SNAPSHOT + + + + + + + + + + + + + + + devon4j + + + + + + + + + + + + + + + ${revision} + + + + + + + + + + + + + + + 2.4.4 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 2020.0.0 + + + + + + + + + + + + + + + 2.12.2 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 30.1.1-jre + + + + + + + + + + + + + + + 5.7.1 + + + + + + + + + + + + + + + 3.4.3 + + + + + + + + + + + + + + + 8.7.0 + + + + + + + + + + + + + + + 1.7.30 + + + + + + + + + + + + + + + https://sonarcloud.io + + + + + + + + + + + + + + + devonfw + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + org.apache.maven.plugins + + + + + + + + + + + + + + + maven-war-plugin + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + WEB-INF/classes/config/application.properties,*.jsp + + + + + + + + + + + + + + + ${project.artifactId} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + org.springframework.boot + + + + + + + + + + + + + + + spring-boot-maven-plugin + + + + + + + + + + + + + + + ${spring.boot.version} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/templates/server/flywayy/pom.xml b/templates/server/flywayy/pom.xml new file mode 100644 index 00000000..2d9b9ad3 --- /dev/null +++ b/templates/server/flywayy/pom.xml @@ -0,0 +1,491 @@ + + + 4.0.0 + flywayy + com.flywayy + ${app.version} + pom + ${project.artifactId} + Application based on the devon4j. + + + 2.4.4 + 2021.04.001-SNAPSHOT + 1.8 + 5.7.1 + UTF-8 + UTF-8 + 2.12.2 + 30.1.1-jre + system + ${revision} + + + + api + core + server + + + + + + + com.fasterxml.jackson + jackson-bom + ${jackson.version} + pom + import + + + + org.junit + junit-bom + ${junit.version} + pom + import + + + + com.google.guava + guava + ${guava.version} + + + + org.springframework.boot + spring-boot-dependencies + ${spring.boot.version} + pom + import + + + + com.devonfw.java.boms + devon4j-bom + ${devon4j.version} + pom + import + + + + + + + org.slf4j + slf4j-api + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + ${project.build.sourceEncoding} + ${java.version} + ${java.version} + + + + + maven-surefire-plugin + + ${devonfw.test.excluded.groups} + true + + + + + + org.jacoco + jacoco-maven-plugin + + + default-prepare-agent + + prepare-agent + + + + default-report + + report + + + + + + + + + org.apache.maven.plugins + maven-resources-plugin + 3.1.0 + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + + org.apache.maven.plugins + maven-install-plugin + 2.5.2 + + + org.apache.maven.plugins + maven-deploy-plugin + 2.8.2 + + + org.apache.maven.plugins + maven-clean-plugin + 3.1.0 + + + org.apache.maven.plugins + maven-jar-plugin + 3.1.2 + + + org.apache.maven.plugins + maven-source-plugin + 3.1.0 + + + org.apache.maven.plugins + maven-site-plugin + 3.7.1 + + + org.apache.maven.plugins + maven-checkstyle-plugin + 3.1.0 + + + org.apache.maven.plugins + maven-changes-plugin + 2.12.1 + + + org.apache.maven.plugins + maven-changelog-plugin + 2.3 + + + org.apache.maven.plugins + maven-project-info-reports-plugin + 3.0.0 + + + org.apache.maven.plugins + maven-jxr-plugin + 3.0.0 + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.1.1 + + + + true + protected + ${project.reporting.outputEncoding} + ${project.build.sourceEncoding} + true + ${user.dir}/src/main/javadoc/stylesheet.css + none + ${java.version} + JavaDocs for ${project.name} ${project.version} + JavaDocs for ${project.name} ${project.version} + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.2 + + + ${basedir} + + + + org.apache.maven.plugins + maven-surefire-report-plugin + 2.22.2 + + + org.apache.maven.plugins + maven-pmd-plugin + 3.9.0 + + ${java.version} + + + + org.apache.maven.plugins + maven-war-plugin + 3.2.3 + + + org.apache.maven.plugins + maven-antrun-plugin + 1.8 + + + org.apache.maven.plugins + maven-help-plugin + 3.2.0 + + + org.apache.maven.plugins + maven-gpg-plugin + 1.6 + + + org.apache.maven.plugins + maven-archetype-plugin + 3.1.2 + + + org.apache.maven.archetype + archetype-packaging + 3.1.2 + + + org.codehaus.mojo + taglist-maven-plugin + 2.4 + + + org.codehaus.mojo + cobertura-maven-plugin + 2.7 + + + org.codehaus.mojo + flatten-maven-plugin + 1.2.2 + + + org.codehaus.mojo + license-maven-plugin + 1.20 + + ${project.build.directory}/generated-resources + true + true + true + true + + Apache Software License, Version 2.0|The Apache Software License, Version 2.0|Apache + 2.0|Apache License, Version 2.0 + + + + + org.codehaus.mojo + servicedocgen-maven-plugin + 1.0.0-beta-3 + + + org.sonarsource.scanner.maven + sonar-maven-plugin + 3.7.0.1746 + + + org.jacoco + jacoco-maven-plugin + 0.8.5 + + + org.owasp + dependency-check-maven + 5.3.2 + + + com.github.spotbugs + spotbugs-maven-plugin + 3.1.12.2 + + + org.springframework.boot + spring-boot-maven-plugin + ${spring.boot.version} + + + + + + + + moduletest + + component,subsystem,system + + + + componenttest + + subsystem,system + + + + subsystemtest + + system + + + + systemtest + + none + + + + security + + + + org.owasp + dependency-check-maven + + 8 + + + + + check + + + + + + + + + licenses + + + + org.codehaus.mojo + license-maven-plugin + + + aggregate-add-third-party + generate-resources + + aggregate-add-third-party + + + + + aggregate-download-licenses + generate-resources + + aggregate-download-licenses + + + + + + + + + + eclipse + + + eclipse.application + + + + eclipse-target + + + + + + + + org.apache.maven.plugins + maven-project-info-reports-plugin + + false + + + + org.apache.maven.plugins + maven-jxr-plugin + + + org.apache.maven.plugins + maven-javadoc-plugin + + + org.codehaus.mojo + taglist-maven-plugin + + + TODO + @todo + FIXME + @deprecated + REVIEW + + + + + org.owasp + dependency-check-maven + + false + + + + + aggregate + check + + + + + + org.codehaus.mojo + servicedocgen-maven-plugin + + + + ${servicedoc.info.title} + ${servicedoc.info.description} + + ${servicedoc.host} + ${servicedoc.port} + ${servicedoc.basePath} + + http + + + + + + org.codehaus.mojo + license-maven-plugin + + + + third-party-report + aggregate-third-party-report + + + + + + + + diff --git a/templates/server/src/main/resources/archetype-resources/core/pom.xml b/templates/server/src/main/resources/archetype-resources/core/pom.xml index 746bcc02..9eb95866 100644 --- a/templates/server/src/main/resources/archetype-resources/core/pom.xml +++ b/templates/server/src/main/resources/archetype-resources/core/pom.xml @@ -1,289 +1,288 @@ - - - 4.0.0 - - ${groupId} - ${rootArtifactId} - ${revision} - - ${rootArtifactId}-core - jar - ${project.artifactId} - Core of the server for the ${rootArtifactId} application - a simple example based on devon4j. - - - - ${project.groupId} - ${rootArtifactId}-api - ${project.version} - - - - - com.devonfw.java.modules - devon4j-beanmapping-orika - - - - - com.devonfw.java.starters - devon4j-starter-security - - - - com.devonfw.java.modules - devon4j-web - - - - com.devonfw.java.modules - devon4j-test-jpa - test - - - - - com.devonfw.java.starters - devon4j-starter-cxf-client-rest - - - - com.devonfw.java.starters - devon4j-starter-cxf-client-ws - - - - - com.devonfw.java.starters - devon4j-starter-cxf-server-rest - - - - com.devonfw.java.starters - devon4j-starter-cxf-server-ws - - - - - com.devonfw.java.starters - devon4j-starter-spring-data-jpa - - - - - - org.springframework.boot - spring-boot-starter-jdbc - - - - - javax.persistence - javax.persistence-api - - - - - org.hibernate - hibernate-entitymanager - - - - - com.querydsl - querydsl-jpa - - - com.querydsl - querydsl-apt - provided - - - - - org.hibernate.validator - hibernate-validator - - - - - javax.servlet - javax.servlet-api - provided - - - - - javax.el - javax.el-api - - - - - org.springframework - spring-webmvc - - - - -#if ($dbType == 'h2') - com.h2database - h2 -#elseif ($dbType == 'hsqldb') - org.hsqldb - hsqldb - 2.4.0 -#elseif ($dbType == 'postgresql') - org.postgresql - postgresql - -#elseif ($dbType == 'mysql') - mysql - mysql-connector-java - 8.0.8-dmr -#elseif ($dbType == 'mariadb') - org.mariadb.jdbc - mariadb-java-client - 1.5.4 -#elseif ($dbType == 'hana') - com.sap.cloud.db.jdbc - ngdbc - 2.3.48 -#elseif ($dbType == 'oracle') - com.oracle.jdbc - ojdbc8 - 12.2.0.1 -#elseif ($dbType == 'mssql') - com.microsoft.sqlserver - mssql-jdbc - 6.4.0.jre8 -#else - $dbType - $dbType - TODO -#end - -#if ($dbType != 'h2') - - com.h2database - h2 - test - -#end - - -#if ($dbMigration == 'flyway') - - org.flywaydb - flyway-core - -#end - -#if ($dbMigration == 'liquibase') - - org.liquibase - liquibase-core - -#end - - - - org.apache.cxf - cxf-rt-rs-service-description - - - - - org.springframework.boot - spring-boot-starter-actuator - - - - - org.springframework - spring-aop - - - - - cglib - cglib - - - - - net.logstash.logback - logstash-logback-encoder - - - - - com.devonfw.java.modules - devon4j-test-jpa - test - - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-tomcat - - - org.springframework.boot - spring-boot-starter-validation - - - - - - - - embedded - - true - - - - org.springframework.boot - spring-boot-starter-tomcat - - ${spring.boot.version} - - - - - - - - - org.apache.maven.plugins - maven-jar-plugin - - - config/application.properties - - - - -#if($dbMigration == 'liquibase') - - org.liquibase - liquibase-maven-plugin - 3.8.0 - - - liquibase - - - -#end - - - + + + 4.0.0 + + ${groupId} + ${rootArtifactId} + ${revision} + + ${rootArtifactId}-core + jar + ${project.artifactId} + Core of the server for the ${rootArtifactId} application - a simple example based on devon4j. + + + + ${project.groupId} + ${rootArtifactId}-api + ${project.version} + + + + + com.devonfw.java.modules + devon4j-beanmapping-orika + + + + + com.devonfw.java.starters + devon4j-starter-security + + + + com.devonfw.java.modules + devon4j-web + + + + com.devonfw.java.modules + devon4j-test-jpa + test + + + + + com.devonfw.java.starters + devon4j-starter-cxf-client-rest + + + + com.devonfw.java.starters + devon4j-starter-cxf-client-ws + + + + + com.devonfw.java.starters + devon4j-starter-cxf-server-rest + + + + com.devonfw.java.starters + devon4j-starter-cxf-server-ws + + + + + com.devonfw.java.starters + devon4j-starter-spring-data-jpa + + + + + org.springframework.boot + spring-boot-starter-jdbc + + + + + javax.persistence + javax.persistence-api + + + + + org.hibernate + hibernate-entitymanager + + + + + com.querydsl + querydsl-jpa + + + com.querydsl + querydsl-apt + provided + + + + + org.hibernate.validator + hibernate-validator + + + + + javax.servlet + javax.servlet-api + provided + + + + + javax.el + javax.el-api + + + + + org.springframework + spring-webmvc + + + + +#if ($dbType == 'h2') + com.h2database + h2 +#elseif ($dbType == 'hsqldb') + org.hsqldb + hsqldb + 2.4.0 +#elseif ($dbType == 'postgresql') + org.postgresql + postgresql + +#elseif ($dbType == 'mysql') + mysql + mysql-connector-java + 8.0.8-dmr +#elseif ($dbType == 'mariadb') + org.mariadb.jdbc + mariadb-java-client + 1.5.4 +#elseif ($dbType == 'hana') + com.sap.cloud.db.jdbc + ngdbc + 2.3.48 +#elseif ($dbType == 'oracle') + com.oracle.jdbc + ojdbc8 + 12.2.0.1 +#elseif ($dbType == 'mssql') + com.microsoft.sqlserver + mssql-jdbc + 6.4.0.jre8 +#else + $dbType + $dbType + TODO +#end + +#if ($dbType != 'h2') + + com.h2database + h2 + test + +#end + + +#if ($dbMigration == 'flyway') + + org.flywaydb + flyway-core + +#end + +#if ($dbMigration == 'liquibase') + + org.liquibase + liquibase-core + +#end + + + + org.apache.cxf + cxf-rt-rs-service-description + + + + + org.springframework.boot + spring-boot-starter-actuator + + + + + org.springframework + spring-aop + + + + + cglib + cglib + + + + + net.logstash.logback + logstash-logback-encoder + + + + + com.devonfw.java.modules + devon4j-test-jpa + test + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-tomcat + + + org.springframework.boot + spring-boot-starter-validation + + + + + + + + embedded + + true + + + + org.springframework.boot + spring-boot-starter-tomcat + + ${spring.boot.version} + + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + config/application.properties + + + + +#if($dbMigration == 'liquibase') + + org.liquibase + liquibase-maven-plugin + 3.8.0 + + + liquibase + + + +#end + + + \ No newline at end of file diff --git a/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/base/test/DbTestHelper.java b/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/base/test/DbTestHelper.java index 65ca1e44..3e0dca55 100644 --- a/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/base/test/DbTestHelper.java +++ b/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/base/test/DbTestHelper.java @@ -1,44 +1,88 @@ package ${package}.general.common.base.test; +import javax.inject.Inject; import javax.inject.Named; - +#if ($dbMigration == 'liquibase') + import liquibase.Liquibase; +#else import org.flywaydb.core.Flyway; - +#end /** * This class provides methods for handling the database during testing where resets (and other operations) may be * necessary. */ @Named public class DbTestHelper { + #if ($dbMigration == 'liquibase') + private Liquibase liquibase; + #else + private Flyway flyway; + #end + + #if ($dbMigration == 'liquibase') + /** + * The constructor. + * + * @param liquibase an instance of type {@link Liquibase}. + */ + public DbTestHelper( Liquibase liquibase) { + super(); + this.liquibase = liquibase; + } + #else + /** + * The constructor. + * + * @param flyway an instance of type {@link Flyway}. + */ + public DbTestHelper( Flyway flyway) { + super(); + this.flyway = flyway; + } + #end + + +// public DbTestHelper(#if ($dbMigration == 'liquibase') Liquibase liquibase #else Flyway flyway #end) { +// super(); +// #if ($dbMigration == 'liquibase') +// this.liquibase = liquibase; +// #else +// this.flyway = flyway; +// #end +// } - private Flyway flyway; - + + #if ($dbMigration == 'flyway') /** - * The constructor. - * - * @param flyway an instance of type {@link Flyway}. + * Calls {@link #dropDatabase()} internally, and migrates to the highest available migration (default) or to the + * {@code migrationVersion} specified by {@link #setMigrationVersion(String)}. */ - public DbTestHelper(Flyway flyway) { - super(); - this.flyway = flyway; + public void resetDatabase() { + + this.flyway.migrate(); } + #end +#if ($dbMigration == 'liquibase') /** * Drops the whole database. */ - public void dropDatabase() { + public void cleanup() { - this.flyway.clean(); - } - - /** - * Calls {@link #dropDatabase()} internally, and migrates to the highest available migration (default) or to the - * {@code migrationVersion} specified by {@link #setMigrationVersion(String)}. - */ - public void resetDatabase() { + try { + this.liquibase.dropAll(); + } catch (Exception e) { + e.printStackTrace(); + } - dropDatabase(); - this.flyway.migrate(); } + #else + /** + * Drops the whole database. + */ + public void dropDatabase() { + this.flyway.clean(); + } +#end } diff --git a/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/impl/config/TestDbConfig.java b/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/impl/config/TestDbConfig.java index ab530c03..8b24fcaa 100644 --- a/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/impl/config/TestDbConfig.java +++ b/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/impl/config/TestDbConfig.java @@ -6,15 +6,20 @@ import com.devonfw.module.test.common.base.clean.TestCleaner; import com.devonfw.module.test.common.base.clean.TestCleanerImpl; import com.devonfw.module.test.common.base.clean.TestCleanerPlugin; -import com.devonfw.module.test.common.base.clean.TestCleanerPluginFlyway; +#if ($dbMigration == 'liquibase') import com.devonfw.module.test.common.base.clean.TestCleanerPluginLiquibase; +#else +import com.devonfw.module.test.common.base.clean.TestCleanerPluginFlyway; +#end + + /** * {@link Configuration} for Database in JUnit tests. */ @Configuration public class TestDbConfig { - + /** * @return the {@link TestCleaner}. */ @@ -24,21 +29,25 @@ public TestCleaner testCleaner() { return new TestCleanerImpl(); } - /** - * @return the {@link TestCleanerPluginFlyway}. - */ - @Bean - public TestCleanerPlugin testCleanerPlugin() { - - - String dbMigrationValue = System.getenv($dbMigration); +#if ($dbMigration == 'liquibase') + /** + * @return the {@link TestCleanerPluginLiquibase}. + */ + @Bean + public TestCleanerPlugin testCleanerPluginLiquibase() { + + return new TestCleanerPluginLiquibase(); + } + +#else + /** + * @return the {@link TestCleanerPluginFlyway}. + */ + @Bean + public TestCleanerPlugin testCleanerPluginFlyway() { + + return new TestCleanerPluginFlyway(); + } +#end - if(dbMigrationValue=="flyway") - { - return new TestCleanerPluginFlyway(); - - }else if(dbMigrationValue=="liquibase") { - return new TestCleanerPluginLiquibase(); - } -} } \ No newline at end of file diff --git a/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/impl/config/TestWebSecurityConfig.java b/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/impl/config/TestWebSecurityConfig.java index 927c50e0..1438572a 100644 --- a/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/impl/config/TestWebSecurityConfig.java +++ b/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/impl/config/TestWebSecurityConfig.java @@ -24,6 +24,7 @@ public class TestWebSecurityConfig extends BaseWebSecurityConfig { private static Logger LOG = LoggerFactory.getLogger(TestWebSecurityConfig.class); + /** * Configure spring security to enable a simple webform-login + a simple rest login. */ diff --git a/templates/server/src/main/resources/archetype-resources/core/src/test/resources/config/application.properties b/templates/server/src/main/resources/archetype-resources/core/src/test/resources/config/application.properties index c6836bab..edd6b742 100644 --- a/templates/server/src/main/resources/archetype-resources/core/src/test/resources/config/application.properties +++ b/templates/server/src/main/resources/archetype-resources/core/src/test/resources/config/application.properties @@ -8,10 +8,22 @@ spring.datasource.password= spring.datasource.username=sa spring.jpa.hibernate.ddl-auto=none -# Flyway for Database Setup and Migrations + +# Configuration for Database Setup and Migrations + +#if ($dbMigration == 'flyway') spring.flyway.enabled=true #if ($dbType == 'h2') spring.flyway.locations=classpath:db/migration #else spring.flyway.locations=classpath:db/test #end +#end +#if ($dbMigration == 'liquibase') +spring.liquibase.enabled=true +#if ($dbType == 'h2') +spring.liquibase.locations=classpath:db/changelog/changelog-master.xml +#else +spring.liquibase.locations=classpath:db/test +#end +#end \ No newline at end of file diff --git a/templates/server/src/main/resources/archetype-resources/core/src/test/resources/db/changelog/changelog-master.xml b/templates/server/src/main/resources/archetype-resources/core/src/test/resources/db/changelog/changelog-master.xml new file mode 100644 index 00000000..c7f1737b --- /dev/null +++ b/templates/server/src/main/resources/archetype-resources/core/src/test/resources/db/changelog/changelog-master.xml @@ -0,0 +1,9 @@ + + + + + \ No newline at end of file diff --git a/templates/server/src/main/resources/archetype-resources/core/src/test/resources/db/changelog/changelog-v1.0.xml b/templates/server/src/main/resources/archetype-resources/core/src/test/resources/db/changelog/changelog-v1.0.xml new file mode 100644 index 00000000..50b8cbdb --- /dev/null +++ b/templates/server/src/main/resources/archetype-resources/core/src/test/resources/db/changelog/changelog-v1.0.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/templates/server/src/main/resources/archetype-resources/pom.xml b/templates/server/src/main/resources/archetype-resources/pom.xml index adadb7f7..bb926b77 100644 --- a/templates/server/src/main/resources/archetype-resources/pom.xml +++ b/templates/server/src/main/resources/archetype-resources/pom.xml @@ -74,7 +74,7 @@ pom import - + @@ -101,6 +101,7 @@ maven-surefire-plugin ${devonfw.test.excluded.groups} + true From 3b9d0ea9ef289a392fa9ace2464238356b7ea9cd Mon Sep 17 00:00:00 2001 From: dixyushi Date: Thu, 20 May 2021 10:01:15 +0530 Subject: [PATCH 25/43] fixed review comments --- pom.xml | 753 ++---------------- templates/pom.xml | 34 +- templates/server/flywayy/pom.xml | 491 ------------ .../test/SpringBatchIntegrationTest .java | 73 ++ .../src/main/resources/application.properties | 2 - .../common/base/test/DbTestHelper.java | 11 - .../impl/config/TestWebSecurityConfig.java | 1 - .../resources/config/application.properties | 2 - .../resources/archetype-resources/pom.xml | 3 +- 9 files changed, 127 insertions(+), 1243 deletions(-) delete mode 100644 templates/server/flywayy/pom.xml create mode 100644 templates/server/src/main/resources/archetype-resources/__batch__/src/test/java/__packageInPathFormat__/general/batch/base/test/SpringBatchIntegrationTest .java diff --git a/pom.xml b/pom.xml index 0308d799..5f73d94b 100644 --- a/pom.xml +++ b/pom.xml @@ -1,637 +1,50 @@ - + - - - - - - - - - - - - - 4.0.0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - com.devonfw - - - - - - - - - - - - - - - maven-parent - - - - - - - - - - - - - - - 6 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - com.devonfw.java.dev - - - - - - - - - - - - - - - devon4j - - - - - - - - - - - - - - - dev-SNAPSHOT - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - pom - - - - - - - - - - - - - - - ${project.artifactId} - - - - - - - - - - - - - - - Java stack of devonfw.com (devon4j): develop Java apps standardized, faster and with less risk. - - - - - - - - - - - - - - - 2014 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - boms - - - - - - - - - - - - - - - modules - - - - - - - - - - - - - - - starters - - - - - - - - - - - - - - - templates - - - - - - - - - - - - - - - documentation - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - dev-SNAPSHOT - - - - - - - - - - - - - - - devon4j - - - - - - - - - - - - - - - ${revision} - - - - - - - - - - - - - - - 2.4.4 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 2020.0.0 - - - - - - - - - - - - - - - 2.12.2 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 30.1.1-jre - - - - - - - - - - - - - - - 5.7.1 - - - - - - - - - - - - - - - 3.4.3 - - - - - - - - - - - - - - - 8.7.0 - - - - - - - - - - - - - - - 1.7.30 - - - - - - - - - - - - - - - https://sonarcloud.io - - - - - - - - - - - - - - - devonfw - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - org.apache.maven.plugins + 4.0.0 + + com.devonfw + maven-parent + 6 + + com.devonfw.java.dev + devon4j + dev-SNAPSHOT + +pom + ${project.artifactId} +Java stack of devonfw.com (devon4j): develop Java apps standardized, faster and with less risk. + 2014 + +boms + modules + starters +templates +documentation + + + dev-SNAPSHOT + devon4j + ${revision} +2.4.4 + +2020.0.0 +2.12.2 + + 30.1.1-jre + 5.7.1 +3.4.3 + 8.7.0 +1.7.30 +https://sonarcloud.io + devonfw + + + + + +org.apache.maven.plugins @@ -827,78 +240,8 @@ ${spring.boot.version} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + diff --git a/templates/pom.xml b/templates/pom.xml index 43e0f835..d3a57f1e 100644 --- a/templates/pom.xml +++ b/templates/pom.xml @@ -1,43 +1,19 @@ - - - - + + 4.0.0 - - - - com.devonfw.java.dev - - devon4j - - dev-SNAPSHOT - - - - devon4j-templates - - pom - - ${project.artifactId} - - Templates (maven archetypes) of devon4j. - - + - - server - - - + \ No newline at end of file diff --git a/templates/server/flywayy/pom.xml b/templates/server/flywayy/pom.xml deleted file mode 100644 index 2d9b9ad3..00000000 --- a/templates/server/flywayy/pom.xml +++ /dev/null @@ -1,491 +0,0 @@ - - - 4.0.0 - flywayy - com.flywayy - ${app.version} - pom - ${project.artifactId} - Application based on the devon4j. - - - 2.4.4 - 2021.04.001-SNAPSHOT - 1.8 - 5.7.1 - UTF-8 - UTF-8 - 2.12.2 - 30.1.1-jre - system - ${revision} - - - - api - core - server - - - - - - - com.fasterxml.jackson - jackson-bom - ${jackson.version} - pom - import - - - - org.junit - junit-bom - ${junit.version} - pom - import - - - - com.google.guava - guava - ${guava.version} - - - - org.springframework.boot - spring-boot-dependencies - ${spring.boot.version} - pom - import - - - - com.devonfw.java.boms - devon4j-bom - ${devon4j.version} - pom - import - - - - - - - org.slf4j - slf4j-api - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - ${project.build.sourceEncoding} - ${java.version} - ${java.version} - - - - - maven-surefire-plugin - - ${devonfw.test.excluded.groups} - true - - - - - - org.jacoco - jacoco-maven-plugin - - - default-prepare-agent - - prepare-agent - - - - default-report - - report - - - - - - - - - org.apache.maven.plugins - maven-resources-plugin - 3.1.0 - - - org.apache.maven.plugins - maven-compiler-plugin - 3.8.1 - - - org.apache.maven.plugins - maven-install-plugin - 2.5.2 - - - org.apache.maven.plugins - maven-deploy-plugin - 2.8.2 - - - org.apache.maven.plugins - maven-clean-plugin - 3.1.0 - - - org.apache.maven.plugins - maven-jar-plugin - 3.1.2 - - - org.apache.maven.plugins - maven-source-plugin - 3.1.0 - - - org.apache.maven.plugins - maven-site-plugin - 3.7.1 - - - org.apache.maven.plugins - maven-checkstyle-plugin - 3.1.0 - - - org.apache.maven.plugins - maven-changes-plugin - 2.12.1 - - - org.apache.maven.plugins - maven-changelog-plugin - 2.3 - - - org.apache.maven.plugins - maven-project-info-reports-plugin - 3.0.0 - - - org.apache.maven.plugins - maven-jxr-plugin - 3.0.0 - - - org.apache.maven.plugins - maven-javadoc-plugin - 3.1.1 - - - - true - protected - ${project.reporting.outputEncoding} - ${project.build.sourceEncoding} - true - ${user.dir}/src/main/javadoc/stylesheet.css - none - ${java.version} - JavaDocs for ${project.name} ${project.version} - JavaDocs for ${project.name} ${project.version} - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.22.2 - - - ${basedir} - - - - org.apache.maven.plugins - maven-surefire-report-plugin - 2.22.2 - - - org.apache.maven.plugins - maven-pmd-plugin - 3.9.0 - - ${java.version} - - - - org.apache.maven.plugins - maven-war-plugin - 3.2.3 - - - org.apache.maven.plugins - maven-antrun-plugin - 1.8 - - - org.apache.maven.plugins - maven-help-plugin - 3.2.0 - - - org.apache.maven.plugins - maven-gpg-plugin - 1.6 - - - org.apache.maven.plugins - maven-archetype-plugin - 3.1.2 - - - org.apache.maven.archetype - archetype-packaging - 3.1.2 - - - org.codehaus.mojo - taglist-maven-plugin - 2.4 - - - org.codehaus.mojo - cobertura-maven-plugin - 2.7 - - - org.codehaus.mojo - flatten-maven-plugin - 1.2.2 - - - org.codehaus.mojo - license-maven-plugin - 1.20 - - ${project.build.directory}/generated-resources - true - true - true - true - - Apache Software License, Version 2.0|The Apache Software License, Version 2.0|Apache - 2.0|Apache License, Version 2.0 - - - - - org.codehaus.mojo - servicedocgen-maven-plugin - 1.0.0-beta-3 - - - org.sonarsource.scanner.maven - sonar-maven-plugin - 3.7.0.1746 - - - org.jacoco - jacoco-maven-plugin - 0.8.5 - - - org.owasp - dependency-check-maven - 5.3.2 - - - com.github.spotbugs - spotbugs-maven-plugin - 3.1.12.2 - - - org.springframework.boot - spring-boot-maven-plugin - ${spring.boot.version} - - - - - - - - moduletest - - component,subsystem,system - - - - componenttest - - subsystem,system - - - - subsystemtest - - system - - - - systemtest - - none - - - - security - - - - org.owasp - dependency-check-maven - - 8 - - - - - check - - - - - - - - - licenses - - - - org.codehaus.mojo - license-maven-plugin - - - aggregate-add-third-party - generate-resources - - aggregate-add-third-party - - - - - aggregate-download-licenses - generate-resources - - aggregate-download-licenses - - - - - - - - - - eclipse - - - eclipse.application - - - - eclipse-target - - - - - - - - org.apache.maven.plugins - maven-project-info-reports-plugin - - false - - - - org.apache.maven.plugins - maven-jxr-plugin - - - org.apache.maven.plugins - maven-javadoc-plugin - - - org.codehaus.mojo - taglist-maven-plugin - - - TODO - @todo - FIXME - @deprecated - REVIEW - - - - - org.owasp - dependency-check-maven - - false - - - - - aggregate - check - - - - - - org.codehaus.mojo - servicedocgen-maven-plugin - - - - ${servicedoc.info.title} - ${servicedoc.info.description} - - ${servicedoc.host} - ${servicedoc.port} - ${servicedoc.basePath} - - http - - - - - - org.codehaus.mojo - license-maven-plugin - - - - third-party-report - aggregate-third-party-report - - - - - - - - diff --git a/templates/server/src/main/resources/archetype-resources/__batch__/src/test/java/__packageInPathFormat__/general/batch/base/test/SpringBatchIntegrationTest .java b/templates/server/src/main/resources/archetype-resources/__batch__/src/test/java/__packageInPathFormat__/general/batch/base/test/SpringBatchIntegrationTest .java new file mode 100644 index 00000000..94842e72 --- /dev/null +++ b/templates/server/src/main/resources/archetype-resources/__batch__/src/test/java/__packageInPathFormat__/general/batch/base/test/SpringBatchIntegrationTest .java @@ -0,0 +1,73 @@ +package ${package}.general.batch.base.test; + +import javax.inject.Inject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.batch.core.Job; +import org.springframework.batch.core.launch.JobLauncher; +import org.springframework.batch.test.JobLauncherTestUtils; +import ${package}.general.common.base.test.TestUtil; +import com.devonfw.module.test.common.base.ComponentTest; +#if ($dbMigration == 'liquibase') + import liquibase.Liquibase; +#else + import org.flywaydb.core.Flyway; +#end + +/** + * Base class for all spring batch integration tests. It helps to do End-to-End job tests. + */ +public abstract class SpringBatchIntegrationTest extends ComponentTest { + + @Inject + private JobLauncher jobLauncher; + + #if ($dbMigration == 'liquibase') + @Inject + private Liquibase liquibase; + #else + @Inject + private Flyway flyway; + #end + + #if ($dbMigration == 'liquibase') + @Override + protected void doSetUp() { + super.doSetUp(); + try { + this.liquibase.dropAll(); + } catch (Exception e) { + e.printStackTrace(); + } + } + #else + @Override + protected void doSetUp() { + + super.doSetUp(); + this.flyway.clean(); + this.flyway.migrate(); + } + #end + + + @Override + protected void doTearDown() { + + super.doTearDown(); + TestUtil.logout(); + } + + /** + * @param job job to configure + * @return jobLauncherTestUtils + */ + public JobLauncherTestUtils getJobLauncherTestUtils(Job job) { + + JobLauncherTestUtils jobLauncherTestUtils = new JobLauncherTestUtils(); + jobLauncherTestUtils.setJob(job); + jobLauncherTestUtils.setJobLauncher(this.jobLauncher); + + return jobLauncherTestUtils; + } +} \ No newline at end of file diff --git a/templates/server/src/main/resources/archetype-resources/core/src/main/resources/application.properties b/templates/server/src/main/resources/archetype-resources/core/src/main/resources/application.properties index bc0a35ee..e27bc1f9 100644 --- a/templates/server/src/main/resources/archetype-resources/core/src/main/resources/application.properties +++ b/templates/server/src/main/resources/archetype-resources/core/src/main/resources/application.properties @@ -69,8 +69,6 @@ spring.jpa.open-in-view=false # see http://stackoverflow.com/questions/22318907/how-to-stop-spring-batch-scheduled-jobs-from-running-at-first-time-when-executin spring.batch.job.enabled=false - - # Configuration for Database Setup and Migrations #if ($dbMigration == 'flyway') spring.flyway.locations=classpath:db/migration diff --git a/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/base/test/DbTestHelper.java b/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/base/test/DbTestHelper.java index 3e0dca55..02dc1359 100644 --- a/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/base/test/DbTestHelper.java +++ b/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/base/test/DbTestHelper.java @@ -41,17 +41,6 @@ public DbTestHelper( Flyway flyway) { } #end - -// public DbTestHelper(#if ($dbMigration == 'liquibase') Liquibase liquibase #else Flyway flyway #end) { -// super(); -// #if ($dbMigration == 'liquibase') -// this.liquibase = liquibase; -// #else -// this.flyway = flyway; -// #end -// } - - #if ($dbMigration == 'flyway') /** * Calls {@link #dropDatabase()} internally, and migrates to the highest available migration (default) or to the diff --git a/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/impl/config/TestWebSecurityConfig.java b/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/impl/config/TestWebSecurityConfig.java index 1438572a..652ab5dc 100644 --- a/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/impl/config/TestWebSecurityConfig.java +++ b/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/impl/config/TestWebSecurityConfig.java @@ -23,7 +23,6 @@ @Profile(SpringProfileConstants.JUNIT) public class TestWebSecurityConfig extends BaseWebSecurityConfig { private static Logger LOG = LoggerFactory.getLogger(TestWebSecurityConfig.class); - /** * Configure spring security to enable a simple webform-login + a simple rest login. diff --git a/templates/server/src/main/resources/archetype-resources/core/src/test/resources/config/application.properties b/templates/server/src/main/resources/archetype-resources/core/src/test/resources/config/application.properties index edd6b742..6ba36f33 100644 --- a/templates/server/src/main/resources/archetype-resources/core/src/test/resources/config/application.properties +++ b/templates/server/src/main/resources/archetype-resources/core/src/test/resources/config/application.properties @@ -8,9 +8,7 @@ spring.datasource.password= spring.datasource.username=sa spring.jpa.hibernate.ddl-auto=none - # Configuration for Database Setup and Migrations - #if ($dbMigration == 'flyway') spring.flyway.enabled=true #if ($dbType == 'h2') diff --git a/templates/server/src/main/resources/archetype-resources/pom.xml b/templates/server/src/main/resources/archetype-resources/pom.xml index bb926b77..adadb7f7 100644 --- a/templates/server/src/main/resources/archetype-resources/pom.xml +++ b/templates/server/src/main/resources/archetype-resources/pom.xml @@ -74,7 +74,7 @@ pom import - + @@ -101,7 +101,6 @@ maven-surefire-plugin ${devonfw.test.excluded.groups} - true From 9a4b7a1afc054a580d035e9ddbed926f286728c8 Mon Sep 17 00:00:00 2001 From: dixyushi Date: Thu, 20 May 2021 19:29:52 +0530 Subject: [PATCH 26/43] fixed the existing error of SpringBatchIntegrationTes file --- pom.xml | 345 +++++++++++++++--- .../test/SpringBatchIntegrationTest .java | 73 ---- .../common/base/test/DbTestHelper.java | 83 ++--- 3 files changed, 316 insertions(+), 185 deletions(-) delete mode 100644 templates/server/src/main/resources/archetype-resources/__batch__/src/test/java/__packageInPathFormat__/general/batch/base/test/SpringBatchIntegrationTest .java diff --git a/pom.xml b/pom.xml index 5f73d94b..955551b7 100644 --- a/pom.xml +++ b/pom.xml @@ -1,51 +1,228 @@ - + + + + + 4.0.0 + + + + + + + + com.devonfw + + + + maven-parent - 6 + + + + + 6 + + + + + + + + + com.devonfw.java.dev - devon4j + + + + + devon4j + + + + dev-SNAPSHOT + + + + -pom + + + + + pom + + + + ${project.artifactId} -Java stack of devonfw.com (devon4j): develop Java apps standardized, faster and with less risk. - 2014 + + + + + Java stack of devonfw.com (devon4j): develop Java apps standardized, faster and with less risk. + + + + + 2014 + + + + -boms - modules - starters -templates -documentation + + + + + boms + + + + + modules + + + + + starters + + + + + templates + + + + + documentation + + + + - - dev-SNAPSHOT - devon4j - ${revision} -2.4.4 - -2020.0.0 -2.12.2 - - 30.1.1-jre - 5.7.1 -3.4.3 - 8.7.0 -1.7.30 -https://sonarcloud.io - devonfw - - - - - -org.apache.maven.plugins - + + + + + + + + + + dev-SNAPSHOT + + + + + devon4j + + + + + ${revision} + + + + + 2.4.4 + + + + + + + + + + 2020.0.0 + + + + + 2.12.2 + + + + + + + + + + 30.1.1-jre + + + + + 5.7.1 + + + + + 3.4.3 + + + + + 8.7.0 + + + + + 1.7.30 + + + + + https://sonarcloud.io + + + + + devonfw + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + org.apache.maven.plugins + + + + + @@ -60,7 +237,11 @@ maven-war-plugin - + + + + + @@ -75,7 +256,11 @@ - + + + + + @@ -90,7 +275,11 @@ WEB-INF/classes/config/application.properties,*.jsp - + + + + + @@ -105,7 +294,11 @@ ${project.artifactId} - + + + + + @@ -120,7 +313,11 @@ - + + + + + @@ -135,7 +332,11 @@ - + + + + + @@ -150,7 +351,11 @@ - + + + + + @@ -165,7 +370,11 @@ - + + + + + @@ -180,7 +389,11 @@ - + + + + + @@ -195,7 +408,11 @@ - + + + + + @@ -210,7 +427,11 @@ org.springframework.boot - + + + + + @@ -225,7 +446,11 @@ spring-boot-maven-plugin - + + + + + @@ -240,8 +465,28 @@ ${spring.boot.version} - - - - + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/templates/server/src/main/resources/archetype-resources/__batch__/src/test/java/__packageInPathFormat__/general/batch/base/test/SpringBatchIntegrationTest .java b/templates/server/src/main/resources/archetype-resources/__batch__/src/test/java/__packageInPathFormat__/general/batch/base/test/SpringBatchIntegrationTest .java deleted file mode 100644 index 94842e72..00000000 --- a/templates/server/src/main/resources/archetype-resources/__batch__/src/test/java/__packageInPathFormat__/general/batch/base/test/SpringBatchIntegrationTest .java +++ /dev/null @@ -1,73 +0,0 @@ -package ${package}.general.batch.base.test; - -import javax.inject.Inject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.batch.core.Job; -import org.springframework.batch.core.launch.JobLauncher; -import org.springframework.batch.test.JobLauncherTestUtils; -import ${package}.general.common.base.test.TestUtil; -import com.devonfw.module.test.common.base.ComponentTest; -#if ($dbMigration == 'liquibase') - import liquibase.Liquibase; -#else - import org.flywaydb.core.Flyway; -#end - -/** - * Base class for all spring batch integration tests. It helps to do End-to-End job tests. - */ -public abstract class SpringBatchIntegrationTest extends ComponentTest { - - @Inject - private JobLauncher jobLauncher; - - #if ($dbMigration == 'liquibase') - @Inject - private Liquibase liquibase; - #else - @Inject - private Flyway flyway; - #end - - #if ($dbMigration == 'liquibase') - @Override - protected void doSetUp() { - super.doSetUp(); - try { - this.liquibase.dropAll(); - } catch (Exception e) { - e.printStackTrace(); - } - } - #else - @Override - protected void doSetUp() { - - super.doSetUp(); - this.flyway.clean(); - this.flyway.migrate(); - } - #end - - - @Override - protected void doTearDown() { - - super.doTearDown(); - TestUtil.logout(); - } - - /** - * @param job job to configure - * @return jobLauncherTestUtils - */ - public JobLauncherTestUtils getJobLauncherTestUtils(Job job) { - - JobLauncherTestUtils jobLauncherTestUtils = new JobLauncherTestUtils(); - jobLauncherTestUtils.setJob(job); - jobLauncherTestUtils.setJobLauncher(this.jobLauncher); - - return jobLauncherTestUtils; - } -} \ No newline at end of file diff --git a/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/base/test/DbTestHelper.java b/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/base/test/DbTestHelper.java index 02dc1359..0106535a 100644 --- a/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/base/test/DbTestHelper.java +++ b/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/base/test/DbTestHelper.java @@ -1,77 +1,36 @@ package ${package}.general.common.base.test; -import javax.inject.Inject; import javax.inject.Named; -#if ($dbMigration == 'liquibase') - import liquibase.Liquibase; -#else -import org.flywaydb.core.Flyway; -#end +import com.devonfw.module.test.common.base.clean.TestCleanerPlugin; +import com.devonfw.module.test.common.base.clean.TestCleanerPluginLiquibase; +import com.devonfw.module.test.common.base.clean.TestCleanerPluginFlyway; /** * This class provides methods for handling the database during testing where resets (and other operations) may be * necessary. */ @Named -public class DbTestHelper { - #if ($dbMigration == 'liquibase') - private Liquibase liquibase; - #else - private Flyway flyway; - #end - - #if ($dbMigration == 'liquibase') - /** - * The constructor. - * - * @param liquibase an instance of type {@link Liquibase}. - */ - public DbTestHelper( Liquibase liquibase) { - super(); - this.liquibase = liquibase; - } - #else - /** - * The constructor. - * - * @param flyway an instance of type {@link Flyway}. - */ - public DbTestHelper( Flyway flyway) { - super(); - this.flyway = flyway; - } - #end - - #if ($dbMigration == 'flyway') - /** - * Calls {@link #dropDatabase()} internally, and migrates to the highest available migration (default) or to the - * {@code migrationVersion} specified by {@link #setMigrationVersion(String)}. - */ - public void resetDatabase() { - - this.flyway.migrate(); +public class DbTestHelper{ + + + private TestCleanerPlugin testCleanerPlugin; + + public DbTestHelper(TestCleanerPlugin testCleanerPlugin) { + + super(); + this.testCleanerPlugin = testCleanerPlugin; } - #end -#if ($dbMigration == 'liquibase') /** * Drops the whole database. */ - public void cleanup() { - - try { - this.liquibase.dropAll(); - } catch (Exception e) { - e.printStackTrace(); - } - - } - #else - /** - * Drops the whole database. - */ - public void dropDatabase() { - this.flyway.clean(); - } + public void dropDatabase() { +#if($dbMigration == 'liquibase') + testCleanerPlugin = new TestCleanerPluginLiquibase(); +#end +#if($dbMigration == 'flyway') + testCleanerPlugin = new TestCleanerPluginFlyway(); #end + testCleanerPlugin.cleanup(); + } -} +} \ No newline at end of file From c17e4f3bec940fbe332060c82f8ae514e4853a31 Mon Sep 17 00:00:00 2001 From: dixyushi <72491437+dixyushi@users.noreply.github.com> Date: Thu, 20 May 2021 19:26:54 +0530 Subject: [PATCH 27/43] Update pom.xml --- pom.xml | 447 ++------------------------------------------------------ 1 file changed, 11 insertions(+), 436 deletions(-) diff --git a/pom.xml b/pom.xml index 955551b7..75031fcf 100644 --- a/pom.xml +++ b/pom.xml @@ -1,492 +1,67 @@ - - - - - - - - + + 4.0.0 - - - - - - - - com.devonfw - - - - maven-parent - - - - 6 - - - - - - - - - com.devonfw.java.dev - - - - devon4j - - - - - dev-SNAPSHOT - - - - - - - - - + dev-SNAPSHOT pom - - - - ${project.artifactId} - - - - Java stack of devonfw.com (devon4j): develop Java apps standardized, faster and with less risk. - - - - 2014 - - - - + - - - - boms - - - - modules - - - - starters - - - - templates - - - - documentation - - - - - - - - + - - - - dev-SNAPSHOT - - - - devon4j - - - - ${revision} - - - - 2.4.4 - - - - - - - - 2020.0.0 - - - - - 2.12.2 - - - - - - - - - + 2.12.2 30.1.1-jre - - - - 5.7.1 - - - - 3.4.3 - - - - 8.7.0 - - - - 1.7.30 - - - - https://sonarcloud.io - - - - devonfw - - - - - - - - + - - - - - - - - + - - - - - - - - org.apache.maven.plugins - - - - - - - - - - - - - - - - - - maven-war-plugin - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - WEB-INF/classes/config/application.properties,*.jsp - - - - - - - - - - - - - - - - - - ${project.artifactId} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - org.springframework.boot - - - - - - - - - - - - - - - - - - spring-boot-maven-plugin - - - - - - - - - - - - - - - - - - ${spring.boot.version} - - - - - - - - - - - - - - - - - - - - - + \ No newline at end of file From 89c23b860cbd07df7229d2e908a7107d38c83efd Mon Sep 17 00:00:00 2001 From: dixyushi <72491437+dixyushi@users.noreply.github.com> Date: Fri, 21 May 2021 17:58:12 +0530 Subject: [PATCH 28/43] Update TestWebSecurityConfig.java --- .../general/common/impl/config/TestWebSecurityConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/impl/config/TestWebSecurityConfig.java b/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/impl/config/TestWebSecurityConfig.java index 652ab5dc..927c50e0 100644 --- a/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/impl/config/TestWebSecurityConfig.java +++ b/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/impl/config/TestWebSecurityConfig.java @@ -23,7 +23,7 @@ @Profile(SpringProfileConstants.JUNIT) public class TestWebSecurityConfig extends BaseWebSecurityConfig { private static Logger LOG = LoggerFactory.getLogger(TestWebSecurityConfig.class); - + /** * Configure spring security to enable a simple webform-login + a simple rest login. */ From 4042d7ac9469ac2c51beb34f4afc19d86670a56e Mon Sep 17 00:00:00 2001 From: dixyushi Date: Mon, 24 May 2021 11:20:36 +0530 Subject: [PATCH 29/43] fixed review comments --- .../test/common/base/clean/TestCleanerPluginLiquibase.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginLiquibase.java b/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginLiquibase.java index c9104da4..8244ffa4 100644 --- a/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginLiquibase.java +++ b/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginLiquibase.java @@ -1,11 +1,14 @@ package com.devonfw.module.test.common.base.clean; import javax.inject.Inject; + +import org.flywaydb.core.Flyway; + import liquibase.Liquibase; /** - * @author ayudixit - * + * Implementation of {@link TestCleanerPlugin} base on {@link Liquibase}. It will {@link Liquibase#dropAll() clean} + * on {@link #cleanup()}. Therefore after {@link #cleanup()} it will drop all database objects. */ public class TestCleanerPluginLiquibase implements TestCleanerPlugin { From 246a4d78ecd8e467b38ed17b9c6f0986fe142939 Mon Sep 17 00:00:00 2001 From: dixyushi Date: Mon, 31 May 2021 14:18:08 +0530 Subject: [PATCH 30/43] Implemented review comments --- .../clean/TestCleanerPluginLiquibase.java | 26 ++++++++++++------- .../archetype-resources/__batch__/pom.xml | 6 +++++ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginLiquibase.java b/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginLiquibase.java index 8244ffa4..4ec83455 100644 --- a/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginLiquibase.java +++ b/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginLiquibase.java @@ -3,15 +3,22 @@ import javax.inject.Inject; import org.flywaydb.core.Flyway; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import liquibase.Liquibase; +import liquibase.exception.DatabaseException; /** - * Implementation of {@link TestCleanerPlugin} base on {@link Liquibase}. It will {@link Liquibase#dropAll() clean} - * on {@link #cleanup()}. Therefore after {@link #cleanup()} it will drop all database objects. + * Implementation of {@link TestCleanerPlugin} base on {@link Liquibase}. It will {@link Liquibase#dropAll() clean} on + * {@link #cleanup()}. Therefore after {@link #cleanup()} it will drop all database objects. */ public class TestCleanerPluginLiquibase implements TestCleanerPlugin { + + private static final Logger LOG = LoggerFactory.getLogger(TestCleanerPluginLiquibase.class); + @Inject private Liquibase liquibase; @@ -35,14 +42,13 @@ public TestCleanerPluginLiquibase(Liquibase liquibase) { } @Override - public void cleanup() { - - try { - this.liquibase.dropAll(); - } catch (Exception e) { - e.printStackTrace(); - } - + public void cleanup() { + try { + this.liquibase.dropAll(); + }catch(DatabaseException databaseException) { + LOG.error("Database exception occurred!", new DatabaseException()); + } + } } diff --git a/templates/server/src/main/resources/archetype-resources/__batch__/pom.xml b/templates/server/src/main/resources/archetype-resources/__batch__/pom.xml index bf27e0bb..9f460c63 100644 --- a/templates/server/src/main/resources/archetype-resources/__batch__/pom.xml +++ b/templates/server/src/main/resources/archetype-resources/__batch__/pom.xml @@ -36,6 +36,12 @@ devon4j-test test + + + com.devonfw.java.modules + devon4j-test-jpa + test + From 8bfb77ff7bc72263bd62e0bc31bb9baa4eeb4424 Mon Sep 17 00:00:00 2001 From: dixyushi Date: Wed, 2 Jun 2021 10:15:38 +0530 Subject: [PATCH 31/43] handled DatabaseException --- .../test/common/base/clean/TestCleanerPluginLiquibase.java | 3 +-- .../main/resources/META-INF/maven/archetype-metadata.xml | 1 + .../core/src/test/resources/config/application.properties | 2 +- .../src/test/resources/projects/basic/archetype.properties | 7 ++++++- .../src/test/resources/projects/batch/archetype.properties | 7 ++++++- .../resources/projects/enterprise/archetype.properties | 7 ++++++- 6 files changed, 21 insertions(+), 6 deletions(-) diff --git a/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginLiquibase.java b/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginLiquibase.java index 4ec83455..a444987e 100644 --- a/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginLiquibase.java +++ b/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginLiquibase.java @@ -2,7 +2,6 @@ import javax.inject.Inject; -import org.flywaydb.core.Flyway; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -46,7 +45,7 @@ public void cleanup() { try { this.liquibase.dropAll(); }catch(DatabaseException databaseException) { - LOG.error("Database exception occurred!", new DatabaseException()); + LOG.error("Database exception occurred!", databaseException); } } diff --git a/templates/server/src/main/resources/META-INF/maven/archetype-metadata.xml b/templates/server/src/main/resources/META-INF/maven/archetype-metadata.xml index 47874b1a..fe75a1da 100644 --- a/templates/server/src/main/resources/META-INF/maven/archetype-metadata.xml +++ b/templates/server/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -97,4 +97,5 @@ + \ No newline at end of file diff --git a/templates/server/src/main/resources/archetype-resources/core/src/test/resources/config/application.properties b/templates/server/src/main/resources/archetype-resources/core/src/test/resources/config/application.properties index 6ba36f33..9ffe674c 100644 --- a/templates/server/src/main/resources/archetype-resources/core/src/test/resources/config/application.properties +++ b/templates/server/src/main/resources/archetype-resources/core/src/test/resources/config/application.properties @@ -20,7 +20,7 @@ spring.flyway.locations=classpath:db/test #if ($dbMigration == 'liquibase') spring.liquibase.enabled=true #if ($dbType == 'h2') -spring.liquibase.locations=classpath:db/changelog/changelog-master.xml +spring.liquibase.locations=classpath:db/changelog/changelog-v1.0.xml #else spring.liquibase.locations=classpath:db/test #end diff --git a/templates/server/src/test/resources/projects/basic/archetype.properties b/templates/server/src/test/resources/projects/basic/archetype.properties index 5af903a8..f3631b2f 100644 --- a/templates/server/src/test/resources/projects/basic/archetype.properties +++ b/templates/server/src/test/resources/projects/basic/archetype.properties @@ -6,4 +6,9 @@ artifactId=basic earProjectName=. batch=. dbType=h2 -dbMigration=flyway \ No newline at end of file +#if($dbMigration == 'liquibase') +dbMigration=liquibase +#end +#if($dbMigration == 'flyway') +dbMigration=flyway +#end \ No newline at end of file diff --git a/templates/server/src/test/resources/projects/batch/archetype.properties b/templates/server/src/test/resources/projects/batch/archetype.properties index f30b83ec..8f10db0d 100644 --- a/templates/server/src/test/resources/projects/batch/archetype.properties +++ b/templates/server/src/test/resources/projects/batch/archetype.properties @@ -6,4 +6,9 @@ artifactId=app-with-batch earProjectName=. batch=batch dbType=mysql -dbMigration=flyway \ No newline at end of file +#if($dbMigration == 'liquibase') +dbMigration=liquibase +#end +#if($dbMigration == 'flyway') +dbMigration=flyway +#end \ No newline at end of file diff --git a/templates/server/src/test/resources/projects/enterprise/archetype.properties b/templates/server/src/test/resources/projects/enterprise/archetype.properties index 9a75406b..f551f6b7 100644 --- a/templates/server/src/test/resources/projects/enterprise/archetype.properties +++ b/templates/server/src/test/resources/projects/enterprise/archetype.properties @@ -6,4 +6,9 @@ artifactId=enterprise earProjectName=${artifactId}-ear batch=. dbType=postgresql -dbMigration=flyway \ No newline at end of file +#if($dbMigration == 'liquibase') +dbMigration=liquibase +#end +#if($dbMigration == 'flyway') +dbMigration=flyway +#end \ No newline at end of file From 679b9701625a1646804c6930ae7e6ce8dcc2c1f9 Mon Sep 17 00:00:00 2001 From: dixyushi <72491437+dixyushi@users.noreply.github.com> Date: Wed, 2 Jun 2021 14:22:10 +0530 Subject: [PATCH 32/43] removed commented code --- .../META-INF/maven/archetype-metadata.xml | 123 +++++++++--------- 1 file changed, 61 insertions(+), 62 deletions(-) diff --git a/templates/server/src/main/resources/META-INF/maven/archetype-metadata.xml b/templates/server/src/main/resources/META-INF/maven/archetype-metadata.xml index 1f4b9b4a..31747e5b 100644 --- a/templates/server/src/main/resources/META-INF/maven/archetype-metadata.xml +++ b/templates/server/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -15,65 +15,64 @@ flyway - - - - . - batch|[.] - - - - - api - - **/*.* - - - - core - - **/*.* - - - - - batch - - **/*.* - - - - - - .gitignore - - - - .mvn - - **/*.* - - - - - - - - src/main/java - - - src/main/resources - - - src/test/java - - - src/test/resources - - - src/main/webapp - - - - - \ No newline at end of file + + + . + batch|[.] + + + + + api + + **/*.* + + + + core + + **/*.* + + + + + batch + + **/*.* + + + + + + .gitignore + + + + .mvn + + **/*.* + + + + + + + + src/main/java + + + src/main/resources + + + src/test/java + + + src/test/resources + + + src/main/webapp + + + + + From f850517826c5100c26d82fed99401e72297d8ad2 Mon Sep 17 00:00:00 2001 From: dixyushi <72491437+dixyushi@users.noreply.github.com> Date: Wed, 2 Jun 2021 15:42:20 +0530 Subject: [PATCH 33/43] Cleared the formatting --- pom.xml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index 06bc932e..b6ba0484 100644 --- a/pom.xml +++ b/pom.xml @@ -2,19 +2,17 @@ 4.0.0 - com.devonfw maven-parent 6 - com.devonfw.java.dev devon4j dev-SNAPSHOT pom ${project.artifactId} - Java stack of devonfw.com (devon4j): develop Java apps standardized, faster and with less risk. + Java stack of devonfw.com (devon4j): develop Java apps standardized, faster and with less risk. 2014 @@ -24,15 +22,15 @@ templates documentation - + dev-SNAPSHOT devon4j ${revision} 2.4.4 - 2020.0.0 - 2.12.2 + 2020.0.0 + 2.12.2 30.1.1-jre 5.7.1 3.4.3 @@ -43,7 +41,8 @@ - + + org.apache.maven.plugins @@ -52,7 +51,8 @@ WEB-INF/classes/config/application.properties,*.jsp ${project.artifactId} - + + @@ -63,5 +63,5 @@ - - \ No newline at end of file + + From 6c39c5465d4881eec964f78701db1fea817faed5 Mon Sep 17 00:00:00 2001 From: dixyushi <72491437+dixyushi@users.noreply.github.com> Date: Wed, 2 Jun 2021 15:44:21 +0530 Subject: [PATCH 34/43] Cleared the formatting --- templates/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/pom.xml b/templates/pom.xml index d3a57f1e..4322b9e8 100644 --- a/templates/pom.xml +++ b/templates/pom.xml @@ -16,4 +16,4 @@ server - \ No newline at end of file + From 3d50fe38c34cb9721d4ef51c696aac3d24c085f4 Mon Sep 17 00:00:00 2001 From: dixyushi Date: Wed, 2 Jun 2021 15:51:54 +0530 Subject: [PATCH 35/43] removed EAR as a key and cleared the formatting --- pom.xml | 20 +++++++++---------- templates/pom.xml | 2 +- .../META-INF/maven/archetype-metadata.xml | 3 --- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/pom.xml b/pom.xml index 06bc932e..b6ba0484 100644 --- a/pom.xml +++ b/pom.xml @@ -2,19 +2,17 @@ 4.0.0 - com.devonfw maven-parent 6 - com.devonfw.java.dev devon4j dev-SNAPSHOT pom ${project.artifactId} - Java stack of devonfw.com (devon4j): develop Java apps standardized, faster and with less risk. + Java stack of devonfw.com (devon4j): develop Java apps standardized, faster and with less risk. 2014 @@ -24,15 +22,15 @@ templates documentation - + dev-SNAPSHOT devon4j ${revision} 2.4.4 - 2020.0.0 - 2.12.2 + 2020.0.0 + 2.12.2 30.1.1-jre 5.7.1 3.4.3 @@ -43,7 +41,8 @@ - + + org.apache.maven.plugins @@ -52,7 +51,8 @@ WEB-INF/classes/config/application.properties,*.jsp ${project.artifactId} - + + @@ -63,5 +63,5 @@ - - \ No newline at end of file + + diff --git a/templates/pom.xml b/templates/pom.xml index d3a57f1e..4322b9e8 100644 --- a/templates/pom.xml +++ b/templates/pom.xml @@ -16,4 +16,4 @@ server - \ No newline at end of file + diff --git a/templates/server/src/main/resources/META-INF/maven/archetype-metadata.xml b/templates/server/src/main/resources/META-INF/maven/archetype-metadata.xml index 1f4b9b4a..6fcd0018 100644 --- a/templates/server/src/main/resources/META-INF/maven/archetype-metadata.xml +++ b/templates/server/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -6,9 +6,6 @@ devon4j-template-server - - . - h2 From 4540198255dbb468d16399f0b2c059542336945a Mon Sep 17 00:00:00 2001 From: dixyushi Date: Thu, 3 Jun 2021 13:17:19 +0530 Subject: [PATCH 36/43] modified Groovy scripts --- .../META-INF/archetype-post-generate.groovy | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/templates/server/src/main/resources/META-INF/archetype-post-generate.groovy b/templates/server/src/main/resources/META-INF/archetype-post-generate.groovy index a6f2bfde..f765aed2 100644 --- a/templates/server/src/main/resources/META-INF/archetype-post-generate.groovy +++ b/templates/server/src/main/resources/META-INF/archetype-post-generate.groovy @@ -14,18 +14,26 @@ String batch = properties.get("batch") // dbMigration is either flyway or liquibase String dbMigration = properties.get("dbMigration") +println "*****************************Hello Groovy**************************************" if (dbMigration == "flyway") { - // delete the changelog folder as it is not required for flyway - Files.deleteIfExists projectPath.resolve("src/main/resources/db/changelog/changelog-master.xml") - Files.deleteIfExists projectPath.resolve("src/main/resources/db/changelog/changelog-v1.0.xml") - Files.deleteIfExists projectPath.resolve("src/test/resources/db/changelog/changelog-master.xml") - Files.deleteIfExists projectPath.resolve("src/test/resources/db/changelog/changelog-v1.0.xml") + println "*****************************Hello Groovy inside flyway**************************************" +//delete changelog and testchangelog folder which is not required for flyway + Path rootPath = projectPath.resolve("core/src/main/resources/db/changelog") + deleteDirectoryRecursion(rootPath) + + Path rootPathtest = projectPath.resolve("core/src/test/resources/db/changelog") + deleteDirectoryRecursion(rootPathtest) } else if(dbMigration == "liquibase") { - // delete the changelog folder as it is not required for flyway - Files.deleteIfExists projectPath.resolve("src/main/resources/db/migration/1.0/V0001_Create_Sequence.sql") - Files.deleteIfExists projectPath.resolve("src/main/resources/db/test/V0001_InitDb.sql") +println "*****************************Hello Groovy inside liquibase**************************************" +//delete migration and test folder which is not required for liquibase + Path rootPath = projectPath.resolve("core/src/main/resources/db/migration") + deleteDirectoryRecursion(rootPath) + + Path rootPathtest = projectPath.resolve("core/src/test/resources/db/test") + deleteDirectoryRecursion(rootPathtest) + } if (batch != "batch") { From b29c704082296d5fb4301d86e2ebf76b0b30bc01 Mon Sep 17 00:00:00 2001 From: dixyushi Date: Fri, 4 Jun 2021 11:42:32 +0530 Subject: [PATCH 37/43] removed commented code from Groovy --- .../main/resources/META-INF/archetype-post-generate.groovy | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/templates/server/src/main/resources/META-INF/archetype-post-generate.groovy b/templates/server/src/main/resources/META-INF/archetype-post-generate.groovy index f765aed2..e6313e5a 100644 --- a/templates/server/src/main/resources/META-INF/archetype-post-generate.groovy +++ b/templates/server/src/main/resources/META-INF/archetype-post-generate.groovy @@ -13,11 +13,9 @@ String batch = properties.get("batch") // dbMigration is either flyway or liquibase String dbMigration = properties.get("dbMigration") - -println "*****************************Hello Groovy**************************************" + if (dbMigration == "flyway") { - println "*****************************Hello Groovy inside flyway**************************************" //delete changelog and testchangelog folder which is not required for flyway Path rootPath = projectPath.resolve("core/src/main/resources/db/changelog") deleteDirectoryRecursion(rootPath) @@ -26,7 +24,6 @@ if (dbMigration == "flyway") { deleteDirectoryRecursion(rootPathtest) } else if(dbMigration == "liquibase") { -println "*****************************Hello Groovy inside liquibase**************************************" //delete migration and test folder which is not required for liquibase Path rootPath = projectPath.resolve("core/src/main/resources/db/migration") deleteDirectoryRecursion(rootPath) From dc5407386824ffb41af7a31ce6df24bf3400170f Mon Sep 17 00:00:00 2001 From: dixyushi <72491437+dixyushi@users.noreply.github.com> Date: Fri, 4 Jun 2021 13:44:30 +0530 Subject: [PATCH 38/43] rearranged as per review comment --- .../META-INF/archetype-post-generate.groovy | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/templates/server/src/main/resources/META-INF/archetype-post-generate.groovy b/templates/server/src/main/resources/META-INF/archetype-post-generate.groovy index e6313e5a..45d776a6 100644 --- a/templates/server/src/main/resources/META-INF/archetype-post-generate.groovy +++ b/templates/server/src/main/resources/META-INF/archetype-post-generate.groovy @@ -1,20 +1,26 @@ import java.nio.file.Files import java.nio.file.Path import java.nio.file.Paths -import java.nio.file.LinkOption +import java.nio.file.LinkOption // the path where the project got generated Path projectPath = Paths.get(request.outputDirectory, request.artifactId) // the properties available to the archetype -Properties properties = request.properties +Properties properties = request.properties -String batch = properties.get("batch") +String batch = properties.get("batch") -// dbMigration is either flyway or liquibase +if (batch != "batch") { + // delete folder batch recursively + Path rootPath = projectPath.resolve("batch") + deleteDirectoryRecursion(rootPath) +} + +//dbMigration is either flyway or liquibase String dbMigration = properties.get("dbMigration") - + if (dbMigration == "flyway") { //delete changelog and testchangelog folder which is not required for flyway Path rootPath = projectPath.resolve("core/src/main/resources/db/changelog") @@ -31,23 +37,17 @@ if (dbMigration == "flyway") { Path rootPathtest = projectPath.resolve("core/src/test/resources/db/test") deleteDirectoryRecursion(rootPathtest) -} - -if (batch != "batch") { - // delete folder batch recursively - Path rootPath = projectPath.resolve("batch") - deleteDirectoryRecursion(rootPath) -} - -void deleteDirectoryRecursion(Path path) { - if (Files.isDirectory(path, LinkOption.NOFOLLOW_LINKS)) { - try { - for (Path entry : Files.newDirectoryStream(path)) { - deleteDirectoryRecursion(entry); - } - } catch(IOException e) { - e.printStackTrace() - } - } - Files.delete(path); -} \ No newline at end of file +} + +void deleteDirectoryRecursion(Path path) { + if (Files.isDirectory(path, LinkOption.NOFOLLOW_LINKS)) { + try { + for (Path entry : Files.newDirectoryStream(path)) { + deleteDirectoryRecursion(entry); + } + } catch(IOException e) { + e.printStackTrace() + } + } + Files.delete(path); +} From dabd4c8125001ca1da0d092cac502624834ccb50 Mon Sep 17 00:00:00 2001 From: dixyushi Date: Mon, 7 Jun 2021 18:19:11 +0530 Subject: [PATCH 39/43] after rethrowing the error-fixed error handling --- .../com/devonfw/module/test/common/base/DbTest.java | 12 ++++++++++-- .../test/common/base/clean/AbstractTestCleaner.java | 2 +- .../test/common/base/clean/TestCleanerImpl.java | 2 +- .../common/base/clean/TestCleanerPluginFlyway.java | 2 +- .../base/clean/TestCleanerPluginLiquibase.java | 13 ++----------- .../common/base/clean/TestCleanerPluginNone.java | 2 +- .../batch/base/test/SpringBatchIntegrationTest.java | 12 +++++++++++- .../general/common/base/test/DbTestHelper.java | 2 +- 8 files changed, 28 insertions(+), 19 deletions(-) diff --git a/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/DbTest.java b/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/DbTest.java index a71dd931..32569981 100644 --- a/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/DbTest.java +++ b/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/DbTest.java @@ -4,7 +4,9 @@ import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; -import com.devonfw.module.test.common.base.BaseTest; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import com.devonfw.module.test.common.base.clean.TestCleaner; /** @@ -18,6 +20,8 @@ */ public abstract class DbTest extends BaseTest { + private static final Logger LOG = LoggerFactory.getLogger(DbTest.class); + @PersistenceContext private EntityManager entityManager; @@ -33,7 +37,11 @@ protected void doSetUp() { } if (isPerformCleanup()) { if (isAllowMultiCleanup() || isInitialSetup()) { - this.testUtility.cleanup(); + try { + this.testUtility.cleanup(); + } catch (Exception exception) { + LOG.error("Exception occurred while performing cleanup", exception); + } } } } diff --git a/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/AbstractTestCleaner.java b/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/AbstractTestCleaner.java index 4e2eba8d..fbe60fa6 100644 --- a/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/AbstractTestCleaner.java +++ b/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/AbstractTestCleaner.java @@ -9,6 +9,6 @@ public abstract interface AbstractTestCleaner { * Performs a cleanup of contextual data. E.g. it may rest the database so according side-effects from previous tests * are eliminated. */ - void cleanup(); + void cleanup() throws Exception; } diff --git a/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerImpl.java b/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerImpl.java index d36717ae..1977f66b 100644 --- a/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerImpl.java +++ b/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerImpl.java @@ -21,7 +21,7 @@ public void setPlugins(List plugins) { } @Override - public void cleanup() { + public void cleanup() throws Exception { for (TestCleanerPlugin plugin : this.plugins) { plugin.cleanup(); diff --git a/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginFlyway.java b/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginFlyway.java index 909fb263..d8d7e9d1 100644 --- a/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginFlyway.java +++ b/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginFlyway.java @@ -34,7 +34,7 @@ public TestCleanerPluginFlyway(Flyway flyway) { } @Override - public void cleanup() { + public void cleanup() throws Exception { this.flyway.clean(); this.flyway.migrate(); diff --git a/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginLiquibase.java b/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginLiquibase.java index a444987e..4c9aad04 100644 --- a/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginLiquibase.java +++ b/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginLiquibase.java @@ -5,7 +5,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; - import liquibase.Liquibase; import liquibase.exception.DatabaseException; @@ -14,10 +13,7 @@ * {@link #cleanup()}. Therefore after {@link #cleanup()} it will drop all database objects. */ public class TestCleanerPluginLiquibase implements TestCleanerPlugin { - - private static final Logger LOG = LoggerFactory.getLogger(TestCleanerPluginLiquibase.class); - @Inject private Liquibase liquibase; @@ -41,13 +37,8 @@ public TestCleanerPluginLiquibase(Liquibase liquibase) { } @Override - public void cleanup() { - try { - this.liquibase.dropAll(); - }catch(DatabaseException databaseException) { - LOG.error("Database exception occurred!", databaseException); - } - + public void cleanup() throws Exception { + this.liquibase.dropAll(); } } diff --git a/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginNone.java b/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginNone.java index 1df70541..e8458b4e 100644 --- a/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginNone.java +++ b/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginNone.java @@ -8,7 +8,7 @@ public class TestCleanerPluginNone implements TestCleanerPlugin { @Override - public void cleanup() { + public void cleanup() throws Exception { // do nothing by design } diff --git a/templates/server/src/main/resources/archetype-resources/batch/src/test/java/__packageInPathFormat__/general/batch/base/test/SpringBatchIntegrationTest.java b/templates/server/src/main/resources/archetype-resources/batch/src/test/java/__packageInPathFormat__/general/batch/base/test/SpringBatchIntegrationTest.java index bf7d95a8..00e9df47 100644 --- a/templates/server/src/main/resources/archetype-resources/batch/src/test/java/__packageInPathFormat__/general/batch/base/test/SpringBatchIntegrationTest.java +++ b/templates/server/src/main/resources/archetype-resources/batch/src/test/java/__packageInPathFormat__/general/batch/base/test/SpringBatchIntegrationTest.java @@ -8,13 +8,17 @@ import org.springframework.batch.test.JobLauncherTestUtils; import ${package}.general.common.base.test.TestUtil; import com.devonfw.module.test.common.base.ComponentTest; +import com.devonfw.module.test.common.base.DbTest; import com.devonfw.module.test.common.base.clean.TestCleanerPlugin; import com.devonfw.module.test.common.base.clean.TestCleanerPluginFlyway; + /** * Base class for all spring batch integration tests. It helps to do End-to-End job tests. */ public abstract class SpringBatchIntegrationTest extends ComponentTest { + private static final Logger LOG = LoggerFactory.getLogger(SpringBatchIntegrationTest.class); + @Inject private JobLauncher jobLauncher; @@ -29,7 +33,13 @@ protected void doSetUp() { #else if($dbMigration == 'liquibase') testCleanerPlugin = new TestCleanerPluginLiquibase(); #end - testCleanerPlugin.cleanup(); +try { + testCleanerPlugin.cleanup(); +} +catch(Exception exception) { + LOG.error("Exception occurred while performing cleanup", exception); +} + } protected void doTearDown() { diff --git a/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/base/test/DbTestHelper.java b/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/base/test/DbTestHelper.java index 88151d55..ec7d3cbd 100644 --- a/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/base/test/DbTestHelper.java +++ b/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/base/test/DbTestHelper.java @@ -24,7 +24,7 @@ public DbTestHelper(TestCleanerPlugin testCleanerPlugin) { /** * Drops the whole database. */ - public void dropDatabase() { + public void dropDatabase() throws Exception { #if($dbMigration == 'liquibase') testCleanerPlugin = new TestCleanerPluginLiquibase(); #end From bab5a5fbab645fef3aa29fb6560e18d3a4c3df37 Mon Sep 17 00:00:00 2001 From: dixyushi Date: Tue, 8 Jun 2021 19:53:19 +0530 Subject: [PATCH 40/43] fixed runtime exception and Added proper injects --- .../module/test/common/base/DbTest.java | 11 +------- .../base/clean/AbstractTestCleaner.java | 2 +- .../common/base/clean/TestCleanerImpl.java | 2 +- .../base/clean/TestCleanerPluginFlyway.java | 4 ++- .../clean/TestCleanerPluginLiquibase.java | 13 ++++++---- .../base/clean/TestCleanerPluginNone.java | 2 +- .../META-INF/archetype-post-generate.groovy | 12 ++++----- .../base/test/SpringBatchIntegrationTest.java | 25 ++++++------------- .../common/base/test/DbTestHelper.java | 18 ++++++------- .../common/impl/config/TestDbConfig.java | 6 ----- .../{changelog => test}/changelog-master.xml | 0 .../db/{changelog => test}/changelog-v1.0.xml | 0 12 files changed, 37 insertions(+), 58 deletions(-) rename templates/server/src/main/resources/archetype-resources/core/src/test/resources/db/{changelog => test}/changelog-master.xml (100%) rename templates/server/src/main/resources/archetype-resources/core/src/test/resources/db/{changelog => test}/changelog-v1.0.xml (100%) diff --git a/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/DbTest.java b/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/DbTest.java index 32569981..67054fdf 100644 --- a/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/DbTest.java +++ b/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/DbTest.java @@ -4,9 +4,6 @@ import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.devonfw.module.test.common.base.clean.TestCleaner; /** @@ -20,8 +17,6 @@ */ public abstract class DbTest extends BaseTest { - private static final Logger LOG = LoggerFactory.getLogger(DbTest.class); - @PersistenceContext private EntityManager entityManager; @@ -37,11 +32,7 @@ protected void doSetUp() { } if (isPerformCleanup()) { if (isAllowMultiCleanup() || isInitialSetup()) { - try { - this.testUtility.cleanup(); - } catch (Exception exception) { - LOG.error("Exception occurred while performing cleanup", exception); - } + this.testUtility.cleanup(); } } } diff --git a/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/AbstractTestCleaner.java b/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/AbstractTestCleaner.java index fbe60fa6..4e2eba8d 100644 --- a/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/AbstractTestCleaner.java +++ b/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/AbstractTestCleaner.java @@ -9,6 +9,6 @@ public abstract interface AbstractTestCleaner { * Performs a cleanup of contextual data. E.g. it may rest the database so according side-effects from previous tests * are eliminated. */ - void cleanup() throws Exception; + void cleanup(); } diff --git a/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerImpl.java b/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerImpl.java index 1977f66b..d36717ae 100644 --- a/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerImpl.java +++ b/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerImpl.java @@ -21,7 +21,7 @@ public void setPlugins(List plugins) { } @Override - public void cleanup() throws Exception { + public void cleanup() { for (TestCleanerPlugin plugin : this.plugins) { plugin.cleanup(); diff --git a/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginFlyway.java b/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginFlyway.java index d8d7e9d1..1caf590b 100644 --- a/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginFlyway.java +++ b/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginFlyway.java @@ -3,12 +3,14 @@ import javax.inject.Inject; import org.flywaydb.core.Flyway; +import org.springframework.beans.factory.annotation.Qualifier; /** * Implementation of {@link TestCleanerPlugin} base on {@link Flyway}. It will {@link Flyway#clean() clean} and * {@link Flyway#migrate() migrate} on {@link #cleanup()}. Therefore after {@link #cleanup()} only DDL and master-data * will be left in the database. */ +@Qualifier("TestCleanerPluginFlyway") public class TestCleanerPluginFlyway implements TestCleanerPlugin { @Inject @@ -34,7 +36,7 @@ public TestCleanerPluginFlyway(Flyway flyway) { } @Override - public void cleanup() throws Exception { + public void cleanup() { this.flyway.clean(); this.flyway.migrate(); diff --git a/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginLiquibase.java b/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginLiquibase.java index 4c9aad04..deb7550b 100644 --- a/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginLiquibase.java +++ b/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginLiquibase.java @@ -2,9 +2,7 @@ import javax.inject.Inject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - +import org.springframework.beans.factory.annotation.Qualifier; import liquibase.Liquibase; import liquibase.exception.DatabaseException; @@ -12,6 +10,7 @@ * Implementation of {@link TestCleanerPlugin} base on {@link Liquibase}. It will {@link Liquibase#dropAll() clean} on * {@link #cleanup()}. Therefore after {@link #cleanup()} it will drop all database objects. */ +@Qualifier("TestCleanerPluginLiquibase") public class TestCleanerPluginLiquibase implements TestCleanerPlugin { @Inject @@ -37,8 +36,12 @@ public TestCleanerPluginLiquibase(Liquibase liquibase) { } @Override - public void cleanup() throws Exception { - this.liquibase.dropAll(); + public void cleanup() { + try { + this.liquibase.dropAll(); + } catch(DatabaseException databaseException ) { + throw new RuntimeException(databaseException); + } } } diff --git a/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginNone.java b/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginNone.java index e8458b4e..1df70541 100644 --- a/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginNone.java +++ b/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginNone.java @@ -8,7 +8,7 @@ public class TestCleanerPluginNone implements TestCleanerPlugin { @Override - public void cleanup() throws Exception { + public void cleanup() { // do nothing by design } diff --git a/templates/server/src/main/resources/META-INF/archetype-post-generate.groovy b/templates/server/src/main/resources/META-INF/archetype-post-generate.groovy index 45d776a6..58dcd880 100644 --- a/templates/server/src/main/resources/META-INF/archetype-post-generate.groovy +++ b/templates/server/src/main/resources/META-INF/archetype-post-generate.groovy @@ -20,23 +20,21 @@ if (batch != "batch") { //dbMigration is either flyway or liquibase String dbMigration = properties.get("dbMigration") - if (dbMigration == "flyway") { //delete changelog and testchangelog folder which is not required for flyway Path rootPath = projectPath.resolve("core/src/main/resources/db/changelog") deleteDirectoryRecursion(rootPath) - - Path rootPathtest = projectPath.resolve("core/src/test/resources/db/changelog") - deleteDirectoryRecursion(rootPathtest) + + Files.deleteIfExists projectPath.resolve("core/src/test/resources/db/test/changelog-master.xml") + Files.deleteIfExists projectPath.resolve("core/src/test/resources/db/test/changelog-v1.0.xml") } else if(dbMigration == "liquibase") { //delete migration and test folder which is not required for liquibase Path rootPath = projectPath.resolve("core/src/main/resources/db/migration") deleteDirectoryRecursion(rootPath) - Path rootPathtest = projectPath.resolve("core/src/test/resources/db/test") - deleteDirectoryRecursion(rootPathtest) - + Files.deleteIfExists projectPath.resolve("core/src/test/resources/db/test/V0001__InitDb.sql") + } void deleteDirectoryRecursion(Path path) { diff --git a/templates/server/src/main/resources/archetype-resources/batch/src/test/java/__packageInPathFormat__/general/batch/base/test/SpringBatchIntegrationTest.java b/templates/server/src/main/resources/archetype-resources/batch/src/test/java/__packageInPathFormat__/general/batch/base/test/SpringBatchIntegrationTest.java index 00e9df47..c5e29358 100644 --- a/templates/server/src/main/resources/archetype-resources/batch/src/test/java/__packageInPathFormat__/general/batch/base/test/SpringBatchIntegrationTest.java +++ b/templates/server/src/main/resources/archetype-resources/batch/src/test/java/__packageInPathFormat__/general/batch/base/test/SpringBatchIntegrationTest.java @@ -1,8 +1,6 @@ package ${package}.general.batch.base.test; import javax.inject.Inject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.batch.core.Job; import org.springframework.batch.core.launch.JobLauncher; import org.springframework.batch.test.JobLauncherTestUtils; @@ -10,36 +8,29 @@ import com.devonfw.module.test.common.base.ComponentTest; import com.devonfw.module.test.common.base.DbTest; import com.devonfw.module.test.common.base.clean.TestCleanerPlugin; -import com.devonfw.module.test.common.base.clean.TestCleanerPluginFlyway; +import org.springframework.beans.factory.annotation.Qualifier; /** * Base class for all spring batch integration tests. It helps to do End-to-End job tests. */ public abstract class SpringBatchIntegrationTest extends ComponentTest { - private static final Logger LOG = LoggerFactory.getLogger(SpringBatchIntegrationTest.class); - @Inject private JobLauncher jobLauncher; - + @Inject +#if($dbMigration == 'flyway') + @Qualifier("TestCleanerPluginFlyway") + private TestCleanerPlugin testCleanerPlugin; +#else if($dbMigration == 'liquibase') + @Qualifier("TestCleanerPluginLiquibase") private TestCleanerPlugin testCleanerPlugin; +#end @Override protected void doSetUp() { super.doSetUp(); -#if($dbMigration == 'flyway') - testCleanerPlugin = new TestCleanerPluginFlyway(); -#else if($dbMigration == 'liquibase') - testCleanerPlugin = new TestCleanerPluginLiquibase(); -#end -try { testCleanerPlugin.cleanup(); -} -catch(Exception exception) { - LOG.error("Exception occurred while performing cleanup", exception); -} - } protected void doTearDown() { diff --git a/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/base/test/DbTestHelper.java b/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/base/test/DbTestHelper.java index ec7d3cbd..917accd5 100644 --- a/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/base/test/DbTestHelper.java +++ b/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/base/test/DbTestHelper.java @@ -1,9 +1,9 @@ package ${package}.general.common.base.test; import javax.inject.Named; +import javax.inject.Inject; +import org.springframework.beans.factory.annotation.Qualifier; import com.devonfw.module.test.common.base.clean.TestCleanerPlugin; -import com.devonfw.module.test.common.base.clean.TestCleanerPluginLiquibase; -import com.devonfw.module.test.common.base.clean.TestCleanerPluginFlyway; /** * This class provides methods for handling the database during testing where resets (and other operations) may be @@ -11,9 +11,15 @@ */ @Named public class DbTestHelper{ - + @Inject +#if($dbMigration == 'flyway') + @Qualifier("TestCleanerPluginFlyway") + private TestCleanerPlugin testCleanerPlugin; +#else if($dbMigration == 'liquibase') + @Qualifier("TestCleanerPluginLiquibase") private TestCleanerPlugin testCleanerPlugin; +#end public DbTestHelper(TestCleanerPlugin testCleanerPlugin) { @@ -25,12 +31,6 @@ public DbTestHelper(TestCleanerPlugin testCleanerPlugin) { * Drops the whole database. */ public void dropDatabase() throws Exception { -#if($dbMigration == 'liquibase') - testCleanerPlugin = new TestCleanerPluginLiquibase(); -#end -#if($dbMigration == 'flyway') - testCleanerPlugin = new TestCleanerPluginFlyway(); -#end testCleanerPlugin.cleanup(); } diff --git a/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/impl/config/TestDbConfig.java b/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/impl/config/TestDbConfig.java index b8c88def..72bad43d 100644 --- a/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/impl/config/TestDbConfig.java +++ b/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/impl/config/TestDbConfig.java @@ -12,7 +12,6 @@ import com.devonfw.module.test.common.base.clean.TestCleanerPluginFlyway; #end - /** * {@link Configuration} for Database in JUnit tests. */ @@ -28,7 +27,6 @@ public TestCleaner testCleaner() { return new TestCleanerImpl(); } - #if ($dbMigration == 'liquibase') /** * @return the {@link TestCleanerPluginLiquibase}. @@ -38,8 +36,6 @@ public TestCleanerPlugin testCleanerPluginLiquibase() { return new TestCleanerPluginLiquibase(); } - - #else /** * @return the {@link TestCleanerPluginFlyway}. @@ -49,7 +45,5 @@ public TestCleanerPlugin testCleanerPluginFlyway() { return new TestCleanerPluginFlyway(); } - #end - } \ No newline at end of file diff --git a/templates/server/src/main/resources/archetype-resources/core/src/test/resources/db/changelog/changelog-master.xml b/templates/server/src/main/resources/archetype-resources/core/src/test/resources/db/test/changelog-master.xml similarity index 100% rename from templates/server/src/main/resources/archetype-resources/core/src/test/resources/db/changelog/changelog-master.xml rename to templates/server/src/main/resources/archetype-resources/core/src/test/resources/db/test/changelog-master.xml diff --git a/templates/server/src/main/resources/archetype-resources/core/src/test/resources/db/changelog/changelog-v1.0.xml b/templates/server/src/main/resources/archetype-resources/core/src/test/resources/db/test/changelog-v1.0.xml similarity index 100% rename from templates/server/src/main/resources/archetype-resources/core/src/test/resources/db/changelog/changelog-v1.0.xml rename to templates/server/src/main/resources/archetype-resources/core/src/test/resources/db/test/changelog-v1.0.xml From e00c2e78b8d907c8f3d86f939073a68e4a571912 Mon Sep 17 00:00:00 2001 From: dixyushi Date: Thu, 10 Jun 2021 10:17:52 +0530 Subject: [PATCH 41/43] review comment-minor change on Qualifier implemented --- .../test/common/base/clean/TestCleanerPluginFlyway.java | 2 +- .../common/base/clean/TestCleanerPluginLiquibase.java | 2 +- .../batch/base/test/SpringBatchIntegrationTest.java | 9 ++------- .../general/common/base/test/DbTestHelper.java | 9 ++------- .../src/test/resources/config/application.properties | 4 ++-- .../core/src/test/resources/db/test/changelog-master.xml | 2 +- 6 files changed, 9 insertions(+), 19 deletions(-) diff --git a/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginFlyway.java b/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginFlyway.java index 1caf590b..0aa1c1e8 100644 --- a/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginFlyway.java +++ b/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginFlyway.java @@ -10,7 +10,7 @@ * {@link Flyway#migrate() migrate} on {@link #cleanup()}. Therefore after {@link #cleanup()} only DDL and master-data * will be left in the database. */ -@Qualifier("TestCleanerPluginFlyway") +@Qualifier("testCleanerPluginflyway") public class TestCleanerPluginFlyway implements TestCleanerPlugin { @Inject diff --git a/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginLiquibase.java b/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginLiquibase.java index deb7550b..0a09b27a 100644 --- a/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginLiquibase.java +++ b/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginLiquibase.java @@ -10,7 +10,7 @@ * Implementation of {@link TestCleanerPlugin} base on {@link Liquibase}. It will {@link Liquibase#dropAll() clean} on * {@link #cleanup()}. Therefore after {@link #cleanup()} it will drop all database objects. */ -@Qualifier("TestCleanerPluginLiquibase") +@Qualifier("testCleanerPluginliquibase") public class TestCleanerPluginLiquibase implements TestCleanerPlugin { @Inject diff --git a/templates/server/src/main/resources/archetype-resources/batch/src/test/java/__packageInPathFormat__/general/batch/base/test/SpringBatchIntegrationTest.java b/templates/server/src/main/resources/archetype-resources/batch/src/test/java/__packageInPathFormat__/general/batch/base/test/SpringBatchIntegrationTest.java index c5e29358..f4eb3b58 100644 --- a/templates/server/src/main/resources/archetype-resources/batch/src/test/java/__packageInPathFormat__/general/batch/base/test/SpringBatchIntegrationTest.java +++ b/templates/server/src/main/resources/archetype-resources/batch/src/test/java/__packageInPathFormat__/general/batch/base/test/SpringBatchIntegrationTest.java @@ -19,14 +19,9 @@ public abstract class SpringBatchIntegrationTest extends ComponentTest { private JobLauncher jobLauncher; @Inject -#if($dbMigration == 'flyway') - @Qualifier("TestCleanerPluginFlyway") + @Qualifier("testCleanerPlugin$dbMigration") private TestCleanerPlugin testCleanerPlugin; -#else if($dbMigration == 'liquibase') - @Qualifier("TestCleanerPluginLiquibase") - private TestCleanerPlugin testCleanerPlugin; -#end - + @Override protected void doSetUp() { super.doSetUp(); diff --git a/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/base/test/DbTestHelper.java b/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/base/test/DbTestHelper.java index 917accd5..24475397 100644 --- a/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/base/test/DbTestHelper.java +++ b/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/base/test/DbTestHelper.java @@ -13,13 +13,8 @@ public class DbTestHelper{ @Inject -#if($dbMigration == 'flyway') - @Qualifier("TestCleanerPluginFlyway") + @Qualifier("testCleanerPlugin$dbMigration") private TestCleanerPlugin testCleanerPlugin; -#else if($dbMigration == 'liquibase') - @Qualifier("TestCleanerPluginLiquibase") - private TestCleanerPlugin testCleanerPlugin; -#end public DbTestHelper(TestCleanerPlugin testCleanerPlugin) { @@ -30,7 +25,7 @@ public DbTestHelper(TestCleanerPlugin testCleanerPlugin) { /** * Drops the whole database. */ - public void dropDatabase() throws Exception { + public void dropDatabase() { testCleanerPlugin.cleanup(); } diff --git a/templates/server/src/main/resources/archetype-resources/core/src/test/resources/config/application.properties b/templates/server/src/main/resources/archetype-resources/core/src/test/resources/config/application.properties index 9ffe674c..0b7628c2 100644 --- a/templates/server/src/main/resources/archetype-resources/core/src/test/resources/config/application.properties +++ b/templates/server/src/main/resources/archetype-resources/core/src/test/resources/config/application.properties @@ -20,8 +20,8 @@ spring.flyway.locations=classpath:db/test #if ($dbMigration == 'liquibase') spring.liquibase.enabled=true #if ($dbType == 'h2') -spring.liquibase.locations=classpath:db/changelog/changelog-v1.0.xml +spring.liquibase.change-log=classpath:db/changelog #else -spring.liquibase.locations=classpath:db/test +spring.liquibase.change-log=classpath:db/test #end #end \ No newline at end of file diff --git a/templates/server/src/main/resources/archetype-resources/core/src/test/resources/db/test/changelog-master.xml b/templates/server/src/main/resources/archetype-resources/core/src/test/resources/db/test/changelog-master.xml index c7f1737b..7f0803cc 100644 --- a/templates/server/src/main/resources/archetype-resources/core/src/test/resources/db/test/changelog-master.xml +++ b/templates/server/src/main/resources/archetype-resources/core/src/test/resources/db/test/changelog-master.xml @@ -4,6 +4,6 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd"> - + \ No newline at end of file From 5ef5923d7c634d71cfdf50f1b7695d666c67849f Mon Sep 17 00:00:00 2001 From: dixyushi Date: Mon, 14 Jun 2021 19:08:48 +0530 Subject: [PATCH 42/43] Fixed Liquibase bean configuration Issue --- .../SpringBootApp.java | 4 +- .../common/impl/config/TestDbConfig.java | 59 ++++++++++++++----- .../resources/config/application.properties | 6 +- 3 files changed, 49 insertions(+), 20 deletions(-) diff --git a/templates/server/src/main/resources/archetype-resources/core/src/main/java/__packageInPathFormat__/SpringBootApp.java b/templates/server/src/main/resources/archetype-resources/core/src/main/java/__packageInPathFormat__/SpringBootApp.java index 4c12884c..160113e0 100644 --- a/templates/server/src/main/resources/archetype-resources/core/src/main/java/__packageInPathFormat__/SpringBootApp.java +++ b/templates/server/src/main/resources/archetype-resources/core/src/main/java/__packageInPathFormat__/SpringBootApp.java @@ -5,7 +5,8 @@ import org.springframework.boot.autoconfigure.domain.EntityScan; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; - +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration; import com.devonfw.module.jpa.dataaccess.api.AdvancedRevisionEntity; import com.devonfw.module.jpa.dataaccess.impl.data.GenericRepositoryFactoryBean; @@ -15,6 +16,7 @@ @SpringBootApplication @EnableJpaRepositories(repositoryFactoryBeanClass = GenericRepositoryFactoryBean.class) @EnableGlobalMethodSecurity(jsr250Enabled = true) +@EnableAutoConfiguration(exclude = LiquibaseAutoConfiguration.class) public class SpringBootApp { /** diff --git a/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/impl/config/TestDbConfig.java b/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/impl/config/TestDbConfig.java index 72bad43d..9fbe776b 100644 --- a/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/impl/config/TestDbConfig.java +++ b/templates/server/src/main/resources/archetype-resources/core/src/test/java/__packageInPathFormat__/general/common/impl/config/TestDbConfig.java @@ -2,22 +2,27 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; - +import org.springframework.beans.factory.annotation.Value;#if($dbMigration=='liquibase') +import liquibase.Liquibase; +import liquibase.resource.ResourceAccessor; +import liquibase.resource.FileSystemResourceAccessor; +import liquibase.database.Database; +import liquibase.exception.DatabaseException; +import liquibase.database.DatabaseFactory;#end +import org.springframework.jdbc.datasource.DriverManagerDataSource; +import javax.sql.DataSource; import com.devonfw.module.test.common.base.clean.TestCleaner; import com.devonfw.module.test.common.base.clean.TestCleanerImpl; -import com.devonfw.module.test.common.base.clean.TestCleanerPlugin; -#if ($dbMigration == 'liquibase') -import com.devonfw.module.test.common.base.clean.TestCleanerPluginLiquibase; -#else -import com.devonfw.module.test.common.base.clean.TestCleanerPluginFlyway; -#end +import com.devonfw.module.test.common.base.clean.TestCleanerPlugin;#if($dbMigration=='liquibase') +import com.devonfw.module.test.common.base.clean.TestCleanerPluginLiquibase;#else +import com.devonfw.module.test.common.base.clean.TestCleanerPluginFlyway;#end /** * {@link Configuration} for Database in JUnit tests. */ @Configuration public class TestDbConfig { - + /** * @return the {@link TestCleaner}. */ @@ -27,8 +32,9 @@ public TestCleaner testCleaner() { return new TestCleanerImpl(); } -#if ($dbMigration == 'liquibase') - /** + #if($dbMigration=='liquibase') + + /** * @return the {@link TestCleanerPluginLiquibase}. */ @Bean @@ -36,14 +42,39 @@ public TestCleanerPlugin testCleanerPluginLiquibase() { return new TestCleanerPluginLiquibase(); } -#else - /** + + @Value("${spring.datasource.url}") + private String spring_datasource_url; + + @Value("${spring.datasource.password}") + private String spring_datasource_password; + + @Value("${spring.datasource.username}") + private String spring_datasource_username; + + @Value("${spring.liquibase.change-log}") + private String spring_liquibase_change_log; + + @Bean + public Liquibase liquibase() throws DatabaseException { + + ResourceAccessor resourceAccessor = new FileSystemResourceAccessor(); + Database database = DatabaseFactory.getInstance().openDatabase(this.spring_datasource_url, + this.spring_datasource_username, this.spring_datasource_password, null, null, null, null, + resourceAccessor); + Liquibase liquibase = new Liquibase(this.spring_liquibase_change_log, resourceAccessor, database); + + return liquibase; + } + + #else + + /** * @return the {@link TestCleanerPluginFlyway}. */ @Bean public TestCleanerPlugin testCleanerPluginFlyway() { return new TestCleanerPluginFlyway(); - } -#end + }#end } \ No newline at end of file diff --git a/templates/server/src/main/resources/archetype-resources/core/src/test/resources/config/application.properties b/templates/server/src/main/resources/archetype-resources/core/src/test/resources/config/application.properties index 0b7628c2..604a17bc 100644 --- a/templates/server/src/main/resources/archetype-resources/core/src/test/resources/config/application.properties +++ b/templates/server/src/main/resources/archetype-resources/core/src/test/resources/config/application.properties @@ -19,9 +19,5 @@ spring.flyway.locations=classpath:db/test #end #if ($dbMigration == 'liquibase') spring.liquibase.enabled=true -#if ($dbType == 'h2') -spring.liquibase.change-log=classpath:db/changelog -#else -spring.liquibase.change-log=classpath:db/test -#end +spring.liquibase.change-log=classpath:db/test/changelog-master.xml #end \ No newline at end of file From ee9318b667ba242933c8716f5aec36a524531bd3 Mon Sep 17 00:00:00 2001 From: dixyushi Date: Mon, 14 Jun 2021 19:46:07 +0530 Subject: [PATCH 43/43] removed DbTest which is not required --- .../main/java/com/devonfw/module/test/common/base/DbTest.java | 1 + .../test/common/base/clean/TestCleanerPluginLiquibase.java | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/DbTest.java b/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/DbTest.java index 67054fdf..a71dd931 100644 --- a/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/DbTest.java +++ b/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/DbTest.java @@ -4,6 +4,7 @@ import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; +import com.devonfw.module.test.common.base.BaseTest; import com.devonfw.module.test.common.base.clean.TestCleaner; /** diff --git a/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginLiquibase.java b/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginLiquibase.java index 0a09b27a..526bb764 100644 --- a/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginLiquibase.java +++ b/modules/test-jpa/src/main/java/com/devonfw/module/test/common/base/clean/TestCleanerPluginLiquibase.java @@ -13,7 +13,6 @@ @Qualifier("testCleanerPluginliquibase") public class TestCleanerPluginLiquibase implements TestCleanerPlugin { - @Inject private Liquibase liquibase; /**