Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
minerva
core
Commits
44c50dc5
Commit
44c50dc5
authored
Jun 19, 2019
by
Sascha Herzinger
Browse files
First working integration test for api
parent
b0e00e01
Pipeline
#10846
failed with stage
in 62 minutes and 30 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
pom.xml
View file @
44c50dc5
...
...
@@ -105,8 +105,11 @@
<reflections.version>
0.9.11
</reflections.version>
<osgi.version>
1.0.0
</osgi.version>
<junit.version>
4.12
</junit.version>
<hamcrest.version>
2.1
</hamcrest.version>
<surefire-api.version>
2.22.2
</surefire-api.version>
<surefire.rerunFailingTestsCount>
4
</surefire.rerunFailingTestsCount>
...
...
web/pom.xml
View file @
44c50dc5
...
...
@@ -238,6 +238,13 @@
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.hamcrest
</groupId>
<artifactId>
hamcrest
</artifactId>
<version>
${hamcrest.version}
</version>
<scope>
test
</scope>
</dependency>
</dependencies>
<build>
...
...
web/src/main/java/lcsb/mapviewer/web/config/SpringSecurityConfig.java
View file @
44c50dc5
...
...
@@ -94,6 +94,7 @@ public class SpringSecurityConfig extends WebSecurityConfigurerAdapter {
.
cors
()
.
and
()
.
logout
()
.
logoutUrl
(
"/api/doLogout"
)
.
deleteCookies
(
lcsb
.
mapviewer
.
common
.
Configuration
.
AUTH_TOKEN
);
}
...
...
web/src/main/java/lcsb/mapviewer/web/config/SpringWebConfig.java
View file @
44c50dc5
...
...
@@ -10,7 +10,7 @@ import org.springframework.web.servlet.config.annotation.*;
@EnableWebMvc
@Import
(
SpringRestApiConfig
.
class
)
@ComponentScan
(
basePackages
=
{
"lcsb.mapviewer.web"
})
public
class
SpringWebConfig
ext
en
d
s
WebMvcConfigurer
Adapter
{
public
class
SpringWebConfig
implem
en
t
s
WebMvcConfigurer
{
@Override
public
void
addViewControllers
(
ViewControllerRegistry
registry
)
{
...
...
web/src/test/java/lcsb/mapviewer/web/
ProjectController
IntegrationTest.java
→
web/src/test/java/lcsb/mapviewer/web/
SpringSecurityGeneral
IntegrationTest.java
View file @
44c50dc5
package
lcsb.mapviewer.web
;
import
lcsb.mapviewer.model.user.User
;
import
lcsb.mapviewer.services.interfaces.IUserService
;
import
lcsb.mapviewer.web.config.SpringWebConfig
;
import
org.json.simple.JSONObject
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.*
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.
http.MediaType
;
import
org.springframework.
security.crypto.password.PasswordEncoder
;
import
org.springframework.test.context.ContextConfiguration
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.test.context.web.WebAppConfiguration
;
import
org.springframework.test.web.servlet.MockMvc
;
import
org.springframework.test.web.servlet.RequestBuilder
;
import
org.springframework.test.web.servlet.setup.MockMvcBuilders
;
import
org.springframework.web.context.WebApplicationContext
;
import
java.util.HashMap
;
import
java.util.Map
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.*;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.*;
import
static
org
.
springframework
.
security
.
test
.
web
.
servlet
.
setup
.
SecurityMockMvcConfigurers
.*;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@ContextConfiguration
(
classes
=
{
SpringWebConfig
.
class
})
@WebAppConfiguration
public
class
ProjectControllerIntegrationTest
{
@ContextConfiguration
(
classes
=
SpringWebConfig
.
class
)
public
class
SpringSecurityGeneralIntegrationTest
{
private
final
static
MediaType
JSON
=
MediaType
.
APPLICATION_JSON_UTF8
;
private
MockMvc
mockMvc
;
@Autowired
private
WebApplicationContext
context
;
...
...
@@ -34,20 +33,43 @@ public class ProjectControllerIntegrationTest {
@Autowired
private
IUserService
userService
;
private
MockMvc
mockMvc
;
@Autowired
private
PasswordEncoder
passwordEncoder
;
private
User
user
=
new
User
();
@Before
public
void
setup
()
{
mockMvc
=
MockMvcBuilders
.
webAppContextSetup
(
context
).
build
();
mockMvc
=
MockMvcBuilders
.
webAppContextSetup
(
context
)
.
apply
(
springSecurity
())
.
build
();
user
.
setLogin
(
"test_user"
);
user
.
setCryptedPassword
(
passwordEncoder
.
encode
(
"test_pass"
));
userService
.
addUser
(
user
);
}
@After
public
void
teardown
()
{
userService
.
deleteUser
(
user
);
}
@Test
public
void
loginWorks
()
throws
Exception
{
Map
<
String
,
String
>
params
=
new
HashMap
<>();
params
.
put
(
"login"
,
"test_user"
);
params
.
put
(
"password"
,
"test_pass"
);
String
body
=
new
JSONObject
(
params
).
toJSONString
();
mockMvc
.
perform
(
post
(
"/api/doLogin"
).
contentType
(
JSON
).
content
(
body
))
public
void
login2xxWithValidCredentials
()
throws
Exception
{
RequestBuilder
request
=
post
(
"/api/doLogin"
)
.
param
(
"login"
,
"test_user"
)
.
param
(
"password"
,
"test_pass"
);
mockMvc
.
perform
(
request
)
.
andExpect
(
status
().
isOk
());
}
@Test
public
void
login4xxWithInvalidCredentials
()
throws
Exception
{
RequestBuilder
request
=
post
(
"/api/doLogin"
)
.
param
(
"login"
,
"test_user"
)
.
param
(
"password"
,
"test_foo"
);
mockMvc
.
perform
(
request
)
.
andExpect
(
status
().
is4xxClientError
());
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment