luchob / softuni-spring-may-2024

Our common projects
15 stars 1 forks source link

Проблем с @Bean dataSourceInitializer при стартиране на интеграционни тестове #75

Closed BogoevaPetya closed 3 months ago

BogoevaPetya commented 3 months ago

Здрасти, Лъчо,

при стартиране на интеграционните тестове получавам тази грешка: image

Знам, че е свързана с настройката, която съм направила за стартиране нa data.sql файла, но не мога да я оправя.

https://github.com/BogoevaPetya/DeliciousRecipes

luchob commented 3 months ago

🎉Благодаря, че сте тук и се интересувате от Spring Framework!🎉

🌴 За съжаление обаче, аз не съм тук (това е автоматичен отговор) и ще бъда много ограничено достъпен чак до 10-ти август.
🥲Така че, не обещавам да ви отговоря или да ви пиша.
🥹Извинете ме!

:rocket: Успешно и приятно програмиране! :rocket:

BogoevaPetya commented 3 months ago

И още нещо, закоментирах dataSourceInitializer бийнa, за да мога поне да си подкарам тестовете, но получавам друга грешка пак още при инициализирането на контекста: image

luchob commented 3 months ago

Здрасти, Петя!

Не знам дали умишлено или по-скоро не, тестовото ти application.yaml се казва application-test.yaml. Това би имало смисъл ако ползваш профили, но ти никъде не си казвала такова нещо. Затова по-скоро би трябвало да се казва application.yaml защото иначе Spring няма да го забележи.

