-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Development of Search Filter on Surname
- Loading branch information
Showing
73 changed files
with
8,382 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.geekhelp.test; | ||
|
||
import com.tngtech.archunit.core.domain.JavaClasses; | ||
import com.tngtech.archunit.core.importer.ClassFileImporter; | ||
import com.tngtech.archunit.core.importer.ImportOption; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses; | ||
|
||
class ArchTest { | ||
|
||
@Test | ||
void servicesAndRepositoriesShouldNotDependOnWebLayer() { | ||
|
||
JavaClasses importedClasses = new ClassFileImporter() | ||
.withImportOption(ImportOption.Predefined.DO_NOT_INCLUDE_TESTS) | ||
.importPackages("com.geekhelp.test"); | ||
|
||
noClasses() | ||
.that() | ||
.resideInAnyPackage("com.geekhelp.test.service..") | ||
.or() | ||
.resideInAnyPackage("com.geekhelp.test.repository..") | ||
.should().dependOnClassesThat() | ||
.resideInAnyPackage("..com.geekhelp.test.web..") | ||
.because("Services and repositories should not depend on web layer") | ||
.check(importedClasses); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/test/java/com/geekhelp/test/config/NoOpMailConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.geekhelp.test.config; | ||
|
||
import com.geekhelp.test.service.MailService; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.doNothing; | ||
import static org.mockito.Mockito.mock; | ||
|
||
@Configuration | ||
public class NoOpMailConfiguration { | ||
private final MailService mockMailService; | ||
|
||
public NoOpMailConfiguration() { | ||
mockMailService = mock(MailService.class); | ||
doNothing().when(mockMailService).sendActivationEmail(any()); | ||
} | ||
|
||
@Bean | ||
public MailService mailService() { | ||
return mockMailService; | ||
} | ||
} |
165 changes: 165 additions & 0 deletions
165
src/test/java/com/geekhelp/test/config/WebConfigurerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
package com.geekhelp.test.config; | ||
|
||
import io.github.jhipster.config.JHipsterConstants; | ||
import io.github.jhipster.config.JHipsterProperties; | ||
import io.github.jhipster.web.filter.CachingHttpHeadersFilter; | ||
import org.h2.server.web.WebServlet; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.mock.env.MockEnvironment; | ||
import org.springframework.mock.web.MockServletContext; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.setup.MockMvcBuilders; | ||
|
||
import javax.servlet.*; | ||
import java.io.File; | ||
import java.util.*; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.anyString; | ||
import static org.mockito.Mockito.*; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.options; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
/** | ||
* Unit tests for the {@link WebConfigurer} class. | ||
*/ | ||
public class WebConfigurerTest { | ||
|
||
private WebConfigurer webConfigurer; | ||
|
||
private MockServletContext servletContext; | ||
|
||
private MockEnvironment env; | ||
|
||
private JHipsterProperties props; | ||
|
||
@BeforeEach | ||
public void setup() { | ||
servletContext = spy(new MockServletContext()); | ||
doReturn(mock(FilterRegistration.Dynamic.class)) | ||
.when(servletContext).addFilter(anyString(), any(Filter.class)); | ||
doReturn(mock(ServletRegistration.Dynamic.class)) | ||
.when(servletContext).addServlet(anyString(), any(Servlet.class)); | ||
|
||
env = new MockEnvironment(); | ||
props = new JHipsterProperties(); | ||
|
||
webConfigurer = new WebConfigurer(env, props); | ||
} | ||
|
||
@Test | ||
public void testStartUpProdServletContext() throws ServletException { | ||
env.setActiveProfiles(JHipsterConstants.SPRING_PROFILE_PRODUCTION); | ||
webConfigurer.onStartup(servletContext); | ||
|
||
verify(servletContext).addFilter(eq("cachingHttpHeadersFilter"), any(CachingHttpHeadersFilter.class)); | ||
verify(servletContext, never()).addServlet(eq("H2Console"), any(WebServlet.class)); | ||
} | ||
|
||
@Test | ||
public void testStartUpDevServletContext() throws ServletException { | ||
env.setActiveProfiles(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT); | ||
webConfigurer.onStartup(servletContext); | ||
|
||
verify(servletContext, never()).addFilter(eq("cachingHttpHeadersFilter"), any(CachingHttpHeadersFilter.class)); | ||
verify(servletContext).addServlet(eq("H2Console"), any(WebServlet.class)); | ||
} | ||
|
||
@Test | ||
public void testCustomizeServletContainer() { | ||
env.setActiveProfiles(JHipsterConstants.SPRING_PROFILE_PRODUCTION); | ||
UndertowServletWebServerFactory container = new UndertowServletWebServerFactory(); | ||
webConfigurer.customize(container); | ||
assertThat(container.getMimeMappings().get("abs")).isEqualTo("audio/x-mpeg"); | ||
assertThat(container.getMimeMappings().get("html")).isEqualTo("text/html;charset=utf-8"); | ||
assertThat(container.getMimeMappings().get("json")).isEqualTo("text/html;charset=utf-8"); | ||
if (container.getDocumentRoot() != null) { | ||
assertThat(container.getDocumentRoot()).isEqualTo(new File("build/resources/main/static/")); | ||
} | ||
} | ||
|
||
@Test | ||
public void testCorsFilterOnApiPath() throws Exception { | ||
props.getCors().setAllowedOrigins(Collections.singletonList("*")); | ||
props.getCors().setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE")); | ||
props.getCors().setAllowedHeaders(Collections.singletonList("*")); | ||
props.getCors().setMaxAge(1800L); | ||
props.getCors().setAllowCredentials(true); | ||
|
||
MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()) | ||
.addFilters(webConfigurer.corsFilter()) | ||
.build(); | ||
|
||
mockMvc.perform( | ||
options("/api/test-cors") | ||
.header(HttpHeaders.ORIGIN, "other.domain.com") | ||
.header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "POST")) | ||
.andExpect(status().isOk()) | ||
.andExpect(header().string(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, "other.domain.com")) | ||
.andExpect(header().string(HttpHeaders.VARY, "Origin")) | ||
.andExpect(header().string(HttpHeaders.ACCESS_CONTROL_ALLOW_METHODS, "GET,POST,PUT,DELETE")) | ||
.andExpect(header().string(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS, "true")) | ||
.andExpect(header().string(HttpHeaders.ACCESS_CONTROL_MAX_AGE, "1800")); | ||
|
||
mockMvc.perform( | ||
get("/api/test-cors") | ||
.header(HttpHeaders.ORIGIN, "other.domain.com")) | ||
.andExpect(status().isOk()) | ||
.andExpect(header().string(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, "other.domain.com")); | ||
} | ||
|
||
@Test | ||
public void testCorsFilterOnOtherPath() throws Exception { | ||
props.getCors().setAllowedOrigins(Collections.singletonList("*")); | ||
props.getCors().setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE")); | ||
props.getCors().setAllowedHeaders(Collections.singletonList("*")); | ||
props.getCors().setMaxAge(1800L); | ||
props.getCors().setAllowCredentials(true); | ||
|
||
MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()) | ||
.addFilters(webConfigurer.corsFilter()) | ||
.build(); | ||
|
||
mockMvc.perform( | ||
get("/test/test-cors") | ||
.header(HttpHeaders.ORIGIN, "other.domain.com")) | ||
.andExpect(status().isOk()) | ||
.andExpect(header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN)); | ||
} | ||
|
||
@Test | ||
public void testCorsFilterDeactivated() throws Exception { | ||
props.getCors().setAllowedOrigins(null); | ||
|
||
MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()) | ||
.addFilters(webConfigurer.corsFilter()) | ||
.build(); | ||
|
||
mockMvc.perform( | ||
get("/api/test-cors") | ||
.header(HttpHeaders.ORIGIN, "other.domain.com")) | ||
.andExpect(status().isOk()) | ||
.andExpect(header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN)); | ||
} | ||
|
||
@Test | ||
public void testCorsFilterDeactivated2() throws Exception { | ||
props.getCors().setAllowedOrigins(new ArrayList<>()); | ||
|
||
MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()) | ||
.addFilters(webConfigurer.corsFilter()) | ||
.build(); | ||
|
||
mockMvc.perform( | ||
get("/api/test-cors") | ||
.header(HttpHeaders.ORIGIN, "other.domain.com")) | ||
.andExpect(status().isOk()) | ||
.andExpect(header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN)); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/test/java/com/geekhelp/test/config/WebConfigurerTestController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.geekhelp.test.config; | ||
|
||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
public class WebConfigurerTestController { | ||
|
||
@GetMapping("/api/test-cors") | ||
public void testCorsOnApiPath() { | ||
} | ||
|
||
@GetMapping("/test/test-cors") | ||
public void testCorsOnOtherPath() { | ||
} | ||
} |
Oops, something went wrong.