Skip to content

Commit

Permalink
add html file tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Quim committed Sep 3, 2019
1 parent 8d0c8bb commit 119c49f
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
65 changes: 65 additions & 0 deletions src/test/java/com/essi/Dependency/AppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;

import java.io.BufferedReader;
import java.io.FileReader;
Expand Down Expand Up @@ -47,6 +51,67 @@ public void crossReferenceJSONProject() throws Exception {
Assert.assertEquals(1, result.getJSONArray("dependencies").length());
}

@Test
public void crossReferenceJSONProjectNM() throws Exception {
String projectId = "QTBUG";
String response = this.mockMvc.perform(
post("/upc/cross-reference-detection/json/" + projectId + "/1/2")
.contentType(MediaType.APPLICATION_JSON)
.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());
}

@Test
public void crossReferenceHTMLProject() throws Exception {
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")
.file(mockMultipartFile);

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());
}

@Test
public void crossReferenceHTMLProjectNM() throws Exception {
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/1/2")
.file(mockMultipartFile);

String response = this.mockMvc.perform(builder).andExpect(status().isOk())
.andDo(MockMvcResultHandlers.print()).andReturn().getResponse().getContentAsString();;
JSONObject result = new JSONObject(response);
Assert.assertEquals(0, result.getJSONArray("dependencies").length());
}

private String read_html_file(String path) throws Exception {
String result = "";
String line = "";
FileReader fileReader = null;
BufferedReader bufferedReader = null;
try {
fileReader = new FileReader(path);
bufferedReader = new BufferedReader(fileReader);
while ((line = bufferedReader.readLine()) != null) {
result = result.concat(line);
}
bufferedReader.close();
return result;
} finally {
if (fileReader != null) fileReader.close();
if (bufferedReader != null) bufferedReader.close();
}
}

private String read_file(String path) throws Exception {
String result = "";
String line = "";
Expand Down
10 changes: 10 additions & 0 deletions testing/integration/sample-2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<html>
<head></head>
<body>
<h1><span>1 <span> </span>FIRST SECTION</span></h1>
<h2><span>1.1<span> </span>FIRST SUBSECTION</span></h2>
<p>The system must be tested [...]</p>
<h2><span>1.2<span> </span>SECOND SUBSECTION</span></h2>
<p>As it is mentioned in the previous subsection 1.1, the system has to be validated [...]</p>
</body>
</html>

0 comments on commit 119c49f

Please sign in to comment.