├── .github
└── workflows
│ └── run-renovate.yml
├── .gitignore
├── Examples
├── .mvn
│ └── wrapper
│ │ └── maven-wrapper.properties
├── Docker-webserver-cache
│ ├── Dockerfile
│ ├── build.cmd
│ ├── run.cmd
│ └── stop.cmd
├── apache-pdfbox
│ ├── pom.xml
│ └── src
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── ApachePDFBoxTest.java
├── apache-poi
│ ├── pom.xml
│ └── src
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── ApachePOITest.java
├── apache-spark
│ ├── pom.xml
│ └── src
│ │ └── test
│ │ ├── java
│ │ └── com
│ │ │ └── examples
│ │ │ ├── ApacheSparkTest.java
│ │ │ └── Review.java
│ │ └── resources
│ │ └── log4j2.properties
├── archunit
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ └── java
│ │ │ └── com
│ │ │ └── example
│ │ │ ├── common
│ │ │ └── service
│ │ │ │ └── CommonService.java
│ │ │ ├── payment
│ │ │ └── controller
│ │ │ │ ├── PaymentController.java
│ │ │ │ └── WronglyNamed.java
│ │ │ └── reservation
│ │ │ ├── controller
│ │ │ └── ReservationController.java
│ │ │ └── service
│ │ │ └── ReservationService.java
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── examples
│ │ └── ArchUnitTest.java
├── assertj
│ ├── pom.xml
│ └── src
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── examples
│ │ └── AssertJTest.java
├── autoservice
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ └── java
│ │ │ └── com
│ │ │ └── examples
│ │ │ ├── CarService.java
│ │ │ ├── PaganiCarService.java
│ │ │ └── PorscheCarService.java
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── examples
│ │ └── AutoServiceTest.java
├── autovalue
│ ├── pom.xml
│ └── src
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── examples
│ │ ├── AutoValueBook.java
│ │ └── AutoValueTest.java
├── awaitility
│ ├── pom.xml
│ └── src
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── AwaitilityTest.java
├── classgraph
│ ├── pom.xml
│ └── src
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── examples
│ │ ├── ClassGraphTest.java
│ │ └── classgraph
│ │ └── Car.java
├── command.cmd
├── dockerimages
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── example
│ │ ├── Car.java
│ │ ├── CarApplication.java
│ │ ├── CarPart.java
│ │ └── CarRestController.java
├── equalsverifier
│ ├── pom.xml
│ └── src
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── EqualsVerifierTest.java
├── flexmark
│ ├── pom.xml
│ └── src
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── example
│ │ ├── FlexMarkJavaTest.java
│ │ └── GitHubRepository.java
├── gatling-kafka
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ └── java
│ │ │ └── com
│ │ │ └── example
│ │ │ ├── KafkaConsumer.java
│ │ │ └── SpringKafkaApplication.java
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── SpringBootKafkaTest.java
├── gatling
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ └── java
│ │ │ └── com
│ │ │ └── example
│ │ │ ├── Car.java
│ │ │ ├── CarApplication.java
│ │ │ ├── CarPart.java
│ │ │ └── CarRestController.java
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── BasicSimulation.java
├── graphql
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── example
│ │ │ │ ├── Account.java
│ │ │ │ ├── AccountController.java
│ │ │ │ ├── GraphqlServerApplication.java
│ │ │ │ └── User.java
│ │ └── resources
│ │ │ └── graphql
│ │ │ └── schema.graphqls
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── example
│ │ ├── AccountControllerTests.java
│ │ └── GraphqlServerApplicationTests.java
├── guice
│ ├── pom.xml
│ └── src
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── examples
│ │ ├── BookService.java
│ │ ├── GuiceTest.java
│ │ └── PrintService.java
├── handlebars
│ ├── pom.xml
│ └── src
│ │ └── test
│ │ ├── java
│ │ └── com
│ │ │ └── example
│ │ │ └── HandlebarsTest.java
│ │ └── resources
│ │ └── HandlebarsExample.hbs
├── itext
│ ├── pom.xml
│ └── src
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── iTextTest.java
├── jacoco-agent
│ ├── README.md
│ ├── pom.xml
│ ├── src
│ │ └── main
│ │ │ └── java
│ │ │ └── com
│ │ │ └── example
│ │ │ ├── Car.java
│ │ │ ├── CarApplication.java
│ │ │ ├── CarPart.java
│ │ │ └── CarRestController.java
│ └── test.cmd
├── javapoet
│ ├── pom.xml
│ └── src
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── JavaPoetTest.java
├── jdbi
│ ├── pom.xml
│ └── src
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── examples
│ │ ├── Book.java
│ │ └── JdbiTest.java
├── jfrunit
│ ├── pom.xml
│ └── src
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── JfrUnitTest.java
├── jlink
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── examples
│ │ └── jlink
│ │ └── HelloJlink.java
├── jmolecules
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ └── java
│ │ │ └── com
│ │ │ └── example
│ │ │ ├── Address.java
│ │ │ ├── Student.java
│ │ │ ├── Students.java
│ │ │ └── jMoleculesApplication.java
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── jMoleculesTest.java
├── jobrunr
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── examples
│ │ │ │ └── jobrunr
│ │ │ │ ├── JobRunrApplication.java
│ │ │ │ └── JobRunrService.java
│ │ └── resources
│ │ │ └── application.properties
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── examples
│ │ └── JobRunrTest.java
├── jooq
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── examples
│ │ │ │ └── jOOQApplication.java
│ │ └── resources
│ │ │ ├── application.properties
│ │ │ └── schema.sql
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── examples
│ │ └── jOOQTest.java
├── jpackage
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── examples
│ │ └── jpackage
│ │ └── Hellojpackage.java
├── jreleaser
│ └── pom.xml
├── jsoup
│ ├── pom.xml
│ └── src
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── jsoupTest.java
├── libphonenumber
│ ├── pom.xml
│ └── src
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── libphonenumberTest.java
├── mapstruct
│ ├── pom.xml
│ └── src
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── examples
│ │ ├── Book.java
│ │ ├── BookEntity.java
│ │ ├── BookMapper.java
│ │ └── MapStructTest.java
├── maven-enforcer-plugin
│ └── pom.xml
├── micrometer
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ ├── java
│ │ └── com
│ │ │ └── example
│ │ │ ├── MicrometerApplication.java
│ │ │ └── MicrometerService.java
│ │ └── resources
│ │ └── application.properties
├── microstream
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── example
│ │ │ │ ├── Car.java
│ │ │ │ ├── CarPart.java
│ │ │ │ ├── CarRepository.java
│ │ │ │ ├── CarRepositoryImpl.java
│ │ │ │ └── MicroStreamApplication.java
│ │ └── resources
│ │ │ └── application.properties
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── MicroStreamTest.java
├── mvnw
├── mvnw.cmd
├── old-groupids-alerter
│ └── pom.xml
├── openrewrite
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ └── java
│ │ │ └── com
│ │ │ └── example
│ │ │ └── Main.java
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── ExampleTest.java
├── owasp-dependency-check
│ └── pom.xml
├── passay
│ ├── pom.xml
│ └── src
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── PassayTest.java
├── pebble-templates
│ ├── pom.xml
│ └── src
│ │ └── test
│ │ ├── java
│ │ └── com
│ │ │ └── example
│ │ │ └── PebbleTemplatesTest.java
│ │ └── resources
│ │ ├── base.html
│ │ └── specificFunction.html
├── pitest
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ └── java
│ │ │ └── com
│ │ │ └── example
│ │ │ └── PitestExample.java
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── PitestExampleTest.java
├── pom.xml
├── rest-assured
│ ├── pom.xml
│ └── src
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── examples
│ │ ├── Car.java
│ │ ├── CarApplication.java
│ │ ├── CarPart.java
│ │ ├── CarRestController.java
│ │ └── RESTassuredTest.java
├── rest-easy
│ ├── pom.xml
│ └── src
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── examples
│ │ ├── Car.java
│ │ ├── CarApplication.java
│ │ ├── CarPart.java
│ │ ├── CarRestController.java
│ │ └── RESTEasyTest.java
├── retrofit
│ ├── pom.xml
│ └── src
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── examples
│ │ ├── Car.java
│ │ ├── CarApplication.java
│ │ ├── CarPart.java
│ │ ├── CarRestController.java
│ │ └── RetrofitTest.java
├── shedlock
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── example
│ │ ├── ShedLockApplication.java
│ │ └── ShedLockService.java
├── testcontainers
│ ├── pom.xml
│ └── src
│ │ └── test
│ │ ├── java
│ │ └── com
│ │ │ └── example
│ │ │ └── TestcontainersTest.java
│ │ └── resources
│ │ └── logback-test.xml
├── timefold
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── examples
│ │ │ │ └── timefold
│ │ │ │ ├── TimefoldConferenceSchedulingApp.java
│ │ │ │ ├── domain
│ │ │ │ ├── Room.java
│ │ │ │ ├── Session.java
│ │ │ │ ├── TimeTable.java
│ │ │ │ └── Timeslot.java
│ │ │ │ ├── persistence
│ │ │ │ ├── RoomRepository.java
│ │ │ │ ├── SessionRepository.java
│ │ │ │ ├── TimeTableRepository.java
│ │ │ │ └── TimeslotRepository.java
│ │ │ │ ├── rest
│ │ │ │ └── TimeTableController.java
│ │ │ │ └── solver
│ │ │ │ └── ConferenceConstraintsProvider.java
│ │ └── resources
│ │ │ └── static
│ │ │ ├── app.js
│ │ │ └── index.html
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── examples
│ │ └── timefold
│ │ └── SpringBootApplicationContextTest.java
├── togglz
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ ├── java
│ │ └── com
│ │ │ └── example
│ │ │ ├── TogglzApplication.java
│ │ │ ├── TogglzController.java
│ │ │ └── TogglzFeatures.java
│ │ └── resources
│ │ └── application.properties
├── typesafe-config
│ ├── pom.xml
│ └── src
│ │ └── test
│ │ ├── java
│ │ └── com
│ │ │ └── examples
│ │ │ └── TypeSafeConfigTest.java
│ │ └── resources
│ │ └── application.properties
├── vavr
│ ├── pom.xml
│ └── src
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── examples
│ │ └── VavrTest.java
├── wiremock
│ ├── pom.xml
│ └── src
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── examples
│ │ ├── Car.java
│ │ └── WireMockTest.java
└── zxcvbn4j
│ ├── pom.xml
│ └── src
│ └── test
│ └── java
│ └── com
│ └── example
│ └── zxcvbn4jTest.java
├── README.md
├── renovate-config.js
└── renovate.json
/.github/workflows/run-renovate.yml:
--------------------------------------------------------------------------------
1 | name: Run Renovate
2 | on: workflow_dispatch
3 | jobs:
4 | Run-Renovate:
5 | runs-on: ubuntu-latest
6 | steps:
7 | - name: Checkout
8 | uses: actions/checkout@v2.0.0
9 | - name: Self-hosted Renovate
10 | uses: renovatebot/github-action@v34.105.6
11 | with:
12 | configurationFile: renovate-config.js
13 | token: ${{ secrets.RENOVATE_TOKEN }}
14 |
--------------------------------------------------------------------------------
/Examples/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.4/apache-maven-3.8.4-bin.zip
2 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar
3 |
--------------------------------------------------------------------------------
/Examples/Docker-webserver-cache/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM eclipse-temurin:17.0.3_7-jdk as java
2 | WORKDIR /mirror
3 | RUN apt-get update && apt-get install wget
4 |
5 | SHELL ["/bin/bash", "-c"]
6 | # From https://github.com/jeremylong/Open-Vulnerability-Project/tree/main/vulnz#caching-the-nvd-cve-data
7 | #RUN wget https://nvd.nist.gov/feeds/json/cve/1.1/nvdcve-1.1-modified.json.gz
8 | #RUN wget https://nvd.nist.gov/feeds/json/cve/1.1/nvdcve-1.1-modified.meta
9 | #RUN wget https://nvd.nist.gov/feeds/json/cve/1.1/nvdcve-1.1-2023.json.gz
10 | #RUN wget https://nvd.nist.gov/feeds/json/cve/1.1/nvdcve-1.1-2022.json.gz
11 | #RUN wget https://nvd.nist.gov/feeds/json/cve/1.1/nvdcve-1.1-2021.json.gz
12 | #RUN wget https://nvd.nist.gov/feeds/json/cve/1.1/nvdcve-1.1-2020.json.gz
13 | #RUN wget https://nvd.nist.gov/feeds/json/cve/1.1/nvdcve-1.1-$(date +%Y).json.gz
14 |
15 | RUN wget https://github.com/jeremylong/Open-Vulnerability-Project/releases/download/v5.0.3/vulnz-5.0.3.jar
16 | RUN chmod +x vulnz-5.0.3.jar
17 | RUN ./vulnz-5.0.3.jar cve --cache --directory .
18 |
19 | RUN wget --no-check-certificate https://www.cisa.gov/sites/default/files/feeds/known_exploited_vulnerabilities.json
20 |
21 | # Old GroupIds Alerter
22 | RUN wget https://raw.githubusercontent.com/jonathanlermitage/oga-maven-plugin/master/uc/og-definitions.json --no-check-certificate
23 | RUN wget https://raw.githubusercontent.com/jonathanlermitage/oga-maven-plugin/master/uc/og-unofficial-definitions.json --no-check-certificate
24 |
25 | FROM nginx:1.27.0-alpine
26 | COPY --from=java /mirror /usr/share/nginx/html
--------------------------------------------------------------------------------
/Examples/Docker-webserver-cache/build.cmd:
--------------------------------------------------------------------------------
1 | docker build -t cache .
--------------------------------------------------------------------------------
/Examples/Docker-webserver-cache/run.cmd:
--------------------------------------------------------------------------------
1 | docker stop cache
2 | docker run -d -p 80:80 --rm --name cache cache
--------------------------------------------------------------------------------
/Examples/Docker-webserver-cache/stop.cmd:
--------------------------------------------------------------------------------
1 | docker stop cache
--------------------------------------------------------------------------------
/Examples/apache-pdfbox/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | Examples
7 | com.example
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | apache-pdfbox
13 |
14 |
15 |
16 |
17 | org.apache.pdfbox
18 | pdfbox
19 |
20 |
21 |
--------------------------------------------------------------------------------
/Examples/apache-pdfbox/src/test/java/com/example/ApachePDFBoxTest.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import org.apache.pdfbox.pdmodel.PDDocument;
4 | import org.apache.pdfbox.pdmodel.PDPage;
5 | import org.apache.pdfbox.pdmodel.PDPageContentStream;
6 | import org.apache.pdfbox.pdmodel.font.PDFont;
7 | import org.apache.pdfbox.pdmodel.font.PDType1Font;
8 | import org.apache.pdfbox.pdmodel.font.Standard14Fonts;
9 | import org.junit.jupiter.api.Test;
10 |
11 | import java.io.File;
12 | import java.io.IOException;
13 |
14 | public class ApachePDFBoxTest {
15 |
16 | @Test
17 | public void testPDF() throws IOException {
18 | PDDocument document = new PDDocument();
19 |
20 | PDPage page = new PDPage();
21 | document.addPage( page );
22 |
23 | PDPageContentStream contentStream = new PDPageContentStream(document, page);
24 |
25 | contentStream.beginText();
26 | contentStream.newLineAtOffset(100, 500);
27 | contentStream.setFont(new PDType1Font(Standard14Fonts.FontName.COURIER_BOLD), 14 );
28 | contentStream.showText("Hello conference");
29 | contentStream.endText();
30 |
31 | contentStream.close();
32 |
33 | document.save(new File("target", "Example.pdf"));
34 |
35 | document.close();
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/Examples/apache-poi/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | Examples
7 | com.example
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | apache-poi
13 |
14 |
15 |
16 |
17 | org.apache.poi
18 | poi
19 |
20 |
21 | org.apache.poi
22 | poi-ooxml
23 |
24 |
25 | commons-io
26 | commons-io
27 | 2.16.1
28 |
29 |
30 |
--------------------------------------------------------------------------------
/Examples/apache-spark/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | com.example
12 | 0.0.1-SNAPSHOT
13 | 4.0.0
14 |
15 | apache-spark
16 |
17 |
18 | 21
19 |
20 |
21 |
22 |
23 | org.junit.jupiter
24 | junit-jupiter
25 | test
26 | 5.10.3
27 |
28 |
29 | org.apache.spark
30 | spark-core_2.13
31 | 3.5.1
32 |
33 |
34 | org.apache.spark
35 | spark-sql_2.13
36 | 3.5.1
37 |
38 |
39 | com.fasterxml.jackson.core
40 | jackson-core
41 | 2.17.1
42 |
43 |
44 |
45 |
46 |
47 |
48 | org.apache.maven.plugins
49 | maven-compiler-plugin
50 | 3.13.0
51 |
52 | ${java.version}
53 |
54 |
55 |
56 | org.apache.maven.plugins
57 | maven-surefire-plugin
58 | 3.3.0
59 |
60 | --add-exports java.base/sun.nio.ch=ALL-UNNAMED
61 |
62 |
63 |
64 |
65 |
--------------------------------------------------------------------------------
/Examples/apache-spark/src/test/java/com/examples/ApacheSparkTest.java:
--------------------------------------------------------------------------------
1 | package com.examples;
2 |
3 | import org.apache.spark.api.java.function.FilterFunction;
4 | import org.apache.spark.sql.Dataset;
5 | import org.apache.spark.sql.Encoder;
6 | import org.apache.spark.sql.Encoders;
7 | import org.apache.spark.sql.SparkSession;
8 | import org.junit.jupiter.api.Test;
9 |
10 | import java.io.IOException;
11 | import java.nio.file.Files;
12 | import java.nio.file.Path;
13 | import java.time.Duration;
14 | import java.time.Instant;
15 |
16 | import static org.junit.jupiter.api.Assertions.assertEquals;
17 |
18 |
19 | // Apache Spark's Web UI is available on http://localhost:4040 when the application is running
20 | public class ApacheSparkTest {
21 | @Test
22 | void testApacheSpark() throws IOException {
23 | Instant start = Instant.now();
24 |
25 | String amazonDatasetFile = "../../../kcore_5.json"; // You need to download the file yourself from http://jmcauley.ucsd.edu/data/amazon/links.html and place it one directory above the Git repository
26 | SparkSession spark = SparkSession.builder().appName("Amazon Dataset Example").master("local[*]").getOrCreate();
27 |
28 | assertEquals(29, Files.size(Path.of(amazonDatasetFile)) / 1024 / 1024 / 1024 );
29 | System.out.println("29GB Dataset contains 41.135.700 records");
30 |
31 | Encoder reviewEncoder = Encoders.bean(Review.class);
32 |
33 | Dataset amazonDataSet = spark.read().option("multiLine", false).json(amazonDatasetFile).select("reviewText", "reviewerID").as(reviewEncoder);
34 |
35 | Dataset filteredSet = amazonDataSet.filter((FilterFunction) a -> a.getReviewText().contains("Java Programming Language"));
36 |
37 | assertEquals(28, filteredSet.count());
38 |
39 | Instant finish = Instant.now();
40 | Duration duration = Duration.between(start, finish);
41 | System.out.println("Spark duration: " + duration.toSeconds());
42 | spark.stop();
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/Examples/apache-spark/src/test/java/com/examples/Review.java:
--------------------------------------------------------------------------------
1 | package com.examples;
2 |
3 |
4 | public class Review {
5 | private String reviewerID;
6 | private String reviewText;
7 |
8 | public String getReviewerID() {
9 | return reviewerID;
10 | }
11 |
12 | public void setReviewerID(String reviewerID) {
13 | this.reviewerID = reviewerID;
14 | }
15 |
16 | public String getReviewText() {
17 | return reviewText;
18 | }
19 |
20 | public void setReviewText(String reviewText) {
21 | this.reviewText = reviewText;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Examples/apache-spark/src/test/resources/log4j2.properties:
--------------------------------------------------------------------------------
1 | # Set to debug or trace if log4j initialization is failing
2 | status = warn
3 |
4 | # Name of the configuration
5 | name = ConsoleLogConfigDemo
6 |
7 | # Console appender configuration
8 | appender.console.type = Console
9 | appender.console.name = consoleLogger
10 | appender.console.layout.type = PatternLayout
11 | appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
12 |
13 | # Root logger level
14 | rootLogger.level = error
15 |
16 | # Root logger referring to console appender
17 | rootLogger.appenderRef.stdout.ref = consoleLogger
--------------------------------------------------------------------------------
/Examples/archunit/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | Examples
7 | com.example
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | archunit
13 |
14 |
15 |
16 | org.springframework.boot
17 | spring-boot-starter-web
18 |
19 |
20 | com.tngtech.archunit
21 | archunit
22 | test
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/Examples/archunit/src/main/java/com/example/common/service/CommonService.java:
--------------------------------------------------------------------------------
1 | package com.example.common.service;
2 |
3 | import com.example.reservation.service.ReservationService;
4 | import org.springframework.beans.factory.annotation.Autowired;
5 |
6 | public class CommonService {
7 | private ReservationService reservationService;
8 |
9 | @Autowired
10 | public CommonService(ReservationService reservationService) {
11 | this.reservationService = reservationService;
12 | }
13 |
14 | public void commonFunction() {
15 | reservationService.reservationServiceFunction();
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Examples/archunit/src/main/java/com/example/payment/controller/PaymentController.java:
--------------------------------------------------------------------------------
1 | package com.example.payment.controller;
2 |
3 | import com.example.reservation.service.ReservationService;
4 | import org.springframework.beans.factory.annotation.Autowired;
5 | import org.springframework.web.bind.annotation.RestController;
6 |
7 | @RestController
8 | public class PaymentController {
9 |
10 | private ReservationService reservationService;
11 |
12 | @Autowired
13 | public PaymentController(ReservationService reservationService) {
14 | this.reservationService = reservationService;
15 | }
16 |
17 | public void paymentFunction() {
18 | reservationService.reservationServiceFunction();
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Examples/archunit/src/main/java/com/example/payment/controller/WronglyNamed.java:
--------------------------------------------------------------------------------
1 | package com.example.payment.controller;
2 |
3 | import org.springframework.web.bind.annotation.RestController;
4 |
5 | @RestController
6 | public class WronglyNamed {
7 | }
8 |
--------------------------------------------------------------------------------
/Examples/archunit/src/main/java/com/example/reservation/controller/ReservationController.java:
--------------------------------------------------------------------------------
1 | package com.example.reservation.controller;
2 |
3 | public class ReservationController {
4 | public void reservationControllerFunction() {
5 | System.out.println("ReservationControllerFunction");
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/Examples/archunit/src/main/java/com/example/reservation/service/ReservationService.java:
--------------------------------------------------------------------------------
1 | package com.example.reservation.service;
2 |
3 | import com.example.reservation.controller.ReservationController;
4 | import org.springframework.beans.factory.annotation.Autowired;
5 |
6 | public class ReservationService {
7 | private ReservationController reservationController;
8 |
9 | @Autowired
10 | public ReservationService(ReservationController reservationController) {
11 | this.reservationController = reservationController;
12 | }
13 |
14 | public void reservationServiceFunction() {
15 | System.out.println("ReservationServiceFunction");
16 | reservationController.reservationControllerFunction();
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/Examples/assertj/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | Examples
7 | com.example
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | assertj
13 |
14 |
15 |
16 | org.assertj
17 | assertj-core
18 | test
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Examples/assertj/src/test/java/com/examples/AssertJTest.java:
--------------------------------------------------------------------------------
1 | package com.examples;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | import java.util.List;
6 |
7 | import static org.assertj.core.api.Assertions.assertThat;
8 | import static org.assertj.core.api.Assertions.assertThatThrownBy;
9 |
10 | public class AssertJTest {
11 | record Book(String title, String author) {
12 |
13 | }
14 |
15 | @Test
16 | void testStudent() {
17 | Book springBootBook = new Book("Spring Boot in Action", "Craig Walls");
18 | Book concurrencyBook = new Book("Java Concurrency in Practice", "Brian Goetz");
19 | List bookList = List.of(springBootBook, concurrencyBook);
20 |
21 | assertThat(springBootBook.title).isEqualTo("Spring Boot in Action");
22 | assertThat(springBootBook.title).isNotEqualTo(null);
23 | assertThat(concurrencyBook.title).startsWith("Java")
24 | .endsWith("Practice")
25 | .isEqualToIgnoringCase("java concurrency in practice");
26 |
27 | assertThat(bookList).hasSize(2)
28 | .contains(springBootBook, concurrencyBook)
29 | .doesNotContain(new Book("bla", "bla"));
30 |
31 | assertThat(bookList).extracting(Book::author).containsExactly("Craig Walls", "Brian Goetz")
32 | .doesNotContain("Johan");
33 |
34 | assertThat(bookList).filteredOn(book -> book.author.startsWith("B"))
35 | .containsOnly(concurrencyBook)
36 | .extracting(Book::title)
37 | .contains("Java Concurrency in Practice");
38 |
39 | assertThatThrownBy(() -> {throw new Exception("Oh no!");}).hasMessage("Oh no!");
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/Examples/autoservice/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | Examples
7 | com.example
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | autoservice
13 |
14 |
15 |
16 | com.google.auto.service
17 | auto-service-annotations
18 |
19 |
20 |
21 |
22 |
23 |
24 | org.apache.maven.plugins
25 | maven-compiler-plugin
26 | 3.13.0
27 |
28 | ${java.version}
29 |
30 |
31 | com.google.auto.service
32 | auto-service
33 | 1.1.1
34 |
35 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/Examples/autoservice/src/main/java/com/examples/CarService.java:
--------------------------------------------------------------------------------
1 | package com.examples;
2 |
3 | public interface CarService {
4 | public String retrieveBrand();
5 | }
6 |
--------------------------------------------------------------------------------
/Examples/autoservice/src/main/java/com/examples/PaganiCarService.java:
--------------------------------------------------------------------------------
1 | package com.examples;
2 |
3 | import com.google.auto.service.AutoService;
4 |
5 | @AutoService(CarService.class)
6 | public class PaganiCarService implements CarService {
7 | @Override
8 | public String retrieveBrand() {
9 | return "Pagani";
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/Examples/autoservice/src/main/java/com/examples/PorscheCarService.java:
--------------------------------------------------------------------------------
1 | package com.examples;
2 |
3 | import com.google.auto.service.AutoService;
4 |
5 | @AutoService(CarService.class)
6 | public class PorscheCarService implements CarService {
7 | @Override
8 | public String retrieveBrand() {
9 | return "Porsche";
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/Examples/autoservice/src/test/java/com/examples/AutoServiceTest.java:
--------------------------------------------------------------------------------
1 | package com.examples;
2 |
3 | import org.junit.jupiter.api.Assertions;
4 | import org.junit.jupiter.api.Test;
5 |
6 | import java.util.ArrayList;
7 | import java.util.List;
8 | import java.util.ServiceLoader;
9 |
10 | import static org.junit.jupiter.api.Assertions.assertEquals;
11 |
12 | public class AutoServiceTest {
13 |
14 | @Test
15 | void testAutoService() {
16 | ServiceLoader carServiceServiceLoader = ServiceLoader.load(CarService.class);
17 | assertEquals(2, carServiceServiceLoader.stream().count());
18 |
19 | List carServiceList = new ArrayList<>();
20 | carServiceServiceLoader.stream().forEach(c -> carServiceList.add(c.get()));
21 |
22 | for (CarService carService: carServiceList) {
23 | if (carService instanceof PaganiCarService) {
24 | Assertions.assertEquals("Pagani", carService.retrieveBrand());
25 | } else if (carService instanceof PorscheCarService) {
26 | Assertions.assertEquals("Porsche", carService.retrieveBrand());
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/Examples/autovalue/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | Examples
7 | com.example
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | autovalue
13 |
14 |
15 |
16 | com.google.auto.value
17 | auto-value-annotations
18 | provided
19 |
20 |
21 |
22 |
23 |
24 |
25 | org.apache.maven.plugins
26 | maven-compiler-plugin
27 | 3.13.0
28 |
29 | ${java.version}
30 |
31 |
32 | com.google.auto.value
33 | auto-value
34 | 1.11.0
35 |
36 |
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/Examples/autovalue/src/test/java/com/examples/AutoValueBook.java:
--------------------------------------------------------------------------------
1 | package com.examples;
2 |
3 | import com.google.auto.value.AutoValue;
4 |
5 | @AutoValue
6 | abstract class AutoValueBook {
7 | static AutoValueBook create(String author, String title) {
8 | return new AutoValue_AutoValueBook(author, title);
9 | }
10 |
11 | abstract String author();
12 | abstract String title();
13 | }
14 |
--------------------------------------------------------------------------------
/Examples/autovalue/src/test/java/com/examples/AutoValueTest.java:
--------------------------------------------------------------------------------
1 | package com.examples;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | import static org.junit.jupiter.api.Assertions.*;
6 |
7 | public class AutoValueTest {
8 |
9 | class Book {
10 | private String author;
11 | private String title;
12 |
13 | public Book(String author, String title) {
14 | this.author = author;
15 | this.title = title;
16 | }
17 |
18 | public String getAuthor() {
19 | return author;
20 | }
21 |
22 | public String getTitle() {
23 | return title;
24 | }
25 | }
26 |
27 | @Test
28 | void traditionalClassTest() {
29 | Book book1 = new Book("Craig Walls", "Spring Boot In Action");
30 | assertEquals("Craig Walls", book1.getAuthor());
31 |
32 | Book book2 = new Book("Craig Walls", "Spring Boot In Action");
33 | assertFalse(book1.equals(book2)); // only compares object reference, not content
34 | }
35 |
36 | @Test
37 | void autoValueTest() {
38 | AutoValueBook book1 = AutoValueBook.create("Craig Walls", "Spring Boot In Action");
39 | assertEquals("Craig Walls", book1.author());
40 |
41 | AutoValueBook book2 = AutoValueBook.create("Craig Walls", "Spring Boot In Action");
42 | assertTrue(book1.equals(book2));
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/Examples/awaitility/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | Examples
7 | com.example
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | awaitility
13 |
14 |
15 |
16 |
17 | org.awaitility
18 | awaitility
19 |
20 |
21 |
--------------------------------------------------------------------------------
/Examples/awaitility/src/test/java/com/example/AwaitilityTest.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | import java.util.ArrayList;
6 | import java.util.List;
7 | import java.util.concurrent.CompletableFuture;
8 |
9 | import static java.util.concurrent.TimeUnit.SECONDS;
10 | import static org.awaitility.Awaitility.await;
11 | import static org.junit.jupiter.api.Assertions.assertEquals;
12 |
13 | public class AwaitilityTest {
14 | private List exampleList = new ArrayList<>();
15 | void addToList(String value) {
16 | exampleList.add(value);
17 | }
18 |
19 | @Test
20 | void testAsynchronousOperation() throws InterruptedException {
21 | long start = System.currentTimeMillis();
22 |
23 | assertEquals(0, exampleList.size());
24 |
25 | CompletableFuture.runAsync(() -> {
26 | try {
27 | Thread.sleep(1000);
28 | } catch (InterruptedException e) {
29 | e.printStackTrace();
30 | }
31 | addToList("Test " + Math.random());
32 | });
33 | assertEquals(0, exampleList.size());
34 |
35 | await().atMost(2, SECONDS).until(() -> exampleList.size() == 1);
36 |
37 | assertEquals(1, exampleList.size());
38 |
39 | long finish = System.currentTimeMillis();
40 | long timeElapsed = finish - start;
41 | System.out.println("Duration with awaitility: " + timeElapsed);
42 | }
43 |
44 | @Test
45 | void testAsynchronousOperationWithThreadSleep() throws InterruptedException {
46 | long start = System.currentTimeMillis();
47 |
48 | assertEquals(0, exampleList.size());
49 |
50 | CompletableFuture.runAsync(() -> {
51 | try {
52 | Thread.sleep(1000);
53 | } catch (InterruptedException e) {
54 | e.printStackTrace();
55 | }
56 | addToList("Test " + Math.random());
57 | });
58 | assertEquals(0, exampleList.size());
59 | Thread.sleep(2000);
60 | assertEquals(1, exampleList.size());
61 |
62 | long finish = System.currentTimeMillis();
63 | long timeElapsed = finish - start;
64 | System.out.println("Duration with Thread.sleep(): " + timeElapsed);
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/Examples/classgraph/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | Examples
7 | com.example
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | classgraph
13 |
14 |
15 |
16 | io.github.classgraph
17 | classgraph
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/Examples/classgraph/src/test/java/com/examples/ClassGraphTest.java:
--------------------------------------------------------------------------------
1 | package com.examples;
2 |
3 | import io.github.classgraph.ClassGraph;
4 | import io.github.classgraph.ClassInfo;
5 | import io.github.classgraph.ScanResult;
6 | import org.junit.jupiter.api.Test;
7 |
8 | import java.lang.annotation.Annotation;
9 | import java.lang.reflect.Constructor;
10 |
11 | import static org.junit.jupiter.api.Assertions.assertEquals;
12 |
13 |
14 | public class ClassGraphTest {
15 |
16 | @Test
17 | void testClassGraph() {
18 | String pkg = "com.examples.classgraph";
19 | try (ScanResult scanResult =
20 | new ClassGraph()
21 | //.verbose() // Log to stderr
22 | //.enableAllInfo() // Scan classes, methods, fields, annotations
23 | .acceptPackages(pkg)
24 | .scan()) {
25 | for (ClassInfo routeClassInfo : scanResult.getAllClasses()) {
26 | assertEquals("class com.examples.classgraph.Car", routeClassInfo.loadClass().toString());
27 | assertEquals("@java.lang.Deprecated(forRemoval=false, since=\"\")", routeClassInfo.loadClass().getAnnotations()[0].toString());
28 | assertEquals("public com.examples.classgraph.Car()", routeClassInfo.loadClass().getConstructors()[0].toString());
29 | assertEquals("public com.examples.classgraph.Car(java.lang.String,java.lang.String)", routeClassInfo.loadClass().getConstructors()[1].toString());
30 | }
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/Examples/classgraph/src/test/java/com/examples/classgraph/Car.java:
--------------------------------------------------------------------------------
1 | package com.examples.classgraph;
2 |
3 | @Deprecated
4 | public class Car {
5 | private String brand;
6 | private String model;
7 | public Car() {
8 | }
9 |
10 | public Car(String brand, String model) {
11 | this.brand = brand;
12 | this.model = model;
13 | }
14 |
15 | public String getBrand() {
16 | return brand;
17 | }
18 |
19 | public void setBrand(String brand) {
20 | this.brand = brand;
21 | }
22 |
23 | public String getModel() {
24 | return model;
25 | }
26 |
27 | public void setModel(String model) {
28 | this.model = model;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/Examples/command.cmd:
--------------------------------------------------------------------------------
1 | mcs search equalsverifier
2 | mcs class-search EqualsVerifier
3 | mcs search nl.jqno.equalsverifier:equalsverifier:3.10
4 |
5 | jshell --class-path .
6 | # Use tab completion
7 |
8 | # int value = 2
9 |
10 | # Math.random * value
11 |
12 | # System.out.println($2)
13 |
14 | # double times10(double input) {
15 | # return input*10;
16 | # }
17 |
18 | # times10($2)
19 |
20 | # /vars
21 | # /methods
22 | # /list
23 | # /edit 1
24 |
25 | # /exit
26 |
27 | jbang init ThisIsTheWay.java
28 | jbang ThisIsTheWay.java
29 |
30 | jbang init -t cli ExampleCLI.java
31 | jbang ExampleCLI.java hellow
32 | # Add dependencies after /DEPS in the ExampleCLI.java file: com.googlecode.libphonenumber:libphonenumber:8.12.46
33 |
34 | # Add:
35 |
36 | # import com.google.i18n.phonenumbers.PhoneNumberUtil;
37 | # import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber;
38 |
39 | # private PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil.getInstance();
40 |
41 | # System.out.println("Hello " + greeting);
42 | # PhoneNumber parsedNumber = phoneNumberUtil.parse(greeting, "NL");
43 | # System.out.println("Phone number is valid: " + phoneNumberUtil.isValidNumber(parsedNumber));
44 |
45 | # jbang ExampleCLI.java hellow
46 | # jbang ExampleCLI.java 0612345678
47 |
48 | # JLink create custom Java runtime image
49 | cd Examples\src\main\java\
50 | javac -d . com\examples\jlink\HelloJlink.java
51 | jdeps -s com\examples\jlink\HelloJlink.class
52 |
53 | jlink --add-modules java.base,java.logging --output jlink-image --launcher launch=com.examples.jlink.HelloJlink
54 | jlink-image\bin\java.exe com.examples.jlink.HelloJlink
55 |
56 | # JLink with modules and launcher
57 | # Doesn't work? javac -d out com\examples\jlink\module-info.java
58 |
59 | javac -d out --module-path out com\examples\jlink\HelloJlink.java
60 | java --module-path out --module jlinkModule/com.examples.jlink.HelloJlink
61 | jlink --launcher customjrelauncher=jlinkModule/com.examples.jlink.HelloJlink --module-path "%JAVA_HOME%\jmods";out --add-modules jlinkModule --output jpackagecustumjre
62 | jpackagecustumjre\bin\customjrelauncher.bat
63 |
64 |
65 |
66 | # JPackage self contained Java package
67 | javac -d . com\examples\jpackage\Hellojpackage.java
68 | jar cf jpackageExample.jar com/examples/jpackage/*.class
69 |
70 | # Needs wix tools
71 | jpackage --input target/ --name jpackageExample --main-jar jpackageExample.jar --main-class com.examples.jlink.HelloJlink --type msi
72 |
73 | # module-info.java in the com/examples/jlink directory gives issues, removed it for now
74 | # module jlinkModule
75 | # {
76 | # requires java.logging;
77 | # }
78 |
79 | mvn test -Dmaven.test.skip
80 | mvnw test -Dmaven.test.skip
81 | mvnd test -Dmaven.test.skip
82 |
83 | jmc
84 |
85 | mvn jreleaser:assemble
86 | mvn jreleaser:changelog
87 |
88 |
--------------------------------------------------------------------------------
/Examples/dockerimages/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | Examples
7 | com.example
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | dockerimages
13 |
14 |
15 |
16 |
17 | org.springframework.boot
18 | spring-boot-starter-web
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 | com.google.cloud.tools
30 | jib-maven-plugin
31 | 3.4.3
32 |
33 |
34 | eclipse-temurin:21-jre
35 |
36 |
37 | jibexample
38 |
39 |
40 | com.example.CarApplication
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/Examples/dockerimages/src/main/java/com/example/Car.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import java.util.List;
4 |
5 | public class Car {
6 | private String brand;
7 | private String model;
8 | private List carPartList;
9 |
10 | public Car() {
11 | }
12 |
13 | public Car(String brand, String model, List carPartList) {
14 | this.brand = brand;
15 | this.model = model;
16 | this.carPartList = carPartList;
17 | }
18 |
19 | public String getBrand() {
20 | return brand;
21 | }
22 |
23 | public void setBrand(String brand) {
24 | this.brand = brand;
25 | }
26 |
27 | public String getModel() {
28 | return model;
29 | }
30 |
31 | public void setModel(String model) {
32 | this.model = model;
33 | }
34 |
35 | public List getCarPartList() {
36 | return carPartList;
37 | }
38 |
39 | public void setCarPartList(List carPartList) {
40 | this.carPartList = carPartList;
41 | }
42 |
43 | @Override
44 | public String toString() {
45 | return "Car{" +
46 | "brand='" + brand + '\'' +
47 | ", model='" + model + '\'' +
48 | ", carPartList=" + carPartList +
49 | '}';
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/Examples/dockerimages/src/main/java/com/example/CarApplication.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class CarApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(CarApplication.class, args);
11 | }
12 |
13 | }
--------------------------------------------------------------------------------
/Examples/dockerimages/src/main/java/com/example/CarPart.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | public class CarPart {
4 |
5 | private String name;
6 |
7 | private double price;
8 |
9 | public CarPart() {
10 | }
11 |
12 | public CarPart(String name, double price) {
13 | this.name = name;
14 | this.price = price;
15 | }
16 |
17 | public String getName() {
18 | return name;
19 | }
20 |
21 | public void setName(String name) {
22 | this.name = name;
23 | }
24 |
25 | public double getPrice() {
26 | return price;
27 | }
28 |
29 | public void setPrice(double price) {
30 | this.price = price;
31 | }
32 |
33 | @Override
34 | public String toString() {
35 | return "CarPart{" +
36 | "name='" + name + '\'' +
37 | ", price=" + price +
38 | '}';
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/Examples/dockerimages/src/main/java/com/example/CarRestController.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import org.springframework.web.bind.annotation.GetMapping;
4 | import org.springframework.web.bind.annotation.PostMapping;
5 | import org.springframework.web.bind.annotation.RequestBody;
6 | import org.springframework.web.bind.annotation.RestController;
7 |
8 | import java.util.ArrayList;
9 | import java.util.List;
10 |
11 | @RestController
12 | public class CarRestController {
13 | List carList = new ArrayList<>();
14 |
15 | public CarRestController() {
16 | CarPart huayraCarPart = new CarPart("engine", 8342.28);
17 | Car huayra = new Car("Pagani", "Huayra", List.of(huayraCarPart));
18 | carList.add(huayra);
19 | }
20 |
21 | @GetMapping("/car")
22 | public List retrieveCar() {
23 | return carList;
24 | }
25 |
26 | @PostMapping(path = "/car")
27 | public Car addCar(@RequestBody Car car) {
28 | carList.add(car);
29 | return car;
30 |
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/Examples/equalsverifier/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | Examples
7 | com.example
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | equalsverifier
13 |
14 |
15 |
16 |
17 | nl.jqno.equalsverifier
18 | equalsverifier
19 | 3.16.1
20 | test
21 |
22 |
23 |
24 |
25 |
26 |
27 | org.apache.maven.plugins
28 | maven-surefire-plugin
29 |
30 | -Dnet.bytebuddy.experimental=true
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/Examples/equalsverifier/src/test/java/com/example/EqualsVerifierTest.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import nl.jqno.equalsverifier.EqualsVerifier;
4 | import org.junit.jupiter.api.Assertions;
5 | import org.junit.jupiter.api.Test;
6 |
7 | import java.util.Objects;
8 |
9 | import static org.junit.jupiter.api.Assertions.assertTrue;
10 |
11 | public class EqualsVerifierTest {
12 |
13 | private String expectedErrorMessage = """
14 | EqualsVerifier found a problem in class com.example.EqualsVerifierTest$Student.
15 | -> hashCode: hashCodes should be equal:""";
16 |
17 | class Student {
18 | private String firstName;
19 | private String lastName;
20 |
21 | public Student(String firstName, String lastName) {
22 | this.firstName = firstName;
23 | this.lastName = lastName;
24 | }
25 |
26 | @Override
27 | public boolean equals(Object obj) {
28 | if (!(obj instanceof Student student)) {
29 | return false;
30 | }
31 | return firstName == student.firstName && lastName == student.firstName;
32 | }
33 | }
34 |
35 | class FixedStudent {
36 | private final String firstName; // Add final
37 | private final String lastName; // Add final
38 |
39 | public FixedStudent(String firstName, String lastName) {
40 | this.firstName = firstName;
41 | this.lastName = lastName;
42 | }
43 |
44 | @Override
45 | public final boolean equals(Object o) { // Add final and rewrite content
46 | if (this == o) return true;
47 | if (!(o instanceof FixedStudent)) return false;
48 | FixedStudent that = (FixedStudent) o;
49 | return Objects.equals(firstName, that.firstName) && Objects.equals(lastName, that.lastName);
50 | }
51 |
52 | @Override // Add hashcode
53 | public final int hashCode() {
54 | return Objects.hash(firstName, lastName);
55 | }
56 | }
57 |
58 | @Test
59 | public void testStudentEquals() {
60 | AssertionError assertionError = Assertions.assertThrows(AssertionError.class, () -> {
61 | EqualsVerifier.forClass(Student.class).verify();
62 | });
63 |
64 | assertTrue(assertionError.getMessage().startsWith(expectedErrorMessage));
65 | }
66 |
67 | @Test
68 | public void testFixedStudentEquals() {
69 | Assertions.assertDoesNotThrow(() -> {
70 | EqualsVerifier.forClass(FixedStudent.class).verify();
71 | });
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/Examples/flexmark/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | Examples
7 | com.example
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | flexmark
13 |
14 |
15 |
16 |
17 | org.springframework.boot
18 | spring-boot-starter-web
19 |
20 |
21 |
22 | com.vladsch.flexmark
23 | flexmark-all
24 |
25 |
26 |
--------------------------------------------------------------------------------
/Examples/flexmark/src/test/java/com/example/GitHubRepository.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4 |
5 | import java.time.LocalDateTime;
6 | import java.time.ZonedDateTime;
7 | import java.util.Date;
8 | import java.util.Locale;
9 |
10 | @JsonIgnoreProperties(ignoreUnknown = true)
11 | class GitHubRepository {
12 | private String html_url;
13 | private String pushed_at;
14 | private String updated_at;
15 | private String stargazers_count;
16 | private String watchers_count;
17 |
18 | public GitHubRepository() {
19 | }
20 |
21 | public String getHtml_url() {
22 | return html_url;
23 | }
24 |
25 | public void setHtml_url(String html_url) {
26 | this.html_url = html_url;
27 | }
28 |
29 | public String getPushed_at() {
30 | return pushed_at;
31 | }
32 |
33 | public void setPushed_at(String pushed_at) {
34 | this.pushed_at = pushed_at;
35 | }
36 |
37 | public String getUpdated_at() {
38 | return updated_at;
39 | }
40 |
41 | public void setUpdated_at(String updated_at) {
42 | this.updated_at = updated_at;
43 | }
44 |
45 | public String getStargazers_count() {
46 | return stargazers_count;
47 | }
48 |
49 | public void setStargazers_count(String stargazers_count) {
50 | this.stargazers_count = stargazers_count;
51 | }
52 |
53 | public String getWatchers_count() {
54 | return watchers_count;
55 | }
56 |
57 | public void setWatchers_count(String watchers_count) {
58 | this.watchers_count = watchers_count;
59 | }
60 |
61 | @Override
62 | public String toString() {
63 | ZonedDateTime lastPushedDateTime = ZonedDateTime.parse(pushed_at);
64 | String lastPush = " last push: " + lastPushedDateTime.getDayOfYear() + "-" + lastPushedDateTime.getMonth().toString().toLowerCase(Locale.ROOT) + "-" + lastPushedDateTime.getYear();
65 |
66 | String longAgo = "";
67 | ZonedDateTime now = ZonedDateTime.now();
68 | ZonedDateTime oneYearAgo = now.minusYears(1);
69 | ZonedDateTime twoYearsAgo = now.minusYears(2);
70 | if (lastPushedDateTime.isBefore(twoYearsAgo)) {
71 | longAgo = " !! No commit for more than 2 years !!";
72 | } else if (lastPushedDateTime.isBefore(oneYearAgo)) {
73 | longAgo = " !! No commit for more than 1 year !!";
74 | }
75 |
76 | return html_url + lastPush + " stargazers: " + stargazers_count + " watchers: " + watchers_count + longAgo;
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/Examples/gatling-kafka/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | Examples
7 | com.example
8 | 0.0.1-SNAPSHOT
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | 4.0.0
17 |
18 | gatling-kafka
19 |
20 |
21 |
22 |
23 | org.springframework.boot
24 | spring-boot-starter-test
25 | test
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 | org.springframework.boot
35 | spring-boot-starter-web
36 |
37 |
38 | io.gatling.highcharts
39 | gatling-charts-highcharts
40 | 3.10.5
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 | org.springframework.kafka
50 | spring-kafka
51 |
52 |
53 |
54 | org.testcontainers
55 | kafka
56 |
57 | test
58 |
59 |
60 | org.testcontainers
61 | junit-jupiter
62 | test
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 | io.gatling
71 | gatling-maven-plugin
72 | 4.9.6
73 |
74 |
75 |
76 |
--------------------------------------------------------------------------------
/Examples/gatling-kafka/src/main/java/com/example/KafkaConsumer.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.kafka.annotation.KafkaListener;
5 | import org.springframework.kafka.core.KafkaTemplate;
6 | import org.springframework.stereotype.Component;
7 |
8 | @Component
9 | public class KafkaConsumer {
10 |
11 | @Autowired
12 | private KafkaTemplate kafkaTemplate;
13 |
14 | @KafkaListener(topics = "request-topic", groupId = "test-groupId")
15 | public void receive(String string) {
16 | System.out.println("Received from request topic " + string);
17 | kafkaTemplate.send("response-topic", "Send to response topic " + string);
18 | }
19 | }
--------------------------------------------------------------------------------
/Examples/gatling-kafka/src/main/java/com/example/SpringKafkaApplication.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class SpringKafkaApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(SpringKafkaApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Examples/gatling-kafka/src/test/java/com/example/SpringBootKafkaTest.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import org.junit.jupiter.api.Test;
4 | import org.springframework.beans.factory.annotation.Autowired;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.kafka.annotation.KafkaListener;
7 | import org.springframework.kafka.core.KafkaTemplate;
8 | import org.springframework.test.context.DynamicPropertyRegistry;
9 | import org.springframework.test.context.DynamicPropertySource;
10 | import org.testcontainers.junit.jupiter.Container;
11 | import org.testcontainers.junit.jupiter.Testcontainers;
12 | import org.testcontainers.kafka.KafkaContainer;
13 | import org.testcontainers.utility.DockerImageName;
14 |
15 | import static java.util.concurrent.TimeUnit.SECONDS;
16 | import static org.awaitility.Awaitility.await;
17 | import static org.junit.jupiter.api.Assertions.assertEquals;
18 |
19 |
20 | @SpringBootTest
21 | @Testcontainers
22 | class SpringBootKafkaTest {
23 | @Container
24 | private static KafkaContainer kafka = new KafkaContainer(DockerImageName.parse("apache/kafka-native:3.8.0").asCompatibleSubstituteFor("apache/kafka"));
25 |
26 | @DynamicPropertySource
27 | static void overrideProperties(DynamicPropertyRegistry registry) {
28 | registry.add("spring.kafka.bootstrap-servers", kafka::getBootstrapServers);
29 | }
30 |
31 | private String response;
32 |
33 | @Autowired
34 | private KafkaTemplate kafkaTemplate;
35 |
36 | @KafkaListener(topics = "response-topic", groupId = "test-groupId")
37 | public void receive(String string) {
38 | response = string;
39 | System.out.println("Received from response topic in test " + response);
40 | }
41 |
42 | @Test
43 | public void testNotificationSending() throws InterruptedException {
44 | kafkaTemplate.send("request-topic", "Send to request topic in test: blablabla");
45 |
46 | await().atMost(5, SECONDS).until(() -> response != null);
47 | assertEquals("Send to response topic Send to request topic in test: blablabla", response);
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/Examples/gatling/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | Examples
7 | com.example
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | gatling
13 |
14 |
15 |
16 |
17 | org.springframework.boot
18 | spring-boot-starter-web
19 |
20 |
21 | io.gatling.highcharts
22 | gatling-charts-highcharts
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 | io.gatling
31 | gatling-maven-plugin
32 | 4.9.6
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/Examples/gatling/src/main/java/com/example/Car.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import java.util.List;
4 |
5 | public class Car {
6 | private String brand;
7 | private String model;
8 | private List carPartList;
9 |
10 | public Car() {
11 | }
12 |
13 | public Car(String brand, String model, List carPartList) {
14 | this.brand = brand;
15 | this.model = model;
16 | this.carPartList = carPartList;
17 | }
18 |
19 | public String getBrand() {
20 | return brand;
21 | }
22 |
23 | public void setBrand(String brand) {
24 | this.brand = brand;
25 | }
26 |
27 | public String getModel() {
28 | return model;
29 | }
30 |
31 | public void setModel(String model) {
32 | this.model = model;
33 | }
34 |
35 | public List getCarPartList() {
36 | return carPartList;
37 | }
38 |
39 | public void setCarPartList(List carPartList) {
40 | this.carPartList = carPartList;
41 | }
42 |
43 | @Override
44 | public String toString() {
45 | return "Car{" +
46 | "brand='" + brand + '\'' +
47 | ", model='" + model + '\'' +
48 | ", carPartList=" + carPartList +
49 | '}';
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/Examples/gatling/src/main/java/com/example/CarApplication.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class CarApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(CarApplication.class, args);
11 | }
12 |
13 | }
--------------------------------------------------------------------------------
/Examples/gatling/src/main/java/com/example/CarPart.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | public class CarPart {
4 |
5 | private String name;
6 |
7 | private double price;
8 |
9 | public CarPart() {
10 | }
11 |
12 | public CarPart(String name, double price) {
13 | this.name = name;
14 | this.price = price;
15 | }
16 |
17 | public String getName() {
18 | return name;
19 | }
20 |
21 | public void setName(String name) {
22 | this.name = name;
23 | }
24 |
25 | public double getPrice() {
26 | return price;
27 | }
28 |
29 | public void setPrice(double price) {
30 | this.price = price;
31 | }
32 |
33 | @Override
34 | public String toString() {
35 | return "CarPart{" +
36 | "name='" + name + '\'' +
37 | ", price=" + price +
38 | '}';
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/Examples/gatling/src/main/java/com/example/CarRestController.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import org.springframework.web.bind.annotation.GetMapping;
4 | import org.springframework.web.bind.annotation.PostMapping;
5 | import org.springframework.web.bind.annotation.RequestBody;
6 | import org.springframework.web.bind.annotation.RestController;
7 |
8 | import java.util.ArrayList;
9 | import java.util.List;
10 |
11 | @RestController
12 | public class CarRestController {
13 | private List carList = new ArrayList<>();
14 | private List carPartList = new ArrayList<>();
15 |
16 | public CarRestController() {
17 | CarPart huayraCarPart = new CarPart("engine", 8342.28);
18 | carPartList.add(huayraCarPart);
19 |
20 | Car huayra = new Car("Pagani", "Huayra", List.of(huayraCarPart));
21 | carList.add(huayra);
22 | }
23 |
24 | @GetMapping("/car")
25 | public List retrieveCar() {
26 | return carList;
27 | }
28 |
29 | @GetMapping("/carpart")
30 | public List retrieveCarPart() {
31 | return carPartList;
32 | }
33 |
34 | @PostMapping(path = "/car")
35 | public Car addCar(@RequestBody Car car) {
36 | carList.add(car);
37 | return car;
38 |
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/Examples/gatling/src/test/java/com/example/BasicSimulation.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import io.gatling.javaapi.core.*;
4 | import io.gatling.javaapi.http.*;
5 |
6 | import java.time.Duration;
7 |
8 | import static io.gatling.javaapi.core.CoreDsl.*;
9 | import static io.gatling.javaapi.http.HttpDsl.*;
10 |
11 | // First start the web application
12 | public class BasicSimulation extends Simulation {
13 |
14 | HttpProtocolBuilder httpProtocol = http
15 | .baseUrl("http://localhost:8080");
16 |
17 | ScenarioBuilder scn = scenario("BasicSimulation")
18 | .repeat(5).on(
19 | exec(http("car").get("/car")
20 | .check(status().is(200)))
21 | .pause(1)
22 | .exec(http("carpart")
23 | .get("/carpart")
24 | .check(status().is(200)))
25 | );
26 |
27 | {
28 | setUp(
29 | scn.injectOpen(rampUsers(8).during(Duration.ofSeconds(10)))
30 | ).protocols(httpProtocol);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/Examples/graphql/src/main/java/com/example/Account.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import java.util.Arrays;
4 | import java.util.List;
5 |
6 | public record Account (String id, int number, String userId){
7 | private static List accounts = Arrays.asList(
8 | new Account("account-1", 42, "user-1"),
9 | new Account("account-2", 21, "user-2"),
10 | new Account("account-3", 84, "user-3")
11 | );
12 |
13 | public static Account getById(String id) {
14 | return accounts.stream()
15 | .filter(account -> account.id().equals(id))
16 | .findFirst()
17 | .orElse(null);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Examples/graphql/src/main/java/com/example/AccountController.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import org.springframework.graphql.data.method.annotation.Argument;
4 | import org.springframework.graphql.data.method.annotation.QueryMapping;
5 | import org.springframework.graphql.data.method.annotation.SchemaMapping;
6 | import org.springframework.stereotype.Controller;
7 |
8 | @Controller
9 | public class AccountController {
10 | @QueryMapping
11 | public Account accountById(@Argument String id) {
12 | return Account.getById(id);
13 | }
14 |
15 | @SchemaMapping
16 | public User user(Account account) {
17 | return User.getById(account.userId());
18 | }
19 | }
--------------------------------------------------------------------------------
/Examples/graphql/src/main/java/com/example/GraphqlServerApplication.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class GraphqlServerApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(GraphqlServerApplication.class, args);
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/Examples/graphql/src/main/java/com/example/User.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import java.util.Arrays;
4 | import java.util.List;
5 |
6 | public record User(String id, String firstName, String lastName){
7 |
8 | private static List users = Arrays.asList(
9 | new User("user-1", "James", "Gosling"),
10 | new User("user-2", "Patrick", "Naughton"),
11 | new User("user-3", "Mike", "Sheridan")
12 | );
13 |
14 | public static User getById(String id) {
15 | return users.stream()
16 | .filter(user -> user.id().equals(id))
17 | .findFirst()
18 | .orElse(null);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Examples/graphql/src/main/resources/graphql/schema.graphqls:
--------------------------------------------------------------------------------
1 | type Query {
2 | accountById(id: ID): Account
3 | }
4 |
5 | type Account {
6 | id: ID
7 | number: Int
8 | user: User
9 | }
10 |
11 | type User {
12 | id: ID
13 | firstName: String
14 | lastName: String
15 | }
--------------------------------------------------------------------------------
/Examples/graphql/src/test/java/com/example/AccountControllerTests.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import com.example.graphql.model.client.AccountByIdGraphQLQuery;
4 | import com.example.graphql.model.client.AccountByIdProjectionRoot;
5 | import com.example.graphql.model.types.Account;
6 | import com.netflix.graphql.dgs.client.codegen.GraphQLQueryRequest;
7 | import org.junit.jupiter.api.Test;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.boot.test.autoconfigure.graphql.GraphQlTest;
10 | import org.springframework.graphql.test.tester.GraphQlTester;
11 |
12 | import static org.junit.jupiter.api.Assertions.assertEquals;
13 | import static org.junit.jupiter.api.Assertions.assertNull;
14 |
15 | @GraphQlTest(AccountController.class)
16 | public class AccountControllerTests {
17 |
18 | @Autowired
19 | private GraphQlTester graphQlTester;
20 |
21 | @Test
22 | void shouldGetFirstAccount() {
23 | // arrange
24 | GraphQLQueryRequest graphQLQueryRequest = new GraphQLQueryRequest(
25 | AccountByIdGraphQLQuery.newRequest().id("account-1").build()
26 | , new AccountByIdProjectionRoot().id().number() );
27 | // act
28 | Account accountById = this.graphQlTester
29 | .document(graphQLQueryRequest.serialize())
30 | .execute().path("accountById").entity(Account.class).get();
31 | // assert
32 | assertEquals("account-1", accountById.getId());
33 | assertEquals(42, accountById.getNumber());
34 | assertNull(accountById.getUser());
35 | }
36 | @Test
37 | void shouldGetFirstAccountWithUser() {
38 | // arrange
39 | GraphQLQueryRequest graphQLQueryRequest = new GraphQLQueryRequest(
40 | AccountByIdGraphQLQuery.newRequest().id("account-1").build()
41 | , new AccountByIdProjectionRoot().id().number().user().firstName().lastName() );
42 | // act
43 | Account accountById = this.graphQlTester
44 | .document(graphQLQueryRequest.serialize())
45 | .execute().path("accountById").entity(Account.class).get();
46 | // assert
47 | assertEquals("account-1", accountById.getId());
48 | assertEquals(42, accountById.getNumber());
49 | assertEquals("James", accountById.getUser().getFirstName());
50 | assertEquals("Gosling", accountById.getUser().getLastName());
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/Examples/graphql/src/test/java/com/example/GraphqlServerApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import org.junit.jupiter.api.Test;
4 | import org.springframework.boot.test.context.SpringBootTest;
5 |
6 | @SpringBootTest
7 | class GraphqlServerApplicationTests {
8 |
9 | @Test
10 | void contextLoads() {
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/Examples/guice/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | Examples
7 | com.example
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | guice
13 |
14 |
15 |
16 | com.google.inject
17 | guice
18 |
19 |
20 |
--------------------------------------------------------------------------------
/Examples/guice/src/test/java/com/examples/BookService.java:
--------------------------------------------------------------------------------
1 | package com.examples;
2 |
3 | import com.google.inject.Inject;
4 |
5 | class BookService {
6 | @Inject
7 | private PrintService printService;
8 |
9 | public String handleBook() {
10 | return printService.enrichInfo("The Hobbit");
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Examples/guice/src/test/java/com/examples/GuiceTest.java:
--------------------------------------------------------------------------------
1 | package com.examples;
2 |
3 | import com.google.inject.Guice;
4 | import com.google.inject.Injector;
5 | import org.junit.jupiter.api.Test;
6 |
7 | import static org.junit.jupiter.api.Assertions.assertEquals;
8 |
9 | public class GuiceTest {
10 | @Test
11 | void testGuice() {
12 | Injector injector = Guice.createInjector();
13 |
14 | BookService bookService = injector.getInstance(BookService.class);
15 |
16 | assertEquals("Much richer The Hobbit", bookService.handleBook());
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/Examples/guice/src/test/java/com/examples/PrintService.java:
--------------------------------------------------------------------------------
1 | package com.examples;
2 |
3 | import com.google.inject.Singleton;
4 |
5 | @Singleton
6 | class PrintService {
7 | public String enrichInfo(String info) {
8 | return "Much richer " + info;
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/Examples/handlebars/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | Examples
7 | com.example
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | handlebars
13 |
14 |
15 |
16 |
17 | com.github.jknack
18 | handlebars
19 |
20 |
21 |
--------------------------------------------------------------------------------
/Examples/handlebars/src/test/java/com/example/HandlebarsTest.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import com.github.jknack.handlebars.Handlebars;
4 | import com.github.jknack.handlebars.Template;
5 | import org.junit.jupiter.api.Test;
6 |
7 | import java.io.File;
8 | import java.io.IOException;
9 | import java.util.Arrays;
10 | import java.util.List;
11 | import java.util.Random;
12 |
13 | import static org.junit.jupiter.api.Assertions.assertTrue;
14 |
15 | // see test/resources/HandlebarsExample.hbs
16 | public class HandlebarsTest {
17 | record Expertise(String technology, int years) {}
18 | record Person(String firstName, String lastName) {}
19 | record Vacancy(String title, Person person, String functionTitle, List expertiseList, int salary, int workinghours, int vacationdays) {}
20 |
21 | @Test
22 | void testHandlebars() throws IOException {
23 | String classpath = System.getProperty("java.class.path");
24 | String[] classPathValues = classpath.split(File.pathSeparator);
25 | System.out.println(Arrays.toString(classPathValues));
26 |
27 | Handlebars handlebars = new Handlebars();
28 |
29 | Template template = handlebars.compile("HandlebarsExample");
30 |
31 | Random random = new Random();
32 | Person person = new Person("{{}}", "Janssen");
33 | Expertise expertise1 = new Expertise("GraalVM", 20);
34 | Expertise expertise2 = new Expertise("PHP", random.nextInt(8));
35 | Expertise expertise3 = new Expertise("Spring Boot", random.nextInt(8));
36 | Expertise expertise4 = new Expertise("J2EE (yes I know it should be Java EE or Jakarta EE ;))", random.nextInt(15));
37 | List expertiseList = List.of(expertise1, expertise2, expertise3, expertise4);
38 | Vacancy vacancy = new Vacancy("New super duper function", person, "Senior vice president principal code ninja turtle warrior architect", expertiseList, random.nextInt(2000), (int)(Math.random()*(60-40))+40, 20);
39 | String templateString = template.apply(vacancy);
40 |
41 | System.out.println(templateString);
42 | assertTrue(templateString.contains("Janssen"));
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/Examples/handlebars/src/test/resources/HandlebarsExample.hbs:
--------------------------------------------------------------------------------
1 |
2 |
3 | {{title}}
4 |
5 |
6 | {{#with person ~}}
7 | Hello {{firstName}} {{lastName}} would you be interested in this vacancy?
8 | {{/with ~}}
9 |
10 | {{functionTitle ~}}
11 | Expected knowledge:
12 |
13 | {{#each expertiseList ~}}
14 | - {{technology}} (years of experience {{years}})
15 | {{/each ~}}
16 |
17 | To provide a good work life balance you only work {{workinghours}} hours per week
18 | We care about your wellbeing so you get an awesome {{wrong_name}} days off per year.
19 |
20 | Expected salary: an awesome above market salary of at least {{salary}} euro
21 |
22 |
--------------------------------------------------------------------------------
/Examples/itext/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | Examples
7 | com.example
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | itext
13 |
14 |
15 |
16 |
17 | com.itextpdf
18 | itextpdf
19 |
20 |
21 |
--------------------------------------------------------------------------------
/Examples/itext/src/test/java/com/example/iTextTest.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import com.itextpdf.text.*;
4 | import com.itextpdf.text.pdf.PdfWriter;
5 | import org.junit.jupiter.api.Test;
6 |
7 | import java.io.File;
8 | import java.io.FileNotFoundException;
9 | import java.io.FileOutputStream;
10 | import java.nio.file.Path;
11 | import java.nio.file.Paths;
12 |
13 | public class iTextTest {
14 | @Test
15 | void testiText() throws FileNotFoundException, DocumentException {
16 |
17 | Document document = new Document();
18 |
19 | Path resourceDirectory = Paths.get("target", "POI.pdf");
20 |
21 | PdfWriter.getInstance(document, new FileOutputStream(resourceDirectory.toFile()));
22 | document.open();
23 |
24 | Font larger = new Font();
25 | larger.setSize(14);
26 |
27 | Paragraph paragraph1 = new Paragraph();
28 | String firstParagraph = """
29 | Java is a high-level, class-based, object-oriented programming language that is designed to have as few implementation dependencies as possible. It is a general-purpose programming language intended to let programmers write once, run anywhere (WORA),[17] meaning that compiled Java code can run on all platforms that support Java without the need to recompile.[18] Java applications are typically compiled to bytecode that can run on any Java virtual machine (JVM) regardless of the underlying computer architecture. The syntax of Java is similar to C and C++, but has fewer low-level facilities than either of them. The Java runtime provides dynamic capabilities (such as reflection and runtime code modification) that are typically not available in traditional compiled languages. As of 2019, Java was one of the most popular programming languages in use according to GitHub,[19][20] particularly for client–server web applications, with a reported 9 million developers.[21]""";
30 | document.add(new Paragraph(firstParagraph, larger));
31 |
32 | Paragraph paragraph2 = new Paragraph();
33 | String secondParagraph = """
34 | Java was originally developed by James Gosling at Sun Microsystems and released in May 1995 as a core component of Sun Microsystems' Java platform. The original and reference implementation Java compilers, virtual machines, and class libraries were originally released by Sun under proprietary licenses. As of May 2007, in compliance with the specifications of the Java Community Process, Sun had relicensed most of its Java technologies under the GPL-2.0-only license. Oracle offers its own HotSpot Java Virtual Machine, however the official reference implementation is the OpenJDK JVM which is free open-source software and used by most developers and is the default JVM for almost all Linux distributions.""";
35 | document.add(new Paragraph(secondParagraph, larger));
36 |
37 | Font smallBold = new Font();
38 | smallBold.setStyle(Font.BOLD);
39 | smallBold.setSize(8);
40 |
41 | document.add(new Paragraph("From: https://en.wikipedia.org/wiki/Java_(programming_language)", smallBold));
42 |
43 | document.close();
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/Examples/jacoco-agent/README.md:
--------------------------------------------------------------------------------
1 | # Extract jacocoagent.jar and jacococli.jar from the latest zip release build on https://www.eclemma.org/jacoco/
2 |
3 | mvn clean package
4 |
5 | Start the application with the Java agent:
6 | java -javaagent:jacocoagent.jar=destfile=target\jacoco.exec,append=false,includes=com.example.* -jar target\jacoco-agent-0.0.1-SNAPSHOT.jar
7 |
8 | GOTO http://localhost:8080/car
9 |
10 | Stop the application
11 |
12 | Create the report:
13 | java -jar jacococli.jar report target\jacoco.exec --classfiles target\classes\com\example\ --sourcefiles src\main\java\ --html target\
14 |
--------------------------------------------------------------------------------
/Examples/jacoco-agent/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | Examples
7 | com.example
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | jacoco-agent
13 |
14 |
15 |
16 | org.springframework.boot
17 | spring-boot-starter-web
18 |
19 |
20 |
21 |
22 |
23 | org.springframework.boot
24 | spring-boot-maven-plugin
25 |
26 | com.example.CarApplication
27 |
28 |
29 |
30 | org.codehaus.mojo
31 | exec-maven-plugin
32 | 3.3.0
33 |
34 |
35 | test
36 | verify
37 |
38 | exec
39 |
40 |
41 | test.cmd
42 |
43 |
44 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/Examples/jacoco-agent/src/main/java/com/example/Car.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import java.util.List;
4 |
5 | public class Car {
6 | private String brand;
7 | private String model;
8 | private List carPartList;
9 |
10 | public Car() {
11 | }
12 |
13 | public Car(String brand, String model, List carPartList) {
14 | this.brand = brand;
15 | this.model = model;
16 | this.carPartList = carPartList;
17 | }
18 |
19 | public String getBrand() {
20 | return brand;
21 | }
22 |
23 | public void setBrand(String brand) {
24 | this.brand = brand;
25 | }
26 |
27 | public String getModel() {
28 | return model;
29 | }
30 |
31 | public void setModel(String model) {
32 | this.model = model;
33 | }
34 |
35 | public List getCarPartList() {
36 | return carPartList;
37 | }
38 |
39 | public void setCarPartList(List carPartList) {
40 | this.carPartList = carPartList;
41 | }
42 |
43 | @Override
44 | public String toString() {
45 | return "Car{" +
46 | "brand='" + brand + '\'' +
47 | ", model='" + model + '\'' +
48 | ", carPartList=" + carPartList +
49 | '}';
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/Examples/jacoco-agent/src/main/java/com/example/CarApplication.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class CarApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(CarApplication.class, args);
11 | }
12 |
13 | }
--------------------------------------------------------------------------------
/Examples/jacoco-agent/src/main/java/com/example/CarPart.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | public class CarPart {
4 |
5 | private String name;
6 |
7 | private double price;
8 |
9 | public CarPart() {
10 | }
11 |
12 | public CarPart(String name, double price) {
13 | this.name = name;
14 | this.price = price;
15 | }
16 |
17 | public String getName() {
18 | return name;
19 | }
20 |
21 | public void setName(String name) {
22 | this.name = name;
23 | }
24 |
25 | public double getPrice() {
26 | return price;
27 | }
28 |
29 | public void setPrice(double price) {
30 | this.price = price;
31 | }
32 |
33 | @Override
34 | public String toString() {
35 | return "CarPart{" +
36 | "name='" + name + '\'' +
37 | ", price=" + price +
38 | '}';
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/Examples/jacoco-agent/src/main/java/com/example/CarRestController.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import org.springframework.web.bind.annotation.GetMapping;
4 | import org.springframework.web.bind.annotation.PostMapping;
5 | import org.springframework.web.bind.annotation.RequestBody;
6 | import org.springframework.web.bind.annotation.RestController;
7 |
8 | import java.util.ArrayList;
9 | import java.util.List;
10 |
11 | @RestController
12 | public class CarRestController {
13 | List carList = new ArrayList<>();
14 |
15 | public CarRestController() {
16 | CarPart huayraCarPart = new CarPart("engine", 8342.28);
17 | Car huayra = new Car("Pagani", "Huayra", List.of(huayraCarPart));
18 | carList.add(huayra);
19 | }
20 |
21 | @GetMapping("/car")
22 | public List retrieveCar() {
23 | return carList;
24 | }
25 |
26 | @PostMapping(path = "/car")
27 | public Car addCar(@RequestBody Car car) {
28 | carList.add(car);
29 | return car;
30 |
31 | }
32 |
33 | @GetMapping("/exit")
34 | public void exit() {
35 | System.exit(1);
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/Examples/jacoco-agent/test.cmd:
--------------------------------------------------------------------------------
1 | REM Extract jacocoagent.jar and jacococli.jar from the latest zip release build on https://www.eclemma.org/jacoco/
2 | call mvn clean package
3 |
4 | REM Start the application with the Java agent as a background process:
5 | START /MIN java -javaagent:jacocoagent.jar=destfile=target\jacoco.exec,append=false,includes=com.example.* -jar target\jacoco-agent-0.0.1-SNAPSHOT.jar
6 |
7 | call curl http://localhost:8080/car
8 | call curl http://localhost:8080/car
9 | call curl http://localhost:8080/exit
10 |
11 | REM Create the report:
12 | call java -jar jacococli.jar report target\jacoco.exec --classfiles target\classes\com\example\ --sourcefiles src\main\java\ --html target\
--------------------------------------------------------------------------------
/Examples/javapoet/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | Examples
7 | com.example
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | javapoet
13 |
14 |
15 |
16 |
17 | com.palantir.javapoet
18 | javapoet
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Examples/jdbi/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | Examples
7 | com.example
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | jdbi
13 |
14 |
15 |
16 | org.jdbi
17 | jdbi3-core
18 |
19 |
20 | com.h2database
21 | h2
22 | runtime
23 |
24 |
25 |
--------------------------------------------------------------------------------
/Examples/jdbi/src/test/java/com/examples/Book.java:
--------------------------------------------------------------------------------
1 | package com.examples;
2 |
3 | public class Book {
4 | private int id;
5 | private String title;
6 |
7 | public Book() {
8 | }
9 |
10 | public Book(int id) {
11 | this.id = id;
12 | }
13 |
14 | public Book(String title) {
15 | this.title = title;
16 | }
17 |
18 | public Book(int id, String title) {
19 | this.id = id;
20 | this.title = title;
21 | }
22 |
23 | public int getId() {
24 | return id;
25 | }
26 |
27 | public void setId(int id) {
28 | this.id = id;
29 | }
30 |
31 | public String getTitle() {
32 | return title;
33 | }
34 |
35 | public void setTitle(String title) {
36 | this.title = title;
37 | }
38 | }
--------------------------------------------------------------------------------
/Examples/jdbi/src/test/java/com/examples/JdbiTest.java:
--------------------------------------------------------------------------------
1 | package com.examples;
2 |
3 | import org.jdbi.v3.core.Jdbi;
4 | import org.junit.jupiter.api.Test;
5 |
6 | import java.util.List;
7 |
8 | import static org.junit.jupiter.api.Assertions.assertEquals;
9 |
10 | public class JdbiTest {
11 |
12 | @Test
13 | void testDB() {
14 | Jdbi jdbi = Jdbi.create("jdbc:h2:mem:test"); // (H2 in-memory database)
15 |
16 | List bookList = jdbi.withHandle(handle -> {
17 | handle.execute("CREATE TABLE \"book\" (id INTEGER PRIMARY KEY, \"title\" VARCHAR)");
18 |
19 | handle.createUpdate("INSERT INTO \"book\" (id, \"title\") VALUES (:id, :title)")
20 | .bindBean(new Book(0, "Spring Boot In Action"))
21 | .execute();
22 |
23 | handle.createUpdate("INSERT INTO \"book\" (id, \"title\") VALUES (:id, :title)")
24 | .bindBean(new Book(1, "Java Concurrency in Practice"))
25 | .execute();
26 |
27 | return handle.createQuery("SELECT * FROM \"book\" ORDER BY \"title\"")
28 | .mapToBean(Book.class)
29 | .list();
30 | });
31 |
32 | for (Book book: bookList) {
33 | System.out.println(book.getTitle());
34 | }
35 | assertEquals(2, bookList.size());
36 | assertEquals("Java Concurrency in Practice", bookList.get(0).getTitle());
37 | assertEquals("Spring Boot In Action", bookList.get(1).getTitle());
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/Examples/jfrunit/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | Examples
7 | com.example
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | jfrunit
13 |
14 |
15 |
16 |
17 | org.moditect.jfrunit
18 | jfrunit-core
19 |
20 |
21 |
--------------------------------------------------------------------------------
/Examples/jfrunit/src/test/java/com/example/JfrUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import org.junit.jupiter.api.Test;
4 | import org.moditect.jfrunit.EnableEvent;
5 | import org.moditect.jfrunit.JfrEventTest;
6 | import org.moditect.jfrunit.JfrEvents;
7 | import org.moditect.jfrunit.events.GarbageCollection;
8 | import org.moditect.jfrunit.events.JfrEventTypes;
9 | import org.moditect.jfrunit.events.ThreadSleep;
10 |
11 | import java.time.Duration;
12 |
13 | import static org.moditect.jfrunit.ExpectedEvent.event;
14 | import static org.moditect.jfrunit.JfrEventsAssert.assertThat;
15 |
16 |
17 | @JfrEventTest
18 | public class JfrUnitTest {
19 |
20 | public JfrEvents jfrEvents = new JfrEvents();
21 |
22 | @Test
23 | @EnableEvent(GarbageCollection.EVENT_NAME)
24 | @EnableEvent(ThreadSleep.EVENT_NAME)
25 | public void shouldHaveGcAndSleepEvents() throws Exception {
26 | System.gc();
27 | Thread.sleep(42);
28 |
29 | jfrEvents.awaitEvents();
30 |
31 | assertThat(jfrEvents).contains(JfrEventTypes.GARBAGE_COLLECTION);
32 | assertThat(jfrEvents)
33 | .contains(event("jdk.ThreadSleep")
34 | .with("time", Duration.ofMillis(42)));
35 | }
36 | }
--------------------------------------------------------------------------------
/Examples/jlink/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | Examples
7 | com.example
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | jlink
13 |
14 |
--------------------------------------------------------------------------------
/Examples/jlink/src/main/java/com/examples/jlink/HelloJlink.java:
--------------------------------------------------------------------------------
1 | package com.examples.jlink;
2 |
3 | import java.util.logging.Logger;
4 |
5 | public class HelloJlink {
6 | private static final Logger LOG = Logger.getLogger(HelloJlink.class.getName());
7 |
8 | public static void main(String[] args) {
9 | LOG.info("Hello JLink!");
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/Examples/jmolecules/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | Examples
7 | com.example
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | jmolecules
13 |
14 |
15 |
16 | org.jmolecules
17 | jmolecules-ddd
18 |
19 |
20 | com.h2database
21 | h2
22 | runtime
23 |
24 |
25 | org.springframework.boot
26 | spring-boot-starter-data-jpa
27 |
28 |
29 | org.jmolecules.integrations
30 | jmolecules-spring-data-jpa
31 |
32 |
33 | org.projectlombok
34 | lombok
35 | provided
36 |
37 |
38 | org.hibernate.validator
39 | hibernate-validator
40 | 8.0.1.Final
41 | test
42 |
43 |
44 | org.glassfish
45 | jakarta.el
46 | 4.0.2
47 | test
48 |
49 |
50 |
51 |
52 |
53 |
54 | net.bytebuddy
55 | byte-buddy-maven-plugin
56 | 1.14.17
57 |
58 |
59 |
60 | transform
61 |
62 |
63 |
64 |
65 |
66 | org.jmolecules.integrations
67 | jmolecules-bytebuddy
68 | 1.6.0
69 |
70 |
71 |
72 |
73 |
74 |
75 |
--------------------------------------------------------------------------------
/Examples/jmolecules/src/main/java/com/example/Address.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import com.example.Address.AddressId;
4 | import lombok.Getter;
5 | import lombok.Value;
6 | import org.jmolecules.ddd.types.Entity;
7 | import org.jmolecules.ddd.types.Identifier;
8 |
9 | import java.util.UUID;
10 |
11 | @Getter
12 | public class Address implements Entity {
13 |
14 | private Address.AddressId id;
15 | private final String zipCode;
16 |
17 | public Address(String zipCode) {
18 | this.id = AddressId.of(UUID.randomUUID());
19 | this.zipCode = zipCode;
20 | }
21 |
22 | @Value(staticConstructor = "of")
23 | public static class AddressId implements Identifier {
24 | private final UUID id;
25 | }
26 | }
--------------------------------------------------------------------------------
/Examples/jmolecules/src/main/java/com/example/Student.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 |
4 | import com.example.Student.StudentId;
5 | import lombok.Getter;
6 | import lombok.Value;
7 | import org.jmolecules.ddd.types.AggregateRoot;
8 | import org.jmolecules.ddd.types.Identifier;
9 |
10 | import java.util.ArrayList;
11 | import java.util.List;
12 | import java.util.UUID;
13 |
14 | //No need for Constructor, @Entity, @EmbeddedId, @OneToMany, serialVersionUID
15 | @Getter
16 | public class Student implements AggregateRoot {
17 |
18 | private final StudentId id;
19 | private String name;
20 | private List addressList = new ArrayList<>();
21 |
22 | public Student(String name, List addressList) {
23 | this.id = StudentId.of(UUID.randomUUID().toString());
24 | this.name = name;
25 | this.addressList = addressList;
26 | }
27 |
28 | @Value(staticConstructor = "of")
29 | public static class StudentId implements Identifier {
30 | private final String id;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/Examples/jmolecules/src/main/java/com/example/Students.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import com.example.Student.StudentId;
4 |
5 | import org.jmolecules.spring.AssociationResolver;
6 | import org.springframework.data.repository.CrudRepository;
7 |
8 |
9 | public interface Students extends CrudRepository, AssociationResolver {
10 | }
--------------------------------------------------------------------------------
/Examples/jmolecules/src/main/java/com/example/jMoleculesApplication.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class jMoleculesApplication {
8 | public static void main(String[] args) {
9 | SpringApplication.run(jMoleculesApplication.class, args);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/Examples/jmolecules/src/test/java/com/example/jMoleculesTest.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 |
4 | import lombok.RequiredArgsConstructor;
5 | import org.junit.jupiter.api.Test;
6 | import org.springframework.boot.test.context.SpringBootTest;
7 | import org.springframework.context.ConfigurableApplicationContext;
8 |
9 | import java.util.List;
10 | import java.util.Optional;
11 |
12 | import static org.junit.jupiter.api.Assertions.assertEquals;
13 |
14 | @SpringBootTest(classes = jMoleculesApplication.class)
15 | @RequiredArgsConstructor
16 | class jMoleculesTest {
17 |
18 | private final ConfigurableApplicationContext context;
19 |
20 | @Test
21 | void testjMolecules() {
22 | Address address = new Address("42");
23 | Students students = context.getBean(Students.class);
24 | Student storedStudent = students.save(new Student("James", List.of(address)));
25 | Optional retrievedStudent = students.findById(storedStudent.getId());
26 | assertEquals("James", retrievedStudent.get().getName());
27 | }
28 | }
--------------------------------------------------------------------------------
/Examples/jobrunr/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | Examples
7 | com.example
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | jobrunr
13 |
14 |
15 |
16 | org.springframework.boot
17 | spring-boot-starter-web
18 |
19 |
20 |
21 | org.jobrunr
22 | jobrunr-spring-boot-3-starter
23 |
24 |
25 |
26 |
27 | org.springframework.boot
28 | spring-boot-starter-data-jpa
29 |
30 |
31 | com.h2database
32 | h2
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/Examples/jobrunr/src/main/java/com/examples/jobrunr/JobRunrApplication.java:
--------------------------------------------------------------------------------
1 | package com.examples.jobrunr;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class JobRunrApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(JobRunrApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Examples/jobrunr/src/main/java/com/examples/jobrunr/JobRunrService.java:
--------------------------------------------------------------------------------
1 | package com.examples.jobrunr;
2 |
3 | import org.jobrunr.jobs.annotations.Job;
4 | import org.jobrunr.spring.annotations.Recurring;
5 | import org.springframework.stereotype.Service;
6 |
7 | @Service
8 | public class JobRunrService {
9 |
10 | @Job(name = "The sample job with variable %0", retries = 1)
11 | public void annotatedJob(String variable) throws Exception {
12 | System.out.println("Annotated job " + variable);
13 | throw new Exception("Trigger retry");
14 | }
15 |
16 | @Recurring(id="a-recurring-job", cron="* * * * *")
17 | @Job(name = "My Recurring job")
18 | public void aRecurringJob() {
19 | System.out.println("This wil run every minute");
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Examples/jobrunr/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | # Configuration for JobRunr
2 | org.jobrunr.background-job-server.enabled=true
3 | org.jobrunr.dashboard.enabled=true
4 | org.jobrunr.background-job-server.poll-interval-in-seconds=5
5 |
6 | # Configuration of Datasource that will automatically be used by JobRunr
7 | spring.datasource.url=jdbc:h2:mem:testdb
8 | spring.datasource.driverClassName=org.h2.Driver
9 | spring.datasource.username=sa
10 | spring.datasource.password=password
11 | spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
--------------------------------------------------------------------------------
/Examples/jobrunr/src/test/java/com/examples/JobRunrTest.java:
--------------------------------------------------------------------------------
1 | package com.examples;
2 |
3 |
4 | import com.examples.jobrunr.JobRunrApplication;
5 | import com.examples.jobrunr.JobRunrService;
6 | import org.jobrunr.scheduling.JobScheduler;
7 | import org.jobrunr.scheduling.cron.Cron;
8 | import org.junit.jupiter.api.Test;
9 | import org.springframework.beans.factory.annotation.Autowired;
10 | import org.springframework.boot.test.context.SpringBootTest;
11 |
12 | import java.time.LocalDateTime;
13 |
14 | // Also see http://localhost:8000/
15 | @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = JobRunrApplication.class)
16 | public class JobRunrTest {
17 |
18 | @Autowired
19 | private JobScheduler jobScheduler;
20 |
21 | @Autowired
22 | private JobRunrService jobRunrService;
23 |
24 | @Test
25 | void testJobRunr() throws InterruptedException {
26 | jobScheduler.enqueue(() -> System.out.println(" Enqueued job"));
27 |
28 | jobScheduler.schedule(LocalDateTime.now().plusSeconds(2), () -> System.out.println(" Scheduled job"));
29 |
30 | jobScheduler.scheduleRecurrently(Cron.every15seconds(), () -> System.out.println("Recurring job"));
31 |
32 | jobScheduler.enqueue(() -> jobRunrService.annotatedJob("retry"));
33 |
34 | Thread.sleep(30000);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/Examples/jooq/src/main/java/com/examples/jOOQApplication.java:
--------------------------------------------------------------------------------
1 | package com.examples;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 |
7 | @SpringBootApplication
8 | public class jOOQApplication {
9 |
10 | public static void main(String[] args) {
11 | SpringApplication.run(jOOQApplication.class, args);
12 | }
13 |
14 | }
--------------------------------------------------------------------------------
/Examples/jooq/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | # jOOQ
2 | spring.datasource.driverClassName=org.h2.Driver
3 | spring.datasource.url=jdbc:h2:~/jooqdb
4 |
5 | spring.jooq.sql-dialect=H2
6 | spring.datasource.initialize=false
7 | spring.datasource.continueOnError=true
8 |
9 | spring.sql.init.mode=always
--------------------------------------------------------------------------------
/Examples/jooq/src/main/resources/schema.sql:
--------------------------------------------------------------------------------
1 | DROP TABLE IF EXISTS CARPART;
2 | DROP TABLE IF EXISTS CAR;
3 |
4 | CREATE TABLE CAR (
5 | ID INT PRIMARY KEY,
6 | BRAND varchar(200) NOT NULL,
7 | MODEL varchar(200) NOT NULL
8 | );
9 |
10 | CREATE TABLE CARPART (
11 | ID INT PRIMARY KEY,
12 | CAR_ID INT NOT NULL,
13 | NAME varchar(200) NOT NULL,
14 | PRICE decimal(10,2) NOT NULL,
15 | FOREIGN KEY (CAR_ID) REFERENCES CAR(ID)
16 | );
--------------------------------------------------------------------------------
/Examples/jooq/src/test/java/com/examples/jOOQTest.java:
--------------------------------------------------------------------------------
1 | package com.examples;
2 |
3 | import com.examples.jooq.generated.tables.records.CarRecord;
4 | import org.jooq.DSLContext;
5 | import org.jooq.Result;
6 | import org.junit.jupiter.api.Test;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.boot.test.context.SpringBootTest;
9 |
10 | import static com.examples.jooq.generated.tables.Car.CAR;
11 | import static org.junit.jupiter.api.Assertions.assertEquals;
12 |
13 | // Also see src/main/resources/schema.sql
14 | @SpringBootTest(classes = {jOOQApplication.class})
15 | public class jOOQTest {
16 | @Autowired
17 | private DSLContext dslContext;
18 |
19 | @Test
20 | void testjOOQ() {
21 | dslContext.delete(CAR).execute();
22 |
23 | CarRecord porsche = new CarRecord(1, "Porsche", "911");
24 | saveCar(porsche);
25 |
26 | CarRecord lamborghini = new CarRecord(2, "Lamborghini", "Diablo");
27 | saveCar(lamborghini);
28 |
29 | Result cars = dslContext.selectFrom(CAR).fetch();
30 | assertEquals(2, cars.size());
31 | assertEquals("Porsche", cars.get(0).getBrand());
32 | assertEquals("Lamborghini", cars.get(1).getBrand());
33 | }
34 |
35 | public void saveCar(CarRecord carRecord) {
36 | dslContext.insertInto(CAR)
37 | .set(CAR.ID, carRecord.getId())
38 | .set(CAR.BRAND, carRecord.getBrand())
39 | .set(CAR.MODEL, carRecord.getModel()).execute();
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/Examples/jpackage/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | Examples
7 | com.example
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | jpackage
13 |
14 |
--------------------------------------------------------------------------------
/Examples/jpackage/src/main/java/com/examples/jpackage/Hellojpackage.java:
--------------------------------------------------------------------------------
1 | package com.examples.jpackage;
2 |
3 | import java.util.logging.Logger;
4 |
5 | public class Hellojpackage {
6 | private static final Logger LOG = Logger.getLogger(Hellojpackage.class.getName());
7 |
8 | public static void main(String[] args) {
9 | LOG.info("Hello jpackage!");
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/Examples/jreleaser/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | Examples
7 | com.example
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | jreleaser
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 | org.jreleaser
22 | jreleaser-maven-plugin
23 | 1.13.1
24 |
25 | true
26 |
27 |
28 | Dummy
29 |
30 |
31 |
32 |
33 |
34 | true
35 | ALWAYS
36 | gitmoji
37 | - {{commitShortHash}} {{commitTitle}}
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/Examples/jsoup/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | Examples
7 | com.example
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | jsoup
13 |
14 |
15 |
16 |
17 | org.jsoup
18 | jsoup
19 |
20 |
21 |
--------------------------------------------------------------------------------
/Examples/jsoup/src/test/java/com/example/jsoupTest.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import org.jsoup.Jsoup;
4 | import org.jsoup.nodes.Document;
5 | import org.jsoup.nodes.Element;
6 | import org.jsoup.select.Elements;
7 | import org.junit.jupiter.api.Test;
8 |
9 | import java.io.IOException;
10 |
11 | import static org.junit.jupiter.api.Assertions.assertTrue;
12 |
13 | public class jsoupTest {
14 |
15 | @Test
16 | void testChocolatey() throws IOException {
17 | Document doc = Jsoup.connect("https://community.chocolatey.org/profiles/JohanJanssen").get();
18 | Elements elements = doc.select(".card-header").select("div.col-md.py-3.py-md-0");
19 |
20 | for (Element element : elements) {
21 | if (element.text().contains("Downloads of Packages")) {
22 | String result = element.select("h4").get(0).text();
23 | System.out.println("Number of downloads " + result);
24 | String plainResult = result.replaceAll(",", "");
25 | Integer integerResult = Integer.valueOf(plainResult);
26 | assertTrue(Integer.valueOf(plainResult) > 3_000_000);
27 | }
28 | }
29 |
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/Examples/libphonenumber/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | Examples
7 | com.example
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | libphonenumber
13 |
14 |
15 |
16 |
17 | com.googlecode.libphonenumber
18 | libphonenumber
19 |
20 |
21 | com.googlecode.libphonenumber
22 | geocoder
23 |
24 |
25 | com.googlecode.libphonenumber
26 | carrier
27 |
28 |
29 |
--------------------------------------------------------------------------------
/Examples/libphonenumber/src/test/java/com/example/libphonenumberTest.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import com.google.i18n.phonenumbers.NumberParseException;
4 | import com.google.i18n.phonenumbers.PhoneNumberToCarrierMapper;
5 | import com.google.i18n.phonenumbers.PhoneNumberUtil;
6 | import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber;
7 | import com.google.i18n.phonenumbers.geocoding.PhoneNumberOfflineGeocoder;
8 | import org.junit.jupiter.api.Test;
9 |
10 | import java.util.Locale;
11 |
12 | import static org.junit.jupiter.api.Assertions.*;
13 |
14 | public class libphonenumberTest {
15 | PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil.getInstance();
16 | PhoneNumberToCarrierMapper phoneNumberToCarrierMapper = PhoneNumberToCarrierMapper.getInstance();
17 | PhoneNumberOfflineGeocoder phoneNumberOfflineGeocoder = PhoneNumberOfflineGeocoder.getInstance();
18 |
19 | @Test
20 | void testDutchNumber() throws NumberParseException {
21 | String number = "0478 501234";
22 | PhoneNumber parsedNumber = phoneNumberUtil.parse(number, "NL");
23 | assertTrue(phoneNumberUtil.isValidNumber(parsedNumber));
24 | assertEquals("Venray", phoneNumberOfflineGeocoder.getDescriptionForNumber(parsedNumber, Locale.ENGLISH));
25 | assertEquals("", phoneNumberToCarrierMapper.getNameForNumber(parsedNumber, Locale.ENGLISH));
26 |
27 | number = "0478 01234";
28 | parsedNumber = phoneNumberUtil.parse(number, "NL");
29 | assertFalse(phoneNumberUtil.isValidNumber(parsedNumber));
30 |
31 | number = "06 12345678";
32 | parsedNumber = phoneNumberUtil.parse(number, "NL");
33 | assertTrue(phoneNumberUtil.isValidNumber(parsedNumber));
34 | assertEquals("Netherlands", phoneNumberOfflineGeocoder.getDescriptionForNumber(parsedNumber, Locale.ENGLISH));
35 | assertEquals("KPN", phoneNumberToCarrierMapper.getNameForNumber(parsedNumber, Locale.ENGLISH));
36 |
37 |
38 | number = "00316 12345678";
39 | parsedNumber = phoneNumberUtil.parse(number, "NL");
40 | assertTrue(phoneNumberUtil.isValidNumber(parsedNumber));
41 |
42 | number = "+316 12345678";
43 | parsedNumber = phoneNumberUtil.parse(number, "NL");
44 | assertTrue(phoneNumberUtil.isValidNumber(parsedNumber));
45 |
46 | number = "06 12345";
47 | parsedNumber = phoneNumberUtil.parse(number, "NL");
48 | assertFalse(phoneNumberUtil.isValidNumber(parsedNumber));
49 |
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/Examples/mapstruct/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | Examples
7 | com.example
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | mapstruct
13 |
14 |
15 |
16 | org.mapstruct
17 | mapstruct
18 |
19 |
20 |
21 |
22 |
23 |
24 | org.apache.maven.plugins
25 | maven-compiler-plugin
26 | 3.13.0
27 |
28 | ${java.version}
29 |
30 |
31 | org.mapstruct
32 | mapstruct-processor
33 | 1.5.5.Final
34 |
35 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/Examples/mapstruct/src/test/java/com/examples/Book.java:
--------------------------------------------------------------------------------
1 | package com.examples;
2 |
3 | public class Book {
4 | private String title;
5 | private String bookValue;
6 |
7 | public Book() {
8 | }
9 |
10 | public Book(String title, String bookValue) {
11 | this.title = title;
12 | this.bookValue = bookValue;
13 | }
14 |
15 | public String getTitle() {
16 | return title;
17 | }
18 |
19 | public void setTitle(String title) {
20 | this.title = title;
21 | }
22 |
23 | public String getBookValue() {
24 | return bookValue;
25 | }
26 |
27 | public void setBookValue(String bookValue) {
28 | this.bookValue = bookValue;
29 | }
30 | }
--------------------------------------------------------------------------------
/Examples/mapstruct/src/test/java/com/examples/BookEntity.java:
--------------------------------------------------------------------------------
1 | package com.examples;
2 |
3 | //@Entity
4 | public class BookEntity {
5 | private int id;
6 | private String title;
7 | private String entityValue;
8 |
9 | public BookEntity() {
10 | }
11 |
12 | public BookEntity(int id, String title, String entityValue) {
13 | this.id = id;
14 | this.title = title;
15 | this.entityValue = entityValue;
16 | }
17 |
18 | public int getId() {
19 | return id;
20 | }
21 |
22 | public void setId(int id) {
23 | this.id = id;
24 | }
25 |
26 | public String getTitle() {
27 | return title;
28 | }
29 |
30 | public void setTitle(String title) {
31 | this.title = title;
32 | }
33 |
34 | public String getEntityValue() {
35 | return entityValue;
36 | }
37 |
38 | public void setEntityValue(String entityValue) {
39 | this.entityValue = entityValue;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/Examples/mapstruct/src/test/java/com/examples/BookMapper.java:
--------------------------------------------------------------------------------
1 | package com.examples;
2 |
3 | import org.mapstruct.Mapper;
4 | import org.mapstruct.Mapping;
5 | import org.mapstruct.factory.Mappers;
6 |
7 | @Mapper
8 | public interface BookMapper {
9 |
10 | BookMapper INSTANCE = Mappers.getMapper(BookMapper.class);
11 |
12 | @Mapping(source = "entityValue", target = "bookValue")
13 | Book bookEntityToBook(BookEntity bookEntity);
14 | }
--------------------------------------------------------------------------------
/Examples/mapstruct/src/test/java/com/examples/MapStructTest.java:
--------------------------------------------------------------------------------
1 | package com.examples;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | import static org.junit.jupiter.api.Assertions.assertEquals;
6 |
7 | // Fist compile the project
8 | // Also see the annotation processor in the maven-compiler-plugin
9 | public class MapStructTest {
10 | @Test
11 | void mapBookEntityToBook() {
12 | BookEntity bookEntity = new BookEntity(0, "Spring Boot In Action", "Answer to the Ultimate Question of Life, the Universe, and Everything");
13 |
14 | Book book = BookMapper.INSTANCE.bookEntityToBook(bookEntity);
15 |
16 | assertEquals("Spring Boot In Action", book.getTitle());
17 | assertEquals("Answer to the Ultimate Question of Life, the Universe, and Everything", book.getBookValue());
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Examples/micrometer/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | Examples
7 | com.example
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | micrometer
13 |
14 |
15 |
16 |
17 | org.springframework.boot
18 | spring-boot-starter-web
19 |
20 |
21 | org.springframework.boot
22 | spring-boot-starter-actuator
23 |
24 |
25 | org.springframework.boot
26 | spring-boot-starter-aop
27 |
28 |
29 |
--------------------------------------------------------------------------------
/Examples/micrometer/src/main/java/com/example/MicrometerApplication.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import io.micrometer.core.aop.TimedAspect;
4 | import io.micrometer.core.instrument.MeterRegistry;
5 | import org.springframework.boot.SpringApplication;
6 | import org.springframework.boot.autoconfigure.SpringBootApplication;
7 | import org.springframework.context.annotation.Bean;
8 |
9 |
10 | // http://localhost:8080/actuator/metrics
11 | // http://localhost:8080/actuator/metrics/http.server.requests
12 | @SpringBootApplication
13 | public class MicrometerApplication {
14 |
15 | public static void main(String[] args) {
16 | SpringApplication.run(MicrometerApplication.class, args);
17 | }
18 |
19 | @Bean
20 | public TimedAspect timedAspect(MeterRegistry registry) {
21 | return new TimedAspect(registry);
22 | }
23 |
24 | }
--------------------------------------------------------------------------------
/Examples/micrometer/src/main/java/com/example/MicrometerService.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import io.micrometer.core.annotation.Timed;
4 | import io.micrometer.core.instrument.Counter;
5 | import io.micrometer.core.instrument.Gauge;
6 | import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.web.bind.annotation.GetMapping;
9 | import org.springframework.web.bind.annotation.RestController;
10 |
11 | import java.time.LocalDateTime;
12 | import java.util.ArrayList;
13 | import java.util.List;
14 |
15 | // Also see application.properties
16 | // http://localhost:8080/actuator/metrics/micrometer.endpoint.counter
17 | // http://localhost:8080/actuator/metrics/micrometer.endpoint.time
18 | // http://localhost:8080/actuator/metrics/micrometer.endpoint.gauge
19 | @RestController
20 | public class MicrometerService {
21 |
22 | @Autowired
23 | private SimpleMeterRegistry simpleMeterRegistry;
24 |
25 | List gaugeList = new ArrayList<>();
26 |
27 | @Timed(value = "micrometer.endpoint.time", description = "Duration of the Micrometer endpoint")
28 | @GetMapping("/micro")
29 | public String micro() {
30 | Counter counter = simpleMeterRegistry.counter("micrometer.endpoint.counter");
31 | counter.increment();
32 |
33 | int seconds = LocalDateTime.now().getSecond();
34 | if ((LocalDateTime.now().getSecond() % 2) ==0) {
35 | gaugeList.add(seconds);
36 | }
37 |
38 | Gauge gauge = Gauge
39 | .builder("micrometer.endpoint.gauge", gaugeList, List::size)
40 | .register(simpleMeterRegistry);
41 | return "Hello, measuring method duration";
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/Examples/micrometer/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | # Enable actuator endpoints and show Micrometer
2 | management.endpoints.web.exposure.include=*
3 |
4 |
--------------------------------------------------------------------------------
/Examples/microstream/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | Examples
7 | com.example
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | microstream
13 |
14 |
15 |
16 | org.springframework.boot
17 | spring-boot-starter-web
18 |
19 |
20 | one.microstream
21 | microstream-storage-embedded
22 |
23 |
24 | one.microstream
25 | microstream-storage-embedded-configuration
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/Examples/microstream/src/main/java/com/example/Car.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import java.util.List;
4 |
5 | public class Car {
6 | private String brand;
7 | private String model;
8 | private List carPartList;
9 |
10 | public Car() {
11 | }
12 |
13 | public Car(String brand, String model, List carPartList) {
14 | this.brand = brand;
15 | this.model = model;
16 | this.carPartList = carPartList;
17 | }
18 |
19 | public String getBrand() {
20 | return brand;
21 | }
22 |
23 | public void setBrand(String brand) {
24 | this.brand = brand;
25 | }
26 |
27 | public String getModel() {
28 | return model;
29 | }
30 |
31 | public void setModel(String model) {
32 | this.model = model;
33 | }
34 |
35 | public List getCarPartList() {
36 | return carPartList;
37 | }
38 |
39 | public void setCarPartList(List carPartList) {
40 | this.carPartList = carPartList;
41 | }
42 |
43 | @Override
44 | public String toString() {
45 | return "Car{" +
46 | "brand='" + brand + '\'' +
47 | ", model='" + model + '\'' +
48 | ", carPartList=" + carPartList +
49 | '}';
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/Examples/microstream/src/main/java/com/example/CarPart.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | public class CarPart {
4 |
5 | private String name;
6 |
7 | private double price;
8 |
9 | public CarPart() {
10 | }
11 |
12 | public CarPart(String name, double price) {
13 | this.name = name;
14 | this.price = price;
15 | }
16 |
17 | public String getName() {
18 | return name;
19 | }
20 |
21 | public void setName(String name) {
22 | this.name = name;
23 | }
24 |
25 | public double getPrice() {
26 | return price;
27 | }
28 |
29 | public void setPrice(double price) {
30 | this.price = price;
31 | }
32 |
33 | @Override
34 | public String toString() {
35 | return "CarPart{" +
36 | "name='" + name + '\'' +
37 | ", price=" + price +
38 | '}';
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/Examples/microstream/src/main/java/com/example/CarRepository.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import java.util.List;
4 |
5 | public interface CarRepository
6 | {
7 | void add(Car car);
8 |
9 | List findAll();
10 |
11 | void removeAll();
12 |
13 | void storeAll();
14 | }
--------------------------------------------------------------------------------
/Examples/microstream/src/main/java/com/example/CarRepositoryImpl.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import one.microstream.storage.embedded.types.EmbeddedStorage;
4 | import one.microstream.storage.embedded.types.EmbeddedStorageManager;
5 | import org.springframework.beans.factory.annotation.Value;
6 | import org.springframework.stereotype.Component;
7 |
8 | import java.nio.file.Paths;
9 | import java.util.ArrayList;
10 | import java.util.List;
11 |
12 | @Component
13 | public class CarRepositoryImpl implements CarRepository
14 | {
15 | private final List carList;
16 | private final EmbeddedStorageManager storage;
17 |
18 | public CarRepositoryImpl(@Value("${microstream.store.location}") final String location)
19 | {
20 | super();
21 |
22 | this.carList = new ArrayList<>();
23 |
24 | this.storage = EmbeddedStorage.start(
25 | this.carList,
26 | Paths.get(location)
27 | );
28 | }
29 |
30 | @Override
31 | public void removeAll() {
32 | this.carList.clear();
33 | this.storeAll();
34 | }
35 |
36 | @Override
37 | public void storeAll()
38 | {
39 | this.storage.store(this.carList);
40 | }
41 |
42 | @Override
43 | public void add(final Car customer)
44 | {
45 | this.carList.add(customer);
46 | this.storeAll();
47 | }
48 |
49 | @Override
50 | public List findAll()
51 | {
52 | return this.carList;
53 | }
54 | }
--------------------------------------------------------------------------------
/Examples/microstream/src/main/java/com/example/MicroStreamApplication.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class MicroStreamApplication {
8 | public static void main(String[] args) {
9 | SpringApplication.run(MicroStreamApplication.class, args);
10 | }
11 |
12 | }
--------------------------------------------------------------------------------
/Examples/microstream/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | microstream.store.location=microstream-store
2 |
3 |
--------------------------------------------------------------------------------
/Examples/microstream/src/test/java/com/example/MicroStreamTest.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import one.microstream.storage.embedded.types.EmbeddedStorage;
4 | import one.microstream.storage.embedded.types.EmbeddedStorageManager;
5 | import org.junit.jupiter.api.Assertions;
6 | import org.junit.jupiter.api.Test;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.boot.test.context.SpringBootTest;
9 |
10 | import java.util.List;
11 |
12 | import static org.junit.jupiter.api.Assertions.assertEquals;
13 | import static org.junit.jupiter.api.Assertions.assertTrue;
14 |
15 | @SpringBootTest(classes = MicroStreamApplication.class)
16 | public class MicroStreamTest {
17 |
18 | @Autowired
19 | private CarRepository carRepository;
20 |
21 | @Test
22 | void testMicroStream() {
23 | final EmbeddedStorageManager storageManager = EmbeddedStorage.start();
24 |
25 | CarPart porscheCarPart1 = new CarPart("wheel", 23.23);
26 | Car porsche = new Car("Porsche", "911", List.of(porscheCarPart1));
27 |
28 | storageManager.setRoot(porsche);
29 | storageManager.storeRoot();
30 | final Object root = storageManager.root();
31 |
32 | String porscheExpected = "Car{brand='Porsche', model='911', carPartList=[CarPart{name='wheel', price=23.23}]}";
33 | assertTrue(root instanceof Car);
34 | if (root instanceof Car car) {
35 | Assertions.assertEquals(porscheExpected, car.toString());
36 | }
37 |
38 | storageManager.shutdown();
39 | }
40 |
41 | @Test
42 | void testMicroStreamSpringBoot() {
43 | carRepository.removeAll(); // To facilitate multiple test runs
44 | CarPart porscheCarPart1 = new CarPart("wheel", 23.23);
45 | Car porsche = new Car("Porsche", "911", List.of(porscheCarPart1));
46 |
47 | CarPart lamborghiniCarPart1 = new CarPart("mirror", 232.25);
48 | Car lamborghini = new Car("Lamborghini", "Diablo", List.of(lamborghiniCarPart1));
49 |
50 | CarPart paganiCarPart = new CarPart("engine", 8342.28);
51 | Car pagani = new Car("Pagani", "Huayra", List.of(paganiCarPart));
52 |
53 | List retrievedCarList = carRepository.findAll();
54 | assertEquals(0, retrievedCarList.size());
55 |
56 | carRepository.add(porsche);
57 | carRepository.add(lamborghini);
58 | carRepository.add(pagani);
59 |
60 | retrievedCarList = carRepository.findAll();
61 | assertEquals(3, retrievedCarList.size());
62 | String lamborghiniExpected = "Car{brand='Lamborghini', model='Diablo', carPartList=[CarPart{name='mirror', price=232.25}]}";
63 | Assertions.assertEquals(lamborghiniExpected, retrievedCarList.get(1).toString());
64 |
65 | carRepository.findAll().forEach(car -> car.setBrand(car.getBrand() + " rebranded"));
66 | carRepository.storeAll();
67 |
68 | retrievedCarList = carRepository.findAll();
69 | assertEquals(3, retrievedCarList.size());
70 | Assertions.assertEquals("Porsche rebranded", retrievedCarList.get(0).getBrand());
71 | Assertions.assertEquals("Lamborghini rebranded", retrievedCarList.get(1).getBrand());
72 | Assertions.assertEquals("Pagani rebranded", retrievedCarList.get(2).getBrand());
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/Examples/old-groupids-alerter/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | Examples
7 | com.example
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | old-groupids-alerter
13 |
14 |
15 |
16 |
17 | com.graphql-java
18 | graphql-java-tools
19 | 5.2.4
20 |
21 |
22 | javax.xml.bind
23 | jaxb-api
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 | biz.lermitage.oga
34 | oga-maven-plugin
35 | 1.9.2
36 |
37 | http://localhost:80/og-definitions.json
38 | http://localhost:80/og-unofficial-definitions.json
39 | false
40 |
41 |
42 |
43 | verify
44 |
45 | check
46 |
47 |
48 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/Examples/openrewrite/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | Examples
7 | com.example
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | openrewrite
13 |
14 |
23 |
24 |
25 |
26 | junit
27 | junit
28 | 4.13.2
29 | test
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/Examples/openrewrite/src/main/java/com/example/Main.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | public class Main {
4 | public static void main(String[] args) {
5 | System.out.println("Hello world!");
6 | System.out.println("Crappy formatting");
7 |
8 | String nullText = null;
9 | if (nullText.equals("example")) {
10 | System.out.println("This breaks");
11 | }
12 | }
13 | }
--------------------------------------------------------------------------------
/Examples/openrewrite/src/test/java/com/example/ExampleTest.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import org.junit.Assert;
4 | import org.junit.Rule;
5 | import org.junit.Test;
6 | import org.junit.rules.TemporaryFolder;
7 |
8 | import java.io.File;
9 | import java.io.IOException;
10 |
11 | public class ExampleTest {
12 |
13 | @Test
14 | public void simpleTest() {
15 | Assert.assertEquals(42, 42);
16 | }
17 |
18 | @Rule
19 | public TemporaryFolder folder = new TemporaryFolder();
20 |
21 | @Test
22 | public void temporaryFileTest() throws IOException {
23 | File testFile = folder.newFile("test.txt");
24 | Assert.assertTrue(testFile.exists());
25 | }
26 |
27 | @Test(expected = IOException.class)
28 | public void expectedExceptionTest() throws IOException {
29 | maybeThrowException(true);
30 | }
31 |
32 | private void maybeThrowException(boolean maybe) throws IOException {
33 | if (maybe) {
34 | throw new IOException();
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/Examples/owasp-dependency-check/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | Examples
7 | com.example
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | owasp-dependency-check
13 |
14 |
15 |
16 |
17 |
18 | org.apache.logging.log4j
19 | log4j-core
20 | 2.0
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | org.owasp
48 | dependency-check-maven
49 | 9.2.0
50 |
51 | http://localhost:80/nvdcve-{0}.json.gz
52 | http://localhost:80/known_exploited_vulnerabilities.json
53 | false
54 | false
55 | false
56 |
57 |
58 |
59 | verify
60 |
61 | check
62 |
63 |
64 |
65 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/Examples/passay/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | Examples
7 | com.example
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | passay
13 |
14 |
15 |
16 |
17 | org.passay
18 | passay
19 |
20 |
21 |
--------------------------------------------------------------------------------
/Examples/passay/src/test/java/com/example/PassayTest.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import org.junit.jupiter.api.Test;
4 | import org.passay.*;
5 |
6 | import static org.junit.jupiter.api.Assertions.*;
7 |
8 | public class PassayTest {
9 | PasswordValidator validator = new PasswordValidator(
10 | // Length should be between 8 and 50
11 | new LengthRule(8, 50),
12 |
13 | // Contains at least two uppercase characer
14 | new CharacterRule(EnglishCharacterData.UpperCase, 2),
15 |
16 | // Contains at least three digit character
17 | new CharacterRule(EnglishCharacterData.Digit, 3),
18 |
19 | // Contains at least one symbol (special character)
20 | new CharacterRule(EnglishCharacterData.Special, 1),
21 |
22 | // Doesn't contain a sequence of 3 or more characters
23 | new IllegalSequenceRule(EnglishSequenceData.Numerical, 3, false),
24 |
25 | // Doesn't contain whitespaces
26 | new WhitespaceRule()
27 | );
28 |
29 | @Test
30 | void testInvalidPasswords() {
31 | RuleResult ruleResult = validator.validate(new PasswordData("password"));
32 | assertFalse(ruleResult.isValid());
33 | assertEquals(3, validator.getMessages(ruleResult).size());
34 | assertEquals("Password must contain 2 or more uppercase characters.", validator.getMessages(ruleResult).get(0));
35 | assertEquals("Password must contain 3 or more digit characters.", validator.getMessages(ruleResult).get(1));
36 | assertEquals("Password must contain 1 or more special characters.", validator.getMessages(ruleResult).get(2));
37 |
38 | ruleResult = validator.validate(new PasswordData("DifficultPassword!123"));
39 | assertFalse(ruleResult.isValid());
40 | assertEquals(1, validator.getMessages(ruleResult).size());
41 | assertEquals("Password contains the illegal numerical sequence '123'.", validator.getMessages(ruleResult).get(0));
42 | }
43 |
44 | @Test
45 | void testValidPasswords() {
46 | RuleResult ruleResult = validator.validate(new PasswordData("AB721$MORETEST"));
47 | assertTrue(ruleResult.isValid());
48 |
49 | ruleResult = validator.validate(new PasswordData("a83by4oYUAp23#(%V*N"));
50 | assertTrue(ruleResult.isValid());
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/Examples/pebble-templates/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | Examples
7 | com.example
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | pebble-templates
13 |
14 |
15 |
16 |
17 | io.pebbletemplates
18 | pebble
19 | test
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Examples/pebble-templates/src/test/java/com/example/PebbleTemplatesTest.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import io.pebbletemplates.pebble.PebbleEngine;
4 | import io.pebbletemplates.pebble.template.PebbleTemplate;
5 | import org.junit.jupiter.api.Test;
6 |
7 | import java.io.IOException;
8 | import java.io.StringWriter;
9 | import java.io.Writer;
10 | import java.util.HashMap;
11 | import java.util.List;
12 | import java.util.Map;
13 | import java.util.Random;
14 |
15 | // see test/webapp/WEB-INF
16 | public class PebbleTemplatesTest {
17 | record Expertise(String technology, int years) {}
18 | record Person(String firstName, String lastName) {}
19 |
20 | @Test
21 | void testPebbleTemplates() throws IOException {
22 | PebbleEngine engine = new PebbleEngine.Builder().build();
23 | PebbleTemplate compiledTemplate = engine.getTemplate("specificFunction.html");
24 |
25 | Map context = new HashMap<>();
26 | context.put("firstName", "{{}}");
27 | context.put("lastName", "Janssen");
28 |
29 | context.put("functionTitle", "Senior vice president principal code ninja turtle warrior architect");
30 |
31 | Random random = new Random();
32 | Expertise expertise1 = new Expertise("GraalVM", 20);
33 | Expertise expertise2 = new Expertise("PHP", random.nextInt(8));
34 | Expertise expertise3 = new Expertise("Spring Boot", random.nextInt(8));
35 | Expertise expertise4 = new Expertise("J2EE (yes I know it should be Java EE or Jakarta EE ;))", random.nextInt(15));
36 | List expertiseList = List.of(expertise1, expertise2, expertise3, expertise4);
37 | context.put("expertiseList", expertiseList);
38 |
39 | context.put("workingHours", (int)(Math.random()*(60-40))+40);
40 | context.put("vacationDays", 20);
41 |
42 | context.put("salary", random.nextInt(2000));
43 |
44 |
45 | Writer writer = new StringWriter();
46 | compiledTemplate.evaluate(writer, context);
47 |
48 | System.out.println(writer.toString());
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/Examples/pebble-templates/src/test/resources/base.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | {{title}}
4 |
5 |
6 | Hello {{firstName}} {{lastName}} would you be interested in this vacancy?
7 |
8 | {% block specificFunction %}{% endblock %}
9 |
10 | To provide a good work life balance you only work {{workingHours}} hours per week
11 | We care about your wellbeing so you get an awesome {{wrong_name}} days off per year.
12 |
13 | Expected salary: an awesome above market salary of at least {{salary}} euro
14 |
15 |
16 |
--------------------------------------------------------------------------------
/Examples/pebble-templates/src/test/resources/specificFunction.html:
--------------------------------------------------------------------------------
1 | {% extends "base.html" %}
2 | {% block specificFunction %}
3 | {{functionTitle}}
4 | Expected knowledge:
5 |
6 | {% for expertise in expertiseList %}
7 | - {{expertise.technology}} (years of experience {{expertise.years}})
8 | {% endfor %}
9 |
10 | {% endblock %}
--------------------------------------------------------------------------------
/Examples/pitest/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | Examples
7 | com.example
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | pitest
13 |
14 |
15 |
16 |
17 |
18 |
19 | org.pitest
20 | pitest-maven
21 | 1.16.1
22 |
23 |
24 | com.example.*
25 |
26 |
27 | com.example.*
28 |
29 |
30 | com.example**.*IT
31 |
32 |
33 |
34 |
35 | pit-report
36 | test
37 |
38 | mutationCoverage
39 |
40 |
41 |
42 |
43 |
44 | org.pitest
45 | pitest-junit5-plugin
46 | 1.2.1
47 |
48 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/Examples/pitest/src/main/java/com/example/PitestExample.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | public class PitestExample {
4 | private int variable;
5 |
6 | public PitestExample(int variable) {
7 | this.variable = variable;
8 | }
9 |
10 | public int getVariable() {
11 | return variable;
12 | }
13 |
14 | public void setVariable(int variable) {
15 | this.variable = variable;
16 | }
17 |
18 | public int higherOrVariable(int value1, int value2) {
19 | int highest = 0;
20 | if (value2 > value1) {
21 | highest = value2;
22 | } else {
23 | highest = value1;
24 | }
25 |
26 | if (variable > highest) {
27 | return variable;
28 | } else {
29 | return highest;
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/Examples/pitest/src/test/java/com/example/PitestExampleTest.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | import static org.junit.jupiter.api.Assertions.assertEquals;
6 |
7 | public class PitestExampleTest {
8 | private PitestExample pitestExample = new PitestExample(42);
9 |
10 | @Test
11 | public void testPitest() {
12 | assertEquals(42, pitestExample.higherOrVariable(2,5));
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Examples/rest-assured/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | Examples
7 | com.example
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | rest-assured
13 |
14 |
15 |
16 | org.springframework.boot
17 | spring-boot-starter-web
18 |
19 |
20 | io.rest-assured
21 | rest-assured
22 |
23 |
24 | io.rest-assured
25 | json-path
26 |
27 |
28 | io.rest-assured
29 | xml-path
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/Examples/rest-assured/src/test/java/com/examples/Car.java:
--------------------------------------------------------------------------------
1 | package com.examples;
2 |
3 | import java.util.List;
4 |
5 | public class Car {
6 | private String brand;
7 | private String model;
8 | private List carPartList;
9 |
10 | public Car() {
11 | }
12 |
13 | public Car(String brand, String model, List carPartList) {
14 | this.brand = brand;
15 | this.model = model;
16 | this.carPartList = carPartList;
17 | }
18 |
19 | public String getBrand() {
20 | return brand;
21 | }
22 |
23 | public void setBrand(String brand) {
24 | this.brand = brand;
25 | }
26 |
27 | public String getModel() {
28 | return model;
29 | }
30 |
31 | public void setModel(String model) {
32 | this.model = model;
33 | }
34 |
35 | public List getCarPartList() {
36 | return carPartList;
37 | }
38 |
39 | public void setCarPartList(List carPartList) {
40 | this.carPartList = carPartList;
41 | }
42 |
43 | @Override
44 | public String toString() {
45 | return "Car{" +
46 | "brand='" + brand + '\'' +
47 | ", model='" + model + '\'' +
48 | ", carPartList=" + carPartList +
49 | '}';
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/Examples/rest-assured/src/test/java/com/examples/CarApplication.java:
--------------------------------------------------------------------------------
1 | package com.examples;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class CarApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(CarApplication.class, args);
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/Examples/rest-assured/src/test/java/com/examples/CarPart.java:
--------------------------------------------------------------------------------
1 | package com.examples;
2 |
3 | public class CarPart {
4 |
5 | private String name;
6 |
7 | private double price;
8 |
9 | public CarPart() {
10 | }
11 |
12 | public CarPart(String name, double price) {
13 | this.name = name;
14 | this.price = price;
15 | }
16 |
17 | public String getName() {
18 | return name;
19 | }
20 |
21 | public void setName(String name) {
22 | this.name = name;
23 | }
24 |
25 | public double getPrice() {
26 | return price;
27 | }
28 |
29 | public void setPrice(double price) {
30 | this.price = price;
31 | }
32 |
33 | @Override
34 | public String toString() {
35 | return "CarPart{" +
36 | "name='" + name + '\'' +
37 | ", price=" + price +
38 | '}';
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/Examples/rest-assured/src/test/java/com/examples/CarRestController.java:
--------------------------------------------------------------------------------
1 | package com.examples;
2 |
3 | import org.springframework.web.bind.annotation.GetMapping;
4 | import org.springframework.web.bind.annotation.PostMapping;
5 | import org.springframework.web.bind.annotation.RequestBody;
6 | import org.springframework.web.bind.annotation.RestController;
7 |
8 | import java.util.ArrayList;
9 | import java.util.List;
10 |
11 | @RestController
12 | public class CarRestController {
13 | List carList = new ArrayList<>();
14 |
15 | public CarRestController() {
16 | CarPart huayraCarPart = new CarPart("engine", 8342.28);
17 | Car huayra = new Car("Pagani", "Huayra", List.of(huayraCarPart));
18 | carList.add(huayra);
19 | }
20 |
21 | @GetMapping("/car")
22 | public List retrieveCar() {
23 | return carList;
24 | }
25 |
26 | @PostMapping(path = "/car")
27 | public Car addCar(@RequestBody Car car) {
28 | carList.add(car);
29 | return car;
30 |
31 | }
32 | }
--------------------------------------------------------------------------------
/Examples/rest-assured/src/test/java/com/examples/RESTassuredTest.java:
--------------------------------------------------------------------------------
1 | package com.examples;
2 |
3 | import io.restassured.http.ContentType;
4 | import io.restassured.response.ValidatableResponse;
5 | import org.apache.http.HttpStatus;
6 | import org.junit.jupiter.api.Assertions;
7 | import org.junit.jupiter.api.Test;
8 | import org.springframework.boot.test.context.SpringBootTest;
9 | import org.springframework.boot.test.web.server.LocalServerPort;
10 | import org.springframework.test.annotation.DirtiesContext;
11 |
12 | import java.util.List;
13 |
14 | import static io.restassured.RestAssured.given;
15 | import static org.junit.jupiter.api.Assertions.assertEquals;
16 |
17 | @DirtiesContext
18 | @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = CarApplication.class)
19 | public class RESTassuredTest {
20 | @LocalServerPort
21 | private int port;
22 |
23 | @Test
24 | void testRESTassured() {
25 | List carList =
26 | given()
27 | .baseUri("http://localhost:" + port + "/")
28 | .when()
29 | .get("/car")
30 | .then()
31 | .extract()
32 | .body()
33 | .jsonPath().getList(".", Car.class);
34 |
35 | String paganiExpected = "Car{brand='Pagani', model='Huayra', carPartList=[CarPart{name='engine', price=8342.28}]}";
36 |
37 | assertEquals(1, carList.size());
38 | Assertions.assertEquals(paganiExpected, carList.get(0).toString());
39 |
40 | CarPart porscheCarPart1 = new CarPart("wheel", 23.23);
41 | Car porsche = new Car("Porsche", "911", List.of(porscheCarPart1));
42 |
43 | ValidatableResponse validatableResponse =
44 | given()
45 | .baseUri("http://localhost:" + port + "/")
46 | .contentType(ContentType.JSON)
47 | .body(porsche)
48 | .when()
49 | .post("/car")
50 | .then()
51 | .statusCode(HttpStatus.SC_OK);
52 | assertEquals(200, validatableResponse.extract().statusCode());
53 |
54 |
55 | List newCarList =
56 | given()
57 | .baseUri("http://localhost:" + port + "/")
58 | .when()
59 | .get("/car")
60 | .then()
61 | .extract()
62 | .body()
63 | .jsonPath().getList(".", Car.class);
64 | System.out.println(newCarList.get(0).toString());
65 | assertEquals(2, newCarList.size());
66 | Assertions.assertEquals(paganiExpected, newCarList.get(0).toString());
67 |
68 | String porscheExpected = "Car{brand='Porsche', model='911', carPartList=[CarPart{name='wheel', price=23.23}]}";
69 | Assertions.assertEquals(porscheExpected, newCarList.get(1).toString());
70 |
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/Examples/rest-easy/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | Examples
7 | com.example
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | rest-easy
13 |
14 |
15 |
16 | org.springframework.boot
17 | spring-boot-starter-web
18 |
19 |
20 | org.jboss.resteasy
21 | resteasy-client
22 |
23 |
24 | org.jboss.resteasy
25 | resteasy-jackson2-provider
26 |
27 |
28 | jakarta.xml.bind
29 | jakarta.xml.bind-api
30 |
31 |
32 | jakarta.annotation
33 | jakarta.annotation-api
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/Examples/rest-easy/src/test/java/com/examples/Car.java:
--------------------------------------------------------------------------------
1 | package com.examples;
2 |
3 | import java.util.List;
4 |
5 | public class Car {
6 | private String brand;
7 | private String model;
8 | private List carPartList;
9 |
10 | public Car() {
11 | }
12 |
13 | public Car(String brand, String model, List carPartList) {
14 | this.brand = brand;
15 | this.model = model;
16 | this.carPartList = carPartList;
17 | }
18 |
19 | public String getBrand() {
20 | return brand;
21 | }
22 |
23 | public void setBrand(String brand) {
24 | this.brand = brand;
25 | }
26 |
27 | public String getModel() {
28 | return model;
29 | }
30 |
31 | public void setModel(String model) {
32 | this.model = model;
33 | }
34 |
35 | public List getCarPartList() {
36 | return carPartList;
37 | }
38 |
39 | public void setCarPartList(List carPartList) {
40 | this.carPartList = carPartList;
41 | }
42 |
43 | @Override
44 | public String toString() {
45 | return "Car{" +
46 | "brand='" + brand + '\'' +
47 | ", model='" + model + '\'' +
48 | ", carPartList=" + carPartList +
49 | '}';
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/Examples/rest-easy/src/test/java/com/examples/CarApplication.java:
--------------------------------------------------------------------------------
1 | package com.examples;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class CarApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(CarApplication.class, args);
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/Examples/rest-easy/src/test/java/com/examples/CarPart.java:
--------------------------------------------------------------------------------
1 | package com.examples;
2 |
3 | public class CarPart {
4 | private String name;
5 | private double price;
6 |
7 | public CarPart() {
8 | }
9 | public CarPart(String name, double price) {
10 | this.name = name;
11 | this.price = price;
12 | }
13 | public String getName() {
14 | return name;
15 | }
16 |
17 | public void setName(String name) {
18 | this.name = name;
19 | }
20 |
21 | public double getPrice() {
22 | return price;
23 | }
24 |
25 | public void setPrice(double price) {
26 | this.price = price;
27 | }
28 |
29 | @Override
30 | public String toString() {
31 | return "CarPart{" +
32 | "name='" + name + '\'' +
33 | ", price=" + price +
34 | '}';
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/Examples/rest-easy/src/test/java/com/examples/CarRestController.java:
--------------------------------------------------------------------------------
1 | package com.examples;
2 |
3 | import org.springframework.web.bind.annotation.GetMapping;
4 | import org.springframework.web.bind.annotation.PostMapping;
5 | import org.springframework.web.bind.annotation.RequestBody;
6 | import org.springframework.web.bind.annotation.RestController;
7 |
8 | import java.util.ArrayList;
9 | import java.util.List;
10 |
11 | @RestController
12 | public class CarRestController {
13 | List carList = new ArrayList<>();
14 |
15 | public CarRestController() {
16 | CarPart huayraCarPart = new CarPart("engine", 8342.28);
17 | Car huayra = new Car("Pagani", "Huayra", List.of(huayraCarPart));
18 | carList.add(huayra);
19 | }
20 |
21 | @GetMapping("/car")
22 | public List retrieveCar() {
23 | return carList;
24 | }
25 |
26 | @PostMapping(path = "/car")
27 | public Car addCar(@RequestBody Car car) {
28 | carList.add(car);
29 | return car;
30 |
31 | }
32 | }
--------------------------------------------------------------------------------
/Examples/rest-easy/src/test/java/com/examples/RESTEasyTest.java:
--------------------------------------------------------------------------------
1 | package com.examples;
2 |
3 | import jakarta.ws.rs.client.Client;
4 | import jakarta.ws.rs.client.ClientBuilder;
5 | import jakarta.ws.rs.client.Entity;
6 | import jakarta.ws.rs.client.WebTarget;
7 | import jakarta.ws.rs.core.GenericType;
8 | import jakarta.ws.rs.core.MediaType;
9 | import jakarta.ws.rs.core.Response;
10 | import jakarta.ws.rs.core.UriBuilder;
11 | import org.jboss.resteasy.plugins.providers.jackson.ResteasyJackson2Provider;
12 | import org.junit.jupiter.api.Test;
13 | import org.springframework.boot.test.context.SpringBootTest;
14 | import org.springframework.boot.test.web.server.LocalServerPort;
15 | import org.springframework.test.annotation.DirtiesContext;
16 |
17 | import java.util.List;
18 | import java.util.concurrent.Future;
19 |
20 | import static org.junit.jupiter.api.Assertions.assertEquals;
21 |
22 | @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = CarApplication.class)
23 | @DirtiesContext
24 | public class RESTEasyTest {
25 | @LocalServerPort
26 | private int port;
27 |
28 | @Test
29 | void testRESTEasy() throws InterruptedException {
30 | final String path = "http://localhost:" + port + "/car";
31 |
32 | final Client client = ClientBuilder.newBuilder().register(ResteasyJackson2Provider.class).build();
33 | WebTarget target = client.target(UriBuilder.fromPath(path));
34 | Response response = target.request().accept(MediaType.APPLICATION_JSON).get();
35 | List carList = response.readEntity(new GenericType>() {});
36 |
37 | String paganiExpected = "Car{brand='Pagani', model='Huayra', carPartList=[CarPart{name='engine', price=8342.28}]}";
38 | assertEquals(1, carList.size());
39 | assertEquals(paganiExpected, carList.get(0).toString());
40 |
41 | // asynchronous
42 | CarPart porscheCarPart1 = new CarPart("wheel", 23.23);
43 | Car porsche = new Car("Porsche", "911", List.of(porscheCarPart1));
44 |
45 | Future storedPorscheReponse = target.request().async()
46 | .post(Entity.entity(porsche, "application/json"));
47 |
48 | Thread.sleep(1000);
49 |
50 | // synchronous
51 | CarPart lamborghiniCarPart1 = new CarPart("mirror", 232.25);
52 | Car lamborghini = new Car("Lamborghini", "Diablo", List.of(lamborghiniCarPart1));
53 |
54 | Response storedLamborghiniReponse = target.request()
55 | .post(Entity.entity(lamborghini, "application/json"));
56 | assertEquals(200, response.getStatus());
57 |
58 | response = target.request().accept(MediaType.APPLICATION_JSON).get();
59 | carList = response.readEntity(new GenericType>() {});
60 |
61 | String porscheExpected = "Car{brand='Porsche', model='911', carPartList=[CarPart{name='wheel', price=23.23}]}";
62 | String lamborghiniExpected = "Car{brand='Lamborghini', model='Diablo', carPartList=[CarPart{name='mirror', price=232.25}]}";
63 | assertEquals(3, carList.size());
64 | assertEquals(paganiExpected, carList.get(0).toString());
65 | assertEquals(porscheExpected, carList.get(1).toString());
66 | assertEquals(lamborghiniExpected, carList.get(2).toString());
67 |
68 | response.close();
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/Examples/retrofit/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | Examples
7 | com.example
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | retrofit
13 |
14 |
15 |
16 | org.springframework.boot
17 | spring-boot-starter-web
18 |
19 |
20 | com.squareup.retrofit2
21 | retrofit
22 |
23 |
24 | com.squareup.retrofit2
25 | converter-gson
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/Examples/retrofit/src/test/java/com/examples/Car.java:
--------------------------------------------------------------------------------
1 | package com.examples;
2 |
3 | import java.util.List;
4 |
5 | public class Car {
6 | private String brand;
7 | private String model;
8 | private List carPartList;
9 |
10 | public Car() {
11 | }
12 |
13 | public Car(String brand, String model, List carPartList) {
14 | this.brand = brand;
15 | this.model = model;
16 | this.carPartList = carPartList;
17 | }
18 |
19 | public String getBrand() {
20 | return brand;
21 | }
22 |
23 | public void setBrand(String brand) {
24 | this.brand = brand;
25 | }
26 |
27 | public String getModel() {
28 | return model;
29 | }
30 |
31 | public void setModel(String model) {
32 | this.model = model;
33 | }
34 |
35 | public List getCarPartList() {
36 | return carPartList;
37 | }
38 |
39 | public void setCarPartList(List carPartList) {
40 | this.carPartList = carPartList;
41 | }
42 |
43 | @Override
44 | public String toString() {
45 | return "Car{" +
46 | "brand='" + brand + '\'' +
47 | ", model='" + model + '\'' +
48 | ", carPartList=" + carPartList +
49 | '}';
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/Examples/retrofit/src/test/java/com/examples/CarApplication.java:
--------------------------------------------------------------------------------
1 | package com.examples;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class CarApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(CarApplication.class, args);
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/Examples/retrofit/src/test/java/com/examples/CarPart.java:
--------------------------------------------------------------------------------
1 | package com.examples;
2 |
3 | public class CarPart {
4 |
5 | private String name;
6 |
7 | private double price;
8 |
9 | public CarPart() {
10 | }
11 |
12 | public CarPart(String name, double price) {
13 | this.name = name;
14 | this.price = price;
15 | }
16 |
17 | public String getName() {
18 | return name;
19 | }
20 |
21 | public void setName(String name) {
22 | this.name = name;
23 | }
24 |
25 | public double getPrice() {
26 | return price;
27 | }
28 |
29 | public void setPrice(double price) {
30 | this.price = price;
31 | }
32 |
33 | @Override
34 | public String toString() {
35 | return "CarPart{" +
36 | "name='" + name + '\'' +
37 | ", price=" + price +
38 | '}';
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/Examples/retrofit/src/test/java/com/examples/CarRestController.java:
--------------------------------------------------------------------------------
1 | package com.examples;
2 |
3 | import org.springframework.web.bind.annotation.GetMapping;
4 | import org.springframework.web.bind.annotation.PostMapping;
5 | import org.springframework.web.bind.annotation.RequestBody;
6 | import org.springframework.web.bind.annotation.RestController;
7 |
8 | import java.util.ArrayList;
9 | import java.util.List;
10 |
11 | @RestController
12 | public class CarRestController {
13 | List carList = new ArrayList<>();
14 |
15 | public CarRestController() {
16 | CarPart huayraCarPart = new CarPart("engine", 8342.28);
17 | Car huayra = new Car("Pagani", "Huayra", List.of(huayraCarPart));
18 | carList.add(huayra);
19 | }
20 |
21 | @GetMapping("/car")
22 | public List retrieveCar() {
23 | return carList;
24 | }
25 |
26 | @PostMapping(path = "/car")
27 | public Car addCar(@RequestBody Car car) {
28 | carList.add(car);
29 | return car;
30 |
31 | }
32 | }
--------------------------------------------------------------------------------
/Examples/shedlock/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | Examples
7 | com.example
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | shedlock
13 |
14 |
15 |
16 |
17 | org.springframework.boot
18 | spring-boot-starter-web
19 |
20 |
21 | net.javacrumbs.shedlock
22 | shedlock-spring
23 |
24 |
25 |
26 | net.javacrumbs.shedlock
27 | shedlock-provider-inmemory
28 |
29 |
30 |
--------------------------------------------------------------------------------
/Examples/shedlock/src/main/java/com/example/ShedLockApplication.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import net.javacrumbs.shedlock.core.LockProvider;
4 | import net.javacrumbs.shedlock.provider.inmemory.InMemoryLockProvider;
5 | import org.springframework.boot.SpringApplication;
6 | import org.springframework.boot.autoconfigure.SpringBootApplication;
7 | import org.springframework.context.annotation.Bean;
8 |
9 |
10 | @SpringBootApplication
11 | public class ShedLockApplication {
12 |
13 | public static void main(String[] args) {
14 | SpringApplication.run(ShedLockApplication.class, args);
15 | }
16 |
17 | @Bean
18 | public LockProvider lockProvider() {
19 | return new InMemoryLockProvider();
20 | }
21 | }
--------------------------------------------------------------------------------
/Examples/shedlock/src/main/java/com/example/ShedLockService.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import net.javacrumbs.shedlock.spring.annotation.EnableSchedulerLock;
4 | import net.javacrumbs.shedlock.spring.annotation.SchedulerLock;
5 | import org.springframework.scheduling.annotation.EnableScheduling;
6 | import org.springframework.scheduling.annotation.Scheduled;
7 | import org.springframework.stereotype.Service;
8 |
9 | import java.time.LocalTime;
10 | import java.time.format.DateTimeFormatter;
11 |
12 | @EnableSchedulerLock(defaultLockAtMostFor = "10m")
13 | @EnableScheduling
14 | @Service
15 | public class ShedLockService {
16 | private DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss");
17 |
18 | @Scheduled(cron = "0/5 * * * * *")//Every 5 seconds
19 | public void schedule1(){
20 | System.out.println(" Default scheduling 1 " + LocalTime.now().format(dateTimeFormatter).toString());
21 | }
22 |
23 | @Scheduled(cron = "0/5 * * * * *")//Every 5 seconds
24 | public void schedule2(){
25 | System.out.println(" Default scheduling 2 " + LocalTime.now().format(dateTimeFormatter).toString());
26 | }
27 |
28 | @Scheduled(cron = "0/5 * * * * *")//Every 5 seconds
29 | @SchedulerLock(name = "taskName", lockAtMostFor = "14m", lockAtLeastFor = "4s")
30 | public void scheduledTask1() {
31 | System.out.println("ShedLock method 1 " + LocalTime.now().format(dateTimeFormatter).toString());
32 |
33 | }
34 |
35 | @Scheduled(cron = "0/5 * * * * *")//Every 5 seconds
36 | @SchedulerLock(name = "taskName", lockAtMostFor = "14m", lockAtLeastFor = "4s")
37 | public void scheduledTask2() {
38 | System.out.println("ShedLock method 2 " + LocalTime.now().format(dateTimeFormatter).toString());
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/Examples/testcontainers/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | Examples
7 | com.example
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | testcontainers
13 |
14 |
15 |
16 |
17 | org.testcontainers
18 | mysql
19 |
20 |
21 | org.testcontainers
22 | testcontainers
23 |
24 |
25 | org.testcontainers
26 | junit-jupiter
27 |
28 |
29 | mysql
30 | mysql-connector-java
31 |
32 |
33 |
34 |
35 |
36 |
37 | org.testcontainers
38 | testcontainers-bom
39 | 1.19.8
40 | pom
41 | import
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/Examples/testcontainers/src/test/java/com/example/TestcontainersTest.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import org.junit.jupiter.api.BeforeEach;
4 | import org.junit.jupiter.api.Test;
5 | import org.testcontainers.containers.MySQLContainer;
6 | import org.testcontainers.junit.jupiter.Container;
7 | import org.testcontainers.junit.jupiter.Testcontainers;
8 |
9 | import java.sql.*;
10 |
11 | import static org.junit.jupiter.api.Assertions.assertEquals;
12 |
13 | @Testcontainers
14 | public class TestcontainersTest {
15 |
16 | @Container
17 | private static final MySQLContainer mySQLContainer = new MySQLContainer("mysql:8.0.28");
18 |
19 | @BeforeEach
20 | public void setUp() {
21 | }
22 |
23 | private static final String createBookTable = """
24 | CREATE TABLE BOOK
25 | (
26 | ID serial,
27 | NAME varchar(100) NOT NULL,
28 | PRIMARY KEY (ID)
29 | )""";
30 |
31 | private static final String storeBook = "INSERT INTO BOOK (NAME) VALUES (?)";
32 |
33 | private static final String retrieveBooks = "SELECT * FROM BOOK";
34 |
35 |
36 | @Test
37 | public void testSimplePutAndGet() throws SQLException {
38 | String url = mySQLContainer.getJdbcUrl();
39 | String username = mySQLContainer.getUsername();
40 | String password = mySQLContainer.getPassword();
41 | try (Connection conn = DriverManager.getConnection(url, username, password)) {
42 | Statement statement = conn.createStatement();
43 | statement.execute(createBookTable);
44 |
45 | PreparedStatement preparedStatement = conn.prepareStatement(storeBook);
46 | preparedStatement.setString(1, "Spring Boot in Action");
47 | preparedStatement.executeUpdate();
48 | preparedStatement.setString(1, "Learning MySQL");
49 | preparedStatement.executeUpdate();
50 |
51 | ResultSet rs = statement.executeQuery(retrieveBooks);
52 | rs.next();
53 | assertEquals("Spring Boot in Action", rs.getString("NAME"));
54 | rs.next();
55 | assertEquals("Learning MySQL", rs.getString("NAME"));
56 |
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/Examples/testcontainers/src/test/resources/logback-test.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Examples/timefold/src/main/java/com/examples/timefold/domain/Room.java:
--------------------------------------------------------------------------------
1 | package com.examples.timefold.domain;
2 |
3 | import ai.timefold.solver.core.api.domain.lookup.PlanningId;
4 |
5 | import jakarta.persistence.Entity;
6 | import jakarta.persistence.GeneratedValue;
7 | import jakarta.persistence.Id;
8 |
9 | @Entity
10 | public class Room {
11 | @PlanningId
12 | @Id @GeneratedValue
13 | private Long id;
14 |
15 | private String name;
16 |
17 | public Room() {
18 | }
19 |
20 | public Room(String name) {
21 | this.name = name;
22 | }
23 |
24 | public Room(long id, String name) {
25 | this(name);
26 | this.id = id;
27 | }
28 |
29 | @Override
30 | public String toString() {
31 | return name;
32 | }
33 |
34 | public Long getId() {
35 | return id;
36 | }
37 |
38 | public String getName() {
39 | return name;
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/Examples/timefold/src/main/java/com/examples/timefold/domain/Session.java:
--------------------------------------------------------------------------------
1 | package com.examples.timefold.domain;
2 |
3 | import ai.timefold.solver.core.api.domain.entity.PlanningEntity;
4 | import ai.timefold.solver.core.api.domain.lookup.PlanningId;
5 | import ai.timefold.solver.core.api.domain.variable.PlanningVariable;
6 |
7 | import jakarta.persistence.Entity;
8 | import jakarta.persistence.GeneratedValue;
9 | import jakarta.persistence.Id;
10 | import jakarta.persistence.ManyToOne;
11 |
12 | @PlanningEntity
13 | @Entity
14 | public class Session {
15 | @PlanningId
16 | @Id @GeneratedValue
17 | private Long id;
18 |
19 | private String title;
20 | private String speaker;
21 | private String language;
22 |
23 | @PlanningVariable(valueRangeProviderRefs = "timeslotRange")
24 | @ManyToOne
25 | private Timeslot timeslot;
26 |
27 | @PlanningVariable(valueRangeProviderRefs = "roomRange")
28 | @ManyToOne
29 | private Room room;
30 |
31 | public Session() {
32 | }
33 |
34 | public Session(String title, String speaker, String language) {
35 | this.title = title;
36 | this.speaker = speaker;
37 | this.language = language;
38 | }
39 |
40 | public Session(long id, String title, String speaker, String language, Timeslot timeslot, Room room) {
41 | this(title, speaker, language);
42 | this.id = id;
43 | this.timeslot = timeslot;
44 | this.room = room;
45 | }
46 |
47 | @Override
48 | public String toString() {
49 | return title + "(" + id + ")";
50 | }
51 |
52 | public Long getId() {
53 | return id;
54 | }
55 |
56 | public String getTitle() {
57 | return title;
58 | }
59 |
60 | public String getSpeaker() {
61 | return speaker;
62 | }
63 |
64 | public String getLanguage() {
65 | return language;
66 | }
67 |
68 | public Timeslot getTimeslot() {
69 | return timeslot;
70 | }
71 |
72 | public void setTimeslot(Timeslot timeslot) {
73 | this.timeslot = timeslot;
74 | }
75 |
76 | public Room getRoom() {
77 | return room;
78 | }
79 |
80 | public void setRoom(Room room) {
81 | this.room = room;
82 | }
83 |
84 | }
85 |
--------------------------------------------------------------------------------
/Examples/timefold/src/main/java/com/examples/timefold/domain/TimeTable.java:
--------------------------------------------------------------------------------
1 | package com.examples.timefold.domain;
2 |
3 | import ai.timefold.solver.core.api.domain.solution.PlanningEntityCollectionProperty;
4 | import ai.timefold.solver.core.api.domain.solution.PlanningScore;
5 | import ai.timefold.solver.core.api.domain.solution.PlanningSolution;
6 | import ai.timefold.solver.core.api.domain.solution.ProblemFactCollectionProperty;
7 | import ai.timefold.solver.core.api.domain.valuerange.ValueRangeProvider;
8 | import ai.timefold.solver.core.api.score.buildin.hardsoft.HardSoftScore;
9 | import ai.timefold.solver.core.api.solver.SolverStatus;
10 |
11 | import java.util.List;
12 |
13 | @PlanningSolution
14 | public class TimeTable {
15 |
16 | @ValueRangeProvider(id = "timeslotRange")
17 | @ProblemFactCollectionProperty
18 | private List timeslotList;
19 |
20 | @ValueRangeProvider(id = "roomRange")
21 | @ProblemFactCollectionProperty
22 | private List roomList;
23 |
24 | @PlanningEntityCollectionProperty
25 | private List sessionList;
26 |
27 | @PlanningScore
28 | private HardSoftScore score;
29 |
30 | // Ignored by Timefold, used by the UI to display solve or stop solving button
31 | private SolverStatus solverStatus;
32 |
33 | public TimeTable() {
34 | }
35 |
36 | public TimeTable(List timeslotList, List roomList,
37 | List sessionList) {
38 | this.timeslotList = timeslotList;
39 | this.roomList = roomList;
40 | this.sessionList = sessionList;
41 | }
42 |
43 | public List getTimeslotList() {
44 | return timeslotList;
45 | }
46 |
47 | public List getRoomList() {
48 | return roomList;
49 | }
50 |
51 | public List getLessonList() {
52 | return sessionList;
53 | }
54 |
55 | public HardSoftScore getScore() {
56 | return score;
57 | }
58 |
59 | public SolverStatus getSolverStatus() {
60 | return solverStatus;
61 | }
62 |
63 | public void setSolverStatus(SolverStatus solverStatus) {
64 | this.solverStatus = solverStatus;
65 | }
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/Examples/timefold/src/main/java/com/examples/timefold/domain/Timeslot.java:
--------------------------------------------------------------------------------
1 | package com.examples.timefold.domain;
2 |
3 | import ai.timefold.solver.core.api.domain.lookup.PlanningId;
4 |
5 | import jakarta.persistence.Entity;
6 | import jakarta.persistence.GeneratedValue;
7 | import jakarta.persistence.Id;
8 | import java.time.DayOfWeek;
9 | import java.time.LocalTime;
10 |
11 | @Entity
12 | public class Timeslot {
13 |
14 | @PlanningId
15 | @Id @GeneratedValue
16 | private Long id;
17 |
18 | private DayOfWeek dayOfWeek;
19 | private LocalTime startTime;
20 | private LocalTime endTime;
21 |
22 | public Timeslot() {
23 | }
24 |
25 | public Timeslot(DayOfWeek dayOfWeek, LocalTime startTime, LocalTime endTime) {
26 | this.dayOfWeek = dayOfWeek;
27 | this.startTime = startTime;
28 | this.endTime = endTime;
29 | }
30 |
31 | public Timeslot(long id, DayOfWeek dayOfWeek, LocalTime startTime) {
32 | this(dayOfWeek, startTime, startTime.plusMinutes(50));
33 | this.id = id;
34 | }
35 |
36 | @Override
37 | public String toString() {
38 | return dayOfWeek + " " + startTime;
39 | }
40 |
41 | public Long getId() {
42 | return id;
43 | }
44 |
45 | public DayOfWeek getDayOfWeek() {
46 | return dayOfWeek;
47 | }
48 |
49 | public LocalTime getStartTime() {
50 | return startTime;
51 | }
52 |
53 | public LocalTime getEndTime() {
54 | return endTime;
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/Examples/timefold/src/main/java/com/examples/timefold/persistence/RoomRepository.java:
--------------------------------------------------------------------------------
1 | package com.examples.timefold.persistence;
2 |
3 | import com.examples.timefold.domain.Room;
4 | import org.springframework.data.jpa.repository.JpaRepository;
5 |
6 | public interface RoomRepository extends JpaRepository {
7 | }
8 |
--------------------------------------------------------------------------------
/Examples/timefold/src/main/java/com/examples/timefold/persistence/SessionRepository.java:
--------------------------------------------------------------------------------
1 | package com.examples.timefold.persistence;
2 |
3 | import com.examples.timefold.domain.Session;
4 | import org.springframework.data.jpa.repository.JpaRepository;
5 |
6 | public interface SessionRepository extends JpaRepository {
7 | }
8 |
--------------------------------------------------------------------------------
/Examples/timefold/src/main/java/com/examples/timefold/persistence/TimeTableRepository.java:
--------------------------------------------------------------------------------
1 | package com.examples.timefold.persistence;
2 |
3 | import com.examples.timefold.domain.Session;
4 | import com.examples.timefold.domain.TimeTable;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.stereotype.Service;
7 | import org.springframework.transaction.annotation.Transactional;
8 |
9 | @Service
10 | @Transactional
11 | public class TimeTableRepository {
12 |
13 | // There is only one time table, so there is only timeTableId (= problemId).
14 | public static final Long SINGLETON_TIME_TABLE_ID = 1L;
15 |
16 | @Autowired
17 | private TimeslotRepository timeslotRepository;
18 | @Autowired
19 | private RoomRepository roomRepository;
20 | @Autowired
21 | private SessionRepository sessionRepository;
22 |
23 | public TimeTable findById(Long id) {
24 | if (!SINGLETON_TIME_TABLE_ID.equals(id)) {
25 | throw new IllegalStateException("There is no timeTable with id (" + id + ").");
26 | }
27 | return new TimeTable(
28 | timeslotRepository.findAll(),
29 | roomRepository.findAll(),
30 | sessionRepository.findAll());
31 | }
32 |
33 | public void save(TimeTable timeTable) {
34 | for (Session session : timeTable.getLessonList()) {
35 | sessionRepository.save(session);
36 | }
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/Examples/timefold/src/main/java/com/examples/timefold/persistence/TimeslotRepository.java:
--------------------------------------------------------------------------------
1 | package com.examples.timefold.persistence;
2 |
3 | import com.examples.timefold.domain.Timeslot;
4 | import org.springframework.data.jpa.repository.JpaRepository;
5 |
6 | public interface TimeslotRepository extends JpaRepository {
7 | }
8 |
--------------------------------------------------------------------------------
/Examples/timefold/src/main/java/com/examples/timefold/rest/TimeTableController.java:
--------------------------------------------------------------------------------
1 | package com.examples.timefold.rest;
2 |
3 | import com.examples.timefold.domain.TimeTable;
4 | import com.examples.timefold.persistence.TimeTableRepository;
5 | import ai.timefold.solver.core.api.score.buildin.hardsoft.HardSoftScore;
6 | import ai.timefold.solver.core.api.solver.SolutionManager;
7 | import ai.timefold.solver.core.api.solver.SolverManager;
8 | import ai.timefold.solver.core.api.solver.SolverStatus;
9 | import org.springframework.web.bind.annotation.GetMapping;
10 | import org.springframework.web.bind.annotation.PostMapping;
11 | import org.springframework.web.bind.annotation.RequestMapping;
12 | import org.springframework.web.bind.annotation.RestController;
13 |
14 | @RestController
15 | @RequestMapping("/timeTable")
16 | public class TimeTableController {
17 |
18 | private TimeTableRepository timeTableRepository;
19 | private SolverManager solverManager;
20 | private SolutionManager solutionManager;
21 |
22 | public TimeTableController(TimeTableRepository timeTableRepository, SolverManager solverManager, SolutionManager solutionManager) {
23 | this.timeTableRepository = timeTableRepository;
24 | this.solverManager = solverManager;
25 | this.solutionManager = solutionManager;
26 | }
27 |
28 | @GetMapping()
29 | public TimeTable getTimeTable() {
30 | SolverStatus solverStatus = getSolverStatus();
31 | TimeTable solution = timeTableRepository.findById(TimeTableRepository.SINGLETON_TIME_TABLE_ID);
32 | solutionManager.update(solution);
33 | solution.setSolverStatus(solverStatus);
34 | return solution;
35 | }
36 |
37 | @PostMapping("/solve")
38 | public void solve() {
39 | solverManager.solveAndListen(TimeTableRepository.SINGLETON_TIME_TABLE_ID,
40 | timeTableRepository::findById,
41 | timeTableRepository::save);
42 | }
43 |
44 | public SolverStatus getSolverStatus() {
45 | return solverManager.getSolverStatus(TimeTableRepository.SINGLETON_TIME_TABLE_ID);
46 | }
47 |
48 | @PostMapping("/stopSolving")
49 | public void stopSolving() {
50 | solverManager.terminateEarly(TimeTableRepository.SINGLETON_TIME_TABLE_ID);
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/Examples/timefold/src/test/java/com/examples/timefold/SpringBootApplicationContextTest.java:
--------------------------------------------------------------------------------
1 | package com.examples.timefold;
2 |
3 | import org.junit.jupiter.api.Test;
4 | import org.springframework.boot.test.context.SpringBootTest;
5 |
6 | @SpringBootTest
7 | class SpringBootApplicationContextTest {
8 |
9 | @Test
10 | void contextLoads() {
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/Examples/togglz/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | Examples
7 | com.example
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | togglz
13 |
14 |
15 |
16 |
17 | org.springframework.boot
18 | spring-boot-starter-web
19 |
20 |
21 |
22 | org.togglz
23 | togglz-spring-boot-starter
24 |
25 |
26 |
27 |
28 | org.togglz
29 | togglz-console
30 |
31 |
32 |
33 | org.springframework.boot
34 | spring-boot-starter-validation
35 |
36 |
37 |
--------------------------------------------------------------------------------
/Examples/togglz/src/main/java/com/example/TogglzApplication.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.context.annotation.Bean;
6 | import org.togglz.core.manager.EnumBasedFeatureProvider;
7 | import org.togglz.core.spi.FeatureProvider;
8 |
9 | // See application.properties
10 | @SpringBootApplication
11 | public class TogglzApplication {
12 | public static void main(String[] args) {
13 | SpringApplication.run(TogglzApplication.class, args);
14 | }
15 | @Bean
16 | public FeatureProvider featureProvider() {
17 | return new EnumBasedFeatureProvider(TogglzFeatures.class);
18 | }
19 | }
--------------------------------------------------------------------------------
/Examples/togglz/src/main/java/com/example/TogglzController.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import org.springframework.web.bind.annotation.GetMapping;
4 | import org.springframework.web.bind.annotation.RestController;
5 | import org.togglz.core.manager.FeatureManager;
6 |
7 | import static com.example.TogglzFeatures.ALMOST_READY;
8 | import static com.example.TogglzFeatures.AWESOME;
9 |
10 | // http://localhost:8080/actuator/togglz
11 | // http://localhost:8080/console
12 | @RestController
13 | public class TogglzController {
14 | private FeatureManager featureManager;
15 |
16 | public TogglzController(FeatureManager featureManager) {
17 | this.featureManager = featureManager;
18 | }
19 |
20 | @GetMapping("feature1")
21 | public String feature1() {
22 | return "Standard old stuff";
23 | }
24 |
25 | @GetMapping("awesome")
26 | public String awesome() {
27 | if (featureManager.isActive(AWESOME)) {
28 | return "Awesome feature";
29 | } else {
30 | return "";
31 | }
32 | }
33 |
34 | @GetMapping("almostready")
35 | public String almostready() {
36 | if (featureManager.isActive(ALMOST_READY)) {
37 | return "Almost ready feature";
38 | } else {
39 | return "";
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/Examples/togglz/src/main/java/com/example/TogglzFeatures.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import org.togglz.core.Feature;
4 | import org.togglz.core.annotation.EnabledByDefault;
5 | import org.togglz.core.annotation.Label;
6 |
7 | public enum TogglzFeatures implements Feature {
8 |
9 | @EnabledByDefault
10 | @Label("Awesome Feature")
11 | AWESOME,
12 |
13 | @Label("Almost ready Feature")
14 | ALMOST_READY;
15 | }
16 |
--------------------------------------------------------------------------------
/Examples/togglz/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | togglz.enabled=true
2 | togglz.console.enabled=true
3 | togglz.console.secured=false
4 | togglz.console.path=/console
5 | togglz.console.use-management-port=false
6 |
7 |
--------------------------------------------------------------------------------
/Examples/typesafe-config/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | Examples
7 | com.example
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | typesafe-config
13 |
14 |
15 |
16 | com.typesafe
17 | config
18 |
19 |
20 |
21 | pl.touk
22 | tsc-reload
23 |
24 |
25 |
--------------------------------------------------------------------------------
/Examples/typesafe-config/src/test/java/com/examples/TypeSafeConfigTest.java:
--------------------------------------------------------------------------------
1 | package com.examples;
2 |
3 | import com.typesafe.config.Config;
4 | import com.typesafe.config.ConfigFactory;
5 | import org.junit.jupiter.api.Test;
6 | import pl.touk.tscreload.Reloadable;
7 | import pl.touk.tscreload.TscReloadableConfigFactory;
8 |
9 | import java.io.File;
10 | import java.time.Duration;
11 |
12 | import static org.junit.jupiter.api.Assertions.assertEquals;
13 |
14 | public class TypeSafeConfigTest {
15 |
16 | @Test
17 | void testConfig() throws InterruptedException {
18 | System.setProperty("typesafe-config.answer", "42 from a system property");
19 |
20 | Config configuration = ConfigFactory.load();
21 |
22 | assertEquals("42 from a system property", configuration.getString("typesafe-config.answer"));
23 | assertEquals("? from application.properties", configuration.getString("typesafe-config.question"));
24 |
25 | // Optional hot reload config with extra dependency
26 | Reloadable configReloadable = TscReloadableConfigFactory.parseFile(new File("src/test/resources/application.properties"), Duration.ofSeconds(1));
27 | //Reloadable integerReloadable = configReloadable.map(c -> c.getInt("typesafe-config.changevalue"));
28 |
29 |
30 |
31 | for (int i = 0; i < 10; i++) {
32 | System.out.println("Default configuration: " + configuration.getInt("typesafe-config.changevalue"));
33 | System.out.println("Hot reload configuration: " + configReloadable.map(c -> c.getInt("typesafe-config.changevalue")).currentValue());
34 | Thread.sleep(5000);
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/Examples/typesafe-config/src/test/resources/application.properties:
--------------------------------------------------------------------------------
1 | # TypeSafe Config
2 | typesafe-config.answer=42 from application.properties
3 | typesafe-config.question=? from application.properties
4 | typesafe-config.changevalue=42
--------------------------------------------------------------------------------
/Examples/vavr/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | Examples
7 | com.example
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | vavr
13 |
14 |
15 |
16 | io.vavr
17 | vavr
18 |
19 |
20 |
--------------------------------------------------------------------------------
/Examples/vavr/src/test/java/com/examples/VavrTest.java:
--------------------------------------------------------------------------------
1 | package com.examples;
2 |
3 | import io.vavr.Function8;
4 | import io.vavr.Lazy;
5 | import io.vavr.Tuple;
6 | import io.vavr.Tuple2;
7 | import io.vavr.collection.List;
8 | import io.vavr.control.Option;
9 | import io.vavr.control.Try;
10 | import org.junit.jupiter.api.Test;
11 |
12 | import java.util.Locale;
13 |
14 | import static org.junit.jupiter.api.Assertions.*;
15 |
16 | public class VavrTest {
17 |
18 | @Test
19 | void testVavrOptions() {
20 | Option