Skip to content

Commit

Permalink
Test/database postgres (#94)
Browse files Browse the repository at this point in the history
* consertando typo

* criando classe de teste, erro encontrado em variavelEnvExists

* removendo teste com instancia invalida

* removendo sysout

* adicionando construtor

* adicionando visualizacao das classes de teste detectadas

* mudando privacidade do construtor

* corrigindo maven.yml

* inicializando variaveis no construtor tambem
  • Loading branch information
Joao-Pedro-P-Holanda authored Nov 1, 2023
1 parent 9068135 commit 3ab75d3
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 35 deletions.
67 changes: 33 additions & 34 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,42 @@ name: Java CI with Maven

on:
push:
branches: [ "main","development" ]
branches: ["main", "development"]
pull_request:
branches: [ "main","development" ]
branches: ["main", "development"]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up JDK 20.0.2
uses: actions/setup-java@v3
with:
java-version: '20.0.2'
distribution: 'temurin'
cache: maven
- name: Set up Environment Variables
env:
URL: ${{ secrets.URL }}
USER_NAME: ${{ secrets.USER_NAME }}
PASSWORD: ${{ secrets.PASSWORD }}
ACCESS_KEY: ${{ secrets.ACCESS_KEY }}
SECRET_KEY: ${{ secrets.SECRET_KEY }}
URL_TEST: ${{ secrets.URL_TEST }}
USER_NAME_TEST: ${{ secrets.USER_NAME_TEST }}
PASSWORD_TEST: ${{ secrets.PASSWORD_TEST }}
run: |
echo "URL=$URL" > $GITHUB_WORKSPACE/.env
echo "USER_NAME=$USER_NAME" >> $GITHUB_WORKSPACE/.env
echo "PASSWORD=$PASSWORD" >> $GITHUB_WORKSPACE/.env
echo "ACCESS_KEY=$ACCESS_KEY" >> $GITHUB_WORKSPACE/.env
echo "SECRET_KEY=$SECRET_KEY" >> $GITHUB_WORKSPACE/.env
echo "URL_TEST=$URL_TEST" >> $GITHUB_WORKSPACE/.env
echo "USER_NAME_TEST=$USER_NAME_TEST" >> $GITHUB_WORKSPACE/.env
echo "PASSWORD_TEST=$PASSWORD_TEST" >> $GITHUB_WORKSPACE/.env
- name: Build with Maven
run: mvn -B package --file pom.xml
- uses: actions/checkout@v3
- name: Set up JDK 20.0.2
uses: actions/setup-java@v3
with:
java-version: "20.0.2"
distribution: "temurin"
cache: maven

- name: Set up Environment Variables
env:
URL: ${{ secrets.URL }}
USER_NAME: ${{ secrets.USER_NAME }}
PASSWORD: ${{ secrets.PASSWORD }}
ACCESS_KEY: ${{ secrets.ACCESS_KEY }}
SECRET_KEY: ${{ secrets.SECRET_KEY }}
URL_TEST: ${{ secrets.URL_TEST }}
USER_NAME_TEST: ${{ secrets.USER_NAME_TEST }}
PASSWORD_TEST: ${{ secrets.PASSWORD_TEST }}
run: |
echo "URL=$URL" > $GITHUB_WORKSPACE/.env
echo "USER_NAME=$USER_NAME" >> $GITHUB_WORKSPACE/.env
echo "PASSWORD=$PASSWORD" >> $GITHUB_WORKSPACE/.env
echo "ACCESS_KEY=$ACCESS_KEY" >> $GITHUB_WORKSPACE/.env
echo "SECRET_KEY=$SECRET_KEY" >> $GITHUB_WORKSPACE/.env
echo "URL_TEST=$URL_TEST" >> $GITHUB_WORKSPACE/.env
echo "USER_NAME_TEST=$USER_NAME_TEST" >> $GITHUB_WORKSPACE/.env
echo "PASSWORD_TEST=$PASSWORD_TEST" >> $GITHUB_WORKSPACE/.env
- name: Build with Maven
run: mvn -B package --file pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void setSenha(String passwordKey) throws IncorrectEnvironmentVariableExce
}

private boolean variavelEnvExists(String envKey) {
return dotenv.get(envKey) == null;
return dotenv.get(envKey) != null;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.casaculturaqxd.sgec.jdbc;

import java.sql.Connection;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;


public class TestDatabasePostgres {
DatabasePostgres database;
String INVALID_ENV = "";

public TestDatabasePostgres() {
database = DatabasePostgres.getInstance("URL_TEST", "USER_NAME_TEST", "PASSWORD_TEST");
INVALID_ENV = "";
}

@BeforeEach
public void setUp() throws IncorrectEnvironmentVariableException {
database = DatabasePostgres.getInstance("URL_TEST", "USER_NAME_TEST", "PASSWORD_TEST");
}


@Test
public void testUniqueInstance() {
Connection firstConnection = database.getConnection();
Connection secondConnection = database.getConnection();
assertEquals(firstConnection, secondConnection);
}


@Test
public void testDesconectarOnValidConnection() {
database.getConnection();
assertDoesNotThrow(() -> {
database.desconectar(database.getConnection());
});
}

@Test
public void testSetInvalidUrlDataBase() throws IncorrectEnvironmentVariableException {
assertThrows(IncorrectEnvironmentVariableException.class, () -> {
database.setUrlDataBase(INVALID_ENV);
});
}

@Test
public void testSetInvalidNomeUsuario() {
assertThrows(IncorrectEnvironmentVariableException.class, () -> {
database.setNomeUsuario(INVALID_ENV);
});
}

@Test
public void testSetInvalidSenha() {
assertThrows(IncorrectEnvironmentVariableException.class, () -> {
database.setSenha(INVALID_ENV);
});
}

}

0 comments on commit 3ab75d3

Please sign in to comment.