> clauseList) {
*
* @param file
*/
- public void store(MultipartFile file) {
+ public void store(MultipartFile file) throws StorageException {
this.filename = StringUtils.cleanPath(file.getOriginalFilename());
try {
if (file.isEmpty()) {
diff --git a/src/main/java/com/essi/dependency/service/FileFormatException.java b/src/main/java/com/essi/dependency/service/FileFormatException.java
index b8386a7..9cac0ad 100644
--- a/src/main/java/com/essi/dependency/service/FileFormatException.java
+++ b/src/main/java/com/essi/dependency/service/FileFormatException.java
@@ -6,20 +6,4 @@ public FileFormatException() {
super();
}
- public FileFormatException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
- super(message, cause, enableSuppression, writableStackTrace);
- }
-
- public FileFormatException(String message, Throwable cause) {
- super(message, cause);
- }
-
- public FileFormatException(String message) {
- super(message);
- }
-
- public FileFormatException(Throwable cause) {
- super(cause);
- }
-
}
diff --git a/src/test/java/com/essi/Dependency/AppTest.java b/src/test/java/com/essi/Dependency/AppTest.java
index 5355c5a..aba620e 100644
--- a/src/test/java/com/essi/Dependency/AppTest.java
+++ b/src/test/java/com/essi/Dependency/AppTest.java
@@ -21,7 +21,7 @@
import java.io.BufferedReader;
import java.io.FileReader;
-import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@@ -48,7 +48,7 @@ public void crossReferenceJSONProject() throws Exception {
.content(read_file(path+"sample-1.json")))
.andDo(print()).andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
JSONObject result = new JSONObject(response);
- Assert.assertEquals(1, result.getJSONArray("dependencies").length());
+ Assert.assertEquals(2, result.getJSONArray("dependencies").length());
}
@Test
@@ -60,7 +60,7 @@ public void crossReferenceJSONProjectNM() throws Exception {
.content(read_file(path+"sample-1.json")))
.andDo(print()).andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
JSONObject result = new JSONObject(response);
- Assert.assertEquals(1, result.getJSONArray("dependencies").length());
+ Assert.assertEquals(2, result.getJSONArray("dependencies").length());
}
@Test
@@ -75,7 +75,92 @@ public void crossReferenceHTMLProject() throws Exception {
String response = this.mockMvc.perform(builder).andExpect(status().isOk())
.andDo(MockMvcResultHandlers.print()).andReturn().getResponse().getContentAsString();;
JSONObject result = new JSONObject(response);
- Assert.assertEquals(1, result.getJSONArray("dependencies").length());
+ Assert.assertEquals(21, result.getJSONArray("dependencies").length());
+ }
+
+ @Test
+ public void crossReferenceHTMLProjectComplex() throws Exception {
+ MockMultipartFile mockMultipartFile = new MockMultipartFile("file","complex.html",
+ "text/html", read_html_file(path+"complex.html").getBytes());
+
+ MockHttpServletRequestBuilder builder =
+ MockMvcRequestBuilders.fileUpload("/upc/cross-reference-detection/file")
+ .file(mockMultipartFile);
+
+ String response = this.mockMvc.perform(builder).andExpect(status().isOk())
+ .andDo(MockMvcResultHandlers.print()).andReturn().getResponse().getContentAsString();;
+ JSONObject result = new JSONObject(response);
+ Assert.assertEquals(4, result.getJSONArray("dependencies").length());
+ }
+
+ @Test
+ public void crossReferenceHTMLProjectExternal() throws Exception {
+ MockMultipartFile mockMultipartFile = new MockMultipartFile("file","external.html",
+ "text/html", read_html_file(path+"external.html").getBytes());
+
+ MockHttpServletRequestBuilder builder =
+ MockMvcRequestBuilders.fileUpload("/upc/cross-reference-detection/file")
+ .file(mockMultipartFile);
+
+ String response = this.mockMvc.perform(builder).andExpect(status().isOk())
+ .andDo(MockMvcResultHandlers.print()).andReturn().getResponse().getContentAsString();;
+ JSONObject result = new JSONObject(response);
+ Assert.assertEquals(4, result.getJSONArray("dependencies").length());
+ }
+
+
+ @Test
+ public void crossReferenceHTMLProjectWithGrammar() throws Exception {
+ this.mockMvc.perform(
+ post("/upc/cross-reference-detection/reqPrefix?company=upc_new")
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(read_file(path+"prefixes.json")))
+ .andDo(print()).andExpect(status().isOk());
+ MockMultipartFile mockMultipartFile = new MockMultipartFile("file","sample-2.html",
+ "text/html", read_html_file(path+"sample-2.html").getBytes());
+
+ MockHttpServletRequestBuilder builder =
+ MockMvcRequestBuilders.fileUpload("/upc/cross-reference-detection/file?company=upc_new")
+ .file(mockMultipartFile);
+
+ String response = this.mockMvc.perform(builder).andExpect(status().isOk())
+ .andDo(MockMvcResultHandlers.print()).andReturn().getResponse().getContentAsString();;
+ JSONObject result = new JSONObject(response);
+ Assert.assertEquals(21, result.getJSONArray("dependencies").length());
+ this.mockMvc.perform(
+ delete("/upc/cross-reference-detection/reqPrefix?company=upc_new"))
+ .andDo(print()).andExpect(status().isOk());
+ }
+
+
+ @Test
+ public void crossReferenceHTMLProjectException() throws Exception {
+ MockMultipartFile mockMultipartFile = new MockMultipartFile("file","aux_exception.txt",
+ "text/html", read_html_file(path+"aux_exception.txt").getBytes());
+
+ MockHttpServletRequestBuilder builder =
+ MockMvcRequestBuilders.fileUpload("/upc/cross-reference-detection/file")
+ .file(mockMultipartFile);
+
+ this.mockMvc.perform(builder).andExpect(status().isInternalServerError());
+
+ mockMultipartFile = new MockMultipartFile("file","empty_file.html",
+ "text/html", read_html_file(path+"empty_file.html").getBytes());
+
+ builder =
+ MockMvcRequestBuilders.fileUpload("/upc/cross-reference-detection/file")
+ .file(mockMultipartFile);
+
+ this.mockMvc.perform(builder).andExpect(status().isInternalServerError());
+
+ mockMultipartFile = new MockMultipartFile("file","../aux_exception.html",
+ "text/html", read_html_file(path+"../aux_exception.html").getBytes());
+
+ builder =
+ MockMvcRequestBuilders.fileUpload("/upc/cross-reference-detection/file")
+ .file(mockMultipartFile);
+
+ this.mockMvc.perform(builder).andExpect(status().isInternalServerError());
}
@Test
@@ -88,9 +173,100 @@ public void crossReferenceHTMLProjectNM() throws Exception {
.file(mockMultipartFile);
String response = this.mockMvc.perform(builder).andExpect(status().isOk())
- .andDo(MockMvcResultHandlers.print()).andReturn().getResponse().getContentAsString();;
+ .andDo(MockMvcResultHandlers.print()).andReturn().getResponse().getContentAsString();
+ JSONObject result = new JSONObject(response);
+ Assert.assertEquals(4, result.getJSONArray("dependencies").length());
+ }
+
+ @Test
+ public void crossReferenceHTMLProjectNMException() throws Exception {
+ MockMultipartFile mockMultipartFile = new MockMultipartFile("file","aux_exception.txt",
+ "text/html", read_html_file(path+"aux_exception.txt").getBytes());
+ MockHttpServletRequestBuilder builder =
+ MockMvcRequestBuilders.fileUpload("/upc/cross-reference-detection/file/1/2")
+ .file(mockMultipartFile);
+ this.mockMvc.perform(builder).andExpect(status().isInternalServerError());
+
+ mockMultipartFile = new MockMultipartFile("file","sample-2.html",
+ "text/html", read_html_file(path+"sample-2.html").getBytes());
+ builder =
+ MockMvcRequestBuilders.fileUpload("/upc/cross-reference-detection/file/2/1")
+ .file(mockMultipartFile);
+ this.mockMvc.perform(builder).andExpect(status().isInternalServerError());
+ }
+
+ @Test
+ public void GrammarDeletePrefixes() throws Exception {
+ this.mockMvc.perform(
+ post("/upc/cross-reference-detection/reqPrefix?company=upc_new")
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(read_file(path+"prefixes.json")))
+ .andDo(print()).andExpect(status().isOk());
+ this.mockMvc.perform(
+ delete("/upc/cross-reference-detection/reqPrefix?company=upc_new"))
+ .andDo(print()).andExpect(status().isOk());
+ this.mockMvc.perform(
+ delete("/upc/cross-reference-detection/reqPrefix?company=upc_new"))
+ .andDo(print()).andExpect(status().isInternalServerError());
+ }
+
+ @Test
+ public void GrammarStorePrefixes() throws Exception {
+ this.mockMvc.perform(
+ post("/upc/cross-reference-detection/reqPrefix?company=upc_new")
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(read_file(path+"prefixes.json")))
+ .andDo(print()).andExpect(status().isOk());
+ this.mockMvc.perform(
+ post("/upc/cross-reference-detection/reqPrefix?company=upc_new")
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(read_file(path+"prefixes.json")))
+ .andDo(print()).andExpect(status().isInternalServerError());
+ this.mockMvc.perform(
+ delete("/upc/cross-reference-detection/reqPrefix?company=upc_new"))
+ .andDo(print()).andExpect(status().isOk());
+ }
+
+ @Test
+ public void GrammarUpdatePrefixes() throws Exception {
+ this.mockMvc.perform(
+ post("/upc/cross-reference-detection/reqPrefix?company=upc_new")
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(read_file(path+"prefixes.json")))
+ .andDo(print()).andExpect(status().isOk());
+ this.mockMvc.perform(
+ put("/upc/cross-reference-detection/reqPrefix?company=upc_new")
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(read_file(path+"prefixes.json")))
+ .andDo(print()).andExpect(status().isOk());
+ this.mockMvc.perform(
+ delete("/upc/cross-reference-detection/reqPrefix?company=upc_new"))
+ .andDo(print()).andExpect(status().isOk());
+ this.mockMvc.perform(
+ put("/upc/cross-reference-detection/reqPrefix?company=upc_exception")
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(read_file(path+"prefixes.json")))
+ .andDo(print()).andExpect(status().isInternalServerError());
+ }
+
+ @Test
+ public void GrammarGetPrefixes() throws Exception {
+ this.mockMvc.perform(
+ post("/upc/cross-reference-detection/reqPrefix?company=upc_new")
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(read_file(path+"prefixes.json")))
+ .andDo(print()).andExpect(status().isOk());
+ String response = this.mockMvc.perform(
+ get("/upc/cross-reference-detection/reqPrefix?company=upc_new"))
+ .andDo(MockMvcResultHandlers.print()).andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
JSONObject result = new JSONObject(response);
- Assert.assertEquals(0, result.getJSONArray("dependencies").length());
+ Assert.assertEquals("{\"prefixes\":[\"upc\",\"bug\",\"issue\"]}", result.toString());
+ this.mockMvc.perform(
+ delete("/upc/cross-reference-detection/reqPrefix?company=upc_new"))
+ .andDo(print()).andExpect(status().isOk());
+ this.mockMvc.perform(
+ get("/upc/cross-reference-detection/reqPrefix?company=upc_exception"))
+ .andDo(MockMvcResultHandlers.print()).andExpect(status().isInternalServerError()).andReturn().getResponse().getContentAsString();
}
private String read_html_file(String path) throws Exception {
diff --git a/testing/aux_exception.html b/testing/aux_exception.html
new file mode 100644
index 0000000..97896a0
--- /dev/null
+++ b/testing/aux_exception.html
@@ -0,0 +1 @@
+nothing
\ No newline at end of file
diff --git a/testing/integration/aux_exception.txt b/testing/integration/aux_exception.txt
new file mode 100644
index 0000000..97896a0
--- /dev/null
+++ b/testing/integration/aux_exception.txt
@@ -0,0 +1 @@
+nothing
\ No newline at end of file
diff --git a/testing/integration/complex.html b/testing/integration/complex.html
new file mode 100644
index 0000000..1cc847f
--- /dev/null
+++ b/testing/integration/complex.html
@@ -0,0 +1,21 @@
+
+
+
+1 FIRST PARAGRAPH
+1.1 FIRST SUBPARAGRAPH
+
+complex_1: article:A - article:B of the book-ix
+complex_2: 1st article 2nd article or #12132
+complex_3: lot-213 and -313 of above section
+complex_4: item#2 to #3 above items
+complex_5: item#2 to above
+complex_5: item#2 to 5
+complex_5: volume 1.1 to 2.1
+complex_5: volume 1.2 to 2
+complex_5: 1.1 to 1.3
+complex_5: item#2 to 5.5.
+complex_5: item#2 to A
+complex_5: item#2 to subitem
+complex_5: item z and 5
+
+
\ No newline at end of file
diff --git a/testing/integration/empty_file.html b/testing/integration/empty_file.html
new file mode 100644
index 0000000..e69de29
diff --git a/testing/integration/external.html b/testing/integration/external.html
new file mode 100644
index 0000000..e625108
--- /dev/null
+++ b/testing/integration/external.html
@@ -0,0 +1,15 @@
+
+
+
+1 SECTION
+1.1 SUBSECTION
+
+external_1: article 2 of the contract
+external_2: item#2 to #3 of a tendering documentation
+
+1.2 SUBSECTION
+
+external_3: 4th article or 1st article and -3 and of the technical specifications
+external_4: contractor proposal, described in item#2 to #3
+
+
\ No newline at end of file
diff --git a/testing/integration/prefixes.json b/testing/integration/prefixes.json
new file mode 100644
index 0000000..46504b6
--- /dev/null
+++ b/testing/integration/prefixes.json
@@ -0,0 +1,5 @@
+{
+ "prefixes": [
+ "upc","bug","issue"
+ ]
+}
\ No newline at end of file
diff --git a/testing/integration/sample-1.json b/testing/integration/sample-1.json
index 36f481a..d221c98 100644
--- a/testing/integration/sample-1.json
+++ b/testing/integration/sample-1.json
@@ -8,7 +8,7 @@
"name" : "QTBUG",
- "specifiedRequirements" : [ "QTBUG-150890", "QTBUG-162454"]
+ "specifiedRequirements" : [ "QTBUG-150890", "QTBUG-162454", "QTBUG-162455", "QTBUG-162456"]
}
@@ -34,8 +34,43 @@
"text": "Following issue qtbug-150890, the dialog do not work for multiple users under Windows O.S."
+ },
+ {
+
+ "id": "QTBUG-162455",
+
+ "name": "complex_1: article:A - article:B of the book-ix",
+
+ "text": "complex_2: 1st article 2nd article or #12132"
+
+ },
+ {
+
+ "id": "QTBUG-162456",
+
+ "name": "complex_3: lot-213 and -313 of above section ",
+
+ "text": "complex_4: item#2 to #3 above items ",
+
+ "comments": [{"text": "complex_5: lot-213 to 313 , subitem#xi or iv, subparagraph:21312 or 3213, section-3 to 1"}]
+
}
+ ],
+ "dependencies" : [
+ {
+
+ "dependency_type": "similar",
+
+ "status": "accepted",
+
+ "fromid": "QTBUG-150890",
+
+ "toid": "QTBUG-150891",
+
+ "description": "duplicates"
+
+ }
]
}
\ No newline at end of file
diff --git a/testing/integration/sample-2.html b/testing/integration/sample-2.html
index 8687ccc..9344454 100644
--- a/testing/integration/sample-2.html
+++ b/testing/integration/sample-2.html
@@ -1,10 +1,38 @@
-1 FIRST SECTION
-1.1 FIRST SUBSECTION
-The system must be tested [...]
-1.2 SECOND SUBSECTION
-As it is mentioned in the previous subsection 1.1, the system has to be validated [...]
+1 SECTION 1
+1.1 SUBSECTION 1
+aux
+
+1.1.1 SUBSECTION 1.1.1
+simple_1: section-1 subsections:1.1 paragraph-Z volume=iv book#ix qtbug-(1324) autosuite-(A.341+.)
+1.1.1.1 SUBSECTION 1.1.1.1
+simple_2_1: 1st item
+1.2 SUBSECTION 2
+simple_2_2: 2nd subsect.
+1.2.1 SUBSECTION 1.2.1
+simple_2_3: 3rd lot previous articles
+3rd lot above volume
+this books
+same points
+same points ix
+
+ 2.
+ xl)
+ (xl)
+PART 1
+simple_2_4: 4th sect.
+PART 2
+simple_3: above articles-1 current paragraph-A next book#ix
+LOT 3
+simple_4: previous 1st paragraphs
+SECTION 2
+simple_5: section-1 preceding
+VOLUME IX
+simple_6: that follows subitems
+simple_7: lot preceding
+
+