Group testing modules (#3014)
* move security content from spring-security-rest-full * swagger update * move query language to new module * rename spring-security-rest-full to spring-rest-full * group persistence modules * group testing modules * try fix conflict
This commit is contained in:
committed by
GitHub
parent
b383d83bf4
commit
776a01429e
+29
@@ -0,0 +1,29 @@
|
||||
package org.baeldung.mocks.testCase;
|
||||
|
||||
public class LoginController {
|
||||
|
||||
public LoginService loginService;
|
||||
|
||||
public String login(UserForm userForm) {
|
||||
if (null == userForm) {
|
||||
return "ERROR";
|
||||
} else {
|
||||
boolean logged;
|
||||
|
||||
try {
|
||||
logged = loginService.login(userForm);
|
||||
} catch (Exception e) {
|
||||
return "ERROR";
|
||||
}
|
||||
|
||||
if (logged) {
|
||||
loginService.setCurrentUser(userForm.getUsername());
|
||||
return "OK";
|
||||
} else {
|
||||
return "KO";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// standard setters and getters
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package org.baeldung.mocks.testCase;
|
||||
|
||||
public class LoginDao {
|
||||
|
||||
public int login(UserForm userForm) {
|
||||
//actual call to a third party library
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package org.baeldung.mocks.testCase;
|
||||
|
||||
public class LoginService {
|
||||
|
||||
private LoginDao loginDao;
|
||||
|
||||
private String currentUser;
|
||||
|
||||
public boolean login(UserForm userForm) {
|
||||
assert null != userForm;
|
||||
|
||||
int loginResults = loginDao.login(userForm);
|
||||
|
||||
switch (loginResults) {
|
||||
case 1:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void setCurrentUser(String username) {
|
||||
if (null != username) {
|
||||
this.currentUser = username;
|
||||
}
|
||||
}
|
||||
|
||||
public void setLoginDao(LoginDao loginDao) {
|
||||
this.loginDao = loginDao;
|
||||
}
|
||||
|
||||
// standard setters and getters
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package org.baeldung.mocks.testCase;
|
||||
|
||||
public class UserForm {
|
||||
|
||||
// public access modifiers as only for testing
|
||||
|
||||
public String password;
|
||||
|
||||
public String username;
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user