From 995e104e8691ba1485e47d06f65e89bda9bb54b8 Mon Sep 17 00:00:00 2001 From: MaxKarme <91691525+MaxKarme@users.noreply.github.com> Date: Sat, 25 Mar 2023 18:30:02 +0400 Subject: [PATCH] third lab --- .gitignore | 1 + build.gradle | 6 ++ .../java/ru/ip/labs/labs/LabsApplication.java | 5 -- .../calculator/controller/CalcController.java | 7 ++ .../calculator/domain/CalculatorArray.java | 2 +- .../calculator/service/CalculatorService.java | 1 + .../labs/films/controller/FilmController.java | 56 ++++++++++++ .../films/controller/GenreController.java | 46 ++++++++++ .../ru/ip/labs/labs/films/models/Actor.java | 56 ++++++++++++ .../ru/ip/labs/labs/films/models/Film.java | 56 ++++++++++++ .../ru/ip/labs/labs/films/models/Genre.java | 39 +++++++++ .../labs/labs/films/service/ActorService.java | 85 +++++++++++++++++++ .../labs/labs/films/service/FilmsService.java | 85 +++++++++++++++++++ .../labs/labs/films/service/GenreService.java | 69 +++++++++++++++ src/main/resources/application.properties | 12 ++- .../java/ru/ip/labs/labs/JpaActorsTest.java | 4 + .../java/ru/ip/labs/labs/JpaFilmsTest.java | 61 +++++++++++++ .../java/ru/ip/labs/labs/JpaGenresTest.java | 4 + .../ru/ip/labs/labs/LabsApplicationTests.java | 5 -- 19 files changed, 588 insertions(+), 12 deletions(-) create mode 100644 src/main/java/ru/ip/labs/labs/films/controller/FilmController.java create mode 100644 src/main/java/ru/ip/labs/labs/films/controller/GenreController.java create mode 100644 src/main/java/ru/ip/labs/labs/films/models/Actor.java create mode 100644 src/main/java/ru/ip/labs/labs/films/models/Film.java create mode 100644 src/main/java/ru/ip/labs/labs/films/models/Genre.java create mode 100644 src/main/java/ru/ip/labs/labs/films/service/ActorService.java create mode 100644 src/main/java/ru/ip/labs/labs/films/service/FilmsService.java create mode 100644 src/main/java/ru/ip/labs/labs/films/service/GenreService.java create mode 100644 src/test/java/ru/ip/labs/labs/JpaActorsTest.java create mode 100644 src/test/java/ru/ip/labs/labs/JpaFilmsTest.java create mode 100644 src/test/java/ru/ip/labs/labs/JpaGenresTest.java diff --git a/.gitignore b/.gitignore index c2065bc..accda65 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ build/ .apt_generated .classpath .factorypath + .project .settings .springBeans diff --git a/build.gradle b/build.gradle index 499d691..eedb56e 100644 --- a/build.gradle +++ b/build.gradle @@ -14,6 +14,12 @@ repositories { dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' + + implementation 'org.springframework.boot:spring-boot-starter-data-jpa' + implementation 'com.h2database:h2:2.1.210' + + implementation group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.6.5' + testImplementation 'org.springframework.boot:spring-boot-starter-test' } diff --git a/src/main/java/ru/ip/labs/labs/LabsApplication.java b/src/main/java/ru/ip/labs/labs/LabsApplication.java index 4605fb7..345aaae 100644 --- a/src/main/java/ru/ip/labs/labs/LabsApplication.java +++ b/src/main/java/ru/ip/labs/labs/LabsApplication.java @@ -2,11 +2,6 @@ package ru.ip.labs.labs; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -import javax.servlet.http.HttpServletResponse; @SpringBootApplication public class LabsApplication { diff --git a/src/main/java/ru/ip/labs/labs/calculator/controller/CalcController.java b/src/main/java/ru/ip/labs/labs/calculator/controller/CalcController.java index 0fc64e6..cbf676b 100644 --- a/src/main/java/ru/ip/labs/labs/calculator/controller/CalcController.java +++ b/src/main/java/ru/ip/labs/labs/calculator/controller/CalcController.java @@ -1,11 +1,13 @@ package ru.ip.labs.labs.calculator.controller; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import ru.ip.labs.labs.calculator.service.CalculatorService; @RestController +@RequestMapping("/test") public class CalcController { private final CalculatorService calculatorService; @@ -13,6 +15,11 @@ public class CalcController { this.calculatorService = calculatorService; } + @GetMapping("/hello") + public String hello() { + return "Hi man"; + } + @GetMapping("/sumInt") public int sumInt(@RequestParam int x, @RequestParam int y) { return calculatorService.getSum(x, y, "int"); diff --git a/src/main/java/ru/ip/labs/labs/calculator/domain/CalculatorArray.java b/src/main/java/ru/ip/labs/labs/calculator/domain/CalculatorArray.java index 2dd73b5..2b67c6b 100644 --- a/src/main/java/ru/ip/labs/labs/calculator/domain/CalculatorArray.java +++ b/src/main/java/ru/ip/labs/labs/calculator/domain/CalculatorArray.java @@ -2,7 +2,7 @@ package ru.ip.labs.labs.calculator.domain; import org.springframework.stereotype.Component; -@Component(value = "array") +@Component(value = "testDatabase") public class CalculatorArray implements Calculator { @Override public String sum(String x, int y) { diff --git a/src/main/java/ru/ip/labs/labs/calculator/service/CalculatorService.java b/src/main/java/ru/ip/labs/labs/calculator/service/CalculatorService.java index cfbbf8f..683054a 100644 --- a/src/main/java/ru/ip/labs/labs/calculator/service/CalculatorService.java +++ b/src/main/java/ru/ip/labs/labs/calculator/service/CalculatorService.java @@ -18,6 +18,7 @@ public class CalculatorService { } public T getDiff(T x, int y, String opType) { + Calculator calc = (Calculator)_applicationContext.getBean(opType); return calc.diff(x, y); } diff --git a/src/main/java/ru/ip/labs/labs/films/controller/FilmController.java b/src/main/java/ru/ip/labs/labs/films/controller/FilmController.java new file mode 100644 index 0000000..2525694 --- /dev/null +++ b/src/main/java/ru/ip/labs/labs/films/controller/FilmController.java @@ -0,0 +1,56 @@ +package ru.ip.labs.labs.films.controller; + +import org.springframework.web.bind.annotation.*; +import ru.ip.labs.labs.films.models.Film; +import ru.ip.labs.labs.films.service.FilmsService; + +import java.util.Iterator; +import java.util.List; + +@RestController +@RequestMapping("/film") +public class FilmController { + private final FilmsService filmService; + + + public FilmController(FilmsService filmService) { + this.filmService = filmService; + } + + @GetMapping("/test") + public String test() { + return "Test request"; + } + + + @GetMapping("/{id}") + public Film getFilm(@PathVariable Long id) { + return filmService.findFilm(id); + } + + @GetMapping("/") + public List getFilms() { + return filmService.findAllFilms(); + } + + @PostMapping("/") + public Film createFilm(@RequestParam String name) { + return filmService.addFilm(name); + } + + @PatchMapping("/{id}") + public Film updateFilm(@PathVariable Long id, + @RequestParam("firstName") String name) { + return filmService.updateFilm(id, name); + } + + @PatchMapping("/add_genre/{id}") + public Film addGenre(@PathVariable Long id, @RequestParam Long genre_id) { + return filmService.addGenre(id, genre_id); + } + + @DeleteMapping("/{id}") + public Film deleteFilm(@PathVariable Long id) { + return filmService.deleteFilm(id); + } +} diff --git a/src/main/java/ru/ip/labs/labs/films/controller/GenreController.java b/src/main/java/ru/ip/labs/labs/films/controller/GenreController.java new file mode 100644 index 0000000..bb371f1 --- /dev/null +++ b/src/main/java/ru/ip/labs/labs/films/controller/GenreController.java @@ -0,0 +1,46 @@ +package ru.ip.labs.labs.films.controller; + +import org.springframework.web.bind.annotation.*; +import ru.ip.labs.labs.films.models.Film; +import ru.ip.labs.labs.films.models.Genre; +import ru.ip.labs.labs.films.service.FilmsService; +import ru.ip.labs.labs.films.service.GenreService; + +import java.util.List; + +@RestController +@RequestMapping("/genre") +public class GenreController { + private final GenreService genreService; + + + public GenreController(GenreService genreService) { + this.genreService = genreService; + } + + @GetMapping("/{id}") + public Genre getGenre(@PathVariable Long id) { + return genreService.findGenre(id); + } + + @GetMapping("/") + public List getGenres() { + return genreService.findAllFilms(); + } + + @PostMapping("/") + public Genre createGenre(@RequestParam("name") String name) { + return genreService.addGenre(name); + } + + @PatchMapping("/{id}") + public Genre updateGenre(@PathVariable Long id, + @RequestParam("name") String name) { + return genreService.updateGenre(id, name); + } + + @DeleteMapping("/{id}") + public Genre deleteGenre(@PathVariable Long id) { + return genreService.deleteGenre(id); + } +} diff --git a/src/main/java/ru/ip/labs/labs/films/models/Actor.java b/src/main/java/ru/ip/labs/labs/films/models/Actor.java new file mode 100644 index 0000000..e28f066 --- /dev/null +++ b/src/main/java/ru/ip/labs/labs/films/models/Actor.java @@ -0,0 +1,56 @@ +package ru.ip.labs.labs.films.models; +import javax.persistence.*; +import java.util.List; + +@Entity +public class Actor { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + private String name; + private String surname; + + @ManyToMany(fetch = FetchType.EAGER) + @JoinTable(name="actors_films", + joinColumns = @JoinColumn(name="actor_id"), + inverseJoinColumns = @JoinColumn(name="film_id") + ) + private List films; + + public Actor() {} + + public Actor(String name) { + this.name = name; + } + + public Long getId() { + return id; + } + + public String getSurname() { + return surname; + } + + public void setSurname(String surname) { + this.surname = surname; + } + + public void setName(String name) { + this.name = name; + } + + public void addFilm(Film f) { + films.add(f); + } + + @Override + public String toString() { + String res = "\nFilm{" + + "id: " + id + "," + + "name: " + name + "," + + "surname: " + name + "," + + "films:" + (films == null ? "[]" : films.toString()) + "}" + ; + return res; + } +} diff --git a/src/main/java/ru/ip/labs/labs/films/models/Film.java b/src/main/java/ru/ip/labs/labs/films/models/Film.java new file mode 100644 index 0000000..2ddf4a9 --- /dev/null +++ b/src/main/java/ru/ip/labs/labs/films/models/Film.java @@ -0,0 +1,56 @@ +package ru.ip.labs.labs.films.models; +import javax.persistence.*; +import java.util.Iterator; +import java.util.List; + +@Entity +public class Film { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + private String name; + + @ManyToMany(fetch = FetchType.EAGER) + @JoinTable(name="films_genres", + joinColumns = @JoinColumn(name="film_id"), + inverseJoinColumns = @JoinColumn(name="genre_id") + ) + private List genres; + + public Film() {} + + public Film(String name) { + this.name = name; + } + + public Long getId() { + return id; + } + + public void setName(String name) { + this.name = name; + } + + public void addGenre(Genre g) { + genres.add(g); + } + + @Override + public String toString() { + String res = "\nFilm{" + + "id: " + id + "," + + "name: " + name + "," + + "genres:" + (genres == null ? "[]" : genres.toString()) + "}" + ; + + /* + Iterator iter = genres.iterator(); + while(iter.hasNext()) { + Genre curr = iter.next(); + res += "{ id: " + curr.getId() + ", name: " + curr.getName() + (iter.hasNext() ? "}, " : "}"); + } + + res += "]\n}";*/ + return res; + } +} diff --git a/src/main/java/ru/ip/labs/labs/films/models/Genre.java b/src/main/java/ru/ip/labs/labs/films/models/Genre.java new file mode 100644 index 0000000..8e4dd75 --- /dev/null +++ b/src/main/java/ru/ip/labs/labs/films/models/Genre.java @@ -0,0 +1,39 @@ +package ru.ip.labs.labs.films.models; +import javax.persistence.*; +import java.util.List; + +@Entity +public class Genre { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + private String name; + + @ManyToMany(fetch = FetchType.EAGER, mappedBy = "genres") + private List films; + + public Genre() {} + public Genre(String name) { + this.name = name; + } + + public Long getId() { + return id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public String toString() { + return "Genre{" + + "id=" + id + + ", name='" + name + '\'' + + '}'; + } +} diff --git a/src/main/java/ru/ip/labs/labs/films/service/ActorService.java b/src/main/java/ru/ip/labs/labs/films/service/ActorService.java new file mode 100644 index 0000000..d420ded --- /dev/null +++ b/src/main/java/ru/ip/labs/labs/films/service/ActorService.java @@ -0,0 +1,85 @@ +package ru.ip.labs.labs.films.service; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.StringUtils; +import ru.ip.labs.labs.films.models.Actor; +import ru.ip.labs.labs.films.models.Film; + +import javax.persistence.EntityManager; +import javax.persistence.EntityNotFoundException; +import javax.persistence.PersistenceContext; +import java.util.List; + +@Service +public class ActorService { + + @PersistenceContext + private EntityManager em; + + @Transactional + public Actor addActor(String name, String surname) { + if (!StringUtils.hasText(name)) { + throw new IllegalArgumentException("Student name is null or empty"); + } + + Actor actor = new Actor(name); + + em.persist(actor); + return em.find(Actor.class, actor.getId()); + } + + @Transactional + public Actor addFilm(Long actorId, Long filmId) { + final Actor actor = em.find(Actor.class, actorId); + if (actor == null) { + throw new EntityNotFoundException(String.format("Actor with id [%s] is not found", actorId)); + } + + final Film film = em.find(Film.class, filmId); + if (film == null) { + throw new EntityNotFoundException(String.format("Film with id [%s] is not found", filmId)); + } + + actor.addFilm(film); + return em.merge(actor); + } + + @Transactional(readOnly = true) + public Actor findActor(Long id) { + final Actor actor = em.find(Actor.class, id); + if (actor == null) { + throw new EntityNotFoundException(String.format("Actor with id [%s] is not found", id)); + } + return actor; + } + + + @Transactional(readOnly = true) + public List findAllActors() { + return em.createQuery("select f from Actor f", Actor.class) + .getResultList(); + } + + @Transactional + public Actor updateActor(Long id, String name) { + if (!StringUtils.hasText(name)) { + throw new IllegalArgumentException("Actor name is null or empty"); + } + final Actor currentActor = findActor(id); + currentActor.setName(name); + return em.merge(currentActor); + } + + @Transactional + public Actor deleteActor(Long id) { + final Actor currentActor = findActor(id); + em.remove(currentActor); + return currentActor; + } + + @Transactional + public void deleteAllActors() { + em.createQuery("delete from Actor").executeUpdate(); + } +} diff --git a/src/main/java/ru/ip/labs/labs/films/service/FilmsService.java b/src/main/java/ru/ip/labs/labs/films/service/FilmsService.java new file mode 100644 index 0000000..4b75781 --- /dev/null +++ b/src/main/java/ru/ip/labs/labs/films/service/FilmsService.java @@ -0,0 +1,85 @@ +package ru.ip.labs.labs.films.service; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.StringUtils; +import ru.ip.labs.labs.films.models.Film; +import ru.ip.labs.labs.films.models.Genre; + +import javax.persistence.EntityManager; +import javax.persistence.EntityNotFoundException; +import javax.persistence.PersistenceContext; +import java.util.List; + +@Service +public class FilmsService { + + @PersistenceContext + private EntityManager em; + + @Transactional + public Film addFilm(String name) { + if (!StringUtils.hasText(name)) { + throw new IllegalArgumentException("Student name is null or empty"); + } + + Film film = new Film(name); + + em.persist(film); + return em.find(Film.class, film.getId()); + } + + @Transactional + public Film addGenre(Long filmId, Long genreId) { + final Film film = em.find(Film.class, filmId); + if (film == null) { + throw new EntityNotFoundException(String.format("Film with id [%s] is not found", filmId)); + } + + final Genre genre = em.find(Genre.class, genreId); + if (genre == null) { + throw new EntityNotFoundException(String.format("Genre with id [%s] is not found", genreId)); + } + + film.addGenre(genre); + return em.merge(film); + } + + @Transactional(readOnly = true) + public Film findFilm(Long id) { + final Film film = em.find(Film.class, id); + if (film == null) { + throw new EntityNotFoundException(String.format("Film with id [%s] is not found", id)); + } + return film; + } + + + @Transactional(readOnly = true) + public List findAllFilms() { + return em.createQuery("select f from Film f", Film.class) + .getResultList(); + } + + @Transactional + public Film updateFilm(Long id, String name) { + if (!StringUtils.hasText(name)) { + throw new IllegalArgumentException("Film name is null or empty"); + } + final Film currentFilm = findFilm(id); + currentFilm.setName(name); + return em.merge(currentFilm); + } + + @Transactional + public Film deleteFilm(Long id) { + final Film currentFilm = findFilm(id); + em.remove(currentFilm); + return currentFilm; + } + + @Transactional + public void deleteAllFilms() { + em.createQuery("delete from Film").executeUpdate(); + } +} diff --git a/src/main/java/ru/ip/labs/labs/films/service/GenreService.java b/src/main/java/ru/ip/labs/labs/films/service/GenreService.java new file mode 100644 index 0000000..c520984 --- /dev/null +++ b/src/main/java/ru/ip/labs/labs/films/service/GenreService.java @@ -0,0 +1,69 @@ +package ru.ip.labs.labs.films.service; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.StringUtils; +import ru.ip.labs.labs.films.models.Film; +import ru.ip.labs.labs.films.models.Genre; + +import javax.persistence.EntityManager; +import javax.persistence.EntityNotFoundException; +import javax.persistence.PersistenceContext; +import java.util.List; + +@Service +public class GenreService { + + @PersistenceContext + private EntityManager em; + + @Transactional + public Genre addGenre(String name) { + if (!StringUtils.hasText(name)) { + throw new IllegalArgumentException("Genre name is null or empty"); + } + + Genre genre = new Genre(name); + + em.persist(genre); + return em.find(Genre.class, genre.getId()); + } + + @Transactional(readOnly = true) + public Genre findGenre(Long id) { + final Genre genre = em.find(Genre.class, id); + if (genre == null) { + throw new EntityNotFoundException(String.format("Genre with id [%s] is not found", id)); + } + return genre; + } + + + @Transactional(readOnly = true) + public List findAllFilms() { + return em.createQuery("select g from Genre g", Genre.class) + .getResultList(); + } + + @Transactional + public Genre updateGenre(Long id, String name) { + if (!StringUtils.hasText(name)) { + throw new IllegalArgumentException("Film name is null or empty"); + } + final Genre currentGenre = findGenre(id); + currentGenre.setName(name); + return em.merge(currentGenre); + } + + @Transactional + public Genre deleteGenre(Long id) { + final Genre currentGenre = findGenre(id); + em.remove(currentGenre); + return currentGenre; + } + + @Transactional + public void deleteAllGenres() { + em.createQuery("delete from Genre").executeUpdate(); + } +} \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 8b13789..da7b0b1 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1 +1,11 @@ - +spring.main.banner-mode=off +#server.port=8080 +spring.datasource.url=jdbc:h2:file:./data +spring.datasource.driverClassName=org.h2.Driver +spring.datasource.username=sa +spring.datasource.password=password +spring.jpa.database-platform=org.hibernate.dialect.H2Dialect +spring.jpa.hibernate.ddl-auto=update +spring.h2.console.enabled=true +spring.h2.console.settings.trace=false +spring.h2.console.settings.web-allow-others=false diff --git a/src/test/java/ru/ip/labs/labs/JpaActorsTest.java b/src/test/java/ru/ip/labs/labs/JpaActorsTest.java new file mode 100644 index 0000000..cb462ab --- /dev/null +++ b/src/test/java/ru/ip/labs/labs/JpaActorsTest.java @@ -0,0 +1,4 @@ +package ru.ip.labs.labs; + +public class JpaActorsTest { +} diff --git a/src/test/java/ru/ip/labs/labs/JpaFilmsTest.java b/src/test/java/ru/ip/labs/labs/JpaFilmsTest.java new file mode 100644 index 0000000..27629c2 --- /dev/null +++ b/src/test/java/ru/ip/labs/labs/JpaFilmsTest.java @@ -0,0 +1,61 @@ +package ru.ip.labs.labs; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import ru.ip.labs.labs.films.models.Film; +import ru.ip.labs.labs.films.service.FilmsService; + +import javax.persistence.EntityNotFoundException; +import java.util.List; + +@SpringBootTest +public class JpaFilmsTest { + private static final Logger log = LoggerFactory.getLogger(JpaFilmsTest.class); + @Autowired + FilmsService filmService; + + @Test + void testFilmCreate() { + filmService.deleteAllFilms(); + final Film film = filmService.addFilm("Terminator 2"); + log.info(film.toString()); + Assertions.assertNotNull(film.getId()); + } + + @Test + void testStudentReadNotFound() { + filmService.deleteAllFilms(); + Assertions.assertThrows(EntityNotFoundException.class, () -> filmService.findFilm(-1L)); + } + + @Test + void findFilm() { + filmService.deleteAllFilms(); + final Film film = filmService.addFilm("Terminator 2"); + log.info(film.toString()); + final Film findFilm = filmService.findFilm(film.getId()); + log.info(findFilm.toString()); + Assertions.assertEquals(film.toString(), findFilm.toString()); + } + + @Test + void testReadAll() { + filmService.deleteAllFilms(); + final Film film = filmService.addFilm("Terminator 2"); + log.info(film.toString()); + final List films = filmService.findAllFilms(); + Assertions.assertEquals(films.size(), 1); + } + + @Test + void deleteFilm() { + filmService.deleteAllFilms(); + final Film film = filmService.addFilm("Terminator 2"); + log.info(film.toString()); + filmService.deleteFilm(film.getId()); + Assertions.assertThrows(EntityNotFoundException.class, () -> filmService.findFilm(film.getId())); + } +} diff --git a/src/test/java/ru/ip/labs/labs/JpaGenresTest.java b/src/test/java/ru/ip/labs/labs/JpaGenresTest.java new file mode 100644 index 0000000..d09eb6b --- /dev/null +++ b/src/test/java/ru/ip/labs/labs/JpaGenresTest.java @@ -0,0 +1,4 @@ +package ru.ip.labs.labs; + +public class JpaGenresTest { +} diff --git a/src/test/java/ru/ip/labs/labs/LabsApplicationTests.java b/src/test/java/ru/ip/labs/labs/LabsApplicationTests.java index 6ce7aa0..4e4ad75 100644 --- a/src/test/java/ru/ip/labs/labs/LabsApplicationTests.java +++ b/src/test/java/ru/ip/labs/labs/LabsApplicationTests.java @@ -19,11 +19,6 @@ class LabsApplicationTests { Assertions.assertEquals(4, res); } @Test - void testStringSum() { - String res = calculatorService.getSum("hello, ", 2, "string"); - Assertions.assertEquals("hello, 2", res); - } - @Test void testArraySum() { String res = calculatorService.getSum("1,2", 2, "array"); Assertions.assertEquals("3,4", res);