-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added parser for additional attributes. #34
- Loading branch information
1 parent
610d941
commit 4cdd5e2
Showing
10 changed files
with
158 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/java/org/wise/vle/domain/webservice/crater/CRaterIdea.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.wise.vle.domain.webservice.crater; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.w3c.dom.Node; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class CRaterIdea { | ||
|
||
String name; | ||
boolean detected; | ||
List<Integer> characterOffsets; | ||
|
||
public CRaterIdea(Node ideaNode) { | ||
this.name = getNodeValue(ideaNode, "name"); | ||
this.detected = getNodeValue(ideaNode, "detected").equals("1"); | ||
this.characterOffsets = new ArrayList<Integer>(); | ||
} | ||
|
||
private String getNodeValue(Node node, String name) { | ||
return node.getAttributes().getNamedItem(name).getNodeValue(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 19 additions & 7 deletions
26
src/main/java/org/wise/vle/domain/webservice/crater/CRaterSubScore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,33 @@ | ||
package org.wise.vle.domain.webservice.crater; | ||
|
||
import org.w3c.dom.NamedNodeMap; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
|
||
import org.w3c.dom.Node; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
public class CRaterSubScore { | ||
String id; | ||
int score; | ||
float realNumberScore; | ||
int score; | ||
Integer scoreRangeMax; | ||
Integer scoreRangeMin; | ||
|
||
public CRaterSubScore(Node scoreNode) { | ||
NamedNodeMap attributes = scoreNode.getAttributes(); | ||
this.id = attributes.getNamedItem("id").getNodeValue(); | ||
this.score = Integer.parseInt(attributes.getNamedItem("score").getNodeValue()); | ||
this.realNumberScore = | ||
Float.parseFloat(attributes.getNamedItem("realNumberScore").getNodeValue()); | ||
this.id = getNodeValue(scoreNode, "id"); | ||
this.score = Integer.parseInt(getNodeValue(scoreNode, "score")); | ||
this.realNumberScore = Float.parseFloat(getNodeValue(scoreNode, "realNumberScore")); | ||
if (scoreNode.getAttributes().getNamedItem("score_range_min") != null) { | ||
this.scoreRangeMin = Integer.parseInt(getNodeValue(scoreNode, "score_range_min")); | ||
} | ||
if (scoreNode.getAttributes().getNamedItem("score_range_max") != null) { | ||
this.scoreRangeMax = Integer.parseInt(getNodeValue(scoreNode, "score_range_max")); | ||
} | ||
} | ||
|
||
private String getNodeValue(Node node, String name) { | ||
return node.getAttributes().getNamedItem(name).getNodeValue(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/test/java/org/wise/vle/domain/webservice/crater/CRaterIdeaTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.wise.vle.domain.webservice.crater; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import org.junit.Test; | ||
|
||
public class CRaterIdeaTest extends CRaterResponseSubItemTest { | ||
|
||
@Test | ||
public void constructor_ShouldDetectIdea() throws Exception { | ||
CRaterIdea idea = new CRaterIdea(getNode( | ||
"<idea name=\"idea1\" detected=\"1\" character_offsets=\"[]\" />")); | ||
assertEquals("idea1", idea.getName()); | ||
assertTrue(idea.isDetected()); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/test/java/org/wise/vle/domain/webservice/crater/CRaterResponseSubItemTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.wise.vle.domain.webservice.crater; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import javax.xml.parsers.DocumentBuilderFactory; | ||
import org.w3c.dom.Node; | ||
|
||
public class CRaterResponseSubItemTest { | ||
|
||
protected Node getNode(String xmlString) throws Exception { | ||
return DocumentBuilderFactory.newInstance().newDocumentBuilder().parse( | ||
new ByteArrayInputStream(xmlString.getBytes())).getDocumentElement(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/test/java/org/wise/vle/domain/webservice/crater/CRaterSubScoreTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.wise.vle.domain.webservice.crater; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNull; | ||
import org.junit.Test; | ||
|
||
public class CRaterSubScoreTest extends CRaterResponseSubItemTest { | ||
|
||
String subScoreXmlWithoutMinMax = "<score id=\"science\" score=\"1\" realNumberScore=\"0.2919\" />"; | ||
String subScoreXmlWithMinMax = | ||
"<score id=\"science\" score=\"1\" realNumberScore=\"0.2919\" score_range_min=\"1\" score_range_max=\"5\" />"; | ||
|
||
@Test | ||
public void constructor_NoRangeMinMax_FieldsShouldBeNull() throws Exception { | ||
CRaterSubScore score = new CRaterSubScore(getNode(subScoreXmlWithoutMinMax)); | ||
assertEquals(1, score.getScore()); | ||
assertEquals(0.2919, score.getRealNumberScore(), 0.00001); | ||
assertNull(score.getScoreRangeMin()); | ||
assertNull(score.getScoreRangeMax()); | ||
} | ||
|
||
@Test | ||
public void constructor_WithRangeMinMax_FieldsShouldBeSet() throws Exception { | ||
CRaterSubScore score = new CRaterSubScore(getNode(subScoreXmlWithMinMax)); | ||
assertEquals(1, score.getScore()); | ||
assertEquals(0.2919, score.getRealNumberScore(), 0.00001); | ||
assertEquals(1, score.getScoreRangeMin().intValue()); | ||
assertEquals(5, score.getScoreRangeMax().intValue()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters