Commit 531e204f authored by Matija Obreza's avatar Matija Obreza
Browse files

Source code formatted

parent 2895d37b
......@@ -45,225 +45,225 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@ActiveProfiles("dev")
public abstract class AbstractServicesTest {
@Configuration
@Import({ JpaDataConfig.class, HazelcastConfig.class })
@PropertySource({ "classpath:application.properties", "classpath:spring/spring.properties" })
public static class Config {
@Bean
public UserDetailsService userDetailsService() {
return new AuthUserDetailsService();
}
@Bean
public UserService userService() {
return new UserServiceImpl();
}
@Bean
public CacheManager cacheManager(){
return new NoOpCacheManager();
}
@Bean
public ContentService contentService(){
return new ContentServiceImpl();
}
@Bean
public HtmlSanitizer htmlSanitizer(){
return new OWASPSanitizer();
}
@Bean
public ContentSanitizer contentSanitizer(){
return new ContentSanitizer();
}
@Bean
public VelocityEngine velocityEngine(){
return new VelocityEngine();
}
@Bean
public DescriptorService descriptorService(){
return new DescriptorServiceImpl();
}
@Bean
public ThreadPoolTaskExecutor threadPoolTaskExecutor() {
return new ThreadPoolTaskExecutor();
}
@Bean
public EMailService eMailService() {
return new EMailServiceImpl();
}
@Bean
public JavaMailSender mailSender() {
return Mockito.mock(JavaMailSenderImpl.class);
}
@Bean
public EMailVerificationService emailVerificationService() {
return new EMailVerificationServiceImpl();
}
@Bean
public TokenVerificationService tokenVerificationService() {
return new TokenVerificationServiceImpl();
}
@Bean
public TaxonomyService taxonomyService(){
return new TaxonomyServiceImpl();
}
@Bean
public CropService cropService(){
return new CropServiceImpl();
}
@Bean
public TeamService teamService() {
return new TeamServiceImpl();
}
@Bean
public GenesysLowlevelRepository genesysLowlevelRepository(){
return new GenesysLowlevelRepositoryCustomImpl();
}
@Bean
public AclService aclService(){
return new AclServiceImpl();
}
@Bean
public AsAdminAspect asAdminAspect(){
return new AsAdminAspect();
}
@Bean
public InstituteService instituteService(){
return new InstituteServiceImpl();
}
@Bean
public GenesysFilterService genesysFilterService(){
return new GenesysFilterServiceImpl();
}
@Configuration
@Import({ JpaDataConfig.class, HazelcastConfig.class })
@PropertySource({ "classpath:application.properties", "classpath:spring/spring.properties" })
public static class Config {
@Bean
public UserDetailsService userDetailsService() {
return new AuthUserDetailsService();
}
@Bean
public UserService userService() {
return new UserServiceImpl();
}
@Bean
public CacheManager cacheManager() {
return new NoOpCacheManager();
}
@Bean
public ContentService contentService() {
return new ContentServiceImpl();
}
@Bean
public HtmlSanitizer htmlSanitizer() {
return new OWASPSanitizer();
}
@Bean
public ContentSanitizer contentSanitizer() {
return new ContentSanitizer();
}
@Bean
public VelocityEngine velocityEngine() {
return new VelocityEngine();
}
@Bean
public DescriptorService descriptorService() {
return new DescriptorServiceImpl();
}
@Bean
public ThreadPoolTaskExecutor threadPoolTaskExecutor() {
return new ThreadPoolTaskExecutor();
}
@Bean
public EMailService eMailService() {
return new EMailServiceImpl();
}
@Bean
public JavaMailSender mailSender() {
return Mockito.mock(JavaMailSenderImpl.class);
}
@Bean
public EMailVerificationService emailVerificationService() {
return new EMailVerificationServiceImpl();
}
@Bean
public TokenVerificationService tokenVerificationService() {
return new TokenVerificationServiceImpl();
}
@Bean
public TaxonomyService taxonomyService() {
return new TaxonomyServiceImpl();
}
@Bean
public CropService cropService() {
return new CropServiceImpl();
}
@Bean
public TeamService teamService() {
return new TeamServiceImpl();
}
@Bean
public GenesysLowlevelRepository genesysLowlevelRepository() {
return new GenesysLowlevelRepositoryCustomImpl();
}
@Bean
public AclService aclService() {
return new AclServiceImpl();
}
@Bean
public AsAdminAspect asAdminAspect() {
return new AsAdminAspect();
}
@Bean
public InstituteService instituteService() {
return new InstituteServiceImpl();
}
@Bean
public GenesysFilterService genesysFilterService() {
return new GenesysFilterServiceImpl();
}
@Bean
public MappingService mappingService(){
return new MappingServiceImpl();
}
@Bean
public MappingService mappingService() {
return new MappingServiceImpl();
}
@Bean
public GenesysService genesysService(){
return new GenesysServiceImpl();
}
@Bean
public GenesysService genesysService() {
return new GenesysServiceImpl();
}
@Bean
public TraitValueRepository traitValueRepository(){
return new TraitValueRepositoryImpl();
}
@Bean
public TraitValueRepository traitValueRepository() {
return new TraitValueRepositoryImpl();
}
@Bean
public OrganizationService organizationService(){
return new OrganizationServiceImpl();
}
@Bean
public OrganizationService organizationService() {
return new OrganizationServiceImpl();
}
@Bean
public TraitService traitService(){
return new TraitServiceImpl();
}
@Bean
public TraitService traitService() {
return new TraitServiceImpl();
}
@Bean
public GeoService geoService(){
return new GeoServiceImpl();
}
}
@Bean
public GeoService geoService() {
return new GeoServiceImpl();
}
}
@Autowired
public UserDetailsService userDetailsService;
@Autowired
public UserDetailsService userDetailsService;
@Autowired
public UserPersistence userPersistence;
@Autowired
public UserPersistence userPersistence;
@Autowired
public ContentSanitizer contentSanitizer;
@Autowired
public ContentSanitizer contentSanitizer;
@Autowired
public ActivityPostRepository postRepository;
@Autowired
public ActivityPostRepository postRepository;
@Autowired
public DescriptorService descriptorService;
@Autowired
public DescriptorService descriptorService;
@Autowired
public DescriptorRepository descriptorRepository;
@Autowired
public DescriptorRepository descriptorRepository;
@Autowired
public JavaMailSender mailSender;
@Autowired
public JavaMailSender mailSender;
@Autowired
public EMailService eMailService;
@Autowired
public EMailService eMailService;
@Autowired
public VerificationTokenRepository verificationTokenRepository;
@Autowired
public VerificationTokenRepository verificationTokenRepository;
@Autowired
public EMailVerificationService emailVerificationService;
@Autowired
public EMailVerificationService emailVerificationService;
@Autowired
public ContentService contentService;
@Autowired
public ContentService contentService;
@Autowired
public ArticleRepository articleRepository;
@Autowired
public ArticleRepository articleRepository;
@Autowired
public HtmlSanitizer htmlSanitizer;
@Autowired
public HtmlSanitizer htmlSanitizer;
@Autowired
public TaxonomyService taxonomyService;
@Autowired
public TaxonomyService taxonomyService;
@Autowired
public TokenVerificationService tokenVerificationService;
@Autowired
public TokenVerificationService tokenVerificationService;
@Autowired
public VerificationTokenRepository tokenRepository;
@Autowired
public VerificationTokenRepository tokenRepository;
@Autowired
public InstituteService instituteService;
@Autowired
public InstituteService instituteService;
@Autowired
public TeamRepository teamRepository;
@Autowired
public TeamRepository teamRepository;
@Autowired
public TeamService teamService;
@Autowired
public TeamService teamService;
@Autowired
public UserService userService;
@Autowired
public UserService userService;
@Autowired
public CropService cropService;
@Autowired
public CropService cropService;
@Autowired
public CropRepository cropRepository;
@Autowired
public CropRepository cropRepository;
@Autowired
public CropRuleRepository cropRuleRepository;
@Autowired
public CropRuleRepository cropRuleRepository;
@Autowired
public CropTaxonomyRepository cropTaxonomyRepository;
@Autowired
public CropTaxonomyRepository cropTaxonomyRepository;
@Autowired
public Taxonomy2Repository taxonomy2Repository;
@Autowired
public Taxonomy2Repository taxonomy2Repository;
@Autowired
public GenesysFilterService genesysFilterService;
@Autowired
public GenesysFilterService genesysFilterService;
@Autowired
public MappingService mappingService;
@Autowired
public MappingService mappingService;
}
......@@ -44,7 +44,7 @@ public class AuthUserDetailsServiceTest extends AbstractServicesTest {
assertTrue(userDetails != null);
assertTrue(userDetails.getPassword().equals(user.getPassword()));
userService.removeUser(user);
} catch (UserException e) {
org.junit.Assert.fail(e.getMessage());
}
......
......@@ -27,23 +27,23 @@ import static org.junit.Assert.assertTrue;
public class ContentSanitizerTest extends AbstractServicesTest {
private static final Log LOG = LogFactory.getLog(DescriptorServiceTest.class);
private static final Log LOG = LogFactory.getLog(DescriptorServiceTest.class);
@Test
public void sanitizeAllTest(){
LOG.info("Start test-method sanitizeAllTest");
@Test
public void sanitizeAllTest() {
LOG.info("Start test-method sanitizeAllTest");
String articleBody = "<script></script><h2><small>Genesys account</small><br />Verify your email address</h2><p>You can already use your Genesys account. We need to confirm your email account before granting you access to all Genesys features.</p><p><a href=\"{0}/profile/{1}/validate\" rel=\"nofollow\">Verify {2}</a></p><h2>Validation key: {3}</h2><p>If you didn&#39;t make this request, <a href=\"{0}/profile/{1}/cancel\" rel=\"nofollow\">click here to cancel</a>.</p><p>Thanks,<br />Genesys team</p>";
String expectedBody = "<h2><small>Genesys account</small><br />Verify your email address</h2><p>You can already use your Genesys account. We need to confirm your email account before granting you access to all Genesys features.</p><p><a href=\"{0}/profile/{1}/validate\" rel=\"nofollow\">Verify {2}</a></p><h2>Validation key: {3}</h2><p>If you didn&#39;t make this request, <a href=\"{0}/profile/{1}/cancel\" rel=\"nofollow\">click here to cancel</a>.</p><p>Thanks,<br />Genesys team</p>";
String articleBody = "<script></script><h2><small>Genesys account</small><br />Verify your email address</h2><p>You can already use your Genesys account. We need to confirm your email account before granting you access to all Genesys features.</p><p><a href=\"{0}/profile/{1}/validate\" rel=\"nofollow\">Verify {2}</a></p><h2>Validation key: {3}</h2><p>If you didn&#39;t make this request, <a href=\"{0}/profile/{1}/cancel\" rel=\"nofollow\">click here to cancel</a>.</p><p>Thanks,<br />Genesys team</p>";
String expectedBody = "<h2><small>Genesys account</small><br />Verify your email address</h2><p>You can already use your Genesys account. We need to confirm your email account before granting you access to all Genesys features.</p><p><a href=\"{0}/profile/{1}/validate\" rel=\"nofollow\">Verify {2}</a></p><h2>Validation key: {3}</h2><p>If you didn&#39;t make this request, <a href=\"{0}/profile/{1}/cancel\" rel=\"nofollow\">click here to cancel</a>.</p><p>Thanks,<br />Genesys team</p>";
contentService.createGlobalArticle("smtp.email-verification", Locale.ENGLISH, "Test title", articleBody);
contentSanitizer.sanitizeAll();
contentService.createGlobalArticle("smtp.email-verification", Locale.ENGLISH, "Test title", articleBody);
Article articleAfterSanitize = contentService.listArticles(new PageRequest(0, 10)).getContent().get(0);
assertTrue(!articleAfterSanitize.getBody().equals(articleBody));
assertTrue(articleAfterSanitize.getBody().equals(expectedBody));
contentSanitizer.sanitizeAll();
LOG.info("Test sanitizeAllTest passed!");
}
Article articleAfterSanitize = contentService.listArticles(new PageRequest(0, 10)).getContent().get(0);
assertTrue(!articleAfterSanitize.getBody().equals(articleBody));
assertTrue(articleAfterSanitize.getBody().equals(expectedBody));
LOG.info("Test sanitizeAllTest passed!");
}
}
......@@ -30,253 +30,253 @@ import static org.junit.Assert.*;
public class ContentServiceTest extends AbstractServicesTest {
private final Log LOG = LogFactory.getLog(ContentServiceTest.class);
private final Log LOG = LogFactory.getLog(ContentServiceTest.class);
@Before
public void setUp() {
//create activity post for test
contentService.createActivityPost("title of activity post", "body of activity post");
@Before
public void setUp() {
// create activity post for test
contentService.createActivityPost("title of activity post", "body of activity post");
//create article for test
List<Article> articleList = new ArrayList<>();
Article article = new Article();
article.setLang("en");
article.setSlug("smtp.email-verification");
article.setTitle("title of article");
article.setBody("<h3>body of article</h3");
article.setClassPk(contentService.ensureClassPK(Article.class));
articleList.add(article);
contentService.save(articleList);
// create article for test
List<Article> articleList = new ArrayList<>();
Article article = new Article();
article.setLang("en");
article.setSlug("smtp.email-verification");
article.setTitle("title of article");
article.setBody("<h3>body of article</h3");
article.setClassPk(contentService.ensureClassPK(Article.class));
articleList.add(article);
contentService.save(articleList);
}
}
@After
public void teardown() {
//delete activity post
postRepository.deleteAll();
@After
public void teardown() {
// delete activity post
postRepository.deleteAll();
//delete articles
articleRepository.deleteAll();
}
// delete articles
articleRepository.deleteAll();
}
@Test
public void getDefaultLocaleTest() {
LOG.info("Start test-method getDefaultLocaleTest");
@Test
public void getDefaultLocaleTest() {
LOG.info("Start test-method getDefaultLocaleTest");
assertNotNull(contentService.getDefaultLocale());
assertNotNull(contentService.getDefaultLocale());
LOG.info("Test getDefaultLocaleTest is passed!");
}
LOG.info("Test getDefaultLocaleTest is passed!");
}
@Test
public void lastNewsTest() {
LOG.info("Start test-method lastNewsTest");
@Test
public void lastNewsTest() {
LOG.info("Start test-method lastNewsTest");
List<ActivityPost> postList = contentService.lastNews();
List<ActivityPost> postList = contentService.lastNews();
assertTrue(postList.size() == 1);
assertTrue(postList.get(0).getTitle().equals("title of activity post"));
assertTrue(postList.get(0).getBody().equals("body of activity post"));
assertTrue(postList.size() == 1);
assertTrue(postList.get(0).getTitle().equals("title of activity post"));
assertTrue(postList.get(0).getBody().equals("body of activity post"));
LOG.info("Test lastNewsTest is passed!");
}
LOG.info("Test lastNewsTest is passed!");
}
@Test
public void listArticlesTest() {
LOG.info("Start test-method listArticlesTest");
@Test
public void listArticlesTest() {
LOG.info("Start test-method listArticlesTest");
List<Article> articleList = contentService.listArticles(new PageRequest(0, 6)).getContent();
assertNotNull("ArticleList must be not null", articleList);
assertTrue(!articleList.isEmpty());
List<Article> articleList = contentService.listArticles(new PageRequest(0, 6)).getContent();
assertNotNull("ArticleList must be not null", articleList);
assertTrue(!articleList.isEmpty());
LOG.info("Test listArticlesTest is passed!");
}
LOG.info("Test listArticlesTest is passed!");
}
@Test
public void listArticlesByLangTest() {
LOG.info("Start test-method listArticlesByLangTest");
@Test
public void listArticlesByLangTest() {
LOG.info("Start test-method listArticlesByLangTest");
List<Article> articleList = contentService.listArticlesByLang("ru", new PageRequest(0, 6)).getContent();
assertTrue(articleList.isEmpty());
List<Article> articleList = contentService.listArticlesByLang("ru", new PageRequest(0, 6)).getContent();
assertTrue(articleList.isEmpty());