* BAEL-1271 - initial commit

* BAEL-1271 - created an admin server and a client app that registers to

* BAEL-1271 - added security on admin server/on client actuator endpoints

* BAEL-1271 - configured mail notifications

* added unit test coverage

* added unit test coverage

* hipchat configuration
This commit is contained in:
Bogdan Stoean
2017-11-02 17:44:01 +02:00
committed by maibin
parent 6365159f68
commit 45997664ad
18 changed files with 601 additions and 0 deletions
@@ -0,0 +1,55 @@
package com.baeldung.springbootadminclient;
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.core.env.Environment;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import static org.junit.Assert.assertEquals;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.httpBasic;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = RANDOM_PORT)
public class SpringBootAdminClientApplicationTests {
@Autowired Environment environment;
@Autowired WebApplicationContext wac;
private MockMvc mockMvc;
@Before
public void setup() {
mockMvc = MockMvcBuilders
.webAppContextSetup(wac)
.build();
}
@Test
public void whenEnvironmentAvailable_ThenAdminServerPropertiesExist() {
assertEquals(environment.getProperty("spring.boot.admin.url"), "http://localhost:8080");
assertEquals(environment.getProperty("spring.boot.admin.username"), "admin");
assertEquals(environment.getProperty("spring.boot.admin.password"), "admin");
}
@Test
public void whenHttpBasicAttempted_ThenSuccess() throws Exception {
mockMvc.perform(get("/env").with(httpBasic("client", "client")));
}
@Test
public void whenInvalidHttpBasicAttempted_ThenUnauthorized() throws Exception {
mockMvc
.perform(get("/env").with(httpBasic("client", "invalid")))
.andExpect(status().isUnauthorized());
}
}