-
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.
- Loading branch information
Showing
29 changed files
with
440 additions
and
44 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
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
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
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
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
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
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
19 changes: 19 additions & 0 deletions
19
src/main/java/edu/tamu/app/model/repo/specification/ServiceSpecification.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,19 @@ | ||
package edu.tamu.app.model.repo.specification; | ||
|
||
import java.util.Map; | ||
|
||
import javax.persistence.criteria.CriteriaBuilder; | ||
import javax.persistence.criteria.CriteriaQuery; | ||
import javax.persistence.criteria.Root; | ||
|
||
public class ServiceSpecification<E> extends AbstractSpecification<E> { | ||
|
||
public ServiceSpecification(Map<String, String[]> filters) { | ||
super(filters); | ||
} | ||
|
||
@Override | ||
protected void toPredicateDefaultQueryOrderBy(Root<E> root, CriteriaQuery<?> query, CriteriaBuilder cb) { | ||
query.orderBy(cb.desc(root.get("name"))); | ||
} | ||
} |
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
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
32 changes: 32 additions & 0 deletions
32
src/test/java/edu/tamu/app/auth/model/AppUserDetailsTest.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,32 @@ | ||
package edu.tamu.app.auth.model; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
|
||
import edu.tamu.app.enums.Role; | ||
import edu.tamu.app.model.User; | ||
import edu.tamu.weaver.auth.model.Credentials; | ||
|
||
@RunWith(SpringRunner.class) | ||
public class AppUserDetailsTest { | ||
|
||
private static final Credentials TEST_CREDENTIALS = new Credentials(); | ||
static { | ||
TEST_CREDENTIALS.setUin("123456789"); | ||
TEST_CREDENTIALS.setEmail("aggieJack@tamu.edu"); | ||
TEST_CREDENTIALS.setFirstName("Aggie"); | ||
TEST_CREDENTIALS.setLastName("Jack"); | ||
TEST_CREDENTIALS.setRole("ROLE_USER"); | ||
} | ||
|
||
private User testUser = new User(TEST_CREDENTIALS.getUin(), TEST_CREDENTIALS.getEmail(), TEST_CREDENTIALS.getFirstName(), TEST_CREDENTIALS.getLastName(), Role.valueOf(TEST_CREDENTIALS.getRole())); | ||
|
||
@Test | ||
public void testConstructor() { | ||
AppUserDetails appUser = new AppUserDetails(testUser); | ||
assertEquals("The parent constructor was not called correctly", testUser.getId(), appUser.getId()); | ||
} | ||
} |
116 changes: 116 additions & 0 deletions
116
src/test/java/edu/tamu/app/auth/service/AppUserCredentialsServiceTest.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,116 @@ | ||
package edu.tamu.app.auth.service; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.mockito.Matchers.any; | ||
import static org.mockito.Mockito.when; | ||
import static org.springframework.test.util.ReflectionTestUtils.setField; | ||
|
||
import java.util.Optional; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
|
||
import edu.tamu.app.enums.Role; | ||
import edu.tamu.app.model.User; | ||
import edu.tamu.app.model.repo.UserRepo; | ||
import edu.tamu.weaver.auth.model.Credentials; | ||
|
||
@RunWith(SpringRunner.class) | ||
public class AppUserCredentialsServiceTest { | ||
|
||
private static final Credentials TEST_CREDENTIALS_1 = new Credentials(); | ||
static { | ||
TEST_CREDENTIALS_1.setUin("123456789"); | ||
TEST_CREDENTIALS_1.setEmail("aggieJack@tamu.edu"); | ||
TEST_CREDENTIALS_1.setFirstName("Aggie"); | ||
TEST_CREDENTIALS_1.setLastName("Jack"); | ||
TEST_CREDENTIALS_1.setRole("ROLE_USER"); | ||
} | ||
|
||
private static final Credentials TEST_CREDENTIALS_2 = new Credentials(); | ||
static { | ||
TEST_CREDENTIALS_2.setUin("987654321"); | ||
TEST_CREDENTIALS_2.setEmail("aggieJack@tamu.edu"); | ||
TEST_CREDENTIALS_2.setFirstName("Aggie"); | ||
TEST_CREDENTIALS_2.setLastName("Jack"); | ||
TEST_CREDENTIALS_2.setRole("ROLE_USER"); | ||
} | ||
|
||
private static final Credentials TEST_NULL_CREDENTIALS = new Credentials(); | ||
static { | ||
TEST_NULL_CREDENTIALS.setUin("987654321"); | ||
TEST_NULL_CREDENTIALS.setEmail("aggieJack@tamu.edu"); | ||
TEST_NULL_CREDENTIALS.setFirstName("Aggie"); | ||
TEST_NULL_CREDENTIALS.setLastName("Jack"); | ||
} | ||
|
||
private static final Credentials TEST_CHANGED_CREDENTIALS = new Credentials(); | ||
static { | ||
TEST_CHANGED_CREDENTIALS.setUin("111111111"); | ||
TEST_CHANGED_CREDENTIALS.setEmail("jsmithk@tamu.edu"); | ||
TEST_CHANGED_CREDENTIALS.setFirstName("John"); | ||
TEST_CHANGED_CREDENTIALS.setLastName("Smith"); | ||
TEST_CHANGED_CREDENTIALS.setRole("ROLE_ADMIN"); | ||
} | ||
|
||
private User testUser1 = new User(TEST_CREDENTIALS_1.getUin(), TEST_CREDENTIALS_1.getEmail(), TEST_CREDENTIALS_1.getFirstName(), TEST_CREDENTIALS_1.getLastName(), Role.valueOf(TEST_CREDENTIALS_1.getRole())); | ||
private User testUser2 = new User(TEST_CREDENTIALS_2.getUin(), TEST_CREDENTIALS_2.getEmail(), TEST_CREDENTIALS_2.getFirstName(), TEST_CREDENTIALS_2.getLastName(), Role.valueOf(TEST_CREDENTIALS_2.getRole())); | ||
|
||
private static final String[] testAdmins = { "123456789", "987654321" }; | ||
|
||
private Optional<User> optionalUser1 = Optional.of(testUser1); | ||
|
||
@Mock | ||
private UserRepo userRepo; | ||
|
||
@InjectMocks | ||
private AppUserCredentialsService credentialsService; | ||
|
||
@Before | ||
public void setUp() { | ||
MockitoAnnotations.initMocks(this); | ||
when(userRepo.findByUsername(TEST_CREDENTIALS_1.getUin())).thenReturn(optionalUser1); | ||
when(userRepo.findByUsername(TEST_CREDENTIALS_2.getUin())).thenReturn(Optional.empty()); | ||
when(userRepo.findByUsername(TEST_CHANGED_CREDENTIALS.getUin())).thenReturn(optionalUser1); | ||
when(userRepo.create(any(String.class), any(String.class), any(String.class), any(String.class), any(Role.class))).thenReturn(testUser2); | ||
when(userRepo.save(any(User.class))).thenReturn(testUser1); | ||
} | ||
|
||
@Test | ||
public void testUpdateUserByCredentials() { | ||
setField(credentialsService, "admins", testAdmins); | ||
User foundUser = credentialsService.updateUserByCredentials(TEST_CREDENTIALS_1); | ||
assertEquals("Unable to find user", testUser1, foundUser); | ||
User unfoundUser = credentialsService.updateUserByCredentials(TEST_CREDENTIALS_2); | ||
assertEquals("Unable to find user", testUser2, unfoundUser); | ||
} | ||
|
||
@Test | ||
public void testGetAnonymousRole() { | ||
String anonRole = credentialsService.getAnonymousRole(); | ||
assertEquals("Anonymous Role not set correctly", Role.ROLE_ANONYMOUS.toString(), anonRole); | ||
} | ||
|
||
@Test | ||
public void testNullRole() { | ||
setField(credentialsService, "admins", testAdmins); | ||
User nullUser = credentialsService.updateUserByCredentials(TEST_NULL_CREDENTIALS); | ||
assertEquals("Null Role not updated", TEST_CREDENTIALS_1.getRole(), nullUser.getRole().toString()); | ||
} | ||
|
||
@Test | ||
public void testChangedUser() { | ||
User changedUser = credentialsService.updateUserByCredentials(TEST_CHANGED_CREDENTIALS); | ||
assertEquals("is present", changedUser, optionalUser1.get()); | ||
assertEquals("Username was not updated", TEST_CHANGED_CREDENTIALS.getUin(), changedUser.getUsername()); | ||
assertEquals("Email was not updated", TEST_CHANGED_CREDENTIALS.getEmail(), changedUser.getEmail()); | ||
assertEquals("First name was not updated", TEST_CHANGED_CREDENTIALS.getFirstName(), changedUser.getFirstName()); | ||
assertEquals("Last name was not updated", TEST_CHANGED_CREDENTIALS.getLastName(), changedUser.getLastName()); | ||
assertEquals("Role was not updated", TEST_CHANGED_CREDENTIALS.getRole(), changedUser.getRole().toString()); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/test/java/edu/tamu/app/auth/service/AppUserDetailsServiceTest.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,38 @@ | ||
package edu.tamu.app.auth.service; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.springframework.security.core.userdetails.UserDetails; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
|
||
import edu.tamu.app.enums.Role; | ||
import edu.tamu.app.model.User; | ||
import edu.tamu.weaver.auth.model.Credentials; | ||
|
||
@RunWith(SpringRunner.class) | ||
public class AppUserDetailsServiceTest { | ||
|
||
private static final Credentials TEST_CREDENTIALS_1 = new Credentials(); | ||
static { | ||
TEST_CREDENTIALS_1.setUin("123456789"); | ||
TEST_CREDENTIALS_1.setEmail("aggieJack@tamu.edu"); | ||
TEST_CREDENTIALS_1.setFirstName("Aggie"); | ||
TEST_CREDENTIALS_1.setLastName("Jack"); | ||
TEST_CREDENTIALS_1.setRole("ROLE_USER"); | ||
} | ||
|
||
private User testUser1 = new User(TEST_CREDENTIALS_1.getUin(), TEST_CREDENTIALS_1.getEmail(), TEST_CREDENTIALS_1.getFirstName(), TEST_CREDENTIALS_1.getLastName(), Role.valueOf(TEST_CREDENTIALS_1.getRole())); | ||
|
||
@InjectMocks | ||
private AppUserDetailsService appUserDetailsService; | ||
|
||
@Test | ||
public void testBuildUserDetails() { | ||
UserDetails details = appUserDetailsService.buildUserDetails(testUser1); | ||
assertEquals("User details not built correctly", TEST_CREDENTIALS_1.getUin(), details.getUsername()); | ||
} | ||
|
||
} |
Oops, something went wrong.