Skip to content

Commit

Permalink
Corrected junit tests; Updated pom dependencies to latest; Updated pr…
Browse files Browse the repository at this point in the history
…oject version, readme and changed Dockerfile to use supervisord and java 22
  • Loading branch information
MarkoDojkic committed Nov 2, 2024
1 parent 1a54666 commit 9cf6052
Show file tree
Hide file tree
Showing 20 changed files with 228 additions and 124 deletions.
33 changes: 18 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Stage 1: Build the Spring Boot application
FROM amazoncorretto:21-alpine AS build
FROM amazoncorretto:22-alpine-jdk AS build

# Install necessary build tools
RUN apk add --no-cache maven
Expand All @@ -15,34 +15,37 @@ COPY src /app/src/
RUN mvn clean package -DskipTests

# Stage 2: Create an image with RabbitMQ and your Spring Boot application
FROM rabbitmq:3.13.7-management-alpine AS final
FROM rabbitmq:management-alpine AS final

# Install necessary runtime packages
RUN apk add --no-cache openjdk21-jdk \
RUN apk add --no-cache openjdk22-jdk supervisor \
&& rabbitmq-plugins enable --offline rabbitmq_mqtt \
&& rabbitmq-plugins enable --offline rabbitmq_web_mqtt
&& rabbitmq-plugins enable --offline rabbitmq_web_mqtt \
&& addgroup -S runtimeUsers \
&& adduser -S runtimeUser -G runtimeUsers

# Copy the Spring Boot application from the build stage
COPY --from=build /app/target/softwaredevelopmentsimulation-1.3.0.jar /app/software-development-simulation.jar
COPY --from=build /app/target/softwaredevelopmentsimulation-1.4.0.jar /app/software-development-simulation.jar

#Use nonroot user to run application
USER runtimeUser

# Supervisor configuration
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf

# Add a health check for RabbitMQ
HEALTHCHECK --interval=10s --timeout=3s --retries=3 \
CMD nc -z localhost 5672 || exit 1
CMD ["sh", "-c", "nc -z localhost 5672 || exit 1"]

# Expose ports for RabbitMQ and Spring Boot application
EXPOSE 5672 15672 15675 21682

