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

Update bug-report file #12

Merged
merged 21 commits into from
Oct 15, 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
10 changes: 9 additions & 1 deletion .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Bug Report
name: Bug Report for testing seMethod
description: File a bug report.
title: "[Bug]: "
labels: ["bug", "triage"]
Expand Down Expand Up @@ -54,6 +54,14 @@ body:
label: Relevant log output
description: Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks.
render: shell
- type: markdown
attributes:
value: |
## Screenshot (if applicable)
If applicable, add a screenshot to help explain your problem.
You can **drag and drop** or **paste** your screenshots directly here in the issue.

![Screenshot](image-url) <!-- Instruct users to replace this comment by dragging images -->
- type: checkboxes
id: terms
attributes:
Expand Down
63 changes: 55 additions & 8 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
name: A workflow for my Hello World App
on: push

on:
push:
branches:
- master
- develop
jobs:
build:
name: Hello world action
UnitTests:
name: Unit Tests
runs-on: ubuntu-20.04
steps:
- name: Checkout
Expand All @@ -15,8 +18,52 @@ jobs:
with:
java-version: '17'
distribution: 'adopt'
- name: Build with Maven
run: mvn package
- name: Run docker compose
run: docker compose up --abort-on-container-exit
- name: Unit Tests
run: mvn -Dtest=com.napier.sem.AppTest test

IntegrationTests:
name: Integration Tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
submodules: recursive

- name: Set up JDK 17
uses: actions/setup-java@v2
with:
java-version: '17'
distribution: 'adopt'

- name: Integration Tests and CodeCov
run: |
docker build -t database ./db
docker run --name employees -dp 33060:3306 database
mvn -Dtest=com.napier.sem.AppIntegrationTest test jacoco:report
docker stop employees
docker rm employees
docker image rm database

- name: Upload results to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}

build:
name: Build and Start Using docker compose
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2
with:
submodules: recursive
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
java-version: '17'
distribution: 'adopt'
- name: Package and Run docker compose
run: |
mvn package -DskipTests
docker compose up --abort-on-container-exit
1 change: 1 addition & 0 deletions .idea/vcs.xml

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

4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM openjdk:17-oracle
COPY ./target/seMethods-1.0-SNAPSHOT-jar-with-dependencies.jar /tmp
COPY ./target/devopsethods.jar /tmp
WORKDIR /tmp
ENTRYPOINT ["java", "-jar", "seMethods-1.0-SNAPSHOT-jar-with-dependencies.jar"]
ENTRYPOINT ["java", "-jar", "devopsethods.jar", "db:3306", "30000"]
65 changes: 62 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,85 @@

<groupId>com.napier.sem</groupId>
<artifactId>seMethods</artifactId>
<version>1.0-SNAPSHOT</version>
<version>1.0-alpha-2</version>

<properties>
<maven.compiler.source>10</maven.compiler.source>
<maven.compiler.target>10</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<!-- MySQL Connector -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.18</version>
</dependency>

<!-- JUnit 5 -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.1.0</version>
<scope>test</scope>
</dependency>

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

<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>1.9.0</version> <!-- Adding JUnit platform launcher to ensure JUnit 5 is picked up -->
<scope>test</scope>
</dependency>

</dependencies>

<build>
<finalName>devopsethods</finalName>
<plugins>
<!-- Maven Surefire Plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
</plugin>

<!-- Jacoco Plugin for Test Coverage -->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version> <!-- Use latest version -->
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>

<!-- Maven Assembly Plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<finalName>devopsethods</finalName>
<archive>
<manifest>
<mainClass>com.napier.sem.App</mainClass>
Expand All @@ -37,6 +93,7 @@
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
Expand All @@ -48,6 +105,8 @@
</execution>
</executions>
</plugin>


</plugins>
</build>

