From b1a8cac64c5caeded035dd11033042f8f747710b Mon Sep 17 00:00:00 2001 From: Tyrel Souza Date: Mon, 27 Feb 2017 22:56:52 -0500 Subject: [PATCH] add packages, daos, etc --- src/main/java/HourTracker.java | 7 +++--- src/main/java/dao/EntryDAO.java | 8 ++++++ src/main/java/dao/UserDAO.java | 35 ++++++++++++++++++++++++++ src/main/java/db/DBConnection.java | 22 ++++++++++++++++ src/main/java/model/Entry.java | 7 ++++++ src/main/java/model/User.java | 40 ++++++++++++++++++++++++++++++ src/test/java/HourTrackerTest.java | 24 ++++++++++++++---- 7 files changed, 135 insertions(+), 8 deletions(-) create mode 100644 src/main/java/dao/EntryDAO.java create mode 100644 src/main/java/dao/UserDAO.java create mode 100644 src/main/java/db/DBConnection.java create mode 100644 src/main/java/model/Entry.java create mode 100644 src/main/java/model/User.java diff --git a/src/main/java/HourTracker.java b/src/main/java/HourTracker.java index 865b78c..e7529d9 100644 --- a/src/main/java/HourTracker.java +++ b/src/main/java/HourTracker.java @@ -1,3 +1,5 @@ +import db.DBConnection; + /* * This Java source file was auto generated by running 'gradle buildInit --type java-library' * by 'tyrelsouza' at '2/27/17 9:23 PM' with Gradle 2.10 @@ -6,8 +8,7 @@ */ public class HourTracker { public void main(String[] args){ - - - + DBConnection db = new DBConnection(); + db.connect(); } } diff --git a/src/main/java/dao/EntryDAO.java b/src/main/java/dao/EntryDAO.java new file mode 100644 index 0000000..ad48683 --- /dev/null +++ b/src/main/java/dao/EntryDAO.java @@ -0,0 +1,8 @@ +package dao; + +/** + * Created by tyrelsouza on 2/27/17. + */ +public class EntryDAO { + +} diff --git a/src/main/java/dao/UserDAO.java b/src/main/java/dao/UserDAO.java new file mode 100644 index 0000000..aac8a48 --- /dev/null +++ b/src/main/java/dao/UserDAO.java @@ -0,0 +1,35 @@ +package dao; + +import model.User; + +import java.util.List; + +/** + * Created by tyrelsouza on 2/27/17. + CREATE TABLE entry ( + `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, + `username` varchar(100) not null, + `full_name` varchar(200) not null + ); + */ +public class UserDAO { + List findAll(){ + return null; + } + List findById(int id){ + return null; + } + List findByName(String name){ + return null; + } + boolean insertUser(User User){ + return false; + } + boolean updateUser(User User){ + return false; + } + boolean deleteUser(User User){ + return false; + + } +} diff --git a/src/main/java/db/DBConnection.java b/src/main/java/db/DBConnection.java new file mode 100644 index 0000000..0e1d85b --- /dev/null +++ b/src/main/java/db/DBConnection.java @@ -0,0 +1,22 @@ +package db; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; + +/** + * Created by tyrelsouza on 2/27/17. + */ +public class DBConnection { + public static Connection conn = null; + public static void connect(){ + try { + conn = DriverManager.getConnection("jdbc:mysql://localhost/hourtracker?user=hourtracker&password=hours"); + } catch (SQLException e) { + System.out.println("SQLException: " + e.getMessage()); + System.out.println("SQLState: " + e.getSQLState()); + System.out.println("VendorError: " + e.getErrorCode()); + e.printStackTrace(); + } + } +} diff --git a/src/main/java/model/Entry.java b/src/main/java/model/Entry.java new file mode 100644 index 0000000..21744d8 --- /dev/null +++ b/src/main/java/model/Entry.java @@ -0,0 +1,7 @@ +package model; + +/** + * Created by tyrelsouza on 2/27/17. + */ +public class Entry { +} diff --git a/src/main/java/model/User.java b/src/main/java/model/User.java new file mode 100644 index 0000000..63e8131 --- /dev/null +++ b/src/main/java/model/User.java @@ -0,0 +1,40 @@ +package model; + +/** + * Created by tyrelsouza on 2/27/17. + */ +public class User { + int id; + String username; + String fullName; + + public User(int id, String username, String fullName) { + this.id = id; + this.username = username; + this.fullName = fullName; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getFullName() { + return fullName; + } + + public void setFullName(String fullName) { + this.fullName = fullName; + } +} diff --git a/src/test/java/HourTrackerTest.java b/src/test/java/HourTrackerTest.java index be75a98..c3c352d 100644 --- a/src/test/java/HourTrackerTest.java +++ b/src/test/java/HourTrackerTest.java @@ -1,4 +1,7 @@ +import db.DBConnection; +import junit.framework.Assert; +import model.User; import org.junit.Test; @@ -10,9 +13,20 @@ import static junit.framework.Assert.assertTrue; * @author tyrelsouza, @date 2/27/17 9:23 PM */ public class HourTrackerTest { -// @Test -// public void testSomeLibraryMethod() { -// HourTracker classUnderTest = new HourTracker(); -// assertTrue("someLibraryMethod should return 'true'", classUnderTest.someLibraryMethod()); -// } + @Test + public void testUserCreate() { + User user = new User(1, "tyrel", "Tyrel Souza"); + // assertTrue("someLibraryMethod should return 'true'", classUnderTest.someLibraryMethod()); + + // Basic Tests for Basic Getters and setters + Assert.assertEquals(1, user.getId()); + Assert.assertEquals("tyrel", user.getUsername()); + Assert.assertEquals("Tyrel Souza", user.getFullName()); + } + + @Test + public void testDBConnection(){ + DBConnection db = new DBConnection(); + db.connect(); + } }