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

databaseTests #1733

Merged
merged 9 commits into from
Sep 11, 2024
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
23 changes: 22 additions & 1 deletion .github/workflows/e2eTests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,30 @@ jobs:
Ubuntu_Database:
needs: [ Ubuntu_APIs ]
runs-on: ubuntu-latest
services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432

steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Connect to PostgreSQL
run: |
cd src/main/resources/docker-compose/postgres/
npm install pg
node client.js
env:
POSTGRES_HOST: localhost
POSTGRES_PORT: 5432
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
Expand All @@ -25,7 +46,7 @@ jobs:
cache: 'maven'
- name: Run tests
continue-on-error: true
run: mvn -e test "-DdefaultElementIdentificationTimeout=5" "-DsetParallelMode=DYNAMIC" "-DsetParallel=METHODS" "-DgenerateAllureReportArchive=true" "-Dtest=%regex[.*DatabaseActions.*], %regex[.*DB.*], %regex[.*Db.*], %regex[.*db.*]"
run: mvn -e test "-DgenerateAllureReportArchive=true" "-Dtest=%regex[.*DatabaseActions.*], %regex[.*DB.*], %regex[.*Db.*], %regex[.*db.*]"
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
Expand Down
29 changes: 29 additions & 0 deletions src/main/resources/docker-compose/postgres/client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const { Client } = require('pg');

const pgclient = new Client({
host: process.env.POSTGRES_HOST,
port: process.env.POSTGRES_PORT,
user: 'postgres',
password: 'postgres',
database: 'postgres'
});

pgclient.connect();

const table = 'CREATE TABLE student(id SERIAL PRIMARY KEY, firstName VARCHAR(40) NOT NULL, lastName VARCHAR(40) NOT NULL, age INT, address VARCHAR(80), email VARCHAR(40))'
const text = 'INSERT INTO student(firstname, lastname, age, address, email) VALUES($1, $2, $3, $4, $5) RETURNING *'
const values = ['Mona the', 'Octocat', 9, '88 Colin P Kelly Jr St, San Francisco, CA 94107, United States', 'octocat@github.com']

pgclient.query(table, (err, res) => {
if (err) throw err
});

pgclient.query(text, values, (err, res) => {
if (err) throw err
});

pgclient.query('SELECT * FROM student', (err, res) => {
if (err) throw err
console.log(err, res.rows) // Print the data in student table
pgclient.end()
});
61 changes: 0 additions & 61 deletions src/test/java/mockito/DatabaseActionsTests.java

This file was deleted.

42 changes: 42 additions & 0 deletions src/test/java/testPackage/mockedTests/DbTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package testPackage.mockedTests;

import com.shaft.driver.SHAFT;
import com.shaft.db.DatabaseActions.*;
import org.testng.annotations.*;

public class DbTests {
SHAFT.DB databaseInstance;

@BeforeClass
public void beforeMethod(){
databaseInstance = new SHAFT.DB(DatabaseType.POSTGRES_SQL, "localhost","5432","postgres","postgres","postgres");
}

@Test
public void select(){
databaseInstance.executeSelectQuery("SELECT * FROM student");
SHAFT.Validations.assertThat().object(databaseInstance.getResult()).contains("Octocat");
}

@Test(dependsOnMethods = {"select"})
public void insert() {
databaseInstance.executeInsertQuery("INSERT INTO student(firstname, lastname, age, address, email) VALUES('Ahmed the', 'Octocat', 9, '88 Colin P Kelly Jr St, San Francisco, CA 94107, United States', 'ahmedoctocat@github.com')");
databaseInstance.executeSelectQuery("SELECT * FROM student");
SHAFT.Validations.assertThat().object(databaseInstance.getResult()).contains("Ahmed");
}

@Test(dependsOnMethods = {"select","insert"})
public void update() {
databaseInstance.executeUpdateQuery("UPDATE student SET age = 8 WHERE email = 'octocat@github.com';");
databaseInstance.executeSelectQuery("SELECT * FROM student");
SHAFT.Validations.assertThat().object(databaseInstance.getResult()).contains("8");
}

@Test(dependsOnMethods = {"select","insert","update"})
public void delete() {
databaseInstance.executeDeleteQuery("DELETE FROM student WHERE email = 'octocat@github.com';");
databaseInstance.executeSelectQuery("SELECT * FROM student");
SHAFT.Validations.assertThat().object(databaseInstance.getResult()).doesNotContain("Mona");
}

}
Loading