Skip to content

Commit

Permalink
Updated dependencies, added web application tests. Updated news.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nils Hoffmann committed May 25, 2020
1 parent fb531f7 commit b76df63
Show file tree
Hide file tree
Showing 7 changed files with 259 additions and 13 deletions.
19 changes: 10 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>de.isas.lifs</groupId>
<artifactId>lifs-goslin-webapp</artifactId>
<version>1.1.2-SNAPSHOT</version>
<version>1.1.2</version>
<packaging>jar</packaging>
<description>Grammar of Succinct Lipid Nomenclature - Webapplication and REST service for parsing, validation and normalization of lipid names.</description>
<name>LIFS Goslin webapp.</name>
Expand Down Expand Up @@ -59,7 +59,7 @@
<!--<java.version>1.8</java.version>-->
<application.version.number>${project.version}</application.version.number>
<springfox.version>2.9.2</springfox.version>
<spring.boot.version>2.1.13.RELEASE</spring.boot.version>
<spring.boot.version>2.1.14.RELEASE</spring.boot.version>
<docker.image.prefix>lifs</docker.image.prefix>
<dockerfile.plugin.version>1.4.10</dockerfile.plugin.version>
<lombok.version>1.18.10</lombok.version>
Expand All @@ -71,7 +71,7 @@
<junit.platform.version>1.0.3</junit.platform.version>
<swagger.version>1.5.21</swagger.version>
<jersey.version>2.22.2</jersey.version>
<jackson.version>2.10.3</jackson.version>
<jackson.version>2.10.4</jackson.version>
<jodatime.version>2.9.9</jodatime.version>
<hibernate.validator.version>6.0.14.Final</hibernate.validator.version>
<slf4j.version>1.7.25</slf4j.version>
Expand All @@ -86,7 +86,7 @@
<guava.version>27.1-jre</guava.version>
<stomp.version>2.3.3</stomp.version>
<javax.ws.rs.version>2.1.1</javax.ws.rs.version>
<jgoslin.version>1.1.2-SNAPSHOT</jgoslin.version>
<jgoslin.version>1.1.2</jgoslin.version>
<assembly.dir>${project.artifactId}</assembly.dir>
<app.name>goslin</app.name>
<contextPath>/goslin</contextPath>
Expand Down Expand Up @@ -281,6 +281,12 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
Expand All @@ -302,11 +308,6 @@
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-csv</artifactId>
</dependency>
<!-- <dependency>
<groupId>ognl</groupId>
<artifactId>ognl</artifactId>
<version>3.0.21</version>
</dependency>-->
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/de/isas/lifs/palinom/webapp/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
*/
@SpringBootApplication
@EnableSwagger2
@EnableConfigurationProperties(value = {StorageProperties.class, NewsPropertyConfig.class})
@EnableConfigurationProperties(value = {StorageProperties.class,
NewsPropertyConfig.class})
@EnableScheduling
@ComponentScan(basePackages = {"de.isas.lifs.webapps", "de.isas.lifs.palinom"})
public class Application {
Expand All @@ -51,4 +52,5 @@ public int getExitCode() {
}

}

}
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);
}
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
import de.isas.lifs.webapps.common.service.storage.StorageProperties;
import java.util.Locale;
import java.util.concurrent.Executor;
import org.apache.coyote.http11.AbstractHttp11Protocol;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.embedded.tomcat.TomcatConnectorCustomizer;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand Down Expand Up @@ -123,7 +125,7 @@ private ApiInfo apiEndPointsInfo() {
.version(appInfo().getVersionNumber())
.build();
}

@Bean
public StorageService storageService(@Autowired StorageProperties storageProperties) {
return new FileSystemStorageService(storageProperties);
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/news.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ news.news[1].title = Added masses, sum formulas and adducts
news.news[1].content = <p>This release adds support for mass and sum formula calculation for most lipid classes (please check <a href="/documentation#lipid-classes-supported-by-goslin-and-the-web-application">the lipid class table</a>) based on the neutral lipid. It also adds support for adducts within the Goslin and Goslin fragments grammars, currently limited to those supported by <a href="https://lifs.isas.de/lipidcreator" target="_blank">LipidCreator</a>. Thus, normalized lipid shorthand notation names, as provided <b>after translation with Goslin</b>, can now be combined with an adduct. Please note that adduct charges need to be explicit, thus '[M+H]+' needs to be provided as '[M+H]1+'. Adducts are also factored into the mass and sum formula calculations.</p><p>This release contains mappings for normalized lipid names to SwissLipids (updated May 15th, 2020) and LipidMaps (updated February 10th, 2020). The Goslin web application is <b>not</b> a meta search engine (yet).</p>

news.news[2].link = https://github.com/lifs-tools/goslin-webapp/releases/tag/v1.1.2
news.news[2].date = v1.1.2 - May 20th, 2020
news.news[2].date = v1.1.2 - May 25th, 2020
news.news[2].title = Maintenance update
news.news[2].content = <p>This release adds additional warnings whenever modifications are encountered. At the moment, only hydroxylations are properly accounted for within the mass and sum formula calculation. It also updates the jgoslin dependency to the latest release version 1.1.2.</p>
news.news[2].content = <p>This release follows release <a href="https://github.com/lifs-tools/jgoslin/releases/tag/v1.1.2" target="_blank">1.1.2 of the jgoslin library</a>. It adds additional warnings whenever modifications are encountered. At the moment, only hydroxylations are properly accounted for within the mass and sum formula calculation. It also updates the jgoslin dependency to the latest release version 1.1.2.</p>
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"));
}
}
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)));
}

}

0 comments on commit b76df63

Please sign in to comment.