-
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.
Merge branch 'master' of github.com:sjtu-meow/web
- Loading branch information
Showing
14 changed files
with
217 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
# Meow Web Project | ||
[](https://travis-ci.org/sjtu-meow/web) | ||
|
||
## Deploy | ||
``` | ||
./gradlew buildDocker | ||
docker-compose up | ||
``` |
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
21 changes: 21 additions & 0 deletions
21
src/main/java/me/sjtumeow/meow/util/LocalDateAttributeConverter.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,21 @@ | ||
package me.sjtumeow.meow.util; | ||
|
||
import java.sql.Timestamp; | ||
import java.time.LocalDateTime; | ||
|
||
import javax.persistence.AttributeConverter; | ||
import javax.persistence.Converter; | ||
|
||
@Converter(autoApply = true) | ||
public class LocalDateAttributeConverter implements AttributeConverter<LocalDateTime, Timestamp> { | ||
|
||
@Override | ||
public Timestamp convertToDatabaseColumn(LocalDateTime localDateTime) { | ||
return (localDateTime == null ? null : Timestamp.valueOf(localDateTime)); | ||
} | ||
|
||
@Override | ||
public LocalDateTime convertToEntityAttribute(Timestamp timestamp) { | ||
return (timestamp == null ? null : timestamp.toLocalDateTime()); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/me/sjtumeow/meow/util/LocalDateTimeAttributeConverter.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,25 @@ | ||
package me.sjtumeow.meow.util; | ||
|
||
import java.sql.Date; | ||
import java.time.LocalDate; | ||
|
||
import javax.persistence.AttributeConverter; | ||
import javax.persistence.Converter; | ||
|
||
/** | ||
* Custom converter class that enables usage of LocalDateTime with the DB | ||
*/ | ||
|
||
@Converter(autoApply = true) | ||
public class LocalDateTimeAttributeConverter implements AttributeConverter<LocalDate, Date> { | ||
|
||
@Override | ||
public Date convertToDatabaseColumn(LocalDate localDate) { | ||
return (localDate == null ? null : Date.valueOf(localDate)); | ||
} | ||
|
||
@Override | ||
public LocalDate convertToEntityAttribute(Date date) { | ||
return (date == null ? null : date.toLocalDate()); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package me.sjtumeow.meow; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
|
||
@SpringBootTest | ||
@RunWith(SpringRunner.class) | ||
public class ApiTest { | ||
|
||
/*private MockMvc mockMvc; | ||
@Autowired | ||
private WebApplicationContext context;*/ | ||
|
||
@Before | ||
public void setupMockMvc() { | ||
//mockMvc = MockMvcBuilders.webAppContextSetup(context).build(); | ||
|
||
} | ||
|
||
@Test | ||
public void testLogin() throws Exception { | ||
//MockHttpServletRequestBuilder builder = new MockHttpServletRequestBuilder(null, null); | ||
//mockMvc.perform(builder).andReturn(); | ||
// TODO | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/test/java/me/sjtumeow/meow/authorization/manager/impl/RedisTokenManagerTest.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,41 @@ | ||
package me.sjtumeow.meow.authorization.manager.impl; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
|
||
import me.sjtumeow.meow.authorization.manager.TokenManager; | ||
import me.sjtumeow.meow.authorization.model.TokenModel; | ||
|
||
@SpringBootTest | ||
@RunWith(SpringRunner.class) | ||
public class RedisTokenManagerTest { | ||
@Autowired | ||
TokenManager tokenManager; | ||
|
||
@Test | ||
public void checkToken() throws Exception { | ||
Long userId = 1L; | ||
TokenModel token = tokenManager.createToken(userId); | ||
assertTrue(tokenManager.checkToken(token)); | ||
tokenManager.deleteToken(userId); | ||
assertFalse(tokenManager.checkToken(token)); | ||
} | ||
|
||
@Test | ||
public void getToken() throws Exception { | ||
String userId = "123"; | ||
String tokenString = "tokenString"; | ||
String auth = userId + '_' + tokenString; | ||
TokenModel token = tokenManager.getToken(auth); | ||
assertEquals(Long.valueOf(userId), Long.valueOf(token.getUserId())); | ||
assertEquals(tokenString, token.getToken()); | ||
} | ||
|
||
} |
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
29 changes: 23 additions & 6 deletions
29
src/test/java/me/sjtumeow/meow/service/PushServiceTest.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 |
---|---|---|
@@ -1,22 +1,39 @@ | ||
package me.sjtumeow.meow.service; | ||
|
||
import org.junit.Assert; | ||
import static org.junit.Assert.assertNotNull; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
|
||
import static org.junit.Assert.*; | ||
import me.sjtumeow.meow.model.form.PushForm; | ||
import me.sjtumeow.meow.model.result.CreateResult; | ||
|
||
@SpringBootTest | ||
@RunWith(SpringRunner.class) | ||
public class PushServiceTest { | ||
@Test | ||
public void findAll() throws Exception { | ||
|
||
} | ||
@Autowired | ||
PushService pushService; | ||
|
||
@Test | ||
public void findAllPageable() throws Exception { | ||
public void findAll() throws Exception { | ||
/*List<PushArchive> result = pushService.findAll("99"); | ||
assertEquals(4, result.length());*/ | ||
} | ||
|
||
@Test | ||
public void create() throws Exception { | ||
PushForm pf = new PushForm(); | ||
pf.setItemId(1L); | ||
pf.setItemType(1); | ||
String message = "Test Push"; | ||
pf.setText(message); | ||
CreateResult result = pushService.create(pf); | ||
|
||
assertNotNull(result); | ||
} | ||
|
||
} |
37 changes: 33 additions & 4 deletions
37
src/test/java/me/sjtumeow/meow/util/FormatValidatorTest.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 |
---|---|---|
@@ -1,42 +1,71 @@ | ||
package me.sjtumeow.meow.util; | ||
|
||
import java.text.Normalizer; | ||
import javax.validation.constraints.AssertTrue; | ||
import org.junit.Test; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import static org.junit.Assert.*; | ||
import org.junit.Test; | ||
|
||
public class FormatValidatorTest { | ||
@Test | ||
public void checkNonNegativeInt() throws Exception { | ||
assertFalse(FormatValidator.checkNonNegativeInt(null)); | ||
assertTrue(FormatValidator.checkNonNegativeInt(100)); | ||
assertTrue(FormatValidator.checkNonNegativeInt(0)); | ||
assertFalse(FormatValidator.checkNonNegativeInt(-33)); | ||
} | ||
|
||
@Test | ||
public void checkPositiveInt() throws Exception { | ||
assertFalse(FormatValidator.checkPositiveInt(null)); | ||
assertTrue(FormatValidator.checkPositiveInt(100)); | ||
assertFalse(FormatValidator.checkPositiveInt(0)); | ||
assertFalse(FormatValidator.checkPositiveInt(-33)); | ||
} | ||
|
||
@Test | ||
public void checkPhone() throws Exception { | ||
assertFalse(FormatValidator.checkPhone(null)); | ||
assertFalse(FormatValidator.checkPhone("123")); | ||
assertFalse(FormatValidator.checkPhone("123xxxxyyyy")); | ||
assertTrue(FormatValidator.checkPhone("12333333333")); | ||
} | ||
|
||
@Test | ||
public void checkPassword() throws Exception { | ||
assertFalse(FormatValidator.checkPassword(null)); | ||
assertTrue(FormatValidator.checkPassword("password")); | ||
assertTrue(FormatValidator.checkPassword("666666")); | ||
assertFalse(FormatValidator.checkPassword("123")); | ||
} | ||
|
||
@Test | ||
public void checkSmsCode() throws Exception { | ||
assertFalse(FormatValidator.checkSmsCode(null)); | ||
assertFalse(FormatValidator.checkSmsCode("hacode")); | ||
assertTrue(FormatValidator.checkSmsCode("666666")); | ||
} | ||
|
||
@Test | ||
public void checkMainItemType() throws Exception { | ||
assertFalse(FormatValidator.checkMainItemType(null)); | ||
assertFalse(FormatValidator.checkMainItemType(-1)); | ||
assertTrue(FormatValidator.checkMainItemType(0)); | ||
assertTrue(FormatValidator.checkMainItemType(1)); | ||
assertTrue(FormatValidator.checkMainItemType(2)); | ||
assertTrue(FormatValidator.checkMainItemType(3)); | ||
assertFalse(FormatValidator.checkMainItemType(4)); | ||
} | ||
|
||
@Test | ||
public void checkItemType() throws Exception { | ||
assertFalse(FormatValidator.checkItemType(null)); | ||
assertFalse(FormatValidator.checkItemType(-1)); | ||
assertTrue(FormatValidator.checkItemType(0)); | ||
assertTrue(FormatValidator.checkItemType(1)); | ||
assertTrue(FormatValidator.checkItemType(2)); | ||
assertTrue(FormatValidator.checkItemType(3)); | ||
assertTrue(FormatValidator.checkItemType(4)); | ||
assertFalse(FormatValidator.checkItemType(5)); | ||
} | ||
|
||
} |
Oops, something went wrong.