# Start RabbitMQ and wait for it to be ready before starting the Spring Boot application
CMD sh -c "rabbitmq-server & \
until nc -z localhost 5672; do \
echo 'Waiting for RabbitMQ...'; \
sleep 1; \
done; \
java -jar /app/software-development-simulation.jar"
# Use supervisord to start and manage RabbitMQ and the Java application
ENTRYPOINT ["supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]

LABEL maintainer="Marko Dojkic <marko.dojkic@gmail.com>" \
version="1.3.0" \
version="1.4.0" \
description="Docker image for the Software Development Simulation Spring Boot application" \
org.opencontainers.image.source="https://github.com/MarkoDojkic/Software-Development-Simulation" \
org.opencontainers.image.documentation="https://github.com/MarkoDojkic/Software-Development-Simulation#readme" \
org.opencontainers.image.licenses="MIT"
org.opencontainers.image.licenses="MIT"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The Software Development Simulation project is a web-based application designed

## Features

- **Spring Boot Application**: Built with Spring Boot 3.3.3.
- **Spring Boot Application**: Built with Spring Boot 3.3.5.
- **Spring Integration**: Configured with multiple channels for task management.
- **Swagger Documentation**: Integrated for API documentation and testing.
- **SonarQube Integration**: Quality and security analysis with all issues resolved.
Expand Down
22 changes: 11 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>dev.markodojkic</groupId>
<artifactId>softwaredevelopmentsimulation</artifactId>
<name>Software development simulator™</name>
<version>1.3.0</version>
<version>1.4.0</version>
<url>https://github.com/MarkoDojkic/Software-Development-Simulation</url>
<licenses>
<license>
Expand Down Expand Up @@ -37,10 +37,10 @@
</issueManagement>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring-version>3.3.2</spring-version>
<spring-integration-version>6.3.2</spring-integration-version>
<spring-version>3.3.5</spring-version>
<spring-integration-version>6.3.5</spring-integration-version>
<jmockit-version>1.49.2</jmockit-version>
<junit-jupiter-version>5.11.0</junit-jupiter-version>
<junit-jupiter-version>5.11.3</junit-jupiter-version>
<application.version>${project.version}</application.version>
</properties>

Expand Down Expand Up @@ -138,7 +138,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>33.3.0-jre</version>
<version>33.3.1-jre</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -183,13 +183,13 @@
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite-api</artifactId>
<version>1.11.0</version>
<version>1.11.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>5.13.0</version>
<version>5.14.2</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -248,8 +248,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<source>21</source>
<target>21</target>
<source>22</source>
<target>22</target>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -279,10 +279,10 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
<version>3.5.1</version>
<configuration>
<argLine>
${argLine} <!-- Needed for jacoco to run -->
${argLine} <!-- Defines jacoco javaagent -->
-Dspring.profiles.active=test
-Xshare:off
-XX:+EnableDynamicAgentLoading
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
@MessageEndpoint
public class DeveloperImpl {
private static final Logger logger = Logger.getLogger(DeveloperImpl.class.getName());
public static final String SPRING_PROFILES_ACTIVE = "spring.profiles.active";
public static final String TEST = "test";

@ServiceActivator(inputChannel = "trivialTechnicalTask.intermediate", outputChannel = "doneTechnicalTasks.output")
public TechnicalTask trivialTaskHandler(TechnicalTask technicalTask) {
Expand All @@ -29,7 +31,7 @@ public TechnicalTask trivialTaskHandler(TechnicalTask technicalTask) {
* (6 - technicalTask.getPriority().getUrgency()) / 5.0
* 0.01
+ 1500)
, TimeUnit.MILLISECONDS);
, System.getProperty(SPRING_PROFILES_ACTIVE, "").equals(TEST) ? TimeUnit.NANOSECONDS : TimeUnit.MILLISECONDS);
logger.log(Level.INFO, () -> colorize(String.format("%n###Developer %s finished working on trivial technical task %s", technicalTask.getAssignee().getDisplayName(), technicalTask.getId()), Attribute.TEXT_COLOR(0), Attribute.BACK_COLOR(technicalTask.getPriority().getAnsiColorCode())));
return technicalTask;
}
Expand All @@ -45,7 +47,7 @@ public TechnicalTask normalTaskHandler(TechnicalTask technicalTask) {
* (6 - technicalTask.getPriority().getUrgency()) / 5.0
* 0.02
+ 1500)
, TimeUnit.MILLISECONDS);
, System.getProperty(SPRING_PROFILES_ACTIVE, "").equals(TEST) ? TimeUnit.NANOSECONDS : TimeUnit.MILLISECONDS);
logger.log(Level.INFO, () -> colorize(String.format("%n###Developer %s finished working on normal technical task %s", technicalTask.getAssignee().getDisplayName(), technicalTask.getId()), Attribute.TEXT_COLOR(0), Attribute.BACK_COLOR(technicalTask.getPriority().getAnsiColorCode())));
return technicalTask;
}
Expand All @@ -61,7 +63,7 @@ public TechnicalTask minorTaskHandler(TechnicalTask technicalTask) {
* (6 - technicalTask.getPriority().getUrgency()) / 5.0
* 0.03
+ 1500)
, TimeUnit.MILLISECONDS);
, System.getProperty(SPRING_PROFILES_ACTIVE, "").equals(TEST) ? TimeUnit.NANOSECONDS : TimeUnit.MILLISECONDS);
logger.log(Level.INFO, () -> colorize(String.format("%n###Developer %s finished working on minor technical task %s", technicalTask.getAssignee().getDisplayName(), technicalTask.getId()), Attribute.TEXT_COLOR(0), Attribute.BACK_COLOR(technicalTask.getPriority().getAnsiColorCode())));
return technicalTask;
}
Expand All @@ -77,7 +79,7 @@ public TechnicalTask majorTaskHandler(TechnicalTask technicalTask) {
* (6 - technicalTask.getPriority().getUrgency()) / 5.0
* 0.04
+ 1500)
, TimeUnit.MILLISECONDS);
, System.getProperty(SPRING_PROFILES_ACTIVE, "").equals(TEST) ? TimeUnit.NANOSECONDS : TimeUnit.MILLISECONDS);
logger.log(Level.INFO, () -> colorize(String.format("%n###Developer %s finished working on major technical task %s", technicalTask.getAssignee().getDisplayName(), technicalTask.getId()), Attribute.TEXT_COLOR(0), Attribute.BACK_COLOR(technicalTask.getPriority().getAnsiColorCode())));
return technicalTask;
}
Expand All @@ -93,7 +95,7 @@ public TechnicalTask criticalTaskHandler(TechnicalTask technicalTask) {
* (6 - technicalTask.getPriority().getUrgency()) / 5.0
* 0.05
+ 1500)
, TimeUnit.MILLISECONDS);
, System.getProperty(SPRING_PROFILES_ACTIVE, "").equals(TEST) ? TimeUnit.NANOSECONDS : TimeUnit.MILLISECONDS);
logger.log(Level.INFO, () -> colorize(String.format("%n###Developer %s finished working on critical technical task %s", technicalTask.getAssignee().getDisplayName(), technicalTask.getId()), Attribute.TEXT_COLOR(0), Attribute.BACK_COLOR(technicalTask.getPriority().getAnsiColorCode())));
return technicalTask;
}
Expand All @@ -109,7 +111,7 @@ public TechnicalTask blockerTaskHandler(TechnicalTask technicalTask) {
* (6 - technicalTask.getPriority().getUrgency()) / 5.0
* 0.06
+ 1500)
, TimeUnit.MILLISECONDS);
, System.getProperty(SPRING_PROFILES_ACTIVE, "").equals(TEST) ? TimeUnit.NANOSECONDS : TimeUnit.MILLISECONDS);
logger.log(Level.INFO, () -> colorize(String.format("%n###Developer %s finished working on blocker technical task %s", technicalTask.getAssignee().getDisplayName(), technicalTask.getId()), Attribute.TEXT_COLOR(0), Attribute.BACK_COLOR(technicalTask.getPriority().getAnsiColorCode())));
return technicalTask;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ public OpenAPI customOpenAPI() {
return new OpenAPI()
.info(new Info().title("Software development simulator™ API")
.description("This is the API documentation for the Software development simulator™ Developed by Ⓒ Marko Dojkić")
.version("v1.3.0")
.license(new License().name("Apache 2.0").url("https://springdoc.org")))
.version("v1.4.0")
.license(new License()
.name("MIT License")
.url("https://github.com/MarkoDojkic/Software-Development-Simulation/blob/main/LICENSE")))
.externalDocs(new ExternalDocumentation()
.description("GitHub Repository")
.url("https://github.com/MarkoDojkic/Software-Development-Simulation"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ public class Utilities {
static {
boolean isTesting = System.getProperty("spring.profiles.active", "default").equals("test");

Path base = isTesting ? Paths.get("src/test/resources", "dev.markodojkic.software_development_simulation.testing_data") : Paths.get(System.getProperty("user.home"), "dev.markodojkic", "software_development_simulation", "1.3.0");
Path base = isTesting ? Paths.get("src/test/resources", "dev.markodojkic.software_development_simulation.testing_data") : Paths.get(System.getProperty("user.home"), "dev.markodojkic", "software_development_simulation", "1.4.0");

currentApplicationDataPath = base;
currentApplicationLogsPath = Paths.get(String.valueOf(base), "logs", isTesting ? "2012-12-12 00:00:00" : ZonedDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH-mm-ss")));
currentApplicationLogsPath = Paths.get(String.valueOf(base), "logs", isTesting ? "2012-12-12 00-00-00" : ZonedDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH-mm-ss")));

if(isTesting){
try {
Expand Down Expand Up @@ -116,7 +116,7 @@ public static void loadPredefinedTasks(List<Epic> predefinedEpics){
public static void generateRandomEpics(boolean save, int epicCountDownLimit, int epicCountUpperLimit){
List<Epic> epicList = new ArrayList<>();
AtomicReference<String> jiraEpicCreatedOutput = new AtomicReference<>(Strings.EMPTY);
totalEpicsCount = (epicCountDownLimit == 0 && epicCountUpperLimit == 0) ? 0 : SECURE_RANDOM.nextInt(epicCountDownLimit,epicCountUpperLimit);
totalEpicsCount = epicCountDownLimit == epicCountUpperLimit ? epicCountDownLimit : SECURE_RANDOM.nextInt(epicCountUpperLimit - epicCountDownLimit + 1) + epicCountDownLimit;

getAvailableDevelopmentTeamIds().addAll(IntStream.rangeClosed(0, getCurrentDevelopmentTeamsSetup().size() - 1).boxed().collect(Collectors.toCollection(ArrayList::new)));
totalDevelopmentTeamsPresent = getCurrentDevelopmentTeamsSetup().size();
Expand Down Expand Up @@ -214,7 +214,7 @@ public static void addEpicForSaving(Epic epic) {

public static void saveEpics(){
try {
String folderName = System.getProperty("spring.profiles.active", "default").equals("test") ? "2012-12-12 00:00:00" : ZonedDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH-mm-ss"));
String folderName = System.getProperty("spring.profiles.active", "default").equals("test") ? "2012-12-12 00-00-00" : ZonedDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH-mm-ss"));
Path parentDirectory = Utilities.getCurrentApplicationDataPath().resolve(PREDEFINED_DATA);

Files.createDirectories(parentDirectory.resolve(folderName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public ModelAndView getDevelopersPage(){
})
@GetMapping(value = "/developers/edit")
public ModelAndView getEditingDeveloperForm(@RequestParam("developmentTeamIndex") int developmentTeamIndex, @RequestParam("developerIndex") int developerIndex){
ModelAndView editingDeveloperForm = new ModelAndView("/developers::editingDeveloperForm"); //Warning is false positive: View is thymeleaf fragment contained in developersPage.html file
ModelAndView editingDeveloperForm = new ModelAndView("/developersPage::editingDeveloperForm"); //Warning is false positive: View is thymeleaf fragment contained in developersPage.html file

editingDeveloperForm.addObject("developmentTeams", getCurrentDevelopmentTeamsSetup());
editingDeveloperForm.addObject("developmentTeamIndex", developmentTeamIndex);
Expand Down Expand Up @@ -101,7 +101,7 @@ public String modifyDeveloper(@ModelAttribute(name = "formEditDeveloperPlacehold
@DeleteMapping(value = "/api/deleteDeveloper")
public ModelAndView deleteDeveloper(@RequestParam("developmentTeamIndex") int developmentTeamIndex, @RequestParam("developerIndex") int developerIndex){
removeDeveloper(developmentTeamIndex, developerIndex);
return null; //This call is used in async matter so no redirection is needed
return null; //This call is used in async manner so no redirection is needed
}

private String getBackgroundColor(String text) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public ResponseEntity<String> getPredefinedDataFoldersList() {
@PostMapping(value = "/api/saveSessionData")
public ResponseEntity<String> saveCurrentPredefinedData(@RequestBody String sessionDataJSON){
try {
String folderName = System.getProperty("spring.profiles.active", "default").equals("test") ? "2012-12-12 00:00:00" : ZonedDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH-mm-ss"));
String folderName = System.getProperty("spring.profiles.active", "default").equals("test") ? "2012-12-12 00-00-00" : ZonedDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH-mm-ss"));
Path parentDirectory = getCurrentApplicationDataPath().resolve(PREDEFINED_DATA);

Files.createDirectories(parentDirectory.resolve(folderName));
Expand Down Expand Up @@ -150,6 +150,6 @@ public ResponseEntity<String> applicationFlowPredefined(@RequestBody String pred
@PostMapping(value = "/api/applicationFlowRandomized")
public ModelAndView applicationFlowRandomized(@RequestParam(name = "save", defaultValue = "false", required = false) boolean save, @RequestParam("min") int min, @RequestParam("max") int max){
generateRandomEpics(save, min, max);
return null; //This call is used in async matter so no redirection is needed
return null; //This call is used in async manner so no redirection is needed
}
}
4 changes: 2 additions & 2 deletions src/main/resources/banner.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
\__ \ | | | | | | |_| | | (_| | || (_) | |
|___/_|_| |_| |_|\__,_|_|\__,_|\__\___/|_|

Version: ${application.version}
Powered by Spring Boot ${spring-boot.version}
Application version: ${application.version}
Powered by Spring Boot (v${spring-version}) and Spring Integration (v${spring-integration-version})
Ⓒ Marko Dojkić 2024
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,16 @@
import dev.markodojkic.softwaredevelopmentsimulation.enums.DeveloperType;
import dev.markodojkic.softwaredevelopmentsimulation.model.BaseTask;
import dev.markodojkic.softwaredevelopmentsimulation.model.Developer;
import dev.markodojkic.softwaredevelopmentsimulation.test.Config.GlobalSetupExtension;
import dev.markodojkic.softwaredevelopmentsimulation.test.Config.SoftwareDevelopmentSimulationAppBaseTest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.test.context.SpringBootTest;

import java.time.ZonedDateTime;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

@SpringBootTest
@ExtendWith(GlobalSetupExtension.class)
class BaseTaskTest {
class BaseTaskTest extends SoftwareDevelopmentSimulationAppBaseTest {
@Test
void when_noArgsConstructorIsCalled_correctValuesAreSetAsDefault() {
BaseTask task = new BaseTask();
Expand Down

This file was deleted.

Loading

0 comments on commit 9cf6052

Please sign in to comment.