Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
FROM maven:3.8.4-openjdk-8 AS build
FROM maven:3.8.4-openjdk-17 AS build
WORKDIR /app
COPY pom.xml .
COPY src ./src
COPY web ./web
RUN mvn clean package

FROM tomcat:8.5-jre8
FROM tomcat:8.5-jdk17-temurin

# Instala o unzip para inspeção do .war
RUN apt-get update && apt-get install -y unzip

# Copia o .war gerado pelo Maven
COPY --from=build /app/target/*.war /usr/local/tomcat/webapps/ROOT.war
COPY context.xml /usr/local/tomcat/conf/
EXPOSE 8080
CMD ["catalina.sh", "run"]
EXPOSE 8080 5005
CMD ["catalina.sh", "run"]
5 changes: 5 additions & 0 deletions Dockerfile.tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM maven:3.8.4-openjdk-8

RUN apt-get update && apt-get install -y postgresql-client

WORKDIR /app
19 changes: 18 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,21 @@ services:
environment:
- SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/lanchonete
- SPRING_DATASOURCE_USERNAME=postgres
- SPRING_DATASOURCE_PASSWORD=postgres
- SPRING_DATASOURCE_PASSWORD=postgres

tests:
image: maven:3.8.4-openjdk-8
working_dir: /app
volumes:
- ./:/app
depends_on:
db:
condition: service_healthy
# Instala o psql e roda o script de testes
command: /bin/bash -c "apt-get update && apt-get install -y postgresql-client && ./scripts/run_tests.sh"
environment:
- SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/lanchonete
- SPRING_DATASOURCE_USERNAME=postgres
- SPRING_DATASOURCE_PASSWORD=postgres
ports:
- "5005:5005"
37 changes: 37 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,33 @@
<artifactId>json</artifactId>
<version>20210307</version>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.10.2</version>
<scope>test</scope>
</dependency>

<!-- Mockito Core -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.14.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.15.0</version>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>5.8.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand All @@ -64,6 +91,11 @@
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M7</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
Expand All @@ -74,6 +106,11 @@
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat9-maven-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
Expand Down
13 changes: 13 additions & 0 deletions scripts/run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
set -e

echo "Esperando o banco de dados ficar pronto..."
until pg_isready -h db -p 5432 -U postgres; do
>&2 echo "Banco de dados não está pronto ainda..."
sleep 2
done

echo "Banco de dados está pronto. Rodando testes em modo DEBUG..."

# Forçando debug manualmente com suspend=y para aguardar conexão do IntelliJ
mvn test -DforkCount=0 -Dmaven.surefire.argLine="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005"
4 changes: 2 additions & 2 deletions src/java/Controllers/cadastro.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected void processRequest(HttpServletRequest request, HttpServletResponse re

//E Para finalizar, salva no Banco usando o DAO deles
cliente.setEndereco(endereco);

DaoCliente clienteDAO = new DaoCliente();
clienteDAO.salvar(cliente);

Expand Down Expand Up @@ -119,7 +119,7 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
Expand Down
2 changes: 1 addition & 1 deletion src/java/DAO/DaoCliente.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
public class DaoCliente {

private Connection conecta;
Connection conecta;

public DaoCliente(){
this.conecta = new DaoUtil().conecta();
Expand Down
4 changes: 2 additions & 2 deletions src/java/DAO/DaoUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public class DaoUtil {
public Connection conecta(){
try{
Class.forName("org.postgresql.Driver");
String url = "jdbc:postgresql://db:5432/lanchonete";
String url = "jdbc:postgresql://localhost:5432/lanchonete";
String usuario = "postgres";
String senha = "123456";
String senha = "admin123";
return DriverManager.getConnection(url, usuario, senha);
}catch(Exception e){
throw new RuntimeException(e);
Expand Down
5 changes: 5 additions & 0 deletions src/test/java/DAO/BebidaTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package DAO;

public class BebidaTest {

}
Loading