Skip to content
Snippets Groups Projects
Commit 590aec61 authored by Thomas Schnaak's avatar Thomas Schnaak
Browse files

#76 feat: added Test for DescriptionService and Bugfixes

parent 99af7a42
No related branches found
No related tags found
No related merge requests found
......@@ -19,30 +19,27 @@ public class ProjectDescription {
private String descriptionMD;
private boolean open;
private ArrayList<Link> links;
private ArrayList<String> group;
private long timestamp;
public ProjectDescription() {
}
public ProjectDescription(String id, String name, String description, String project, ArrayList<Link> links, ArrayList<String> group) {
public ProjectDescription(String id, String name, String description, String project, ArrayList<Link> links) {
this.id = id;
this.student = new StudentIdentifier(project, name);
this.descriptionHTML = convertMarkdownToHtml(description);
this.descriptionMD = description;
this.links = links;
this.group = group;
this.timestamp = new Date().getTime();
this.open = true;
}
public ProjectDescription(String id, String name, String description, String project, ArrayList<Link> links, ArrayList<String> group, long timestamp, boolean open) {
public ProjectDescription(String id, String name, String description, String project, ArrayList<Link> links, long timestamp, boolean open) {
this.id = id;
this.student = new StudentIdentifier(project, name);
this.descriptionHTML = convertMarkdownToHtml(description);
this.descriptionMD = description;
this.links = links;
this.group = group;
this.timestamp = timestamp;
this.open = open;
}
......@@ -100,14 +97,6 @@ public class ProjectDescription {
this.links = links;
}
public ArrayList<String> getGroup() {
return group;
}
public void setGroup(ArrayList<String> group) {
this.group = group;
}
public long getTimestamp() {
return timestamp;
}
......@@ -125,7 +114,6 @@ public class ProjectDescription {
", descriptionMD='" + descriptionMD + '\'' +
", open=" + open +
", links=" + links +
", group=" + group +
", timestamp=" + timestamp +
'}';
}
......
......@@ -168,7 +168,7 @@ public class ProjectDescriptionDAOImpl implements ProjectDescriptionDAO {
String text = rs.getString("text");
boolean open = rs.getBoolean("open");
return new ProjectDescription(id,author,text,project,new ArrayList<>(),new ArrayList<>(),timestamp, open);
return new ProjectDescription(id,author,text,project,new ArrayList<>(), timestamp, open);
}
}
......@@ -15,16 +15,15 @@ import java.util.ArrayList;
public class ProjectDescriptionImpl implements ProjectDescriptionService {
ProjectDescriptionDAO descriptionDAO = new ProjectDescriptionDAOImpl();
LinkDAO linkDAO = new LinkDAOImpl();
private ProjectDescriptionDAO descriptionDAO = new ProjectDescriptionDAOImpl();
private LinkDAO linkDAO = new LinkDAOImpl();
@Override
public ProjectDescription getProjectbyStudent(StudentIdentifier studentIdentifier) {
//if no description exists, create a new
//if no description exists (when page is opend for the first time), create a new one
if(descriptionDAO.getDescription(studentIdentifier)==null){
//TODO richtige Daten, standartwerte über config?
ProjectDescription description = new ProjectDescription("0", studentIdentifier.getStudentId(), "Hier soll ein Turtorialtext stehen", studentIdentifier.getProjectId(), null, null);
ProjectDescription description = new ProjectDescription("0", studentIdentifier.getStudentId(), "Hier soll ein Turtorialtext stehen", studentIdentifier.getProjectId(), null);
descriptionDAO.createDescription(description);
}
......@@ -67,7 +66,7 @@ public class ProjectDescriptionImpl implements ProjectDescriptionService {
@Override
public boolean checkIfAllDescriptionsClosed(Project project) {
return (descriptionDAO.getOpenDescriptions(project).size() == 0); //TODO Jeder eine desc?
return (descriptionDAO.getOpenDescriptions(project).size() == 0);
}
@Override
......
......@@ -18,13 +18,13 @@ public class ProjectDescriptionImplDAOTest {
private final ProjectDescriptionDAO descriptionDAO = new ProjectDescriptionDAOImpl();
private final MysqlConnect connection = new MysqlConnect();
String testId = "-1";
String testStudent = "testStudent";
String testDescription = "testDescription";
String testProjekt = "testProjekt";
ArrayList<String> testGroup = new ArrayList<>();
private String testId = "-1";
private String testStudent = "testStudent";
private String testDescription = "testDescription";
private String testProjekt = "testProjekt";
private ArrayList<String> testGroup = new ArrayList<>();
ProjectDescription testProjectDescription = new ProjectDescription(testId, testStudent, testDescription, testProjekt, null /*Links are added in Service*/, testGroup);
private ProjectDescription testProjectDescription = new ProjectDescription(testId, testStudent, testDescription, testProjekt, null /*Links are added in Service*/);
@Test
public void createDescription() {
......@@ -32,7 +32,6 @@ public class ProjectDescriptionImplDAOTest {
connection.connect();
ProjectDescription createDescription = testProjectDescription;
createDescription.getGroup().add("test");
descriptionDAO.createDescription(testProjectDescription);
......@@ -223,7 +222,7 @@ public class ProjectDescriptionImplDAOTest {
String text = rs.getString("text");
boolean open = rs.getBoolean("open");
return new ProjectDescription(id, author, text, project, new ArrayList<>(), new ArrayList<>(), timestamp, open);
return new ProjectDescription(id, author, text, project, new ArrayList<>(), timestamp, open);
}
}
package unipotsdam.gf.modules.journal.service;
import org.junit.After;
import org.junit.Test;
import unipotsdam.gf.core.management.Management;
import unipotsdam.gf.core.management.ManagementImpl;
import unipotsdam.gf.core.management.project.Project;
import unipotsdam.gf.core.management.user.User;
import unipotsdam.gf.modules.assessment.controller.model.StudentIdentifier;
import unipotsdam.gf.modules.journal.model.Link;
import unipotsdam.gf.modules.journal.model.ProjectDescription;
import unipotsdam.gf.modules.journal.model.dao.LinkDAO;
import unipotsdam.gf.modules.journal.model.dao.LinkDAOImpl;
import unipotsdam.gf.modules.journal.model.dao.ProjectDescriptionDAO;
import unipotsdam.gf.modules.journal.model.dao.ProjectDescriptionDAOImpl;
import java.util.ArrayList;
import static org.junit.Assert.*;
public class ProjectDescriptionImplTest {
private ProjectDescriptionService projectDescriptionService = new ProjectDescriptionImpl();
private ProjectDescriptionDAO descriptionDAO = new ProjectDescriptionDAOImpl();
private LinkDAO linkDAO = new LinkDAOImpl();
private Management management = new ManagementImpl();
private String testId = "-1";
private String testStudent = "testStudent";
private String testDescription = "testDescription";
private String testProject = "testProject";
private String testProjectDescription = "testproject";
private String testName = "testname";
private String testLink = "https://www.test.de";
private Link testLinkObj = new Link(testId, testProjectDescription, testName, testLink);
private ArrayList<Link> linkArrayList = new ArrayList<>();
private ProjectDescription testProjectDescriptionObj = new ProjectDescription(testId, testStudent, testDescription, testProject, linkArrayList);
@After
public void cleanUp() {
StudentIdentifier deleteIdentifier = new StudentIdentifier(testProject, testStudent);
ProjectDescription deleteDescription = descriptionDAO.getDescription(deleteIdentifier);
descriptionDAO.deleteDescription(deleteIdentifier);
if (deleteDescription != null) {
ArrayList<Link> deleteLinks = linkDAO.getAllLinks(deleteDescription.getId());
for (Link l : deleteLinks) {
linkDAO.deleteLink(l.getId());
}
}
}
@Test
public void getProjectbyStudent() {
//NO description exists
projectDescriptionService.getProjectbyStudent(new StudentIdentifier(testProject, testStudent));
ProjectDescription resProjectDescription = descriptionDAO.getDescription(new StudentIdentifier(testProject, testStudent));
String id = resProjectDescription.getId();
assertNotNull(resProjectDescription);
assertEquals("Hier soll ein Turtorialtext stehen", resProjectDescription.getDescriptionMD());
assertEquals(testStudent, resProjectDescription.getStudent().getStudentId());
assertEquals(testProject, resProjectDescription.getStudent().getProjectId());
//description exists
resProjectDescription = descriptionDAO.getDescription(new StudentIdentifier(testProject, testStudent));
assertNotNull(resProjectDescription);
assertEquals(id, resProjectDescription.getId());
assertEquals("Hier soll ein Turtorialtext stehen", resProjectDescription.getDescriptionMD());
assertEquals(testStudent, resProjectDescription.getStudent().getStudentId());
assertEquals(testProject, resProjectDescription.getStudent().getProjectId());
}
@Test
public void getProjectbyId() {
descriptionDAO.createDescription(testProjectDescriptionObj);
String id = descriptionDAO.getDescription(new StudentIdentifier(testProject, testStudent)).getId();
testLinkObj.setProjectDescription(id);
linkDAO.addLink(testLinkObj);
ProjectDescription resProjectDescription = projectDescriptionService.getProjectbyId(id);
assertNotNull(resProjectDescription);
assertEquals(testDescription, resProjectDescription.getDescriptionMD());
assertEquals(testStudent, resProjectDescription.getStudent().getStudentId());
assertEquals(testProject, resProjectDescription.getStudent().getProjectId());
ArrayList<Link> links = resProjectDescription.getLinks();
assertEquals(1, links.size());
assertEquals(testLink, links.get(0).getLink());
assertEquals(testName, links.get(0).getName());
}
@Test
public void saveProjectText() {
descriptionDAO.createDescription(testProjectDescriptionObj);
projectDescriptionService.saveProjectText(new StudentIdentifier(testProject, testStudent), testName);
ProjectDescription resProjectDescription = descriptionDAO.getDescription(new StudentIdentifier(testProject, testStudent));
assertEquals(testName, resProjectDescription.getDescriptionMD());
}
@Test
public void addLink() {
descriptionDAO.createDescription(testProjectDescriptionObj);
ProjectDescription resProjectDescription = descriptionDAO.getDescription(new StudentIdentifier(testProject, testStudent));
projectDescriptionService.addLink(resProjectDescription.getId(), testLink, testName);
ArrayList<Link> resLinks = linkDAO.getAllLinks(resProjectDescription.getId());
assertEquals(1, resLinks.size());
assertEquals(resProjectDescription.getId(), resLinks.get(0).getProjectDescription());
assertEquals(testName, resLinks.get(0).getName());
assertEquals(testLink, resLinks.get(0).getLink());
}
@Test
public void deleteLink() {
descriptionDAO.createDescription(testProjectDescriptionObj);
ProjectDescription resProjectDescription = descriptionDAO.getDescription(new StudentIdentifier(testProject, testStudent));
testLinkObj.setProjectDescription(resProjectDescription.getId());
linkDAO.addLink(testLinkObj);
ArrayList<Link> resLinks = linkDAO.getAllLinks(resProjectDescription.getId());
assertEquals(1, resLinks.size());
projectDescriptionService.deleteLink(resLinks.get(0).getId());
resLinks = linkDAO.getAllLinks(resProjectDescription.getId());
assertEquals(0, resLinks.size());
}
@Test
public void closeDescription() {
descriptionDAO.createDescription(testProjectDescriptionObj);
ProjectDescription resDescription = descriptionDAO.getDescription(new StudentIdentifier(testProject, testStudent));
assertTrue(resDescription.isOpen());
projectDescriptionService.closeDescription(resDescription.getId());
resDescription = descriptionDAO.getDescription(new StudentIdentifier(testProject, testStudent));
assertFalse(resDescription.isOpen());
}
@Test
public void checkIfAllDescriptionsClosed() {
descriptionDAO.createDescription(testProjectDescriptionObj);
Project project = new Project();
project.setId(testProject);
assertFalse(projectDescriptionService.checkIfAllDescriptionsClosed(project));
ProjectDescription resDescription = descriptionDAO.getDescription(new StudentIdentifier(testProject, testStudent));
descriptionDAO.closeDescription(resDescription.getId());
assertTrue(projectDescriptionService.checkIfAllDescriptionsClosed(project));
}
@Test
public void getOpenUserByProject() {
User user = new User("Test", "Test", "test@test.de", true);
String token = management.getUserToken(user);
Project project = new Project();
project.setId(testProject);
testProjectDescriptionObj.getStudent().setStudentId(token);
descriptionDAO.createDescription(testProjectDescriptionObj);
ArrayList<User> resultUser = projectDescriptionService.getOpenUserByProject(project);
assertEquals(1, resultUser.size());
assertEquals(user.getEmail(), resultUser.get(0).getId());
StudentIdentifier delUser = new StudentIdentifier(testProject, token);
descriptionDAO.deleteDescription(delUser);
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment