Commit 3591b05a authored by Alexander Basov's avatar Alexander Basov Committed by Matija Obreza

Start testing EmailVerification Test

parent 5fe4d46d
......@@ -479,6 +479,17 @@
<artifactId>pgr-ontology-model</artifactId>
<version>0.7.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>2.0.2-beta</version>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<version>3.3.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
......
......@@ -64,7 +64,7 @@ public class DescriptorServiceTest {
}
@After
public void tearDown(){
public void teardown(){
descriptorRepository.deleteAll();
}
......
package org.genesys2.unit;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.velocity.app.VelocityEngine;
import org.easymock.EasyMock;
import org.genesys2.server.exception.UserException;
import org.genesys2.server.model.impl.Article;
import org.genesys2.server.model.impl.ClassPK;
import org.genesys2.server.model.impl.User;
import org.genesys2.server.model.impl.VerificationToken;
import org.genesys2.server.persistence.domain.ClassPKRepository;
import org.genesys2.server.service.*;
import org.genesys2.server.service.impl.*;
import org.genesys2.server.test.JpaDataConfig;
import org.genesys2.server.test.PropertyPlacholderInitializer;
import org.genesys2.spring.config.HazelcastConfig;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.CacheManager;
import org.springframework.cache.support.NoOpCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.PropertySource;
import org.springframework.data.domain.PageRequest;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = EmailVerificationServiceTest.Config.class, initializers = PropertyPlacholderInitializer.class)
@ActiveProfiles("dev")
public class EmailVerificationServiceTest {
private final Log LOG = LogFactory.getLog(EmailVerificationServiceTest.class);
@Import({JpaDataConfig.class, HazelcastConfig.class})
@PropertySource({"classpath:application.properties", "classpath:spring/spring.properties"})
public static class Config {
@Bean
public EMailVerificationService emailVerificationService() {
return new EMailVerificationServiceImpl();
}
@Bean
public EMailService eMailService() {
return Mockito.mock(EMailServiceImpl.class);
}
@Bean
public TokenVerificationService tokenVerificationService() {
return Mockito.mock(TokenVerificationServiceImpl.class);
}
@Bean
public UserService userService() {
return Mockito.mock(UserServiceImpl.class);
}
@Bean
public ContentService contentService() {
return Mockito.mock(ContentServiceImpl.class);
}
@Bean
public CacheManager cacheManager() {
return new NoOpCacheManager();
}
@Bean
public JavaMailSender javaMailSender() {
return new JavaMailSenderImpl();
}
@Bean
public ThreadPoolTaskExecutor threadPoolTaskExecutor() {
return new ThreadPoolTaskExecutor();
}
@Bean
public HtmlSanitizer htmlSanitizer() {
return new OWASPSanitizer();
}
@Bean
public VelocityEngine velocityEngine() {
return new VelocityEngine();
}
}
@Autowired
private EMailVerificationService emailVerificationService;
@Autowired
private TokenVerificationService tokenVerificationService;
@Autowired
private ContentService contentService;
@Autowired
private EMailService eMailService;
@Autowired
private UserService userService;
@Autowired
private ClassPKRepository classPkRepository;
private Article article;
private User user;
private VerificationToken verificationToken;
@Before
public void setUp() {
LOG.info("set up");
user = new User();
user.setName("Name 1");
user.setPassword("password of user");
user.setEmail("salexandrbasov@gmail.com");
user.setUuid("Uuid");
verificationToken = new VerificationToken();
verificationToken.setUuid("tokenUuid");
verificationToken.setKey("tokenKey");
article = new Article();
article.setTitle("articleTitle");
article.setBody("body article");
article.setSlug("smtp.email-verification");
article.setLang("en");
LOG.info("finish set up");
}
@After
public void teardown() {
Mockito.validateMockitoUsage();
// Mockito.reset(eMailService, tokenVerificationService, contentService, userService);
}
// @Test
// public void sendVerificationEmailTest() {
// LOG.info("Start test-method sendVerificationEmailTest");
//
// Mockito.when(contentService.getGlobalArticle("smtp.email-verification", Locale.ENGLISH)).thenReturn(article);
// Mockito.when(tokenVerificationService.generateToken("email-verification", user.getUuid())).thenReturn(verificationToken);
//
// Mockito.doNothing().when(eMailService).sendMail(article.getTitle(), article.getBody(), user.getEmail());
//
// emailVerificationService.sendVerificationEmail(user);
//
// Mockito.verify(eMailService).sendMail(article.getTitle(), article.getBody(), user.getEmail());
//
// LOG.info("Test sendVerificationEmailTest passed!");
// }
//
// @Test
// public void sendPasswordResetEmailTest() {
// LOG.info("Start test-method sendPasswordResetEmailTest");
//
// Mockito.when(tokenVerificationService.generateToken("email-password", user.getUuid())).thenReturn(verificationToken);
// Mockito.when(contentService.getGlobalArticle("smtp.email-password", Locale.ENGLISH)).thenReturn(article);
//
// Mockito.doNothing().when(eMailService).sendMail(article.getTitle(), article.getBody(), user.getEmail());
//
// emailVerificationService.sendPasswordResetEmail(user);
//
// Mockito.verify(eMailService).sendMail(article.getTitle(), article.getBody(), user.getEmail());
//
// LOG.info("Test sendPasswordResetEmailTest passed!");
// }
@Test
public void cancelValidationTest() throws TokenVerificationService.NoSuchVerificationTokenException {
LOG.info("Start test-method cancelValidationTest");
Mockito.doNothing().when(tokenVerificationService).cancel(verificationToken.getUuid());
emailVerificationService.cancelValidation(verificationToken.getUuid());
Mockito.verify(tokenVerificationService).cancel(verificationToken.getUuid());
LOG.info("Test cancelValidationTest passed!");
}
}
......@@ -174,7 +174,7 @@ public class TeamServiceTest {
}
@After
public void tearDown() throws UserException {
public void teardown() throws UserException {
teamRepository.deleteAll();
userService.removeUser(userService.getUserByEmail(user.getEmail()));
......
......@@ -71,7 +71,7 @@ public class TokenVerificationServiceTest {
}
@After
public void afterEachMethod() {
public void teardown() {
if (isAnyTokensExists()) {
tokenRepository.delete(tokenRepository.findAll().get(0).getId());
......
......@@ -85,7 +85,7 @@ public class UserServiceTest {
}
@After
public void afterEachTest() {
public void teardown() {
try {
if (userService.exists(email)) {
......
......@@ -61,6 +61,8 @@ auto.createContent=false
scheduler.tokens.cleanup.hours=1
# Mail configuration
mail.host=localhost
mail.port=25
mail.user.from=test@localhost
mail.requests.to=test@localhost
mail.async=true
......
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