.travis.ymlファイルに以下を追記する。
before_script:
- mysql -uroot -e "create database common"
- mysql -uroot common < src/config/schema.sql
- mysql -uroot common < src/config/data.sql
Technical Notes
.travis.ymlファイルに以下を追記する。
before_script:
- mysql -uroot -e "create database common"
- mysql -uroot common < src/config/schema.sql
- mysql -uroot common < src/config/data.sql
Thymeleafはテンプレートの一種。
Springとの相性が良く簡単に使用出来る。
・top.html
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<p th:text="Hello, Thymeleaf!">Hello, hide6644!</p>
</body>
</html>
View Resolverを設定する。
<!-- View Resolver for Thymeleaf -->
<bean id="templateResolver" class="org.thymeleaf.spring4.templateresolver.SpringResourceTemplateResolver">
<property name="prefix" value="/WEB-INF/pages/" />
<property name="suffix" value=".html" />
<property name="templateMode" value="HTML" />
<property name="cacheable" value="false" />
</bean>
<bean id="templateEngine" class="org.thymeleaf.spring4.SpringTemplateEngine">
<property name="templateResolver" ref="templateResolver" />
<property name="enableSpringELCompiler" value="true" />
</bean>
<bean class="org.thymeleaf.spring4.view.ThymeleafViewResolver">
<property name="templateEngine" ref="templateEngine" />
<property name="characterEncoding" value="UTF-8" />
<property name="order" value="4" />
</bean>
Veiwを呼び出す。
@RequestMapping(value = "top", method = RequestMethod.GET)
public String topRequest() {
return "top";
}
小説自体を表すデータモデルと、小説の管理に使用する付随情報がある。
それと、更新履歴を表すクラスがある。
小説を読もう!の更新を自動でチェックしたかったのだが、自分の好みに合ったサービスがなかった。
じゃあ、自分で作っちゃえってことで以下の通り。
※2022/05/05追記:jenkinsの設定方法も含めた、2022年現在の連携方向を参照したい場合はこちら。
Githubにpushされたら、Jenkinsのビルドを起動したい。
下記のインスタンスを生成する部分をMockにしたい。
NovelSource novelSource = new NovelSource(url);
そこで、PowerMockitoを使用してみる。
<!-- https://mvnrepository.com/artifact/org.powermock/powermock-api-mockito -->
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>1.6.6</version>
</dependency>
使用方法はこんな感じ。
@RunWith(PowerMockRunner.class)
@PrepareForTest({ NovelManagerImpl.class })
@PowerMockIgnore("javax.management.*")
public class NovelManagerImplTest extends BaseManagerMockTestCase {
@Mock
private NovelSource novelSource;
@Mock
private Logger log;
@Mock
private NovelDao novelDao;
@Mock
private NovelInfoManager novelInfoManager;
@Mock
private NovelChapterManager novelChapterManager;
@InjectMocks
private NovelManagerImpl novelManager = new NovelManagerImpl();
@Test
public void testAdd() throws Exception {
String fileName = this.getClass().getClassLoader().getResource("novel/20160924/test.html").getPath();
File file = new File(fileName);
String url = "http://www.foo.bar/20160924/";
NovelSource novelSource = new NovelSource(new Source(file));
{
// 初期化
MockitoAnnotations.initMocks(this);
// NovelSourceをnewするとき、thenReturn(~)のインスタンスを返却する
PowerMockito.whenNew(NovelSource.class).withArguments(url).thenReturn(novelSource);
}
}
コンストラクタに引数を渡したいときは、withArguments()を使用する。
しかし、カバレッジが測定出来ないので注意。