<commit_before>/*
 * Copyright 2012-2014 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package pl.hycom.pip.messanger;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.List;

import org.junit.*;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;

import lombok.extern.log4j.Log4j2;
import ma.glasnost.orika.MapperFacade;
import pl.hycom.pip.messanger.repository.model.Keyword;
import pl.hycom.pip.messanger.repository.model.Product;
import pl.hycom.pip.messanger.service.KeywordService;
import pl.hycom.pip.messanger.service.ProductService;

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK)
@ActiveProfiles({ "dev", "testdb" })
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@Log4j2
public class ProductDTOServiceTest {

    @Autowired
    private MapperFacade orikaMapper;

    @Value("${messenger.recommendation.products-amount:3}")
    Integer expectedNumberOfProducts;
    @Autowired
    private ProductService productService;
    @Autowired
    private KeywordService keywordService;

    private Product product1;
    private Product product2;
    private Product product3;
    private Product product4;
    private Product product5;
    private Product product6;
    private Keyword keyword;
    private Keyword keyword1;
    private Keyword keyword2;
    private Keyword keyword3;
    private Keyword keyword4;

    @Before
    public void setUp() {
        product1 = new Product();
        product1.setName("name1");
        product1.setDescription("desc1");
        product1.setImageUrl("url1");

        product2 = new Product();
        product2.setName("name2");
        product2.setDescription("desc2");
        product2.setImageUrl("url2");

        product3 = new Product();
        product3.setName("name3");
        product3.setDescription("desc3");
        product3.setImageUrl("url3");

        product4 = new Product();
        product4.setName("name4");
        product4.setDescription("desc4");
        product4.setImageUrl("url4");

        product5 = new Product();
        product5.setName("name5");
        product5.setDescription("desc5");
        product5.setImageUrl("url5");

        product6 = new Product();
        product6.setName("name6");
        product6.setDescription("desc6");
        product6.setImageUrl("url6");

        keyword = new Keyword();
        keyword.setWord("test_keyword");

        keyword1 = new Keyword();
        keyword2 = new Keyword();
        keyword3 = new Keyword();
        keyword4 = new Keyword();

        keyword1.setWord("test1");
        keyword2.setWord("test2");
        keyword3.setWord("test3");
        keyword4.setWord("test4");
    }

    private void addKeywordsToProduct1() {
        LinkedHashSet<Keyword> keywords1 = new LinkedHashSet<>();
        keywords1.add(keyword1);
        keywords1.add(keyword2);
        product1.setKeywords(keywords1);
    }

    private void addKeywordsToDB() {
        keywordService.addKeyword(keyword1);
        keywordService.addKeyword(keyword2);
        keywordService.addKeyword(keyword3);
        keywordService.addKeyword(keyword4);
    }

    private void addKeywordsToProducts() {
        addKeywordsToDB();

        product1.addKeyword(keyword1);
        product1.addKeyword(keyword2);
        product1.addKeyword(keyword3);
        product2.addKeyword(keyword2);
        product3.addKeyword(keyword3);
    }

    @Ignore
    @Test
    public void addProductWithKeywordsTest() {
        log.info("Test of addProduct method from ProductService class");

        // preparation
        long productsCount = productService.count();
        addKeywordsToProduct1();

        // action
        productService.addProduct(product1);

        // assertion<commit_msg>test fixing<commit_after>/*
 * Copyright 2012-2014 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package pl.hycom.pip.messanger;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.List;

import org.junit.*;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;

import lombok.extern.log4j.Log4j2;
import ma.glasnost.orika.MapperFacade;
import pl.hycom.pip.messanger.repository.model.Keyword;
import pl.hycom.pip.messanger.repository.model.Product;
import pl.hycom.pip.messanger.service.KeywordService;
import pl.hycom.pip.messanger.service.ProductService;

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK)
@ActiveProfiles({ "dev", "testdb" })
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@Log4j2
public class ProductDTOServiceTest {

    @Autowired
    private MapperFacade orikaMapper;

    @Value("${messenger.recommendation.products-amount:3}")
    Integer expectedNumberOfProducts;
    @Autowired
    private ProductService productService;
    @Autowired
    private KeywordService keywordService;

    private Product product1;
    private Product product2;
    private Product product3;
    private Product product4;
    private Product product5;
    private Product product6;
    private Keyword keyword;
    private Keyword keyword1;
    private Keyword keyword2;
    private Keyword keyword3;
    private Keyword keyword4;

    @Before
    public void setUp() {
        product1 = new Product();
        product1.setName("name1");
        product1.setDescription("desc1");
        product1.setImageUrl("url1");

        product2 = new Product();
        product2.setName("name2");
        product2.setDescription("desc2");
        product2.setImageUrl("url2");

        product3 = new Product();
        product3.setName("name3");
        product3.setDescription("desc3");
        product3.setImageUrl("url3");

        product4 = new Product();
        product4.setName("name4");
        product4.setDescription("desc4");
        product4.setImageUrl("url4");

        product5 = new Product();
        product5.setName("name5");
        product5.setDescription("desc5");
        product5.setImageUrl("url5");

        product6 = new Product();
        product6.setName("name6");
        product6.setDescription("desc6");
        product6.setImageUrl("url6");

        keyword = new Keyword();
        keyword.setWord("test_keyword");

        keyword1 = new Keyword();
        keyword2 = new Keyword();
        keyword3 = new Keyword();
        keyword4 = new Keyword();

        keyword1.setWord("test1");
        keyword2.setWord("test2");
        keyword3.setWord("test3");
        keyword4.setWord("test4");
    }

    private void addKeywordsToProduct1() {
        LinkedHashSet<Keyword> keywords1 = new LinkedHashSet<>();
        keywords1.add(keyword1);
        keywords1.add(keyword2);
        product1.setKeywords(keywords1);
    }

    private void addKeywordsToDB() {
        keywordService.addKeyword(keyword1);
        keywordService.addKeyword(keyword2);
        keywordService.addKeyword(keyword3);
        keywordService.addKeyword(keyword4);
    }

    private void addKeywordsToProducts() {
        addKeywordsToDB();

        product1.addKeyword(keyword1);
        product1.addKeyword(keyword2);
        product1.addKeyword(keyword3);
        product2.addKeyword(keyword2);
        product3.addKeyword(keyword3);
    }

    
    @Test
    public void addProductWithKeywordsTest() {
        log.info("Test of addProduct method from ProductService class");

        // preparation
        long productsCount = productService.count();
        addKeywordsToProduct1();

        // action
        productService.addProduct(product1);

        // assertion
{'fraction_non_alphanumeric': 0.10222952840850714, 'fraction_numerical': 0.02198705435117641, 'mean_word_length': 3.4285714285714284, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5759861', 'n_tokens_mistral': 2740, 'n_tokens_neox': 2699, 'n_words': 601}