Commit 4462b801 authored by Aleksandr Sharaban's avatar Aleksandr Sharaban Committed by Matija Obreza

Spring test configuration fixed, unit test fails fixed.

parent 39102ce9
......@@ -125,6 +125,12 @@
<version>1.0.1.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>2.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
......
......@@ -65,7 +65,8 @@ public class Crop extends GlobalVersionedAuditedModel implements AclAwareModel {
private String shortName;
@Column(name = "otherName", nullable = false)
@ElementCollection(fetch = FetchType.LAZY)
//FetchType.LAZY doesn't work in unit tests, it causes org.hibernate.LazyInitializationException
@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(name = "cropname", joinColumns = @JoinColumn(name = "cropId", referencedColumnName = "id"), uniqueConstraints = { @UniqueConstraint(columnNames = "otherName") })
@OrderBy("otherName")
private List<String> otherNames;
......
......@@ -22,6 +22,8 @@ import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IQueue;
import org.apache.log4j.Logger;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.exception.VelocityException;
......@@ -29,6 +31,7 @@ import org.genesys2.server.aspect.AsAdminAspect;
import org.genesys2.server.model.elastic.AccessionDetails;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.model.impl.Organization;
import org.genesys2.server.service.ElasticSearchManagementService;
import org.genesys2.server.service.AclService;
import org.genesys2.server.service.ContentService;
import org.genesys2.server.service.CropService;
......@@ -45,6 +48,7 @@ import org.genesys2.server.service.TraitService;
import org.genesys2.server.service.UserService;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilter;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilters;
import org.genesys2.server.service.worker.ElasticUpdater;
import org.genesys2.server.test.JpaDataConfig;
import org.genesys2.server.test.PropertyPlacholderInitializer;
import org.genesys2.spring.config.ElasticsearchConfig;
......@@ -171,6 +175,31 @@ public class ElasticsearchTest {
private TraitService traitService() {
return new TraitServiceImpl();
}
@Bean
public ElasticSearchManagementService elasticSearchManagementService() {
return new ElasticSearchManagementServiceImpl();
}
@Bean
public ElasticUpdater elasticUpdater() {
return new ElasticUpdater();
}
@Bean
public ElasticUpdater.ElasticNode elasticNode() {
return null;
}
@Bean
public IQueue<Object> elasticRemoveQueue(HazelcastInstance hazelcast) {
return hazelcast.getQueue("es-remove");
}
@Bean
public IQueue<Object> elasticUpdateQueue(HazelcastInstance hazelcast) {
return hazelcast.getQueue("es-update");
}
}
@Autowired
......
......@@ -39,7 +39,7 @@ public class PropertyPlacholderInitializer implements ApplicationContextInitiali
try {
postProcessor.setLocations(
// add all properties
resourcePatternResolver.getResources("classpath:**/*.properties"));
resourcePatternResolver.getResources("classpath*:**/*.properties"));
} catch (final IOException e) {
throw new BeanCreationException("Could not create bean " + postProcessor.toString(), e);
}
......
package org.genesys2.tests.resttests;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IQueue;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.velocity.app.VelocityEngine;
import org.genesys2.server.aspect.AsAdminAspect;
......@@ -38,6 +40,9 @@ import org.genesys2.server.persistence.domain.UserPersistence;
import org.genesys2.server.persistence.domain.kpi.KPIParameterRepository;
import org.genesys2.server.persistence.domain.kpi.ObservationRepository;
import org.genesys2.server.persistence.domain.mock.TraitServiceMock;
import org.genesys2.server.service.worker.ElasticUpdater;
import org.genesys2.server.service.ElasticSearchManagementService;
import org.genesys2.server.service.impl.ElasticSearchManagementServiceImpl;
import org.genesys2.server.service.AclService;
import org.genesys2.server.service.BatchRESTService;
import org.genesys2.server.service.ContentService;
......@@ -413,6 +418,31 @@ public abstract class AbstractRestTest extends SpringTest {
mapperFactoryBean.setFeaturesToDisable(SerializationFeature.FAIL_ON_EMPTY_BEANS, DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
return mapperFactoryBean;
}
@Bean
public ElasticSearchManagementService elasticSearchManagementService() {
return new ElasticSearchManagementServiceImpl();
}
@Bean
public ElasticUpdater elasticUpdater() {
return new ElasticUpdater();
}
@Bean
public ElasticUpdater.ElasticNode elasticNode() {
return null;
}
@Bean
public IQueue<Object> elasticRemoveQueue(HazelcastInstance hazelcast) {
return hazelcast.getQueue("es-remove");
}
@Bean
public IQueue<Object> elasticUpdateQueue(HazelcastInstance hazelcast) {
return hazelcast.getQueue("es-update");
}
}
@Autowired
......
......@@ -146,6 +146,7 @@ public class CropsControllerTest extends AbstractRestTest {
fieldWithPath("description").description("Crop description in English"),
fieldWithPath("rdfUri").type(JsonFieldType.STRING).optional().description("URI of RDF term describing the crop"),
fieldWithPath("i18n").type(JsonFieldType.STRING).optional().description("i18n map"),
fieldWithPath("otherNames").ignored(),
fieldWithPath("createdBy").ignored(),
fieldWithPath("createdDate").ignored(),
fieldWithPath("lastModifiedBy").ignored(),
......@@ -179,6 +180,7 @@ public class CropsControllerTest extends AbstractRestTest {
fieldWithPath("description").description("Crop description in English"),
fieldWithPath("rdfUri").type(JsonFieldType.STRING).optional().description("URI of RDF term describing the crop"),
fieldWithPath("i18n").type(JsonFieldType.STRING).optional().description("i18n map"),
fieldWithPath("otherNames").ignored(),
fieldWithPath("createdBy").ignored(),
fieldWithPath("createdDate").ignored(),
fieldWithPath("lastModifiedBy").ignored(),
......
......@@ -149,7 +149,7 @@ public class ContentServiceTest extends AbstractServicesTest {
String slug = contentService.listArticles(new PageRequest(0, 6)).getContent().get(0).getSlug();
Article article = contentService.getArticle(Article.class, null, slug, Locale.getDefault(), true);
Article article = contentService.getArticle(Article.class, null, slug, Locale.ENGLISH, true);
assertNotNull(article);
......
......@@ -125,22 +125,24 @@ public class EmailVerificationServiceTest extends AbstractServicesTest {
}
@Test
public void sendVerificationEmailTest() {
public void sendVerificationEmailTest() throws InterruptedException {
LOG.info("Start test-method sendVerificationEmailTest");
Mockito.doNothing().when(mailSender).send(isA(MimeMessagePreparator.class));
emailVerificationService.sendVerificationEmail(userService.listUsers(new PageRequest(0, 1)).getContent().get(0));
Thread.sleep(100);
Mockito.verify(mailSender).send(isA(MimeMessagePreparator.class));
LOG.info("Test sendVerificationEmailTest passed!");
}
@Test
public void sendPasswordResetEmailTest() {
public void sendPasswordResetEmailTest() throws InterruptedException {
LOG.info("Start test-method sendPasswordResetEmailTest");
User user = userService.listUsers(new PageRequest(0, 1)).getContent().get(0);
Mockito.doNothing().when(mailSender).send(isA(MimeMessagePreparator.class));
emailVerificationService.sendPasswordResetEmail(user);
Thread.sleep(100);
Mockito.verify(mailSender).send(isA(MimeMessagePreparator.class));
LOG.info("Test sendPasswordResetEmailTest 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