Skip to content

Commit

Permalink
Merge pull request #128 from ssylver93/feature/WFPREV-34_3
Browse files Browse the repository at this point in the history
Post to Slack channel on quality gate failure
  • Loading branch information
ssylver93 authored Oct 2, 2024
2 parents 71a1a4d + 40fd533 commit b3e964d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/sonarscan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ jobs:
echo "quality_gate_failed=false" >> $GITHUB_OUTPUT
fi
- name: Notify Slack on Failure
- name: Notify Slack on Failure
if: failure() || steps.sonarcloud_quality_gate.outputs.quality_gate_failed == 'true'
uses: ravsamhq/[email protected]
with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,16 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti

http.csrf().disable();

http.authorizeHttpRequests().anyRequest().permitAll();

// http
// .oauth2ResourceServer(oauth2 -> oauth2
// .authenticationManagerResolver(authenticationManagerResolver())
// )
// .httpBasic().and()
// .authorizeHttpRequests((authorize) -> authorize
// .anyRequest().authenticated()
// )
// .exceptionHandling()
// .authenticationEntryPoint(authenticationEntryPoint());
http
.oauth2ResourceServer(oauth2 -> oauth2
.authenticationManagerResolver(authenticationManagerResolver())
)
.httpBasic().and()
.authorizeHttpRequests((authorize) -> authorize
.anyRequest().authenticated()
)
.exceptionHandling()
.authenticationEntryPoint(authenticationEntryPoint());

return http.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,35 @@

import org.junit.jupiter.api.Test;
import static org.mockito.ArgumentMatchers.eq;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import static org.mockito.Mockito.when;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Import;
import org.springframework.hateoas.CollectionModel;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import ca.bc.gov.nrs.wfprev.controllers.ExampleController;
import ca.bc.gov.nrs.wfprev.data.resources.ExampleCodeModel;
import ca.bc.gov.nrs.wfprev.data.resources.ExampleModel;
import ca.bc.gov.nrs.wfprev.services.ExampleService;

@Import(TestcontainersConfiguration.class)
@SpringBootTest
@AutoConfigureMockMvc
@WebMvcTest(ExampleController.class)
@Import({SecurityConfig.class, TestcontainersConfiguration.class})
class ExampleControllerTest {

@Mock
@MockBean
private ExampleService exampleService;

@InjectMocks
private ExampleController exampleController;

@Autowired
private MockMvc mockMvc;

@Test
@WithMockUser
void testGetAllExamples() throws Exception {
String exampleId1 = UUID.randomUUID().toString();
String exampleId2 = UUID.randomUUID().toString();
Expand All @@ -59,6 +56,7 @@ void testGetAllExamples() throws Exception {
}

@Test
@WithMockUser
void testGetExampleById() throws Exception {
String exampleId = UUID.randomUUID().toString();
ExampleModel exampleModel = new ExampleModel();
Expand All @@ -72,6 +70,7 @@ void testGetExampleById() throws Exception {
}

@Test
@WithMockUser
void testGetExampleByIdNotFound() throws Exception {
String exampleId = null;
ExampleModel exampleModel = new ExampleModel();
Expand All @@ -84,12 +83,27 @@ void testGetExampleByIdNotFound() throws Exception {
}

@Test
void getExampleCodeById() throws Exception {
@WithMockUser
void getUserNotFoundCodeById() throws Exception {
String exampleCodeId = "INVALID_CODE";

when(exampleService.getExampleCodeById(eq(exampleCodeId))).thenReturn(null);

mockMvc.perform(get("/wfprev/exampleCodes/{id}", exampleCodeId))
.andExpect(status().isOk());
.andExpect(status().isNotFound());
}

}
@Test
@WithMockUser
void getExampleCodeById() throws Exception {
String exampleCodeId = "VALID_CODE";
ExampleCodeModel exampleCodeModel = new ExampleCodeModel();
exampleCodeModel.setExampleCode(exampleCodeId);

when(exampleService.getExampleCodeById(eq(exampleCodeId))).thenReturn(exampleCodeModel);

mockMvc.perform(get("/wfprev/exampleCodes/{id}", exampleCodeId))
.andExpect(status().isOk());

}
}
1 change: 1 addition & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ sonar.test.inclusions=**/Test*.java,**/*Tests.java,**/*Test.java,**/*.spec.ts,**
sonar.java.binaries=server/wfprev-api/target/classes
sonar.java.test.binaries=server/wfprev-api/target/test-classes
sonar.java.coveragePlugin=jacoco
sonar.qualitygate.wait=true

0 comments on commit b3e964d

Please sign in to comment.