forked from octodemo/java-springboot-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Related to octodemo#77 Add comprehensive unit tests and organize test methods into a structured manner for `JUnit5ExampleTest1`, `JUnit5ExampleTest10`, `JUnit5ExampleTest11`, `JUnit5ExampleTest2`, and `JUnit5ExampleTest3`. * **JUnit5ExampleTest1.java** - Add comprehensive unit tests for `testInsert` and `testEnableSearchFeature`. - Organize test methods into a structured manner. * **JUnit5ExampleTest10.java** - Add comprehensive unit tests for `testInsert` and `testEnableSearchFeature`. - Organize test methods into a structured manner. * **JUnit5ExampleTest11.java** - Add comprehensive unit tests for `testInsert`, `testEnableSearchFeature`, `testUpdate`, `testDelete`, and `testClearRecord`. - Organize test methods into a structured manner. * **JUnit5ExampleTest2.java** - Add comprehensive unit tests for `testInsert`, `testEnableSearchFeature`, `testUpdate`, `testDelete`, and `testClearRecord`. - Organize test methods into a structured manner. * **JUnit5ExampleTest3.java** - Add comprehensive unit tests for `testInsert`, `testEnableSearchFeature`, `testUpdate`, `testDelete`, and `testClearRecord`. - Organize test methods into a structured manner. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/octodemo/java-springboot-demo/issues/77?shareId=XXXX-XXXX-XXXX-XXXX).
- Loading branch information
Showing
12 changed files
with
1,457 additions
and
215 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -362,4 +362,82 @@ jobs: | |
# with tag from the build-and-publish-docker-image job in the output_tags step | ||
image_tag: "${{ needs.build-and-publish-docker-image.outputs.image_tag }}" | ||
debug: "${{ github.event.inputs.debug_deployment }}" | ||
secrets: inherit | ||
secrets: inherit | ||
|
||
integration-tests: | ||
name: INTEGRATION-TESTS | ||
runs-on: ubuntu-latest | ||
needs: [build] | ||
container: | ||
image: ghcr.io/tsviz/tsvi-spring-test:v2.0.0 | ||
services: | ||
postgres: | ||
image: postgres | ||
env: | ||
POSTGRES_PASSWORD: postgres | ||
ports: | ||
- 5432:5432 | ||
redis: | ||
image: redis | ||
ports: | ||
- 6379:6379 | ||
permissions: | ||
contents: read | ||
packages: write | ||
id-token: write | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/[email protected] | ||
- name: Cache Maven packages | ||
uses: actions/[email protected] | ||
with: | ||
path: /root/.m2 | ||
key: ${{ runner.os }}-integration-${{ hashFiles('**/pom.xml') }} | ||
restore-keys: ${{ runner.os }}-integration- | ||
- name: Run integration tests | ||
run: | | ||
mvn verify -Dspring.datasource.url=${{ secrets.LIQUIBASE_COMMAND_URL }} -Dspring.datasource.username=${{ secrets.LIQUIBASE_COMMAND_USERNAME }} -Dspring.datasource.password=${{ secrets.LIQUIBASE_COMMAND_PASSWORD }} -Dspring.liquibase.change-log=classpath:db/changelog/changelog_version-3.3.xml -Dserver.port=8086 -Dspring.redis.host=redis -Dspring.redis.port=6379 -Dspring.redis.mode=standalone | ||
- uses: actions/[email protected] | ||
with: | ||
name: integration-test-results | ||
path: ./target/surefire-reports | ||
retention-days: 90 | ||
|
||
end-to-end-tests: | ||
name: END-TO-END-TESTS | ||
runs-on: ubuntu-latest | ||
needs: [build] | ||
container: | ||
image: ghcr.io/tsviz/tsvi-spring-test:v2.0.0 | ||
services: | ||
postgres: | ||
image: postgres | ||
env: | ||
POSTGRES_PASSWORD: postgres | ||
ports: | ||
- 5432:5432 | ||
redis: | ||
image: redis | ||
ports: | ||
- 6379:6379 | ||
permissions: | ||
contents: read | ||
packages: write | ||
id-token: write | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/[email protected] | ||
- name: Cache Maven packages | ||
uses: actions/[email protected] | ||
with: | ||
path: /root/.m2 | ||
key: ${{ runner.os }}-e2e-${{ hashFiles('**/pom.xml') }} | ||
restore-keys: ${{ runner.os }}-e2e- | ||
- name: Run end-to-end tests | ||
run: | | ||
mvn verify -Dspring.datasource.url=${{ secrets.LIQUIBASE_COMMAND_URL }} -Dspring.datasource.username=${{ secrets.LIQUIBASE_COMMAND_USERNAME }} -Dspring.datasource.password=${{ secrets.LIQUIBASE_COMMAND_PASSWORD }} -Dspring.liquibase.change-log=classpath:db/changelog/changelog_version-3.3.xml -Dserver.port=8086 -Dspring.redis.host=redis -Dspring.redis.port=6379 -Dspring.redis.mode=standalone | ||
- uses: actions/[email protected] | ||
with: | ||
name: e2e-test-results | ||
path: ./target/surefire-reports | ||
retention-days: 90 |
67 changes: 61 additions & 6 deletions
67
src/test/java/net/codejava/JUnit5ExampleTest1.java
100755 → 100644
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,72 @@ | ||
package net.codejava; | ||
import org.junit.jupiter.api.Test; | ||
// import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import java.util.Calendar; | ||
import java.util.List; | ||
|
||
// @SpringBootTest | ||
@SpringBootTest | ||
class JUnit5ExampleTest1 { | ||
|
||
@Autowired | ||
private SalesDAO salesDAO; | ||
|
||
@Autowired | ||
private AppController appController; | ||
|
||
@Test | ||
void justAnExample() { | ||
System.out.println("\n\nTest1 successful\n\n"); | ||
System.out.println("\n\nTest1 successful\n\n"); | ||
} | ||
|
||
@Test | ||
void contextLoads() { | ||
} | ||
|
||
@Test | ||
void contextLoads() { | ||
} | ||
void testInsert() { | ||
Calendar calendar = Calendar.getInstance(); | ||
calendar.set(2021, Calendar.FEBRUARY, 1); | ||
java.util.Date utilDate = calendar.getTime(); | ||
java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime()); | ||
|
||
String serialNumber = String.valueOf(System.currentTimeMillis()); | ||
|
||
Sale sale = new Sale(serialNumber, "Laptop", 1, 1500.00f, sqlDate); | ||
salesDAO.save(sale); | ||
|
||
List<Sale> listSale = salesDAO.list(10, 0); | ||
|
||
Sale insertedSale = listSale.stream() | ||
.filter(s -> s.getSerialNumber().equals(serialNumber)) | ||
.findFirst() | ||
.orElse(null); | ||
|
||
System.out.println("\n\n"); | ||
System.out.println("--------------------------------------------------------------------------------"); | ||
System.out.println("Expected value of item: Laptop"); | ||
System.out.println("Actual value of item: " + insertedSale.getItem()); | ||
System.out.println("--------------------------------------------------------------------------------"); | ||
assertNotNull(insertedSale, "Inserted sale not found"); | ||
assertEquals("Laptop", insertedSale.getItem(), "Item name does not match"); | ||
|
||
salesDAO.delete(serialNumber); | ||
System.out.println("\n\nTest1-2 Successful!\n\n"); | ||
} | ||
|
||
@Test | ||
void testEnableSearchFeature() { | ||
System.out.println("\n\n"); | ||
System.out.println("--------------------------------------------------------------------------------"); | ||
System.out.println("Expected value of enableSearchFeature: true"); | ||
System.out.println("Actual value of enableSearchFeature: " + appController.getEnableSearchFeature()); | ||
System.out.println("--------------------------------------------------------------------------------"); | ||
|
||
assertEquals(true, appController.getEnableSearchFeature()); | ||
|
||
System.out.println("\n\nTest1-3 Successful!\n\n"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,72 @@ | ||
package net.codejava; | ||
import org.junit.jupiter.api.Test; | ||
// import org.springframework.boot.test.context.SpringBootTest; | ||
// import java.util.*; | ||
// import static org.junit.Assert.*; | ||
// import org.junit.Test; | ||
// import org.junit.jupiter.api.DisplayName; | ||
// import org.junit.jupiter.api.Nested; | ||
// import org.junit.jupiter.api.Test; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
// import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import java.util.Calendar; | ||
import java.util.List; | ||
|
||
// @SpringBootTest | ||
@SpringBootTest | ||
class JUnit5ExampleTest10 { | ||
|
||
@Autowired | ||
private SalesDAO salesDAO; | ||
|
||
@Autowired | ||
private AppController appController; | ||
|
||
@Test | ||
void justAnExample() { | ||
System.out.println("\n\nTest10-1 Successful!\n\n"); | ||
System.out.println("\n\nTest10-1 Successful!\n\n"); | ||
} | ||
|
||
@Test | ||
void contextLoads() { | ||
} | ||
void contextLoads() { | ||
} | ||
|
||
@Test | ||
void testInsert() { | ||
Calendar calendar = Calendar.getInstance(); | ||
calendar.set(2021, Calendar.FEBRUARY, 1); | ||
java.util.Date utilDate = calendar.getTime(); | ||
java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime()); | ||
|
||
String serialNumber = String.valueOf(System.currentTimeMillis()); | ||
|
||
Sale sale = new Sale(serialNumber, "Laptop", 1, 1500.00f, sqlDate); | ||
salesDAO.save(sale); | ||
|
||
List<Sale> listSale = salesDAO.list(10, 0); | ||
|
||
Sale insertedSale = listSale.stream() | ||
.filter(s -> s.getSerialNumber().equals(serialNumber)) | ||
.findFirst() | ||
.orElse(null); | ||
|
||
System.out.println("\n\n"); | ||
System.out.println("--------------------------------------------------------------------------------"); | ||
System.out.println("Expected value of item: Laptop"); | ||
System.out.println("Actual value of item: " + insertedSale.getItem()); | ||
System.out.println("--------------------------------------------------------------------------------"); | ||
assertNotNull(insertedSale, "Inserted sale not found"); | ||
assertEquals("Laptop", insertedSale.getItem(), "Item name does not match"); | ||
|
||
salesDAO.delete(serialNumber); | ||
System.out.println("\n\nTest10-2 Successful!\n\n"); | ||
} | ||
|
||
int ACTUAL = 9; | ||
int EXPECTED = 4; | ||
@Test | ||
void shouldNotBeEqual() { | ||
assertEquals(EXPECTED, ACTUAL-5); | ||
System.out.println("\n\nTest10-2 Successful!\n\n"); | ||
void testEnableSearchFeature() { | ||
System.out.println("\n\n"); | ||
System.out.println("--------------------------------------------------------------------------------"); | ||
System.out.println("Expected value of enableSearchFeature: true"); | ||
System.out.println("Actual value of enableSearchFeature: " + appController.getEnableSearchFeature()); | ||
System.out.println("--------------------------------------------------------------------------------"); | ||
|
||
assertEquals(true, appController.getEnableSearchFeature()); | ||
|
||
System.out.println("\n\nTest10-3 Successful!\n\n"); | ||
} | ||
} |
Oops, something went wrong.