-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Login): Added login command to check for valid credentials (#285)
- Loading branch information
1 parent
4b56f2b
commit e7605b5
Showing
6 changed files
with
122 additions
and
22 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
33 changes: 33 additions & 0 deletions
33
src/main/java/com/bullhorn/dataloader/service/LoginService.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,33 @@ | ||
package com.bullhorn.dataloader.service; | ||
|
||
import com.bullhorn.dataloader.rest.RestSession; | ||
import com.bullhorn.dataloader.util.PrintUtil; | ||
|
||
/** | ||
* Test user provided credentials to see if login is successful | ||
*/ | ||
public class LoginService implements Action { | ||
|
||
private final RestSession restSession; | ||
private final PrintUtil printUtil; | ||
|
||
LoginService(RestSession restSession, PrintUtil printUtil) { | ||
this.restSession = restSession; | ||
this.printUtil = printUtil; | ||
} | ||
|
||
@Override | ||
public void run(String[] args) { | ||
try { | ||
restSession.getRestApi(); | ||
printUtil.printAndLog("Login Successful"); | ||
} catch (Exception e) { | ||
printUtil.printAndLog("Login Failed"); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isValidArguments(String[] args) { | ||
return true; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,5 +38,4 @@ public void testIsValidArguments() { | |
|
||
Assert.assertTrue(result); | ||
} | ||
|
||
} |
58 changes: 58 additions & 0 deletions
58
src/test/java/com/bullhorn/dataloader/service/LoginServiceTest.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,58 @@ | ||
package com.bullhorn.dataloader.service; | ||
|
||
import com.bullhorn.dataloader.enums.Command; | ||
import com.bullhorn.dataloader.rest.RestSession; | ||
import com.bullhorn.dataloader.util.PrintUtil; | ||
import com.bullhornsdk.data.exception.RestApiException; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import static org.mockito.Matchers.eq; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class LoginServiceTest { | ||
|
||
private RestSession restSessionMock; | ||
private PrintUtil printUtilMock; | ||
private LoginService loginService; | ||
|
||
@Before | ||
public void setup() { | ||
restSessionMock = mock(RestSession.class); | ||
printUtilMock = mock(PrintUtil.class); | ||
loginService = new LoginService(restSessionMock, printUtilMock); | ||
} | ||
|
||
@Test | ||
public void testRunLoginSuccessful() { | ||
final String[] testArgs = {Command.LOGIN.getMethodName()}; | ||
|
||
loginService.run(testArgs); | ||
|
||
verify(printUtilMock, times(1)).printAndLog(eq("Login Successful")); | ||
} | ||
|
||
@Test | ||
public void testRunLoginFailed() { | ||
final String[] testArgs = {Command.LOGIN.getMethodName()}; | ||
when(restSessionMock.getRestApi()).thenThrow(new RestApiException("fail")); | ||
|
||
loginService.run(testArgs); | ||
|
||
verify(printUtilMock, times(1)).printAndLog(eq("Login Failed")); | ||
} | ||
|
||
|
||
@Test | ||
public void testIsValidArguments() { | ||
final String[] testArgs = {Command.LOGIN.getMethodName()}; | ||
|
||
boolean result = loginService.isValidArguments(testArgs); | ||
|
||
Assert.assertTrue(result); | ||
} | ||
} |