diff --git a/pom.xml b/pom.xml
index c51ad61..f5b9a78 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
com.nablarch.example
nablarch-example-rest
- 5u20
+ 5u21
war
@@ -39,7 +39,14 @@
com.nablarch.profile
nablarch-bom
- 5u20
+ 5u21
+ pom
+ import
+
+
+ org.junit
+ junit-bom
+ 5.8.2
pom
import
@@ -138,7 +145,7 @@
javax.ws.rs
javax.ws.rs-api
- 2.0
+ 2.1.1
@@ -180,6 +187,17 @@
test
+
+ com.nablarch.framework
+ nablarch-testing-junit5
+ test
+
+
+
+ org.junit.jupiter
+ junit-jupiter
+ test
+
@@ -187,7 +205,7 @@
jp.co.tis.gsp
gsp-dba-maven-plugin
- 4.4.1
+ 4.5.0
src/main/resources/entity/data-model.edm
@@ -274,6 +292,7 @@
org.apache.maven.plugins
maven-war-plugin
+ 3.3.2
${webxml.path}
${env.classifier}
diff --git a/src/main/java/com/nablarch/example/action/ProjectAction.java b/src/main/java/com/nablarch/example/action/ProjectAction.java
index 3891db3..73475c4 100644
--- a/src/main/java/com/nablarch/example/action/ProjectAction.java
+++ b/src/main/java/com/nablarch/example/action/ProjectAction.java
@@ -4,6 +4,7 @@
import com.nablarch.example.dto.ProjectSearchDto;
import com.nablarch.example.entity.Project;
import com.nablarch.example.form.ProjectForm;
+import com.nablarch.example.form.ProjectRenameForm;
import com.nablarch.example.form.ProjectSearchForm;
import com.nablarch.example.form.ProjectUpdateForm;
import nablarch.common.dao.EntityList;
@@ -16,6 +17,7 @@
import javax.validation.Valid;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
+import javax.ws.rs.PATCH;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
@@ -86,4 +88,22 @@ public HttpResponse update(ProjectUpdateForm form) {
return new HttpResponse(HttpResponse.Status.OK.getStatusCode());
}
+
+ /**
+ * プロジェクト名を更新する。
+ *
+ * @param form プロジェクト情報(プロジェクト名)
+ * @return HTTPレスポンス
+ */
+ @PATCH
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Valid
+ public HttpResponse patch(ProjectRenameForm form) {
+ Project project = UniversalDao.findById(Project.class, form.getProjectId());
+ project.setProjectName(form.getProjectName());
+
+ UniversalDao.update(project);
+
+ return new HttpResponse(HttpResponse.Status.NO_CONTENT.getStatusCode());
+ }
}
diff --git a/src/main/java/com/nablarch/example/form/ProjectRenameForm.java b/src/main/java/com/nablarch/example/form/ProjectRenameForm.java
new file mode 100644
index 0000000..716cde7
--- /dev/null
+++ b/src/main/java/com/nablarch/example/form/ProjectRenameForm.java
@@ -0,0 +1,63 @@
+package com.nablarch.example.form;
+
+import nablarch.core.validation.ee.Domain;
+import nablarch.core.validation.ee.Required;
+
+import javax.validation.constraints.AssertTrue;
+import java.io.Serializable;
+
+/**
+ * プロジェクト更新フォーム。
+ * @author Nabu Rakutaro
+ */
+public class ProjectRenameForm implements Serializable {
+
+ /** シリアルバージョンUID */
+ private static final long serialVersionUID = 1L;
+
+ /** プロジェクトID */
+ @Required
+ @Domain("id")
+ private String projectId;
+
+ /** プロジェクト名 */
+ @Required
+ @Domain("projectName")
+ private String projectName;
+
+ /**
+ * プロジェクトIDを取得する。
+ *
+ * @return プロジェクトID
+ */
+ public String getProjectId() {
+ return projectId;
+ }
+
+ /**
+ * プロジェクト名を取得する。
+ *
+ * @return プロジェクト名
+ */
+ public String getProjectName() {
+ return projectName;
+ }
+
+ /**
+ * プロジェクトIDを設定する。
+ *
+ * @param projectId プロジェクトID
+ */
+ public void setProjectId(String projectId) {
+ this.projectId = projectId;
+ }
+
+ /**
+ * プロジェクト名を設定する。
+ *
+ * @param projectName プロジェクト名
+ */
+ public void setProjectName(String projectName) {
+ this.projectName = projectName;
+ }
+}
diff --git a/src/test/java/com/nablarch/example/action/ProjectActionTest.java b/src/test/java/com/nablarch/example/action/ProjectActionTest.java
index 8d2b3a7..d54dbee 100644
--- a/src/test/java/com/nablarch/example/action/ProjectActionTest.java
+++ b/src/test/java/com/nablarch/example/action/ProjectActionTest.java
@@ -3,12 +3,14 @@
import com.jayway.jsonpath.JsonPath;
import com.nablarch.example.entity.Project;
import com.nablarch.example.form.ProjectForm;
+import com.nablarch.example.form.ProjectRenameForm;
import com.nablarch.example.form.ProjectUpdateForm;
import nablarch.core.beans.BeanUtil;
import nablarch.fw.web.HttpResponse;
import nablarch.test.core.http.RestTestSupport;
+import nablarch.test.junit5.extension.http.RestTest;
import org.json.JSONException;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.skyscreamer.jsonassert.JSONAssert;
import org.skyscreamer.jsonassert.JSONCompareMode;
@@ -19,60 +21,63 @@
import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath;
import static com.jayway.jsonpath.matchers.JsonPathMatchers.isJson;
import static com.jayway.jsonpath.matchers.JsonPathMatchers.withJsonPath;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.hasSize;
-import static org.junit.Assert.assertThat;
-public class ProjectActionTest extends RestTestSupport {
+@RestTest
+class ProjectActionTest {
+ RestTestSupport support;
+
@Test
- public void プロジェクト一覧が取得できること() throws JSONException {
+ void プロジェクト一覧が取得できること() throws JSONException {
String message = "プロジェクト一覧取得";
- HttpResponse response = sendRequest(get("/projects"));
- assertStatusCode(message, HttpResponse.Status.OK, response);
+ HttpResponse response = support.sendRequest(support.get("/projects"));
+ support.assertStatusCode(message, HttpResponse.Status.OK, response);
assertThat(response.getBodyString(), hasJsonPath("$", hasSize(10)));
- JSONAssert.assertEquals(message, readTextResource("プロジェクト一覧が取得できること.json")
+ JSONAssert.assertEquals(message, support.readTextResource(ProjectActionTest.class, "プロジェクト一覧が取得できること.json")
, response.getBodyString(), JSONCompareMode.LENIENT);
}
@Test
- public void プロジェクトを新規登録できること() {
+ void プロジェクトを新規登録できること() {
// プロジェクトが1件も登録されていないこと
String message1 = "プロジェクト一覧取得(登録前)";
- HttpResponse beforeRegisterResponse = sendRequest(get("/projects"));
- assertStatusCode(message1, HttpResponse.Status.OK, beforeRegisterResponse);
+ HttpResponse beforeRegisterResponse = support.sendRequest(support.get("/projects"));
+ support.assertStatusCode(message1, HttpResponse.Status.OK, beforeRegisterResponse);
assertThat(beforeRegisterResponse.getBodyString(), hasJsonPath("$", empty()));
// 新規登録
String message2 = "プロジェクト新規登録";
ProjectForm projectForm = createInsertProject();
- HttpResponse registerResponse = sendRequest(post("/projects").setBody(projectForm));
- assertStatusCode(message2, HttpResponse.Status.CREATED, registerResponse);
+ HttpResponse registerResponse = support.sendRequest(support.post("/projects").setBody(projectForm));
+ support.assertStatusCode(message2, HttpResponse.Status.CREATED, registerResponse);
// 登録したプロジェクトが取得できること
String message3 = "プロジェクト一覧取得(登録後)";
- HttpResponse afterRegisterResponse = sendRequest(get("/projects"));
- assertStatusCode(message3, HttpResponse.Status.OK, afterRegisterResponse);
+ HttpResponse afterRegisterResponse = support.sendRequest(support.get("/projects"));
+ support.assertStatusCode(message3, HttpResponse.Status.OK, afterRegisterResponse);
assertProjectEquals(BeanUtil.createAndCopy(Project.class, projectForm), afterRegisterResponse);
- assertTableEquals("プロジェクトを新規登録できること");
+ support.assertTableEquals("プロジェクトを新規登録できること");
}
@Test
- public void プロジェクトを更新できること() throws IOException {
+ void プロジェクトを更新できること() throws IOException {
String project001Uri = "/projects?projectName=プロジェクト001";
String project888Uri = "/projects?projectName=プロジェクト888";
String message1 = "変更前に変更しようとするプロジェクト名に一致するデータが存在しないこと";
- HttpResponse projectNameNotFoundResponse = sendRequest(get(project888Uri));
- assertStatusCode(message1, HttpResponse.Status.OK, projectNameNotFoundResponse);
+ HttpResponse projectNameNotFoundResponse = support.sendRequest(support.get(project888Uri));
+ support.assertStatusCode(message1, HttpResponse.Status.OK, projectNameNotFoundResponse);
assertThat(message1, projectNameNotFoundResponse.getBodyString(), hasJsonPath("$", empty()));
String message2 = "変更対象取得";
- HttpResponse getTargetProjectResponse = sendRequest(get(project001Uri));
- assertStatusCode(message2, HttpResponse.Status.OK, getTargetProjectResponse);
+ HttpResponse getTargetProjectResponse = support.sendRequest(support.get(project001Uri));
+ support.assertStatusCode(message2, HttpResponse.Status.OK, getTargetProjectResponse);
assertThat(message2, getTargetProjectResponse.getBodyString(), isJson(allOf(
withJsonPath("$", hasSize(1))
, withJsonPath("$[0]", hasEntry("projectName", "プロジェクト001")))));
@@ -81,21 +86,58 @@ public class ProjectActionTest extends RestTestSupport {
ProjectUpdateForm updateForm = setUpdateProject(String.valueOf(projectId));
String message3 = "プロジェクト更新";
- HttpResponse updateResponse = sendRequest(put("/projects").setBody(updateForm));
- assertStatusCode(message3, HttpResponse.Status.OK, updateResponse);
+ HttpResponse updateResponse = support.sendRequest(support.put("/projects").setBody(updateForm));
+ support.assertStatusCode(message3, HttpResponse.Status.OK, updateResponse);
String message4 = "変更前のプロジェクト名に一致するデータが存在しないこと";
- HttpResponse previousNameNotFoundResponse = sendRequest(get(project001Uri));
- assertStatusCode(message4, HttpResponse.Status.OK, previousNameNotFoundResponse);
+ HttpResponse previousNameNotFoundResponse = support.sendRequest(support.get(project001Uri));
+ support.assertStatusCode(message4, HttpResponse.Status.OK, previousNameNotFoundResponse);
assertThat(message4, previousNameNotFoundResponse.getBodyString(), hasJsonPath("$", empty()));
String message5 = "取得したプロジェクトが変更した内容と一致すること";
- HttpResponse projectNameFoundResponse = sendRequest(get(project888Uri));
- assertStatusCode(message5, HttpResponse.Status.OK, projectNameFoundResponse);
+ HttpResponse projectNameFoundResponse = support.sendRequest(support.get(project888Uri));
+ support.assertStatusCode(message5, HttpResponse.Status.OK, projectNameFoundResponse);
// Projectとのアサート
assertProjectEquals(BeanUtil.createAndCopy(Project.class, updateForm), projectNameFoundResponse);
}
+
+ @Test
+ void プロジェクト名を更新できること() throws IOException {
+ String project002Uri = "/projects?projectName=プロジェクト002";
+ String project777Uri = "/projects?projectName=プロジェクト777";
+
+ String message1 = "変更前に変更しようとするプロジェクト名に一致するデータが存在しないこと";
+ HttpResponse projectNameNotFoundResponse = support.sendRequest(support.get(project777Uri));
+ support.assertStatusCode(message1, HttpResponse.Status.OK, projectNameNotFoundResponse);
+ assertThat(message1, projectNameNotFoundResponse.getBodyString(), hasJsonPath("$", empty()));
+
+ String message2 = "変更対象取得";
+ HttpResponse getTargetProjectResponse = support.sendRequest(support.get(project002Uri));
+ support.assertStatusCode(message2, HttpResponse.Status.OK, getTargetProjectResponse);
+ assertThat(message2, getTargetProjectResponse.getBodyString(), isJson(allOf(
+ withJsonPath("$", hasSize(1))
+ , withJsonPath("$[0]", hasEntry("projectName", "プロジェクト002")))));
+
+ int projectId = JsonPath.read(getTargetProjectResponse.getBodyStream(), "$[0].projectId");
+ ProjectRenameForm renameForm = setRenameProject(String.valueOf(projectId));
+
+ String message3 = "プロジェクト名更新";
+ HttpResponse renamedResponse = support.sendRequest(support.patch("/projects").setBody(renameForm));
+ support.assertStatusCode(message3, HttpResponse.Status.NO_CONTENT, renamedResponse);
+
+ String message4 = "変更前のプロジェクト名に一致するデータが存在しないこと";
+ HttpResponse previousNameNotFoundResponse = support.sendRequest(support.get(project002Uri));
+ support.assertStatusCode(message4, HttpResponse.Status.OK, previousNameNotFoundResponse);
+ assertThat(message4, previousNameNotFoundResponse.getBodyString(), hasJsonPath("$", empty()));
+ String message5 = "取得したプロジェクトが変更した内容と一致すること";
+ HttpResponse projectNameFoundResponse = support.sendRequest(support.get(project777Uri));
+ support.assertStatusCode(message5, HttpResponse.Status.OK, projectNameFoundResponse);
+ with(projectNameFoundResponse.getBodyString())
+ .assertThat("$", hasSize(1))
+ .assertThat("$[0]", hasEntry("projectId", Integer.parseInt(renameForm.getProjectId())))
+ .assertThat("$[0]", hasEntry("projectName", renameForm.getProjectName()));
+ }
private void assertProjectEquals(Project expected, HttpResponse response) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
@@ -163,4 +205,17 @@ private static ProjectUpdateForm setUpdateProject(String projectId) {
form.setAllocationOfCorpExpenses("4000");
return form;
}
+
+ /**
+ * プロジェクト名変更用プロジェクト情報設定
+ *
+ * @param projectId 更新対象プロジェクトID
+ * @return プロジェクト名変更用プロジェクト情報
+ */
+ private static ProjectRenameForm setRenameProject(String projectId) {
+ ProjectRenameForm form = new ProjectRenameForm();
+ form.setProjectId(projectId);
+ form.setProjectName("プロジェクト777");
+ return form;
+ }
}
diff --git a/src/test/java/com/nablarch/example/form/ProjectFormTestIsValidProjectPeriod.java b/src/test/java/com/nablarch/example/form/ProjectFormTestIsValidProjectPeriod.java
index 6e92a29..48fc181 100644
--- a/src/test/java/com/nablarch/example/form/ProjectFormTestIsValidProjectPeriod.java
+++ b/src/test/java/com/nablarch/example/form/ProjectFormTestIsValidProjectPeriod.java
@@ -1,35 +1,37 @@
package com.nablarch.example.form;
import org.hamcrest.CoreMatchers;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
-import org.junit.Assert;
-import org.junit.experimental.theories.DataPoints;
-import org.junit.experimental.theories.Theories;
-import org.junit.experimental.theories.Theory;
-import org.junit.runner.RunWith;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.hamcrest.MatcherAssert.assertThat;
/**
* {@link ProjectForm#isValidProjectPeriod()}のテスト。
*/
-@RunWith(Theories.class)
-public class ProjectFormTestIsValidProjectPeriod {
-
- @DataPoints
- public static Fixture[] fixtures = {
+class ProjectFormTestIsValidProjectPeriod {
+
+ static List プロジェクト期間の相関バリデーションのテスト() {
+ return Arrays.asList(
new Fixture("", "", true),
new Fixture("", "20150101", true),
new Fixture("20150101", "", true),
new Fixture("20150101", "20150102", true),
new Fixture("20150102", "20150101", false)
- };
+ );
+ }
- @Theory
- public void プロジェクト期間の相関バリデーションのテスト(Fixture fixture) throws Exception {
+ @ParameterizedTest
+ @MethodSource
+ void プロジェクト期間の相関バリデーションのテスト(Fixture fixture) throws Exception {
final ProjectForm form = new ProjectForm();
form.setProjectStartDate(fixture.start);
form.setProjectEndDate(fixture.end);
- Assert.assertThat(form.isValidProjectPeriod(), CoreMatchers.is(fixture.expected));
+ assertThat(form.isValidProjectPeriod(), CoreMatchers.is(fixture.expected));
}
private static class Fixture {