Skip to content

Commit

Permalink
final
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Petkanic committed Jun 14, 2016
1 parent 0282503 commit 1044581
Show file tree
Hide file tree
Showing 13 changed files with 208 additions and 53 deletions.
41 changes: 41 additions & 0 deletions response.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<responses xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="response.xsd">
<response>
<surveyId>1</surveyId>
<questions>
<question>
<questionId>2</questionId>
<answers>
<answerId>5</answerId>
<answerId>8</answerId>
</answers>
</question>
<question>
<questionId>4</questionId>
<answers>
<answerId>5</answerId>
<answerId>8</answerId>
</answers>
</question>
</questions>
</response>
<response>
<surveyId>9</surveyId>
<questions>
<question>
<questionId>2</questionId>
<answers>
<answerId>5</answerId>
<answerId>8</answerId>
</answers>
</question>
<question>
<questionId>4</questionId>
<answers>
<answerId>5</answerId>
<answerId>8</answerId>
</answers>
</question>
</questions>
</response>
</responses>
7 changes: 7 additions & 0 deletions src/survey/backend/SchemaValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,20 @@
import org.xml.sax.SAXParseException;

/**
* Class SchemaValidator represents set of functions for xml files validation
* @author Peter Petkanic
*/
public class SchemaValidator {

private DocumentBuilder docBuilder;
private String error;

/**
* Initializes schema validator
* @param schemaName path to xml schema
* @throws SAXException
* @throws ParserConfigurationException
*/
public SchemaValidator(String schemaName) throws SAXException, ParserConfigurationException{
try {
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Expand Down
13 changes: 13 additions & 0 deletions src/survey/backend/entities/Question.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import java.util.HashMap;
import java.util.Set;

/**
* Class Question represents question of survey
* @author Peter Petkanic
*/
public class Question {

private int qid;
Expand All @@ -20,10 +24,19 @@ public int getAnswerSize(){
return answers.size();
}

/**
* Adds or updates answer
* @param aid ID of answer
* @param text answer string
*/
public void addAnswer(int aid, String text) {
answers.put(aid, text);
}

/**
* Returns Set of answer IDs of question
* @return set of answer IDs
*/
public Set<Integer> getAnswerIDs() {
return answers.keySet();
}
Expand Down
4 changes: 4 additions & 0 deletions src/survey/backend/entities/QuestionType.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package survey.backend.entities;

/**
* Class QuestionType represents types of question
* @author Peter Petkanic
*/
public enum QuestionType {
CLOSED, MULTIPLE;
}
12 changes: 12 additions & 0 deletions src/survey/backend/entities/Survey.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import java.util.List;

/**
* Class Survey represents survey of survey.xml file
* @author Peter Petkanic
*/
public class Survey {
private final int sid;
private String title;
Expand Down Expand Up @@ -43,10 +47,18 @@ public void setQuestions(List<Question> questions) {
this.questions = questions;
}

/**
* adds a Question to survey
* @param question
*/
public void addQuestion(Question question){
this.questions.add(question);
}

/**
* edits a Question in survey
* @param question
*/
public void editQuestion(Question question){
for(int i = 0; i < questions.size(); i++){
if(questions.get(i).getQid() == question.getQid()){
Expand Down
5 changes: 4 additions & 1 deletion src/survey/frontend/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
import survey.backend.SurveyEngineException;
import survey.frontend.panels.jPanelMain;


/**
* Main class
* @author Peter Petkanič
*/
public class Main {
public static void main(String[] args) {

Expand Down
2 changes: 1 addition & 1 deletion src/survey/frontend/models/AnswersTableModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

/**
*
* @author Peter Petkanič
* @author Jakub Gavlas
*/
public class AnswersTableModel extends AbstractTableModel{

Expand Down
2 changes: 1 addition & 1 deletion src/survey/frontend/models/QuestionTableModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import survey.backend.entities.Question;

/**
*
*
* @author Jakub Gavlas
*/
public class QuestionTableModel extends AbstractTableModel{
Expand Down
4 changes: 2 additions & 2 deletions src/survey/frontend/panels/jPanelMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
import javax.swing.SwingUtilities;
import javax.swing.table.TableColumn;
import survey.backend.SurveyEngine;
import survey.backend.SurveyEngineException;
import survey.backend.entities.Survey;
import survey.frontend.models.SurveyTableModel;

/**
* @author Peter Petkanič/433422
*
* @author Peter Petkanič
*/
public class jPanelMain extends javax.swing.JPanel {

Expand Down
30 changes: 0 additions & 30 deletions src/xml/valid/response/response_valid_responses.xml
Original file line number Diff line number Diff line change
@@ -1,42 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>

<!--root element-->
<responses xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="response.xsd">
<!--
- element response represents response from respondent
- it must contain survey ID and questions at all times
-->
<response>
<!--
- this element has the value of survey ID from survey.xml
- only non-negative integer is permitted
-->
<surveyId>1</surveyId>
<!--
- questions is a set of questions with AT LEAST ONE selected answer
- if there was no selected answer for question it is not present
-->
<questions>
<!--
- question element represents question with at least one selected answer
- must contain question ID and set of answers
- question ID is unique inside response
-->
<question>
<!--
- this element has the value of question ID from survey.xml
- only non-negative integer is permitted
-->
<questionId>1</questionId>
<!--
- answers represents set of selected answers in question
- must contain at least one ID
-->
<answers>
<!--
- this element has the value of answer ID from survey.xml
- only non-negative integer is permitted
-->
<answerId>1</answerId>
</answers>
</question>
Expand Down
81 changes: 64 additions & 17 deletions test/survey/SurveyEngineTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,76 @@
* and open the template in the editor.
*/
package survey;




import java.util.ArrayList;
import org.junit.Test;
import survey.backend.SurveyEngine;
import survey.backend.SurveyEngineException;
import survey.backend.entities.Survey;

import static junit.framework.TestCase.assertEquals;
import survey.backend.entities.Question;
import survey.backend.entities.QuestionType;

/**
* Contains few tests for SurveyEngine.
*
* @author peteru
* @author Martin
*/
public class SurveyEngineTest {
public static void main(String[] args) {
SurveyEngine se = null;
try {
se = new SurveyEngine("survey.xml");
} catch (SurveyEngineException e) {
System.err.println(e.getMessage());
System.exit(-1);
}


/**
* Tests loading surveys.
*
* @throws SurveyEngineException
*/
@Test
public void getSurveyTest() throws SurveyEngineException {
SurveyEngine se = new SurveyEngine("test/survey/surveytest.xml");

Survey s = se.getSurvey(1);
System.out.println("kekis");
//se.saveSurvey(0, title, description, questions);

assertEquals(s.getSid(), 1);
}
}


/**
* Tests saving of an incorrect survey. Survey has a question with no
* answers.
*
* @throws SurveyEngineException
*/
@Test(expected=SurveyEngineException.class)
public void saveIncorrectTest() throws SurveyEngineException {
SurveyEngine se = new SurveyEngine("test/survey/surveytest.xml");

Question q = new Question(1, "mas rad jablka?", QuestionType.CLOSED);
ArrayList<Question> qs = new ArrayList<>();
qs.add(q);
Survey s = new Survey(5, "test survey", "some description", qs);
se.saveSurvey(s);
}

/**
* Tests repetitive loading, changing and saving of a survey.
*
* @throws SurveyEngineException
*/
@Test
public void saveTest() throws SurveyEngineException {
SurveyEngine se = new SurveyEngine("test/survey/surveytest.xml");

Survey s = se.getSurvey(1);
s.setTitle("Halo?");
se.saveSurvey(s);

s = se.getSurvey(1);
assertEquals("Halo?", s.getTitle());


s.setTitle("Ahoj");
se.saveSurvey(s);

s = se.getSurvey(1);
assertEquals("Ahoj", s.getTitle());
}
}
2 changes: 1 addition & 1 deletion test/survey/XMLmanagementTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void testImporting() throws ParserConfigurationException, SAXException, I
System.out.println("importing");

XMLmanagement xman = new XMLmanagement();
xman.importing("response.xml");
xman.importing("src/xml/response.xml");

System.out.println(xman.restringing());
}
Expand Down
58 changes: 58 additions & 0 deletions test/survey/surveytest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<surveys xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="/src/xml/survey.xsd">
<survey sid="2">
<title>Predmetová anketa predmetu PB138</title>
<description>Tento dotazník má dopomôcť k skvaliteniu prednášok a cvičení predmetu PB138.</description>
<questions>
<question qid="1" type="closed">
<description>Ako hodnotíte prednášky na predmete?</description>
<answers>
<answer aid="1">Veľmi kvalitné</answer>
<answer aid="2">Kvalitné</answer>
<answer aid="3">Vylepšil by som ich</answer>
<answer aid="4">Nekvalitné</answer>
<answer aid="5">Úplne nekvalitné</answer>
</answers>
</question>
<question qid="2" type="closed">
<description>Ako dlho ste týždenne strávili študovaním predmetu?</description>
<answers>
<answer aid="1">13 a viac hodín</answer>
<answer aid="2">10-12</answer>
<answer aid="3">6-9</answer>
<answer aid="4">2-5</answer>
<answer aid="5">menej ako hodinu alebo vôbec</answer>
</answers>
</question>
</questions>
</survey>



<survey sid="1">
<title>Ahoj</title>
<description>Tento dotazník je určený pre študentov FI a má dopomôcť k skvalitneniu štúdia.</description>
<questions>
<question qid="1" type="closed">
<description>Ako ste spokojný so štúdiom na FI?</description>
<answers>
<answer aid="1">Veľmi spokojný</answer>
<answer aid="2">Spokojný</answer>
<answer aid="3">Neutrálny</answer>
<answer aid="4">Nespokojný</answer>
<answer aid="5">Vôbec nespokojný</answer>
</answers>
</question>
<question qid="2" type="multiple">
<description>Ktoré programovacie jazyky ovladáte?</description>
<answers>
<answer aid="1">C/C++</answer>
<answer aid="2">Java</answer>
<answer aid="3">C#</answer>
<answer aid="4">Ruby</answer>
<answer aid="5">R</answer>
</answers>
</question>
</questions>
</survey>
</surveys>

0 comments on commit 1044581

Please sign in to comment.