-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated dependencies, added web application tests. Updated news.
- Loading branch information
Nils Hoffmann
committed
May 25, 2020
1 parent
fb531f7
commit b76df63
Showing
7 changed files
with
259 additions
and
13 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
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
45 changes: 45 additions & 0 deletions
45
src/main/java/de/isas/lifs/palinom/webapp/config/TomcatCustomizer.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,45 @@ | ||
/* | ||
* Copyright 2020 Leibniz Institut für Analytische Wissenschaften - ISAS e.V.. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package de.isas.lifs.palinom.webapp.config; | ||
|
||
import org.apache.catalina.connector.Connector; | ||
import org.apache.coyote.http11.AbstractHttp11Protocol; | ||
import org.springframework.boot.web.embedded.tomcat.TomcatConnectorCustomizer; | ||
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; | ||
import org.springframework.boot.web.server.WebServerFactoryCustomizer; | ||
import org.springframework.stereotype.Component; | ||
|
||
/** | ||
* | ||
* @author nilshoffmann | ||
*/ | ||
@Component | ||
public class TomcatCustomizer implements | ||
WebServerFactoryCustomizer<TomcatServletWebServerFactory> { | ||
|
||
@Override | ||
public void customize(TomcatServletWebServerFactory factory) { | ||
|
||
factory.addConnectorCustomizers(new TomcatConnectorCustomizer() { | ||
@Override | ||
public void customize(Connector connector) { | ||
if (connector.getProtocolHandler() instanceof AbstractHttp11Protocol) { | ||
((AbstractHttp11Protocol<?>) connector.getProtocolHandler()).setMaxSwallowSize(-1); | ||
} | ||
} | ||
}); | ||
} | ||
} |
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
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
129 changes: 129 additions & 0 deletions
129
src/test/java/de/isas/lifs/palinom/webapp/controller/LipidNameValidationControllerTest.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,129 @@ | ||
/* | ||
* Copyright 2020 Leibniz Institut für Analytische Wissenschaften - ISAS e.V.. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package de.isas.lifs.palinom.webapp.controller; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import de.isas.lifs.palinom.webapp.Application; | ||
import de.isas.lifs.palinom.webapp.domain.ValidationRequest; | ||
import de.isas.lifs.palinom.webapp.domain.ValidationResult.Grammar; | ||
import java.util.Arrays; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestBuilders.FormLoginRequestBuilder; | ||
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestBuilders.formLogin; | ||
import static org.springframework.security.test.web.servlet.response.SecurityMockMvcResultMatchers.authenticated; | ||
import static org.springframework.security.test.web.servlet.response.SecurityMockMvcResultMatchers.unauthenticated; | ||
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
import org.springframework.test.context.web.WebAppConfiguration; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view; | ||
import org.springframework.test.web.servlet.setup.MockMvcBuilders; | ||
import org.springframework.web.context.WebApplicationContext; | ||
|
||
/** | ||
* | ||
* @author nilshoffmann | ||
*/ | ||
@RunWith(SpringRunner.class) | ||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK, | ||
classes = Application.class) | ||
@AutoConfigureMockMvc | ||
@WebAppConfiguration | ||
@ActiveProfiles(profiles = {"test", "dev"}) | ||
public class LipidNameValidationControllerTest { | ||
|
||
@Autowired | ||
private WebApplicationContext wac; | ||
|
||
@Autowired | ||
private MockMvc mockMvc; | ||
|
||
@Autowired | ||
private ObjectMapper objectMapper; | ||
|
||
@Before | ||
public void setUp() { | ||
mockMvc = MockMvcBuilders.webAppContextSetup(wac) | ||
.apply(springSecurity()) | ||
.build(); | ||
} | ||
|
||
@Test | ||
public void loginAuthenticated() throws Exception { | ||
FormLoginRequestBuilder login = formLogin().loginProcessingUrl("/login") | ||
.user("testuser") | ||
.password("K/sZ!a:M*W*b"); | ||
|
||
mockMvc.perform(login) | ||
.andExpect(authenticated().withUsername("testuser")); | ||
} | ||
|
||
@Test | ||
public void loginUnauthenticated() throws Exception { | ||
FormLoginRequestBuilder login = formLogin().loginProcessingUrl("/login") | ||
.user("invalid") | ||
.password("invalidpassword"); | ||
|
||
mockMvc.perform(login) | ||
.andExpect(unauthenticated()); | ||
} | ||
|
||
// /* This test currently has issues with object serialization of the multipart file */ | ||
// @Test | ||
// public void validateFile() throws Exception { | ||
// ValidationFileRequest vfr = new ValidationFileRequest(); | ||
// String fileName = "filename.txt"; | ||
// File file = File.createTempFile(fileName, ""); | ||
// file.delete(); | ||
// Files.writeString(file.toPath(), "CL 18:3(9Z,12Z,15Z)/16:0/22:5(16Z,10Z,19Z,13Z,7Z)/20:0\n"); | ||
// | ||
// MockMultipartFile lipidNamesFile = new MockMultipartFile("file", fileName, "text/plain", Files.readAllBytes(file.toPath())); | ||
// vfr.setFile(lipidNamesFile); | ||
// | ||
// MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(wac).build(); | ||
// mockMvc.perform(MockMvcRequestBuilders.post("/validatefile") | ||
// .contentType(MediaType.MULTIPART_FORM_DATA) | ||
// .content(objectMapper.writeValueAsString(vfr)) | ||
// .accept(MediaType.MULTIPART_FORM_DATA)) | ||
// .andExpect(status().isOk()) | ||
// // .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)) | ||
// .andExpect(view().name("index")); | ||
//// .andExpect(content().string("success")); | ||
// } | ||
@Test | ||
public void validateNames() throws Exception { | ||
ValidationRequest vfr = new ValidationRequest(); | ||
vfr.setGrammars(Arrays.asList(Grammar.values())); | ||
vfr.setLipidNames(Arrays.asList("CL 18:3(9Z,12Z,15Z)/16:0/22:5(16Z,10Z,19Z,13Z,7Z)/20:0")); | ||
|
||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(wac).build(); | ||
mockMvc.perform(MockMvcRequestBuilders.post("/validate") | ||
.contentType(MediaType.MULTIPART_FORM_DATA) | ||
.content(objectMapper.writeValueAsString(vfr)) | ||
.accept(MediaType.MULTIPART_FORM_DATA)) | ||
.andExpect(status().isOk()) | ||
.andExpect(view().name("validationResult")); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
src/test/java/de/isas/lifs/palinom/webapp/rest/LipidNameValidationTest.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,67 @@ | ||
/* | ||
* Copyright 2020 Leibniz Institut für Analytische Wissenschaften - ISAS e.V.. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package de.isas.lifs.palinom.webapp.rest; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import de.isas.lifs.palinom.webapp.domain.ValidationRequest; | ||
import de.isas.lifs.palinom.webapp.domain.ValidationResult; | ||
import java.util.Arrays; | ||
import static org.hamcrest.Matchers.hasSize; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
/** | ||
* | ||
* @author nilshoffmann | ||
*/ | ||
@RunWith(SpringRunner.class) | ||
@SpringBootTest | ||
@AutoConfigureMockMvc | ||
public class LipidNameValidationTest { | ||
|
||
@Autowired | ||
private MockMvc mockMvc; | ||
|
||
@Autowired | ||
private ObjectMapper objectMapper; | ||
|
||
@Test | ||
public void validateNames() throws Exception { | ||
ValidationRequest vfr = new ValidationRequest(); | ||
vfr.setGrammars(Arrays.asList(ValidationResult.Grammar.values())); | ||
vfr.setLipidNames(Arrays.asList("CL 18:3(9Z,12Z,15Z)/16:0/22:5(16Z,10Z,19Z,13Z,7Z)/20:0")); | ||
|
||
mockMvc.perform(MockMvcRequestBuilders.post("/rest/validate") | ||
.contentType(MediaType.APPLICATION_JSON_UTF8) | ||
.content(objectMapper.writeValueAsString(vfr)) | ||
.accept(MediaType.APPLICATION_JSON_UTF8)) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.results", hasSize(1))) | ||
.andExpect(jsonPath("$.totalReceived", org.hamcrest.Matchers.is(1))) | ||
.andExpect(jsonPath("$.totalParsed", org.hamcrest.Matchers.is(1))) | ||
.andExpect(jsonPath("$.failedToParse", org.hamcrest.Matchers.is(0))); | ||
} | ||
|
||
} |