Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
Litemall
Commits
4fec87a7
Commit
4fec87a7
authored
Jun 26, 2019
by
sober
Committed by
linlinjava
Jun 26, 2019
Browse files
remove useless reference and modify log print type about core (#218)
parent
b5d61aae
Changes
28
Hide whitespace changes
Inline
Side-by-side
litemall-core/src/test/java/org/linlinjava/litemall/core/AliyunStorageTest.java
View file @
4fec87a7
package
org.linlinjava.litemall.core
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.linlinjava.litemall.core.storage.AliyunStorage
;
...
...
@@ -17,6 +19,8 @@ import java.io.IOException;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringBootTest
public
class
AliyunStorageTest
{
private
final
Log
logger
=
LogFactory
.
getLog
(
AliyunStorageTest
.
class
);
@Autowired
private
AliyunStorage
aliyunStorage
;
...
...
@@ -27,11 +31,9 @@ public class AliyunStorageTest {
aliyunStorage
.
store
(
new
FileInputStream
(
test
),
testFile
.
length
(),
"image/png"
,
"litemall.png"
);
Resource
resource
=
aliyunStorage
.
loadAsResource
(
"litemall.png"
);
String
url
=
aliyunStorage
.
generateUrl
(
"litemall.png"
);
System
.
out
.
println
(
"test file "
+
test
);
System
.
out
.
println
(
"store file "
+
resource
.
getURI
());
System
.
out
.
println
(
"generate url "
+
url
);
// tencentOsService.delete("litemall.png");
logger
.
info
(
"test file "
+
test
);
logger
.
info
(
"store file "
+
resource
.
getURI
());
logger
.
info
(
"generate url "
+
url
);
}
}
\ No newline at end of file
litemall-core/src/test/java/org/linlinjava/litemall/core/AsyncTask.java
View file @
4fec87a7
package
org.linlinjava.litemall.core
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.springframework.scheduling.annotation.Async
;
import
org.springframework.stereotype.Service
;
@Service
public
class
AsyncTask
{
private
final
Log
logger
=
LogFactory
.
getLog
(
AsyncTask
.
class
);
@Async
public
void
asyncMethod
()
{
System
.
out
.
println
(
"Execute method asynchronously. "
logger
.
info
(
"Execute method asynchronously. "
+
Thread
.
currentThread
().
getName
());
}
public
void
nonasyncMethod
()
{
System
.
out
.
println
(
"Execute method nonasynchronously. "
logger
.
info
(
"Execute method nonasynchronously. "
+
Thread
.
currentThread
().
getName
());
}
}
litemall-core/src/test/java/org/linlinjava/litemall/core/CoreConfigTest.java
View file @
4fec87a7
package
org.linlinjava.litemall.core
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -12,12 +14,13 @@ import org.springframework.test.context.web.WebAppConfiguration;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringBootTest
public
class
CoreConfigTest
{
private
final
Log
logger
=
LogFactory
.
getLog
(
CoreConfigTest
.
class
);
@Autowired
Environment
environment
;
@Test
public
void
test
()
{
// 测试获取application-core.yml配置信息
System
.
out
.
println
(
environment
.
getProperty
(
"litemall.express.appId"
));
logger
.
info
(
environment
.
getProperty
(
"litemall.express.appId"
));
}
}
litemall-core/src/test/java/org/linlinjava/litemall/core/ExpressTest.java
View file @
4fec87a7
package
org.linlinjava.litemall.core
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.linlinjava.litemall.core.express.ExpressService
;
...
...
@@ -13,6 +15,8 @@ import org.springframework.test.context.web.WebAppConfiguration;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringBootTest
(
classes
=
Application
.
class
)
public
class
ExpressTest
{
private
final
Log
logger
=
LogFactory
.
getLog
(
ExpressTest
.
class
);
@Autowired
private
ExpressService
expressService
;
...
...
@@ -22,8 +26,8 @@ public class ExpressTest {
try
{
ei
=
expressService
.
getExpressInfo
(
"YTO"
,
"800669400640887922"
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
(
);
logger
.
error
(
e
.
getMessage
(),
e
);
}
System
.
out
.
print
(
ei
);
logger
.
info
(
ei
);
}
}
litemall-core/src/test/java/org/linlinjava/litemall/core/LocalStorageTest.java
View file @
4fec87a7
package
org.linlinjava.litemall.core
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.linlinjava.litemall.core.storage.LocalStorage
;
...
...
@@ -17,6 +19,8 @@ import java.io.IOException;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringBootTest
public
class
LocalStorageTest
{
private
final
Log
logger
=
LogFactory
.
getLog
(
LocalStorageTest
.
class
);
@Autowired
private
LocalStorage
localStorage
;
...
...
@@ -27,12 +31,9 @@ public class LocalStorageTest {
localStorage
.
store
(
new
FileInputStream
(
test
),
testFile
.
length
(),
"image/png"
,
"litemall.png"
);
Resource
resource
=
localStorage
.
loadAsResource
(
"litemall.png"
);
String
url
=
localStorage
.
generateUrl
(
"litemall.png"
);
System
.
out
.
println
(
"test file "
+
test
);
System
.
out
.
println
(
"store file "
+
resource
.
getURI
());
System
.
out
.
println
(
"generate url "
+
url
);
// localStorage.delete("litemall.png");
logger
.
info
(
"test file "
+
test
);
logger
.
info
(
"store file "
+
resource
.
getURI
());
logger
.
info
(
"generate url "
+
url
);
}
}
\ No newline at end of file
litemall-core/src/test/java/org/linlinjava/litemall/core/QiniuStorageTest.java
View file @
4fec87a7
package
org.linlinjava.litemall.core
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.linlinjava.litemall.core.storage.QiniuStorage
;
...
...
@@ -17,6 +19,8 @@ import java.io.IOException;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringBootTest
public
class
QiniuStorageTest
{
private
final
Log
logger
=
LogFactory
.
getLog
(
QiniuStorageTest
.
class
);
@Autowired
private
QiniuStorage
qiniuStorage
;
...
...
@@ -27,10 +31,9 @@ public class QiniuStorageTest {
qiniuStorage
.
store
(
new
FileInputStream
(
test
),
testFile
.
length
(),
"image/png"
,
"litemall.png"
);
Resource
resource
=
qiniuStorage
.
loadAsResource
(
"litemall.png"
);
String
url
=
qiniuStorage
.
generateUrl
(
"litemall.png"
);
System
.
out
.
println
(
"test file "
+
test
);
System
.
out
.
println
(
"store file "
+
resource
.
getURI
());
System
.
out
.
println
(
"generate url "
+
url
);
// qiniuStorage.delete("litemall.png");
logger
.
info
(
"test file "
+
test
);
logger
.
info
(
"store file "
+
resource
.
getURI
());
logger
.
info
(
"generate url "
+
url
);
}
}
\ No newline at end of file
litemall-core/src/test/java/org/linlinjava/litemall/core/TencentStorageTest.java
View file @
4fec87a7
package
org.linlinjava.litemall.core
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.linlinjava.litemall.core.storage.TencentStorage
;
...
...
@@ -17,6 +19,8 @@ import java.io.IOException;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringBootTest
public
class
TencentStorageTest
{
private
Log
logger
=
LogFactory
.
getLog
(
TencentStorageTest
.
class
);
@Autowired
private
TencentStorage
tencentStorage
;
...
...
@@ -27,11 +31,9 @@ public class TencentStorageTest {
tencentStorage
.
store
(
new
FileInputStream
(
test
),
testFile
.
length
(),
"image/png"
,
"litemall.png"
);
Resource
resource
=
tencentStorage
.
loadAsResource
(
"litemall.png"
);
String
url
=
tencentStorage
.
generateUrl
(
"litemall.png"
);
System
.
out
.
println
(
"test file "
+
test
);
System
.
out
.
println
(
"store file "
+
resource
.
getURI
());
System
.
out
.
println
(
"generate url "
+
url
);
// tencentStorage.delete("litemall.png");
logger
.
info
(
"test file "
+
test
);
logger
.
info
(
"store file "
+
resource
.
getURI
());
logger
.
info
(
"generate url "
+
url
);
}
}
\ No newline at end of file
litemall-core/src/test/java/org/linlinjava/litemall/core/util/bcrypt/BCryptTest.java
View file @
4fec87a7
...
...
@@ -4,9 +4,7 @@ import org.junit.Assert;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.rules.ExpectedException
;
import
org.junit.rules.Timeout
;
import
org.junit.runner.RunWith
;
import
org.linlinjava.litemall.core.util.bcrypt.BCrypt
;
import
org.powermock.api.mockito.PowerMockito
;
import
org.powermock.core.classloader.annotations.PrepareForTest
;
import
org.powermock.modules.junit4.PowerMockRunner
;
...
...
@@ -16,106 +14,107 @@ import java.security.SecureRandom;
@RunWith
(
PowerMockRunner
.
class
)
public
class
BCryptTest
{
@Rule
public
final
ExpectedException
thrown
=
ExpectedException
.
none
();
@Test
public
void
testHashpwSaltIsNull
()
throws
IllegalArgumentException
{
thrown
.
expect
(
IllegalArgumentException
.
class
);
BCrypt
.
hashpw
(
"foo"
,
null
);
}
@Test
public
void
testHashpwSaltTooShort
()
throws
IllegalArgumentException
{
thrown
.
expect
(
IllegalArgumentException
.
class
);
BCrypt
.
hashpw
(
"foo"
,
"foo"
);
}
@Test
public
void
testHashpwInvalidSaltVersion
()
throws
IllegalArgumentException
{
thrown
.
expect
(
IllegalArgumentException
.
class
);
BCrypt
.
hashpw
(
"foo"
,
"+2a$10$....................."
);
}
@Test
public
void
testHashpwInvalidSaltVersion2
()
throws
IllegalArgumentException
{
thrown
.
expect
(
IllegalArgumentException
.
class
);
BCrypt
.
hashpw
(
"foo"
,
"$1a$10$....................."
);
}
@Test
public
void
testHashpwInvalidSaltRevision
()
throws
IllegalArgumentException
{
thrown
.
expect
(
IllegalArgumentException
.
class
);
BCrypt
.
hashpw
(
"foo"
,
"$2+$10$....................."
);
}
@Test
public
void
testHashpwInvalidSaltRevision2
()
throws
IllegalArgumentException
{
thrown
.
expect
(
IllegalArgumentException
.
class
);
BCrypt
.
hashpw
(
"foo"
,
"$2a+10$....................."
);
}
@Test
public
void
testHashpwSaltTooShort2
()
throws
IllegalArgumentException
{
thrown
.
expect
(
IllegalArgumentException
.
class
);
BCrypt
.
hashpw
(
"foo"
,
"$2a$10+....................."
);
}
@Test
public
void
testHashpwMissingSaltRounds
()
throws
IllegalArgumentException
{
thrown
.
expect
(
IllegalArgumentException
.
class
);
BCrypt
.
hashpw
(
"foo"
,
"$2$a10$....................."
);
}
@Test
public
void
testHashpwTooLittleRounds
()
throws
IllegalArgumentException
{
thrown
.
expect
(
IllegalArgumentException
.
class
);
BCrypt
.
hashpw
(
"foo"
,
"$2a$03$......................"
);
}
@Test
public
void
testHashpwTooManyRounds
()
throws
IllegalArgumentException
{
thrown
.
expect
(
IllegalArgumentException
.
class
);
BCrypt
.
hashpw
(
"foo"
,
"$2a$32$......................"
);
}
@Test
public
void
testHashpw
()
{
Assert
.
assertEquals
(
"$2a$10$......................0li5vIK0lccG/IXHAOP2wBncDW/oa2u"
,
BCrypt
.
hashpw
(
"foo"
,
"$2a$10$......................"
));
Assert
.
assertEquals
(
"$2$09$......................GlnmyWmDnFB.MnSSUnFsiPvHsC2KPBm"
,
BCrypt
.
hashpw
(
"foo"
,
"$2$09$......................"
));
}
@PrepareForTest
({
BCrypt
.
class
,
SecureRandom
.
class
})
@Test
public
void
testGensalt
()
throws
Exception
{
PowerMockito
.
whenNew
(
SecureRandom
.
class
).
withNoArguments
()
.
thenReturn
(
PowerMockito
.
mock
(
SecureRandom
.
class
));
Assert
.
assertEquals
(
"$2a$10$......................"
,
BCrypt
.
gensalt
());
Assert
.
assertEquals
(
"$2a$09$......................"
,
BCrypt
.
gensalt
(
9
));
}
@Test
public
void
testGensaltTooLittleRounds
()
throws
IllegalArgumentException
{
thrown
.
expect
(
IllegalArgumentException
.
class
);
BCrypt
.
gensalt
(
3
);
}
@Test
public
void
testGensaltTooManyRounds
()
throws
IllegalArgumentException
{
thrown
.
expect
(
IllegalArgumentException
.
class
);
BCrypt
.
gensalt
(
32
);
}
@Test
public
void
testCheckpw
()
{
Assert
.
assertFalse
(
BCrypt
.
checkpw
(
"foo"
,
"$2a$10$......................"
));
final
String
hashed
=
BCrypt
.
hashpw
(
"foo"
,
BCrypt
.
gensalt
());
Assert
.
assertTrue
(
BCrypt
.
checkpw
(
"foo"
,
hashed
));
Assert
.
assertFalse
(
BCrypt
.
checkpw
(
"bar"
,
hashed
));
}
@Rule
public
final
ExpectedException
thrown
=
ExpectedException
.
none
();
@Test
public
void
testHashpwSaltIsNull
()
throws
IllegalArgumentException
{
thrown
.
expect
(
IllegalArgumentException
.
class
);
BCrypt
.
hashpw
(
"foo"
,
null
);
}
@Test
public
void
testHashpwSaltTooShort
()
throws
IllegalArgumentException
{
thrown
.
expect
(
IllegalArgumentException
.
class
);
BCrypt
.
hashpw
(
"foo"
,
"foo"
);
}
@Test
public
void
testHashpwInvalidSaltVersion
()
throws
IllegalArgumentException
{
thrown
.
expect
(
IllegalArgumentException
.
class
);
BCrypt
.
hashpw
(
"foo"
,
"+2a$10$....................."
);
}
@Test
public
void
testHashpwInvalidSaltVersion2
()
throws
IllegalArgumentException
{
thrown
.
expect
(
IllegalArgumentException
.
class
);
BCrypt
.
hashpw
(
"foo"
,
"$1a$10$....................."
);
}
@Test
public
void
testHashpwInvalidSaltRevision
()
throws
IllegalArgumentException
{
thrown
.
expect
(
IllegalArgumentException
.
class
);
BCrypt
.
hashpw
(
"foo"
,
"$2+$10$....................."
);
}
@Test
public
void
testHashpwInvalidSaltRevision2
()
throws
IllegalArgumentException
{
thrown
.
expect
(
IllegalArgumentException
.
class
);
BCrypt
.
hashpw
(
"foo"
,
"$2a+10$....................."
);
}
@Test
public
void
testHashpwSaltTooShort2
()
throws
IllegalArgumentException
{
thrown
.
expect
(
IllegalArgumentException
.
class
);
BCrypt
.
hashpw
(
"foo"
,
"$2a$10+....................."
);
}
@Test
public
void
testHashpwMissingSaltRounds
()
throws
IllegalArgumentException
{
thrown
.
expect
(
IllegalArgumentException
.
class
);
BCrypt
.
hashpw
(
"foo"
,
"$2$a10$....................."
);
}
@Test
public
void
testHashpwTooLittleRounds
()
throws
IllegalArgumentException
{
thrown
.
expect
(
IllegalArgumentException
.
class
);
BCrypt
.
hashpw
(
"foo"
,
"$2a$03$......................"
);
}
@Test
public
void
testHashpwTooManyRounds
()
throws
IllegalArgumentException
{
thrown
.
expect
(
IllegalArgumentException
.
class
);
BCrypt
.
hashpw
(
"foo"
,
"$2a$32$......................"
);
}
@Test
public
void
testHashpw
()
{
Assert
.
assertEquals
(
"$2a$10$......................0li5vIK0lccG/IXHAOP2wBncDW/oa2u"
,
BCrypt
.
hashpw
(
"foo"
,
"$2a$10$......................"
));
Assert
.
assertEquals
(
"$2$09$......................GlnmyWmDnFB.MnSSUnFsiPvHsC2KPBm"
,
BCrypt
.
hashpw
(
"foo"
,
"$2$09$......................"
));
}
@PrepareForTest
({
BCrypt
.
class
,
SecureRandom
.
class
})
@Test
public
void
testGensalt
()
throws
Exception
{
PowerMockito
.
whenNew
(
SecureRandom
.
class
).
withNoArguments
()
.
thenReturn
(
PowerMockito
.
mock
(
SecureRandom
.
class
));
Assert
.
assertEquals
(
"$2a$10$......................"
,
BCrypt
.
gensalt
());
Assert
.
assertEquals
(
"$2a$09$......................"
,
BCrypt
.
gensalt
(
9
));
}
@Test
public
void
testGensaltTooLittleRounds
()
throws
IllegalArgumentException
{
thrown
.
expect
(
IllegalArgumentException
.
class
);
BCrypt
.
gensalt
(
3
);
}
@Test
public
void
testGensaltTooManyRounds
()
throws
IllegalArgumentException
{
thrown
.
expect
(
IllegalArgumentException
.
class
);
BCrypt
.
gensalt
(
32
);
}
@Test
public
void
testCheckpw
()
{
Assert
.
assertFalse
(
BCrypt
.
checkpw
(
"foo"
,
"$2a$10$......................"
));
final
String
hashed
=
BCrypt
.
hashpw
(
"foo"
,
BCrypt
.
gensalt
());
Assert
.
assertTrue
(
BCrypt
.
checkpw
(
"foo"
,
hashed
));
Assert
.
assertFalse
(
BCrypt
.
checkpw
(
"bar"
,
hashed
));
}
}
Prev
1
2
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment