{"id":318562,"date":"2021-02-24T21:00:37","date_gmt":"2021-02-24T21:00:37","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=318562"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=318562","title":{"rendered":"\u0417\u0430\u043f\u0438\u0441\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u0439 Spring \u043f\u0440\u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 Spring Boot"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<p>\u041e\u0434\u043d\u0430 \u0438\u0437 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 Spring &#8212; \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0439.&nbsp;\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0434\u043b\u044f \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0447\u0430\u0441\u0442\u0435\u0439 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438-\u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0438.&nbsp;\u041e\u0434\u043d\u0430 \u0447\u0430\u0441\u0442\u044c \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u0435, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0440\u0435\u0430\u0433\u0438\u0440\u0443\u044e\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043b\u0443\u0448\u0430\u0442\u0435\u043b\u0435\u0439 (\u0434\u0430\u0436\u0435 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e).&nbsp;\u0412 \u0440\u0430\u043c\u043a\u0430\u0445&nbsp;<a href=\"https:\/\/docs.spring.io\/spring-framework\/docs\/current\/reference\/html\/testing.html#testcontext-application-events\" rel=\"noopener noreferrer nofollow\">Spring Framework 5.3.3<\/a>&nbsp;(Spring Boot 2.4.2) \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0432\u0441\u0435 \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f (&nbsp;<code>ApplicationEvent<\/code>) \u043f\u0440\u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 Spring Boot \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c&nbsp;<code>@RecrodApplicationEvents<\/code>.<\/p>\n<h3>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0434\u043b\u044f \u0437\u0430\u043f\u0438\u0441\u0438 ApplicationEvent \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Spring Boot<\/h3>\n<p>\u0427\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043d\u0430\u043c \u043d\u0443\u0436\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e&nbsp;<a href=\"https:\/\/rieckpil.de\/guide-to-testing-with-spring-boot-starter-test\/\" rel=\"noopener noreferrer nofollow\">Spring Boot Starter Test,<\/a>&nbsp;\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0430\u0441\u0442\u044c\u044e \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430 Spring Boot, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442\u0435 \u043d\u0430&nbsp;<a href=\"https:\/\/start.spring.io\/\" rel=\"noopener noreferrer nofollow\">start.spring.io<\/a>&nbsp;.<\/p>\n<pre><code class=\"xml\">&lt;dependency&gt;   &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;   &lt;artifactId&gt;spring-boot-starter-test&lt;\/artifactId&gt;   &lt;scope&gt;test&lt;\/scope&gt; &lt;\/dependency&gt;<\/code><\/pre>\n<p>\u041e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0432\u0435\u0440\u0441\u0438\u044e Spring Boot &gt;= 2.4.2, \u0442\u0430\u043a \u043a\u0430\u043a \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u0430 \u0432\u0435\u0440\u0441\u0438\u044f Spring Framework &gt;= 5.3.3.<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0448\u0438\u0445 \u0442\u0435\u0441\u0442\u043e\u0432 \u0435\u0441\u0442\u044c \u043e\u0434\u043d\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u0435: \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441\u043e Spring<code>TestContext&nbsp;<\/code>\u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b&nbsp;<code>ApplicationContext<\/code>.<\/p>\n<p>\u0421\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u043e\u043d\u0430 \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0434\u043b\u044f \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0430, \u0433\u0434\u0435 \u043d\u0435&nbsp;<a href=\"https:\/\/docs.spring.io\/spring-framework\/docs\/current\/reference\/html\/testing.html#testcontext-framework\" rel=\"noopener noreferrer nofollow\">\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b Spring TestContext<\/a>.&nbsp;\u0415\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e&nbsp;<a href=\"https:\/\/rieckpil.de\/spring-boot-test-slices-overview-and-usage\/\" rel=\"noopener noreferrer nofollow\">\u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0439 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0445 \u0441\u0440\u0435\u0437\u043e\u0432 Spring Boot,<\/a>&nbsp;\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u0434\u043e\u0431\u043d\u043e \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u044e\u0442 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u0442\u0435\u0441\u0442\u0430.<\/p>\n<h3>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0432 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u044e \u0441\u043e\u0431\u044b\u0442\u0438\u0439 Spring <\/h3>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043c\u044b \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c \u043a\u043b\u0430\u0441\u0441 Java, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0434\u0430\u0435\u0442 <code>UserCreationEvent,&nbsp;<\/code>\u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.&nbsp;\u0421\u043e\u0431\u044b\u0442\u0438\u0435 \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0435 \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435, \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0435 \u0434\u043b\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0437\u0430\u0434\u0430\u0447:<\/p>\n<pre><code class=\"java\">public class UserCreationEvent extends ApplicationEvent {     private final String username;   private final Long id;     public UserCreationEvent(Object source, String username, Long id) {     super(source);     this.username = username;     this.id = id;   }     \/\/ getters }<\/code><\/pre>\n<p>\u041d\u0430\u0447\u0438\u043d\u0430\u044f \u0441\u043e Spring Framework 4.2, \u043d\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0442\u044c \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439&nbsp;\u043a\u043b\u0430\u0441\u0441 <code>ApplicationEvent&nbsp;<\/code>\u0438 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043b\u044e\u0431\u043e\u0439 POJO \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u0439.&nbsp;\u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u0440\u0438\u0432\u0435\u043b\u0435\u043d\u043e&nbsp;<a href=\"https:\/\/reflectoring.io\/spring-boot-application-events-explained\/\" rel=\"noopener noreferrer nofollow\">\u043e\u0442\u043b\u0438\u0447\u043d\u043e\u0435 \u0432\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0432 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439<\/a>&nbsp;\u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Spring Boot.<\/p>\n<p>\u041d\u0430\u0448&nbsp;<code>UserService&nbsp;<\/code>\u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0438 \u0445\u0440\u0430\u043d\u0438\u0442 \u043d\u0430\u0448\u0438\u0445 \u043d\u043e\u0432\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439.&nbsp;\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043a\u0430\u043a \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0442\u0430\u043a \u0438 \u0433\u0440\u0443\u043f\u043f\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439:<\/p>\n<pre><code class=\"java\">@Service public class UserService {     private final ApplicationEventPublisher eventPublisher;     public UserService(ApplicationEventPublisher eventPublisher) {     this.eventPublisher = eventPublisher;   }     public Long createUser(String username) {     \/\/ logic to create a user and store it in a database     Long primaryKey = ThreadLocalRandom.current().nextLong(1, 1000);       this.eventPublisher.publishEvent(new UserCreationEvent(this, username, primaryKey));       return primaryKey;   }     public List&lt;Long&gt; createUser(List&lt;String&gt; usernames) {     List&lt;Long&gt; resultIds = new ArrayList&lt;&gt;();       for (String username : usernames) {       resultIds.add(createUser(username));     }       return resultIds;   } }<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0441\u0442\u0430\u043d\u0435\u0442 \u0447\u0430\u0441\u0442\u044c\u044e \u043d\u0430\u0448\u0435\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b, \u043c\u044b \u0443\u0432\u0435\u0434\u043e\u043c\u0438\u043c \u0434\u0440\u0443\u0433\u0438\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u0432 \u0444\u0430\u0439\u043b&nbsp;<code>UserCreationEvent<\/code>.<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043d\u0430\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0434\u0432\u0435 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0432\u0441\u044f\u043a\u0438\u0439 \u0440\u0430\u0437, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0442\u0430\u043a\u043e\u0435&nbsp;<code>UserCreationEvent<\/code>:<\/p>\n<pre><code class=\"java\">@Component public class ReportingListener {     @EventListener(UserCreationEvent.class)   public void reportUserCreation(UserCreationEvent event) {     \/\/ e.g. increment a counter to report the total amount of new users     System.out.println(\"Increment counter as new user was created: \" + event);   }     @EventListener(UserCreationEvent.class)   public void syncUserToExternalSystem(UserCreationEvent event) {     \/\/ e.g. send a message to a messaging queue to inform other systems     System.out.println(\"informing other systems about new user: \" + event);   } }<\/code><\/pre>\n<p>\u0417\u0430\u043f\u0438\u0441\u044c \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Spring Boot<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043d\u0430\u0448 \u043f\u0435\u0440\u0432\u044b\u0439 \u0442\u0435\u0441\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442,&nbsp;<code>UserService&nbsp;<\/code>\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0432\u0441\u044f\u043a\u0438\u0439 \u0440\u0430\u0437, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.&nbsp;\u041c\u044b \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u0438\u0440\u0443\u0435\u043c Spring \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0448\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e&nbsp;<code>@RecordApplicationEvents&nbsp;<\/code>\u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u043f\u043e\u0432\u0435\u0440\u0445 \u043d\u0430\u0448\u0435\u0433\u043e \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430:<\/p>\n<pre><code class=\"java\">@SpringBootTest @RecordApplicationEvents class UserServiceFullContextTest {     @Autowired   private ApplicationEvents applicationEvents;     @Autowired   private UserService userService;     @Test   void userCreationShouldPublishEvent() {       this.userService.createUser(\"duke\");       assertEquals(1, applicationEvents       .stream(UserCreationEvent.class)       .filter(event -&gt; event.getUsername().equals(\"duke\"))       .count());       \/\/ There are multiple events recorded     \/\/ PrepareInstanceEvent     \/\/ BeforeTestMethodEvent     \/\/ BeforeTestExecutionEvent     \/\/ UserCreationEvent     applicationEvents.stream().forEach(System.out::println);   } }<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a&nbsp;\u043c\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0438\u0441\u043f\u044b\u0442\u044b\u0432\u0430\u0435\u043c\u044b\u0439 (<code>createUser&nbsp;<\/code>\u0438\u0437&nbsp;<code>UserService&nbsp;<\/code>\u0432 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435), \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0438\u0442\u044c \u0432\u0441\u0435 \u0437\u0430\u0445\u0432\u0430\u0447\u0435\u043d\u043d\u044b\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0438\u0437 \u0431\u0438\u043d\u043e\u0432&nbsp;<code>ApplicationEvents<\/code>,&nbsp;\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0432\u043d\u0435\u0434\u0440\u044f\u0435\u043c \u0432 \u043d\u0430\u0448 \u0442\u0435\u0441\u0442.<\/p>\n<p>\u041e\u0442\u043a\u0440\u044b\u0442\u044b\u0439&nbsp;<code>.stream()<\/code>\u043c\u0435\u0442\u043e\u0434&nbsp;\u043a\u043b\u0430\u0441\u0441\u0430 <code>ApplicationEvents&nbsp;<\/code>\u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432\u0441\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f, \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0430.&nbsp;\u0415\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f <code>.stream(),&nbsp;<\/code>\u0432&nbsp;\u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u044b \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c \u043f\u043e\u0442\u043e\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0441\u043e\u0431\u044b\u0442\u0438\u0439.<\/p>\n<p>\u041d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u043c\u044b \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0438\u0437 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, Spring \u0437\u0430\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0447\u0435\u0442\u044b\u0440\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0430 \u0432\u044b\u0448\u0435.&nbsp;\u041e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0442\u0440\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043e\u0442\u043d\u043e\u0441\u044f\u0442\u0441\u044f \u043a Spring, \u043a\u0430\u043a \u0438&nbsp;<code>PrepareInstanceEvent&nbsp;<\/code>\u0432 \u0441\u0440\u0435\u0434\u0435 TestContext.<\/p>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c JUnit Jupiter \u0438&nbsp;<code>SpringExtension&nbsp;<\/code>(\u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0434\u043b\u044f \u043d\u0430\u0441 \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438&nbsp;<code>@SpringBootTest<\/code>), \u043c\u044b \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u043c \u0432\u043d\u0435\u0434\u0440\u0438\u0442\u044c&nbsp;bean-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 <code>ApplicationEvents&nbsp;<\/code>\u0432 \u043c\u0435\u0442\u043e\u0434 \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430 JUnit \u0438\u043b\u0438 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0432 \u0442\u0435\u0441\u0442:<\/p>\n<pre><code class=\"java\">@Test void batchUserCreationShouldPublishEvents(@Autowired ApplicationEvents events) {   List&lt;Long&gt; result = this.userService.createUser(List.of(\"duke\", \"mike\", \"alice\"));     assertEquals(3, result.size());   assertEquals(3, events.stream(UserCreationEvent.class).count()); }<\/code><\/pre>\n<p>\u042d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440&nbsp;<code>ApplicationEvents&nbsp;<\/code>\u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0434\u043e \u0438 \u0443\u0434\u0430\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0430 \u043a\u0430\u043a \u0447\u0430\u0441\u0442\u044c \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430.&nbsp;\u0421\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u0432\u044b \u0434\u0430\u0436\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044f \u0438&nbsp;<code>@TestInstance(TestInstance.Lifecycle.PER_CLASS)<\/code>\u0434\u0435\u043b\u0438\u0442\u044c \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043c\u0435\u0436\u0434\u0443 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0442\u0435\u0441\u0442\u0430\u043c\u0438 (&nbsp;<code>PER_METHOD&nbsp;<\/code>\u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e).<\/p>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0437\u0430\u043f\u0443\u0441\u043a \u0432\u0441\u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 Spring&nbsp;<code>@SpringBootTest&nbsp;<\/code>\u0434\u043b\u044f \u0442\u0430\u043a\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0430&nbsp;\u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u0437\u043b\u0438\u0448\u043d\u0438\u043c.&nbsp;\u041c\u044b \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0435\u0441\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 Spring&nbsp;<code>TestContext&nbsp;<\/code>\u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0448\u0438\u043c&nbsp;bean-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u043c <code>UserService<\/code>, \u0447\u0442\u043e\u0431\u044b \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e&nbsp;<code>UserCreationEvent&nbsp;<\/code> \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043d:<\/p>\n<pre><code class=\"java\">@RecordApplicationEvents @ExtendWith(SpringExtension.class) @ContextConfiguration(classes = UserService.class) class UserServicePerClassTest {     @Autowired   private ApplicationEvents applicationEvents;     @Autowired   private UserService userService;     @Test   void userCreationShouldPublishEvent() {       this.userService.createUser(\"duke\");       assertEquals(1, applicationEvents       .stream(UserCreationEvent.class)       .filter(event -&gt; event.getUsername().equals(\"duke\"))       .count());       applicationEvents.stream().forEach(System.out::println);   } }<\/code><\/pre>\n<p>\u2026 \u0418\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043a \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e.<\/p>\n<h3>\u0410\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u044b \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e \u0432\u0435\u0441\u0435\u043d\u043d\u0438\u0445 \u0441\u043e\u0431\u044b\u0442\u0438\u0439<\/h3>\n<p>\u0412 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u043e\u0433\u043e, \u0447\u0435\u0433\u043e \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0434\u043e\u0441\u0442\u0438\u0447\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0442\u0435\u0441\u0442\u0430, \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0430:<\/p>\n<pre><code class=\"java\">@ExtendWith(MockitoExtension.class) class UserServiceUnitTest {     @Mock   private ApplicationEventPublisher applicationEventPublisher;     @Captor   private ArgumentCaptor&lt;UserCreationEvent&gt; eventArgumentCaptor;     @InjectMocks   private UserService userService;     @Test   void userCreationShouldPublishEvent() {       Long result = this.userService.createUser(\"duke\");       Mockito.verify(applicationEventPublisher).publishEvent(eventArgumentCaptor.capture());       assertEquals(\"duke\", eventArgumentCaptor.getValue().getUsername());   }     @Test   void batchUserCreationShouldPublishEvents() {     List&lt;Long&gt; result = this.userService.createUser(List.of(\"duke\", \"mike\", \"alice\"));       Mockito       .verify(applicationEventPublisher, Mockito.times(3))       .publishEvent(any(UserCreationEvent.class));   } }<\/code><\/pre>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0437\u0434\u0435\u0441\u044c \u043c\u044b \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043d\u0438\u043a\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 Spring Test \u0438&nbsp;<a href=\"https:\/\/rieckpil.de\/hands-on-mocking-with-mockito-online-course\/\" rel=\"noopener noreferrer nofollow\">\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u043c\u0441\u044f<\/a>&nbsp;\u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0430&nbsp;<a href=\"https:\/\/rieckpil.de\/hands-on-mocking-with-mockito-online-course\/\" rel=\"noopener noreferrer nofollow\">Mockito<\/a>&nbsp;\u0438 JUnit Jupiter.<\/p>\n<p>\u0414\u0440\u0443\u0433\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u044f\u0432\u043d\u043e, \u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0432\u0435\u0441\u044c \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0430:<\/p>\n<pre><code class=\"java\">@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) class ApplicationIT {     @Autowired   private TestRestTemplate testRestTemplate;     @Test   void shouldCreateUserAndPerformReporting() {       ResponseEntity&lt;Void&gt; result = this.testRestTemplate       .postForEntity(\"\/api\/users\", \"duke\", Void.class);       assertEquals(201, result.getStatusCodeValue());     assertTrue(result.getHeaders().containsKey(\"Location\"),       \"Response doesn't contain Location header\");       \/\/ additional assertion to verify the counter was incremented     \/\/ additional assertion that a new message is part of the queue   } }<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0430\u0448\u0438\u0445 \u0441\u043b\u0443\u0448\u0430\u0442\u0435\u043b\u0435\u0439 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0447\u0442\u043e \u043c\u044b \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0438\u043b\u0438 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u043c \u0441\u0447\u0435\u0442\u0447\u0438\u043a.<\/p>\n<h3>\u0420\u0435\u0437\u044e\u043c\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u0439 Spring \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Spring Boot<\/h3>\n<p>\u0412\u0441\u0435 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044b \u0441\u0432\u043e\u0434\u044f\u0442\u0441\u044f \u043a \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f.&nbsp;\u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u043d\u043e\u0432\u043e\u0439&nbsp;\u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>@RecordApplicationEvents \u0432&nbsp;<\/code>Spring Test \u0443 \u043d\u0430\u0441&nbsp;<em>\u043c\u043e\u0436\u0435\u0442<\/em>&nbsp;\u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442\u044c \u0441\u043e\u0431\u043b\u0430\u0437\u043d \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0447\u0435\u0441\u043a\u0438\u0445 \u0442\u0435\u0441\u0442\u043e\u0432 \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u044e\u044e \u0447\u0430\u0441\u0442\u044c \u043d\u0430\u0448\u0435\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438.&nbsp;\u0412 \u043e\u0431\u0449\u0435\u043c, \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u043e\u0441\u0440\u0435\u0434\u043e\u0442\u043e\u0447\u0438\u0442\u044c\u0441\u044f \u043d\u0430 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f (\u0442\u0430\u043a\u0436\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e\u043c \u043a\u0430\u043a \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442), \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u043d\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0431\u0435\u0441\u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043d\u044b\u0439 \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433.<\/p>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435 \u0441\u0435\u0431\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435: \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c,&nbsp;<code>ApplicationEvent&nbsp;<\/code>\u0447\u0442\u043e\u0431\u044b \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0442\u044c \u0447\u0430\u0441\u0442\u0438 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u0447\u0442\u043e \u044d\u0442\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0442\u0435\u0441\u0442\u0430.&nbsp;\u0427\u0435\u0440\u0435\u0437 \u0434\u0432\u0435 \u043d\u0435\u0434\u0435\u043b\u0438 \u043c\u044b \u0440\u0435\u0448\u0430\u0435\u043c \u0443\u0431\u0440\u0430\u0442\u044c \/ \u043f\u0435\u0440\u0435\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u044d\u0442\u0443 \u0440\u0430\u0437\u0432\u044f\u0437\u043a\u0443 (\u043f\u043e \u043a\u0430\u043a\u0438\u043c-\u0442\u043e \u043f\u0440\u0438\u0447\u0438\u043d\u0430\u043c).&nbsp;\u041d\u0430\u0448 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c, \u043a\u0430\u043a \u043e\u0436\u0438\u0434\u0430\u043b\u043e\u0441\u044c, \u043d\u043e \u043d\u0430\u0448 \u0442\u0435\u0441\u0442 \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0435 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043c\u044b \u0434\u0435\u043b\u0430\u0435\u043c \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043e \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044f, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u043c\u044b \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043b\u0438.<\/p>\n<p>\u041f\u043e\u043c\u043d\u0438\u0442\u0435 \u043e\u0431 \u044d\u0442\u043e\u043c \u0438 \u043d\u0435 \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0430\u0439\u0442\u0435 \u0441\u0432\u043e\u0438 \u0442\u0435\u0441\u0442\u044b \u0434\u0435\u0442\u0430\u043b\u044f\u043c\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 (\u0435\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433 \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c :).&nbsp;\u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u0435\u0441\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0435 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438, \u043a\u043e\u0433\u0434\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f&nbsp;<code>@RecordApplicationEvents<\/code> \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442.<\/p>\n<p>\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u0441\u043e \u0432\u0441\u0435\u043c\u0438 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u044b\u043c\u0438 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430\u043c\u0438 \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f Spring Event \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Spring Boot&nbsp;<a href=\"https:\/\/github.com\/rieckpil\/blog-tutorials\/tree\/master\/spring-boot-test-spring-events\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u043d\u0430 GitHub<\/a>.<\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/541028\/\"> https:\/\/habr.com\/ru\/post\/541028\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<p>\u041e\u0434\u043d\u0430 \u0438\u0437 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 Spring &#8212; \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0439.&nbsp;\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0434\u043b\u044f \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0447\u0430\u0441\u0442\u0435\u0439 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438-\u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0438.&nbsp;\u041e\u0434\u043d\u0430 \u0447\u0430\u0441\u0442\u044c \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u0435, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0440\u0435\u0430\u0433\u0438\u0440\u0443\u044e\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043b\u0443\u0448\u0430\u0442\u0435\u043b\u0435\u0439 (\u0434\u0430\u0436\u0435 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e).&nbsp;\u0412 \u0440\u0430\u043c\u043a\u0430\u0445&nbsp;<a href=\"https:\/\/docs.spring.io\/spring-framework\/docs\/current\/reference\/html\/testing.html#testcontext-application-events\" rel=\"noopener noreferrer nofollow\">Spring Framework 5.3.3<\/a>&nbsp;(Spring Boot 2.4.2) \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0432\u0441\u0435 \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f (&nbsp;<code>ApplicationEvent<\/code>) \u043f\u0440\u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 Spring Boot \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c&nbsp;<code>@RecrodApplicationEvents<\/code>.<\/p>\n<h3>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0434\u043b\u044f \u0437\u0430\u043f\u0438\u0441\u0438 ApplicationEvent \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Spring Boot<\/h3>\n<p>\u0427\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043d\u0430\u043c \u043d\u0443\u0436\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e&nbsp;<a href=\"https:\/\/rieckpil.de\/guide-to-testing-with-spring-boot-starter-test\/\" rel=\"noopener noreferrer nofollow\">Spring Boot Starter Test,<\/a>&nbsp;\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0430\u0441\u0442\u044c\u044e \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430 Spring Boot, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442\u0435 \u043d\u0430&nbsp;<a href=\"https:\/\/start.spring.io\/\" rel=\"noopener noreferrer nofollow\">start.spring.io<\/a>&nbsp;.<\/p>\n<pre><code class=\"xml\">&lt;dependency&gt;   &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;   &lt;artifactId&gt;spring-boot-starter-test&lt;\/artifactId&gt;   &lt;scope&gt;test&lt;\/scope&gt; &lt;\/dependency&gt;<\/code><\/pre>\n<p>\u041e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0432\u0435\u0440\u0441\u0438\u044e Spring Boot &gt;= 2.4.2, \u0442\u0430\u043a \u043a\u0430\u043a \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u0430 \u0432\u0435\u0440\u0441\u0438\u044f Spring Framework &gt;= 5.3.3.<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0448\u0438\u0445 \u0442\u0435\u0441\u0442\u043e\u0432 \u0435\u0441\u0442\u044c \u043e\u0434\u043d\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u0435: \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441\u043e Spring<code>TestContext&nbsp;<\/code>\u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b&nbsp;<code>ApplicationContext<\/code>.<\/p>\n<p>\u0421\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u043e\u043d\u0430 \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0434\u043b\u044f \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0430, \u0433\u0434\u0435 \u043d\u0435&nbsp;<a href=\"https:\/\/docs.spring.io\/spring-framework\/docs\/current\/reference\/html\/testing.html#testcontext-framework\" rel=\"noopener noreferrer nofollow\">\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b Spring TestContext<\/a>.&nbsp;\u0415\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e&nbsp;<a href=\"https:\/\/rieckpil.de\/spring-boot-test-slices-overview-and-usage\/\" rel=\"noopener noreferrer nofollow\">\u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0439 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0445 \u0441\u0440\u0435\u0437\u043e\u0432 Spring Boot,<\/a>&nbsp;\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u0434\u043e\u0431\u043d\u043e \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u044e\u0442 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u0442\u0435\u0441\u0442\u0430.<\/p>\n<h3>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0432 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u044e \u0441\u043e\u0431\u044b\u0442\u0438\u0439 Spring <\/h3>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043c\u044b \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c \u043a\u043b\u0430\u0441\u0441 Java, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0434\u0430\u0435\u0442 <code>UserCreationEvent,&nbsp;<\/code>\u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.&nbsp;\u0421\u043e\u0431\u044b\u0442\u0438\u0435 \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0435 \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435, \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0435 \u0434\u043b\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0437\u0430\u0434\u0430\u0447:<\/p>\n<pre><code class=\"java\">public class UserCreationEvent extends ApplicationEvent {     private final String username;   private final Long id;     public UserCreationEvent(Object source, String username, Long id) {     super(source);     this.username = username;     this.id = id;   }     \/\/ getters }<\/code><\/pre>\n<p>\u041d\u0430\u0447\u0438\u043d\u0430\u044f \u0441\u043e Spring Framework 4.2, \u043d\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0442\u044c \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439&nbsp;\u043a\u043b\u0430\u0441\u0441 <code>ApplicationEvent&nbsp;<\/code>\u0438 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043b\u044e\u0431\u043e\u0439 POJO \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u0439.&nbsp;\u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u0440\u0438\u0432\u0435\u043b\u0435\u043d\u043e&nbsp;<a href=\"https:\/\/reflectoring.io\/spring-boot-application-events-explained\/\" rel=\"noopener noreferrer nofollow\">\u043e\u0442\u043b\u0438\u0447\u043d\u043e\u0435 \u0432\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0432 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439<\/a>&nbsp;\u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Spring Boot.<\/p>\n<p>\u041d\u0430\u0448&nbsp;<code>UserService&nbsp;<\/code>\u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0438 \u0445\u0440\u0430\u043d\u0438\u0442 \u043d\u0430\u0448\u0438\u0445 \u043d\u043e\u0432\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439.&nbsp;\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043a\u0430\u043a \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0442\u0430\u043a \u0438 \u0433\u0440\u0443\u043f\u043f\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439:<\/p>\n<pre><code class=\"java\">@Service public class UserService {     private final ApplicationEventPublisher eventPublisher;     public UserService(ApplicationEventPublisher eventPublisher) {     this.eventPublisher = eventPublisher;   }     public Long createUser(String username) {     \/\/ logic to create a user and store it in a database     Long primaryKey = ThreadLocalRandom.current().nextLong(1, 1000);       this.eventPublisher.publishEvent(new UserCreationEvent(this, username, primaryKey));       return primaryKey;   }     public List&lt;Long&gt; createUser(List&lt;String&gt; usernames) {     List&lt;Long&gt; resultIds = new ArrayList&lt;&gt;();       for (String username : usernames) {       resultIds.add(createUser(username));     }       return resultIds;   } }<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0441\u0442\u0430\u043d\u0435\u0442 \u0447\u0430\u0441\u0442\u044c\u044e \u043d\u0430\u0448\u0435\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b, \u043c\u044b \u0443\u0432\u0435\u0434\u043e\u043c\u0438\u043c \u0434\u0440\u0443\u0433\u0438\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u0432 \u0444\u0430\u0439\u043b&nbsp;<code>UserCreationEvent<\/code>.<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043d\u0430\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0434\u0432\u0435 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0432\u0441\u044f\u043a\u0438\u0439 \u0440\u0430\u0437, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0442\u0430\u043a\u043e\u0435&nbsp;<code>UserCreationEvent<\/code>:<\/p>\n<pre><code class=\"java\">@Component public class ReportingListener {     @EventListener(UserCreationEvent.class)   public void reportUserCreation(UserCreationEvent event) {     \/\/ e.g. increment a counter to report the total amount of new users     System.out.println(\"Increment counter as new user was created: \" + event);   }     @EventListener(UserCreationEvent.class)   public void syncUserToExternalSystem(UserCreationEvent event) {     \/\/ e.g. send a message to a messaging queue to inform other systems     System.out.println(\"informing other systems about new user: \" + event);   } }<\/code><\/pre>\n<p>\u0417\u0430\u043f\u0438\u0441\u044c \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Spring Boot<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043d\u0430\u0448 \u043f\u0435\u0440\u0432\u044b\u0439 \u0442\u0435\u0441\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442,&nbsp;<code>UserService&nbsp;<\/code>\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0432\u0441\u044f\u043a\u0438\u0439 \u0440\u0430\u0437, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.&nbsp;\u041c\u044b \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u0438\u0440\u0443\u0435\u043c Spring \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0448\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e&nbsp;<code>@RecordApplicationEvents&nbsp;<\/code>\u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u043f\u043e\u0432\u0435\u0440\u0445 \u043d\u0430\u0448\u0435\u0433\u043e \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430:<\/p>\n<pre><code class=\"java\">@SpringBootTest @RecordApplicationEvents class UserServiceFullContextTest {     @Autowired   private ApplicationEvents applicationEvents;     @Autowired   private UserService userService;     @Test   void userCreationShouldPublishEvent() {       this.userService.createUser(\"duke\");       assertEquals(1, applicationEvents       .stream(UserCreationEvent.class)       .filter(event -&gt; event.getUsername().equals(\"duke\"))       .count());       \/\/ There are multiple events recorded     \/\/ PrepareInstanceEvent     \/\/ BeforeTestMethodEvent     \/\/ BeforeTestExecutionEvent     \/\/ UserCreationEvent     applicationEvents.stream().forEach(System.out::println);   } }<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a&nbsp;\u043c\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0438\u0441\u043f\u044b\u0442\u044b\u0432\u0430\u0435\u043c\u044b\u0439 (<code>createUser&nbsp;<\/code>\u0438\u0437&nbsp;<code>UserService&nbsp;<\/code>\u0432 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435), \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0438\u0442\u044c \u0432\u0441\u0435 \u0437\u0430\u0445\u0432\u0430\u0447\u0435\u043d\u043d\u044b\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0438\u0437 \u0431\u0438\u043d\u043e\u0432&nbsp;<code>ApplicationEvents<\/code>,&nbsp;\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0432\u043d\u0435\u0434\u0440\u044f\u0435\u043c \u0432 \u043d\u0430\u0448 \u0442\u0435\u0441\u0442.<\/p>\n<p>\u041e\u0442\u043a\u0440\u044b\u0442\u044b\u0439&nbsp;<code>.stream()<\/code>\u043c\u0435\u0442\u043e\u0434&nbsp;\u043a\u043b\u0430\u0441\u0441\u0430 <code>ApplicationEvents&nbsp;<\/code>\u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432\u0441\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f, \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0430.&nbsp;\u0415\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f <code>.stream(),&nbsp;<\/code>\u0432&nbsp;\u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u044b \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c \u043f\u043e\u0442\u043e\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0441\u043e\u0431\u044b\u0442\u0438\u0439.<\/p>\n<p>\u041d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u043c\u044b \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0438\u0437 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, Spring \u0437\u0430\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0447\u0435\u0442\u044b\u0440\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0430 \u0432\u044b\u0448\u0435.&nbsp;\u041e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0442\u0440\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043e\u0442\u043d\u043e\u0441\u044f\u0442\u0441\u044f \u043a Spring, \u043a\u0430\u043a \u0438&nbsp;<code>PrepareInstanceEvent&nbsp;<\/code>\u0432 \u0441\u0440\u0435\u0434\u0435 TestContext.<\/p>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c JUnit Jupiter \u0438&nbsp;<code>SpringExtension&nbsp;<\/code>(\u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0434\u043b\u044f \u043d\u0430\u0441 \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438&nbsp;<code>@SpringBootTest<\/code>), \u043c\u044b \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u043c \u0432\u043d\u0435\u0434\u0440\u0438\u0442\u044c&nbsp;bean-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 <code>ApplicationEvents&nbsp;<\/code>\u0432 \u043c\u0435\u0442\u043e\u0434 \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430 JUnit \u0438\u043b\u0438 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0432 \u0442\u0435\u0441\u0442:<\/p>\n<pre><code class=\"java\">@Test void batchUserCreationShouldPublishEvents(@Autowired ApplicationEvents events) {   List&lt;Long&gt; result = this.userService.createUser(List.of(\"duke\", \"mike\", \"alice\"));     assertEquals(3, result.size());   assertEquals(3, events.stream(UserCreationEvent.class).count()); }<\/code><\/pre>\n<p>\u042d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440&nbsp;<code>ApplicationEvents&nbsp;<\/code>\u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0434\u043e \u0438 \u0443\u0434\u0430\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0430 \u043a\u0430\u043a \u0447\u0430\u0441\u0442\u044c \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430.&nbsp;\u0421\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u0432\u044b \u0434\u0430\u0436\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044f \u0438&nbsp;<code>@TestInstance(TestInstance.Lifecycle.PER_CLASS)<\/code>\u0434\u0435\u043b\u0438\u0442\u044c \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043c\u0435\u0436\u0434\u0443 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0442\u0435\u0441\u0442\u0430\u043c\u0438 (&nbsp;<code>PER_METHOD&nbsp;<\/code>\u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e).<\/p>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0437\u0430\u043f\u0443\u0441\u043a \u0432\u0441\u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 Spring&nbsp;<code>@SpringBootTest&nbsp;<\/code>\u0434\u043b\u044f \u0442\u0430\u043a\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0430&nbsp;\u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u0437\u043b\u0438\u0448\u043d\u0438\u043c.&nbsp;\u041c\u044b \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0435\u0441\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 Spring&nbsp;<code>TestContext&nbsp;<\/code>\u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0448\u0438\u043c&nbsp;bean-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u043c <code>UserService<\/code>, \u0447\u0442\u043e\u0431\u044b \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e&nbsp;<code>UserCreationEvent&nbsp;<\/code> \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043d:<\/p>\n<pre><code class=\"java\">@RecordApplicationEvents @ExtendWith(SpringExtension.class) @ContextConfiguration(classes = UserService.class) class UserServicePerClassTest {     @Autowired   private ApplicationEvents applicationEvents;     @Autowired   private UserService userService;     @Test   void userCreationShouldPublishEvent() {       this.userService.createUser(\"duke\");       assertEquals(1, applicationEvents       .stream(UserCreationEvent.class)       .filter(event -&gt; event.getUsername().equals(\"duke\"))       .count());       applicationEvents.stream().forEach(System.out::println);   } }<\/code><\/pre>\n<p>\u2026 \u0418\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043a \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e.<\/p>\n<h3>\u0410\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u044b \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e \u0432\u0435\u0441\u0435\u043d\u043d\u0438\u0445 \u0441\u043e\u0431\u044b\u0442\u0438\u0439<\/h3>\n<p>\u0412 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u043e\u0433\u043e, \u0447\u0435\u0433\u043e \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0434\u043e\u0441\u0442\u0438\u0447\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0442\u0435\u0441\u0442\u0430, \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0430:<\/p>\n<pre><code class=\"java\">@ExtendWith(MockitoExtension.class) class UserServiceUnitTest {     @Mock   private ApplicationEventPublisher applicationEventPublisher;     @Captor   private ArgumentCaptor&lt;UserCreationEvent&gt; eventArgumentCaptor;     @InjectMocks   private UserService userService;     @Test   void userCreationShouldPublishEvent() {       Long result = this.userService.createUser(\"duke\");       Mockito.verify(applicationEventPublisher).publishEvent(eventArgumentCaptor.capture());       assertEquals(\"duke\", eventArgumentCaptor.getValue().getUsername());   }     @Test   void batchUserCreationShouldPublishEvents() {     List&lt;Long&gt; result = this.userService.createUser(List.of(\"duke\", \"mike\", \"alice\"));       Mockito       .verify(applicationEventPublisher, Mockito.times(3))       .publishEvent(any(UserCreationEvent.class));   } }<\/code><\/pre>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0437\u0434\u0435\u0441\u044c \u043c\u044b \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043d\u0438\u043a\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 Spring Test \u0438&nbsp;<a href=\"https:\/\/rieckpil.de\/hands-on-mocking-with-mockito-online-course\/\" rel=\"noopener noreferrer nofollow\">\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u043c\u0441\u044f<\/a>&nbsp;\u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0430&nbsp;<a href=\"https:\/\/rieckpil.de\/hands-on-mocking-with-mockito-online-course\/\" rel=\"noopener noreferrer nofollow\">Mockito<\/a>&nbsp;\u0438 JUnit Jupiter.<\/p>\n<p>\u0414\u0440\u0443\u0433\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u044f\u0432\u043d\u043e, \u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0432\u0435\u0441\u044c \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0430:<\/p>\n<pre><code class=\"java\">@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) class ApplicationIT {     @Autowired   private TestRestTemplate testRestTemplate;     @Test   void shouldCreateUserAndPerformReporting() {       ResponseEntity&lt;Void&gt; result = this.testRestTemplate       .postForEntity(\"\/api\/users\", \"duke\", Void.class);       assertEquals(201, result.getStatusCodeValue());     assertTrue(result.getHeaders().containsKey(\"Location\"),       \"Response doesn't contain Location header\");       \/\/ additional assertion to verify the counter was incremented     \/\/ additional assertion that a new message is part of the queue   } }<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0430\u0448\u0438\u0445 \u0441\u043b\u0443\u0448\u0430\u0442\u0435\u043b\u0435\u0439 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0447\u0442\u043e \u043c\u044b \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0438\u043b\u0438 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u043c \u0441\u0447\u0435\u0442\u0447\u0438\u043a.<\/p>\n<h3>\u0420\u0435\u0437\u044e\u043c\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u0439 Spring \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Spring Boot<\/h3>\n<p>\u0412\u0441\u0435 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044b \u0441\u0432\u043e\u0434\u044f\u0442\u0441\u044f \u043a \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f.&nbsp;\u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u043d\u043e\u0432\u043e\u0439&nbsp;\u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>@RecordApplicationEvents \u0432&nbsp;<\/code>Spring Test \u0443 \u043d\u0430\u0441&nbsp;<em>\u043c\u043e\u0436\u0435\u0442<\/em>&nbsp;\u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442\u044c \u0441\u043e\u0431\u043b\u0430\u0437\u043d \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0447\u0435\u0441\u043a\u0438\u0445 \u0442\u0435\u0441\u0442\u043e\u0432 \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u044e\u044e \u0447\u0430\u0441\u0442\u044c \u043d\u0430\u0448\u0435\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438.&nbsp;\u0412 \u043e\u0431\u0449\u0435\u043c, \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u043e\u0441\u0440\u0435\u0434\u043e\u0442\u043e\u0447\u0438\u0442\u044c\u0441\u044f \u043d\u0430 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f (\u0442\u0430\u043a\u0436\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e\u043c \u043a\u0430\u043a \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442), \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u043d\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0431\u0435\u0441\u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043d\u044b\u0439 \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433.<\/p>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435 \u0441\u0435\u0431\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435: \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c,&nbsp;<code>ApplicationEvent&nbsp;<\/code>\u0447\u0442\u043e\u0431\u044b \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0442\u044c \u0447\u0430\u0441\u0442\u0438 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u0447\u0442\u043e \u044d\u0442\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0442\u0435\u0441\u0442\u0430.&nbsp;\u0427\u0435\u0440\u0435\u0437 \u0434\u0432\u0435 \u043d\u0435\u0434\u0435\u043b\u0438 \u043c\u044b \u0440\u0435\u0448\u0430\u0435\u043c \u0443\u0431\u0440\u0430\u0442\u044c \/ \u043f\u0435\u0440\u0435\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u044d\u0442\u0443 \u0440\u0430\u0437\u0432\u044f\u0437\u043a\u0443 (\u043f\u043e \u043a\u0430\u043a\u0438\u043c-\u0442\u043e \u043f\u0440\u0438\u0447\u0438\u043d\u0430\u043c).&nbsp;\u041d\u0430\u0448 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f<\/p>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-318562","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/318562","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=318562"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/318562\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=318562"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=318562"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=318562"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}