Skip to content

Commit

Permalink
Merge pull request #56 from AMOSTeam1/testing-framework
Browse files Browse the repository at this point in the history
testing-framework
  • Loading branch information
AMOSTeam1 authored Jun 13, 2018
2 parents 25f16f8 + f37008a commit 1de9770
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ public void removeProject(Long id) {
* @param id
*/
public void updateProject(Project editedProject) {
//TODO move logic to Project.java
//TODO extract to ProjectQueryService.java
try {
tx.begin();

Expand Down
67 changes: 67 additions & 0 deletions nfabackend/src/test/java/entities/ProjectTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package entities;

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

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;

import org.h2.tools.RunScript;
import org.hibernate.Session;
import org.hibernate.jdbc.Work;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import com.msg.nfabackend.entities.Project;
import com.msg.nfabackend.services.QueryService;

class ProjectTest extends JPAHibernateTest {

@Test
public void testGetObjectById_success() {
//Database has (initially) at least 4 Objects

Project project = em.find(Project.class,(long) 1);
assertNotNull(project);

Project project1 = em.find(Project.class,(long) 4);
assertNotNull(project1);
}

@Test
public void testGetObjectById_failure() {

Project project = em.find(Project.class,(long) Long.MAX_VALUE);
assertNull(project);

Project project1 = em.find(Project.class,(long) -1);
assertNull(project1);

}


/*
* //TODO figure out how to access QueryService
@Test
public void testFindProject_success() {
QueryService qs = new QueryService();
List<Project> foundProjects = qs.findProject("On Process", "ArbeitAgentur");
assertNotNull(foundProjects);
}
*/

}

0 comments on commit 1de9770

Please sign in to comment.