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

LookupControllerTest completed

parent 68ba8658
......@@ -10,6 +10,7 @@ import org.genesys2.server.persistence.domain.*;
import org.genesys2.server.persistence.domain.mock.GenesysLowlevelRepositoryMock;
import org.genesys2.server.service.*;
import org.genesys2.server.service.impl.*;
import org.genesys2.server.servlet.controller.rest.LookupController;
import org.genesys2.server.servlet.controller.rest.TraitsController;
import org.genesys2.server.servlet.controller.rest.UserController;
import org.genesys2.server.servlet.controller.rest.UsersController;
......@@ -42,37 +43,42 @@ public abstract class AbstractRestTest {
@Configuration
@EnableWebMvc
@Import({ JpaDataConfig.class, HazelcastConfig.class })
@PropertySource({ "classpath:application.properties", "classpath:spring/spring.properties" })
@Import({JpaDataConfig.class, HazelcastConfig.class})
@PropertySource({"classpath:application.properties", "classpath:spring/spring.properties"})
public static class Config {
@Bean
public UserController userController(){
public GeoService geoService() {
return new GeoServiceImpl();
}
@Bean
public UserController userController() {
return new UserController();
}
@Bean
public CacheManager cacheManager(){
public CacheManager cacheManager() {
return new NoOpCacheManager();
}
@Bean
public UserService userService(){
public UserService userService() {
return new UserServiceImpl();
}
@Bean
public TeamService teamService(){
public TeamService teamService() {
return new TeamServiceImpl();
}
@Bean
public InstituteService instituteService(){
public InstituteService instituteService() {
return new InstituteServiceImpl();
}
@Bean
public ContentService contentService(){
public ContentService contentService() {
return new ContentServiceImpl();
}
......@@ -102,12 +108,12 @@ public abstract class AbstractRestTest {
}
@Bean
public UsersController restUsersController(){
public UsersController restUsersController() {
return new UsersController();
}
@Bean
public OAuth2ClientDetailsService auth2ClientDetailsService(){
public OAuth2ClientDetailsService auth2ClientDetailsService() {
return new OAuth2ClientDetailsServiceImpl();
}
......@@ -132,47 +138,57 @@ public abstract class AbstractRestTest {
}
@Bean
public ThreadPoolTaskExecutor threadPoolTaskExecutor(){
public ThreadPoolTaskExecutor threadPoolTaskExecutor() {
return new ThreadPoolTaskExecutor();
}
@Bean
public TraitsController traitsController(){
public TraitsController traitsController() {
return new TraitsController();
}
@Bean
public TraitService traitService(){
public TraitService traitService() {
return new TraitServiceImpl();
}
@Bean
public GenesysService genesysService(){
public GenesysService genesysService() {
return new GenesysServiceImpl();
}
@Bean
public CropService cropService(){
public CropService cropService() {
return new CropServiceImpl();
}
@Bean
public TaxonomyService taxonomyService(){
public TaxonomyService taxonomyService() {
return new TaxonomyServiceImpl();
}
@Bean
public TraitValueRepository traitValueRepository(){
public TraitValueRepository traitValueRepository() {
return new TraitValueRepositoryImpl();
}
@Bean
public OrganizationService organizationService(){
public OrganizationService organizationService() {
return new OrganizationServiceImpl();
}
@Bean
public LookupController lookupController(){
return new LookupController();
}
}
@Autowired
GeoService geoService;
@Autowired
CountryRepository countryRepository;
@Autowired
FaoInstituteRepository instituteRepository;
......@@ -185,6 +201,9 @@ public abstract class AbstractRestTest {
@Autowired
GenesysLowlevelRepository genesysLowlevelRepository;
@Autowired
LookupController lookupController;
@Autowired
TraitsController traitsController;
......@@ -239,12 +258,15 @@ public abstract class AbstractRestTest {
@Autowired
GenesysService genesysService;
@Autowired CropService cropService;
@Autowired
CropService cropService;
@Autowired
CropRepository cropRepository;
@Autowired ParameterRepository parameterRepository;
@Autowired
ParameterRepository parameterRepository;
@Autowired ParameterCategoryRepository parameterCategoryRepository;
@Autowired
ParameterCategoryRepository parameterCategoryRepository;
}
package org.genesys2.resttests;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.genesys2.server.exception.UserException;
import org.genesys2.server.model.impl.Country;
import org.genesys2.server.model.impl.User;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import java.util.HashMap;
import java.util.Map;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
public class LookupControllerTest extends AbstractRestTest {
private static final Log LOG = LogFactory.getLog(LookupControllerTest.class);
@Autowired
WebApplicationContext webApplicationContext;
MockMvc mockMvc;
User user;
@Before
public void startUp() throws UserException {
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
Country newCountry = new Country();
newCountry.setCode2("AF");
newCountry.setCode3("AFG");
newCountry.setCodeNum("004");
newCountry.setCurrent(true);
newCountry.setName("Afghanistan");
countryRepository.save(newCountry);
}
@After
public void tearDown(){
countryRepository.deleteAll();
}
@Test
public void getTest() throws Exception {
LOG.info("Start test-method getTest");
ObjectMapper objectmapper = new ObjectMapper();
Map<String, String> orgCty = new HashMap<>();
orgCty.put("AFG", "Afghanistan");
mockMvc.perform(get("/api/v0/lookup/orgCty")
.contentType(MediaType.APPLICATION_JSON).param("lang", ""))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(content().string(objectmapper.writeValueAsString(orgCty)));
LOG.info("Test getTest is passed");
}
}
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