parent
bdbee879af
commit
34ad3ad29b
@ -65,6 +65,24 @@
|
|||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>${maven-surefire-plugin.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<forkCount>3</forkCount>
|
||||||
|
<reuseForks>true</reuseForks>
|
||||||
|
<excludes>
|
||||||
|
<exclude>**/*IntegrationTest.java</exclude>
|
||||||
|
<exclude>**/*LongRunningUnitTest.java</exclude>
|
||||||
|
<exclude>**/*ManualTest.java</exclude>
|
||||||
|
<exclude>**/JdbcTest.java</exclude>
|
||||||
|
<exclude>**/*LiveTest.java</exclude>
|
||||||
|
</excludes>
|
||||||
|
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
@ -107,4 +125,5 @@
|
|||||||
</pluginRepositories>
|
</pluginRepositories>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
@ -7,7 +7,7 @@ import org.springframework.test.context.junit4.SpringRunner;
|
|||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
public class CasSecuredAppApplicationTests {
|
public class CasSecuredAppApplicationIntegrationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void contextLoads() {
|
public void contextLoads() {
|
@ -19,7 +19,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
|||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest(webEnvironment = RANDOM_PORT)
|
@SpringBootTest(webEnvironment = RANDOM_PORT)
|
||||||
public class SpringBootAdminClientApplicationTests {
|
public class SpringBootAdminClientApplicationIntegrationTest {
|
||||||
|
|
||||||
@Autowired Environment environment;
|
@Autowired Environment environment;
|
||||||
|
|
@ -13,7 +13,7 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
|
|||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest(classes = { HazelcastConfig.class }, webEnvironment = NONE)
|
@SpringBootTest(classes = { HazelcastConfig.class }, webEnvironment = NONE)
|
||||||
public class HazelcastConfigTest {
|
public class HazelcastConfigIntegrationTest {
|
||||||
|
|
||||||
@Autowired private ApplicationContext applicationContext;
|
@Autowired private ApplicationContext applicationContext;
|
||||||
|
|
@ -16,7 +16,7 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
|
|||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest(classes = { NotifierConfiguration.class }, webEnvironment = NONE)
|
@SpringBootTest(classes = { NotifierConfiguration.class }, webEnvironment = NONE)
|
||||||
public class NotifierConfigurationTest {
|
public class NotifierConfigurationIntegrationTest {
|
||||||
|
|
||||||
@Autowired private ApplicationContext applicationContext;
|
@Autowired private ApplicationContext applicationContext;
|
||||||
|
|
@ -17,7 +17,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
|||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||||
public class WebSecurityConfigTest {
|
public class WebSecurityConfigIntegrationTest {
|
||||||
|
|
||||||
@Autowired WebApplicationContext wac;
|
@Autowired WebApplicationContext wac;
|
||||||
|
|
@ -20,7 +20,7 @@ import static org.mockito.Mockito.when;
|
|||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@SpringBootTest(classes = SpringBoot.class)
|
@SpringBootTest(classes = SpringBoot.class)
|
||||||
public class KeycloakConfigurationTest {
|
public class KeycloakConfigurationIntegrationTest {
|
||||||
|
|
||||||
@Spy
|
@Spy
|
||||||
private KeycloakSecurityContextClientRequestInterceptor factory;
|
private KeycloakSecurityContextClientRequestInterceptor factory;
|
@ -14,7 +14,7 @@ import org.springframework.test.context.junit4.SpringRunner;
|
|||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@ContextConfiguration(classes = DataSourceRoutingTestConfiguration.class)
|
@ContextConfiguration(classes = DataSourceRoutingTestConfiguration.class)
|
||||||
public class DataSourceRoutingTests {
|
public class DataSourceRoutingIntegrationTest {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
DataSource routingDatasource;
|
DataSource routingDatasource;
|
@ -35,19 +35,17 @@ public class DataSourceRoutingTestConfiguration {
|
|||||||
|
|
||||||
private DataSource clientADatasource() {
|
private DataSource clientADatasource() {
|
||||||
EmbeddedDatabaseBuilder dbBuilder = new EmbeddedDatabaseBuilder();
|
EmbeddedDatabaseBuilder dbBuilder = new EmbeddedDatabaseBuilder();
|
||||||
EmbeddedDatabase embeddedDb = dbBuilder.setType(EmbeddedDatabaseType.H2)
|
return dbBuilder.setType(EmbeddedDatabaseType.H2)
|
||||||
.setName("CLIENT_A")
|
.setName("CLIENT_A")
|
||||||
.addScript("classpath:dsrouting-db.sql")
|
.addScript("classpath:dsrouting-db.sql")
|
||||||
.build();
|
.build();
|
||||||
return embeddedDb;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private DataSource clientBDatasource() {
|
private DataSource clientBDatasource() {
|
||||||
EmbeddedDatabaseBuilder dbBuilder = new EmbeddedDatabaseBuilder();
|
EmbeddedDatabaseBuilder dbBuilder = new EmbeddedDatabaseBuilder();
|
||||||
EmbeddedDatabase embeddedDb = dbBuilder.setType(EmbeddedDatabaseType.H2)
|
return dbBuilder.setType(EmbeddedDatabaseType.H2)
|
||||||
.setName("CLIENT_B")
|
.setName("CLIENT_B")
|
||||||
.addScript("classpath:dsrouting-db.sql")
|
.addScript("classpath:dsrouting-db.sql")
|
||||||
.build();
|
.build();
|
||||||
return embeddedDb;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package org.baeldung.properties;
|
package org.baeldung.properties;
|
||||||
|
|
||||||
import org.baeldung.properties.ConfigProperties;
|
|
||||||
import org.baeldung.properties.ConfigPropertiesDemoApplication;
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
@ -7,7 +7,7 @@ import org.springframework.test.context.junit4.SpringRunner;
|
|||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
public class SpringJMeterJenkinsApplicationTests {
|
public class SpringJMeterJenkinsApplicationIntegrationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void contextLoads() {
|
public void contextLoads() {
|
@ -1,119 +1,119 @@
|
|||||||
package org.baeldung.acl;
|
package org.baeldung.acl;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.baeldung.acl.persistence.dao.NoticeMessageRepository;
|
import org.baeldung.acl.persistence.dao.NoticeMessageRepository;
|
||||||
import org.baeldung.acl.persistence.entity.NoticeMessage;
|
import org.baeldung.acl.persistence.entity.NoticeMessage;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.security.access.AccessDeniedException;
|
import org.springframework.security.access.AccessDeniedException;
|
||||||
import org.springframework.security.test.context.support.WithMockUser;
|
import org.springframework.security.test.context.support.WithMockUser;
|
||||||
import org.springframework.security.test.context.support.WithSecurityContextTestExecutionListener;
|
import org.springframework.security.test.context.support.WithSecurityContextTestExecutionListener;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.TestExecutionListeners;
|
import org.springframework.test.context.TestExecutionListeners;
|
||||||
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
|
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
|
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
|
||||||
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;
|
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;
|
||||||
import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
|
import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
|
||||||
import org.springframework.test.context.web.ServletTestExecutionListener;
|
import org.springframework.test.context.web.ServletTestExecutionListener;
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration
|
@ContextConfiguration
|
||||||
@TestExecutionListeners(listeners={ServletTestExecutionListener.class,
|
@TestExecutionListeners(listeners={ServletTestExecutionListener.class,
|
||||||
DependencyInjectionTestExecutionListener.class,
|
DependencyInjectionTestExecutionListener.class,
|
||||||
DirtiesContextTestExecutionListener.class,
|
DirtiesContextTestExecutionListener.class,
|
||||||
TransactionalTestExecutionListener.class,
|
TransactionalTestExecutionListener.class,
|
||||||
WithSecurityContextTestExecutionListener.class})
|
WithSecurityContextTestExecutionListener.class})
|
||||||
public class SpringAclTest extends AbstractJUnit4SpringContextTests{
|
public class SpringAclIntegrationTest extends AbstractJUnit4SpringContextTests{
|
||||||
|
|
||||||
private static Integer FIRST_MESSAGE_ID = 1;
|
private static Integer FIRST_MESSAGE_ID = 1;
|
||||||
private static Integer SECOND_MESSAGE_ID = 2;
|
private static Integer SECOND_MESSAGE_ID = 2;
|
||||||
private static Integer THIRD_MESSAGE_ID = 3;
|
private static Integer THIRD_MESSAGE_ID = 3;
|
||||||
private static String EDITTED_CONTENT = "EDITED";
|
private static String EDITTED_CONTENT = "EDITED";
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@ComponentScan("org.baeldung.acl.*")
|
@ComponentScan("org.baeldung.acl.*")
|
||||||
public static class SpringConfig {
|
public static class SpringConfig {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
NoticeMessageRepository repo;
|
NoticeMessageRepository repo;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@WithMockUser(username="manager")
|
@WithMockUser(username="manager")
|
||||||
public void givenUsernameManager_whenFindAllMessage_thenReturnFirstMessage(){
|
public void givenUsernameManager_whenFindAllMessage_thenReturnFirstMessage(){
|
||||||
List<NoticeMessage> details = repo.findAll();
|
List<NoticeMessage> details = repo.findAll();
|
||||||
assertNotNull(details);
|
assertNotNull(details);
|
||||||
assertEquals(1,details.size());
|
assertEquals(1,details.size());
|
||||||
assertEquals(FIRST_MESSAGE_ID,details.get(0).getId());
|
assertEquals(FIRST_MESSAGE_ID,details.get(0).getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@WithMockUser(username="manager")
|
@WithMockUser(username="manager")
|
||||||
public void givenUsernameManager_whenFindFirstMessageByIdAndUpdateFirstMessageContent_thenOK(){
|
public void givenUsernameManager_whenFindFirstMessageByIdAndUpdateFirstMessageContent_thenOK(){
|
||||||
NoticeMessage firstMessage = repo.findById(FIRST_MESSAGE_ID);
|
NoticeMessage firstMessage = repo.findById(FIRST_MESSAGE_ID);
|
||||||
assertNotNull(firstMessage);
|
assertNotNull(firstMessage);
|
||||||
assertEquals(FIRST_MESSAGE_ID,firstMessage.getId());
|
assertEquals(FIRST_MESSAGE_ID,firstMessage.getId());
|
||||||
|
|
||||||
firstMessage.setContent(EDITTED_CONTENT);
|
firstMessage.setContent(EDITTED_CONTENT);
|
||||||
repo.save(firstMessage);
|
repo.save(firstMessage);
|
||||||
|
|
||||||
NoticeMessage editedFirstMessage = repo.findById(FIRST_MESSAGE_ID);
|
NoticeMessage editedFirstMessage = repo.findById(FIRST_MESSAGE_ID);
|
||||||
assertNotNull(editedFirstMessage);
|
assertNotNull(editedFirstMessage);
|
||||||
assertEquals(FIRST_MESSAGE_ID,editedFirstMessage.getId());
|
assertEquals(FIRST_MESSAGE_ID,editedFirstMessage.getId());
|
||||||
assertEquals(EDITTED_CONTENT,editedFirstMessage.getContent());
|
assertEquals(EDITTED_CONTENT,editedFirstMessage.getContent());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@WithMockUser(username="hr")
|
@WithMockUser(username="hr")
|
||||||
public void givenUsernameHr_whenFindMessageById2_thenOK(){
|
public void givenUsernameHr_whenFindMessageById2_thenOK(){
|
||||||
NoticeMessage secondMessage = repo.findById(SECOND_MESSAGE_ID);
|
NoticeMessage secondMessage = repo.findById(SECOND_MESSAGE_ID);
|
||||||
assertNotNull(secondMessage);
|
assertNotNull(secondMessage);
|
||||||
assertEquals(SECOND_MESSAGE_ID,secondMessage.getId());
|
assertEquals(SECOND_MESSAGE_ID,secondMessage.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=AccessDeniedException.class)
|
@Test(expected=AccessDeniedException.class)
|
||||||
@WithMockUser(username="hr")
|
@WithMockUser(username="hr")
|
||||||
public void givenUsernameHr_whenUpdateMessageWithId2_thenFail(){
|
public void givenUsernameHr_whenUpdateMessageWithId2_thenFail(){
|
||||||
NoticeMessage secondMessage = new NoticeMessage();
|
NoticeMessage secondMessage = new NoticeMessage();
|
||||||
secondMessage.setId(SECOND_MESSAGE_ID);
|
secondMessage.setId(SECOND_MESSAGE_ID);
|
||||||
secondMessage.setContent(EDITTED_CONTENT);
|
secondMessage.setContent(EDITTED_CONTENT);
|
||||||
repo.save(secondMessage);
|
repo.save(secondMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@WithMockUser(roles={"EDITOR"})
|
@WithMockUser(roles={"EDITOR"})
|
||||||
public void givenRoleEditor_whenFindAllMessage_thenReturnThreeMessage(){
|
public void givenRoleEditor_whenFindAllMessage_thenReturnThreeMessage(){
|
||||||
List<NoticeMessage> details = repo.findAll();
|
List<NoticeMessage> details = repo.findAll();
|
||||||
assertNotNull(details);
|
assertNotNull(details);
|
||||||
assertEquals(3,details.size());
|
assertEquals(3,details.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@WithMockUser(roles={"EDITOR"})
|
@WithMockUser(roles={"EDITOR"})
|
||||||
public void givenRoleEditor_whenUpdateThirdMessage_thenOK(){
|
public void givenRoleEditor_whenUpdateThirdMessage_thenOK(){
|
||||||
NoticeMessage thirdMessage = new NoticeMessage();
|
NoticeMessage thirdMessage = new NoticeMessage();
|
||||||
thirdMessage.setId(THIRD_MESSAGE_ID);
|
thirdMessage.setId(THIRD_MESSAGE_ID);
|
||||||
thirdMessage.setContent(EDITTED_CONTENT);
|
thirdMessage.setContent(EDITTED_CONTENT);
|
||||||
repo.save(thirdMessage);
|
repo.save(thirdMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=AccessDeniedException.class)
|
@Test(expected=AccessDeniedException.class)
|
||||||
@WithMockUser(roles={"EDITOR"})
|
@WithMockUser(roles={"EDITOR"})
|
||||||
public void givenRoleEditor_whenFindFirstMessageByIdAndUpdateFirstMessageContent_thenFail(){
|
public void givenRoleEditor_whenFindFirstMessageByIdAndUpdateFirstMessageContent_thenFail(){
|
||||||
NoticeMessage firstMessage = repo.findById(FIRST_MESSAGE_ID);
|
NoticeMessage firstMessage = repo.findById(FIRST_MESSAGE_ID);
|
||||||
assertNotNull(firstMessage);
|
assertNotNull(firstMessage);
|
||||||
assertEquals(FIRST_MESSAGE_ID,firstMessage.getId());
|
assertEquals(FIRST_MESSAGE_ID,firstMessage.getId());
|
||||||
firstMessage.setContent(EDITTED_CONTENT);
|
firstMessage.setContent(EDITTED_CONTENT);
|
||||||
repo.save(firstMessage);
|
repo.save(firstMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user