Spring DataJpa Test Tutorial : How to Test Database using Spring Boot @DataJPATest Annotation
#SPringDataJPATest #SpringBoot #UnitTesting #DataBase
► SUBSCRIBE & LIKE!!
► Important Information and code guide available bottom of the Description section
► Official Email Id: [email protected]
► Download the sample java microservice application :
https://github.com/admindebu/Spring-Data-JPA--Testing-Project-using-DataJPATest
► Follow on Facebook: https://www.facebook.com/TechTalkDebu
► Follow on LinkedIn: https://www.linkedin.com/in/debu-paul
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
► Here is our amazing playlist for Core Java, Spring MVC/Boot, Git and Microservice
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1. Core Java :: https://www.youtube.com/watch?v=IR_h0...
2. Core Java Important Interview QA : https://www.youtube.com/watch?v=CFoxr...
3. Spring MVC & Spring Boot :: https://www.youtube.com/watch?v=f-Wk1...
4. Micro Services :: https://www.youtube.com/watch?v=pscya...
5. Git/GitHub :: https://www.youtube.com/watch?v=XHxBA...
6. AWS :: https://www.youtube.com/watch?v=81Y_2...
7. Spring Security & OAuth : https://www.youtube.com/watch?v=AvV8l...
8. Coding and Programming : https://www.youtube.com/watch?v=o2BP4...
9. Raspberry PI & Arduino : https://www.youtube.com/watch?v=uauMF...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Watch my "Most Watched Videos"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
► HTTPS & HTTPS protocol :: https://www.youtube.com/watch?v=BlnSS...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Information
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@DataJpaTest is the annotation that Spring supports for a JPA test that focuses only on JPA components.
It will disable full auto-configuration and then, apply only enable configuration relevant to JPA tests. The list of the auto-configuration settings that are enabled can be found here.
By default, tests annotated with @DataJpaTest are transactional and roll back at the end of each test. If you don’t want it, you can disable transaction management for a test or for the whole class using @Transactional annotation:
@DataJpaTest
@Transactional(propagation = Propagation.NOT_SUPPORTED)
class YourNonTransactionalTests {
}
In-memory embedded database (like H2 database in this example) generally works well for tests, it is fast and does not require any installation. However, we can configure for a real database with @AutoConfigureTestDatabase annotation:
@DataJpaTest
@AutoConfigureTestDatabase(replace=Replace.NONE)
class YourRepositoryTests {
}
If you are using JUnit 4, you need to add @RunWith(SpringRunner.class) to the test:
@RunWith(SpringRunner.class)
@DataJpaTest
class YourRepositoryTests {
}
TestEntityManager
The purpose of the EntityManager is to interact with the persistence context. Spring Data JPA abstractes you from the EntityManager through Repository interfaces. And TestEntityManager allows us to use EntityManager in tests.
We can inject a TestEntityManager bean in Data JPA tests. If you want to use TestEntityManager outside of @DataJpaTest instances, just add @AutoConfigureTestEntityManager annotation.
======================================
The job of @Controller is to create a Map of the model object and find a view but @RestController simply returns the object and object data is directly written into HTTP response as JSON or XML.
@Controller since Spring 2.5 Officially (3, 3.1) and @RestController Spring 4
@Controller is a common or generic annotation that is used to mark a class as Spring MVC Controller (web controller) while @RestController is a special controller used in RestFull Webservice API and the equivalent of
@RestController = @Controller + @ResponseBody
@Controller is a stereotype annotation or it’s specialization of @Component annotation, while @RestController is a specialization of @Controller annotation
@RestController and @Controller is that you don't need to use @ResponseBody on every handler method once you annotate the class with @RestController
Controller and @RestCotroller in Spring MVC is that once you mark a class @RestController then every method is written a domain object instead of a view.
GitHub Account for Free Code download: https://github.com/admindebu
Follow me on FaceBook: https://www.facebook.com/TechTalkDebu
Instagram: techtalk_debu
LinkedIn : https://www.linkedin.com/in/debu-paul
if you like my video, please subscribe to my channel and share the video
Thanks & Regards,
Debu Paul
Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Spring DataJpa Test Tutorial : How to Test Database using Spring Boot @DataJPATest Annotation», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.
Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.
Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!
Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.