Commit 4fec87a7 authored by sober's avatar sober Committed by linlinjava
Browse files

remove useless reference and modify log print type about core (#218)

parent b5d61aae
package org.linlinjava.litemall.core; package org.linlinjava.litemall.core;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.linlinjava.litemall.core.storage.AliyunStorage; import org.linlinjava.litemall.core.storage.AliyunStorage;
...@@ -17,6 +19,8 @@ import java.io.IOException; ...@@ -17,6 +19,8 @@ import java.io.IOException;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest @SpringBootTest
public class AliyunStorageTest { public class AliyunStorageTest {
private final Log logger = LogFactory.getLog(AliyunStorageTest.class);
@Autowired @Autowired
private AliyunStorage aliyunStorage; private AliyunStorage aliyunStorage;
...@@ -27,11 +31,9 @@ public class AliyunStorageTest { ...@@ -27,11 +31,9 @@ public class AliyunStorageTest {
aliyunStorage.store(new FileInputStream(test), testFile.length(), "image/png", "litemall.png"); aliyunStorage.store(new FileInputStream(test), testFile.length(), "image/png", "litemall.png");
Resource resource = aliyunStorage.loadAsResource("litemall.png"); Resource resource = aliyunStorage.loadAsResource("litemall.png");
String url = aliyunStorage.generateUrl("litemall.png"); String url = aliyunStorage.generateUrl("litemall.png");
System.out.println("test file " + test); logger.info("test file " + test);
System.out.println("store file " + resource.getURI()); logger.info("store file " + resource.getURI());
System.out.println("generate url " + url); logger.info("generate url " + url);
// tencentOsService.delete("litemall.png");
} }
} }
\ No newline at end of file
package org.linlinjava.litemall.core; 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.scheduling.annotation.Async;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@Service @Service
public class AsyncTask { public class AsyncTask {
private final Log logger = LogFactory.getLog(AsyncTask.class);
@Async @Async
public void asyncMethod() { public void asyncMethod() {
System.out.println("Execute method asynchronously. " logger.info("Execute method asynchronously. "
+ Thread.currentThread().getName()); + Thread.currentThread().getName());
} }
public void nonasyncMethod() { public void nonasyncMethod() {
System.out.println("Execute method nonasynchronously. " logger.info("Execute method nonasynchronously. "
+ Thread.currentThread().getName()); + Thread.currentThread().getName());
} }
} }
package org.linlinjava.litemall.core; package org.linlinjava.litemall.core;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -12,12 +14,13 @@ import org.springframework.test.context.web.WebAppConfiguration; ...@@ -12,12 +14,13 @@ import org.springframework.test.context.web.WebAppConfiguration;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest @SpringBootTest
public class CoreConfigTest { public class CoreConfigTest {
private final Log logger = LogFactory.getLog(CoreConfigTest.class);
@Autowired @Autowired
Environment environment; Environment environment;
@Test @Test
public void test() { public void test() {
// 测试获取application-core.yml配置信息 // 测试获取application-core.yml配置信息
System.out.println(environment.getProperty("litemall.express.appId")); logger.info(environment.getProperty("litemall.express.appId"));
} }
} }
package org.linlinjava.litemall.core; package org.linlinjava.litemall.core;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.linlinjava.litemall.core.express.ExpressService; import org.linlinjava.litemall.core.express.ExpressService;
...@@ -13,6 +15,8 @@ import org.springframework.test.context.web.WebAppConfiguration; ...@@ -13,6 +15,8 @@ import org.springframework.test.context.web.WebAppConfiguration;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = Application.class) @SpringBootTest(classes = Application.class)
public class ExpressTest { public class ExpressTest {
private final Log logger = LogFactory.getLog(ExpressTest.class);
@Autowired @Autowired
private ExpressService expressService; private ExpressService expressService;
...@@ -22,8 +26,8 @@ public class ExpressTest { ...@@ -22,8 +26,8 @@ public class ExpressTest {
try { try {
ei = expressService.getExpressInfo("YTO", "800669400640887922"); ei = expressService.getExpressInfo("YTO", "800669400640887922");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
System.out.print(ei); logger.info(ei);
} }
} }
package org.linlinjava.litemall.core; package org.linlinjava.litemall.core;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.linlinjava.litemall.core.storage.LocalStorage; import org.linlinjava.litemall.core.storage.LocalStorage;
...@@ -17,6 +19,8 @@ import java.io.IOException; ...@@ -17,6 +19,8 @@ import java.io.IOException;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest @SpringBootTest
public class LocalStorageTest { public class LocalStorageTest {
private final Log logger = LogFactory.getLog(LocalStorageTest.class);
@Autowired @Autowired
private LocalStorage localStorage; private LocalStorage localStorage;
...@@ -27,12 +31,9 @@ public class LocalStorageTest { ...@@ -27,12 +31,9 @@ public class LocalStorageTest {
localStorage.store(new FileInputStream(test), testFile.length(), "image/png", "litemall.png"); localStorage.store(new FileInputStream(test), testFile.length(), "image/png", "litemall.png");
Resource resource = localStorage.loadAsResource("litemall.png"); Resource resource = localStorage.loadAsResource("litemall.png");
String url = localStorage.generateUrl("litemall.png"); String url = localStorage.generateUrl("litemall.png");
System.out.println("test file " + test); logger.info("test file " + test);
System.out.println("store file " + resource.getURI()); logger.info("store file " + resource.getURI());
System.out.println("generate url " + url); logger.info("generate url " + url);
// localStorage.delete("litemall.png");
} }
} }
\ No newline at end of file
package org.linlinjava.litemall.core; package org.linlinjava.litemall.core;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.linlinjava.litemall.core.storage.QiniuStorage; import org.linlinjava.litemall.core.storage.QiniuStorage;
...@@ -17,6 +19,8 @@ import java.io.IOException; ...@@ -17,6 +19,8 @@ import java.io.IOException;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest @SpringBootTest
public class QiniuStorageTest { public class QiniuStorageTest {
private final Log logger = LogFactory.getLog(QiniuStorageTest.class);
@Autowired @Autowired
private QiniuStorage qiniuStorage; private QiniuStorage qiniuStorage;
...@@ -27,10 +31,9 @@ public class QiniuStorageTest { ...@@ -27,10 +31,9 @@ public class QiniuStorageTest {
qiniuStorage.store(new FileInputStream(test), testFile.length(), "image/png", "litemall.png"); qiniuStorage.store(new FileInputStream(test), testFile.length(), "image/png", "litemall.png");
Resource resource = qiniuStorage.loadAsResource("litemall.png"); Resource resource = qiniuStorage.loadAsResource("litemall.png");
String url = qiniuStorage.generateUrl("litemall.png"); String url = qiniuStorage.generateUrl("litemall.png");
System.out.println("test file " + test); logger.info("test file " + test);
System.out.println("store file " + resource.getURI()); logger.info("store file " + resource.getURI());
System.out.println("generate url " + url); logger.info("generate url " + url);
// qiniuStorage.delete("litemall.png");
} }
} }
\ No newline at end of file
package org.linlinjava.litemall.core; package org.linlinjava.litemall.core;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.linlinjava.litemall.core.storage.TencentStorage; import org.linlinjava.litemall.core.storage.TencentStorage;
...@@ -17,6 +19,8 @@ import java.io.IOException; ...@@ -17,6 +19,8 @@ import java.io.IOException;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest @SpringBootTest
public class TencentStorageTest { public class TencentStorageTest {
private Log logger = LogFactory.getLog(TencentStorageTest.class);
@Autowired @Autowired
private TencentStorage tencentStorage; private TencentStorage tencentStorage;
...@@ -27,11 +31,9 @@ public class TencentStorageTest { ...@@ -27,11 +31,9 @@ public class TencentStorageTest {
tencentStorage.store(new FileInputStream(test), testFile.length(), "image/png", "litemall.png"); tencentStorage.store(new FileInputStream(test), testFile.length(), "image/png", "litemall.png");
Resource resource = tencentStorage.loadAsResource("litemall.png"); Resource resource = tencentStorage.loadAsResource("litemall.png");
String url = tencentStorage.generateUrl("litemall.png"); String url = tencentStorage.generateUrl("litemall.png");
System.out.println("test file " + test); logger.info("test file " + test);
System.out.println("store file " + resource.getURI()); logger.info("store file " + resource.getURI());
System.out.println("generate url " + url); logger.info("generate url " + url);
// tencentStorage.delete("litemall.png");
} }
} }
\ No newline at end of file
...@@ -4,9 +4,7 @@ import org.junit.Assert; ...@@ -4,9 +4,7 @@ import org.junit.Assert;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;
import org.junit.rules.Timeout;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.linlinjava.litemall.core.util.bcrypt.BCrypt;
import org.powermock.api.mockito.PowerMockito; import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunner;
...@@ -16,106 +14,107 @@ import java.security.SecureRandom; ...@@ -16,106 +14,107 @@ import java.security.SecureRandom;
@RunWith(PowerMockRunner.class) @RunWith(PowerMockRunner.class)
public class BCryptTest { public class BCryptTest {
@Rule public final ExpectedException thrown = ExpectedException.none(); @Rule
public final ExpectedException thrown = ExpectedException.none();
@Test
public void testHashpwSaltIsNull() throws IllegalArgumentException { @Test
thrown.expect(IllegalArgumentException.class); public void testHashpwSaltIsNull() throws IllegalArgumentException {
BCrypt.hashpw("foo", null); thrown.expect(IllegalArgumentException.class);
} BCrypt.hashpw("foo", null);
}
@Test
public void testHashpwSaltTooShort() throws IllegalArgumentException { @Test
thrown.expect(IllegalArgumentException.class); public void testHashpwSaltTooShort() throws IllegalArgumentException {
BCrypt.hashpw("foo", "foo"); thrown.expect(IllegalArgumentException.class);
} BCrypt.hashpw("foo", "foo");
}
@Test
public void testHashpwInvalidSaltVersion() throws IllegalArgumentException { @Test
thrown.expect(IllegalArgumentException.class); public void testHashpwInvalidSaltVersion() throws IllegalArgumentException {
BCrypt.hashpw("foo", "+2a$10$....................."); thrown.expect(IllegalArgumentException.class);
} BCrypt.hashpw("foo", "+2a$10$.....................");
}
@Test
public void testHashpwInvalidSaltVersion2() throws IllegalArgumentException { @Test
thrown.expect(IllegalArgumentException.class); public void testHashpwInvalidSaltVersion2() throws IllegalArgumentException {
BCrypt.hashpw("foo", "$1a$10$....................."); thrown.expect(IllegalArgumentException.class);
} BCrypt.hashpw("foo", "$1a$10$.....................");
}
@Test
public void testHashpwInvalidSaltRevision() throws IllegalArgumentException { @Test
thrown.expect(IllegalArgumentException.class); public void testHashpwInvalidSaltRevision() throws IllegalArgumentException {
BCrypt.hashpw("foo", "$2+$10$....................."); thrown.expect(IllegalArgumentException.class);
} BCrypt.hashpw("foo", "$2+$10$.....................");
}
@Test
public void testHashpwInvalidSaltRevision2() throws IllegalArgumentException { @Test
thrown.expect(IllegalArgumentException.class); public void testHashpwInvalidSaltRevision2() throws IllegalArgumentException {
BCrypt.hashpw("foo", "$2a+10$....................."); thrown.expect(IllegalArgumentException.class);
} BCrypt.hashpw("foo", "$2a+10$.....................");
}
@Test
public void testHashpwSaltTooShort2() throws IllegalArgumentException { @Test
thrown.expect(IllegalArgumentException.class); public void testHashpwSaltTooShort2() throws IllegalArgumentException {
BCrypt.hashpw("foo", "$2a$10+....................."); thrown.expect(IllegalArgumentException.class);
} BCrypt.hashpw("foo", "$2a$10+.....................");
}
@Test
public void testHashpwMissingSaltRounds() throws IllegalArgumentException { @Test
thrown.expect(IllegalArgumentException.class); public void testHashpwMissingSaltRounds() throws IllegalArgumentException {
BCrypt.hashpw("foo", "$2$a10$....................."); thrown.expect(IllegalArgumentException.class);
} BCrypt.hashpw("foo", "$2$a10$.....................");
}
@Test
public void testHashpwTooLittleRounds() throws IllegalArgumentException { @Test
thrown.expect(IllegalArgumentException.class); public void testHashpwTooLittleRounds() throws IllegalArgumentException {
BCrypt.hashpw("foo", "$2a$03$......................"); thrown.expect(IllegalArgumentException.class);
} BCrypt.hashpw("foo", "$2a$03$......................");
}
@Test
public void testHashpwTooManyRounds() throws IllegalArgumentException { @Test
thrown.expect(IllegalArgumentException.class); public void testHashpwTooManyRounds() throws IllegalArgumentException {
BCrypt.hashpw("foo", "$2a$32$......................"); thrown.expect(IllegalArgumentException.class);
} BCrypt.hashpw("foo", "$2a$32$......................");
}
@Test
public void testHashpw() { @Test
Assert.assertEquals( public void testHashpw() {
"$2a$10$......................0li5vIK0lccG/IXHAOP2wBncDW/oa2u", Assert.assertEquals(
BCrypt.hashpw("foo", "$2a$10$......................")); "$2a$10$......................0li5vIK0lccG/IXHAOP2wBncDW/oa2u",
BCrypt.hashpw("foo", "$2a$10$......................"));
Assert.assertEquals(
"$2$09$......................GlnmyWmDnFB.MnSSUnFsiPvHsC2KPBm", Assert.assertEquals(
BCrypt.hashpw("foo", "$2$09$......................")); "$2$09$......................GlnmyWmDnFB.MnSSUnFsiPvHsC2KPBm",
} BCrypt.hashpw("foo", "$2$09$......................"));
}
@PrepareForTest({BCrypt.class, SecureRandom.class})
@Test @PrepareForTest({BCrypt.class, SecureRandom.class})
public void testGensalt() throws Exception { @Test
PowerMockito.whenNew(SecureRandom.class).withNoArguments() public void testGensalt() throws Exception {
.thenReturn(PowerMockito.mock(SecureRandom.class)); PowerMockito.whenNew(SecureRandom.class).withNoArguments()
Assert.assertEquals("$2a$10$......................", BCrypt.gensalt()); .thenReturn(PowerMockito.mock(SecureRandom.class));
Assert.assertEquals("$2a$09$......................", BCrypt.gensalt(9)); Assert.assertEquals("$2a$10$......................", BCrypt.gensalt());
} Assert.assertEquals("$2a$09$......................", BCrypt.gensalt(9));
}
@Test
public void testGensaltTooLittleRounds() throws IllegalArgumentException { @Test
thrown.expect(IllegalArgumentException.class); public void testGensaltTooLittleRounds() throws IllegalArgumentException {
BCrypt.gensalt(3); thrown.expect(IllegalArgumentException.class);
} BCrypt.gensalt(3);
}
@Test
public void testGensaltTooManyRounds() throws IllegalArgumentException { @Test
thrown.expect(IllegalArgumentException.class); public void testGensaltTooManyRounds() throws IllegalArgumentException {
BCrypt.gensalt(32); thrown.expect(IllegalArgumentException.class);
} BCrypt.gensalt(32);
}
@Test
public void testCheckpw() { @Test
Assert.assertFalse(BCrypt.checkpw("foo", "$2a$10$......................")); public void testCheckpw() {
Assert.assertFalse(BCrypt.checkpw("foo", "$2a$10$......................"));
final String hashed = BCrypt.hashpw("foo", BCrypt.gensalt());
Assert.assertTrue(BCrypt.checkpw("foo", hashed)); final String hashed = BCrypt.hashpw("foo", BCrypt.gensalt());
Assert.assertFalse(BCrypt.checkpw("bar", hashed)); Assert.assertTrue(BCrypt.checkpw("foo", hashed));
} Assert.assertFalse(BCrypt.checkpw("bar", hashed));
}
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment