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.*; ...@@ -10,6 +10,7 @@ import org.genesys2.server.persistence.domain.*;
import org.genesys2.server.persistence.domain.mock.GenesysLowlevelRepositoryMock; import org.genesys2.server.persistence.domain.mock.GenesysLowlevelRepositoryMock;
import org.genesys2.server.service.*; import org.genesys2.server.service.*;
import org.genesys2.server.service.impl.*; 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.TraitsController;
import org.genesys2.server.servlet.controller.rest.UserController; import org.genesys2.server.servlet.controller.rest.UserController;
import org.genesys2.server.servlet.controller.rest.UsersController; import org.genesys2.server.servlet.controller.rest.UsersController;
...@@ -42,37 +43,42 @@ public abstract class AbstractRestTest { ...@@ -42,37 +43,42 @@ public abstract class AbstractRestTest {
@Configuration @Configuration
@EnableWebMvc @EnableWebMvc
@Import({ JpaDataConfig.class, HazelcastConfig.class }) @Import({JpaDataConfig.class, HazelcastConfig.class})
@PropertySource({ "classpath:application.properties", "classpath:spring/spring.properties" }) @PropertySource({"classpath:application.properties", "classpath:spring/spring.properties"})
public static class Config { public static class Config {
@Bean @Bean
public UserController userController(){ public GeoService geoService() {
return new GeoServiceImpl();
}
@Bean
public UserController userController() {
return new UserController(); return new UserController();
} }
@Bean @Bean
public CacheManager cacheManager(){ public CacheManager cacheManager() {
return new NoOpCacheManager(); return new NoOpCacheManager();
} }
@Bean @Bean
public UserService userService(){ public UserService userService() {
return new UserServiceImpl(); return new UserServiceImpl();
} }
@Bean @Bean
public TeamService teamService(){ public TeamService teamService() {
return new TeamServiceImpl(); return new TeamServiceImpl();
} }
@Bean @Bean
public InstituteService instituteService(){ public InstituteService instituteService() {
return new InstituteServiceImpl(); return new InstituteServiceImpl();
} }
@Bean @Bean
public ContentService contentService(){ public ContentService contentService() {
return new ContentServiceImpl(); return new ContentServiceImpl();
} }
...@@ -102,12 +108,12 @@ public abstract class AbstractRestTest { ...@@ -102,12 +108,12 @@ public abstract class AbstractRestTest {
} }
@Bean @Bean
public UsersController restUsersController(){ public UsersController restUsersController() {
return new UsersController(); return new UsersController();
} }
@Bean @Bean
public OAuth2ClientDetailsService auth2ClientDetailsService(){ public OAuth2ClientDetailsService auth2ClientDetailsService() {
return new OAuth2ClientDetailsServiceImpl(); return new OAuth2ClientDetailsServiceImpl();
} }
...@@ -132,47 +138,57 @@ public abstract class AbstractRestTest { ...@@ -132,47 +138,57 @@ public abstract class AbstractRestTest {
} }
@Bean @Bean
public ThreadPoolTaskExecutor threadPoolTaskExecutor(){ public ThreadPoolTaskExecutor threadPoolTaskExecutor() {
return new ThreadPoolTaskExecutor(); return new ThreadPoolTaskExecutor();
} }
@Bean @Bean
public TraitsController traitsController(){ public TraitsController traitsController() {
return new TraitsController(); return new TraitsController();
} }
@Bean @Bean
public TraitService traitService(){ public TraitService traitService() {
return new TraitServiceImpl(); return new TraitServiceImpl();
} }
@Bean @Bean
public GenesysService genesysService(){ public GenesysService genesysService() {
return new GenesysServiceImpl(); return new GenesysServiceImpl();
} }
@Bean @Bean
public CropService cropService(){ public CropService cropService() {
return new CropServiceImpl(); return new CropServiceImpl();
} }
@Bean @Bean
public TaxonomyService taxonomyService(){ public TaxonomyService taxonomyService() {
return new TaxonomyServiceImpl(); return new TaxonomyServiceImpl();
} }
@Bean @Bean
public TraitValueRepository traitValueRepository(){ public TraitValueRepository traitValueRepository() {
return new TraitValueRepositoryImpl(); return new TraitValueRepositoryImpl();
} }
@Bean @Bean
public OrganizationService organizationService(){ public OrganizationService organizationService() {
return new OrganizationServiceImpl(); return new OrganizationServiceImpl();
} }
@Bean
public LookupController lookupController(){
return new LookupController();
}
} }
@Autowired
GeoService geoService;
@Autowired
CountryRepository countryRepository;
@Autowired @Autowired
FaoInstituteRepository instituteRepository; FaoInstituteRepository instituteRepository;
...@@ -185,6 +201,9 @@ public abstract class AbstractRestTest { ...@@ -185,6 +201,9 @@ public abstract class AbstractRestTest {
@Autowired @Autowired
GenesysLowlevelRepository genesysLowlevelRepository; GenesysLowlevelRepository genesysLowlevelRepository;
@Autowired
LookupController lookupController;
@Autowired @Autowired
TraitsController traitsController; TraitsController traitsController;
...@@ -239,12 +258,15 @@ public abstract class AbstractRestTest { ...@@ -239,12 +258,15 @@ public abstract class AbstractRestTest {
@Autowired @Autowired
GenesysService genesysService; GenesysService genesysService;
@Autowired CropService cropService; @Autowired
CropService cropService;
@Autowired @Autowired
CropRepository cropRepository; 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