Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test/database postgres #94

Merged
merged 12 commits into from
Nov 1, 2023
Merged
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
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);
});
}

}