1 package dst.ass2.service.auth.client;
3 import static org.junit.Assert.assertFalse;
4 import static org.junit.Assert.assertNotNull;
5 import static org.junit.Assert.assertTrue;
9 import org.junit.After;
10 import org.junit.Before;
11 import org.junit.Test;
12 import org.junit.runner.RunWith;
13 import org.springframework.beans.factory.annotation.Value;
14 import org.springframework.boot.test.context.SpringBootTest;
15 import org.springframework.test.context.ActiveProfiles;
16 import org.springframework.test.context.junit4.SpringRunner;
17 import org.springframework.transaction.annotation.Transactional;
19 import dst.ass1.jpa.tests.TestData;
20 import dst.ass2.service.api.auth.AuthenticationException;
21 import dst.ass2.service.api.auth.NoSuchUserException;
22 import dst.ass2.service.auth.AuthenticationServiceApplication;
23 import dst.ass2.service.auth.client.impl.GrpcAuthenticationClient;
25 @RunWith(SpringRunner.class)
26 @SpringBootTest(classes = AuthenticationServiceApplication.class)
28 @ActiveProfiles("testdata")
29 public class AuthenticationClientTest {
31 @Value("${grpc.port}")
34 private IAuthenticationClient client;
37 public void setUp() throws Exception {
38 AuthenticationClientProperties properties = new AuthenticationClientProperties("localhost", port);
39 client = new GrpcAuthenticationClient(properties);
43 public void tearDown() throws Exception {
47 @Test(expected = NoSuchUserException.class)
48 public void authenticate_invalidUser_throwsException() throws Exception {
49 client.authenticate("nonexisting@example.com", "foo");
52 @Test(expected = AuthenticationException.class)
53 public void authenticate_invalidPassword_throwsException() throws Exception {
54 client.authenticate(TestData.PARTICIPANT_1_EMAIL, "foo");
58 public void authenticate_existingUser_returnsToken() throws Exception {
59 String token = client.authenticate(TestData.PARTICIPANT_1_EMAIL, TestData.PARTICIPANT_1_PW);
64 public void isTokenValid_invalidToken_returnsFalse() throws Exception {
65 boolean valid = client.isTokenValid(UUID.randomUUID().toString()); // should be false in *almost* all cases ;-)
70 public void isTokenValid_onCreatedToken_returnsTrue() throws Exception {
71 String token = client.authenticate(TestData.PARTICIPANT_2_EMAIL, TestData.PARTICIPANT_2_PW);
72 boolean valid = client.isTokenValid(token);