Expand Down
8 changes: 8 additions & 0 deletions seMethods.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module version="4">
<component name="AdditionalModuleElements">
<content url="file://$MODULE_DIR$" dumb="true">
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
</content>
</component>
</module>
91 changes: 50 additions & 41 deletions src/main/java/com/napier/sem/App.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.napier.sem;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class App
{
Expand All @@ -12,39 +14,31 @@ public class App
/**
* Connect to the MySQL database
*/
public void connect()
{
try
{
public void connect(String location, int delay) {
try {
// Load Database driver
Class.forName("com.mysql.cj.jdbc.Driver");
}
catch (ClassNotFoundException e)
{
} catch (ClassNotFoundException e) {
System.out.println("Could not load SQL driver");
System.exit(-1);
}

int retries = 100;
for (int i = 0; i < retries; ++i)
{
int retries = 10;
for (int i = 0; i < retries; ++i) {
System.out.println("Connecting to database...");
try
{
try {
// Wait a bit for db to start
Thread.sleep(30000);
Thread.sleep(delay);
// Connect to database
con = DriverManager.getConnection("jdbc:mysql://db:3306/employees?allowPublicKeyRetrieval=true&useSSL=false", "root", "example");
con = DriverManager.getConnection("jdbc:mysql://" + location
+ "/employees?allowPublicKeyRetrieval=true&useSSL=false",
"root", "example");
System.out.println("Successfully connected");
break;
}
catch (SQLException sqle)
{
} catch (SQLException sqle) {
System.out.println("Failed to connect to database attempt " + Integer.toString(i));
System.out.println(sqle.getMessage());
}
catch (InterruptedException ie)
{
} catch (InterruptedException ie) {
System.out.println("Thread interrupted? Should not happen.");
}
}
Expand All @@ -69,10 +63,8 @@ public void disconnect()
}
}

public Employee getEmployee(int ID)
{
try
{
public Employee getEmployee(int ID) {
try {
// Create an SQL statement
Statement stmt = con.createStatement();
// Create string for SQL statement
Expand All @@ -84,29 +76,28 @@ public Employee getEmployee(int ID)
ResultSet rset = stmt.executeQuery(strSelect);
// Return new employee if valid.
// Check one is returned
if (rset.next())
{
if (rset.next()) {
Employee emp = new Employee();
emp.emp_no = rset.getInt("emp_no");
emp.first_name = rset.getString("first_name");
emp.last_name = rset.getString("last_name");
return emp;
}
else
} else
return null;
}
catch (Exception e)
{
} catch (Exception e) {
System.out.println(e.getMessage());
System.out.println("Failed to get employee details");
return null;
}
}

public void displayEmployee(Employee emp)
{
if (emp != null)
{
/**
* Display Employee
*
* @param emp
*/
public void displayEmployee(Employee emp) {
if (emp != null) {
System.out.println(
emp.emp_no + " "
+ emp.first_name + " "
Expand All @@ -123,15 +114,33 @@ public static void main(String[] args)
// Create new Application
App a = new App();

// Connect to database
a.connect();
// Create new Application and Connect to database
if (args.length < 1){
a.connect("localhost:33060", 5000);
}else {
a.connect(args[0], Integer.parseInt(args[1]));
}


EmployeeSQL employeeSQL = new EmployeeSQL(a.con);
EmployeeDisplay employeeDisplay = new EmployeeDisplay();

// get Employee database
Employee emp = a.getEmployee(255530);
String title = "Engineer";
// get Employee who are Engineers database
ArrayList<Employee> emp = employeeSQL.getEmployeeWithTitle("Engineer");
employeeDisplay.displayEmployeeWithTitle(emp, title);

ArrayList<Employee> emp1 = employeeSQL.getAllSalaries();
employeeDisplay.printSalaries(emp1);

// department
String department = "Development";
DepartmentSQL departmentSQL = new DepartmentSQL(a.con);
Department dept = departmentSQL.getDepartment(department);
List<Employee> emp2 = employeeSQL.getSalariesByDepartment(dept);
employeeDisplay.displaySalariesByDepartment(emp2, department);

a.displayEmployee(emp);
// Disconnect from database
a.disconnect();

}
}
Loading
Loading