Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Team 14 - IDATT1002
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Eirik Steira
Team 14 - IDATT1002
Commits
6d7cfd61
Commit
6d7cfd61
authored
5 years ago
by
Mads Lundegaard
Browse files
Options
Downloads
Patches
Plain Diff
Added more javadoc
parent
665d9496
No related branches found
No related tags found
1 merge request
!50
Fix/login
Pipeline
#76382
passed
5 years ago
Stage: build
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/test/java/NTNU/IDATT1002/repository/LoginRepositoryTest.java
+50
-1
50 additions, 1 deletion
...t/java/NTNU/IDATT1002/repository/LoginRepositoryTest.java
with
50 additions
and
1 deletion
src/test/java/NTNU/IDATT1002/repository/LoginRepositoryTest.java
+
50
−
1
View file @
6d7cfd61
...
@@ -18,6 +18,13 @@ import java.util.Optional;
...
@@ -18,6 +18,13 @@ import java.util.Optional;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.*;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.*;
/**
* Tests for {@link LoginRepository}
*
* @author madslun
* @version 1.0 17.03.20
*/
class
LoginRepositoryTest
{
class
LoginRepositoryTest
{
...
@@ -34,7 +41,10 @@ class LoginRepositoryTest {
...
@@ -34,7 +41,10 @@ class LoginRepositoryTest {
private
Login
login2
;
private
Login
login2
;
/**
* Sets up some testdata for thorough testing
* So much information has been added for making sure every part works as intended
*/
@BeforeEach
@BeforeEach
public
void
setUp
()
{
public
void
setUp
()
{
EntityManagerFactory
entityManagerFactory
=
Persistence
.
createEntityManagerFactory
(
"ImageApplicationTest"
);
EntityManagerFactory
entityManagerFactory
=
Persistence
.
createEntityManagerFactory
(
"ImageApplicationTest"
);
...
@@ -52,12 +62,18 @@ class LoginRepositoryTest {
...
@@ -52,12 +62,18 @@ class LoginRepositoryTest {
loginRepository
=
new
LoginRepository
(
entityManager
);
loginRepository
=
new
LoginRepository
(
entityManager
);
}
}
/**
* Test that saving an entity returns the saved instance
*/
@Test
@Test
void
testSaveReturnsInstance
()
{
void
testSaveReturnsInstance
()
{
Optional
<
Login
>
optionalLogin
=
loginRepository
.
save
(
login1
);
Optional
<
Login
>
optionalLogin
=
loginRepository
.
save
(
login1
);
assertTrue
(
optionalLogin
.
isPresent
());
assertTrue
(
optionalLogin
.
isPresent
());
}
}
/**
* Test that finding all entities returns all entities
*/
@Test
@Test
void
testSaveReturnsAllSavedEntities
()
{
void
testSaveReturnsAllSavedEntities
()
{
...
@@ -68,6 +84,9 @@ class LoginRepositoryTest {
...
@@ -68,6 +84,9 @@ class LoginRepositoryTest {
assertEquals
(
2
,
foundLogins
.
size
());
assertEquals
(
2
,
foundLogins
.
size
());
}
}
/**
* Test that saving invalid entity will fail and return empty optional
*/
@Test
@Test
void
testSaveInvalidEntityReturnsEmptyOptional
()
{
void
testSaveInvalidEntityReturnsEmptyOptional
()
{
Optional
<
Login
>
savedLogin
=
loginRepository
.
save
(
null
);
Optional
<
Login
>
savedLogin
=
loginRepository
.
save
(
null
);
...
@@ -75,6 +94,9 @@ class LoginRepositoryTest {
...
@@ -75,6 +94,9 @@ class LoginRepositoryTest {
assertTrue
(
savedLogin
.
isEmpty
());
assertTrue
(
savedLogin
.
isEmpty
());
}
}
/**
* Test that finding entity by id returns optional with the correct id
*/
@Test
@Test
void
testFindByIdReturnsOptionalWithEntityWithId
()
{
void
testFindByIdReturnsOptionalWithEntityWithId
()
{
...
@@ -85,6 +107,9 @@ class LoginRepositoryTest {
...
@@ -85,6 +107,9 @@ class LoginRepositoryTest {
assertEquals
(
id1
,
foundLogins
.
get
().
getUser
().
getUsername
());
assertEquals
(
id1
,
foundLogins
.
get
().
getUser
().
getUsername
());
}
}
/**
* Test that deleting by id removes the given entity and returns empty optional
*/
@Test
@Test
void
testDeleteById
()
{
void
testDeleteById
()
{
loginRepository
.
save
(
login1
);
loginRepository
.
save
(
login1
);
...
@@ -96,6 +121,9 @@ class LoginRepositoryTest {
...
@@ -96,6 +121,9 @@ class LoginRepositoryTest {
assertTrue
(
deletedLogin
.
isEmpty
());
assertTrue
(
deletedLogin
.
isEmpty
());
}
}
/**
* Test that count returns correct amount of enities
*/
@Test
@Test
void
testCountReturnsAmountOfSavedEntities
()
{
void
testCountReturnsAmountOfSavedEntities
()
{
loginRepository
.
save
(
login1
);
loginRepository
.
save
(
login1
);
...
@@ -106,6 +134,9 @@ class LoginRepositoryTest {
...
@@ -106,6 +134,9 @@ class LoginRepositoryTest {
assertEquals
(
2
,
loginCount
);
assertEquals
(
2
,
loginCount
);
}
}
/**
* Test that a created user can log in
*/
@Test
@Test
void
testLogin
()
{
void
testLogin
()
{
ArrayList
<
String
>
credentials
=
Authentication
.
setPassword
(
password
);
ArrayList
<
String
>
credentials
=
Authentication
.
setPassword
(
password
);
...
@@ -117,6 +148,9 @@ class LoginRepositoryTest {
...
@@ -117,6 +148,9 @@ class LoginRepositoryTest {
assertTrue
(
loginRepository
.
logIn
(
id1
,
password
));
assertTrue
(
loginRepository
.
logIn
(
id1
,
password
));
}
}
/**
* Test that a created user can change the password
*/
@Test
@Test
void
testChangePassword
()
{
void
testChangePassword
()
{
ArrayList
<
String
>
credentials
=
Authentication
.
setPassword
(
password
);
ArrayList
<
String
>
credentials
=
Authentication
.
setPassword
(
password
);
...
@@ -128,6 +162,9 @@ class LoginRepositoryTest {
...
@@ -128,6 +162,9 @@ class LoginRepositoryTest {
assertTrue
(
loginRepository
.
changePassword
(
id1
,
password
,
newPassword
));
assertTrue
(
loginRepository
.
changePassword
(
id1
,
password
,
newPassword
));
}
}
/**
* Test that a user can log in, change password then log in again
*/
@Test
@Test
void
testLoginWithNewPassword
()
{
void
testLoginWithNewPassword
()
{
ArrayList
<
String
>
credentials
=
Authentication
.
setPassword
(
password
);
ArrayList
<
String
>
credentials
=
Authentication
.
setPassword
(
password
);
...
@@ -141,6 +178,9 @@ class LoginRepositoryTest {
...
@@ -141,6 +178,9 @@ class LoginRepositoryTest {
assertTrue
(
loginRepository
.
logIn
(
id1
,
newPassword
));
assertTrue
(
loginRepository
.
logIn
(
id1
,
newPassword
));
}
}
/**
* Test that trying to login with wrong password returns false
*/
@Test
@Test
void
testWrongPasswordDoesNotLogIn
()
{
void
testWrongPasswordDoesNotLogIn
()
{
ArrayList
<
String
>
credentials
=
Authentication
.
setPassword
(
password
);
ArrayList
<
String
>
credentials
=
Authentication
.
setPassword
(
password
);
...
@@ -151,6 +191,9 @@ class LoginRepositoryTest {
...
@@ -151,6 +191,9 @@ class LoginRepositoryTest {
assertFalse
(
loginRepository
.
logIn
(
id1
,
newPassword
));
assertFalse
(
loginRepository
.
logIn
(
id1
,
newPassword
));
}
}
/**
* Test that trying to change password with wrong password returns false
*/
@Test
@Test
void
testWrongPasswordDoesNotChangePassword
()
{
void
testWrongPasswordDoesNotChangePassword
()
{
ArrayList
<
String
>
credentials
=
Authentication
.
setPassword
(
password
);
ArrayList
<
String
>
credentials
=
Authentication
.
setPassword
(
password
);
...
@@ -162,6 +205,9 @@ class LoginRepositoryTest {
...
@@ -162,6 +205,9 @@ class LoginRepositoryTest {
assertTrue
(
loginRepository
.
logIn
(
id1
,
password
));
assertTrue
(
loginRepository
.
logIn
(
id1
,
password
));
}
}
/**
* Test that trying to login with null returns false
*/
@Test
@Test
void
testLoginWithNullReturnsFalse
()
{
void
testLoginWithNullReturnsFalse
()
{
ArrayList
<
String
>
credentials
=
Authentication
.
setPassword
(
password
);
ArrayList
<
String
>
credentials
=
Authentication
.
setPassword
(
password
);
...
@@ -172,6 +218,9 @@ class LoginRepositoryTest {
...
@@ -172,6 +218,9 @@ class LoginRepositoryTest {
assertFalse
(
loginRepository
.
logIn
(
id1
,
null
));
assertFalse
(
loginRepository
.
logIn
(
id1
,
null
));
}
}
/**
* Test that trying to login with null returns false
*/
@Test
@Test
void
testChangeWithNullReturnsFalse
()
{
void
testChangeWithNullReturnsFalse
()
{
ArrayList
<
String
>
credentials
=
Authentication
.
setPassword
(
password
);
ArrayList
<
String
>
credentials
=
Authentication
.
setPassword
(
password
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment