Commit 0febb8e9 authored by Maxym Borodenko's avatar Maxym Borodenko
Browse files

Merge branch 'bug-trim-whitespace-in-taxonomy2' into 'master'

Fix: Taxonomy2 must trim whitespace

See merge request genesys-pgr/genesys-server!437
parents 0f9573b1 0ddcf8b5
......@@ -239,21 +239,16 @@ public class Taxonomy2 extends GlobalVersionedAuditedModel {
* @return
*/
public Taxonomy2 sanitize() {
if (species == null) {
species = "sp.";
}
if ("sp".equalsIgnoreCase(species)) {
genus = StringUtils.trimToEmpty(genus);
species = StringUtils.trimToEmpty(species);
spAuthor = StringUtils.trimToEmpty(spAuthor);
subtaxa = StringUtils.trimToEmpty(subtaxa);
subtAuthor = StringUtils.trimToEmpty(subtAuthor);
if (StringUtils.isBlank(species) || "sp".equalsIgnoreCase(species)) {
species = "sp.";
}
if (spAuthor == null) {
spAuthor = "";
}
if (subtaxa == null) {
subtaxa = "";
}
if (subtAuthor == null) {
subtAuthor = "";
}
return this;
}
......
......@@ -15,6 +15,7 @@
**/
package org.genesys.test.server.services;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -23,6 +24,7 @@ public class MappingServiceTest extends AbstractServicesTest {
private final Logger LOG = LoggerFactory.getLogger(MappingServiceTest.class);
@Ignore
@Test
public void filteredKmlTest() {
LOG.info("Start test-method filteredKmlTest");
......
/**
* Copyright 2015 Global Crop Diversity Trust
/*
* Copyright 2019 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -12,21 +12,51 @@
* 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 org.genesys.test.server.services;
import static org.junit.Assert.assertEquals;
import org.genesys2.server.model.genesys.Taxonomy2;
import org.junit.After;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.transaction.annotation.Transactional;
public class TaxonomyServiceTest extends AbstractServicesTest {
private static final Logger LOG = LoggerFactory.getLogger(UserServiceTest.class);
private static final String GENUS = "Hordeum";
private static final String SPECIES = "sp.";
private static final String WHITESPACE = " ";
@Transactional
@After
@Override
public void cleanup() throws Exception {
taxonomy2Repository.deleteAll();
super.cleanup();
}
@Test
public void getWithLongParameterTest() {
LOG.info("Start test-method getWithLongParameterTest");
public void ensureTaxonomyTest() {
Taxonomy2 taxon1 = new Taxonomy2();
taxon1.setGenus(GENUS);
taxon1.setSpecies(SPECIES);
taxonomyService.ensureTaxonomy(taxon1);
assertEquals(1L, taxonomy2Repository.count());
Taxonomy2 taxon2 = new Taxonomy2();
taxon2.setGenus(GENUS + WHITESPACE);
taxon2.setSpecies(SPECIES + WHITESPACE);
taxonomyService.ensureTaxonomy(taxon2);
assertEquals(1L, taxonomy2Repository.count());
Taxonomy2 taxon3 = new Taxonomy2();
taxon3.setGenus(WHITESPACE + GENUS + WHITESPACE);
taxon3.setSpecies(WHITESPACE + SPECIES + WHITESPACE);
taxonomyService.ensureTaxonomy(taxon3);
LOG.info("Test getWithLongParameterTest passed!");
assertEquals(1L, taxonomy2Repository.count());
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment