Commit fe11dd17 authored by Alexander Basov's avatar Alexander Basov Committed by Matija Obreza
Browse files

CropServiceTest completed

parent 75e84ebb
......@@ -134,6 +134,41 @@ public abstract class AbstractServicesTest {
public InstituteService instituteService(){
return new InstituteServiceImpl();
}
@Bean
public GenesysFilterService genesysFilterService(){
return new GenesysFilterServiceImpl();
}
@Bean
public MappingService mappingService(){
return new MappingServiceImpl();
}
@Bean
public GenesysService genesysService(){
return new GenesysServiceImpl();
}
@Bean
public TraitValueRepository traitValueRepository(){
return new TraitValueRepositoryImpl();
}
@Bean
public OrganizationService organizationService(){
return new OrganizationServiceImpl();
}
@Bean
public TraitService traitService(){
return new TraitServiceImpl();
}
@Bean
public GeoService geoService(){
return new GeoServiceImpl();
}
}
@Autowired
......@@ -196,4 +231,24 @@ public abstract class AbstractServicesTest {
@Autowired
public UserService userService;
@Autowired
public CropService cropService;
@Autowired
public CropRepository cropRepository;
@Autowired
public CropRuleRepository cropRuleRepository;
@Autowired
public CropTaxonomyRepository cropTaxonomyRepository;
@Autowired
public Taxonomy2Repository taxonomy2Repository;
@Autowired
public GenesysFilterService genesysFilterService;
@Autowired
public MappingService mappingService;
}
......@@ -3,10 +3,7 @@ package org.genesys2.unit;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.genesys2.server.model.impl.Article;
import org.genesys2.server.service.ContentService;
import org.genesys2.server.service.impl.ContentSanitizer;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import java.util.Locale;
......
package org.genesys2.unit;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.genesys2.server.model.genesys.Taxonomy2;
import org.genesys2.server.model.impl.Crop;
import org.genesys2.server.model.impl.CropRule;
import org.genesys2.server.model.impl.CropTaxonomy;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
public class CropServiceTest extends AbstractServicesTest{
private static final Log LOG = LogFactory.getLog(CropServiceTest.class);
@Before
public void setUp(){
cropService.addCrop("Crop short name", "Crop name", "description", "en");
}
@After
public void teardown(){
cropTaxonomyRepository.deleteAll();
cropRepository.deleteAll();
cropRuleRepository.deleteAll();
}
@Test
public void getCropTest(){
LOG.info("Start test-method getCropTest");
assertNotNull(cropService.getCrop("Crop short name"));
LOG.info("Test getCropTest passed!");
}
@Test
public void deleteTest(){
LOG.info("Start test-method deleteTest");
Crop cropForRemove = cropService.getCrop("Crop short name");
cropService.delete(cropForRemove);
assertTrue(cropService.listCrops().isEmpty());
LOG.info("Test deleteTest passed!");
}
@Test
public void updateCropTest(){
LOG.info("Start test-method updateCropTest");
Crop cropForUpdate = cropService.getCrop("Crop short name");
cropService.updateCrop(cropForUpdate, "new name", "new description", "ru");
assertTrue(cropService.getCrop("Crop short name").getName().equals("new name"));
LOG.info("Test updateCropTest passed!");
}
@Test
public void addCropRuleTest(){
LOG.info("Start test-method addCropRuleTest");
Crop cropForTest = cropService.getCrop("Crop short name");
cropService.addCropRule(cropForTest, "genus", "species", false);
assertTrue(!cropService.getCropRules(cropForTest).isEmpty());
LOG.info("Test addCropRuleTest passed!");
}
@Test
public void setCropRulesTest(){
LOG.info("Start test-method setCropRulesTest");
Crop cropForTest = cropService.getCrop("Crop short name");
List<CropRule> cropRuleList = new ArrayList<>();
CropRule cropRule = new CropRule();
cropRule.setGenus("genus");
cropRuleList.add(cropRule);
cropService.setCropRules(cropForTest, cropRuleList);
assertTrue(!cropService.getCropRules(cropForTest).isEmpty());
LOG.info("Test setCropRulesTest passed!");
}
@Test
public void getCropRulesTest(){
LOG.info("Start test-method getCropRulesTest");
Crop cropForTest = cropService.getCrop("Crop short name");
assertTrue(cropService.getCropRules(cropForTest).isEmpty());
List<CropRule> cropRuleList = new ArrayList<>();
CropRule cropRule = new CropRule();
cropRule.setGenus("genus");
cropRuleList.add(cropRule);
cropService.setCropRules(cropForTest, cropRuleList);
assertTrue(!cropService.getCropRules(cropForTest).isEmpty());
LOG.info("Test getCropRulesTest passed!");
}
@Test
public void updateCropTaxonomyListsTest(){
LOG.info("Start test-method updateCropTaxonomyListsTest");
Taxonomy2 taxonomy = new Taxonomy2();
taxonomy.setGenus("genus");
taxonomy.setVersion(1);
taxonomy.setSpAuthor("SpAuthor");
taxonomy.setSpecies("species");
taxonomy.setSubtAuthor("SubtAuthor");
taxonomy.setSubtaxa("Subtaxa");
taxonomy.setTaxonName("TaxonName");
Crop cropForTest = cropService.getCrop("Crop short name");
Crop crop2 = cropService.addCrop("Crop short name 2", "Crop name 2", "description 2", "en");
List<CropRule> cropRuleList = new ArrayList<>();
CropRule cropRule = new CropRule();
cropRule.setGenus("genus");
cropRule.setSpecies("species");
cropRule.setSubtaxa("Subtaxa");
cropRule.setCrop(cropForTest);
cropRule.setIncluded(true);
CropRule cropRule2 = new CropRule();
cropRule2.setGenus("genuss");
cropRule2.setSpecies("speciess");
cropRule2.setSubtaxa("Subtaxas");
cropRule2.setCrop(cropForTest);
cropRule2.setIncluded(true);
cropRuleList.add(cropRule2);
cropRuleList.add(cropRule);
cropService.setCropRules(cropForTest, cropRuleList);
List<CropTaxonomy> cropTaxonomyList = new ArrayList<>();
CropTaxonomy cropTaxonomy = new CropTaxonomy();
cropTaxonomy.setTaxonomy(taxonomy);
cropTaxonomy.setCrop(cropForTest);
CropTaxonomy cropTaxonomy2 = new CropTaxonomy();
cropTaxonomy2.setTaxonomy(taxonomy);
cropTaxonomy2.setCrop(crop2);
cropTaxonomyList.add(cropTaxonomy);
cropTaxonomyList.add(cropTaxonomy2);
taxonomy.setCropTaxonomies(cropTaxonomyList);
taxonomy2Repository.save(taxonomy);
cropTaxonomyRepository.save(cropTaxonomyList);
assertTrue(cropTaxonomyRepository.findAll().size() == 2);
cropService.updateCropTaxonomyLists(taxonomy);
assertTrue(cropTaxonomyRepository.findAll().size() == 1);
LOG.info("Test updateCropTaxonomyListsTest passed!");
}
}
......@@ -3,12 +3,9 @@ package org.genesys2.unit;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.genesys2.server.model.impl.Descriptor;
import org.genesys2.server.persistence.domain.DescriptorRepository;
import org.genesys2.server.service.DescriptorService;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import static org.junit.Assert.assertTrue;
......
package org.genesys2.unit;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Test;
public class MappingServiceTest extends AbstractServicesTest{
private final Log LOG = LogFactory.getLog(MappingServiceTest.class);
@Test
public void filteredKmlTest(){
LOG.info("Start test-method filteredKmlTest");
// FilterHandler.AppliedFilters filters = new FilterHandler.AppliedFilters();
// FilterHandler.AppliedFilter filter = new FilterHandler.AppliedFilter();
// filter.setFilterName("filter name");
//
// filter.addFilterValue(new FilterHandler.MaxValueFilter(1));
//
// filters.add(filter);
//
// assertNotNull(mappingService.filteredKml(filters));
LOG.info("Test filteredKmlTest passed!");
}
}
......@@ -3,12 +3,10 @@ package org.genesys2.unit;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.genesys2.server.model.impl.VerificationToken;
import org.genesys2.server.persistence.domain.VerificationTokenRepository;
import org.genesys2.server.service.TokenVerificationService;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import static org.junit.Assert.*;
......
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