配置文件详解:自定义属性、随机数、多环境配置等
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package com.didispace;
|
||||
|
||||
import com.didispace.service.BlogProperties;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.mock.web.MockServletContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 程序猿DD
|
||||
* @version 1.0.0
|
||||
* @blog http://blog.didispace.com
|
||||
*
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(Application.class)
|
||||
public class ApplicationTests {
|
||||
|
||||
private static final Log log = LogFactory.getLog(ApplicationTests.class);
|
||||
|
||||
@Autowired
|
||||
private BlogProperties blogProperties;
|
||||
|
||||
|
||||
@Test
|
||||
public void getHello() throws Exception {
|
||||
Assert.assertEquals(blogProperties.getName(), "程序猿DD");
|
||||
Assert.assertEquals(blogProperties.getTitle(), "Spring Boot教程");
|
||||
Assert.assertEquals(blogProperties.getDesc(), "程序猿DD正在努力写《Spring Boot教程》");
|
||||
|
||||
log.info("随机数测试输出:");
|
||||
log.info("随机字符串 : " + blogProperties.getValue());
|
||||
log.info("随机int : " + blogProperties.getNumber());
|
||||
log.info("随机long : " + blogProperties.getBignumber());
|
||||
log.info("随机10以下 : " + blogProperties.getTest1());
|
||||
log.info("随机10-20 : " + blogProperties.getTest2());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user