Init Commit

This commit is contained in:
松岳 陈
2024-01-02 10:16:15 +08:00
commit 66c710c034
31 changed files with 956 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
package com.realtime.protection;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class ProtectionApplicationTests {
@Test
void contextLoads() {
}
}

View File

@@ -0,0 +1,43 @@
package com.realtime.protection.server.user.login;
import com.realtime.protection.configuration.entity.user.User;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import javax.security.auth.login.LoginException;
import static org.junit.jupiter.api.Assertions.*;
@SpringBootTest
class LoginServiceTest {
private final LoginService loginService;
@Autowired
LoginServiceTest(LoginService loginService) {
this.loginService = loginService;
}
@Test
void testLoginFail() {
User user = new User();
user.setPassword("12345");
user.setUsername("endera");
assertThrows(LoginException.class, () -> loginService.login(user));
user.setUsername("");
user.setPassword("");
assertThrows(LoginException.class, () -> loginService.login(user));
}
@Test
void testLoginSuccess() {
User user = new User();
user.setUsername("endera");
user.setPassword("123456");
assertDoesNotThrow(() -> assertEquals(1, loginService.login(user)));
}
}

View File

@@ -0,0 +1,28 @@
package com.realtime.protection.server.whitelist;
import com.realtime.protection.configuration.entity.whitelist.WhiteListObject;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import static org.junit.jupiter.api.Assertions.*;
@SpringBootTest
class WhiteListServiceTest {
private final WhiteListService whiteListService;
@Autowired
WhiteListServiceTest(WhiteListService whiteListService) {
this.whiteListService = whiteListService;
}
@Test
void testNewWhiteList() {
WhiteListObject object = new WhiteListObject();
object.setWhiteListName("test");
Integer objectId = whiteListService.newWhiteListObject(object);
assertTrue(objectId > 0);
}
}