Вторият проблем е, че както казахме HSQLDB и MySQL са различни бази и има някои особености в SQL синтаксиса. Например, HSQLDB не обича символът ` пък и двойните кавички го смущават. Може би да пробваш с:

INSERT INTO roles VALUES (1, 'USER');
INSERT INTO roles VALUES (2, 'ADMINISTRATOR');

INSERT INTO categories VALUES (1, 'SALAD'), (2, 'SOUP'), (3, 'MAIN_DISH'), (4, 'DESSERT');

INSERT INTO users (id,email,password,username) VALUES (1,'niki@abv.bg','c5c8f6f54c3c1123979cb7509616ca8f3ecedc305321df562b2ff59fecd49a311ce748141f566b9c','nickichka');

INSERT INTO users_roles (user_id, role_id) VALUES (1, 2);

INSERT INTO recipes (image, ingredients, instructions, likes, name, time_for_cooking, added_by_id, category_id) VALUES
('/images/watermelon-salad.webp', '4 cups arugula, 3 cups watermelon, 1/4 cup mint leaves, 1/4 cup feta cheese, 2 cups chicken, balsamic vinegar, balsamic vinegar', 'Chop the watermelon into cubes, and shred the chicken, as needed. Finely slice the mint, and crumble the feta. Spread the arugula over a serving platter. Top the arugula with chicken, watermelon, feta and mint. Drizzle the salad with balsamic vinegar, and olive oil.', '0', 'Watermelon, Feta, and Mint Salad', '10', '1', '1'),
('/images/macaroni-salad.webp', '3/4 tsp. salt, 8 oz. elbow macaroni, 1/2 cup mayonnaise, 1/4 cup sour cream, 1 tsp. lemon zest, 1 Tbsp. lemon juice, 1 stalk celery, 2 green onions, 1/4 cup fresh flat-leaf parsley, 1/4 cup sweet relish, 4 oz. diced pimentos, 1/2 tsp. black pepper', 'Bring a medium pot of salted water to a boil over high heat. Cook macaroni according to package directions until barely tender (al dente), about 9 minutes. Drain macaroni, then rinse with cold water to stop the cooking, and drain. Let macaroni stand in the colander about 10 minutes to dry. Meanwhile, in a large bowl, stir together mayonnaise, sour cream, lemon zest, and lemon juice. Finely chop celery, and chop green onions. Add celery and green onions to bowl with mayonnaise mixture along with parsley, sweet relish, about three-quarters of the pimentos, 3/4 tsp. salt, and the pepper, and stir to blend. Chill if macaroni isn’t ready yet. Add cooked macaroni, stirring to combine. Taste and add more salt and pepper if you like. Sprinkle salad with a little more parsley and with the reserved pimentos and serve, or chill it, covered, up to 3 days. (Salad will absorb some of the dressing as it stands.)', '0', 'Macaroni Salad', '25', '1', '1'),
('/images/spinach-salad.webp', '1/2 cup pecans, 3 Tbsp. extra virgin olive oil, 1 1/2 Tbsp. apple cider vinegar, 1 Tbsp. honey, 1 tsp. Dijon mustard, 1/4 tsp. salt, 1/4 tsp. black pepper, 4 oz. baby spinach leaves, 1/2 cup dried cranberries, salt, black pepper', 'Preheat the oven to 350°F. Spread the nuts evenly in a pie pan. Toast the nuts on middle rack of oven until fragrant and a shade darker, 8-10 minutes. Check to see that nuts are done. Remove from oven or add time as needed. Let nuts cool for about 5 minutes. Combine the oil, vinegar, honey, mustard, salt, and pepper in a small bowl. Combine the spinach, cranberries, pecans, and as much dressing as desired in a large bowl. Add more salt and pepper to taste and serve.', '0', 'Spinach Salad with Toasted Pecans', '20', '1', '1'),
('/images/cucumber-salad.webp', '2 English cucumbers, 3 Tbsp. rice vinegar, 1 Tbsp. fish sauce, 2 Tbsp. sugar, 1/4 tsp. chili flakes, 1 Tbsp. sesame seeds, 1 tsp. salt, 1/2 tsp. pepper, 2 Tbsp. soy sauce', 'Combine all of the ingredients in a large mixing bowl. Toss well to combine, then cover with plastic wrap and refrigerate. Serve with Thai-Style Oven Baked Ribs.', '0', 'Sweet and Sour Smashed Cucumber Salad', '10', '1', '1'),
('/images/ginger-salad.webp', '1 lb. boneless pork loin, 1/2 cup orange juice, 2 Tbsp. ginger, 2 cups melon balls, 1 papaya, 2 Tbsp. orange liqueur, 6 cups mixed greens, 1/2 cup peach yogurt', 'In medium saucepan combine orange juice and ginger; bring to a simmer and add pork cubes. Simmer for about 5 minutes, until pork is cooked. Remove pork and remaining liquid to bowl, refrigerate uncovered to cool slightly, about 5-10 minutes. In medium bowl gently toss together melon, papaya, Grand Marnier, pork cubes and cooking liquid. On each of four plates place 1 1/2 cups salad greens. Serve equal portions pork-melon mixture atop greens, topped with 2 tablespoons yogurt.', '0', 'Gingered Pork and Melon Salad', '20', '1', '1');

На пръв поглед ми изглежда, че ще работи и под двете DB-та, но оставям на теб да тестваш.

Поздрави, Л.

BogoevaPetya commented 3 months ago

Всъщност умишлено съм кръстила файла така. Това с ролите не ми е много ясно, реално тази настройка достатъчна ли е :

image

image

И съм сложила анотация на тестовете image

А иначе не ми работи нищо в момента, не мога да стартирам програмата, защото като стартирам приложението идва проблема с dataSourceInitializer-a, както от първия скрийншот. Как да го оправя?

BogoevaPetya commented 3 months ago

И трябва ли да имам още един data.sql файл за тестовата среда, отделно от този, който имам до момента, защото като променя синтаксиса в data.sql файла и или основното приложение не тръгва или тестовата среда

luchob commented 3 months ago

Здрасти!

Според мен най-лесно ще се справиш ако:

  1. Преименуваш application-test.yml на application.yml.
  2. Предвид малките разлики в синтаксиса на HSQLDB/MySQL сложиш следното data.sql (което ще минава и на двете ДБ-та):
    
    INSERT INTO roles VALUES (1, 'USER');
    INSERT INTO roles VALUES (2, 'ADMINISTRATOR');

INSERT INTO categories VALUES (1, 'SALAD'), (2, 'SOUP'), (3, 'MAIN_DISH'), (4, 'DESSERT');

INSERT INTO users (id,email,password,username) VALUES (1,'niki@abv.bg','c5c8f6f54c3c1123979cb7509616ca8f3ecedc305321df562b2ff59fecd49a311ce748141f566b9c','nickichka');

INSERT INTO users_roles (user_id, role_id) VALUES (1, 2);

INSERT INTO recipes (image, ingredients, instructions, likes, name, time_for_cooking, added_by_id, category_id) VALUES ('/images/watermelon-salad.webp', '4 cups arugula, 3 cups watermelon, 1/4 cup mint leaves, 1/4 cup feta cheese, 2 cups chicken, balsamic vinegar, balsamic vinegar', 'Chop the watermelon into cubes, and shred the chicken, as needed. Finely slice the mint, and crumble the feta. Spread the arugula over a serving platter. Top the arugula with chicken, watermelon, feta and mint. Drizzle the salad with balsamic vinegar, and olive oil.', '0', 'Watermelon, Feta, and Mint Salad', '10', '1', '1'), ('/images/macaroni-salad.webp', '3/4 tsp. salt, 8 oz. elbow macaroni, 1/2 cup mayonnaise, 1/4 cup sour cream, 1 tsp. lemon zest, 1 Tbsp. lemon juice, 1 stalk celery, 2 green onions, 1/4 cup fresh flat-leaf parsley, 1/4 cup sweet relish, 4 oz. diced pimentos, 1/2 tsp. black pepper', 'Bring a medium pot of salted water to a boil over high heat. Cook macaroni according to package directions until barely tender (al dente), about 9 minutes. Drain macaroni, then rinse with cold water to stop the cooking, and drain. Let macaroni stand in the colander about 10 minutes to dry. Meanwhile, in a large bowl, stir together mayonnaise, sour cream, lemon zest, and lemon juice. Finely chop celery, and chop green onions. Add celery and green onions to bowl with mayonnaise mixture along with parsley, sweet relish, about three-quarters of the pimentos, 3/4 tsp. salt, and the pepper, and stir to blend. Chill if macaroni isn’t ready yet. Add cooked macaroni, stirring to combine. Taste and add more salt and pepper if you like. Sprinkle salad with a little more parsley and with the reserved pimentos and serve, or chill it, covered, up to 3 days. (Salad will absorb some of the dressing as it stands.)', '0', 'Macaroni Salad', '25', '1', '1'), ('/images/spinach-salad.webp', '1/2 cup pecans, 3 Tbsp. extra virgin olive oil, 1 1/2 Tbsp. apple cider vinegar, 1 Tbsp. honey, 1 tsp. Dijon mustard, 1/4 tsp. salt, 1/4 tsp. black pepper, 4 oz. baby spinach leaves, 1/2 cup dried cranberries, salt, black pepper', 'Preheat the oven to 350°F. Spread the nuts evenly in a pie pan. Toast the nuts on middle rack of oven until fragrant and a shade darker, 8-10 minutes. Check to see that nuts are done. Remove from oven or add time as needed. Let nuts cool for about 5 minutes. Combine the oil, vinegar, honey, mustard, salt, and pepper in a small bowl. Combine the spinach, cranberries, pecans, and as much dressing as desired in a large bowl. Add more salt and pepper to taste and serve.', '0', 'Spinach Salad with Toasted Pecans', '20', '1', '1'), ('/images/cucumber-salad.webp', '2 English cucumbers, 3 Tbsp. rice vinegar, 1 Tbsp. fish sauce, 2 Tbsp. sugar, 1/4 tsp. chili flakes, 1 Tbsp. sesame seeds, 1 tsp. salt, 1/2 tsp. pepper, 2 Tbsp. soy sauce', 'Combine all of the ingredients in a large mixing bowl. Toss well to combine, then cover with plastic wrap and refrigerate. Serve with Thai-Style Oven Baked Ribs.', '0', 'Sweet and Sour Smashed Cucumber Salad', '10', '1', '1'), ('/images/ginger-salad.webp', '1 lb. boneless pork loin, 1/2 cup orange juice, 2 Tbsp. ginger, 2 cups melon balls, 1 papaya, 2 Tbsp. orange liqueur, 6 cups mixed greens, 1/2 cup peach yogurt', 'In medium saucepan combine orange juice and ginger; bring to a simmer and add pork cubes. Simmer for about 5 minutes, until pork is cooked. Remove pork and remaining liquid to bowl, refrigerate uncovered to cool slightly, about 5-10 minutes. In medium bowl gently toss together melon, papaya, Grand Marnier, pork cubes and cooking liquid. On each of four plates place 1 1/2 cups salad greens. Serve equal portions pork-melon mixture atop greens, topped with 2 tablespoons yogurt.', '0', 'Gingered Pork and Melon Salad', '20', '1', '1');


3. Махнеш "active-profiles" отвсякъде.

<img width="355" alt="Screenshot 2024-08-02 at 18 42 21" src="https://github.com/user-attachments/assets/30dd350f-f97a-48d3-b373-e0b3ae2692eb">
<img width="906" alt="Screenshot 2024-08-02 at 18 42 47" src="https://github.com/user-attachments/assets/9a651f30-a423-4ef8-8796-7f541215145a">

За жалост в момента не мога да вляза в повече детайли.

Поздрави,
Л.