BAEL-5061 Joinpoint vs. ProceedingJoinPoint in AspectJ (#11209)
* BAEL-5061 Joinpoint vs. ProceedingJoinPoint in AspectJ * BAEL-5061 Joinpoint vs. ProceedingJoinPoint in AspectJ * BAEL-5061 Joinpoint vs. ProceedingJoinPoint in AspectJ * BAEL-5061 Joinpoint vs. ProceedingJoinPoint in AspectJ * BAEL-5061 Joinpoint vs. ProceedingJoinPoint in AspectJ * BAEL-5061 Joinpoint vs. ProceedingJoinPoint in AspectJ - add tests * BAEL-5061 Joinpoint vs. ProceedingJoinPoint in AspectJ - add tests * BAEL-5061 Joinpoint vs. ProceedingJoinPoint in AspectJ - add tests * BAEL-5061 Joinpoint vs. ProceedingJoinPoint in AspectJ - add tests Co-authored-by: majewsk6 <krzysztof.majewski.km1@contractors.roche.com>
This commit is contained in:
committed by
GitHub
parent
8fc8af79bf
commit
141a837679
@@ -0,0 +1,39 @@
|
||||
package com.baeldung.joinpoint;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringBootTest
|
||||
public class ArticleServiceIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private ArticleService articleService;
|
||||
|
||||
@Test
|
||||
public void shouldGetNotEmptyArticleList() {
|
||||
List<String> articleList = articleService.getArticleList();
|
||||
|
||||
assertFalse(articleList.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldGetNotEmptyArticleListWithStartsWithFilter() {
|
||||
List<String> articleList = articleService.getArticleList("Article");
|
||||
|
||||
assertFalse(articleList.isEmpty());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void shouldThrowExceptionIfStartsWithFilterIsBlank() {
|
||||
articleService.getArticleList(" ");
|
||||
}
|
||||
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
package com.baeldung.joinpoint;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.LogRecord;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringBootTest
|
||||
@EnableAspectJAutoProxy
|
||||
public class JoinPointAfterThrowingAspectIntegrationTest {
|
||||
|
||||
private final List<String> messages = new ArrayList<>();
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
Handler logEventHandler = new Handler() {
|
||||
@Override
|
||||
public void publish(LogRecord record) {
|
||||
messages.add(record.getLevel().getName() + " " + record.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws SecurityException {
|
||||
}
|
||||
};
|
||||
|
||||
Logger logger = Logger.getLogger(JoinPointAfterThrowingAspect.class.getName());
|
||||
logger.addHandler(logEventHandler);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private ArticleService articleService;
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void shouldLogMethodSignatureBeforeExecution() {
|
||||
articleService.getArticleList(" ");
|
||||
|
||||
assertThat(messages, hasSize(1));
|
||||
assertTrue(messages.contains("SEVERE startsWithFilter can't be blank"));
|
||||
}
|
||||
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package com.baeldung.joinpoint;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringBootTest
|
||||
@EnableAspectJAutoProxy
|
||||
public class JoinPointAroundCacheAspectIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private ArticleService articleService;
|
||||
|
||||
@Test
|
||||
public void shouldPopulateCache() {
|
||||
assertTrue(JoinPointAroundCacheAspect.CACHE.isEmpty());
|
||||
|
||||
List<String> articles = articleService.getArticleList();
|
||||
|
||||
assertFalse(JoinPointAroundCacheAspect.CACHE.isEmpty());
|
||||
assertEquals(JoinPointAroundCacheAspect.CACHE.size(), 1);
|
||||
assertEquals(JoinPointAroundCacheAspect.CACHE.values().iterator().next(), articles);
|
||||
}
|
||||
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
package com.baeldung.joinpoint;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.LogRecord;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringBootTest
|
||||
@EnableAspectJAutoProxy
|
||||
public class JoinPointAroundExceptionAspectIntegrationTest {
|
||||
|
||||
private final List<String> messages = new ArrayList<>();
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
Handler logEventHandler = new Handler() {
|
||||
@Override
|
||||
public void publish(LogRecord record) {
|
||||
messages.add(record.getLevel().getName() + " " + record.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws SecurityException {
|
||||
}
|
||||
};
|
||||
|
||||
Logger logger = Logger.getLogger(JoinPointAroundExceptionAspect.class.getName());
|
||||
logger.addHandler(logEventHandler);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private ArticleService articleService;
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void shouldLogMethodSignatureBeforeExecution() {
|
||||
articleService.getArticleList(" ");
|
||||
|
||||
assertThat(messages, hasSize(1));
|
||||
assertTrue(messages.contains("INFO Retrying operation"));
|
||||
}
|
||||
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
package com.baeldung.joinpoint;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.LogRecord;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringBootTest
|
||||
@EnableAspectJAutoProxy
|
||||
public class JoinPointBeforeAspectIntegrationTest {
|
||||
|
||||
private final List<String> messages = new ArrayList<>();
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
Handler logEventHandler = new Handler() {
|
||||
@Override
|
||||
public void publish(LogRecord record) {
|
||||
messages.add(record.getLevel().getName() + " " + record.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws SecurityException {
|
||||
}
|
||||
};
|
||||
|
||||
Logger logger = Logger.getLogger(JoinPointBeforeAspect.class.getName());
|
||||
logger.addHandler(logEventHandler);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private ArticleService articleService;
|
||||
|
||||
@Test
|
||||
public void shouldLogMethodSignatureBeforeExecution() {
|
||||
articleService.getArticleList();
|
||||
|
||||
assertThat(messages, hasSize(1));
|
||||
assertTrue(messages.contains("INFO Method List com.baeldung.joinpoint.ArticleService.getArticleList() executed with [] arguments"));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user