diff --git a/CHANGELOG.md b/CHANGELOG.md
index 234a0879b..d5d7c49d0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,14 @@
+## 1.5.0
+BUG FIXES:
+* Unavailability of TLS 1.2.
+ ([#3](https://github.com/personium/personium-client-java/issues/3))
+
+IMPROVEMENTS:
+* Enable specification of class URL in RequestRelation of message API.
+ ([#19](https://github.com/personium/personium-core/issues/19))
+* Change OAuth2Token authentication API endpoint.
+ ([#20](https://github.com/personium/personium-core/issues/20))
+
## 1.4.6
BUG FIXES:
* Implementation of BoxBound function of message API.
diff --git a/pom.xml b/pom.xml
index cefc77bf0..b0476d1c9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
io.personium
personium-core
war
- 1.4.6
+ 1.5.0
personium-core Maven Webapp
http://maven.apache.org
@@ -46,7 +46,7 @@
io.personium
personium-client-java
- 1.4.2
+ 1.4.3
test
diff --git a/src/main/java/io/personium/core/PersoniumCoreAuthnException.java b/src/main/java/io/personium/core/PersoniumCoreAuthnException.java
index 51464ae82..f6926eec5 100644
--- a/src/main/java/io/personium/core/PersoniumCoreAuthnException.java
+++ b/src/main/java/io/personium/core/PersoniumCoreAuthnException.java
@@ -16,13 +16,6 @@
*/
package io.personium.core;
-import io.personium.core.auth.OAuth2Helper.Error;
-import io.personium.core.auth.OAuth2Helper.Key;
-import io.personium.core.auth.OAuth2Helper.Scheme;
-import io.personium.core.utils.EscapeControlCode;
-import io.personium.plugin.base.PluginException;
-import io.personium.plugin.base.PluginMessageUtils.Severity;
-
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Map;
@@ -35,6 +28,13 @@
import org.apache.http.HttpStatus;
import org.json.simple.JSONObject;
+import io.personium.core.auth.OAuth2Helper.Error;
+import io.personium.core.auth.OAuth2Helper.Key;
+import io.personium.core.auth.OAuth2Helper.Scheme;
+import io.personium.core.utils.EscapeControlCode;
+import io.personium.plugin.base.PluginException;
+import io.personium.plugin.base.PluginMessageUtils.Severity;
+
/**
* ログメッセージ作成クラス.
*/
@@ -234,7 +234,7 @@ public Response createResponse() {
.entity(errorJson.toJSONString());
// レルム値が設定されていれば、WWW-Authenticateヘッダーを返却する。
- // __authエンドポイントでは、認証失敗時(401返却時)には、同ヘッダーに Auth SchemeがBasicの値を返却するため、ここでは固定値とする。
+ // __tokenエンドポイントでは、認証失敗時(401返却時)には、同ヘッダーに Auth SchemeがBasicの値を返却するため、ここでは固定値とする。
if (this.realm != null && statusCode == HttpStatus.SC_UNAUTHORIZED) {
rb = rb.header(HttpHeaders.WWW_AUTHENTICATE, Scheme.BASIC + " realm=\"" + this.realm + "\"");
}
diff --git a/src/main/java/io/personium/core/PersoniumCoreException.java b/src/main/java/io/personium/core/PersoniumCoreException.java
index 3f6415ec2..43d3f1bef 100644
--- a/src/main/java/io/personium/core/PersoniumCoreException.java
+++ b/src/main/java/io/personium/core/PersoniumCoreException.java
@@ -16,10 +16,6 @@
*/
package io.personium.core;
-import io.personium.core.exceptions.ODataErrorMessage;
-import io.personium.core.utils.EscapeControlCode;
-import io.personium.plugin.base.PluginMessageUtils.Severity;
-
import java.text.MessageFormat;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -29,6 +25,10 @@
import org.apache.http.HttpStatus;
+import io.personium.core.exceptions.ODataErrorMessage;
+import io.personium.core.utils.EscapeControlCode;
+import io.personium.plugin.base.PluginMessageUtils.Severity;
+
/**
* ログメッセージ作成クラス.
*/
@@ -543,6 +543,11 @@ public static class SentMessage {
* 送信先URLが最大送信許可数を超えた場合.
*/
public static final PersoniumCoreException OVER_MAX_SENT_NUM = create("PR400-SM-0003");
+ /**
+ * When the Box corresponding to the schema can not be found from the schema-authenticated token.
+ * {0}:Schema
+ */
+ public static final PersoniumCoreException BOX_THAT_MATCHES_SCHEMA_NOT_EXISTS = create("PR400-SM-0004");
/**
* リクエストに失敗した場合.
@@ -557,11 +562,21 @@ public static class SentMessage {
/**
* ReceiveMessageAPI呼出し時のエラー.
*/
- public static class ReceiveMessage {
+ public static class ReceivedMessage {
/**
* メッセージの関係登録で既に関係が存在する.
*/
public static final PersoniumCoreException REQUEST_RELATION_EXISTS_ERROR = create("PR400-RM-0001");
+ /**
+ * When a Box corresponding to the schema can not be found.
+ * {0}:Schema
+ */
+ public static final PersoniumCoreException BOX_THAT_MATCHES_SCHEMA_NOT_EXISTS = create("PR400-RM-0002");
+ /**
+ * When the Box corresponding to the RelationClassURL can not be found.
+ * {0}:RelationClassURL
+ */
+ public static final PersoniumCoreException BOX_THAT_MATCHES_RELATION_CLASS_URL_NOT_EXISTS = create("PR400-RM-0003"); // CHECKSTYLE IGNORE - To maintain readability
/**
* メッセージのRequestRelationのパースに失敗.
*/
diff --git a/src/main/java/io/personium/core/PersoniumReadDeleteModeManager.java b/src/main/java/io/personium/core/PersoniumReadDeleteModeManager.java
index 9bba6086b..c11774c35 100644
--- a/src/main/java/io/personium/core/PersoniumReadDeleteModeManager.java
+++ b/src/main/java/io/personium/core/PersoniumReadDeleteModeManager.java
@@ -105,10 +105,10 @@ private static boolean isBatchPath(List pathSegment) {
}
private static boolean isAuthPath(List pathSegment) {
- // 認証のパスは/cell名/__auth または /cell名/__authz のためサイズを2とする
+ // 認証のパスは/cell名/__token または /cell名/__authz のためサイズを2とする
if (pathSegment.size() == 2) {
String lastPath = pathSegment.get(1).getPath();
- if ("__auth".equals(lastPath) || "__authz".equals(lastPath)) {
+ if ("__token".equals(lastPath) || "__authz".equals(lastPath)) {
return true;
}
}
diff --git a/src/main/java/io/personium/core/model/ctl/Common.java b/src/main/java/io/personium/core/model/ctl/Common.java
index 4a1a292bd..c84fe19f8 100644
--- a/src/main/java/io/personium/core/model/ctl/Common.java
+++ b/src/main/java/io/personium/core/model/ctl/Common.java
@@ -73,6 +73,8 @@ private Common() {
public static final String P_FORMAT_PATTERN_SCHEMA_URI = "schema-uri";
/** 拡張スキーマFormat定義. */
public static final String P_FORMAT_PATTERN_CELL_URL = "cell-url";
+ /** Extended schema Format definition(Message RequestRelation). */
+ public static final String P_FORMAT_PATTERN_MESSAGE_REQUEST_RELATION = "message-request-relation";
/** 拡張スキーマFormat定義.1つ以上のスペース区切り英数字. */
public static final String P_FORMAT_PATTERN_USUSST = "unordered-set-of-unique-space-separated-tokens";
/** 先頭が-,_以外で始まる半角英数大小文字,-,_が1文字から128文字. */
@@ -81,6 +83,12 @@ private Common() {
public static final String PATTERN_NAME_WITH_SIGN = "^[a-zA-Z0-9][a-zA-Z0-9-_!$*=^`{|}~.@]{0,127}$";
/** 先頭が_,:以外で始まる半角英数大小文字,-,_,+,:が1文字から128文字. */
public static final String PATTERN_RELATION_NAME = "^[a-zA-Z0-9-\\+][a-zA-Z0-9-_\\+:]{0,127}$";
+ /** String containing "/__relation/__/".
+ * Explanation of applicable group.
+ * $1:BaseURL
+ * $2:CellName
+ * $3:RelationName */
+ public static final String PATTERN_RELATION_CLASS_URL = "(^.+)/([^/]+)/__relation/__/([^/]+)/?";
/** multiplicityのFormat定義. */
public static final String PATTERN_MULTIPLICITY = "0\\.\\.1|1|\\*";
/** 先頭が-,_以外で始まる半角英数大小文字,-,_が1文字から200文字. */
@@ -158,6 +166,10 @@ private Common() {
* MessagePriority項目に対するp:Formatの定義.
*/
public static final List> P_FORMAT_MESSAGE_PRIORITY = new ArrayList>();
+ /**
+ * Definition of p: Format for MessageRequestRelation item.
+ */
+ public static final List> P_FORMAT_MESSAGE_REQUEST_RELATION = new ArrayList>();
/**
* AccountType項目に対するp:Formatの定義.
*/
@@ -193,6 +205,7 @@ private Common() {
P_FORMAT_MESSAGE_TYPE.add(createFormatMessageTypeAnnotation());
P_FORMAT_MESSAGE_TITLE.add(createFormatMessageTitleAnnotation());
P_FORMAT_MESSAGE_PRIORITY.add(createFormatMessagePriorityAnnotation());
+ P_FORMAT_MESSAGE_REQUEST_RELATION.add(createFormatMessageRequestRelation());
P_FORMAT_ACCOUNT_TYPE.add(createFormatAccountTypeAnnotation());
}
@@ -316,6 +329,16 @@ public static EdmAnnotation> createFormatMessagePriorityAnnotation() {
P_FORMAT, P_FORMAT_PATTERN_REGEX + "('" + Common.PATTERN_MESSAGE_PRIORITY + "')");
}
+ /**
+ * Return p: Format Annotation for MessageRequestRelation item.
+ * @return EdmAnnotation
+ */
+ public static EdmAnnotation> createFormatMessageRequestRelation() {
+ return new EdmAnnotationAttribute(
+ P_NAMESPACE.getUri(), P_NAMESPACE.getPrefix(),
+ P_FORMAT, P_FORMAT_PATTERN_MESSAGE_REQUEST_RELATION);
+ }
+
/**
* Account Type 項目に対するp:FormatのAnnotationを返却.
* @return EdmAnnotation
diff --git a/src/main/java/io/personium/core/model/ctl/ReceivedMessage.java b/src/main/java/io/personium/core/model/ctl/ReceivedMessage.java
index 48dcd951a..ecfd7c49c 100644
--- a/src/main/java/io/personium/core/model/ctl/ReceivedMessage.java
+++ b/src/main/java/io/personium/core/model/ctl/ReceivedMessage.java
@@ -135,7 +135,7 @@ protected ReceivedMessage() {
public static final EdmProperty.Builder P_REQUEST_RELATION = EdmProperty.newBuilder("RequestRelation")
.setType(EdmSimpleType.STRING)
.setNullable(true)
- .setAnnotations(Common.P_FORMAT_URI);
+ .setAnnotations(Common.P_FORMAT_MESSAGE_REQUEST_RELATION);
/**
* RequestRelationTargetプロパティの定義体.
*/
diff --git a/src/main/java/io/personium/core/model/ctl/SentMessage.java b/src/main/java/io/personium/core/model/ctl/SentMessage.java
index b29b5e9e3..ad278f446 100644
--- a/src/main/java/io/personium/core/model/ctl/SentMessage.java
+++ b/src/main/java/io/personium/core/model/ctl/SentMessage.java
@@ -100,7 +100,7 @@ protected SentMessage() {
public static final EdmProperty.Builder P_REQUEST_RELATION = EdmProperty.newBuilder("RequestRelation")
.setType(EdmSimpleType.STRING)
.setNullable(true)
- .setAnnotations(Common.P_FORMAT_URI);
+ .setAnnotations(Common.P_FORMAT_MESSAGE_REQUEST_RELATION);
/**
* RequestRelationTargetプロパティの定義体.
*/
diff --git a/src/main/java/io/personium/core/model/impl/es/odata/CellCtlODataProducer.java b/src/main/java/io/personium/core/model/impl/es/odata/CellCtlODataProducer.java
index 3b45d647d..32494a9e0 100644
--- a/src/main/java/io/personium/core/model/impl/es/odata/CellCtlODataProducer.java
+++ b/src/main/java/io/personium/core/model/impl/es/odata/CellCtlODataProducer.java
@@ -46,7 +46,6 @@
import io.personium.core.model.ctl.CtlSchema;
import io.personium.core.model.ctl.ExtCell;
import io.personium.core.model.ctl.ReceivedMessage;
-import io.personium.core.model.ctl.ReceivedMessagePort;
import io.personium.core.model.ctl.Relation;
import io.personium.core.model.ctl.SentMessage;
import io.personium.core.model.impl.es.EsModel;
@@ -59,6 +58,7 @@
import io.personium.core.model.impl.es.odata.EsNavigationTargetKeyProperty.NTKPNotFoundException;
import io.personium.core.model.lock.Lock;
import io.personium.core.odata.OEntityWrapper;
+import io.personium.core.utils.UriUtils;
/**
* Cell管理オブジェクトの ODataProducer.
@@ -130,29 +130,13 @@ public String getCellId() {
*/
@Override
public void beforeCreate(final String entitySetName, final OEntity oEntity, final EntitySetDocHandler docHandler) {
- if (entitySetName.equals(ReceivedMessage.EDM_TYPE_NAME)) {
- // 受信メッセージの場合は登録データから「_Box.Name」を削除
- // TODO dynamicに値はこないと思うが既存の処理なのでとりあえず残す。意図が不明。
- Map dynamic = docHandler.getDynamicFields();
- dynamic.remove(ReceivedMessage.P_BOX_NAME.getName());
- docHandler.setDynamicFields(dynamic);
-
- // Removed _Box.Name and add links
- Map staticFields = docHandler.getStaticFields();
- if (staticFields.get(ReceivedMessage.P_BOX_NAME.getName()) != null) {
- Box box = this.cell.getBoxForName((String) staticFields.get(ReceivedMessage.P_BOX_NAME.getName()));
- docHandler.getStaticFields().remove(ReceivedMessage.P_BOX_NAME.getName());
-
- Map links = docHandler.getManyToOnelinkId();
- links.put("Box", box.getId());
- docHandler.setManyToOnelinkId(links);
- }
- } else if (entitySetName.equals(SentMessage.EDM_TYPE_NAME)) {
+ if (entitySetName.equals(ReceivedMessage.EDM_TYPE_NAME)
+ || entitySetName.equals(SentMessage.EDM_TYPE_NAME)) {
// Removed _Box.Name and add links
Map staticFields = docHandler.getStaticFields();
- if (staticFields.get(SentMessage.P_BOX_NAME.getName()) != null) {
- Box box = this.cell.getBoxForName((String) staticFields.get(SentMessage.P_BOX_NAME.getName()));
- docHandler.getStaticFields().remove(SentMessage.P_BOX_NAME.getName());
+ if (staticFields.get(Common.P_BOX_NAME.getName()) != null) {
+ Box box = this.cell.getBoxForName((String) staticFields.get(Common.P_BOX_NAME.getName()));
+ docHandler.getStaticFields().remove(Common.P_BOX_NAME.getName());
Map links = docHandler.getManyToOnelinkId();
links.put("Box", box.getId());
@@ -309,15 +293,17 @@ private void buildRelation(EntitySetDocHandler entitySetDocHandler) {
// 登録対象のRelation名取得
String requestRelation = (String) entitySetDocHandler.getStaticFields().get(
ReceivedMessage.P_REQUEST_RELATION.getName());
- String[] partRequestRelation = requestRelation.split("/");
- String relationName = partRequestRelation[partRequestRelation.length - 1];
+ String relationName = getRelationNameFromRequestRelation(requestRelation);
// Get box name
- String boxName = (String) entitySetDocHandler.getStaticFields().get(
- ReceivedMessage.P_BOX_NAME.getName());
+ String boxName = getBoxNameFromRequestRelation(requestRelation);
+ if (boxName == null) {
+ // If box can not be found from RequestRelation (RequestRelation is RelationName only),
+ // get BoxName from _ Box.Name
+ boxName = (String) entitySetDocHandler.getStaticFields().get(ReceivedMessage.P_BOX_NAME.getName());
+ }
EntitySetDocHandler relation = getRelation(relationName, boxName);
if (relation == null) {
-
// データが存在しない場合はRelationを新規に登録
createRelationEntity(relationName, boxName);
}
@@ -356,7 +342,7 @@ private void createRelationExtCellLinks(String relationName, String boxName, Str
} catch (PersoniumCoreException e) {
if (PersoniumCoreException.OData.CONFLICT_LINKS.getCode().equals(e.getCode())) {
// $linksが既に存在する場合
- throw PersoniumCoreException.ReceiveMessage.REQUEST_RELATION_EXISTS_ERROR;
+ throw PersoniumCoreException.ReceivedMessage.REQUEST_RELATION_EXISTS_ERROR;
}
throw e;
}
@@ -367,7 +353,7 @@ private OEntityKey createExtCellOEntityKey(String requestExtCell) {
try {
extCellOEntityKey = OEntityKey.parse("('" + requestExtCell + "')");
} catch (IllegalArgumentException e) {
- throw PersoniumCoreException.ReceiveMessage.REQUEST_RELATION_TARGET_PARSE_ERROR.reason(e);
+ throw PersoniumCoreException.ReceivedMessage.REQUEST_RELATION_TARGET_PARSE_ERROR.reason(e);
}
return extCellOEntityKey;
}
@@ -390,7 +376,7 @@ private OEntityKey createRelationOEntityKey(String relationName, String boxName)
try {
relationOEntityKey = OEntityKey.parse(parseString);
} catch (IllegalArgumentException e) {
- throw PersoniumCoreException.ReceiveMessage.REQUEST_RELATION_PARSE_ERROR.reason(e);
+ throw PersoniumCoreException.ReceivedMessage.REQUEST_RELATION_PARSE_ERROR.reason(e);
}
return relationOEntityKey;
}
@@ -518,57 +504,87 @@ protected void breakRelation(EntitySetDocHandler entitySetDocHandler) {
log.debug("breakRelation start.");
// RequestRelationからRelation名を取得する
String reqRelation = entitySetDocHandler.getStaticFields()
- .get(ReceivedMessagePort.P_REQUEST_RELATION.getName()).toString();
- String relationName = getRelationFromRelationClassUrl(reqRelation);
+ .get(ReceivedMessage.P_REQUEST_RELATION.getName()).toString();
+ String relationName = getRelationNameFromRequestRelation(reqRelation);
// Get box name
- String boxName = (String) entitySetDocHandler.getStaticFields().get(
- ReceivedMessage.P_BOX_NAME.getName());
- if (relationName == null) {
- throw PersoniumCoreException.ReceiveMessage.REQUEST_RELATION_PARSE_ERROR;
+ String boxName = getBoxNameFromRequestRelation(reqRelation);
+ if (boxName == null) {
+ // If box can not be found from RequestRelation (RequestRelation is RelationName only),
+ // get BoxName from _ Box.Name
+ boxName = (String) entitySetDocHandler.getStaticFields().get(ReceivedMessage.P_BOX_NAME.getName());
}
// 対象のRelationが存在することを確認
EntitySetDocHandler relation = getRelation(relationName, boxName);
if (relation == null) {
log.debug(String.format("RequestRelation does not exists. [%s]", relationName));
- throw PersoniumCoreException.ReceiveMessage.REQUEST_RELATION_DOES_NOT_EXISTS.params(relationName);
+ throw PersoniumCoreException.ReceivedMessage.REQUEST_RELATION_DOES_NOT_EXISTS.params(relationName);
}
// 対象のExtCell(RequestRelationTarget)が存在することを確認
String extCellUrl = entitySetDocHandler.getStaticFields()
- .get(ReceivedMessagePort.P_REQUEST_RELATION_TARGET.getName()).toString();
+ .get(ReceivedMessage.P_REQUEST_RELATION_TARGET.getName()).toString();
EntitySetDocHandler extCell = getExtCell(extCellUrl);
if (extCell == null) {
log.debug(String.format("RequestRelationTarget does not exists. [%s]", extCellUrl));
- throw PersoniumCoreException.ReceiveMessage.REQUEST_RELATION_TARGET_DOES_NOT_EXISTS.params(extCellUrl);
+ throw PersoniumCoreException.ReceivedMessage.REQUEST_RELATION_TARGET_DOES_NOT_EXISTS.params(extCellUrl);
}
// RelationとExtCellの関連を削除する
if (!deleteLinkEntity(relation, extCell)) {
log.debug(String.format("RequestRelation and RequestRelationTarget does not related. [%s] - [%s]",
relationName, extCellUrl));
- throw PersoniumCoreException.ReceiveMessage.LINK_DOES_NOT_EXISTS.params(relationName, extCellUrl);
+ throw PersoniumCoreException.ReceivedMessage.LINK_DOES_NOT_EXISTS.params(relationName, extCellUrl);
}
log.debug("breakRelation success.");
}
/**
- * リレーションクラスURLからリレーション名を取得する.
- * @param relationClassUrl リレーションクラスURL
- * @return リレーション名
+ * Get BoxName from RequestRelation.
+ * If RequestRelation is only RelationName, return null.
+ * @param requestRelation RequestRelation
+ * @return BoxName
+ * @throws PersoniumCoreException Box corresponding to the RelationClassURL can not be found
*/
- protected String getRelationFromRelationClassUrl(String relationClassUrl) {
- String relationName = null;
- log.debug(String.format("RequestRelation URI = [%s]", relationClassUrl));
+ protected String getBoxNameFromRequestRelation(String requestRelation) throws PersoniumCoreException {
+ String boxName = null;
+ log.debug(String.format("RequestRelation URI = [%s]", requestRelation));
+
+ // convert localunitUrl to unitUrl
+ String convertedRequestRelation = UriUtils.convertSchemeFromLocalUnitToHttp(cell.getUnitUrl(), requestRelation);
+ Pattern pattern = Pattern.compile(Common.PATTERN_RELATION_CLASS_URL);
+ Matcher matcher = pattern.matcher(convertedRequestRelation);
+ if (matcher.matches()) {
+ String schema = matcher.replaceAll("$1" + "/" + "$2" + "/");
+ Box box = this.cell.getBoxForSchema(schema);
+ if (box != null) {
+ boxName = box.getName();
+ } else {
+ throw PersoniumCoreException.ReceivedMessage
+ .BOX_THAT_MATCHES_RELATION_CLASS_URL_NOT_EXISTS.params(convertedRequestRelation);
+ }
+ }
+ return boxName;
+ }
- Pattern pattern = Pattern.compile(".+/([^/]+)/__relation/([^/]+)/([^/]+)/?");
- Matcher m = pattern.matcher(relationClassUrl);
- if (!m.matches()) {
- log.debug(String.format("RequestRelation URI if not relationClassUrl format. [%s]", relationClassUrl));
- return relationName;
+ /**
+ * Get RelationName from RequestRelation.
+ * @param requestRelation RequestRelation
+ * @return RelationName
+ */
+ protected String getRelationNameFromRequestRelation(String requestRelation) {
+ String relationName = null;
+ log.debug(String.format("RequestRelation URI = [%s]", requestRelation));
+
+ // convert localunitUrl to unitUrl
+ String convertedRequestRelation = UriUtils.convertSchemeFromLocalUnitToHttp(cell.getUnitUrl(), requestRelation);
+ Pattern pattern = Pattern.compile(Common.PATTERN_RELATION_CLASS_URL);
+ Matcher m = pattern.matcher(convertedRequestRelation);
+ if (m.matches()) {
+ relationName = m.replaceAll("$3");
+ } else {
+ relationName = convertedRequestRelation;
}
- relationName = m.replaceAll("$3");
- log.debug(String.format("RequestRelation URI Path = [%s]", relationName));
return relationName;
}
diff --git a/src/main/java/io/personium/core/model/impl/es/odata/EsODataProducer.java b/src/main/java/io/personium/core/model/impl/es/odata/EsODataProducer.java
index 3a21c2078..fc1fc074c 100644
--- a/src/main/java/io/personium/core/model/impl/es/odata/EsODataProducer.java
+++ b/src/main/java/io/personium/core/model/impl/es/odata/EsODataProducer.java
@@ -923,6 +923,12 @@ public String getEntityTypeId(final String entityTypeName) {
return null;
}
+ /**
+ * Get NtkpValueMap from EntitySet and set it as an object of argument.
+ * @param eSet EntitySet
+ * @param ntkpProperties NtkpProperties
+ * @param ntkpValueMap NtkpValueMap
+ */
@SuppressWarnings("unchecked")
protected void getNtkpValueMap(EdmEntitySet eSet,
Map ntkpProperties,
diff --git a/src/main/java/io/personium/core/rs/cell/CellResource.java b/src/main/java/io/personium/core/rs/cell/CellResource.java
index ed45d4d57..3ecb103b1 100644
--- a/src/main/java/io/personium/core/rs/cell/CellResource.java
+++ b/src/main/java/io/personium/core/rs/cell/CellResource.java
@@ -217,7 +217,7 @@ public PasswordResource mypassword(
*
* @return TokenEndPointResourceオブジェクト
*/
- @Path("__auth")
+ @Path("__token")
public TokenEndPointResource auth() {
return new TokenEndPointResource(this.cell, this.cellRsCmp);
}
diff --git a/src/main/java/io/personium/core/rs/cell/MessageODataResource.java b/src/main/java/io/personium/core/rs/cell/MessageODataResource.java
index 530b5cd9d..44a26518f 100644
--- a/src/main/java/io/personium/core/rs/cell/MessageODataResource.java
+++ b/src/main/java/io/personium/core/rs/cell/MessageODataResource.java
@@ -38,6 +38,7 @@
import javax.ws.rs.core.UriInfo;
import org.apache.commons.lang.CharEncoding;
+import org.apache.commons.lang.StringUtils;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
@@ -606,6 +607,7 @@ private JSONObject bodyAsJson(HttpResponse objResponse) {
public void validate(List> props) {
// メッセージ受信のときのチェック
if (ReceivedMessage.EDM_TYPE_NAME.equals(this.getEntitySetName())) {
+ validateReceivedBoxBoundSchema(this.odataResource, propMap.get(ReceivedMessagePort.P_SCHEMA.getName()));
MessageODataResource.validateUriCsv(ReceivedMessage.P_MULTICAST_TO.getName(),
propMap.get(ReceivedMessage.P_MULTICAST_TO.getName()));
MessageODataResource.validateBody(propMap.get(ReceivedMessage.P_BODY.getName()),
@@ -618,6 +620,8 @@ public void validate(List> props) {
}
// メッセージ送信のときのチェック
if (SentMessage.EDM_TYPE_NAME.equals(this.getEntitySetName())) {
+ validateSentBoxBoundSchema(this.odataResource,
+ Boolean.valueOf(propMap.get(SentMessagePort.P_BOX_BOUND.getName())));
MessageODataResource.validateUriCsv(SentMessage.P_TO.getName(), propMap.get(SentMessage.P_TO.getName()));
MessageODataResource.validateBody(propMap.get(SentMessage.P_BODY.getName()),
Common.MAX_MESSAGE_BODY_LENGTH);
@@ -650,6 +654,35 @@ public void collectProperties(List> props) {
}
}
+ /**
+ * Schema check at Box Bound.
+ * @param messageResource ODataResource
+ * @param schema Schema
+ */
+ public void validateReceivedBoxBoundSchema(MessageResource messageResource, String schema) {
+ if (StringUtils.isNotEmpty(schema)) {
+ Box box = messageResource.getAccessContext().getCell().getBoxForSchema(schema);
+ if (box == null) {
+ throw PersoniumCoreException.ReceivedMessage.BOX_THAT_MATCHES_SCHEMA_NOT_EXISTS.params(schema);
+ }
+ }
+ }
+
+ /**
+ * Schema check at Box Bound.
+ * @param messageResource ODataResource
+ * @param boxboundFlag BoxBoundFlag
+ */
+ public void validateSentBoxBoundSchema(MessageResource messageResource, boolean boxboundFlag) {
+ if (boxboundFlag) {
+ String schema = messageResource.getAccessContext().getSchema();
+ Box box = messageResource.getAccessContext().getCell().getBoxForSchema(schema);
+ if (box == null) {
+ throw PersoniumCoreException.SentMessage.BOX_THAT_MATCHES_SCHEMA_NOT_EXISTS.params(schema);
+ }
+ }
+ }
+
/**
* MulticastToのバリデート.
* @param propKey プロパティキー
diff --git a/src/main/java/io/personium/core/rs/cell/TokenEndPointResource.java b/src/main/java/io/personium/core/rs/cell/TokenEndPointResource.java
index fb365139b..b241bab6e 100644
--- a/src/main/java/io/personium/core/rs/cell/TokenEndPointResource.java
+++ b/src/main/java/io/personium/core/rs/cell/TokenEndPointResource.java
@@ -17,6 +17,35 @@
package io.personium.core.rs.cell;
import static io.personium.common.auth.token.AbstractOAuth2Token.MILLISECS_IN_AN_HOUR;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import javax.ws.rs.FormParam;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.HttpMethod;
+import javax.ws.rs.OPTIONS;
+import javax.ws.rs.POST;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Cookie;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.NewCookie;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.ResponseBuilder;
+import javax.ws.rs.core.UriInfo;
+
+import org.json.simple.JSONObject;
+import org.odata4j.core.OEntityKey;
+import org.odata4j.edm.EdmEntitySet;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import io.personium.common.auth.token.AbstractOAuth2Token;
import io.personium.common.auth.token.AbstractOAuth2Token.TokenDsigException;
import io.personium.common.auth.token.AbstractOAuth2Token.TokenParseException;
@@ -58,34 +87,6 @@
import io.personium.plugin.base.auth.AuthPlugin;
import io.personium.plugin.base.auth.AuthenticatedIdentity;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-
-import javax.ws.rs.FormParam;
-import javax.ws.rs.HeaderParam;
-import javax.ws.rs.HttpMethod;
-import javax.ws.rs.OPTIONS;
-import javax.ws.rs.POST;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.Cookie;
-import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.NewCookie;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.ResponseBuilder;
-import javax.ws.rs.core.UriInfo;
-
-import org.json.simple.JSONObject;
-import org.odata4j.core.OEntityKey;
-import org.odata4j.edm.EdmEntitySet;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
/**
* 認証処理を司るJAX-RSリソース.
*/
@@ -609,7 +610,7 @@ private Response responseAuthSuccess(final IAccessToken accessToken,
.type(MediaType.APPLICATION_JSON_TYPE);
if (accessToken.getTarget() != null) {
resp.put(OAuth2Helper.Key.TARGET, accessToken.getTarget());
- rb.header(HttpHeaders.LOCATION, accessToken.getTarget() + "__auth");
+ rb.header(HttpHeaders.LOCATION, accessToken.getTarget() + "__token");
}
if (issueCookie) {
diff --git a/src/main/java/io/personium/core/rs/odata/AbstractODataResource.java b/src/main/java/io/personium/core/rs/odata/AbstractODataResource.java
index 8e9969457..f41de84cf 100644
--- a/src/main/java/io/personium/core/rs/odata/AbstractODataResource.java
+++ b/src/main/java/io/personium/core/rs/odata/AbstractODataResource.java
@@ -689,6 +689,8 @@ protected void validateProperty(EdmProperty ep, String propName, OProperty> op
validatePropertyCellUrl(propName, op);
} else if (pFormat.startsWith(Common.P_FORMAT_PATTERN_USUSST)) {
validatePropertyUsusst(propName, op, pFormat);
+ } else if (pFormat.startsWith(Common.P_FORMAT_PATTERN_MESSAGE_REQUEST_RELATION)) {
+ validatePropertyMessageRequestRelation(propName, op);
}
}
}
@@ -753,16 +755,13 @@ private void validateDynamicProperty(OProperty> property) {
* @param pFormat pFormatの値
*/
protected void validatePropertyRegEx(String propName, OProperty> op, String pFormat) {
- // regEx('正規表現')から正規表現を抜き出す
+ // Extract regular expressions from('regular expression')
Pattern formatPattern = Pattern.compile(Common.P_FORMAT_PATTERN_REGEX + "\\('(.+)'\\)");
Matcher formatMatcher = formatPattern.matcher(pFormat);
formatMatcher.matches();
pFormat = formatMatcher.group(1);
- // フォーマットのチェックを行う
- Pattern pattern = Pattern.compile(pFormat);
- Matcher matcher = pattern.matcher(op.getValue().toString());
- if (!matcher.matches()) {
+ if (!ODataUtils.validateRegEx(op.getValue().toString(), pFormat)) {
throw PersoniumCoreException.OData.REQUEST_FIELD_FORMAT_ERROR.params(propName);
}
}
@@ -843,6 +842,18 @@ protected void validatePropertyUsusst(String propName, OProperty> op, String p
}
}
+ /**
+ * Message RequestRelation Format Check.
+ * @param propName Property name
+ * @param op OProperty
+ */
+ protected void validatePropertyMessageRequestRelation(String propName, OProperty> op) {
+ if (!ODataUtils.validateClassUrl(op.getValue().toString(), Common.PATTERN_RELATION_CLASS_URL)
+ && !ODataUtils.validateRegEx(op.getValue().toString(), Common.PATTERN_RELATION_NAME)) {
+ throw PersoniumCoreException.OData.REQUEST_FIELD_FORMAT_ERROR.params(propName);
+ }
+ }
+
/**
* OEntityKeyの正規化を行う.
* 正規化後のOEntityKeyをtoKeyStringすると、同一キーであれば同一文字列になる。
diff --git a/src/main/java/io/personium/core/utils/ODataUtils.java b/src/main/java/io/personium/core/utils/ODataUtils.java
index e2873c6b1..926ca3838 100644
--- a/src/main/java/io/personium/core/utils/ODataUtils.java
+++ b/src/main/java/io/personium/core/utils/ODataUtils.java
@@ -299,6 +299,22 @@ public static boolean validateDouble(Double value) {
return false;
}
+ /**
+ * Check the value of property item with regular expression.
+ * @param str Input string
+ * @param pFormat regular expression format
+ * @return true:OK false:NG
+ */
+ public static boolean validateRegEx(String str, String pFormat) {
+ // Check
+ Pattern pattern = Pattern.compile(pFormat);
+ Matcher matcher = pattern.matcher(str);
+ if (!matcher.matches()) {
+ return false;
+ }
+ return true;
+ }
+
/**
* プロパティ項目の値をURIかチェックする.
* @param propValue チェック値
@@ -378,6 +394,35 @@ public static boolean isValidCellUrl(String str) {
return isValidLength && isValidScheme && isNormalized && hasTrailingSlash;
}
+ /**
+ * Check the value of property item with Class URL.
+ * @param str Input string
+ * @param pFormat regular expression format
+ * @return true:OK false:NG
+ */
+ public static boolean validateClassUrl(String str, String pFormat) {
+ URI uri;
+ try {
+ uri = new URI(str);
+ String scheme = uri.getScheme();
+ // Scheme check
+ if (uri.getScheme() == null
+ || (!scheme.equals(UriUtils.SCHEME_HTTP) //NOPMD -To maintain readability
+ && !scheme.equals(UriUtils.SCHEME_HTTPS)
+ && !scheme.equals(UriUtils.SCHEME_LOCALUNIT))) {
+ return false;
+ }
+ // String length check
+ if (uri.toString().length() > URI_MAX_LENGTH) {
+ return false;
+ }
+ } catch (URISyntaxException e) {
+ return false;
+ }
+ // Regular expression check
+ return ODataUtils.validateRegEx(str, pFormat);
+ }
+
/**
* スキーマ定義されたプロパティ数を取得する.
* @param metadata スキーマ情報
diff --git a/src/main/resources/personium-messages.properties b/src/main/resources/personium-messages.properties
index 5a8cb1411..1e1672dd7 100644
--- a/src/main/resources/personium-messages.properties
+++ b/src/main/resources/personium-messages.properties
@@ -155,12 +155,15 @@ io.personium.core.msg.PR500-SC-0006=Invalid HTTP response was returned from a se
io.personium.core.msg.PR400-SM-0001=ToRelation [{0}] does not exist.
io.personium.core.msg.PR400-SM-0002=ToRelation [{0}] does not have related ExtCell.
io.personium.core.msg.PR400-SM-0003=The maximum number of destinations was exceeded.
+io.personium.core.msg.PR400-SM-0004=Box corresponding to the schema can not be found from the schema-authenticated token. Schema[{0}].
# PR500-RS
io.personium.core.msg.PR500-SM-0001=Sent Message connection error.
io.personium.core.msg.PR500-SM-0002=Sent Message body parse error.
## ReceivedMessage
io.personium.core.msg.PR400-RM-0001=Requested relation already exists.
+io.personium.core.msg.PR400-RM-0002=Box corresponding to the schema can not be found. Schema [{0}].
+io.personium.core.msg.PR400-RM-0003=Box corresponding to the RelationClassURL can not be found. RelationClassURL [{0}].
io.personium.core.msg.PR409-RM-0001=Requested relation URL parse error.
io.personium.core.msg.PR409-RM-0002=Requested relation [{0}] does not exists.
io.personium.core.msg.PR409-RM-0003=Requested relation target URL parse error.
diff --git a/src/main/resources/personium-unit-config-default.properties b/src/main/resources/personium-unit-config-default.properties
index e99213232..5811e60bd 100644
--- a/src/main/resources/personium-unit-config-default.properties
+++ b/src/main/resources/personium-unit-config-default.properties
@@ -23,7 +23,7 @@
#################################################
# core version
-io.personium.core.version=1.4.6
+io.personium.core.version=1.5.0
# general configurations
io.personium.core.unitUser.issuers=
@@ -114,7 +114,7 @@ io.personium.core.es.ads.log.count.iteration=100
# security configurations
# You must set these properties to personium-unit-config.properties file.
-io.personium.core.masterToken=personium.io
+io.personium.core.masterToken=
#io.personium.core.security.secret16=changeme
#io.personium.core.security.auth.password.salt=changeme
diff --git a/src/test/java/io/personium/core/PersoniumReadDeleteModeManagerTest.java b/src/test/java/io/personium/core/PersoniumReadDeleteModeManagerTest.java
index 935e9f4f4..fa31e6f92 100644
--- a/src/test/java/io/personium/core/PersoniumReadDeleteModeManagerTest.java
+++ b/src/test/java/io/personium/core/PersoniumReadDeleteModeManagerTest.java
@@ -315,14 +315,14 @@ public class PersoniumReadDeleteModeManagerTest {
}
/**
- * ReadDeleteOnlyモード時に__authに対するPOSTメソッドが実行された場合はPersoniumCoreExceptionが発生しないこと.
+ * ReadDeleteOnlyモード時に__tokenに対するPOSTメソッドが実行された場合はPersoniumCoreExceptionが発生しないこと.
* @throws Exception .
*/
@Test
- public void ReadDeleteOnlyモード時に__authに対するPOSTメソッドが実行された場合はPersoniumCoreExceptionが発生しないこと() throws Exception {
+ public void ReadDeleteOnlyモード時に__tokenに対するPOSTメソッドが実行された場合はPersoniumCoreExceptionが発生しないこと() throws Exception {
PowerMockito.spy(ReadDeleteModeLockManager.class);
PowerMockito.when(ReadDeleteModeLockManager.class, "isReadDeleteOnlyMode").thenReturn(true);
- List pathSegment = getPathSegmentList(new String[] {"cell", "__auth" });
+ List pathSegment = getPathSegmentList(new String[] {"cell", "__token" });
try {
PersoniumReadDeleteModeManager.checkReadDeleteOnlyMode(HttpMethod.POST, pathSegment);
} catch (PersoniumCoreException e) {
diff --git a/src/test/java/io/personium/core/model/impl/es/odata/AllTests.java b/src/test/java/io/personium/core/model/impl/es/odata/AllTests.java
new file mode 100644
index 000000000..244e9614c
--- /dev/null
+++ b/src/test/java/io/personium/core/model/impl/es/odata/AllTests.java
@@ -0,0 +1,31 @@
+/**
+ * personium.io
+ * Copyright 2014 FUJITSU LIMITED
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package io.personium.core.model.impl.es.odata;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
+
+/**
+ * Test suite for executing all the test cases under package.
+ */
+@RunWith(Suite.class)
+@SuiteClasses({
+ CellCtlODataProducerTest.class
+ })
+public class AllTests {
+}
diff --git a/src/test/java/io/personium/core/model/impl/es/odata/CellCtlODataProducerTest.java b/src/test/java/io/personium/core/model/impl/es/odata/CellCtlODataProducerTest.java
index b03cd87bc..d7bea5033 100644
--- a/src/test/java/io/personium/core/model/impl/es/odata/CellCtlODataProducerTest.java
+++ b/src/test/java/io/personium/core/model/impl/es/odata/CellCtlODataProducerTest.java
@@ -20,14 +20,24 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import static org.mockito.Matchers.anyMap;
import static org.mockito.Matchers.anyObject;
import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
@@ -35,31 +45,41 @@
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
import org.odata4j.core.OEntity;
+import org.odata4j.core.OEntityKey;
import org.odata4j.edm.EdmEntitySet;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
+import io.personium.common.es.response.PersoniumIndexResponse;
import io.personium.core.PersoniumCoreException;
import io.personium.core.model.Box;
import io.personium.core.model.Cell;
+import io.personium.core.model.ctl.Common;
import io.personium.core.model.ctl.ReceivedMessage;
import io.personium.core.model.ctl.ReceivedMessagePort;
import io.personium.core.model.ctl.Relation;
import io.personium.core.model.ctl.SentMessage;
import io.personium.core.model.impl.es.CellEsImpl;
+import io.personium.core.model.impl.es.accessor.EntitySetAccessor;
+import io.personium.core.model.impl.es.doc.EntitySetDocHandler;
import io.personium.core.model.impl.es.doc.OEntityDocHandler;
+import io.personium.core.model.impl.es.odata.EsNavigationTargetKeyProperty.NTKPNotFoundException;
+import io.personium.core.model.lock.Lock;
+import io.personium.core.utils.UriUtils;
import io.personium.test.categories.Unit;
/**
* UnitCtlODataProducerユニットテストクラス.
*/
@RunWith(PowerMockRunner.class)
-@PrepareForTest({CellCtlODataProducer.class, Box.class})
+@PrepareForTest({CellCtlODataProducer.class, Box.class, UriUtils.class})
@Category({ Unit.class })
public class CellCtlODataProducerTest {
+ /** Target class of unit test. */
private CellCtlODataProducer cellCtlODataProducer;
/**
@@ -290,26 +310,6 @@ public void befor() {
ReceivedMessagePort.STATUS_REJECTED));
}
- /**
- * リレーションクラスURLからリレーション名を取得できること.
- */
- @Test
- public void リレーションクラスURLからリレーション名を取得できること() {
- String relationName = cellCtlODataProducer.getRelationFromRelationClassUrl(
- "https://example.com/test0110/__relation/box/+:me");
- assertEquals("+:me", relationName);
- }
-
- /**
- * リレーションクラスURLのフォーマットが不正な場合はnullが取得できること.
- */
- @Test
- public void リレーションクラスURLのフォーマットが不正な場合はnullが取得できること() {
- String relationName = cellCtlODataProducer.getRelationFromRelationClassUrl(
- "https://example.com/test0110/__relation/box/");
- assertEquals(null, relationName);
- }
-
/**
* extCellの取得で存在する場合にEntitySetDocHandlerが返却されること.
*/
@@ -327,103 +327,10 @@ public void befor() {
try {
doReturn(new OEntityDocHandler()).when(cellCtlODataProducer).retrieveWithKey(anyObject(), anyObject());
cellCtlODataProducer.getExtCell("https://example.com/'/");
- fail("PersoniumCoreException.ReceiveMessage.REQUEST_RELATION_TARGET_PARSE_ERROR does not occurred.");
- } catch (PersoniumCoreException e) {
- PersoniumCoreException expected = PersoniumCoreException.ReceiveMessage.REQUEST_RELATION_TARGET_PARSE_ERROR;
- assertEquals(expected.getCode(), e.getCode());
- assertEquals(expected.getMessage(), e.getMessage());
- }
- }
-
- /**
- * RequestRelationが不正な場合はREQUEST_RELATION_PARSE_ERRORが発生すること.
- */
- @Test
- public void RequestRelationが不正な場合はREQUEST_RELATION_PARSE_ERRORが発生すること() {
- OEntityDocHandler docHandler = new OEntityDocHandler();
- Map staticFields = new HashMap();
- staticFields.put(ReceivedMessagePort.P_REQUEST_RELATION.getName(),
- "https://example.com/test0110/__relation/box/");
- docHandler.setStaticFields(staticFields);
- try {
- cellCtlODataProducer.breakRelation(docHandler);
- fail("PersoniumCoreException.ReceiveMessage.REQUEST_RELATION_PARSE_ERROR does not occurred.");
- } catch (PersoniumCoreException e) {
- PersoniumCoreException expected = PersoniumCoreException.ReceiveMessage.REQUEST_RELATION_PARSE_ERROR;
- assertEquals(expected.getCode(), e.getCode());
- assertEquals(expected.getMessage(), e.getMessage());
- }
- }
-
- /**
- * RequestRelationが不正な場合はREQUEST_RELATION_DOES_NOT_EXISTSが発生すること.
- */
- @Test
- public void RequestRelationが存在しない場合はREQUEST_RELATION_DOES_NOT_EXISTSが発生すること() {
- OEntityDocHandler docHandler = new OEntityDocHandler();
- Map staticFields = new HashMap();
- staticFields.put(ReceivedMessagePort.P_REQUEST_RELATION.getName(),
- "https://example.com/test0110/__relation/box/+:me");
- docHandler.setStaticFields(staticFields);
- doReturn(null).when(cellCtlODataProducer).getRelation(anyString(), anyString());
- try {
- cellCtlODataProducer.breakRelation(docHandler);
- fail("PersoniumCoreException.ReceiveMessage.REQUEST_RELATION_DOES_NOT_EXISTS does not occurred.");
- } catch (PersoniumCoreException e) {
- PersoniumCoreException expected = PersoniumCoreException.ReceiveMessage.REQUEST_RELATION_DOES_NOT_EXISTS
- .params("+:me");
- assertEquals(expected.getCode(), e.getCode());
- assertEquals(expected.getMessage(), e.getMessage());
- }
- }
-
- /**
- * RequestRelationTargetが存在しない場合はREQUEST_RELATION_TARGET_DOES_NOT_EXISTSが発生すること.
- */
- @Test
- public void RequestRelationTargetが存在しない場合はREQUEST_RELATION_TARGET_DOES_NOT_EXISTSが発生すること() {
- OEntityDocHandler docHandler = new OEntityDocHandler();
- Map staticFields = new HashMap();
- staticFields.put(ReceivedMessagePort.P_REQUEST_RELATION.getName(),
- "https://example.com/test0110/__relation/box/+:me");
- staticFields.put(ReceivedMessagePort.P_REQUEST_RELATION_TARGET.getName(),
- "https://example.com/test0110/");
- docHandler.setStaticFields(staticFields);
- doReturn(new OEntityDocHandler()).when(cellCtlODataProducer).getRelation(anyString(), anyString());
- doReturn(null).when(cellCtlODataProducer).getExtCell(anyString());
- try {
- cellCtlODataProducer.breakRelation(docHandler);
- fail("PersoniumCoreException.ReceiveMessage.REQUEST_RELATION_TARGET_DOES_NOT_EXISTS does not occurred.");
+ fail("PersoniumCoreException.ReceivedMessage.REQUEST_RELATION_TARGET_PARSE_ERROR does not occurred.");
} catch (PersoniumCoreException e) {
PersoniumCoreException expected =
- PersoniumCoreException.ReceiveMessage.REQUEST_RELATION_TARGET_DOES_NOT_EXISTS
- .params("https://example.com/test0110/");
- assertEquals(expected.getCode(), e.getCode());
- assertEquals(expected.getMessage(), e.getMessage());
- }
- }
-
- /**
- * Link情報が存在しない場合はLINK_DOES_NOT_EXISTSが発生すること.
- */
- @Test
- public void Link情報が存在しない場合はLINK_DOES_NOT_EXISTSが発生すること() {
- OEntityDocHandler docHandler = new OEntityDocHandler();
- Map staticFields = new HashMap();
- staticFields.put(ReceivedMessagePort.P_REQUEST_RELATION.getName(),
- "https://example.com/test0110/__relation/box/+:me");
- staticFields.put(ReceivedMessagePort.P_REQUEST_RELATION_TARGET.getName(),
- "https://example.com/test0110/");
- docHandler.setStaticFields(staticFields);
- doReturn(new OEntityDocHandler()).when(cellCtlODataProducer).getRelation(anyString(), anyString());
- doReturn(new OEntityDocHandler()).when(cellCtlODataProducer).getExtCell(anyString());
- doReturn(false).when(cellCtlODataProducer).deleteLinkEntity(anyObject(), anyObject());
- try {
- cellCtlODataProducer.breakRelation(docHandler);
- fail("PersoniumCoreException.ReceiveMessage.LINK_DOES_NOT_EXISTS does not occurred.");
- } catch (PersoniumCoreException e) {
- PersoniumCoreException expected = PersoniumCoreException.ReceiveMessage.LINK_DOES_NOT_EXISTS
- .params("+:me", "https://example.com/test0110/");
+ PersoniumCoreException.ReceivedMessage.REQUEST_RELATION_TARGET_PARSE_ERROR;
assertEquals(expected.getCode(), e.getCode());
assertEquals(expected.getMessage(), e.getMessage());
}
@@ -443,15 +350,11 @@ public void beforeCreate_Normal_receivedmessage_boxname_not_null() {
String entitySetName = ReceivedMessage.EDM_TYPE_NAME;
OEntity oEntity = null;
OEntityDocHandler docHandler = new OEntityDocHandler();
- Map dynamicFields = new HashMap();
- dynamicFields.put(pBoxName, "box1");
- dynamicFields.put("dummy", "dummy1");
Map staticFields = new HashMap();
staticFields.put(pBoxName, "box2");
staticFields.put("dummy", "dummy2");
Map link = new HashMap();
link.put("dummy", "dummy3");
- docHandler.setDynamicFields(dynamicFields);
docHandler.setStaticFields(staticFields);
docHandler.setManyToOnelinkId(link);
@@ -467,8 +370,6 @@ public void beforeCreate_Normal_receivedmessage_boxname_not_null() {
// --------------------
// Expected result
// --------------------
- Map expectedDynamic = new HashMap();
- expectedDynamic.put("dummy", "dummy1");
Map expectedStatic = new HashMap();
expectedStatic.put("dummy", "dummy2");
Map expectedLink = new HashMap();
@@ -483,15 +384,15 @@ public void beforeCreate_Normal_receivedmessage_boxname_not_null() {
// --------------------
// Confirm result
// --------------------
- dynamicFields = docHandler.getDynamicFields();
staticFields = docHandler.getStaticFields();
link = docHandler.getManyToOnelinkId();
- assertThat(dynamicFields.get(pBoxName), is(expectedDynamic.get(pBoxName)));
- assertThat(dynamicFields.get("dummy"), is(expectedDynamic.get("dummy")));
assertThat(staticFields.get(pBoxName), is(expectedStatic.get(pBoxName)));
assertThat(staticFields.get("dummy"), is(expectedStatic.get("dummy")));
assertThat(link.get("Box"), is(expectedLink.get("Box")));
assertThat(link.get("dummy"), is(expectedLink.get("dummy")));
+ // Confirm function call
+ verify(mockCell, times(1)).getBoxForName("box2");
+ verify(mockBox, times(1)).getId();
}
/**
@@ -508,14 +409,10 @@ public void beforeCreate_Normal_receivedmessage_boxname_is_null() {
String entitySetName = ReceivedMessage.EDM_TYPE_NAME;
OEntity oEntity = null;
OEntityDocHandler docHandler = new OEntityDocHandler();
- Map dynamicFields = new HashMap();
- dynamicFields.put(pBoxName, "box1");
- dynamicFields.put("dummy", "dummy1");
Map staticFields = new HashMap();
staticFields.put("dummy", "dummy2");
Map link = new HashMap();
link.put("dummy", "dummy3");
- docHandler.setDynamicFields(dynamicFields);
docHandler.setStaticFields(staticFields);
docHandler.setManyToOnelinkId(link);
@@ -531,8 +428,6 @@ public void beforeCreate_Normal_receivedmessage_boxname_is_null() {
// --------------------
// Expected result
// --------------------
- Map expectedDynamic = new HashMap();
- expectedDynamic.put("dummy", "dummy1");
Map expectedStatic = new HashMap();
expectedStatic.put("dummy", "dummy2");
Map expectedLink = new HashMap();
@@ -546,15 +441,15 @@ public void beforeCreate_Normal_receivedmessage_boxname_is_null() {
// --------------------
// Confirm result
// --------------------
- dynamicFields = docHandler.getDynamicFields();
staticFields = docHandler.getStaticFields();
link = docHandler.getManyToOnelinkId();
- assertThat(dynamicFields.get(pBoxName), is(expectedDynamic.get(pBoxName)));
- assertThat(dynamicFields.get("dummy"), is(expectedDynamic.get("dummy")));
assertThat(staticFields.get(pBoxName), is(expectedStatic.get(pBoxName)));
assertThat(staticFields.get("dummy"), is(expectedStatic.get("dummy")));
assertThat(link.get("Box"), is(expectedLink.get("Box")));
assertThat(link.get("dummy"), is(expectedLink.get("dummy")));
+ // Confirm function call
+ verify(mockCell, never()).getBoxForName(anyString());
+ verify(mockBox, never()).getId();
}
/**
@@ -571,15 +466,11 @@ public void beforeCreate_Normal_sentmessage_boxname_not_null() {
String entitySetName = SentMessage.EDM_TYPE_NAME;
OEntity oEntity = null;
OEntityDocHandler docHandler = new OEntityDocHandler();
- Map dynamicFields = new HashMap();
- dynamicFields.put(pBoxName, "box1");
- dynamicFields.put("dummy", "dummy1");
Map staticFields = new HashMap();
staticFields.put(pBoxName, "box2");
staticFields.put("dummy", "dummy2");
Map link = new HashMap();
link.put("dummy", "dummy3");
- docHandler.setDynamicFields(dynamicFields);
docHandler.setStaticFields(staticFields);
docHandler.setManyToOnelinkId(link);
@@ -595,9 +486,6 @@ public void beforeCreate_Normal_sentmessage_boxname_not_null() {
// --------------------
// Expected result
// --------------------
- Map expectedDynamic = new HashMap();
- expectedDynamic.put(pBoxName, "box1");
- expectedDynamic.put("dummy", "dummy1");
Map expectedStatic = new HashMap();
expectedStatic.put("dummy", "dummy2");
Map expectedLink = new HashMap();
@@ -612,15 +500,15 @@ public void beforeCreate_Normal_sentmessage_boxname_not_null() {
// --------------------
// Confirm result
// --------------------
- dynamicFields = docHandler.getDynamicFields();
staticFields = docHandler.getStaticFields();
link = docHandler.getManyToOnelinkId();
- assertThat(dynamicFields.get(pBoxName), is(expectedDynamic.get(pBoxName)));
- assertThat(dynamicFields.get("dummy"), is(expectedDynamic.get("dummy")));
assertThat(staticFields.get(pBoxName), is(expectedStatic.get(pBoxName)));
assertThat(staticFields.get("dummy"), is(expectedStatic.get("dummy")));
assertThat(link.get("Box"), is(expectedLink.get("Box")));
assertThat(link.get("dummy"), is(expectedLink.get("dummy")));
+ // Confirm function call
+ verify(mockCell, times(1)).getBoxForName("box2");
+ verify(mockBox, times(1)).getId();
}
/**
@@ -637,14 +525,10 @@ public void beforeCreate_Normal_sentmessage_boxname_is_null() {
String entitySetName = SentMessage.EDM_TYPE_NAME;
OEntity oEntity = null;
OEntityDocHandler docHandler = new OEntityDocHandler();
- Map dynamicFields = new HashMap();
- dynamicFields.put(pBoxName, "box1");
- dynamicFields.put("dummy", "dummy1");
Map staticFields = new HashMap();
staticFields.put("dummy", "dummy2");
Map link = new HashMap();
link.put("dummy", "dummy3");
- docHandler.setDynamicFields(dynamicFields);
docHandler.setStaticFields(staticFields);
docHandler.setManyToOnelinkId(link);
@@ -660,9 +544,6 @@ public void beforeCreate_Normal_sentmessage_boxname_is_null() {
// --------------------
// Expected result
// --------------------
- Map expectedDynamic = new HashMap();
- expectedDynamic.put(pBoxName, "box1");
- expectedDynamic.put("dummy", "dummy1");
Map expectedStatic = new HashMap();
expectedStatic.put("dummy", "dummy2");
Map expectedLink = new HashMap();
@@ -676,15 +557,15 @@ public void beforeCreate_Normal_sentmessage_boxname_is_null() {
// --------------------
// Confirm result
// --------------------
- dynamicFields = docHandler.getDynamicFields();
staticFields = docHandler.getStaticFields();
link = docHandler.getManyToOnelinkId();
- assertThat(dynamicFields.get(pBoxName), is(expectedDynamic.get(pBoxName)));
- assertThat(dynamicFields.get("dummy"), is(expectedDynamic.get("dummy")));
assertThat(staticFields.get(pBoxName), is(expectedStatic.get(pBoxName)));
assertThat(staticFields.get("dummy"), is(expectedStatic.get("dummy")));
assertThat(link.get("Box"), is(expectedLink.get("Box")));
assertThat(link.get("dummy"), is(expectedLink.get("dummy")));
+ // Confirm function call
+ verify(mockCell, never()).getBoxForName(anyString());
+ verify(mockBox, never()).getId();
}
/**
@@ -700,15 +581,11 @@ public void beforeCreate_Normal_message_is_not_receive_and_sent() {
String entitySetName = Relation.EDM_TYPE_NAME;
OEntity oEntity = null;
OEntityDocHandler docHandler = new OEntityDocHandler();
- Map dynamicFields = new HashMap();
- dynamicFields.put(pBoxName, "box1");
- dynamicFields.put("dummy", "dummy1");
Map staticFields = new HashMap();
staticFields.put(pBoxName, "box2");
staticFields.put("dummy", "dummy2");
Map link = new HashMap();
link.put("dummy", "dummy3");
- docHandler.setDynamicFields(dynamicFields);
docHandler.setStaticFields(staticFields);
docHandler.setManyToOnelinkId(link);
@@ -720,9 +597,6 @@ public void beforeCreate_Normal_message_is_not_receive_and_sent() {
// --------------------
// Expected result
// --------------------
- Map expectedDynamic = new HashMap();
- expectedDynamic.put(pBoxName, "box1");
- expectedDynamic.put("dummy", "dummy1");
Map expectedStatic = new HashMap();
expectedStatic.put(pBoxName, "box2");
expectedStatic.put("dummy", "dummy2");
@@ -737,17 +611,347 @@ public void beforeCreate_Normal_message_is_not_receive_and_sent() {
// --------------------
// Confirm result
// --------------------
- dynamicFields = docHandler.getDynamicFields();
staticFields = docHandler.getStaticFields();
link = docHandler.getManyToOnelinkId();
- assertThat(dynamicFields.get(pBoxName), is(expectedDynamic.get(pBoxName)));
- assertThat(dynamicFields.get("dummy"), is(expectedDynamic.get("dummy")));
assertThat(staticFields.get(pBoxName), is(expectedStatic.get(pBoxName)));
assertThat(staticFields.get("dummy"), is(expectedStatic.get("dummy")));
assertThat(link.get("Box"), is(expectedLink.get("Box")));
assertThat(link.get("dummy"), is(expectedLink.get("dummy")));
}
+ /**
+ * Test changeStatusAndUpdateRelation().
+ * Normal test.
+ * @throws Exception Unexpected error
+ */
+ @SuppressWarnings("unchecked")
+ @Test
+ public void changeStatusAndUpdateRelation_Normal() throws Exception {
+ cellCtlODataProducer = PowerMockito.spy(new CellCtlODataProducer(new CellEsImpl()));
+ // --------------------
+ // Test method args
+ // --------------------
+ EdmEntitySet entitySet = EdmEntitySet.newBuilder().setName("dummyName").build();
+ Map values = new HashMap();
+ values.put("dummy", "dummy");
+ OEntityKey originalKey = OEntityKey.create(values);
+ String status = "status";
+
+ // --------------------
+ // Mock settings
+ // --------------------
+ Lock mockLock = mock(Lock.class);
+ doNothing().when(mockLock).release();
+ doReturn(mockLock).when(cellCtlODataProducer).lock();
+
+ EntitySetDocHandler mockDocHandler = mock(EntitySetDocHandler.class);
+ Map mockStaticFields = new HashMap();
+ Map mockManyToOnelinkId = new HashMap();
+ doReturn(mockStaticFields).when(mockDocHandler).getStaticFields();
+ doReturn(mockManyToOnelinkId).when(mockDocHandler).getManyToOnelinkId();
+ doReturn(mockDocHandler).when(cellCtlODataProducer).retrieveWithKey(entitySet, originalKey);
+
+ Map mockConvertedStaticFields = new HashMap();
+ mockConvertedStaticFields.put(ReceivedMessage.P_TYPE.getName(), "dummyType");
+ mockConvertedStaticFields.put(ReceivedMessage.P_STATUS.getName(), "dummyStatus");
+ mockConvertedStaticFields.put(ReceivedMessage.P_BOX_NAME.getName(), "dummyBoxName");
+ // Change the return value according to the number of calls to getStaticFields
+ when(mockDocHandler.getStaticFields()).thenReturn(
+ mockStaticFields, mockConvertedStaticFields, mockConvertedStaticFields);
+ doReturn(mockConvertedStaticFields).when(cellCtlODataProducer).convertNtkpValueToFields(entitySet,
+ mockStaticFields, mockManyToOnelinkId);
+ doNothing().when(mockDocHandler).setStaticFields(mockConvertedStaticFields);
+
+ doReturn(true).when(cellCtlODataProducer).isValidMessageStatus("dummyType", status);
+ doReturn(true).when(cellCtlODataProducer).isValidRelationStatus("dummyType", status);
+ doReturn(true).when(cellCtlODataProducer).isValidCurrentStatus("dummyType", "dummyStatus");
+
+ PowerMockito.doNothing().when(cellCtlODataProducer, "updateRelation", mockDocHandler, status);
+ PowerMockito.doNothing().when(cellCtlODataProducer, "updateStatusOfEntitySetDocHandler",
+ mockDocHandler, status);
+
+ EntitySetAccessor mockAccessor = mock(EntitySetAccessor.class);
+ doReturn(mockAccessor).when(cellCtlODataProducer).getAccessorForEntitySet("dummyName");
+ doReturn(1L).when(mockDocHandler).getVersion();
+ doReturn("dummyId").when(mockDocHandler).getId();
+ PersoniumIndexResponse mockIndexResponse = mock(PersoniumIndexResponse.class);
+ doReturn(2L).when(mockIndexResponse).version();
+ doReturn(mockIndexResponse).when(mockAccessor).update("dummyId", mockDocHandler, 1L);
+ doNothing().when(mockDocHandler).setVersion(2L);
+ doReturn("returnEtag").when(mockDocHandler).createEtag();
+
+ // --------------------
+ // Expected result
+ // --------------------
+ String expectedEtag = "returnEtag";
+
+ // --------------------
+ // Run method
+ // --------------------
+ String actualEtag = cellCtlODataProducer.changeStatusAndUpdateRelation(entitySet, originalKey, status);
+
+ // --------------------
+ // Confirm result
+ // --------------------
+ assertThat(actualEtag, is(expectedEtag));
+ assertNull(mockConvertedStaticFields.get(ReceivedMessage.P_BOX_NAME.getName()));
+ }
+
+ /**
+ * Test changeStatusAndUpdateRelation().
+ * Error test.
+ * EntitySetDocHandler is null.
+ */
+ @Test
+ public void changeStatusAndUpdateRelation_Error_EntitySetDocHandler_is_null() {
+ cellCtlODataProducer = PowerMockito.spy(new CellCtlODataProducer(new CellEsImpl()));
+ // --------------------
+ // Test method args
+ // --------------------
+ EdmEntitySet entitySet = EdmEntitySet.newBuilder().setName("dummyName").build();
+ Map values = new HashMap();
+ values.put("dummy", "dummy");
+ OEntityKey originalKey = OEntityKey.create(values);
+ String status = "status";
+
+ // --------------------
+ // Mock settings
+ // --------------------
+ Lock mockLock = mock(Lock.class);
+ doNothing().when(mockLock).release();
+ doReturn(mockLock).when(cellCtlODataProducer).lock();
+
+ doReturn(null).when(cellCtlODataProducer).retrieveWithKey(entitySet, originalKey);
+
+ // --------------------
+ // Expected result
+ // --------------------
+ // Nothing.
+
+ // --------------------
+ // Run method
+ // --------------------
+ try {
+ cellCtlODataProducer.changeStatusAndUpdateRelation(entitySet, originalKey, status);
+ fail("Not exception.");
+ } catch (PersoniumCoreException e) {
+ // --------------------
+ // Confirm result
+ // --------------------
+ assertThat(e, is(PersoniumCoreException.OData.NO_SUCH_ENTITY));
+ }
+ }
+
+ /**
+ * Test changeStatusAndUpdateRelation().
+ * Error test.
+ * ValidMessageStatus is false.
+ */
+ @SuppressWarnings("unchecked")
+ @Test
+ public void changeStatusAndUpdateRelation_Error_ValidMessageStatus_is_false() {
+ cellCtlODataProducer = PowerMockito.spy(new CellCtlODataProducer(new CellEsImpl()));
+ // --------------------
+ // Test method args
+ // --------------------
+ EdmEntitySet entitySet = EdmEntitySet.newBuilder().setName("dummyName").build();
+ Map values = new HashMap();
+ values.put("dummy", "dummy");
+ OEntityKey originalKey = OEntityKey.create(values);
+ String status = "status";
+
+ // --------------------
+ // Mock settings
+ // --------------------
+ Lock mockLock = mock(Lock.class);
+ doNothing().when(mockLock).release();
+ doReturn(mockLock).when(cellCtlODataProducer).lock();
+
+ EntitySetDocHandler mockDocHandler = mock(EntitySetDocHandler.class);
+ Map mockStaticFields = new HashMap();
+ Map mockManyToOnelinkId = new HashMap();
+ doReturn(mockStaticFields).when(mockDocHandler).getStaticFields();
+ doReturn(mockManyToOnelinkId).when(mockDocHandler).getManyToOnelinkId();
+ doReturn(mockDocHandler).when(cellCtlODataProducer).retrieveWithKey(entitySet, originalKey);
+
+ Map mockConvertedStaticFields = new HashMap();
+ mockConvertedStaticFields.put(ReceivedMessage.P_TYPE.getName(), "dummyType");
+ mockConvertedStaticFields.put(ReceivedMessage.P_STATUS.getName(), "dummyStatus");
+ mockConvertedStaticFields.put(ReceivedMessage.P_BOX_NAME.getName(), "dummyBoxName");
+ // Change the return value according to the number of calls to getStaticFields
+ when(mockDocHandler.getStaticFields()).thenReturn(
+ mockStaticFields, mockConvertedStaticFields, mockConvertedStaticFields);
+ doReturn(mockConvertedStaticFields).when(cellCtlODataProducer).convertNtkpValueToFields(entitySet,
+ mockStaticFields, mockManyToOnelinkId);
+ doNothing().when(mockDocHandler).setStaticFields(mockConvertedStaticFields);
+
+ doReturn(false).when(cellCtlODataProducer).isValidMessageStatus("dummyType", status);
+ doReturn(true).when(cellCtlODataProducer).isValidRelationStatus("dummyType", status);
+ doReturn(true).when(cellCtlODataProducer).isValidCurrentStatus("dummyType", "dummyStatus");
+
+ // --------------------
+ // Expected result
+ // --------------------
+ // Nothing.
+
+ // --------------------
+ // Run method
+ // --------------------
+ try {
+ cellCtlODataProducer.changeStatusAndUpdateRelation(entitySet, originalKey, status);
+ fail("Not exception.");
+ } catch (PersoniumCoreException e) {
+ // --------------------
+ // Confirm result
+ // --------------------
+ PersoniumCoreException expected = PersoniumCoreException.OData.REQUEST_FIELD_FORMAT_ERROR.params(
+ ReceivedMessage.MESSAGE_COMMAND);
+ assertThat(e.getStatus(), is(expected.getStatus()));
+ assertThat(e.getCode(), is(expected.getCode()));
+ assertThat(e.getMessage(), is(expected.getMessage()));
+ }
+ }
+
+ /**
+ * Test changeStatusAndUpdateRelation().
+ * Error test.
+ * ValidRelationStatus is false.
+ */
+ @SuppressWarnings("unchecked")
+ @Test
+ public void changeStatusAndUpdateRelation_Error_ValidRelationStatus_is_false() {
+ cellCtlODataProducer = PowerMockito.spy(new CellCtlODataProducer(new CellEsImpl()));
+ // --------------------
+ // Test method args
+ // --------------------
+ EdmEntitySet entitySet = EdmEntitySet.newBuilder().setName("dummyName").build();
+ Map values = new HashMap();
+ values.put("dummy", "dummy");
+ OEntityKey originalKey = OEntityKey.create(values);
+ String status = "status";
+
+ // --------------------
+ // Mock settings
+ // --------------------
+ Lock mockLock = mock(Lock.class);
+ doNothing().when(mockLock).release();
+ doReturn(mockLock).when(cellCtlODataProducer).lock();
+
+ EntitySetDocHandler mockDocHandler = mock(EntitySetDocHandler.class);
+ Map mockStaticFields = new HashMap();
+ Map mockManyToOnelinkId = new HashMap();
+ doReturn(mockStaticFields).when(mockDocHandler).getStaticFields();
+ doReturn(mockManyToOnelinkId).when(mockDocHandler).getManyToOnelinkId();
+ doReturn(mockDocHandler).when(cellCtlODataProducer).retrieveWithKey(entitySet, originalKey);
+
+ Map mockConvertedStaticFields = new HashMap();
+ mockConvertedStaticFields.put(ReceivedMessage.P_TYPE.getName(), "dummyType");
+ mockConvertedStaticFields.put(ReceivedMessage.P_STATUS.getName(), "dummyStatus");
+ mockConvertedStaticFields.put(ReceivedMessage.P_BOX_NAME.getName(), "dummyBoxName");
+ // Change the return value according to the number of calls to getStaticFields
+ when(mockDocHandler.getStaticFields()).thenReturn(
+ mockStaticFields, mockConvertedStaticFields, mockConvertedStaticFields);
+ doReturn(mockConvertedStaticFields).when(cellCtlODataProducer).convertNtkpValueToFields(entitySet,
+ mockStaticFields, mockManyToOnelinkId);
+ doNothing().when(mockDocHandler).setStaticFields(mockConvertedStaticFields);
+
+ doReturn(true).when(cellCtlODataProducer).isValidMessageStatus("dummyType", status);
+ doReturn(false).when(cellCtlODataProducer).isValidRelationStatus("dummyType", status);
+ doReturn(true).when(cellCtlODataProducer).isValidCurrentStatus("dummyType", "dummyStatus");
+
+ // --------------------
+ // Expected result
+ // --------------------
+ // Nothing.
+
+ // --------------------
+ // Run method
+ // --------------------
+ try {
+ cellCtlODataProducer.changeStatusAndUpdateRelation(entitySet, originalKey, status);
+ fail("Not exception.");
+ } catch (PersoniumCoreException e) {
+ // --------------------
+ // Confirm result
+ // --------------------
+ PersoniumCoreException expected = PersoniumCoreException.OData.REQUEST_FIELD_FORMAT_ERROR.params(
+ ReceivedMessage.MESSAGE_COMMAND);
+ assertThat(e.getStatus(), is(expected.getStatus()));
+ assertThat(e.getCode(), is(expected.getCode()));
+ assertThat(e.getMessage(), is(expected.getMessage()));
+ }
+ }
+
+ /**
+ * Test changeStatusAndUpdateRelation().
+ * Error test.
+ * ValidCurrentStatus is false.
+ */
+ @SuppressWarnings("unchecked")
+ @Test
+ public void changeStatusAndUpdateRelation_Error_ValidCurrentStatus_is_false() {
+ cellCtlODataProducer = PowerMockito.spy(new CellCtlODataProducer(new CellEsImpl()));
+ // --------------------
+ // Test method args
+ // --------------------
+ EdmEntitySet entitySet = EdmEntitySet.newBuilder().setName("dummyName").build();
+ Map values = new HashMap();
+ values.put("dummy", "dummy");
+ OEntityKey originalKey = OEntityKey.create(values);
+ String status = "status";
+
+ // --------------------
+ // Mock settings
+ // --------------------
+ Lock mockLock = mock(Lock.class);
+ doNothing().when(mockLock).release();
+ doReturn(mockLock).when(cellCtlODataProducer).lock();
+
+ EntitySetDocHandler mockDocHandler = mock(EntitySetDocHandler.class);
+ Map mockStaticFields = new HashMap();
+ Map mockManyToOnelinkId = new HashMap();
+ doReturn(mockStaticFields).when(mockDocHandler).getStaticFields();
+ doReturn(mockManyToOnelinkId).when(mockDocHandler).getManyToOnelinkId();
+ doReturn(mockDocHandler).when(cellCtlODataProducer).retrieveWithKey(entitySet, originalKey);
+
+ Map mockConvertedStaticFields = new HashMap();
+ mockConvertedStaticFields.put(ReceivedMessage.P_TYPE.getName(), "dummyType");
+ mockConvertedStaticFields.put(ReceivedMessage.P_STATUS.getName(), "dummyStatus");
+ mockConvertedStaticFields.put(ReceivedMessage.P_BOX_NAME.getName(), "dummyBoxName");
+ // Change the return value according to the number of calls to getStaticFields
+ when(mockDocHandler.getStaticFields()).thenReturn(
+ mockStaticFields, mockConvertedStaticFields, mockConvertedStaticFields);
+ doReturn(mockConvertedStaticFields).when(cellCtlODataProducer).convertNtkpValueToFields(entitySet,
+ mockStaticFields, mockManyToOnelinkId);
+ doNothing().when(mockDocHandler).setStaticFields(mockConvertedStaticFields);
+
+ doReturn(true).when(cellCtlODataProducer).isValidMessageStatus("dummyType", status);
+ doReturn(true).when(cellCtlODataProducer).isValidRelationStatus("dummyType", status);
+ doReturn(false).when(cellCtlODataProducer).isValidCurrentStatus("dummyType", "dummyStatus");
+
+ // --------------------
+ // Expected result
+ // --------------------
+ // Nothing.
+
+ // --------------------
+ // Run method
+ // --------------------
+ try {
+ cellCtlODataProducer.changeStatusAndUpdateRelation(entitySet, originalKey, status);
+ fail("Not exception.");
+ } catch (PersoniumCoreException e) {
+ // --------------------
+ // Confirm result
+ // --------------------
+ PersoniumCoreException expected = PersoniumCoreException.OData.REQUEST_FIELD_FORMAT_ERROR.params(
+ ReceivedMessage.MESSAGE_COMMAND);
+ assertThat(e.getStatus(), is(expected.getStatus()));
+ assertThat(e.getCode(), is(expected.getCode()));
+ assertThat(e.getMessage(), is(expected.getMessage()));
+ }
+ }
+
/**
* Test convertNtkpValueToFields().
* Normal test.
@@ -757,7 +961,7 @@ public void convertNtkpValueToFields_Normal() {
// --------------------
// Test method args
// --------------------
- EdmEntitySet entitySet = null;
+ EdmEntitySet entitySet = EdmEntitySet.newBuilder().build();
Map staticFields = new HashMap();
Map links = new HashMap();
links.put("Box", "nGtWo7dYSymzkTjWGMHm1g");
@@ -794,5 +998,1197 @@ protected void getNtkpValueMap(EdmEntitySet eSet,
assertThat(staticFields.get("_Box.Name"), is(expectedStaticFields.get("_Box.Name")));
assertThat(staticFields.get("_Relation.Name"), is(expectedStaticFields.get("_Relation.Name")));
assertThat(staticFields.containsKey("_Relation.Name"), is(true));
+ // Confirm function call
+ ArgumentCaptor captor = ArgumentCaptor.forClass(EdmEntitySet.class);
+ verify(cellCtlODataProducer, times(1)).getNtkpValueMap(captor.capture(), anyObject(), anyObject());
+ assertThat(captor.getValue(), is(entitySet));
+ }
+
+ /**
+ * Test buildRelation().
+ * Relation and extcell is not exists.
+ * @throws Exception Unexpected error
+ */
+ @Test
+ public void buildRelation_Normal_not_exists_relation_and_extcell() throws Exception {
+ cellCtlODataProducer = PowerMockito.spy(new CellCtlODataProducer(new CellEsImpl()));
+ // --------------------
+ // Test method args
+ // --------------------
+ EntitySetDocHandler entitySetDocHandler = mock(EntitySetDocHandler.class);
+
+ // --------------------
+ // Mock settings
+ // --------------------
+ Map mockStaticFields = new HashMap();
+ mockStaticFields.put(ReceivedMessage.P_REQUEST_RELATION.getName(), "dummyRelation");
+ mockStaticFields.put(ReceivedMessage.P_REQUEST_RELATION_TARGET.getName(), "http://personium/dummyExtCell/");
+ doReturn(mockStaticFields).when(entitySetDocHandler).getStaticFields();
+
+ doReturn("dummyRelation").when(cellCtlODataProducer).getRelationNameFromRequestRelation("dummyRelation");
+ doReturn("dummyBoxName").when(cellCtlODataProducer).getBoxNameFromRequestRelation("dummyRelation");
+
+ doReturn(null).when(cellCtlODataProducer).getRelation("dummyRelation", "dummyBoxName");
+ PowerMockito.doNothing().when(cellCtlODataProducer, "createRelationEntity", "dummyRelation", "dummyBoxName");
+
+ doReturn(null).when(cellCtlODataProducer).getExtCell("http://personium/dummyExtCell/");
+ PowerMockito.doNothing().when(cellCtlODataProducer, "createExtCellEntity", "http://personium/dummyExtCell/");
+
+ PowerMockito.doNothing().when(cellCtlODataProducer, "createRelationExtCellLinks", "dummyRelation",
+ "dummyBoxName", "http://personium/dummyExtCell/");
+
+ // --------------------
+ // Expected result
+ // --------------------
+ // Nothing.
+
+ // --------------------
+ // Run method
+ // --------------------
+ // Load methods for private
+ Method method = CellCtlODataProducer.class.getDeclaredMethod("buildRelation", EntitySetDocHandler.class);
+ method.setAccessible(true);
+ // Run method
+ method.invoke(cellCtlODataProducer, entitySetDocHandler);
+
+ // --------------------
+ // Confirm result
+ // --------------------
+ // Confirm function call
+ PowerMockito.verifyPrivate(cellCtlODataProducer, times(1)).invoke(
+ "createRelationEntity", "dummyRelation", "dummyBoxName");
+ PowerMockito.verifyPrivate(cellCtlODataProducer, times(1)).invoke(
+ "createExtCellEntity", "http://personium/dummyExtCell/");
+ PowerMockito.verifyPrivate(cellCtlODataProducer, times(1)).invoke(
+ "createRelationExtCellLinks", "dummyRelation", "dummyBoxName", "http://personium/dummyExtCell/");
+ }
+
+ /**
+ * Test buildRelation().
+ * Relation and extcell is exists.
+ * @throws Exception Unexpected error
+ */
+ @Test
+ public void buildRelation_Normal_exists_relation_and_extcell() throws Exception {
+ cellCtlODataProducer = PowerMockito.spy(new CellCtlODataProducer(new CellEsImpl()));
+ // --------------------
+ // Test method args
+ // --------------------
+ EntitySetDocHandler entitySetDocHandler = mock(EntitySetDocHandler.class);
+
+ // --------------------
+ // Mock settings
+ // --------------------
+ Map mockStaticFields = new HashMap();
+ mockStaticFields.put(ReceivedMessage.P_REQUEST_RELATION.getName(), "dummyRelation");
+ mockStaticFields.put(ReceivedMessage.P_REQUEST_RELATION_TARGET.getName(), "http://personium/dummyExtCell/");
+ doReturn(mockStaticFields).when(entitySetDocHandler).getStaticFields();
+
+ doReturn("dummyRelation").when(cellCtlODataProducer).getRelationNameFromRequestRelation("dummyRelation");
+ doReturn("dummyBoxName").when(cellCtlODataProducer).getBoxNameFromRequestRelation("dummyRelation");
+
+ doReturn(new OEntityDocHandler()).when(cellCtlODataProducer).getRelation("dummyRelation", "dummyBoxName");
+ PowerMockito.doNothing().when(cellCtlODataProducer, "createRelationEntity", "dummyRelation", "dummyBoxName");
+
+ doReturn(new OEntityDocHandler()).when(cellCtlODataProducer).getExtCell("http://personium/dummyExtCell/");
+ PowerMockito.doNothing().when(cellCtlODataProducer, "createExtCellEntity", "http://personium/dummyExtCell/");
+
+ PowerMockito.doNothing().when(cellCtlODataProducer, "createRelationExtCellLinks", "dummyRelation",
+ "dummyBoxName", "http://personium/dummyExtCell/");
+
+ // --------------------
+ // Expected result
+ // --------------------
+ // Nothing.
+
+ // --------------------
+ // Run method
+ // --------------------
+ // Load methods for private
+ Method method = CellCtlODataProducer.class.getDeclaredMethod("buildRelation", EntitySetDocHandler.class);
+ method.setAccessible(true);
+ // Run method
+ method.invoke(cellCtlODataProducer, entitySetDocHandler);
+
+ // --------------------
+ // Confirm result
+ // --------------------
+ // Confirm function call
+ PowerMockito.verifyPrivate(cellCtlODataProducer, never()).invoke(
+ "createRelationEntity", "dummyRelation", "dummyBoxName");
+ PowerMockito.verifyPrivate(cellCtlODataProducer, never()).invoke(
+ "createExtCellEntity", "http://personium/dummyExtCell/");
+ PowerMockito.verifyPrivate(cellCtlODataProducer, times(1)).invoke(
+ "createRelationExtCellLinks", "dummyRelation", "dummyBoxName", "http://personium/dummyExtCell/");
+ }
+
+ /**
+ * Test buildRelation().
+ * requestExtCell does not end with a slash.
+ * @throws Exception Unexpected error
+ */
+ @Test
+ public void buildRelation_Normal_requestExtCell_does_not_endwith_slash() throws Exception {
+ cellCtlODataProducer = PowerMockito.spy(new CellCtlODataProducer(new CellEsImpl()));
+ // --------------------
+ // Test method args
+ // --------------------
+ EntitySetDocHandler entitySetDocHandler = mock(EntitySetDocHandler.class);
+
+ // --------------------
+ // Mock settings
+ // --------------------
+ Map mockStaticFields = new HashMap();
+ mockStaticFields.put(ReceivedMessage.P_REQUEST_RELATION.getName(), "dummyRelation");
+ mockStaticFields.put(ReceivedMessage.P_REQUEST_RELATION_TARGET.getName(), "http://personium/dummyExtCell");
+ doReturn(mockStaticFields).when(entitySetDocHandler).getStaticFields();
+
+ doReturn("dummyRelation").when(cellCtlODataProducer).getRelationNameFromRequestRelation("dummyRelation");
+ doReturn("dummyBoxName").when(cellCtlODataProducer).getBoxNameFromRequestRelation("dummyRelation");
+
+ doReturn(null).when(cellCtlODataProducer).getRelation("dummyRelation", "dummyBoxName");
+ PowerMockito.doNothing().when(cellCtlODataProducer, "createRelationEntity", "dummyRelation", "dummyBoxName");
+
+ doReturn(null).when(cellCtlODataProducer).getExtCell("http://personium/dummyExtCell/");
+ PowerMockito.doNothing().when(cellCtlODataProducer, "createExtCellEntity", "http://personium/dummyExtCell/");
+
+ PowerMockito.doNothing().when(cellCtlODataProducer, "createRelationExtCellLinks", "dummyRelation",
+ "dummyBoxName", "http://personium/dummyExtCell/");
+
+ // --------------------
+ // Expected result
+ // --------------------
+ // Nothing.
+
+ // --------------------
+ // Run method
+ // --------------------
+ // Load methods for private
+ Method method = CellCtlODataProducer.class.getDeclaredMethod("buildRelation", EntitySetDocHandler.class);
+ method.setAccessible(true);
+ // Run method
+ method.invoke(cellCtlODataProducer, entitySetDocHandler);
+
+ // --------------------
+ // Confirm result
+ // --------------------
+ // Confirm function call
+ PowerMockito.verifyPrivate(cellCtlODataProducer, times(1)).invoke(
+ "createRelationEntity", "dummyRelation", "dummyBoxName");
+ PowerMockito.verifyPrivate(cellCtlODataProducer, times(1)).invoke(
+ "createExtCellEntity", "http://personium/dummyExtCell/");
+ PowerMockito.verifyPrivate(cellCtlODataProducer, times(1)).invoke(
+ "createRelationExtCellLinks", "dummyRelation", "dummyBoxName", "http://personium/dummyExtCell/");
+ }
+
+ /**
+ * Test createRelationOEntityKey().
+ * BoxName is not null.
+ * @throws Exception Unexpected error
+ */
+ @Test
+ public void createRelationOEntityKey_Normal_boxName_is_not_null() throws Exception {
+ // --------------------
+ // Test method args
+ // --------------------
+ String relationName = "dummyRelationName";
+ String boxName = "dummyBoxName";
+
+ // --------------------
+ // Mock settings
+ // --------------------
+ // Nothing.
+
+ // --------------------
+ // Expected result
+ // --------------------
+ OEntityKey expectedOEntityKey = OEntityKey.create(
+ Relation.P_NAME.getName(), relationName,
+ Common.P_BOX_NAME.getName(), boxName);
+
+ // --------------------
+ // Run method
+ // --------------------
+ // Load methods for private
+ Method method = CellCtlODataProducer.class.getDeclaredMethod("createRelationOEntityKey",
+ String.class, String.class);
+ method.setAccessible(true);
+ // Run method
+ OEntityKey resultOEntityKey = (OEntityKey) method.invoke(cellCtlODataProducer, relationName, boxName);
+
+ // --------------------
+ // Confirm result
+ // --------------------
+ assertThat(resultOEntityKey.toString(), is(expectedOEntityKey.toString()));
+ }
+
+ /**
+ * Test createRelationOEntityKey().
+ * BoxName is null.
+ * @throws Exception Unexpected error
+ */
+ @Test
+ public void createRelationOEntityKey_Normal_boxName_is_null() throws Exception {
+ // --------------------
+ // Test method args
+ // --------------------
+ String relationName = "dummyRelationName";
+ String boxName = null;
+
+ // --------------------
+ // Mock settings
+ // --------------------
+ // Nothing.
+
+ // --------------------
+ // Expected result
+ // --------------------
+ OEntityKey expectedOEntityKey = OEntityKey.create(
+ Relation.P_NAME.getName(), relationName);
+
+ // --------------------
+ // Run method
+ // --------------------
+ // Load methods for private
+ Method method = CellCtlODataProducer.class.getDeclaredMethod("createRelationOEntityKey",
+ String.class, String.class);
+ method.setAccessible(true);
+ // Run method
+ OEntityKey resultOEntityKey = (OEntityKey) method.invoke(cellCtlODataProducer, relationName, boxName);
+
+ // --------------------
+ // Confirm result
+ // --------------------
+ assertThat(resultOEntityKey.toString(), is(expectedOEntityKey.toString()));
+ }
+
+ /**
+ * Test createRelationOEntityKey().
+ * Error test.
+ * EntityKey parse failed.
+ * @throws Exception Unexpected error
+ */
+ @Test
+ public void createRelationOEntityKey_Error_entityKey_parse_failed() throws Exception {
+ // --------------------
+ // Test method args
+ // --------------------
+ String relationName = "'dummy'";
+ String boxName = null;
+
+ // --------------------
+ // Mock settings
+ // --------------------
+ // Nothing.
+
+ // --------------------
+ // Expected result
+ // --------------------
+ // Nothing.
+
+ // --------------------
+ // Run method
+ // --------------------
+ // Load methods for private
+ Method method = CellCtlODataProducer.class.getDeclaredMethod("createRelationOEntityKey",
+ String.class, String.class);
+ method.setAccessible(true);
+ // Run method
+ try {
+ method.invoke(cellCtlODataProducer, relationName, boxName);
+ fail("Not exception.");
+ } catch (InvocationTargetException e) {
+ // --------------------
+ // Confirm result
+ // --------------------
+ IllegalArgumentException cause = new IllegalArgumentException(
+ "bad valueString [''dummy''] as part of keyString [''dummy'']");
+ PersoniumCoreException expected =
+ PersoniumCoreException.ReceivedMessage.REQUEST_RELATION_PARSE_ERROR.reason(cause);
+ PersoniumCoreException exception = (PersoniumCoreException) e.getCause();
+ assertThat(exception.getStatus(), is(expected.getStatus()));
+ assertThat(exception.getCode(), is(expected.getCode()));
+ assertThat(exception.getMessage(), is(expected.getMessage()));
+ assertThat(exception.getCause().getMessage(), is(expected.getCause().getMessage()));
+ }
+ }
+
+ /**
+ * Test createRelationEntity().
+ * BoxName is not null.
+ * @throws Exception Unexpected error
+ */
+ @Test
+ public void createRelationEntity_Normal_boxName_is_not_null() throws Exception {
+ cellCtlODataProducer = PowerMockito.spy(new CellCtlODataProducer(new CellEsImpl()));
+ // --------------------
+ // Test method args
+ // --------------------
+ String relationName = "dummyRelationName";
+ String boxName = "dummyBoxName";
+
+ // --------------------
+ // Mock settings
+ // --------------------
+ PowerMockito.doNothing().when(cellCtlODataProducer, "createEntity", anyString(), anyMap());
+
+ // --------------------
+ // Expected result
+ // --------------------
+ // Nothing.
+
+ // --------------------
+ // Run method
+ // --------------------
+ // Load methods for private
+ Method method = CellCtlODataProducer.class.getDeclaredMethod("createRelationEntity",
+ String.class, String.class);
+ method.setAccessible(true);
+ // Run method
+ method.invoke(cellCtlODataProducer, relationName, boxName);
+
+ // --------------------
+ // Confirm result
+ // --------------------
+ // Confirm function call
+ Map staticFields = new HashMap();
+ staticFields.put(Relation.P_NAME.getName(), relationName);
+ staticFields.put(Common.P_BOX_NAME.getName(), boxName);
+ PowerMockito.verifyPrivate(cellCtlODataProducer, times(1)).invoke("createEntity",
+ Relation.EDM_TYPE_NAME, staticFields);
+ }
+
+ /**
+ * Test createRelationEntity().
+ * BoxName is null.
+ * @throws Exception Unexpected error
+ */
+ @Test
+ public void createRelationEntity_Normal_boxName_is_null() throws Exception {
+ cellCtlODataProducer = PowerMockito.spy(new CellCtlODataProducer(new CellEsImpl()));
+ // --------------------
+ // Test method args
+ // --------------------
+ String relationName = "dummyRelationName";
+ String boxName = null;
+
+ // --------------------
+ // Mock settings
+ // --------------------
+ PowerMockito.doNothing().when(cellCtlODataProducer, "createEntity", anyString(), anyMap());
+
+ // --------------------
+ // Expected result
+ // --------------------
+ // Nothing.
+
+ // --------------------
+ // Run method
+ // --------------------
+ // Load methods for private
+ Method method = CellCtlODataProducer.class.getDeclaredMethod("createRelationEntity",
+ String.class, String.class);
+ method.setAccessible(true);
+ // Run method
+ method.invoke(cellCtlODataProducer, relationName, boxName);
+
+ // --------------------
+ // Confirm result
+ // --------------------
+ // Confirm function call
+ Map staticFields = new HashMap();
+ staticFields.put(Relation.P_NAME.getName(), relationName);
+ PowerMockito.verifyPrivate(cellCtlODataProducer, times(1)).invoke("createEntity",
+ Relation.EDM_TYPE_NAME, staticFields);
+ }
+
+ /**
+ * Test createEntity().
+ * EntityKey type is complex.
+ * @throws Exception Unexpected error
+ */
+ @Test
+ public void createEntity_Normal_entitykey_type_is_complex() throws Exception {
+ cellCtlODataProducer = PowerMockito.spy(new CellCtlODataProducer(new CellEsImpl()));
+ // --------------------
+ // Test method args
+ // --------------------
+ String typeName = "dummyTypeName";
+ Map staticFields = new HashMap();
+ staticFields.put(Relation.P_NAME.getName(), "dummyRelationName");
+ staticFields.put(Common.P_BOX_NAME.getName(), "dummyBoxName");
+
+ // --------------------
+ // Mock settings
+ // --------------------
+ EntitySetAccessor mockEsType = mock(EntitySetAccessor.class);
+ doReturn(mockEsType).when(cellCtlODataProducer).getAccessorForEntitySet(typeName);
+
+ PowerMockito.doNothing().when(cellCtlODataProducer, "setLinksFromOEntityKey",
+ anyObject(), anyString(), anyObject());
+
+ doNothing().when(cellCtlODataProducer).beforeCreate(anyString(), anyObject(), anyObject());
+ doReturn(null).when(mockEsType).create(anyString(), anyObject());
+ doNothing().when(cellCtlODataProducer).afterCreate(anyString(), anyObject(), anyObject());
+
+ // --------------------
+ // Expected result
+ // --------------------
+ EntitySetDocHandler expectedOedh = new OEntityDocHandler();
+ expectedOedh.setType(typeName);
+ expectedOedh.setStaticFields(staticFields);
+ expectedOedh.setBoxId(null);
+ expectedOedh.setNodeId(null);
+
+ // --------------------
+ // Run method
+ // --------------------
+ // Load methods for private
+ Method method = CellCtlODataProducer.class.getDeclaredMethod("createEntity",
+ String.class, Map.class);
+ method.setAccessible(true);
+ // Run method
+ method.invoke(cellCtlODataProducer, typeName, staticFields);
+
+ // --------------------
+ // Confirm result
+ // --------------------
+ // Confirm function call
+ ArgumentCaptor entityKeyCaptor = ArgumentCaptor.forClass(OEntityKey.class);
+ ArgumentCaptor stringCaptor = ArgumentCaptor.forClass(String.class);
+ ArgumentCaptor docHandlerCaptor = ArgumentCaptor.forClass(EntitySetDocHandler.class);
+ ArgumentCaptor entityCaptor = ArgumentCaptor.forClass(OEntity.class);
+
+ PowerMockito.verifyPrivate(cellCtlODataProducer, times(1)).invoke("setLinksFromOEntityKey",
+ entityKeyCaptor.capture(), stringCaptor.capture(), docHandlerCaptor.capture());
+ assertThat(entityKeyCaptor.getValue(), is(OEntityKey.create(staticFields)));
+ assertThat(stringCaptor.getValue(), is(typeName));
+ confirmEntitySetDocHandler(expectedOedh, docHandlerCaptor.getValue());
+
+ verify(cellCtlODataProducer, times(1)).beforeCreate(stringCaptor.capture(), entityCaptor.capture(),
+ docHandlerCaptor.capture());
+ assertThat(stringCaptor.getValue(), is(typeName));
+ assertNull(entityCaptor.getValue());
+ confirmEntitySetDocHandler(expectedOedh, docHandlerCaptor.getValue());
+
+ verify(mockEsType, times(1)).create(stringCaptor.capture(), docHandlerCaptor.capture());
+ confirmEntitySetDocHandler(expectedOedh, docHandlerCaptor.getValue());
+
+ verify(cellCtlODataProducer, times(1)).afterCreate(stringCaptor.capture(), entityCaptor.capture(),
+ docHandlerCaptor.capture());
+ assertThat(stringCaptor.getValue(), is(typeName));
+ assertNull(entityCaptor.getValue());
+ confirmEntitySetDocHandler(expectedOedh, docHandlerCaptor.getValue());
+ }
+
+ /**
+ * Test createEntity().
+ * EntityKey type is not complex.
+ * @throws Exception Unexpected error
+ */
+ @Test
+ public void createEntity_Normal_entitykey_type_is_not_complex() throws Exception {
+ cellCtlODataProducer = PowerMockito.spy(new CellCtlODataProducer(new CellEsImpl()));
+ // --------------------
+ // Test method args
+ // --------------------
+ String typeName = "dummyTypeName";
+ Map staticFields = new HashMap();
+ staticFields.put(Relation.P_NAME.getName(), "dummyRelationName");
+
+ // --------------------
+ // Mock settings
+ // --------------------
+ EntitySetAccessor mockEsType = mock(EntitySetAccessor.class);
+ doReturn(mockEsType).when(cellCtlODataProducer).getAccessorForEntitySet(typeName);
+
+ PowerMockito.doNothing().when(cellCtlODataProducer, "setLinksFromOEntityKey",
+ anyObject(), anyString(), anyObject());
+
+ doNothing().when(cellCtlODataProducer).beforeCreate(anyString(), anyObject(), anyObject());
+ doReturn(null).when(mockEsType).create(anyString(), anyObject());
+ doNothing().when(cellCtlODataProducer).afterCreate(anyString(), anyObject(), anyObject());
+
+ // --------------------
+ // Expected result
+ // --------------------
+ EntitySetDocHandler expectedOedh = new OEntityDocHandler();
+ expectedOedh.setType(typeName);
+ expectedOedh.setStaticFields(staticFields);
+ expectedOedh.setBoxId(null);
+ expectedOedh.setNodeId(null);
+
+ // --------------------
+ // Run method
+ // --------------------
+ // Load methods for private
+ Method method = CellCtlODataProducer.class.getDeclaredMethod("createEntity",
+ String.class, Map.class);
+ method.setAccessible(true);
+ // Run method
+ method.invoke(cellCtlODataProducer, typeName, staticFields);
+
+ // --------------------
+ // Confirm result
+ // --------------------
+ // Confirm function call
+ ArgumentCaptor entityKeyCaptor = ArgumentCaptor.forClass(OEntityKey.class);
+ ArgumentCaptor stringCaptor = ArgumentCaptor.forClass(String.class);
+ ArgumentCaptor docHandlerCaptor = ArgumentCaptor.forClass(EntitySetDocHandler.class);
+ ArgumentCaptor entityCaptor = ArgumentCaptor.forClass(OEntity.class);
+
+ PowerMockito.verifyPrivate(cellCtlODataProducer, times(0)).invoke("setLinksFromOEntityKey",
+ entityKeyCaptor.capture(), stringCaptor.capture(), docHandlerCaptor.capture());
+
+ verify(cellCtlODataProducer, times(1)).beforeCreate(stringCaptor.capture(), entityCaptor.capture(),
+ docHandlerCaptor.capture());
+ assertThat(stringCaptor.getValue(), is(typeName));
+ assertNull(entityCaptor.getValue());
+ confirmEntitySetDocHandler(expectedOedh, docHandlerCaptor.getValue());
+
+ verify(mockEsType, times(1)).create(stringCaptor.capture(), docHandlerCaptor.capture());
+ confirmEntitySetDocHandler(expectedOedh, docHandlerCaptor.getValue());
+
+ verify(cellCtlODataProducer, times(1)).afterCreate(stringCaptor.capture(), entityCaptor.capture(),
+ docHandlerCaptor.capture());
+ assertThat(stringCaptor.getValue(), is(typeName));
+ assertNull(entityCaptor.getValue());
+ confirmEntitySetDocHandler(expectedOedh, docHandlerCaptor.getValue());
+ }
+
+ /**
+ * Confirm EntitySetDocHandler.
+ * Indefinite values such as UUID and SystemDate are not checked.
+ * @param expected expected
+ * @param actual actual
+ */
+ private void confirmEntitySetDocHandler(EntitySetDocHandler expected, EntitySetDocHandler actual) {
+ assertThat(expected.getType(), is(actual.getType()));
+ assertThat(expected.getStaticFields(), is(actual.getStaticFields()));
+ assertThat(expected.getBoxId(), is(actual.getBoxId()));
+ assertThat(expected.getNodeId(), is(actual.getNodeId()));
+ }
+
+ /**
+ * Test createEntity().
+ * Error test.
+ * setLinksFromOEntityKey fail.
+ * @throws Exception Unexpected error
+ */
+ @Test
+ public void createEntity_Error_setLinksFromOEntityKey_fail() throws Exception {
+ cellCtlODataProducer = PowerMockito.spy(new CellCtlODataProducer(new CellEsImpl()));
+ // --------------------
+ // Test method args
+ // --------------------
+ String typeName = "dummyTypeName";
+ Map staticFields = new HashMap();
+ staticFields.put(Relation.P_NAME.getName(), "dummyRelationName");
+ staticFields.put(Common.P_BOX_NAME.getName(), "dummyBoxName");
+
+ // --------------------
+ // Mock settings
+ // --------------------
+ EntitySetAccessor mockEsType = mock(EntitySetAccessor.class);
+ doReturn(mockEsType).when(cellCtlODataProducer).getAccessorForEntitySet(typeName);
+
+ PowerMockito.doThrow(new NTKPNotFoundException("dummyMsg")).when(cellCtlODataProducer,
+ "setLinksFromOEntityKey", anyObject(), anyString(), anyObject());
+
+ // --------------------
+ // Expected result
+ // --------------------
+ // Nothing.
+
+ // --------------------
+ // Run method
+ // --------------------
+ // Load methods for private
+ Method method = CellCtlODataProducer.class.getDeclaredMethod("createEntity",
+ String.class, Map.class);
+ method.setAccessible(true);
+ try {
+ // Run method
+ method.invoke(cellCtlODataProducer, typeName, staticFields);
+ fail("Not exception.");
+ } catch (InvocationTargetException e) {
+ // --------------------
+ // Confirm result
+ // --------------------
+ PersoniumCoreException expected =
+ PersoniumCoreException.OData.BODY_NTKP_NOT_FOUND_ERROR.params("dummyMsg");
+ PersoniumCoreException exception = (PersoniumCoreException) e.getCause();
+ assertThat(exception.getStatus(), is(expected.getStatus()));
+ assertThat(exception.getCode(), is(expected.getCode()));
+ assertThat(exception.getMessage(), is(expected.getMessage()));
+ }
+ }
+
+ /**
+ * Test setLinksFromOEntityKey().
+ * Normal test.
+ * @throws Exception Unexpected error
+ */
+ @Test
+ public void setLinksFromOEntityKey_Normal() throws Exception {
+ // --------------------
+ // Test method args
+ // --------------------
+ OEntityKey key = OEntityKey.create(
+ Relation.P_NAME.getName(), "dummyRelationName",
+ Common.P_BOX_NAME.getName(), "dummyBoxName");
+ String typeName = Relation.EDM_TYPE_NAME;
+ EntitySetDocHandler oedh = new OEntityDocHandler();
+
+ // --------------------
+ // Mock settings
+ // --------------------
+ doNothing().when(cellCtlODataProducer).setLinksForOedh(anyObject(), anyObject(), anyObject());
+
+ // --------------------
+ // Expected result
+ // --------------------
+ // Nothing.
+
+ // --------------------
+ // Run method
+ // --------------------
+ // Load methods for private
+ Method method = CellCtlODataProducer.class.getDeclaredMethod("setLinksFromOEntityKey",
+ OEntityKey.class, String.class, EntitySetDocHandler.class);
+ method.setAccessible(true);
+ // Run method
+ method.invoke(cellCtlODataProducer, key, typeName, oedh);
+
+ // --------------------
+ // Confirm result
+ // --------------------
+ // Confirm function call
+ verify(cellCtlODataProducer, times(1)).setLinksForOedh(anyObject(), anyObject(), anyObject());
+ }
+
+ /**
+ * Test setLinksFromOEntityKey().
+ * Error test.
+ * setLinksForOedh fail.
+ * @throws Exception Unexpected error
+ */
+ @Test
+ public void setLinksFromOEntityKey_Error_setLinksForOedh_fail() throws Exception {
+ // --------------------
+ // Test method args
+ // --------------------
+ OEntityKey key = OEntityKey.create(
+ Relation.P_NAME.getName(), "dummyRelationName",
+ Common.P_BOX_NAME.getName(), "dummyBoxName");
+ String typeName = Relation.EDM_TYPE_NAME;
+ EntitySetDocHandler oedh = new OEntityDocHandler();
+
+ // --------------------
+ // Mock settings
+ // --------------------
+ doThrow(new NTKPNotFoundException("dummyMsg")).when(cellCtlODataProducer).setLinksForOedh(
+ anyObject(), anyObject(), anyObject());
+
+ // --------------------
+ // Expected result
+ // --------------------
+ // Nothing.
+
+ // --------------------
+ // Run method
+ // --------------------
+ // Load methods for private
+ Method method = CellCtlODataProducer.class.getDeclaredMethod("setLinksFromOEntityKey",
+ OEntityKey.class, String.class, EntitySetDocHandler.class);
+ method.setAccessible(true);
+ try {
+ // Run method
+ method.invoke(cellCtlODataProducer, key, typeName, oedh);
+ fail("Not exception.");
+ } catch (InvocationTargetException e) {
+ // --------------------
+ // Confirm result
+ // --------------------
+ NTKPNotFoundException expected = new NTKPNotFoundException("dummyMsg");
+ NTKPNotFoundException exception = (NTKPNotFoundException) e.getCause();
+ assertThat(exception.getMessage(), is(expected.getMessage()));
+ }
+ }
+
+ /**
+ * Test breakRelation().
+ * Normal test.
+ * getBoxNameFromRequestRelation() is not null.
+ */
+ @Test
+ public void breakRelation_Normal_getBoxNameFromRequestRelation_is_not_null() {
+ // --------------------
+ // Test method args
+ // --------------------
+ EntitySetDocHandler entitySetDocHandler = mock(EntitySetDocHandler.class);
+
+ // --------------------
+ // Mock settings
+ // --------------------
+ Map mockStaticFields = new HashMap();
+ mockStaticFields.put(ReceivedMessage.P_REQUEST_RELATION.getName(),
+ "http://personium/dummyAppCell/__relation/__/dummyRelation");
+ mockStaticFields.put(ReceivedMessage.P_REQUEST_RELATION_TARGET.getName(), "http://personium/dummyExtCell/");
+ doReturn(mockStaticFields).when(entitySetDocHandler).getStaticFields();
+
+ doReturn("dummyRelation").when(cellCtlODataProducer).getRelationNameFromRequestRelation(
+ "http://personium/dummyAppCell/__relation/__/dummyRelation");
+ doReturn("dummyBoxName").when(cellCtlODataProducer).getBoxNameFromRequestRelation(
+ "http://personium/dummyAppCell/__relation/__/dummyRelation");
+
+ EntitySetDocHandler relation = new OEntityDocHandler();
+ EntitySetDocHandler extCell = new OEntityDocHandler();
+ doReturn(relation).when(cellCtlODataProducer).getRelation("dummyRelation", "dummyBoxName");
+ doReturn(extCell).when(cellCtlODataProducer).getExtCell("http://personium/dummyExtCell/");
+
+ doReturn(true).when(cellCtlODataProducer).deleteLinkEntity(relation, extCell);
+
+ // --------------------
+ // Expected result
+ // --------------------
+ // Nothing.
+
+ // --------------------
+ // Run method
+ // --------------------
+ cellCtlODataProducer.breakRelation(entitySetDocHandler);
+
+ // --------------------
+ // Confirm result
+ // --------------------
+ // Confirm function call
+ verify(cellCtlODataProducer, times(1)).deleteLinkEntity(relation, extCell);
+ }
+
+ /**
+ * Test breakRelation().
+ * Normal test.
+ * getBoxNameFromRequestRelation() is null.
+ */
+ @Test
+ public void breakRelation_Normal_getBoxNameFromRequestRelation_is_null() {
+ // --------------------
+ // Test method args
+ // --------------------
+ EntitySetDocHandler entitySetDocHandler = mock(EntitySetDocHandler.class);
+
+ // --------------------
+ // Mock settings
+ // --------------------
+ Map mockStaticFields = new HashMap();
+ mockStaticFields.put(ReceivedMessage.P_REQUEST_RELATION.getName(),
+ "http://personium/dummyAppCell/__relation/__/dummyRelation");
+ mockStaticFields.put(ReceivedMessage.P_BOX_NAME.getName(), "dummyBoxName");
+ mockStaticFields.put(ReceivedMessage.P_REQUEST_RELATION_TARGET.getName(), "http://personium/dummyExtCell/");
+ doReturn(mockStaticFields).when(entitySetDocHandler).getStaticFields();
+
+ doReturn("dummyRelation").when(cellCtlODataProducer).getRelationNameFromRequestRelation(
+ "http://personium/dummyAppCell/__relation/__/dummyRelation");
+ doReturn(null).when(cellCtlODataProducer).getBoxNameFromRequestRelation(
+ "http://personium/dummyAppCell/__relation/__/dummyRelation");
+
+ EntitySetDocHandler relation = new OEntityDocHandler();
+ EntitySetDocHandler extCell = new OEntityDocHandler();
+ doReturn(relation).when(cellCtlODataProducer).getRelation("dummyRelation", "dummyBoxName");
+ doReturn(extCell).when(cellCtlODataProducer).getExtCell("http://personium/dummyExtCell/");
+
+ doReturn(true).when(cellCtlODataProducer).deleteLinkEntity(relation, extCell);
+
+ // --------------------
+ // Expected result
+ // --------------------
+ // Nothing.
+
+ // --------------------
+ // Run method
+ // --------------------
+ cellCtlODataProducer.breakRelation(entitySetDocHandler);
+
+ // --------------------
+ // Confirm result
+ // --------------------
+ // Confirm function call
+ verify(cellCtlODataProducer, times(1)).deleteLinkEntity(relation, extCell);
+ }
+
+ /**
+ * Test breakRelation().
+ * Error test.
+ * relation is null.
+ */
+ @Test
+ public void breakRelation_Error_relation_is_null() {
+ // --------------------
+ // Test method args
+ // --------------------
+ EntitySetDocHandler entitySetDocHandler = mock(EntitySetDocHandler.class);
+
+ // --------------------
+ // Mock settings
+ // --------------------
+ Map mockStaticFields = new HashMap();
+ mockStaticFields.put(ReceivedMessage.P_REQUEST_RELATION.getName(),
+ "http://personium/dummyAppCell/__relation/__/dummyRelation");
+ mockStaticFields.put(ReceivedMessage.P_REQUEST_RELATION_TARGET.getName(), "http://personium/dummyExtCell/");
+ doReturn(mockStaticFields).when(entitySetDocHandler).getStaticFields();
+
+ doReturn("dummyRelation").when(cellCtlODataProducer).getRelationNameFromRequestRelation(
+ "http://personium/dummyAppCell/__relation/__/dummyRelation");
+ doReturn("dummyBoxName").when(cellCtlODataProducer).getBoxNameFromRequestRelation(
+ "http://personium/dummyAppCell/__relation/__/dummyRelation");
+
+ doReturn(null).when(cellCtlODataProducer).getRelation("dummyRelation", "dummyBoxName");
+
+ // --------------------
+ // Expected result
+ // --------------------
+ // Nothing.
+
+ // --------------------
+ // Run method
+ // --------------------
+ try {
+ cellCtlODataProducer.breakRelation(entitySetDocHandler);
+ fail("Not exception.");
+ } catch (PersoniumCoreException e) {
+ // --------------------
+ // Confirm result
+ // --------------------
+ PersoniumCoreException expected =
+ PersoniumCoreException.ReceivedMessage.REQUEST_RELATION_DOES_NOT_EXISTS.params("dummyRelation");
+ assertThat(e.getStatus(), is(expected.getStatus()));
+ assertThat(e.getCode(), is(expected.getCode()));
+ assertThat(e.getMessage(), is(expected.getMessage()));
+ }
+ }
+
+ /**
+ * Test breakRelation().
+ * Error test.
+ * extCell is null.
+ */
+ @Test
+ public void breakRelation_Error_extCell_is_null() {
+ // --------------------
+ // Test method args
+ // --------------------
+ EntitySetDocHandler entitySetDocHandler = mock(EntitySetDocHandler.class);
+
+ // --------------------
+ // Mock settings
+ // --------------------
+ Map mockStaticFields = new HashMap();
+ mockStaticFields.put(ReceivedMessage.P_REQUEST_RELATION.getName(),
+ "http://personium/dummyAppCell/__relation/__/dummyRelation");
+ mockStaticFields.put(ReceivedMessage.P_BOX_NAME.getName(), "dummyBoxName");
+ mockStaticFields.put(ReceivedMessage.P_REQUEST_RELATION_TARGET.getName(), "http://personium/dummyExtCell/");
+ doReturn(mockStaticFields).when(entitySetDocHandler).getStaticFields();
+
+ doReturn("dummyRelation").when(cellCtlODataProducer).getRelationNameFromRequestRelation(
+ "http://personium/dummyAppCell/__relation/__/dummyRelation");
+ doReturn("dummyBoxName").when(cellCtlODataProducer).getBoxNameFromRequestRelation(
+ "http://personium/dummyAppCell/__relation/__/dummyRelation");
+
+ EntitySetDocHandler relation = new OEntityDocHandler();
+ doReturn(relation).when(cellCtlODataProducer).getRelation("dummyRelation", "dummyBoxName");
+ doReturn(null).when(cellCtlODataProducer).getExtCell("http://personium/dummyExtCell/");
+
+ // --------------------
+ // Expected result
+ // --------------------
+ // Nothing.
+
+ // --------------------
+ // Run method
+ // --------------------
+ try {
+ cellCtlODataProducer.breakRelation(entitySetDocHandler);
+ fail("Not exception.");
+ } catch (PersoniumCoreException e) {
+ // --------------------
+ // Confirm result
+ // --------------------
+ PersoniumCoreException expected = PersoniumCoreException.ReceivedMessage
+ .REQUEST_RELATION_TARGET_DOES_NOT_EXISTS.params("http://personium/dummyExtCell/");
+ assertThat(e.getStatus(), is(expected.getStatus()));
+ assertThat(e.getCode(), is(expected.getCode()));
+ assertThat(e.getMessage(), is(expected.getMessage()));
+ }
+ }
+
+ /**
+ * Test breakRelation().
+ * Error test.
+ * deleteLinkEntity is false.
+ */
+ @Test
+ public void breakRelation_Error_deleteLinkEntity_is_false() {
+ // --------------------
+ // Test method args
+ // --------------------
+ EntitySetDocHandler entitySetDocHandler = mock(EntitySetDocHandler.class);
+
+ // --------------------
+ // Mock settings
+ // --------------------
+ Map mockStaticFields = new HashMap();
+ mockStaticFields.put(ReceivedMessage.P_REQUEST_RELATION.getName(),
+ "http://personium/dummyAppCell/__relation/__/dummyRelation");
+ mockStaticFields.put(ReceivedMessage.P_BOX_NAME.getName(), "dummyBoxName");
+ mockStaticFields.put(ReceivedMessage.P_REQUEST_RELATION_TARGET.getName(), "http://personium/dummyExtCell/");
+ doReturn(mockStaticFields).when(entitySetDocHandler).getStaticFields();
+
+ doReturn("dummyRelation").when(cellCtlODataProducer).getRelationNameFromRequestRelation(
+ "http://personium/dummyAppCell/__relation/__/dummyRelation");
+ doReturn("dummyBoxName").when(cellCtlODataProducer).getBoxNameFromRequestRelation(
+ "http://personium/dummyAppCell/__relation/__/dummyRelation");
+
+ EntitySetDocHandler relation = new OEntityDocHandler();
+ EntitySetDocHandler extCell = new OEntityDocHandler();
+ doReturn(relation).when(cellCtlODataProducer).getRelation("dummyRelation", "dummyBoxName");
+ doReturn(extCell).when(cellCtlODataProducer).getExtCell("http://personium/dummyExtCell/");
+
+ doReturn(false).when(cellCtlODataProducer).deleteLinkEntity(relation, extCell);
+
+ // --------------------
+ // Expected result
+ // --------------------
+ // Nothing.
+
+ // --------------------
+ // Run method
+ // --------------------
+ try {
+ cellCtlODataProducer.breakRelation(entitySetDocHandler);
+ fail("Not exception.");
+ } catch (PersoniumCoreException e) {
+ // --------------------
+ // Confirm result
+ // --------------------
+ PersoniumCoreException expected = PersoniumCoreException.ReceivedMessage.LINK_DOES_NOT_EXISTS.params(
+ "dummyRelation", "http://personium/dummyExtCell/");
+ assertThat(e.getStatus(), is(expected.getStatus()));
+ assertThat(e.getCode(), is(expected.getCode()));
+ assertThat(e.getMessage(), is(expected.getMessage()));
+ }
+ }
+
+ /**
+ * Test getBoxNameFromRequestRelation().
+ * Normal test.
+ * RequestRelation is RelationClassURL.
+ * @throws Exception Unexpected error.
+ */
+ @Test
+ public void getBoxNameFromRequestRelation_Normal_requestRelation_is_classURL() throws Exception {
+ // --------------------
+ // Test method args
+ // --------------------
+ String requestRelation = "http://personium/dummyAppCell/__relation/__/dummyRelation";
+
+ // --------------------
+ // Mock settings
+ // --------------------
+ Cell mockCell = mock(Cell.class);
+ cellCtlODataProducer.cell = mockCell;
+ doReturn("http://personium").when(mockCell).getUnitUrl();
+
+ PowerMockito.mockStatic(UriUtils.class);
+ PowerMockito.doReturn(requestRelation).when(UriUtils.class, "convertSchemeFromLocalUnitToHttp",
+ "http://personium", requestRelation);
+
+ Box mockBox = PowerMockito.mock(Box.class);
+ doReturn("dummyBoxName").when(mockBox).getName();
+ doReturn(mockBox).when(mockCell).getBoxForSchema("http://personium/dummyAppCell/");
+
+ // --------------------
+ // Expected result
+ // --------------------
+ String expectedBoxName = "dummyBoxName";
+
+ // --------------------
+ // Run method
+ // --------------------
+ String actualBoxName = cellCtlODataProducer.getBoxNameFromRequestRelation(requestRelation);
+
+ // --------------------
+ // Confirm result
+ // --------------------
+ assertThat(actualBoxName, is(expectedBoxName));
+ }
+
+ /**
+ * Test getBoxNameFromRequestRelation().
+ * Normal test.
+ * RequestRelation is RelationName.
+ * @throws Exception Unexpected error.
+ */
+ @Test
+ public void getBoxNameFromRequestRelation_Normal_requestRelation_is_name() throws Exception {
+ // --------------------
+ // Test method args
+ // --------------------
+ String requestRelation = "dummyRelation";
+
+ // --------------------
+ // Mock settings
+ // --------------------
+ Cell mockCell = mock(Cell.class);
+ cellCtlODataProducer.cell = mockCell;
+ doReturn("http://personium").when(mockCell).getUnitUrl();
+
+ PowerMockito.mockStatic(UriUtils.class);
+ PowerMockito.doReturn(requestRelation).when(UriUtils.class, "convertSchemeFromLocalUnitToHttp",
+ "http://personium", requestRelation);
+
+ // --------------------
+ // Expected result
+ // --------------------
+ String expectedBoxName = null;
+
+ // --------------------
+ // Run method
+ // --------------------
+ String actualBoxName = cellCtlODataProducer.getBoxNameFromRequestRelation(requestRelation);
+
+ // --------------------
+ // Confirm result
+ // --------------------
+ assertThat(actualBoxName, is(expectedBoxName));
+ }
+
+ /**
+ * Test getBoxNameFromRequestRelation().
+ * Error test.
+ * Box associated with class URL does not exist.
+ * @throws Exception Unexpected error.
+ */
+ @Test
+ public void getBoxNameFromRequestRelation_Error_box_associated_with_classURL_does_not_exist() throws Exception {
+ // --------------------
+ // Test method args
+ // --------------------
+ String requestRelation = "http://personium/dummyAppCell/__relation/__/dummyRelation";
+
+ // --------------------
+ // Mock settings
+ // --------------------
+ Cell mockCell = mock(Cell.class);
+ cellCtlODataProducer.cell = mockCell;
+ doReturn("http://personium").when(mockCell).getUnitUrl();
+
+ PowerMockito.mockStatic(UriUtils.class);
+ PowerMockito.doReturn(requestRelation).when(UriUtils.class, "convertSchemeFromLocalUnitToHttp",
+ "http://personium", requestRelation);
+
+ doReturn(null).when(mockCell).getBoxForSchema("http://personium/dummyAppCell/");
+
+ // --------------------
+ // Expected result
+ // --------------------
+ // Nothing.
+
+ // --------------------
+ // Run method
+ // --------------------
+ try {
+ cellCtlODataProducer.getBoxNameFromRequestRelation(requestRelation);
+ fail("Not exception.");
+ } catch (PersoniumCoreException e) {
+ // --------------------
+ // Confirm result
+ // --------------------
+ PersoniumCoreException expected = PersoniumCoreException.ReceivedMessage
+ .BOX_THAT_MATCHES_RELATION_CLASS_URL_NOT_EXISTS.params(requestRelation);
+ assertThat(e.getStatus(), is(expected.getStatus()));
+ assertThat(e.getCode(), is(expected.getCode()));
+ assertThat(e.getMessage(), is(expected.getMessage()));
+ }
+ }
+
+ /**
+ * Test getRelationNameFromRequestRelation().
+ * Normal test.
+ * RequestRelation is RelationClassURL.
+ * @throws Exception Unexpected error.
+ */
+ @Test
+ public void getRelationNameFromRequestRelation_Normal_requestRelation_is_classURL() throws Exception {
+ // --------------------
+ // Test method args
+ // --------------------
+ String requestRelation = "http://personium/dummyAppCell/__relation/__/dummyRelation";
+
+ // --------------------
+ // Mock settings
+ // --------------------
+ Cell mockCell = mock(Cell.class);
+ cellCtlODataProducer.cell = mockCell;
+ doReturn("http://personium").when(mockCell).getUnitUrl();
+
+ PowerMockito.mockStatic(UriUtils.class);
+ PowerMockito.doReturn(requestRelation).when(UriUtils.class, "convertSchemeFromLocalUnitToHttp",
+ "http://personium", requestRelation);
+
+ // --------------------
+ // Expected result
+ // --------------------
+ String expectedRelationName = "dummyRelation";
+
+ // --------------------
+ // Run method
+ // --------------------
+ String actualRelationName = cellCtlODataProducer.getRelationNameFromRequestRelation(requestRelation);
+
+ // --------------------
+ // Confirm result
+ // --------------------
+ assertThat(actualRelationName, is(expectedRelationName));
+ }
+
+ /**
+ * Test getRelationNameFromRequestRelation().
+ * Normal test.
+ * RequestRelation is RelationName.
+ * @throws Exception Unexpected error.
+ */
+ @Test
+ public void getRelationNameFromRequestRelation_Normal_requestRelation_is_name() throws Exception {
+ // --------------------
+ // Test method args
+ // --------------------
+ String requestRelation = "dummyRelation";
+
+ // --------------------
+ // Mock settings
+ // --------------------
+ Cell mockCell = mock(Cell.class);
+ cellCtlODataProducer.cell = mockCell;
+ doReturn("http://personium").when(mockCell).getUnitUrl();
+
+ PowerMockito.mockStatic(UriUtils.class);
+ PowerMockito.doReturn(requestRelation).when(UriUtils.class, "convertSchemeFromLocalUnitToHttp",
+ "http://personium", requestRelation);
+
+ // --------------------
+ // Expected result
+ // --------------------
+ String expectedRelationName = "dummyRelation";
+
+ // --------------------
+ // Run method
+ // --------------------
+ String actualRelationName = cellCtlODataProducer.getRelationNameFromRequestRelation(requestRelation);
+
+ // --------------------
+ // Confirm result
+ // --------------------
+ assertThat(actualRelationName, is(expectedRelationName));
}
}
diff --git a/src/test/java/io/personium/core/rs/cell/AllTests.java b/src/test/java/io/personium/core/rs/cell/AllTests.java
new file mode 100644
index 000000000..c2a800286
--- /dev/null
+++ b/src/test/java/io/personium/core/rs/cell/AllTests.java
@@ -0,0 +1,31 @@
+/**
+ * personium.io
+ * Copyright 2014 FUJITSU LIMITED
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package io.personium.core.rs.cell;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
+
+/**
+ * Test suite for executing all the test cases under package.
+ */
+@RunWith(Suite.class)
+@SuiteClasses({
+ MessageODataResourceTest.class
+})
+public class AllTests {
+}
diff --git a/src/test/java/io/personium/core/rs/cell/MessageODataResourceTest.java b/src/test/java/io/personium/core/rs/cell/MessageODataResourceTest.java
new file mode 100644
index 000000000..271edecfe
--- /dev/null
+++ b/src/test/java/io/personium/core/rs/cell/MessageODataResourceTest.java
@@ -0,0 +1,447 @@
+/**
+ * personium.io
+ * Copyright 2014 FUJITSU LIMITED
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package io.personium.core.rs.cell;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.fail;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+import org.odata4j.core.OProperties;
+import org.odata4j.core.OProperty;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import io.personium.core.PersoniumCoreException;
+import io.personium.core.auth.AccessContext;
+import io.personium.core.model.Box;
+import io.personium.core.model.ctl.Common;
+import io.personium.core.model.ctl.ReceivedMessage;
+import io.personium.core.model.ctl.ReceivedMessagePort;
+import io.personium.core.model.ctl.SentMessage;
+import io.personium.core.model.ctl.SentMessagePort;
+import io.personium.core.model.impl.es.CellEsImpl;
+import io.personium.test.categories.Unit;
+
+/**
+ * MessageODataResource unit test classs.
+ */
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({MessageODataResource.class, MessageResource.class, AccessContext.class, CellEsImpl.class})
+@Category({ Unit.class })
+public class MessageODataResourceTest {
+
+ /** Target class of unit test. */
+ private MessageODataResource messageODataResource;
+
+ /**
+ * Before.
+ */
+ @Before
+ public void befor() {
+ messageODataResource = spy(new MessageODataResource(null, null, null));
+ }
+
+ /**
+ * Test validate().
+ * EntitySetName is ReceivedMessage.
+ * @throws Exception Unexpected error.
+ */
+ @Test
+ public void validate_Normal_entitySetName_is_ReceivedMessage() throws Exception {
+ MessageResource messageResource = PowerMockito.mock(MessageResource.class);
+ messageODataResource = spy(new MessageODataResource(messageResource, null, ReceivedMessage.EDM_TYPE_NAME));
+ // --------------------
+ // Test method args
+ // --------------------
+ List> props = new ArrayList>();
+ props.add(OProperties.string(ReceivedMessagePort.P_SCHEMA.getName(), "http://personium/schema001"));
+ props.add(OProperties.string(ReceivedMessage.P_MULTICAST_TO.getName(), null));
+ props.add(OProperties.string(ReceivedMessage.P_BODY.getName(), "body"));
+ props.add(OProperties.string(ReceivedMessage.P_TYPE.getName(), "message"));
+ props.add(OProperties.string(ReceivedMessage.P_STATUS.getName(), "unread"));
+ props.add(OProperties.string(ReceivedMessage.P_REQUEST_RELATION.getName(), null));
+ props.add(OProperties.string(ReceivedMessage.P_REQUEST_RELATION_TARGET.getName(), null));
+ messageODataResource.collectProperties(props);
+
+ // --------------------
+ // Mock settings
+ // --------------------
+ doNothing().when(messageODataResource).validateReceivedBoxBoundSchema(
+ messageResource, "http://personium/schema001");
+ PowerMockito.mockStatic(MessageODataResource.class);
+ PowerMockito.doNothing().when(MessageODataResource.class, "validateUriCsv",
+ ReceivedMessage.P_MULTICAST_TO.getName(), null);
+ PowerMockito.doNothing().when(MessageODataResource.class, "validateBody", "body",
+ Common.MAX_MESSAGE_BODY_LENGTH);
+ PowerMockito.doNothing().when(MessageODataResource.class, "validateStatus", "message", "unread");
+ PowerMockito.doNothing().when(MessageODataResource.class, "validateReqRelation", "message", null, null);
+
+ // --------------------
+ // Expected result
+ // --------------------
+ // Nothing.
+
+ // --------------------
+ // Run method
+ // --------------------
+ messageODataResource.validate(props);
+
+ // --------------------
+ // Confirm result
+ // --------------------
+ // Confirm function call
+ verify(messageODataResource, times(1)).validateReceivedBoxBoundSchema(messageResource,
+ "http://personium/schema001");
+ PowerMockito.verifyStatic(times(1));
+ MessageODataResource.validateUriCsv(ReceivedMessage.P_MULTICAST_TO.getName(), null);
+ PowerMockito.verifyStatic(times(1));
+ MessageODataResource.validateBody("body", Common.MAX_MESSAGE_BODY_LENGTH);
+ PowerMockito.verifyStatic(times(1));
+ MessageODataResource.validateStatus("message", "unread");
+ PowerMockito.verifyStatic(times(1));
+ MessageODataResource.validateReqRelation("message", null, null);
+ }
+
+ /**
+ * Test validate().
+ * EntitySetName is SentMessage.
+ * @throws Exception Unexpected error.
+ */
+ @Test
+ public void validate_Normal_entitySetName_is_SentMessage() throws Exception {
+ String baseUri = "http://personium/";
+ AccessContext accessContext = PowerMockito.mock(AccessContext.class);
+ doReturn(baseUri).when(accessContext).getBaseUri();
+ MessageResource messageResource = PowerMockito.mock(MessageResource.class);
+ doReturn(accessContext).when(messageResource).getAccessContext();
+
+ messageODataResource = spy(new MessageODataResource(messageResource, null, SentMessage.EDM_TYPE_NAME));
+ // --------------------
+ // Test method args
+ // --------------------
+ List> props = new ArrayList>();
+ props.add(OProperties.string(SentMessagePort.P_BOX_BOUND.getName(), "false"));
+ props.add(OProperties.string(SentMessage.P_TO.getName(), "http://personium/user001"));
+ props.add(OProperties.string(SentMessage.P_BODY.getName(), "body"));
+ props.add(OProperties.string(SentMessage.P_TO_RELATION.getName(), null));
+ props.add(OProperties.string(SentMessage.P_TYPE.getName(), "message"));
+ props.add(OProperties.string(SentMessage.P_REQUEST_RELATION.getName(), null));
+ props.add(OProperties.string(SentMessage.P_REQUEST_RELATION_TARGET.getName(), null));
+ messageODataResource.collectProperties(props);
+
+ // --------------------
+ // Mock settings
+ // --------------------
+ doNothing().when(messageODataResource).validateSentBoxBoundSchema(messageResource, false);
+ PowerMockito.mockStatic(MessageODataResource.class);
+ PowerMockito.doNothing().when(MessageODataResource.class, "validateUriCsv",
+ SentMessage.P_TO.getName(), "http://personium/user001");
+ PowerMockito.doNothing().when(MessageODataResource.class, "validateBody", "body",
+ Common.MAX_MESSAGE_BODY_LENGTH);
+ PowerMockito.doNothing().when(MessageODataResource.class, "validateToAndToRelation",
+ "http://personium/user001", null);
+ PowerMockito.doNothing().when(MessageODataResource.class, "validateToValue",
+ "http://personium/user001", baseUri);
+ PowerMockito.doNothing().when(MessageODataResource.class, "validateReqRelation", "message", null, null);
+
+ // --------------------
+ // Expected result
+ // --------------------
+ // Nothing.
+
+ // --------------------
+ // Run method
+ // --------------------
+ messageODataResource.validate(props);
+
+ // --------------------
+ // Confirm result
+ // --------------------
+ // Confirm function call
+ verify(messageODataResource, times(1)).validateSentBoxBoundSchema(messageResource, false);
+ PowerMockito.verifyStatic(times(1));
+ MessageODataResource.validateUriCsv(SentMessage.P_TO.getName(), "http://personium/user001");
+ PowerMockito.verifyStatic(times(1));
+ MessageODataResource.validateBody("body", Common.MAX_MESSAGE_BODY_LENGTH);
+ PowerMockito.verifyStatic(times(1));
+ MessageODataResource.validateToAndToRelation("http://personium/user001", null);
+ PowerMockito.verifyStatic(times(1));
+ MessageODataResource.validateToValue("http://personium/user001", baseUri);
+ PowerMockito.verifyStatic(times(1));
+ MessageODataResource.validateReqRelation("message", null, null);
+ }
+
+ /**
+ * Test validateReceivedBoxBoundSchema().
+ * Schema is not empty.
+ */
+ @Test
+ public void validateReceivedBoxBoundSchema_Normal_schema_is_not_empty() {
+ // --------------------
+ // Test method args
+ // --------------------
+ MessageResource messageResource = PowerMockito.mock(MessageResource.class);
+ String schema = "http://personium/schema001";
+
+ // --------------------
+ // Mock settings
+ // --------------------
+ Box mockBox = new Box(null, null, null, null, 0L);
+ CellEsImpl mockCell = PowerMockito.mock(CellEsImpl.class);
+ doReturn(mockBox).when(mockCell).getBoxForSchema(schema);
+ AccessContext mockAccessContext = PowerMockito.mock(AccessContext.class);
+ doReturn(mockCell).when(mockAccessContext).getCell();
+ doReturn(mockAccessContext).when(messageResource).getAccessContext();
+
+ // --------------------
+ // Expected result
+ // --------------------
+ // Nothing.
+
+ // --------------------
+ // Run method
+ // --------------------
+ messageODataResource.validateReceivedBoxBoundSchema(messageResource, schema);
+
+ // --------------------
+ // Confirm result
+ // --------------------
+ // Confirm function call
+ verify(mockCell, times(1)).getBoxForSchema(schema);
+ }
+
+ /**
+ * Test validateReceivedBoxBoundSchema().
+ * Schema is empty.
+ */
+ @Test
+ public void validateReceivedBoxBoundSchema_Normal_schema_is_empty() {
+ // --------------------
+ // Test method args
+ // --------------------
+ MessageResource messageResource = PowerMockito.mock(MessageResource.class);
+ String schema = "";
+
+ // --------------------
+ // Mock settings
+ // --------------------
+ CellEsImpl mockCell = PowerMockito.mock(CellEsImpl.class);
+
+ // --------------------
+ // Expected result
+ // --------------------
+ // Nothing.
+
+ // --------------------
+ // Run method
+ // --------------------
+ messageODataResource.validateReceivedBoxBoundSchema(messageResource, schema);
+
+ // --------------------
+ // Confirm result
+ // --------------------
+ // Confirm function call
+ verify(mockCell, never()).getBoxForSchema(schema);
+ }
+
+ /**
+ * Test validateReceivedBoxBoundSchema().
+ * Error test.
+ * Box is null.
+ */
+ @Test
+ public void validateReceivedBoxBoundSchema_Error_box_is_null() {
+ // --------------------
+ // Test method args
+ // --------------------
+ MessageResource messageResource = PowerMockito.mock(MessageResource.class);
+ String schema = "http://personium/schema001";
+
+ // --------------------
+ // Mock settings
+ // --------------------
+ Box mockBox = null;
+ CellEsImpl mockCell = PowerMockito.mock(CellEsImpl.class);
+ doReturn(mockBox).when(mockCell).getBoxForSchema(schema);
+ AccessContext mockAccessContext = PowerMockito.mock(AccessContext.class);
+ doReturn(mockCell).when(mockAccessContext).getCell();
+ doReturn(mockAccessContext).when(messageResource).getAccessContext();
+
+ // --------------------
+ // Expected result
+ // --------------------
+ // Nothing.
+
+ // --------------------
+ // Run method
+ // --------------------
+ try {
+ messageODataResource.validateReceivedBoxBoundSchema(messageResource, schema);
+ fail("Not exception.");
+ } catch (PersoniumCoreException e) {
+ // --------------------
+ // Confirm result
+ // --------------------
+ PersoniumCoreException expected = PersoniumCoreException.ReceivedMessage
+ .BOX_THAT_MATCHES_SCHEMA_NOT_EXISTS.params(schema);
+ assertThat(e.getStatus(), is(expected.getStatus()));
+ assertThat(e.getCode(), is(expected.getCode()));
+ assertThat(e.getMessage(), is(expected.getMessage()));
+ }
+ }
+
+ /**
+ * Test validateSentBoxBoundSchema().
+ * boxboundFlag is true.
+ */
+ @Test
+ public void validateSentBoxBoundSchema_Normal_boxboundFlag_is_true() {
+ // --------------------
+ // Test method args
+ // --------------------
+ MessageResource messageResource = PowerMockito.mock(MessageResource.class);
+ boolean boxboundFlag = true;
+
+ // --------------------
+ // Mock settings
+ // --------------------
+ Box mockBox = new Box(null, null, null, null, 0L);
+ String schema = "http://personium/schema001";
+ CellEsImpl mockCell = PowerMockito.mock(CellEsImpl.class);
+ doReturn(mockBox).when(mockCell).getBoxForSchema(schema);
+ AccessContext mockAccessContext = PowerMockito.mock(AccessContext.class);
+ doReturn(schema).when(mockAccessContext).getSchema();
+ doReturn(mockCell).when(mockAccessContext).getCell();
+ doReturn(mockAccessContext).when(messageResource).getAccessContext();
+
+ // --------------------
+ // Expected result
+ // --------------------
+ // Nothing.
+
+ // --------------------
+ // Run method
+ // --------------------
+ messageODataResource.validateSentBoxBoundSchema(messageResource, boxboundFlag);
+
+ // --------------------
+ // Confirm result
+ // --------------------
+ // Confirm function call
+ verify(mockAccessContext, times(1)).getSchema();
+ verify(mockCell, times(1)).getBoxForSchema(schema);
+ }
+
+ /**
+ * Test validateSentBoxBoundSchema().
+ * boxboundFlag is false.
+ */
+ @Test
+ public void validateSentBoxBoundSchema_Normal_boxboundFlag_is_false() {
+ // --------------------
+ // Test method args
+ // --------------------
+ MessageResource messageResource = PowerMockito.mock(MessageResource.class);
+ boolean boxboundFlag = false;
+
+ // --------------------
+ // Mock settings
+ // --------------------
+ CellEsImpl mockCell = PowerMockito.mock(CellEsImpl.class);
+ AccessContext mockAccessContext = PowerMockito.mock(AccessContext.class);
+
+ // --------------------
+ // Expected result
+ // --------------------
+ // Nothing.
+
+ // --------------------
+ // Run method
+ // --------------------
+ messageODataResource.validateSentBoxBoundSchema(messageResource, boxboundFlag);
+
+ // --------------------
+ // Confirm result
+ // --------------------
+ // Confirm function call
+ verify(mockAccessContext, never()).getSchema();
+ verify(mockCell, never()).getBoxForSchema(anyString());
+ }
+
+ /**
+ * Test validateSentBoxBoundSchema().
+ * Error test.
+ * Box is null.
+ */
+ @Test
+ public void validateSentBoxBoundSchema_Error_box_is_null() {
+ // --------------------
+ // Test method args
+ // --------------------
+ MessageResource messageResource = PowerMockito.mock(MessageResource.class);
+ boolean boxboundFlag = true;
+
+ // --------------------
+ // Mock settings
+ // --------------------
+ Box mockBox = null;
+ String schema = "http://personium/schema001";
+ CellEsImpl mockCell = PowerMockito.mock(CellEsImpl.class);
+ doReturn(mockBox).when(mockCell).getBoxForSchema(schema);
+ AccessContext mockAccessContext = PowerMockito.mock(AccessContext.class);
+ doReturn(schema).when(mockAccessContext).getSchema();
+ doReturn(mockCell).when(mockAccessContext).getCell();
+ doReturn(mockAccessContext).when(messageResource).getAccessContext();
+
+ // --------------------
+ // Expected result
+ // --------------------
+ // Nothing.
+
+ // --------------------
+ // Run method
+ // --------------------
+ try {
+ messageODataResource.validateSentBoxBoundSchema(messageResource, boxboundFlag);
+ fail("Not exception.");
+ } catch (PersoniumCoreException e) {
+ // --------------------
+ // Confirm result
+ // --------------------
+ PersoniumCoreException expected = PersoniumCoreException.SentMessage
+ .BOX_THAT_MATCHES_SCHEMA_NOT_EXISTS.params(schema);
+ assertThat(e.getStatus(), is(expected.getStatus()));
+ assertThat(e.getCode(), is(expected.getCode()));
+ assertThat(e.getMessage(), is(expected.getMessage()));
+ }
+ }
+}
diff --git a/src/test/java/io/personium/core/rs/odata/AbstractODataResourceTest.java b/src/test/java/io/personium/core/rs/odata/AbstractODataResourceTest.java
index 2cdb5dbb8..65e0d67cb 100644
--- a/src/test/java/io/personium/core/rs/odata/AbstractODataResourceTest.java
+++ b/src/test/java/io/personium/core/rs/odata/AbstractODataResourceTest.java
@@ -16,117 +16,319 @@
*/
package io.personium.core.rs.odata;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import org.junit.Before;
+import org.junit.Test;
import org.junit.experimental.categories.Category;
-import org.junit.experimental.runners.Enclosed;
-import org.junit.experimental.theories.DataPoints;
-import org.junit.experimental.theories.Theories;
-import org.junit.experimental.theories.Theory;
import org.junit.runner.RunWith;
+import org.mockito.Mockito;
import org.odata4j.core.OProperties;
import org.odata4j.core.OProperty;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
import io.personium.core.PersoniumCoreException;
+import io.personium.core.model.ctl.Common;
+import io.personium.core.utils.ODataUtils;
import io.personium.test.categories.Unit;
/**
* AbstractODataResourceユニットテストクラス.
*/
-@RunWith(Enclosed.class)
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({AbstractODataResourceTest.class, ODataUtils.class})
@Category({Unit.class })
public class AbstractODataResourceTest {
+ /** Target class of unit test. */
+ private AbstractODataResource abstractODataResource;
+
/**
- * テスト用Fixture。
+ * Before.
*/
- static class Fixture {
- String testComment;
- /**
- * 入力値.
- */
- double inputValue;
- /**
- * 期待する返却値.
- */
- boolean expectedReturnValue;
-
- /**
- * コンストラクタ.
- * @param testComment テスト内容
- * @param inputValue バリデート対象の入力値
- * @param expectedReturnValue 期待する返却値
- */
- Fixture(String testComment,
- double inputValue,
- boolean expectedReturnValue) {
- this.testComment = testComment;
- this.inputValue = inputValue;
- this.expectedReturnValue = expectedReturnValue;
- }
+ @Before
+ public void befor() {
+ abstractODataResource = mock(AbstractODataResource.class, Mockito.CALLS_REAL_METHODS);
}
/**
* Double型の値の有効範囲チェックのテスト.
- * 有効範囲 ± 2.23e -308 から ± 1.79e +308
+ * @throws Exception Exception
*/
- @RunWith(Theories.class)
- public static class ValidateDoubleTest {
-
- /**
- * Double型の有効値チェックテストパターンを作成.
- * @return テストパターン
- */
- @DataPoints
- public static Fixture[] getFixture() {
- Fixture[] datas = {
- new Fixture("負の最小値(-1.79e308d)の場合に例外がスローされないこと", -1.79e308d, true),
- new Fixture("負の最大値(-2.23e-308d)の場合に例外がスローされないこと", -2.23e-308d, true),
- new Fixture("正の最小値(2.23e-308d)の場合に例外がスローされないこと", 2.23e-308d, true),
- new Fixture("正の最大値(1.79e308d)の場合に例外がスローされないこと", 1.79e308d, true),
- new Fixture("負の最小値より小さい値(-1.791e308d)の場合に例外コード[PR400-OD-0006]の例外がスローされること", -1.791e308d, false),
- new Fixture("負の最小値より大きい値(-1.789e308d)の場合に例外がスローされないこと", -1.789e308d, true),
- new Fixture("負の最大値より小さい値(-2.231e-308d)の場合に例外がスローされないこと", -2.231e-308d, true),
- new Fixture("負の最大値より大きい値(-2.229e-308d)の場合に例外コード[PR400-OD-0006]の例外がスローされること", -2.229e-308d, false),
- new Fixture("正の最小値より小さい値(2.229e-308d)の場合に例外コード[PR400-OD-0006]の例外がスローされること", 2.229e-308d, false),
- new Fixture("正の最小値より大きい値(2.231e-308d)の場合に例外がスローされないこと", 2.231e-308d, true),
- new Fixture("正の最大値より小さい値(1.789e308d)の場合に例外がスローされないこと", 1.789e308d, true),
- new Fixture("正の最大値より大きい値(1.791e308d)の場合に例外コード[PR400-OD-0006]の例外がスローされること", 1.791e308d, false),
- new Fixture("0の場合にtrueが返却されること", 0d, true)
- };
- return datas;
- }
+ @Test
+ public void Double型の値の有効範囲チェック() throws Exception {
+ checkValidateDynamicProperty("負の最小値(-1.79e308d)の場合に例外がスローされないこと", -1.79e308d, true);
+ checkValidateDynamicProperty("負の最大値(-2.23e-308d)の場合に例外がスローされないこと", -2.23e-308d, true);
+ checkValidateDynamicProperty("正の最小値(2.23e-308d)の場合に例外がスローされないこと", 2.23e-308d, true);
+ checkValidateDynamicProperty("正の最大値(1.79e308d)の場合に例外がスローされないこと", 1.79e308d, true);
+ checkValidateDynamicProperty(
+ "負の最小値より小さい値(-1.791e308d)の場合に例外コード[PR400-OD-0006]の例外がスローされること", -1.791e308d, false);
+ checkValidateDynamicProperty("負の最小値より大きい値(-1.789e308d)の場合に例外がスローされないこと", -1.789e308d, true);
+ checkValidateDynamicProperty("負の最大値より小さい値(-2.231e-308d)の場合に例外がスローされないこと", -2.231e-308d, true);
+ checkValidateDynamicProperty(
+ "負の最大値より大きい値(-2.229e-308d)の場合に例外コード[PR400-OD-0006]の例外がスローされること", -2.229e-308d, false);
+ checkValidateDynamicProperty(
+ "正の最小値より小さい値(2.229e-308d)の場合に例外コード[PR400-OD-0006]の例外がスローされること", 2.229e-308d, false);
+ checkValidateDynamicProperty("正の最小値より大きい値(2.231e-308d)の場合に例外がスローされないこと", 2.231e-308d, true);
+ checkValidateDynamicProperty("正の最大値より小さい値(1.789e308d)の場合に例外がスローされないこと", 1.789e308d, true);
+ checkValidateDynamicProperty("正の最大値より大きい値(1.791e308d)の場合に例外コード[PR400-OD-0006]の例外がスローされること", 1.791e308d, false);
+ checkValidateDynamicProperty("0の場合にtrueが返却されること", 0d, true);
+ }
- /**
- * Double型の値の有効範囲チェックのテスト.
- * @param f テストパターン
- * @throws Exception Exception
- */
- @Theory
- public void Double型の値の有効範囲チェック(Fixture f) throws Exception {
- ODataEntityResource resource = new ODataEntityResource();
- Method method = AbstractODataResource.class.getDeclaredMethod("validateDynamicProperty",
- new Class[] {OProperty.class});
- method.setAccessible(true);
- OProperty property = OProperties.double_("testKey", f.inputValue);
- boolean valildResult = true;
- try {
- method.invoke(resource, property);
- } catch (InvocationTargetException ex) {
- if (ex.getCause() instanceof PersoniumCoreException) {
- PersoniumCoreException e = (PersoniumCoreException) ex.getCause();
- if (PersoniumCoreException.OData.REQUEST_FIELD_FORMAT_ERROR.getCode().equals(e.getCode())) {
- valildResult = false;
- } else {
- fail(f.testComment + ": 期待したエラーコードではない. 例外コード:[" + e.getCode() + "]");
- }
+ /**
+ * Double型の値の有効範囲チェック.
+ * @param testComment テスト内容
+ * @param inputValue バリデート対象の入力値
+ * @param expectedReturnValue 期待する返却値
+ * @throws Exception Exception
+ */
+ private void checkValidateDynamicProperty(String testComment, double inputValue, boolean expectedReturnValue)
+ throws Exception {
+ ODataEntityResource resource = new ODataEntityResource();
+ Method method = AbstractODataResource.class.getDeclaredMethod("validateDynamicProperty",
+ new Class[] {OProperty.class});
+ method.setAccessible(true);
+ OProperty property = OProperties.double_("testKey", inputValue);
+ boolean valildResult = true;
+ try {
+ method.invoke(resource, property);
+ } catch (InvocationTargetException ex) {
+ if (ex.getCause() instanceof PersoniumCoreException) {
+ PersoniumCoreException e = (PersoniumCoreException) ex.getCause();
+ if (PersoniumCoreException.OData.REQUEST_FIELD_FORMAT_ERROR.getCode().equals(e.getCode())) {
+ valildResult = false;
+ } else {
+ fail(testComment + ": 期待したエラーコードではない. 例外コード:[" + e.getCode() + "]");
}
}
- assertEquals(f.testComment, f.expectedReturnValue, valildResult);
+ }
+ assertEquals(testComment, expectedReturnValue, valildResult);
+ }
+
+ /**
+ * Test validatePropertyRegEx().
+ * Normal test.
+ * isValidRegEx return true;
+ * @throws Exception Unexpected error.
+ */
+ @Test
+ public void validatePropertyRegEx_Normal_check_result_is_true() throws Exception {
+ // --------------------
+ // Test method args
+ // --------------------
+ String propName = "CellName";
+ OProperty> op = OProperties.string("CellName", "testCell");
+ String pFormat = Common.P_FORMAT_PATTERN_REGEX + "('" + Common.PATTERN_NAME + "')";
+
+ // --------------------
+ // Mock settings
+ // --------------------
+ PowerMockito.mockStatic(ODataUtils.class);
+ PowerMockito.doReturn(true).when(ODataUtils.class, "validateRegEx", "testCell", Common.PATTERN_NAME);
+
+ // --------------------
+ // Expected result
+ // --------------------
+ // Nothing.
+
+ // --------------------
+ // Run method
+ // --------------------
+ try {
+ abstractODataResource.validatePropertyRegEx(propName, op, pFormat);
+ } catch (PersoniumCoreException e) {
+ fail("Exception occurred.");
+ }
+
+ // --------------------
+ // Confirm result
+ // --------------------
+ // Nothing.
+ }
+
+ /**
+ * Test validatePropertyRegEx().
+ * Error test.
+ * isValidRegEx return false;
+ * @throws Exception Unexpected error.
+ */
+ @Test
+ public void validatePropertyRegEx_Error_check_result_is_false() throws Exception {
+ // --------------------
+ // Test method args
+ // --------------------
+ String propName = "CellName";
+ OProperty> op = OProperties.string("CellName", "_testCell");
+ String pFormat = Common.P_FORMAT_PATTERN_REGEX + "('" + Common.PATTERN_NAME + "')";
+
+ // --------------------
+ // Mock settings
+ // --------------------
+ PowerMockito.mockStatic(ODataUtils.class);
+ PowerMockito.doReturn(false).when(ODataUtils.class, "validateRegEx", "_testCell", Common.PATTERN_NAME);
+
+ // --------------------
+ // Expected result
+ // --------------------
+ // Nothing.
+
+ // --------------------
+ // Run method
+ // --------------------
+ try {
+ abstractODataResource.validatePropertyRegEx(propName, op, pFormat);
+ fail("Not Exception.");
+ } catch (PersoniumCoreException e) {
+ // --------------------
+ // Confirm result
+ // --------------------
+ PersoniumCoreException expected = PersoniumCoreException.OData.REQUEST_FIELD_FORMAT_ERROR.params(propName);
+ assertThat(e.getStatus(), is(expected.getStatus()));
+ assertThat(e.getCode(), is(expected.getCode()));
+ assertThat(e.getMessage(), is(expected.getMessage()));
+ }
+ }
+
+ /**
+ * Test validatePropertyMessageRequestRelation().
+ * Normal test.
+ * isValidClassUrl return true;
+ * @throws Exception Unexpected error.
+ */
+ @Test
+ public void validatePropertyMessageRequestRelation_Normal_relation_is_classURL() throws Exception {
+ String requestRelation = "http://personium/dummyAppCell/__relation/__/dummyRelation";
+ // --------------------
+ // Test method args
+ // --------------------
+ String propName = "RequestRelation";
+ OProperty> op = OProperties.string("RequestRelation", requestRelation);
+
+ // --------------------
+ // Mock settings
+ // --------------------
+ PowerMockito.mockStatic(ODataUtils.class);
+ PowerMockito.doReturn(true).when(ODataUtils.class, "validateClassUrl",
+ requestRelation, Common.PATTERN_RELATION_CLASS_URL);
+ PowerMockito.doReturn(false).when(ODataUtils.class, "validateRegEx",
+ requestRelation, Common.PATTERN_RELATION_NAME);
+
+ // --------------------
+ // Expected result
+ // --------------------
+ // Nothing.
+
+ // --------------------
+ // Run method
+ // --------------------
+ try {
+ abstractODataResource.validatePropertyMessageRequestRelation(propName, op);
+ } catch (PersoniumCoreException e) {
+ fail("Exception occurred.");
+ }
+
+ // --------------------
+ // Confirm result
+ // --------------------
+ // Nothing.
+ }
+
+ /**
+ * Test validatePropertyMessageRequestRelation().
+ * Normal test.
+ * isValidRegEx return true;
+ * @throws Exception Unexpected error.
+ */
+ @Test
+ public void validatePropertyMessageRequestRelation_Normal_relation_is_name() throws Exception {
+ String requestRelation = "dummyRelation";
+ // --------------------
+ // Test method args
+ // --------------------
+ String propName = "RequestRelation";
+ OProperty> op = OProperties.string("RequestRelation", requestRelation);
+
+ // --------------------
+ // Mock settings
+ // --------------------
+ PowerMockito.mockStatic(ODataUtils.class);
+ PowerMockito.doReturn(false).when(ODataUtils.class, "validateClassUrl",
+ requestRelation, Common.PATTERN_RELATION_CLASS_URL);
+ PowerMockito.doReturn(true).when(ODataUtils.class, "validateRegEx",
+ requestRelation, Common.PATTERN_RELATION_NAME);
+
+ // --------------------
+ // Expected result
+ // --------------------
+ // Nothing.
+
+ // --------------------
+ // Run method
+ // --------------------
+ try {
+ abstractODataResource.validatePropertyMessageRequestRelation(propName, op);
+ } catch (PersoniumCoreException e) {
+ fail("Exception occurred.");
+ }
+
+ // --------------------
+ // Confirm result
+ // --------------------
+ // Nothing.
+ }
+
+ /**
+ * Test validatePropertyMessageRequestRelation().
+ * Error test.
+ * isValidClassUrl and isValidRegEx return false;
+ * @throws Exception Unexpected error.
+ */
+ @Test
+ public void validatePropertyMessageRequestRelation_Error_relation_is_unexpected_format() throws Exception {
+ String requestRelation = "*/dummyRelation";
+ // --------------------
+ // Test method args
+ // --------------------
+ String propName = "RequestRelation";
+ OProperty> op = OProperties.string("RequestRelation", requestRelation);
+
+ // --------------------
+ // Mock settings
+ // --------------------
+ PowerMockito.mockStatic(ODataUtils.class);
+ PowerMockito.doReturn(false).when(ODataUtils.class, "validateClassUrl",
+ requestRelation, Common.PATTERN_RELATION_CLASS_URL);
+ PowerMockito.doReturn(false).when(ODataUtils.class, "validateRegEx",
+ requestRelation, Common.PATTERN_RELATION_NAME);
+
+ // --------------------
+ // Expected result
+ // --------------------
+ // Nothing.
+
+ // --------------------
+ // Run method
+ // --------------------
+ try {
+ abstractODataResource.validatePropertyMessageRequestRelation(propName, op);
+ fail("Exception occurred.");
+ } catch (PersoniumCoreException e) {
+ // --------------------
+ // Confirm result
+ // --------------------
+ PersoniumCoreException expected = PersoniumCoreException.OData.REQUEST_FIELD_FORMAT_ERROR.params(propName);
+ assertThat(e.getStatus(), is(expected.getStatus()));
+ assertThat(e.getCode(), is(expected.getCode()));
+ assertThat(e.getMessage(), is(expected.getMessage()));
}
}
}
diff --git a/src/test/java/io/personium/core/utils/ODataUtilsTest.java b/src/test/java/io/personium/core/utils/ODataUtilsTest.java
index 873b47138..4dba84444 100644
--- a/src/test/java/io/personium/core/utils/ODataUtilsTest.java
+++ b/src/test/java/io/personium/core/utils/ODataUtilsTest.java
@@ -16,181 +16,220 @@
*/
package io.personium.core.utils;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
+import org.junit.Test;
import org.junit.experimental.categories.Category;
-import org.junit.experimental.runners.Enclosed;
-import org.junit.experimental.theories.DataPoints;
-import org.junit.experimental.theories.Theories;
-import org.junit.experimental.theories.Theory;
-import org.junit.runner.RunWith;
+import io.personium.core.model.ctl.Common;
import io.personium.test.categories.Unit;
/**
* ODataUtilsユニットテストクラス.
*/
-@RunWith(Enclosed.class)
@Category({Unit.class })
public class ODataUtilsTest {
/**
- * テスト用Fixture。
+ * 入力値をDouble型とした値の有効範囲チェックのテスト.
+ * 有効範囲 ± 2.23e -308 から ± 1.79e +308
+ * @throws Exception Exception
*/
- static class FixtureForDouble {
- String testComment;
- /**
- * Double型の入力値.
- */
- double inputDoubleValue;
- /**
- * String型の入力値.
- */
- String inputStringValue;
- /**
- * 期待する返却値.
- */
- boolean expectedReturnValue;
-
- /**
- * コンストラクタ.
- * @param testComment テスト内容
- * @param inputValue バリデート対象の入力値
- * @param expectedReturnValue 期待する返却値
- */
- FixtureForDouble(String testComment,
- double inputValue,
- boolean expectedReturnValue) {
- this.testComment = testComment;
- this.inputDoubleValue = inputValue;
- this.expectedReturnValue = expectedReturnValue;
- }
-
- /**
- * コンストラクタ.
- * @param testComment テスト内容
- * @param inputValue バリデート対象の入力値
- * @param expectedReturnValue 期待する返却値
- */
- FixtureForDouble(String testComment,
- String inputValue,
- boolean expectedReturnValue) {
- this.testComment = testComment;
- this.inputStringValue = inputValue;
- this.expectedReturnValue = expectedReturnValue;
- }
+ @Test
+ public void 入力値をDouble型とした値の有効範囲チェック() throws Exception {
+ checkValidateDouble("負の最小値(-1.79e308d)の場合にtrueが返却されること", -1.79e308d, true);
+ checkValidateDouble("負の最大値(-2.23e-308d)の場合にtrueが返却されること", -2.23e-308d, true);
+ checkValidateDouble("正の最小値(2.23e-308d)の場合にtrueが返却されること", 2.23e-308d, true);
+ checkValidateDouble("正の最大値(1.79e308d)の場合にtrueが返却されること", 1.79e308d, true);
+ checkValidateDouble("負の最小値より小さい値(-1.791e308d)の場合にfalseが返却されること", -1.791e308d, false);
+ checkValidateDouble("負の最小値より大きい値(-1.789e308d)の場合にtrueが返却されること", -1.789e308d, true);
+ checkValidateDouble("負の最大値より小さい値(-2.231e-308d)の場合にtrueが返却されること", -2.231e-308d, true);
+ checkValidateDouble("負の最大値より大きい値(-2.229e-308d)の場合にfalseが返却されること", -2.229e-308d, false);
+ checkValidateDouble("正の最小値より小さい値(2.229e-308d)の場合にfalseが返却されること", 2.229e-308d, false);
+ checkValidateDouble("正の最小値より大きい値(2.231e-308d)の場合にtrueが返却されること", 2.231e-308d, true);
+ checkValidateDouble("正の最大値より小さい値(1.789e308d)の場合にtrueが返却されること", 1.789e308d, true);
+ checkValidateDouble("正の最大値より大きい値(1.791e308d)の場合にfalseが返却されること", 1.791e308d, false);
+ checkValidateDouble("0dの場合にtrueが返却されること", 0d, true);
}
/**
- * 入力値をDouble型とした値の有効範囲チェックのテスト.
+ * 入力値を文字列としたDouble型の値の有効範囲チェックのテスト.
* 有効範囲 ± 2.23e -308 から ± 1.79e +308
+ * @throws Exception Exception
*/
- @RunWith(Theories.class)
- public static class ValidateDoubleInputDoubleTest {
-
- /**
- * Double型の有効値チェックテストパターンを作成.
- * @return テストパターン
- */
- @DataPoints
- public static FixtureForDouble[] getFixture() {
- FixtureForDouble[] datas = {
- new FixtureForDouble("負の最小値(-1.79e308d)の場合にtrueが返却されること", -1.79e308d, true),
- new FixtureForDouble("負の最大値(-2.23e-308d)の場合にtrueが返却されること", -2.23e-308d, true),
- new FixtureForDouble("正の最小値(2.23e-308d)の場合にtrueが返却されること", 2.23e-308d, true),
- new FixtureForDouble("正の最大値(1.79e308d)の場合にtrueが返却されること", 1.79e308d, true),
- new FixtureForDouble("負の最小値より小さい値(-1.791e308d)の場合にfalseが返却されること", -1.791e308d, false),
- new FixtureForDouble("負の最小値より大きい値(-1.789e308d)の場合にtrueが返却されること", -1.789e308d, true),
- new FixtureForDouble("負の最大値より小さい値(-2.231e-308d)の場合にtrueが返却されること", -2.231e-308d, true),
- new FixtureForDouble("負の最大値より大きい値(-2.229e-308d)の場合にfalseが返却されること", -2.229e-308d, false),
- new FixtureForDouble("正の最小値より小さい値(2.229e-308d)の場合にfalseが返却されること", 2.229e-308d, false),
- new FixtureForDouble("正の最小値より大きい値(2.231e-308d)の場合にtrueが返却されること", 2.231e-308d, true),
- new FixtureForDouble("正の最大値より小さい値(1.789e308d)の場合にtrueが返却されること", 1.789e308d, true),
- new FixtureForDouble("正の最大値より大きい値(1.791e308d)の場合にfalseが返却されること", 1.791e308d, false),
- new FixtureForDouble("0dの場合にtrueが返却されること", 0d, true),
- };
- return datas;
- }
+ @Test
+ public void 入力値を文字列としたDouble型の値の有効範囲チェック() throws Exception {
+ checkValidateDouble("文字列形式で負の最小値(-1.79e308)の場合にtrueが返却されること", "-1.79e308", true);
+ checkValidateDouble("文字列形式で負の最大値(-2.23e-308)の場合にtrueが返却されること", "-2.23e-308", true);
+ checkValidateDouble("文字列形式で正の最小値(2.23e-308)の場合にtrueが返却されること", "2.23e-308", true);
+ checkValidateDouble("文字列形式で正の最大値(1.79e308)の場合にtrueが返却されること", "1.79e308", true);
+ checkValidateDouble("文字列形式で負の最小値より小さい値(-1.791e308)の場合にfalseが返却されること", "-1.791e308", false);
+ checkValidateDouble("文字列形式で負の最小値より大きい値(-1.789e308)の場合にtrueが返却されること", "-1.789e308", true);
+ checkValidateDouble("文字列形式で負の最大値より小さい値(-2.231e-308)の場合にtrueが返却されること", "-2.231e-308", true);
+ checkValidateDouble("文字列形式で負の最大値より大きい値(-2.229e-308)の場合にfalseが返却されること", "-2.229e-308", false);
+ checkValidateDouble("文字列形式で正の最小値より小さい値(2.229e-308)の場合にfalseが返却されること", "2.229e-308", false);
+ checkValidateDouble("文字列形式で正の最小値より大きい値(2.231e-308)の場合にtrueが返却されること", "2.231e-308", true);
+ checkValidateDouble("文字列形式で正の最大値より小さい値(1.789e308)の場合にtrueが返却されること", "1.789e308", true);
+ checkValidateDouble("文字列形式で正の最大値より大きい値(1.791e308)の場合にfalseが返却されること", "1.791e308", false);
+ checkValidateDouble("文字列形式で0の場合にtrueが返却されること", "0", true);
+ checkValidateDouble("文字列形式で負の最小値(-1.79e308d)の場合にtrueが返却されること", "-1.79e308d", true);
+ checkValidateDouble("文字列形式で負の最大値(-2.23e-308d)の場合にtrueが返却されること", "-2.23e-308d", true);
+ checkValidateDouble("文字列形式で正の最小値(2.23e-308d)の場合にtrueが返却されること", "2.23e-308d", true);
+ checkValidateDouble("文字列形式で正の最大値(1.79e308d)の場合にtrueが返却されること", "1.79e308d", true);
+ checkValidateDouble("文字列形式で負の最小値より小さい値(-1.791e308d)の場合にfalseが返却されること", "-1.791e308d", false);
+ checkValidateDouble("文字列形式で負の最小値より大きい値(-1.789e308d)の場合にtrueが返却されること", "-1.789e308d", true);
+ checkValidateDouble("文字列形式で負の最大値より小さい値(-2.231e-308d)の場合にtrueが返却されること", "-2.231e-308d", true);
+ checkValidateDouble("文字列形式で負の最大値より大きい値(-2.229e-308d)の場合にfalseが返却されること", "-2.229e-308d", false);
+ checkValidateDouble("文字列形式で正の最小値より小さい値(2.229e-308d)の場合にfalseが返却されること", "2.229e-308d", false);
+ checkValidateDouble("文字列形式で正の最小値より大きい値(2.231e-308d)の場合にtrueが返却されること", "2.231e-308d", true);
+ checkValidateDouble("文字列形式で正の最大値より小さい値(1.789e308d)の場合にtrueが返却されること", "1.789e308d", true);
+ checkValidateDouble("文字列形式で正の最大値より大きい値(1.791e308d)の場合にfalseが返却されること", "1.791e308d", false);
+ checkValidateDouble("文字列形式で0dの場合にtrueが返却されること", "0d", true);
+ checkValidateDouble("文字列形式で負の最小値(-1.79e308D)の場合にtrueが返却されること", "-1.79e308D", true);
+ checkValidateDouble("文字列形式で負の最大値(-2.23e-308D)の場合にtrueが返却されること", "-2.23e-308D", true);
+ checkValidateDouble("文字列形式で正の最小値(2.23e-308D)の場合にtrueが返却されること", "2.23e-308D", true);
+ checkValidateDouble("文字列形式で正の最大値(1.79e308D)の場合にtrueが返却されること", "1.79e308D", true);
+ checkValidateDouble("文字列形式で負の最小値より小さい値(-1.791e308D)の場合にfalseが返却されること", "-1.791e308D", false);
+ checkValidateDouble("文字列形式で負の最小値より大きい値(-1.789e308D)の場合にtrueが返却されること", "-1.789e308D", true);
+ checkValidateDouble("文字列形式で負の最大値より小さい値(-2.231e-308D)の場合にtrueが返却されること", "-2.231e-308D", true);
+ checkValidateDouble("文字列形式で負の最大値より大きい値(-2.229e-308D)の場合にfalseが返却されること", "-2.229e-308D", false);
+ checkValidateDouble("文字列形式で正の最小値より小さい値(2.229e-308D)の場合にfalseが返却されること", "2.229e-308D", false);
+ checkValidateDouble("文字列形式で正の最小値より大きい値(2.231e-308D)の場合にtrueが返却されること", "2.231e-308D", true);
+ checkValidateDouble("文字列形式で正の最大値より小さい値(1.789e308D)の場合にtrueが返却されること", "1.789e308D", true);
+ checkValidateDouble("文字列形式で正の最大値より大きい値(1.791e308D)の場合にfalseが返却されること", "1.791e308D", false);
+ checkValidateDouble("文字列形式で0Dの場合にtrueが返却されること", "0D", true);
+ checkValidateDouble("文字列の場合にfalseが返却されること", "parseError", false);
+ }
- /**
- * Double型の値の有効範囲チェックのテスト.
- * @param f テストパターン
- * @throws Exception Exception
- */
- @Theory
- public void Double型の値の有効範囲チェック(FixtureForDouble f) throws Exception {
- boolean result = ODataUtils.validateDouble(f.inputDoubleValue);
- assertEquals(f.testComment, f.expectedReturnValue, result);
- }
+ /**
+ * Double型の値の有効範囲チェックのテスト.
+ * @param testComment テスト内容
+ * @param inputDoubleValue バリデート対象の入力値
+ * @param expectedReturnValue 期待する返却値
+ * @throws Exception Exception
+ */
+ public void checkValidateDouble(String testComment,
+ double inputDoubleValue,
+ boolean expectedReturnValue) throws Exception {
+ boolean result = ODataUtils.validateDouble(inputDoubleValue);
+ assertEquals(testComment, expectedReturnValue, result);
}
/**
- * 入力値を文字列としたDouble型の値の有効範囲チェックのテスト.
- * 有効範囲 ± 2.23e -308 から ± 1.79e +308
+ * Double型の値の有効範囲チェックのテスト.
+ * @param testComment テスト内容
+ * @param inputStringValue バリデート対象の入力値
+ * @param expectedReturnValue 期待する返却値
+ * @throws Exception Exception
*/
- @RunWith(Theories.class)
- public static class ValidateDoubleInputStringTest {
-
- /**
- * Double型の有効値チェックテストパターンを作成.
- * @return テストパターン
- */
- @DataPoints
- public static FixtureForDouble[] getFixture() {
- FixtureForDouble[] datas = {
- new FixtureForDouble("文字列形式で負の最小値(-1.79e308)の場合にtrueが返却されること", "-1.79e308", true),
- new FixtureForDouble("文字列形式で負の最大値(-2.23e-308)の場合にtrueが返却されること", "-2.23e-308", true),
- new FixtureForDouble("文字列形式で正の最小値(2.23e-308)の場合にtrueが返却されること", "2.23e-308", true),
- new FixtureForDouble("文字列形式で正の最大値(1.79e308)の場合にtrueが返却されること", "1.79e308", true),
- new FixtureForDouble("文字列形式で負の最小値より小さい値(-1.791e308)の場合にfalseが返却されること", "-1.791e308", false),
- new FixtureForDouble("文字列形式で負の最小値より大きい値(-1.789e308)の場合にtrueが返却されること", "-1.789e308", true),
- new FixtureForDouble("文字列形式で負の最大値より小さい値(-2.231e-308)の場合にtrueが返却されること", "-2.231e-308", true),
- new FixtureForDouble("文字列形式で負の最大値より大きい値(-2.229e-308)の場合にfalseが返却されること", "-2.229e-308", false),
- new FixtureForDouble("文字列形式で正の最小値より小さい値(2.229e-308)の場合にfalseが返却されること", "2.229e-308", false),
- new FixtureForDouble("文字列形式で正の最小値より大きい値(2.231e-308)の場合にtrueが返却されること", "2.231e-308", true),
- new FixtureForDouble("文字列形式で正の最大値より小さい値(1.789e308)の場合にtrueが返却されること", "1.789e308", true),
- new FixtureForDouble("文字列形式で正の最大値より大きい値(1.791e308)の場合にfalseが返却されること", "1.791e308", false),
- new FixtureForDouble("文字列形式で0の場合にtrueが返却されること", "0", true),
- new FixtureForDouble("文字列形式で負の最小値(-1.79e308d)の場合にtrueが返却されること", "-1.79e308d", true),
- new FixtureForDouble("文字列形式で負の最大値(-2.23e-308d)の場合にtrueが返却されること", "-2.23e-308d", true),
- new FixtureForDouble("文字列形式で正の最小値(2.23e-308d)の場合にtrueが返却されること", "2.23e-308d", true),
- new FixtureForDouble("文字列形式で正の最大値(1.79e308d)の場合にtrueが返却されること", "1.79e308d", true),
- new FixtureForDouble("文字列形式で負の最小値より小さい値(-1.791e308d)の場合にfalseが返却されること", "-1.791e308d", false),
- new FixtureForDouble("文字列形式で負の最小値より大きい値(-1.789e308d)の場合にtrueが返却されること", "-1.789e308d", true),
- new FixtureForDouble("文字列形式で負の最大値より小さい値(-2.231e-308d)の場合にtrueが返却されること", "-2.231e-308d", true),
- new FixtureForDouble("文字列形式で負の最大値より大きい値(-2.229e-308d)の場合にfalseが返却されること", "-2.229e-308d", false),
- new FixtureForDouble("文字列形式で正の最小値より小さい値(2.229e-308d)の場合にfalseが返却されること", "2.229e-308d", false),
- new FixtureForDouble("文字列形式で正の最小値より大きい値(2.231e-308d)の場合にtrueが返却されること", "2.231e-308d", true),
- new FixtureForDouble("文字列形式で正の最大値より小さい値(1.789e308d)の場合にtrueが返却されること", "1.789e308d", true),
- new FixtureForDouble("文字列形式で正の最大値より大きい値(1.791e308d)の場合にfalseが返却されること", "1.791e308d", false),
- new FixtureForDouble("文字列形式で0dの場合にtrueが返却されること", "0d", true),
- new FixtureForDouble("文字列形式で負の最小値(-1.79e308D)の場合にtrueが返却されること", "-1.79e308D", true),
- new FixtureForDouble("文字列形式で負の最大値(-2.23e-308D)の場合にtrueが返却されること", "-2.23e-308D", true),
- new FixtureForDouble("文字列形式で正の最小値(2.23e-308D)の場合にtrueが返却されること", "2.23e-308D", true),
- new FixtureForDouble("文字列形式で正の最大値(1.79e308D)の場合にtrueが返却されること", "1.79e308D", true),
- new FixtureForDouble("文字列形式で負の最小値より小さい値(-1.791e308D)の場合にfalseが返却されること", "-1.791e308D", false),
- new FixtureForDouble("文字列形式で負の最小値より大きい値(-1.789e308D)の場合にtrueが返却されること", "-1.789e308D", true),
- new FixtureForDouble("文字列形式で負の最大値より小さい値(-2.231e-308D)の場合にtrueが返却されること", "-2.231e-308D", true),
- new FixtureForDouble("文字列形式で負の最大値より大きい値(-2.229e-308D)の場合にfalseが返却されること", "-2.229e-308D", false),
- new FixtureForDouble("文字列形式で正の最小値より小さい値(2.229e-308D)の場合にfalseが返却されること", "2.229e-308D", false),
- new FixtureForDouble("文字列形式で正の最小値より大きい値(2.231e-308D)の場合にtrueが返却されること", "2.231e-308D", true),
- new FixtureForDouble("文字列形式で正の最大値より小さい値(1.789e308D)の場合にtrueが返却されること", "1.789e308D", true),
- new FixtureForDouble("文字列形式で正の最大値より大きい値(1.791e308D)の場合にfalseが返却されること", "1.791e308D", false),
- new FixtureForDouble("文字列形式で0Dの場合にtrueが返却されること", "0D", true),
- new FixtureForDouble("文字列の場合にfalseが返却されること", "parseError", false)
- };
- return datas;
- }
+ public void checkValidateDouble(String testComment,
+ String inputStringValue,
+ boolean expectedReturnValue) throws Exception {
+ boolean result = ODataUtils.validateDouble(inputStringValue);
+ assertEquals(testComment, expectedReturnValue, result);
+ }
+
+ /**
+ * Test validateRegEx().
+ * Normal test.
+ * Format match.
+ */
+ @Test
+ public void validateRegEx_Normal_match() {
+ String str = "123test-_";
+ String pFormat = Common.PATTERN_NAME;
+ assertThat(ODataUtils.validateRegEx(str, pFormat), is(true));
+ }
+
+ /**
+ * Test validateRegEx().
+ * Normal test.
+ * Format not match.
+ */
+ @Test
+ public void validateRegEx_Normal_not_match() {
+ String str = "-_123test";
+ String pFormat = Common.PATTERN_NAME;
+ assertThat(ODataUtils.validateRegEx(str, pFormat), is(false));
+ }
- /**
- * Double型の値の有効範囲チェックのテスト.
- * @param f テストパターン
- * @throws Exception Exception
- */
- @Theory
- public void Double型の値の有効範囲チェック(FixtureForDouble f) throws Exception {
- boolean result = ODataUtils.validateDouble(f.inputStringValue);
- assertEquals(f.testComment, f.expectedReturnValue, result);
+ /**
+ * Test validateClassUrl().
+ * Normal test.
+ * Scheme is null.
+ */
+ @Test
+ public void validateClassUrl_Normal_scheme_is_null() {
+ String str = "./dummyBox/dummyRelation";
+ String pFormat = Common.PATTERN_RELATION_CLASS_URL;
+ assertThat(ODataUtils.validateClassUrl(str, pFormat), is(false));
+ }
+
+ /**
+ * Test validateClassUrl().
+ * Normal test.
+ * Scheme is not allowed format.
+ */
+ @Test
+ public void validateClassUrl_Normal_scheme_is_not_allowed_format() {
+ String str = "file://dummyFile";
+ String pFormat = Common.PATTERN_RELATION_CLASS_URL;
+ assertThat(ODataUtils.validateClassUrl(str, pFormat), is(false));
+ }
+
+ /**
+ * Test validateClassUrl().
+ * Normal test.
+ * String length exceeded max.
+ */
+ @Test
+ public void validateClassUrl_Normal_str_length_exceeded_max() {
+ StringBuilder builder = new StringBuilder("http://");
+ int schemeLength = builder.length();
+ for (int i = 0; i < (ODataUtils.URI_MAX_LENGTH + 1 - schemeLength); i++) {
+ builder.append("a");
}
+ String str = new String(builder);
+ String pFormat = Common.PATTERN_RELATION_CLASS_URL;
+ assertThat(ODataUtils.validateClassUrl(str, pFormat), is(false));
}
+
+ /**
+ * Test validateClassUrl().
+ * Normal test.
+ * Not in URI format.
+ */
+ @Test
+ public void validateClassUrl_Normal_not_in_uri_format() {
+ String str = "\\ %";
+ String pFormat = Common.PATTERN_RELATION_CLASS_URL;
+ assertThat(ODataUtils.validateClassUrl(str, pFormat), is(false));
+ }
+
+ /**
+ * Test validateClassUrl().
+ * Normal test.
+ * Not match regular expression.
+ */
+ @Test
+ public void validateClassUrl_Normal_not_match_regular_expression() {
+ String str = "http://personium/dummyCell/__relation/dummyBox/dummyRelation";
+ String pFormat = Common.PATTERN_RELATION_CLASS_URL;
+ assertThat(ODataUtils.validateClassUrl(str, pFormat), is(false));
+ }
+
+ /**
+ * Test validateClassUrl().
+ * Normal test.
+ * Match regular expression.
+ */
+ @Test
+ public void validateClassUrl_Normal_match_regular_expression() {
+ String str = "http://personium/appCell/__relation/__/dummyRelation";
+ String pFormat = Common.PATTERN_RELATION_CLASS_URL;
+ assertThat(ODataUtils.validateClassUrl(str, pFormat), is(true));
+ }
+
}
diff --git a/src/test/java/io/personium/test/jersey/CrossDomainTest.java b/src/test/java/io/personium/test/jersey/CrossDomainTest.java
index e8c4cd9ce..ef1df4bc7 100644
--- a/src/test/java/io/personium/test/jersey/CrossDomainTest.java
+++ b/src/test/java/io/personium/test/jersey/CrossDomainTest.java
@@ -28,6 +28,9 @@
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
+import com.sun.jersey.test.framework.JerseyTest;
+import com.sun.jersey.test.framework.WebAppDescriptor;
+
import io.personium.common.utils.PersoniumCoreUtils.HttpHeaders;
import io.personium.core.PersoniumUnitConfig;
import io.personium.core.model.ctl.ReceivedMessage;
@@ -38,8 +41,6 @@
import io.personium.test.utils.EntityTypeUtils;
import io.personium.test.utils.Http;
import io.personium.test.utils.TResponse;
-import com.sun.jersey.test.framework.JerseyTest;
-import com.sun.jersey.test.framework.WebAppDescriptor;
/**
* 認証のテスト.
@@ -224,7 +225,7 @@ public CrossDomainTest() {
public final void 認証にOPTIONSを指定してXHR2ヘッダーが返却されること() {
TResponse response =
Http.request("crossdomain/xhr2-preflight.txt")
- .with("path", "/testcell1/__auth")
+ .with("path", "/testcell1/__token")
.with("token", PersoniumUnitConfig.getMasterToken())
.returns()
.statusCode(HttpStatus.SC_OK)
@@ -239,7 +240,7 @@ public CrossDomainTest() {
public final void 認証にGETを指定してXHR2ヘッダーのALLOW_ORIGINのみ返却されること() {
TResponse response =
Http.request("crossdomain/xhr2-preflight-no-access-control-allow-headers.txt")
- .with("path", "/testcell1/__auth")
+ .with("path", "/testcell1/__token")
.with("token", PersoniumUnitConfig.getMasterToken())
.returns()
.statusCode(HttpStatus.SC_METHOD_NOT_ALLOWED)
diff --git a/src/test/java/io/personium/test/jersey/cell/AclTest.java b/src/test/java/io/personium/test/jersey/cell/AclTest.java
index 482bc6f0c..1fab67ce0 100644
--- a/src/test/java/io/personium/test/jersey/cell/AclTest.java
+++ b/src/test/java/io/personium/test/jersey/cell/AclTest.java
@@ -1774,7 +1774,7 @@ protected String getReceivedMessageBody(final String type, final String id) {
body.put("Body", "Body");
body.put("Priority", 3);
body.put("Status", status);
- body.put("RequestRelation", "https://fqdn/appcell/__relation/__/user");
+ body.put("RequestRelation", "user");
body.put("RequestRelationTarget", UrlUtils.cellRoot("targetCell"));
return body.toJSONString();
}
diff --git a/src/test/java/io/personium/test/jersey/cell/MessageApproveTest.java b/src/test/java/io/personium/test/jersey/cell/MessageApproveTest.java
index 0bdf80800..aefe2eb3c 100644
--- a/src/test/java/io/personium/test/jersey/cell/MessageApproveTest.java
+++ b/src/test/java/io/personium/test/jersey/cell/MessageApproveTest.java
@@ -47,6 +47,7 @@
import io.personium.test.jersey.PersoniumRestAdapter;
import io.personium.test.setup.Setup;
import io.personium.test.unit.core.UrlUtils;
+import io.personium.test.utils.BoxUtils;
import io.personium.test.utils.ExtCellUtils;
import io.personium.test.utils.Http;
import io.personium.test.utils.ReceivedMessageUtils;
@@ -302,7 +303,7 @@ public MessageApproveTest() {
body.put("InReplyTo", "d3330643f57a42fd854558fb0a96a96a");
body.put("Priority", 3);
body.put("Status", "none");
- body.put("RequestRelation", UrlUtils.cellRoot(Setup.TEST_CELL1) + "__relation/__/" + relationName);
+ body.put("RequestRelation", relationName);
body.put("RequestRelationTarget", UrlUtils.cellRoot("targetCell"));
String locationHeader = null;
@@ -382,7 +383,7 @@ public MessageApproveTest() {
body.put("InReplyTo", "d3330643f57a42fd854558fb0a96a96a");
body.put("Priority", 3);
body.put("Status", "none");
- body.put("RequestRelation", UrlUtils.cellRoot(Setup.TEST_CELL1) + "__relation/__/" + relationName);
+ body.put("RequestRelation", relationName);
body.put("RequestRelationTarget", UrlUtils.cellRoot("targetCell"));
String locationHeader = null;
@@ -439,21 +440,590 @@ public MessageApproveTest() {
}
}
+ /**
+ * Normal test.
+ * Approve build message with RelationClassURL for already existing relation.
+ */
+ @SuppressWarnings("unchecked")
+ @Test
+ public final void normal_approve_build_message_with_relationClassURL_for_allready_exist_relation() {
+ String relationName = "messageTestRelation";
+ String boxName = Setup.TEST_BOX1;
+
+ // Request body of relation
+ JSONObject relationBody = new JSONObject();
+ relationBody.put(Relation.P_NAME.getName(), relationName);
+ relationBody.put(Common.P_BOX_NAME.getName(), boxName);
+
+ // Request body of message
+ JSONObject body = new JSONObject();
+ body.put("__id", "12345678901234567890123456789012");
+ body.put("From", UrlUtils.cellRoot(Setup.TEST_CELL2));
+ body.put("Type", "req.relation.build");
+ body.put("Title", "Title");
+ body.put("Body", "Body");
+ body.put("InReplyTo", "d3330643f57a42fd854558fb0a96a96a");
+ body.put("Priority", 3);
+ body.put("Status", "none");
+ body.put("RequestRelation", UrlUtils.relationClassUrl(Setup.TEST_CELL_SCHEMA1, relationName));
+ body.put("RequestRelationTarget", UrlUtils.cellRoot("targetCell"));
+
+ TResponse response = null;
+ try {
+ // ---------------
+ // Preparation
+ // ---------------
+ // Relation
+ RelationUtils.create(Setup.TEST_CELL1, MASTER_TOKEN_NAME, relationBody, HttpStatus.SC_CREATED);
+ // ExtCell
+ ExtCellUtils.create(MASTER_TOKEN_NAME, Setup.TEST_CELL1, UrlUtils.cellRoot("targetCell"),
+ HttpStatus.SC_CREATED);
+ // ReceivedMessage
+ String requestUrl = UrlUtils.cellRoot(Setup.TEST_CELL1);
+ response = ReceivedMessageUtils.receive(getCellIssueToken(requestUrl), Setup.TEST_CELL1,
+ body.toJSONString(), HttpStatus.SC_CREATED);
+ String messageId = (String) body.get("__id");
+
+ // ---------------
+ // Execution
+ // ---------------
+ // execute approved message
+ PersoniumRestAdapter rest = new PersoniumRestAdapter();
+ HashMap requestheaders = new HashMap();
+ requestheaders.put(HttpHeaders.AUTHORIZATION, BEARER_MASTER_TOKEN);
+ requestUrl = UrlUtils.approvedMessage(Setup.TEST_CELL1, messageId);
+ PersoniumResponse res = rest.post(requestUrl, "{\"Command\":\"approved\" }", requestheaders);
+
+ // ---------------
+ // Verification
+ // ---------------
+ assertEquals(HttpStatus.SC_NO_CONTENT, res.getStatusCode());
+ // Check relation exists
+ RelationUtils.get(Setup.TEST_CELL1, MASTER_TOKEN_NAME, relationName, boxName, HttpStatus.SC_OK);
+ // Check extcell exists
+ ExtCellUtils.get(MASTER_TOKEN_NAME, Setup.TEST_CELL1, UrlUtils.cellRoot("targetCell"), HttpStatus.SC_OK);
+ // Check $links exists
+ ArrayList expectedUriList = new ArrayList();
+ expectedUriList.add(UrlUtils.extCellResource(Setup.TEST_CELL1, UrlUtils.cellRoot("targetCell")));
+ checkRelationExtCellLinks(relationName, boxName, expectedUriList);
+ // Check status changed
+ checkMessageStatus(messageId, "approved");
+ } catch (PersoniumException e) {
+ fail(e.getStackTrace().toString());
+ } finally {
+ // Delete Received message
+ if (response != null) {
+ deleteOdataResource(response.getLocationHeader());
+ }
+ // Delete Relation-ExtCell $links
+ ResourceUtils.linksDelete(Setup.TEST_CELL1, Relation.EDM_TYPE_NAME, relationName, boxName,
+ ExtCell.EDM_TYPE_NAME,
+ "'" + PersoniumCoreUtils.encodeUrlComp(UrlUtils.cellRoot("targetCell")) + "'", MASTER_TOKEN_NAME);
+ // Delete Relation
+ RelationUtils.delete(Setup.TEST_CELL1, MASTER_TOKEN_NAME, relationName, boxName, -1);
+ // Delete ExtCell
+ ExtCellUtils.delete(MASTER_TOKEN_NAME, Setup.TEST_CELL1, UrlUtils.cellRoot("targetCell"));
+ }
+ }
+
+ /**
+ * Normal test.
+ * Approve build message with RelationClassURL for not existing relation.
+ */
+ @SuppressWarnings("unchecked")
+ @Test
+ public final void normal_approve_build_message_with_relationClassURL_for_not_exist_relation() {
+ String relationName = "messageTestRelation";
+ String boxName = Setup.TEST_BOX1;
+
+ // Request body of message
+ JSONObject body = new JSONObject();
+ body.put("__id", "12345678901234567890123456789012");
+ body.put("From", UrlUtils.cellRoot(Setup.TEST_CELL2));
+ body.put("Type", "req.relation.build");
+ body.put("Title", "Title");
+ body.put("Body", "Body");
+ body.put("InReplyTo", "d3330643f57a42fd854558fb0a96a96a");
+ body.put("Priority", 3);
+ body.put("Status", "none");
+ body.put("RequestRelation", UrlUtils.relationClassUrl(Setup.TEST_CELL_SCHEMA1, relationName));
+ body.put("RequestRelationTarget", UrlUtils.cellRoot("targetCell"));
+
+ TResponse response = null;
+ try {
+ // ---------------
+ // Preparation
+ // ---------------
+ // ReceivedMessage
+ String requestUrl = UrlUtils.cellRoot(Setup.TEST_CELL1);
+ response = ReceivedMessageUtils.receive(getCellIssueToken(requestUrl), Setup.TEST_CELL1,
+ body.toJSONString(), HttpStatus.SC_CREATED);
+ String messageId = (String) body.get("__id");
+
+ // ---------------
+ // Execution
+ // ---------------
+ // execute approved message
+ PersoniumRestAdapter rest = new PersoniumRestAdapter();
+ HashMap requestheaders = new HashMap();
+ requestheaders.put(HttpHeaders.AUTHORIZATION, BEARER_MASTER_TOKEN);
+ requestUrl = UrlUtils.approvedMessage(Setup.TEST_CELL1, messageId);
+ PersoniumResponse res = rest.post(requestUrl, "{\"Command\":\"approved\" }", requestheaders);
+
+ // ---------------
+ // Verification
+ // ---------------
+ assertEquals(HttpStatus.SC_NO_CONTENT, res.getStatusCode());
+ // Check relation exists
+ RelationUtils.get(Setup.TEST_CELL1, MASTER_TOKEN_NAME, relationName, boxName, HttpStatus.SC_OK);
+ // Check extcell exists
+ ExtCellUtils.get(MASTER_TOKEN_NAME, Setup.TEST_CELL1, UrlUtils.cellRoot("targetCell"), HttpStatus.SC_OK);
+ // Check $links exists
+ ArrayList expectedUriList = new ArrayList();
+ expectedUriList.add(UrlUtils.extCellResource(Setup.TEST_CELL1, UrlUtils.cellRoot("targetCell")));
+ checkRelationExtCellLinks(relationName, boxName, expectedUriList);
+ // Check status changed
+ checkMessageStatus(messageId, "approved");
+ } catch (PersoniumException e) {
+ fail(e.getStackTrace().toString());
+ } finally {
+ // Delete Received message
+ if (response != null) {
+ deleteOdataResource(response.getLocationHeader());
+ }
+ // Delete Relation-ExtCell $links
+ ResourceUtils.linksDelete(Setup.TEST_CELL1, Relation.EDM_TYPE_NAME, relationName, boxName,
+ ExtCell.EDM_TYPE_NAME,
+ "'" + PersoniumCoreUtils.encodeUrlComp(UrlUtils.cellRoot("targetCell")) + "'", MASTER_TOKEN_NAME);
+ // Delete Relation
+ RelationUtils.delete(Setup.TEST_CELL1, MASTER_TOKEN_NAME, relationName, boxName, -1);
+ // Delete ExtCell
+ ExtCellUtils.delete(MASTER_TOKEN_NAME, Setup.TEST_CELL1, UrlUtils.cellRoot("targetCell"));
+ }
+ }
+
+ /**
+ * Normal test.
+ * Approve break message with RelationClassURL.
+ */
+ @SuppressWarnings("unchecked")
+ @Test
+ public final void normal_approve_break_message_with_relationClassURL() {
+ String relationName = "messageTestRelation";
+ String boxName = Setup.TEST_BOX1;
+
+ // Request body of message
+ JSONObject body = new JSONObject();
+ body.put("__id", "12345678901234567890123456789012");
+ body.put("From", UrlUtils.cellRoot(Setup.TEST_CELL2));
+ body.put("Type", "req.relation.build");
+ body.put("Title", "Title");
+ body.put("Body", "Body");
+ body.put("InReplyTo", "d3330643f57a42fd854558fb0a96a96a");
+ body.put("Priority", 3);
+ body.put("Status", "none");
+ body.put("RequestRelation", UrlUtils.relationClassUrl(Setup.TEST_CELL_SCHEMA1, relationName));
+ body.put("RequestRelationTarget", UrlUtils.cellRoot("targetCell"));
+
+ TResponse buildResponse = null;
+ TResponse breakResponse = null;
+
+ try {
+ // ---------------
+ // Preparation
+ // ---------------
+ // BuildReceivedMessage
+ String requestUrl = UrlUtils.cellRoot(Setup.TEST_CELL1);
+ buildResponse = ReceivedMessageUtils.receive(getCellIssueToken(requestUrl), Setup.TEST_CELL1,
+ body.toJSONString(), HttpStatus.SC_CREATED);
+ String messageId = (String) body.get("__id");
+
+ // Approved message
+ PersoniumRestAdapter rest = new PersoniumRestAdapter();
+ HashMap requestheaders = new HashMap();
+ requestheaders.put(HttpHeaders.AUTHORIZATION, BEARER_MASTER_TOKEN);
+ requestUrl = UrlUtils.approvedMessage(Setup.TEST_CELL1, messageId);
+ PersoniumResponse res = rest.post(requestUrl, "{\"Command\":\"approved\" }", requestheaders);
+ assertEquals(HttpStatus.SC_NO_CONTENT, res.getStatusCode());
+
+ // BreakReceivedMessage
+ body.put("Type", "req.relation.break");
+ body.put("__id", "12345678901234567890123456789013");
+ requestUrl = UrlUtils.cellRoot(Setup.TEST_CELL1);
+ breakResponse = ReceivedMessageUtils.receive(getCellIssueToken(requestUrl), Setup.TEST_CELL1,
+ body.toJSONString(), HttpStatus.SC_CREATED);
+ messageId = (String) body.get("__id");
+
+ // ---------------
+ // Execution
+ // ---------------
+ // execute approved message
+ rest = new PersoniumRestAdapter();
+ requestheaders = new HashMap();
+ requestheaders.put(HttpHeaders.AUTHORIZATION, BEARER_MASTER_TOKEN);
+ requestUrl = UrlUtils.approvedMessage(Setup.TEST_CELL1, messageId);
+ res = rest.post(requestUrl, "{\"Command\":\"approved\" }", requestheaders);
+
+ // ---------------
+ // Verification
+ // ---------------
+ assertEquals(HttpStatus.SC_NO_CONTENT, res.getStatusCode());
+ // Check relation exists
+ RelationUtils.get(Setup.TEST_CELL1, MASTER_TOKEN_NAME, relationName, boxName, HttpStatus.SC_OK);
+ // Check extcell exists
+ ExtCellUtils.get(MASTER_TOKEN_NAME, Setup.TEST_CELL1, UrlUtils.cellRoot("targetCell"), HttpStatus.SC_OK);
+ // Check $links not exists
+ TResponse linkResponse = getRelationExtCellLinks(relationName, boxName);
+ JSONArray results = (JSONArray) ((JSONObject) linkResponse.bodyAsJson().get("d")).get("results");
+ assertEquals(0, results.size());
+ // Check status changed
+ checkMessageStatus(messageId, "approved");
+ } catch (PersoniumException e) {
+ fail(e.getStackTrace().toString());
+ } finally {
+ // Delete Received message
+ if (buildResponse != null) {
+ deleteOdataResource(buildResponse.getLocationHeader());
+ }
+ if (breakResponse != null) {
+ deleteOdataResource(breakResponse.getLocationHeader());
+ }
+ // Delete Relation-ExtCell $links
+ ResourceUtils.linksDelete(Setup.TEST_CELL1, Relation.EDM_TYPE_NAME, relationName, boxName,
+ ExtCell.EDM_TYPE_NAME,
+ "'" + PersoniumCoreUtils.encodeUrlComp(UrlUtils.cellRoot("targetCell")) + "'", MASTER_TOKEN_NAME);
+ // Delete Relation
+ RelationUtils.delete(Setup.TEST_CELL1, MASTER_TOKEN_NAME, relationName, boxName, -1);
+ // Delete ExtCell
+ ExtCellUtils.delete(MASTER_TOKEN_NAME, Setup.TEST_CELL1, UrlUtils.cellRoot("targetCell"));
+ }
+ }
+
+ /**
+ * Normal test.
+ * Reject build message with RelationClassURL.
+ */
+ @SuppressWarnings("unchecked")
+ @Test
+ public final void normal_reject_build_message_with_relationClassURL() {
+ String relationName = "messageTestRelation";
+ String boxName = Setup.TEST_BOX1;
+
+ // Request body of message
+ JSONObject body = new JSONObject();
+ body.put("__id", "12345678901234567890123456789012");
+ body.put("From", UrlUtils.cellRoot(Setup.TEST_CELL2));
+ body.put("Type", "req.relation.build");
+ body.put("Title", "Title");
+ body.put("Body", "Body");
+ body.put("InReplyTo", "d3330643f57a42fd854558fb0a96a96a");
+ body.put("Priority", 3);
+ body.put("Status", "none");
+ body.put("RequestRelation", UrlUtils.relationClassUrl(Setup.TEST_CELL_SCHEMA1, relationName));
+ body.put("RequestRelationTarget", UrlUtils.cellRoot("targetCell"));
+
+ TResponse response = null;
+
+ try {
+ // ---------------
+ // Preparation
+ // ---------------
+ // ReceivedMessage
+ String requestUrl = UrlUtils.cellRoot(Setup.TEST_CELL1);
+ response = ReceivedMessageUtils.receive(getCellIssueToken(requestUrl), Setup.TEST_CELL1,
+ body.toJSONString(), HttpStatus.SC_CREATED);
+ String messageId = (String) body.get("__id");
+
+ // ---------------
+ // Execution
+ // ---------------
+ // execute rejected message
+ PersoniumRestAdapter rest = new PersoniumRestAdapter();
+ HashMap requestheaders = new HashMap();
+ requestheaders.put(HttpHeaders.AUTHORIZATION, BEARER_MASTER_TOKEN);
+ requestUrl = UrlUtils.approvedMessage(Setup.TEST_CELL1, messageId);
+ PersoniumResponse res = rest.post(requestUrl, "{\"Command\":\"rejected\" }", requestheaders);
+
+ // ---------------
+ // Verification
+ // ---------------
+ assertEquals(HttpStatus.SC_NO_CONTENT, res.getStatusCode());
+ // Check relation not exists
+ RelationUtils.get(Setup.TEST_CELL1, MASTER_TOKEN_NAME, relationName, boxName, HttpStatus.SC_NOT_FOUND);
+ // Check status changed
+ checkMessageStatus(messageId, "rejected");
+ } catch (PersoniumException e) {
+ fail(e.getStackTrace().toString());
+ } finally {
+ // Delete Received message
+ if (response != null) {
+ deleteOdataResource(response.getLocationHeader());
+ }
+ // Delete Relation
+ RelationUtils.delete(Setup.TEST_CELL1, MASTER_TOKEN_NAME, relationName, boxName, -1);
+ }
+ }
+
+ /**
+ * Normal test.
+ * Approve build message with unit local RelationClassURL.
+ */
+ @SuppressWarnings("unchecked")
+ @Test
+ public final void normal_approve_build_message_with_unit_local_relationClassURL() {
+ String relationName = "messageTestRelation";
+ String boxName = Setup.TEST_BOX1;
+
+ // Request body of relation
+ JSONObject relationBody = new JSONObject();
+ relationBody.put(Relation.P_NAME.getName(), relationName);
+ relationBody.put(Common.P_BOX_NAME.getName(), boxName);
+
+ // Request body of message
+ JSONObject body = new JSONObject();
+ body.put("__id", "12345678901234567890123456789012");
+ body.put("From", UrlUtils.cellRoot(Setup.TEST_CELL2));
+ body.put("Type", "req.relation.build");
+ body.put("Title", "Title");
+ body.put("Body", "Body");
+ body.put("InReplyTo", "d3330643f57a42fd854558fb0a96a96a");
+ body.put("Priority", 3);
+ body.put("Status", "none");
+ body.put("RequestRelation", UrlUtils.unitLocalRelationClassUrl(Setup.TEST_CELL_SCHEMA1, relationName));
+ body.put("RequestRelationTarget", UrlUtils.cellRoot("targetCell"));
+
+ TResponse response = null;
+ try {
+ // ---------------
+ // Preparation
+ // ---------------
+ // Relation
+ RelationUtils.create(Setup.TEST_CELL1, MASTER_TOKEN_NAME, relationBody, HttpStatus.SC_CREATED);
+ // ExtCell
+ ExtCellUtils.create(MASTER_TOKEN_NAME, Setup.TEST_CELL1, UrlUtils.cellRoot("targetCell"),
+ HttpStatus.SC_CREATED);
+ // ReceivedMessage
+ String requestUrl = UrlUtils.cellRoot(Setup.TEST_CELL1);
+ response = ReceivedMessageUtils.receive(getCellIssueToken(requestUrl), Setup.TEST_CELL1,
+ body.toJSONString(), HttpStatus.SC_CREATED);
+ String messageId = (String) body.get("__id");
+
+ // ---------------
+ // Execution
+ // ---------------
+ // execute approved message
+ PersoniumRestAdapter rest = new PersoniumRestAdapter();
+ HashMap requestheaders = new HashMap();
+ requestheaders.put(HttpHeaders.AUTHORIZATION, BEARER_MASTER_TOKEN);
+ requestUrl = UrlUtils.approvedMessage(Setup.TEST_CELL1, messageId);
+ PersoniumResponse res = rest.post(requestUrl, "{\"Command\":\"approved\" }", requestheaders);
+
+ // ---------------
+ // Verification
+ // ---------------
+ assertEquals(HttpStatus.SC_NO_CONTENT, res.getStatusCode());
+ // Check relation exists
+ RelationUtils.get(Setup.TEST_CELL1, MASTER_TOKEN_NAME, relationName, boxName, HttpStatus.SC_OK);
+ // Check extcell exists
+ ExtCellUtils.get(MASTER_TOKEN_NAME, Setup.TEST_CELL1, UrlUtils.cellRoot("targetCell"), HttpStatus.SC_OK);
+ // Check $links exists
+ ArrayList expectedUriList = new ArrayList();
+ expectedUriList.add(UrlUtils.extCellResource(Setup.TEST_CELL1, UrlUtils.cellRoot("targetCell")));
+ checkRelationExtCellLinks(relationName, boxName, expectedUriList);
+ // Check status changed
+ checkMessageStatus(messageId, "approved");
+ } catch (PersoniumException e) {
+ fail(e.getStackTrace().toString());
+ } finally {
+ // Delete Received message
+ if (response != null) {
+ deleteOdataResource(response.getLocationHeader());
+ }
+ // Delete Relation-ExtCell $links
+ ResourceUtils.linksDelete(Setup.TEST_CELL1, Relation.EDM_TYPE_NAME, relationName, boxName,
+ ExtCell.EDM_TYPE_NAME,
+ "'" + PersoniumCoreUtils.encodeUrlComp(UrlUtils.cellRoot("targetCell")) + "'", MASTER_TOKEN_NAME);
+ // Delete Relation
+ RelationUtils.delete(Setup.TEST_CELL1, MASTER_TOKEN_NAME, relationName, boxName, -1);
+ // Delete ExtCell
+ ExtCellUtils.delete(MASTER_TOKEN_NAME, Setup.TEST_CELL1, UrlUtils.cellRoot("targetCell"));
+ }
+ }
+
/**
* Normal test.
* Approve boxbound build message for already existing relation.
*/
@SuppressWarnings("unchecked")
@Test
- public final void normal_approve_boxbound_build_message_for_allready_exist_relation() {
+ public final void normal_approve_boxbound_build_message_for_allready_exist_relation() {
+ String relationName = "messageTestRelation";
+ String boxName = Setup.TEST_BOX1;
+
+ // Request body of relation
+ JSONObject relationBody = new JSONObject();
+ relationBody.put(Relation.P_NAME.getName(), relationName);
+ relationBody.put(Common.P_BOX_NAME.getName(), boxName);
+
+ // Request body of message
+ JSONObject body = new JSONObject();
+ body.put("__id", "12345678901234567890123456789012");
+ body.put("From", UrlUtils.cellRoot(Setup.TEST_CELL2));
+ body.put("Type", "req.relation.build");
+ body.put("Schema", UrlUtils.cellRoot(Setup.TEST_CELL_SCHEMA1));
+ body.put("Title", "Title");
+ body.put("Body", "Body");
+ body.put("InReplyTo", "d3330643f57a42fd854558fb0a96a96a");
+ body.put("Priority", 3);
+ body.put("Status", "none");
+ body.put("RequestRelation", relationName);
+ body.put("RequestRelationTarget", UrlUtils.cellRoot("targetCell"));
+
+ TResponse response = null;
+ try {
+ // ---------------
+ // Preparation
+ // ---------------
+ // Relation
+ RelationUtils.create(Setup.TEST_CELL1, MASTER_TOKEN_NAME, relationBody, HttpStatus.SC_CREATED);
+ // ExtCell
+ ExtCellUtils.create(MASTER_TOKEN_NAME, Setup.TEST_CELL1, UrlUtils.cellRoot("targetCell"),
+ HttpStatus.SC_CREATED);
+ // ReceivedMessage
+ String requestUrl = UrlUtils.cellRoot(Setup.TEST_CELL1);
+ response = ReceivedMessageUtils.receive(getCellIssueToken(requestUrl), Setup.TEST_CELL1,
+ body.toJSONString(), HttpStatus.SC_CREATED);
+ String messageId = (String) body.get("__id");
+
+ // ---------------
+ // Execution
+ // ---------------
+ // execute approved message
+ PersoniumRestAdapter rest = new PersoniumRestAdapter();
+ HashMap requestheaders = new HashMap();
+ requestheaders.put(HttpHeaders.AUTHORIZATION, BEARER_MASTER_TOKEN);
+ requestUrl = UrlUtils.approvedMessage(Setup.TEST_CELL1, messageId);
+ PersoniumResponse res = rest.post(requestUrl, "{\"Command\":\"approved\" }", requestheaders);
+
+ // ---------------
+ // Verification
+ // ---------------
+ assertEquals(HttpStatus.SC_NO_CONTENT, res.getStatusCode());
+ // Check relation exists
+ RelationUtils.get(Setup.TEST_CELL1, MASTER_TOKEN_NAME, relationName, boxName, HttpStatus.SC_OK);
+ // Check extcell exists
+ ExtCellUtils.get(MASTER_TOKEN_NAME, Setup.TEST_CELL1, UrlUtils.cellRoot("targetCell"), HttpStatus.SC_OK);
+ // Check $links exists
+ ArrayList expectedUriList = new ArrayList();
+ expectedUriList.add(UrlUtils.extCellResource(Setup.TEST_CELL1, UrlUtils.cellRoot("targetCell")));
+ checkRelationExtCellLinks(relationName, boxName, expectedUriList);
+ // Check status changed
+ checkMessageStatus(messageId, "approved");
+ } catch (PersoniumException e) {
+ fail(e.getStackTrace().toString());
+ } finally {
+ // Delete Received message
+ if (response != null) {
+ deleteOdataResource(response.getLocationHeader());
+ }
+ // Delete Relation-ExtCell $links
+ ResourceUtils.linksDelete(Setup.TEST_CELL1, Relation.EDM_TYPE_NAME, relationName, boxName,
+ ExtCell.EDM_TYPE_NAME,
+ "'" + PersoniumCoreUtils.encodeUrlComp(UrlUtils.cellRoot("targetCell")) + "'", MASTER_TOKEN_NAME);
+ // Delete Relation
+ RelationUtils.delete(Setup.TEST_CELL1, MASTER_TOKEN_NAME, relationName, boxName, -1);
+ // Delete ExtCell
+ ExtCellUtils.delete(MASTER_TOKEN_NAME, Setup.TEST_CELL1, UrlUtils.cellRoot("targetCell"));
+ }
+ }
+
+ /**
+ * Normal test.
+ * Approve boxbound build message for not existing relation.
+ */
+ @SuppressWarnings("unchecked")
+ @Test
+ public final void normal_approve_boxbound_build_message_for_not_exist_relation() {
+ String relationName = "messageTestRelation";
+ String boxName = Setup.TEST_BOX1;
+
+ // Request body of message
+ JSONObject body = new JSONObject();
+ body.put("__id", "12345678901234567890123456789012");
+ body.put("From", UrlUtils.cellRoot(Setup.TEST_CELL2));
+ body.put("Type", "req.relation.build");
+ body.put("Schema", UrlUtils.cellRoot(Setup.TEST_CELL_SCHEMA1));
+ body.put("Title", "Title");
+ body.put("Body", "Body");
+ body.put("InReplyTo", "d3330643f57a42fd854558fb0a96a96a");
+ body.put("Priority", 3);
+ body.put("Status", "none");
+ body.put("RequestRelation", relationName);
+ body.put("RequestRelationTarget", UrlUtils.cellRoot("targetCell"));
+
+ TResponse response = null;
+ try {
+ // ---------------
+ // Preparation
+ // ---------------
+ // ReceivedMessage
+ String requestUrl = UrlUtils.cellRoot(Setup.TEST_CELL1);
+ response = ReceivedMessageUtils.receive(getCellIssueToken(requestUrl), Setup.TEST_CELL1,
+ body.toJSONString(), HttpStatus.SC_CREATED);
+ String messageId = (String) body.get("__id");
+
+ // ---------------
+ // Execution
+ // ---------------
+ // execute approved message
+ PersoniumRestAdapter rest = new PersoniumRestAdapter();
+ HashMap requestheaders = new HashMap();
+ requestheaders.put(HttpHeaders.AUTHORIZATION, BEARER_MASTER_TOKEN);
+ requestUrl = UrlUtils.approvedMessage(Setup.TEST_CELL1, messageId);
+ PersoniumResponse res = rest.post(requestUrl, "{\"Command\":\"approved\" }", requestheaders);
+
+ // ---------------
+ // Verification
+ // ---------------
+ assertEquals(HttpStatus.SC_NO_CONTENT, res.getStatusCode());
+ // Check relation exists
+ RelationUtils.get(Setup.TEST_CELL1, MASTER_TOKEN_NAME, relationName, boxName, HttpStatus.SC_OK);
+ // Check extcell exists
+ ExtCellUtils.get(MASTER_TOKEN_NAME, Setup.TEST_CELL1, UrlUtils.cellRoot("targetCell"), HttpStatus.SC_OK);
+ // Check $links exists
+ ArrayList expectedUriList = new ArrayList();
+ expectedUriList.add(UrlUtils.extCellResource(Setup.TEST_CELL1, UrlUtils.cellRoot("targetCell")));
+ checkRelationExtCellLinks(relationName, boxName, expectedUriList);
+ // Check status changed
+ checkMessageStatus(messageId, "approved");
+ } catch (PersoniumException e) {
+ fail(e.getStackTrace().toString());
+ } finally {
+ // Delete Received message
+ if (response != null) {
+ deleteOdataResource(response.getLocationHeader());
+ }
+ // Delete Relation-ExtCell $links
+ ResourceUtils.linksDelete(Setup.TEST_CELL1, Relation.EDM_TYPE_NAME, relationName, boxName,
+ ExtCell.EDM_TYPE_NAME,
+ "'" + PersoniumCoreUtils.encodeUrlComp(UrlUtils.cellRoot("targetCell")) + "'", MASTER_TOKEN_NAME);
+ // Delete Relation
+ RelationUtils.delete(Setup.TEST_CELL1, MASTER_TOKEN_NAME, relationName, boxName, -1);
+ // Delete ExtCell
+ ExtCellUtils.delete(MASTER_TOKEN_NAME, Setup.TEST_CELL1, UrlUtils.cellRoot("targetCell"));
+ }
+ }
+
+ /**
+ * Normal test.
+ * Approve boxbound break message.
+ */
+ @SuppressWarnings("unchecked")
+ @Test
+ public final void normal_approve_boxbound_break_message() {
String relationName = "messageTestRelation";
String boxName = Setup.TEST_BOX1;
- // Request body of relation
- JSONObject relationBody = new JSONObject();
- relationBody.put(Relation.P_NAME.getName(), relationName);
- relationBody.put(Common.P_BOX_NAME.getName(), boxName);
-
// Request body of message
JSONObject body = new JSONObject();
body.put("__id", "12345678901234567890123456789012");
@@ -465,34 +1035,47 @@ public final void normal_approve_boxbound_build_message_for_allready_exist_relat
body.put("InReplyTo", "d3330643f57a42fd854558fb0a96a96a");
body.put("Priority", 3);
body.put("Status", "none");
- body.put("RequestRelation", UrlUtils.cellRoot(Setup.TEST_CELL1) + "__relation/__/" + relationName);
+ body.put("RequestRelation", relationName);
body.put("RequestRelationTarget", UrlUtils.cellRoot("targetCell"));
- TResponse response = null;
+ TResponse buildResponse = null;
+ TResponse breakResponse = null;
+
try {
// ---------------
// Preparation
// ---------------
- // Relation
- RelationUtils.create(Setup.TEST_CELL1, MASTER_TOKEN_NAME, relationBody, HttpStatus.SC_CREATED);
- // ExtCell
- ExtCellUtils.create(MASTER_TOKEN_NAME, Setup.TEST_CELL1, UrlUtils.cellRoot("targetCell"),
- HttpStatus.SC_CREATED);
- // ReceivedMessage
+ // BuildReceivedMessage
String requestUrl = UrlUtils.cellRoot(Setup.TEST_CELL1);
- response = ReceivedMessageUtils.receive(getCellIssueToken(requestUrl), Setup.TEST_CELL1,
+ buildResponse = ReceivedMessageUtils.receive(getCellIssueToken(requestUrl), Setup.TEST_CELL1,
body.toJSONString(), HttpStatus.SC_CREATED);
String messageId = (String) body.get("__id");
+ // Approved message
+ PersoniumRestAdapter rest = new PersoniumRestAdapter();
+ HashMap requestheaders = new HashMap();
+ requestheaders.put(HttpHeaders.AUTHORIZATION, BEARER_MASTER_TOKEN);
+ requestUrl = UrlUtils.approvedMessage(Setup.TEST_CELL1, messageId);
+ PersoniumResponse res = rest.post(requestUrl, "{\"Command\":\"approved\" }", requestheaders);
+ assertEquals(HttpStatus.SC_NO_CONTENT, res.getStatusCode());
+
+ // BreakReceivedMessage
+ body.put("Type", "req.relation.break");
+ body.put("__id", "12345678901234567890123456789013");
+ requestUrl = UrlUtils.cellRoot(Setup.TEST_CELL1);
+ breakResponse = ReceivedMessageUtils.receive(getCellIssueToken(requestUrl), Setup.TEST_CELL1,
+ body.toJSONString(), HttpStatus.SC_CREATED);
+ messageId = (String) body.get("__id");
+
// ---------------
// Execution
// ---------------
// execute approved message
- PersoniumRestAdapter rest = new PersoniumRestAdapter();
- HashMap requestheaders = new HashMap();
+ rest = new PersoniumRestAdapter();
+ requestheaders = new HashMap();
requestheaders.put(HttpHeaders.AUTHORIZATION, BEARER_MASTER_TOKEN);
requestUrl = UrlUtils.approvedMessage(Setup.TEST_CELL1, messageId);
- PersoniumResponse res = rest.post(requestUrl, "{\"Command\":\"approved\" }", requestheaders);
+ res = rest.post(requestUrl, "{\"Command\":\"approved\" }", requestheaders);
// ---------------
// Verification
@@ -502,15 +1085,22 @@ public final void normal_approve_boxbound_build_message_for_allready_exist_relat
RelationUtils.get(Setup.TEST_CELL1, MASTER_TOKEN_NAME, relationName, boxName, HttpStatus.SC_OK);
// Check extcell exists
ExtCellUtils.get(MASTER_TOKEN_NAME, Setup.TEST_CELL1, UrlUtils.cellRoot("targetCell"), HttpStatus.SC_OK);
- // Check $links exists
- ArrayList expectedUriList = new ArrayList();
- expectedUriList.add(UrlUtils.extCellResource(Setup.TEST_CELL1, UrlUtils.cellRoot("targetCell")));
- checkRelationExtCellLinks(relationName, boxName, expectedUriList);
+ // Check $links not exists
+ TResponse linkResponse = getRelationExtCellLinks(relationName, boxName);
+ JSONArray results = (JSONArray) ((JSONObject) linkResponse.bodyAsJson().get("d")).get("results");
+ assertEquals(0, results.size());
// Check status changed
checkMessageStatus(messageId, "approved");
} catch (PersoniumException e) {
fail(e.getStackTrace().toString());
} finally {
+ // Delete Received message
+ if (buildResponse != null) {
+ deleteOdataResource(buildResponse.getLocationHeader());
+ }
+ if (breakResponse != null) {
+ deleteOdataResource(breakResponse.getLocationHeader());
+ }
// Delete Relation-ExtCell $links
ResourceUtils.linksDelete(Setup.TEST_CELL1, Relation.EDM_TYPE_NAME, relationName, boxName,
ExtCell.EDM_TYPE_NAME,
@@ -519,35 +1109,102 @@ public final void normal_approve_boxbound_build_message_for_allready_exist_relat
RelationUtils.delete(Setup.TEST_CELL1, MASTER_TOKEN_NAME, relationName, boxName, -1);
// Delete ExtCell
ExtCellUtils.delete(MASTER_TOKEN_NAME, Setup.TEST_CELL1, UrlUtils.cellRoot("targetCell"));
+ }
+ }
+
+ /**
+ * Normal test.
+ * Reject boxbound build message.
+ */
+ @SuppressWarnings("unchecked")
+ @Test
+ public final void normal_reject_boxbound_build_message() {
+ String relationName = "messageTestRelation";
+ String boxName = Setup.TEST_BOX1;
+
+ // Request body of message
+ JSONObject body = new JSONObject();
+ body.put("__id", "12345678901234567890123456789012");
+ body.put("From", UrlUtils.cellRoot(Setup.TEST_CELL2));
+ body.put("Type", "req.relation.build");
+ body.put("Schema", UrlUtils.cellRoot(Setup.TEST_CELL_SCHEMA1));
+ body.put("Title", "Title");
+ body.put("Body", "Body");
+ body.put("InReplyTo", "d3330643f57a42fd854558fb0a96a96a");
+ body.put("Priority", 3);
+ body.put("Status", "none");
+ body.put("RequestRelation", relationName);
+ body.put("RequestRelationTarget", UrlUtils.cellRoot("targetCell"));
+
+ TResponse response = null;
+
+ try {
+ // ---------------
+ // Preparation
+ // ---------------
+ // ReceivedMessage
+ String requestUrl = UrlUtils.cellRoot(Setup.TEST_CELL1);
+ response = ReceivedMessageUtils.receive(getCellIssueToken(requestUrl), Setup.TEST_CELL1,
+ body.toJSONString(), HttpStatus.SC_CREATED);
+ String messageId = (String) body.get("__id");
+
+ // ---------------
+ // Execution
+ // ---------------
+ // execute rejected message
+ PersoniumRestAdapter rest = new PersoniumRestAdapter();
+ HashMap requestheaders = new HashMap();
+ requestheaders.put(HttpHeaders.AUTHORIZATION, BEARER_MASTER_TOKEN);
+ requestUrl = UrlUtils.approvedMessage(Setup.TEST_CELL1, messageId);
+ PersoniumResponse res = rest.post(requestUrl, "{\"Command\":\"rejected\" }", requestheaders);
+
+ // ---------------
+ // Verification
+ // ---------------
+ assertEquals(HttpStatus.SC_NO_CONTENT, res.getStatusCode());
+ // Check relation not exists
+ RelationUtils.get(Setup.TEST_CELL1, MASTER_TOKEN_NAME, relationName, boxName, HttpStatus.SC_NOT_FOUND);
+ // Check status changed
+ checkMessageStatus(messageId, "rejected");
+ } catch (PersoniumException e) {
+ fail(e.getStackTrace().toString());
+ } finally {
// Delete Received message
if (response != null) {
deleteOdataResource(response.getLocationHeader());
}
+ // Delete Relation
+ RelationUtils.delete(Setup.TEST_CELL1, MASTER_TOKEN_NAME, relationName, boxName, -1);
}
}
/**
* Normal test.
- * Approve boxbound build message for not existing relation.
+ * Approve build boxbound message with RelationClassURL.
*/
@SuppressWarnings("unchecked")
@Test
- public final void normal_approve_boxbound_build_message_for_not_exist_relation() {
+ public final void normal_approve_boxbound_build_message_with_relationClassURL() {
String relationName = "messageTestRelation";
String boxName = Setup.TEST_BOX1;
+ // Request body of relation
+ JSONObject relationBody = new JSONObject();
+ relationBody.put(Relation.P_NAME.getName(), relationName);
+ relationBody.put(Common.P_BOX_NAME.getName(), boxName);
+
// Request body of message
JSONObject body = new JSONObject();
body.put("__id", "12345678901234567890123456789012");
body.put("From", UrlUtils.cellRoot(Setup.TEST_CELL2));
body.put("Type", "req.relation.build");
- body.put("Schema", UrlUtils.cellRoot(Setup.TEST_CELL_SCHEMA1));
+ body.put("Schema", UrlUtils.cellRoot(Setup.TEST_CELL_SCHEMA2));
body.put("Title", "Title");
body.put("Body", "Body");
body.put("InReplyTo", "d3330643f57a42fd854558fb0a96a96a");
body.put("Priority", 3);
body.put("Status", "none");
- body.put("RequestRelation", UrlUtils.cellRoot(Setup.TEST_CELL1) + "__relation/__/" + relationName);
+ body.put("RequestRelation", UrlUtils.relationClassUrl(Setup.TEST_CELL_SCHEMA1, relationName));
body.put("RequestRelationTarget", UrlUtils.cellRoot("targetCell"));
TResponse response = null;
@@ -555,6 +1212,14 @@ public final void normal_approve_boxbound_build_message_for_not_exist_relation()
// ---------------
// Preparation
// ---------------
+ // Box
+ BoxUtils.createWithSchema(Setup.TEST_CELL1, "testBox002", MASTER_TOKEN_NAME,
+ UrlUtils.cellRoot(Setup.TEST_CELL_SCHEMA2));
+ // Relation
+ RelationUtils.create(Setup.TEST_CELL1, MASTER_TOKEN_NAME, relationBody, HttpStatus.SC_CREATED);
+ // ExtCell
+ ExtCellUtils.create(MASTER_TOKEN_NAME, Setup.TEST_CELL1, UrlUtils.cellRoot("targetCell"),
+ HttpStatus.SC_CREATED);
// ReceivedMessage
String requestUrl = UrlUtils.cellRoot(Setup.TEST_CELL1);
response = ReceivedMessageUtils.receive(getCellIssueToken(requestUrl), Setup.TEST_CELL1,
@@ -588,6 +1253,12 @@ public final void normal_approve_boxbound_build_message_for_not_exist_relation()
} catch (PersoniumException e) {
fail(e.getStackTrace().toString());
} finally {
+ // Delete Received message
+ if (response != null) {
+ deleteOdataResource(response.getLocationHeader());
+ }
+ // Delete Box
+ BoxUtils.delete(Setup.TEST_CELL1, MASTER_TOKEN_NAME, "testBox002", -1);
// Delete Relation-ExtCell $links
ResourceUtils.linksDelete(Setup.TEST_CELL1, Relation.EDM_TYPE_NAME, relationName, boxName,
ExtCell.EDM_TYPE_NAME,
@@ -596,20 +1267,16 @@ public final void normal_approve_boxbound_build_message_for_not_exist_relation()
RelationUtils.delete(Setup.TEST_CELL1, MASTER_TOKEN_NAME, relationName, boxName, -1);
// Delete ExtCell
ExtCellUtils.delete(MASTER_TOKEN_NAME, Setup.TEST_CELL1, UrlUtils.cellRoot("targetCell"));
- // Delete Received message
- if (response != null) {
- deleteOdataResource(response.getLocationHeader());
- }
}
}
/**
* Normal test.
- * Approve boxbound break message.
+ * Approve boxbound break message with RelationClassURL.
*/
@SuppressWarnings("unchecked")
@Test
- public final void normal_approve_boxbound_break_message() {
+ public final void normal_approve_boxbound_break_message_with_relationClassURL() {
String relationName = "messageTestRelation";
String boxName = Setup.TEST_BOX1;
@@ -618,13 +1285,13 @@ public final void normal_approve_boxbound_break_message() {
body.put("__id", "12345678901234567890123456789012");
body.put("From", UrlUtils.cellRoot(Setup.TEST_CELL2));
body.put("Type", "req.relation.build");
- body.put("Schema", UrlUtils.cellRoot(Setup.TEST_CELL_SCHEMA1));
+ body.put("Schema", UrlUtils.cellRoot(Setup.TEST_CELL_SCHEMA2));
body.put("Title", "Title");
body.put("Body", "Body");
body.put("InReplyTo", "d3330643f57a42fd854558fb0a96a96a");
body.put("Priority", 3);
body.put("Status", "none");
- body.put("RequestRelation", UrlUtils.cellRoot(Setup.TEST_CELL1) + "__relation/__/" + relationName);
+ body.put("RequestRelation", UrlUtils.relationClassUrl(Setup.TEST_CELL_SCHEMA1, relationName));
body.put("RequestRelationTarget", UrlUtils.cellRoot("targetCell"));
TResponse buildResponse = null;
@@ -634,6 +1301,10 @@ public final void normal_approve_boxbound_break_message() {
// ---------------
// Preparation
// ---------------
+ // Box
+ BoxUtils.createWithSchema(Setup.TEST_CELL1, "testBox002", MASTER_TOKEN_NAME,
+ UrlUtils.cellRoot(Setup.TEST_CELL_SCHEMA2));
+
// BuildReceivedMessage
String requestUrl = UrlUtils.cellRoot(Setup.TEST_CELL1);
buildResponse = ReceivedMessageUtils.receive(getCellIssueToken(requestUrl), Setup.TEST_CELL1,
@@ -661,7 +1332,6 @@ public final void normal_approve_boxbound_break_message() {
// ---------------
// execute approved message
rest = new PersoniumRestAdapter();
- // リクエストヘッダをセット
requestheaders = new HashMap();
requestheaders.put(HttpHeaders.AUTHORIZATION, BEARER_MASTER_TOKEN);
requestUrl = UrlUtils.approvedMessage(Setup.TEST_CELL1, messageId);
@@ -684,6 +1354,15 @@ public final void normal_approve_boxbound_break_message() {
} catch (PersoniumException e) {
fail(e.getStackTrace().toString());
} finally {
+ // Delete Received message
+ if (buildResponse != null) {
+ deleteOdataResource(buildResponse.getLocationHeader());
+ }
+ if (breakResponse != null) {
+ deleteOdataResource(breakResponse.getLocationHeader());
+ }
+ // Delete Box
+ BoxUtils.delete(Setup.TEST_CELL1, MASTER_TOKEN_NAME, "testBox002", -1);
// Delete Relation-ExtCell $links
ResourceUtils.linksDelete(Setup.TEST_CELL1, Relation.EDM_TYPE_NAME, relationName, boxName,
ExtCell.EDM_TYPE_NAME,
@@ -692,42 +1371,34 @@ public final void normal_approve_boxbound_break_message() {
RelationUtils.delete(Setup.TEST_CELL1, MASTER_TOKEN_NAME, relationName, boxName, -1);
// Delete ExtCell
ExtCellUtils.delete(MASTER_TOKEN_NAME, Setup.TEST_CELL1, UrlUtils.cellRoot("targetCell"));
- // Delete Received message
- if (buildResponse != null) {
- deleteOdataResource(buildResponse.getLocationHeader());
- }
- if (breakResponse != null) {
- deleteOdataResource(breakResponse.getLocationHeader());
- }
}
}
/**
- * Normal test.
- * Reject boxbound build message.
+ * Error test.
+ * Approve build message with RelationClassURL.
+ * Box corresponding to the RelationClassURL can not be found.
*/
@SuppressWarnings("unchecked")
@Test
- public final void normal_reject_boxbound_build_message() {
+ public final void error_approve_build_message_not_found_box_corresponding_to_RelationClassURL() {
String relationName = "messageTestRelation";
- String boxName = Setup.TEST_BOX1;
+ String boxName = Setup.TEST_BOX2;
// Request body of message
JSONObject body = new JSONObject();
body.put("__id", "12345678901234567890123456789012");
body.put("From", UrlUtils.cellRoot(Setup.TEST_CELL2));
body.put("Type", "req.relation.build");
- body.put("Schema", UrlUtils.cellRoot(Setup.TEST_CELL_SCHEMA1));
body.put("Title", "Title");
body.put("Body", "Body");
body.put("InReplyTo", "d3330643f57a42fd854558fb0a96a96a");
body.put("Priority", 3);
body.put("Status", "none");
- body.put("RequestRelation", UrlUtils.cellRoot(Setup.TEST_CELL1) + "__relation/__/" + relationName);
+ body.put("RequestRelation", UrlUtils.relationClassUrl(Setup.TEST_CELL_SCHEMA2, relationName));
body.put("RequestRelationTarget", UrlUtils.cellRoot("targetCell"));
TResponse response = null;
-
try {
// ---------------
// Preparation
@@ -741,30 +1412,42 @@ public final void normal_reject_boxbound_build_message() {
// ---------------
// Execution
// ---------------
- // execute rejected message
+ // execute approved message
PersoniumRestAdapter rest = new PersoniumRestAdapter();
HashMap requestheaders = new HashMap();
requestheaders.put(HttpHeaders.AUTHORIZATION, BEARER_MASTER_TOKEN);
requestUrl = UrlUtils.approvedMessage(Setup.TEST_CELL1, messageId);
- PersoniumResponse res = rest.post(requestUrl, "{\"Command\":\"rejected\" }", requestheaders);
+ PersoniumResponse res = rest.post(requestUrl, "{\"Command\":\"approved\" }", requestheaders);
// ---------------
// Verification
// ---------------
- assertEquals(HttpStatus.SC_NO_CONTENT, res.getStatusCode());
+ PersoniumCoreException exception = PersoniumCoreException.ReceivedMessage
+ .BOX_THAT_MATCHES_RELATION_CLASS_URL_NOT_EXISTS.params(body.get("RequestRelation"));
+ assertEquals(HttpStatus.SC_BAD_REQUEST, res.getStatusCode());
+ checkErrorResponse(res.bodyAsJson(), exception.getCode(), exception.getMessage());
// Check relation not exists
RelationUtils.get(Setup.TEST_CELL1, MASTER_TOKEN_NAME, relationName, boxName, HttpStatus.SC_NOT_FOUND);
- // Check status changed
- checkMessageStatus(messageId, "rejected");
+ // Check extcell not exists
+ ExtCellUtils.get(MASTER_TOKEN_NAME, Setup.TEST_CELL1,
+ UrlUtils.cellRoot("targetCell"), HttpStatus.SC_NOT_FOUND);
+ // Check status
+ checkMessageStatus(messageId, "none");
} catch (PersoniumException e) {
fail(e.getStackTrace().toString());
} finally {
- // Delete Relation
- RelationUtils.delete(Setup.TEST_CELL1, MASTER_TOKEN_NAME, relationName, boxName, -1);
// Delete Received message
if (response != null) {
deleteOdataResource(response.getLocationHeader());
}
+ // Delete Relation-ExtCell $links
+ ResourceUtils.linksDelete(Setup.TEST_CELL1, Relation.EDM_TYPE_NAME, relationName, boxName,
+ ExtCell.EDM_TYPE_NAME,
+ "'" + PersoniumCoreUtils.encodeUrlComp(UrlUtils.cellRoot("targetCell")) + "'", MASTER_TOKEN_NAME);
+ // Delete Relation
+ RelationUtils.delete(Setup.TEST_CELL1, MASTER_TOKEN_NAME, relationName, boxName, -1);
+ // Delete ExtCell
+ ExtCellUtils.delete(MASTER_TOKEN_NAME, Setup.TEST_CELL1, UrlUtils.cellRoot("targetCell"));
}
}
@@ -790,7 +1473,7 @@ public final void normal_reject_boxbound_build_message() {
body.put("InReplyTo", "d3330643f57a42fd854558fb0a96a96a");
body.put("Priority", 3);
body.put("Status", "none");
- body.put("RequestRelation", UrlUtils.cellRoot(Setup.TEST_CELL1) + "__relation/__/" + relationName);
+ body.put("RequestRelation", relationName);
body.put("RequestRelationTarget", UrlUtils.cellRoot("targetCell"));
String locationHeader = null;
@@ -825,7 +1508,7 @@ public final void normal_reject_boxbound_build_message() {
requestheaders);
assertEquals(HttpStatus.SC_BAD_REQUEST, res.getStatusCode());
checkErrorResponse(res.bodyAsJson(),
- PersoniumCoreException.ReceiveMessage.REQUEST_RELATION_EXISTS_ERROR.getCode());
+ PersoniumCoreException.ReceivedMessage.REQUEST_RELATION_EXISTS_ERROR.getCode());
} catch (PersoniumException e) {
e.printStackTrace();
@@ -862,7 +1545,7 @@ public final void normal_reject_boxbound_build_message() {
body.put("InReplyTo", "d3330643f57a42fd854558fb0a96a96a");
body.put("Priority", 3);
body.put("Status", "none");
- body.put("RequestRelation", UrlUtils.cellRoot(Setup.TEST_CELL1) + "__relation/__/" + relationName);
+ body.put("RequestRelation", UrlUtils.relationClassUrl(Setup.TEST_CELL_SCHEMA1, relationName));
body.put("RequestRelationTarget", UrlUtils.cellRoot("targetCell"));
String locationHeader = null;
@@ -922,7 +1605,7 @@ public final void normal_reject_boxbound_build_message() {
body.put("InReplyTo", "d3330643f57a42fd854558fb0a96a96a");
body.put("Priority", 3);
body.put("Status", "none");
- body.put("RequestRelation", UrlUtils.cellRoot(Setup.TEST_CELL1) + "__relation/__/" + relationName);
+ body.put("RequestRelation", UrlUtils.relationClassUrl(Setup.TEST_CELL_SCHEMA1, relationName));
body.put("RequestRelationTarget", UrlUtils.cellRoot("targetCell"));
String locationHeader = null;
@@ -993,7 +1676,7 @@ public final void normal_reject_boxbound_build_message() {
body.put("InReplyTo", "d3330643f57a42fd854558fb0a96a96a");
body.put("Priority", 3);
body.put("Status", "none");
- body.put("RequestRelation", UrlUtils.cellRoot(Setup.TEST_CELL1) + "__relation/__/" + relationName);
+ body.put("RequestRelation", UrlUtils.relationClassUrl(Setup.TEST_CELL_SCHEMA1, relationName));
body.put("RequestRelationTarget", UrlUtils.cellRoot("targetCell"));
String locationHeader = null;
@@ -1057,7 +1740,7 @@ public final void normal_reject_boxbound_build_message() {
body.put("InReplyTo", "d3330643f57a42fd854558fb0a96a96a");
body.put("Priority", 3);
body.put("Status", "none");
- body.put("RequestRelation", UrlUtils.cellRoot(Setup.TEST_CELL1) + "__relation/__/" + relationName);
+ body.put("RequestRelation", relationName);
body.put("RequestRelationTarget", UrlUtils.cellRoot("targetCell"));
String locationHeader = null;
@@ -1123,7 +1806,7 @@ public final void normal_reject_boxbound_build_message() {
body.put("InReplyTo", "d3330643f57a42fd854558fb0a96a96a");
body.put("Priority", 3);
body.put("Status", "none");
- body.put("RequestRelation", UrlUtils.cellRoot(Setup.TEST_CELL1) + "__relation/__/" + relationName);
+ body.put("RequestRelation", UrlUtils.relationClassUrl(Setup.TEST_CELL_SCHEMA1, relationName));
body.put("RequestRelationTarget", UrlUtils.cellRoot("targetCell"));
String locationHeader = null;
@@ -1202,63 +1885,6 @@ public final void normal_reject_boxbound_build_message() {
}
}
- /**
- * 不正なRequestRelationが指定されたメッセージを関係登録承認した場合409エラーとなること.
- */
- @SuppressWarnings("unchecked")
- @Test
- public final void 不正なRequestRelationが指定されたメッセージを関係登録承認した場合409エラーとなること() {
- String relationName = "messageTestRelation";
-
- // 受信メッセージのリクエストボディ
- JSONObject body = new JSONObject();
- body.put("__id", "12345678901234567890123456789012");
- body.put("From", UrlUtils.cellRoot(Setup.TEST_CELL2));
- body.put("Type", "req.relation.build");
- body.put("Title", "Title");
- body.put("Body", "Body");
- body.put("InReplyTo", "d3330643f57a42fd854558fb0a96a96a");
- body.put("Priority", 3);
- body.put("Status", "none");
- body.put("RequestRelation", UrlUtils.cellRoot(Setup.TEST_CELL1) + "__relation/__/('" + relationName + "')");
- body.put("RequestRelationTarget", UrlUtils.cellRoot("targetCell"));
-
- String locationHeader = null;
-
- try {
- // メッセージ受信を登録
- String requestUrl = UrlUtils.receivedMessage(Setup.TEST_CELL1);
- PersoniumResponse res = createReceivedMessage(requestUrl, body);
- locationHeader = res.getFirstHeader(HttpHeaders.LOCATION);
-
- String messageId = getMessageId(res);
-
- // メッセージ承認にする
- PersoniumRestAdapter rest = new PersoniumRestAdapter();
-
- // リクエストヘッダをセット
- HashMap requestheaders = new HashMap();
- requestheaders.put(HttpHeaders.AUTHORIZATION, BEARER_MASTER_TOKEN);
-
- requestUrl = UrlUtils.approvedMessage(Setup.TEST_CELL1, messageId);
- res = rest.post(requestUrl, "{\"Command\":\"approved\" }",
- requestheaders);
- assertEquals(HttpStatus.SC_CONFLICT, res.getStatusCode());
- checkErrorResponse(res.bodyAsJson(),
- PersoniumCoreException.ReceiveMessage.REQUEST_RELATION_PARSE_ERROR.getCode());
-
- } catch (PersoniumException e) {
- e.printStackTrace();
- } finally {
- // Relation削除
- RelationUtils.delete(Setup.TEST_CELL1, MASTER_TOKEN_NAME, relationName, null, -1);
- // 受信メッセージ削除
- if (locationHeader != null) {
- deleteOdataResource(locationHeader);
- }
- }
- }
-
/**
* 関係登録で不正なRelationTarget名を指定した場合409エラーとなること.
*/
@@ -1272,13 +1898,12 @@ public final void normal_reject_boxbound_build_message() {
body.put("__id", "12345678901234567890123456789012");
body.put("From", UrlUtils.cellRoot(Setup.TEST_CELL2));
body.put("Type", "req.relation.build");
- body.put("Schema", true);
body.put("Title", "Title");
body.put("Body", "Body");
body.put("InReplyTo", "d3330643f57a42fd854558fb0a96a96a");
body.put("Priority", 3);
body.put("Status", "none");
- body.put("RequestRelation", UrlUtils.cellRoot(Setup.TEST_CELL1) + "__relation/__/" + relationName);
+ body.put("RequestRelation", relationName);
body.put("RequestRelationTarget", UrlUtils.cellRoot("('targetCell')"));
String locationHeader = null;
@@ -1303,7 +1928,7 @@ public final void normal_reject_boxbound_build_message() {
requestheaders);
assertEquals(HttpStatus.SC_CONFLICT, res.getStatusCode());
checkErrorResponse(res.bodyAsJson(),
- PersoniumCoreException.ReceiveMessage.REQUEST_RELATION_TARGET_PARSE_ERROR.getCode());
+ PersoniumCoreException.ReceivedMessage.REQUEST_RELATION_TARGET_PARSE_ERROR.getCode());
} catch (PersoniumException e) {
e.printStackTrace();
@@ -1335,7 +1960,7 @@ public final void normal_reject_boxbound_build_message() {
body.put("InReplyTo", "d3330643f57a42fd854558fb0a96a96a");
body.put("Priority", 3);
body.put("Status", "none");
- body.put("RequestRelation", UrlUtils.cellRoot(Setup.TEST_CELL1) + "__relation/__/" + relationName);
+ body.put("RequestRelation", relationName);
body.put("RequestRelationTarget", UrlUtils.cellRoot("targetCell"));
String locationHeader = null;
@@ -1434,7 +2059,7 @@ public final void normal_reject_boxbound_build_message() {
body.put("InReplyTo", "d3330643f57a42fd854558fb0a96a96a");
body.put("Priority", 3);
body.put("Status", "none");
- body.put("RequestRelation", UrlUtils.cellRoot(Setup.TEST_CELL1) + "__relation/__/" + relationName);
+ body.put("RequestRelation", relationName);
body.put("RequestRelationTarget", UrlUtils.cellRoot("targetCell"));
String breakLocationHeader = null;
@@ -1487,7 +2112,7 @@ public final void normal_reject_boxbound_build_message() {
body.put("InReplyTo", "d3330643f57a42fd854558fb0a96a96a");
body.put("Priority", 3);
body.put("Status", "none");
- body.put("RequestRelation", UrlUtils.cellRoot(Setup.TEST_CELL1) + "__relation/__/" + relationName);
+ body.put("RequestRelation", UrlUtils.relationClassUrl(Setup.TEST_CELL_SCHEMA1, relationName));
body.put("RequestRelationTarget", UrlUtils.cellRoot("targetCell"));
String locationHeader = null;
diff --git a/src/test/java/io/personium/test/jersey/cell/MessageEscapeTest.java b/src/test/java/io/personium/test/jersey/cell/MessageEscapeTest.java
index 46369e57f..a798b5617 100644
--- a/src/test/java/io/personium/test/jersey/cell/MessageEscapeTest.java
+++ b/src/test/java/io/personium/test/jersey/cell/MessageEscapeTest.java
@@ -29,8 +29,8 @@
import io.personium.test.categories.Integration;
import io.personium.test.categories.Regression;
import io.personium.test.categories.Unit;
-import io.personium.test.jersey.PersoniumIntegTestRunner;
import io.personium.test.jersey.ODataCommon;
+import io.personium.test.jersey.PersoniumIntegTestRunner;
import io.personium.test.setup.Setup;
import io.personium.test.unit.core.UrlUtils;
import io.personium.test.utils.ReceivedMessageUtils;
@@ -271,7 +271,7 @@ public MessageEscapeTest() {
body.put("Title", "title");
body.put("Body", "body");
body.put("Priority", 3);
- body.put("RequestRelation", UrlUtils.cellRoot("re\\u0000lation"));
+ body.put("RequestRelation", "re\\u0000lation");
body.put("RequestRelationTarget", UrlUtils.cellRoot(targetCell));
TResponse response = null;
@@ -316,7 +316,7 @@ public MessageEscapeTest() {
body.put("Title", "title");
body.put("Body", "body");
body.put("Priority", 3);
- body.put("RequestRelation", UrlUtils.cellRoot(targetCell));
+ body.put("RequestRelation", UrlUtils.relationClassUrl("appCell", "relationName"));
body.put("RequestRelationTarget", UrlUtils.cellRoot("re\\u0000lation"));
TResponse response = null;
diff --git a/src/test/java/io/personium/test/jersey/cell/MessageReceivedTest.java b/src/test/java/io/personium/test/jersey/cell/MessageReceivedTest.java
index 8b7891d81..b043e1fc4 100644
--- a/src/test/java/io/personium/test/jersey/cell/MessageReceivedTest.java
+++ b/src/test/java/io/personium/test/jersey/cell/MessageReceivedTest.java
@@ -16,6 +16,8 @@
*/
package io.personium.test.jersey.cell;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
@@ -364,11 +366,12 @@ public MessageReceivedTest() {
}
/**
- * Schema指定ありでMessageを受信できること.
+ * Normal test.
+ * Received message of type relation.
*/
@SuppressWarnings("unchecked")
@Test
- public final void Schema指定ありでMessageを受信できること() {
+ public final void normal_received_message_of_type_relation() {
String targetCellName = Setup.TEST_CELL1;
String targetRelationName = "testRelation001";
String srcCellName = Setup.TEST_CELL2;
@@ -378,13 +381,13 @@ public MessageReceivedTest() {
body.put("__id", "12345678901234567890123456789012");
body.put("From", UrlUtils.cellRoot(srcCellName));
body.put("Type", "req.relation.build");
- body.put("Schema", UrlUtils.cellRoot(appCellName));
+ body.put("Schema", null);
body.put("Title", "Title");
body.put("Body", "Body");
body.put("InReplyTo", "d3330643f57a42fd854558fb0a96a96a");
body.put("Priority", 3);
body.put("Status", "none");
- body.put("RequestRelation", UrlUtils.cellRoot(targetCellName) + "__relation/__/" + targetRelationName);
+ body.put("RequestRelation", UrlUtils.relationClassUrl(appCellName, targetRelationName));
body.put("RequestRelationTarget", UrlUtils.cellRoot(srcCellName));
TResponse response = null;
@@ -406,12 +409,12 @@ public MessageReceivedTest() {
// ---------------
Map expected = new HashMap();
expected.put("Body", "Body");
- expected.put("_Box.Name", Setup.TEST_BOX1);
+ expected.put("_Box.Name", null);
expected.put("Type", "req.relation.build");
expected.put("Title", "Title");
expected.put("Priority", 3);
expected.put("Status", "none");
- expected.put("RequestRelation", UrlUtils.cellRoot(targetCellName) + "__relation/__/" + targetRelationName);
+ expected.put("RequestRelation", UrlUtils.relationClassUrl(appCellName, targetRelationName));
expected.put("RequestRelationTarget", UrlUtils.cellRoot(srcCellName));
expected.put("InReplyTo", "d3330643f57a42fd854558fb0a96a96a");
expected.put("MulticastTo", null);
@@ -429,6 +432,181 @@ public MessageReceivedTest() {
}
}
+ /**
+ * Error test.
+ * Received message of type relation.
+ * RequestRelation is invalid format.
+ */
+ @SuppressWarnings("unchecked")
+ @Test
+ public final void error_received_message_of_type_relation_requestRelation_invalid_format() {
+ String targetCellName = Setup.TEST_CELL1;
+ String targetRelationName = "testRelation001";
+ String srcCellName = Setup.TEST_CELL2;
+ String appCellName = Setup.TEST_CELL_SCHEMA1;
+
+ JSONObject body = new JSONObject();
+ body.put("__id", "12345678901234567890123456789012");
+ body.put("From", UrlUtils.cellRoot(srcCellName));
+ body.put("Type", "req.relation.build");
+ body.put("Schema", null);
+ body.put("Title", "Title");
+ body.put("Body", "Body");
+ body.put("InReplyTo", "d3330643f57a42fd854558fb0a96a96a");
+ body.put("Priority", 3);
+ body.put("Status", "none");
+ body.put("RequestRelation", UrlUtils.relationUrl(appCellName, "box1", targetRelationName));
+ body.put("RequestRelationTarget", UrlUtils.cellRoot(srcCellName));
+
+ TResponse response = null;
+ try {
+ // ---------------
+ // Preparation
+ // ---------------
+ // Authorizationヘッダ
+ String targetCellUrl = UrlUtils.cellRoot(targetCellName);
+
+ // ---------------
+ // Execution
+ // ---------------
+ response = ReceivedMessageUtils.receive(getCellIssueToken(targetCellUrl), targetCellName,
+ body.toJSONString(), HttpStatus.SC_BAD_REQUEST);
+
+ // ---------------
+ // Verification
+ // ---------------
+ // Check response body
+ PersoniumCoreException exception = PersoniumCoreException.OData.REQUEST_FIELD_FORMAT_ERROR
+ .params("RequestRelation");
+ String message = (String) ((JSONObject) response.bodyAsJson().get("message")).get("value");
+ assertThat(message, is(exception.getMessage()));
+ } finally {
+ if (response != null) {
+ deleteOdataResource(response.getLocationHeader());
+ }
+ }
+ }
+
+ /**
+ * Normal test.
+ * Received schema message.
+ */
+ @SuppressWarnings("unchecked")
+ @Test
+ public final void normal_received_schema_message() {
+ String targetCellName = Setup.TEST_CELL1;
+ String srcCellName = Setup.TEST_CELL2;
+ String appCellName = Setup.TEST_CELL_SCHEMA1;
+
+ JSONObject body = new JSONObject();
+ body.put("__id", "12345678901234567890123456789012");
+ body.put("From", UrlUtils.cellRoot(srcCellName));
+ body.put("Type", "message");
+ body.put("Schema", UrlUtils.cellRoot(appCellName));
+ body.put("Title", "Title");
+ body.put("Body", "Body");
+ body.put("InReplyTo", "d3330643f57a42fd854558fb0a96a96a");
+ body.put("Priority", 3);
+ body.put("Status", "unread");
+ body.put("RequestRelation", null);
+ body.put("RequestRelationTarget", null);
+
+ TResponse response = null;
+ try {
+ // ---------------
+ // Preparation
+ // ---------------
+ // Authorizationヘッダ
+ String targetCellUrl = UrlUtils.cellRoot(targetCellName);
+
+ // ---------------
+ // Execution
+ // ---------------
+ response = ReceivedMessageUtils.receive(getCellIssueToken(targetCellUrl), targetCellName,
+ body.toJSONString(), HttpStatus.SC_CREATED);
+
+ // ---------------
+ // Verification
+ // ---------------
+ Map expected = new HashMap();
+ expected.put("Body", "Body");
+ expected.put("_Box.Name", Setup.TEST_BOX1);
+ expected.put("Type", "message");
+ expected.put("Title", "Title");
+ expected.put("Priority", 3);
+ expected.put("Status", "unread");
+ expected.put("RequestRelation", null);
+ expected.put("RequestRelationTarget", null);
+ expected.put("InReplyTo", "d3330643f57a42fd854558fb0a96a96a");
+ expected.put("MulticastTo", null);
+ expected.put("From", UrlUtils.getBaseUrl() + "/testcell2/");
+
+ // Check response body
+ ODataCommon.checkResponseBody(response.bodyAsJson(), response.getLocationHeader(),
+ "CellCtl.ReceivedMessage", expected);
+ // Verify that the received message is saved
+ ReceivedMessageUtils.get(MASTER_TOKEN_NAME, targetCellName, HttpStatus.SC_OK, (String) body.get("__id"));
+ } finally {
+ if (response != null) {
+ deleteOdataResource(response.getLocationHeader());
+ }
+ }
+ }
+
+ /**
+ * Error test.
+ * Received schema message of type Message.
+ * Box corresponding to the schema does not exist.
+ */
+ @SuppressWarnings("unchecked")
+ @Test
+ public final void error_received_schema_message_box_not_exists() {
+ String targetCellName = Setup.TEST_CELL1;
+ String srcCellName = Setup.TEST_CELL2;
+ String appCellName = "testSchema001";
+
+ JSONObject body = new JSONObject();
+ body.put("__id", "12345678901234567890123456789012");
+ body.put("From", UrlUtils.cellRoot(srcCellName));
+ body.put("Type", "message");
+ body.put("Schema", UrlUtils.cellRoot(appCellName));
+ body.put("Title", "Title");
+ body.put("Body", "Body");
+ body.put("InReplyTo", "d3330643f57a42fd854558fb0a96a96a");
+ body.put("Priority", 3);
+ body.put("Status", "none");
+ body.put("RequestRelation", null);
+ body.put("RequestRelationTarget", null);
+
+ TResponse response = null;
+ try {
+ // ---------------
+ // Preparation
+ // ---------------
+ // Authorizationヘッダ
+ String targetCellUrl = UrlUtils.cellRoot(targetCellName);
+
+ // ---------------
+ // Execution
+ // ---------------
+ response = ReceivedMessageUtils.receive(getCellIssueToken(targetCellUrl), targetCellName,
+ body.toJSONString(), HttpStatus.SC_BAD_REQUEST);
+
+ // ---------------
+ // Verification
+ // ---------------
+ // Check response body
+ PersoniumCoreException exception = PersoniumCoreException.ReceivedMessage.BOX_THAT_MATCHES_SCHEMA_NOT_EXISTS
+ .params(UrlUtils.cellRoot(appCellName));
+ String message = (String) ((JSONObject) response.bodyAsJson().get("message")).get("value");
+ assertThat(message, is(exception.getMessage()));
+ } finally {
+ if (response != null) {
+ deleteOdataResource(response.getLocationHeader());
+ }
+ }
+ }
+
/**
* 受信メッセージの一覧取得ができること.
*/
diff --git a/src/test/java/io/personium/test/jersey/cell/MessageSentTest.java b/src/test/java/io/personium/test/jersey/cell/MessageSentTest.java
index d5fea4574..9379ef58d 100644
--- a/src/test/java/io/personium/test/jersey/cell/MessageSentTest.java
+++ b/src/test/java/io/personium/test/jersey/cell/MessageSentTest.java
@@ -27,14 +27,10 @@
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
-import io.personium.common.utils.PersoniumCoreUtils;
import io.personium.core.PersoniumCoreException;
import io.personium.core.auth.OAuth2Helper;
-import io.personium.core.model.Box;
import io.personium.core.model.ctl.Common;
-import io.personium.core.model.ctl.ExtCell;
import io.personium.core.model.ctl.ReceivedMessagePort;
-import io.personium.core.model.ctl.Relation;
import io.personium.core.model.ctl.SentMessage;
import io.personium.test.categories.Integration;
import io.personium.test.categories.Regression;
@@ -44,6 +40,8 @@
import io.personium.test.jersey.PersoniumIntegTestRunner;
import io.personium.test.setup.Setup;
import io.personium.test.unit.core.UrlUtils;
+import io.personium.test.utils.AccountUtils;
+import io.personium.test.utils.BoxUtils;
import io.personium.test.utils.CellUtils;
import io.personium.test.utils.Http;
import io.personium.test.utils.ReceivedMessageUtils;
@@ -711,6 +709,732 @@ public MessageSentTest() {
}
}
+ /**
+ * Normal test.
+ * Send message of type RelationBuild.
+ * RequestRelation is RelationClassURL.
+ */
+ @SuppressWarnings("unchecked")
+ @Test
+ public final void normal_send_message_of_type_relation_build_relationClassURL() {
+ String targetCellName = Setup.TEST_CELL2;
+ String targetRelationName = "testRelation001";
+ String srcCellName = TEST_CELL1;
+ String appCellName = Setup.TEST_CELL_SCHEMA1;
+
+ // Set request body
+ JSONObject body = new JSONObject();
+ body.put("BoxBound", false);
+ body.put("InReplyTo", null);
+ body.put("To", UrlUtils.cellRoot(targetCellName));
+ body.put("ToRelation", null);
+ body.put("Type", REQ_RELATION_BUILD);
+ body.put("Title", "title");
+ body.put("Body", "body");
+ body.put("Priority", 3);
+ body.put("RequestRelation", UrlUtils.relationClassUrl(appCellName, targetRelationName));
+ body.put("RequestRelationTarget", UrlUtils.cellRoot(srcCellName));
+
+ TResponse response = null;
+ try {
+ // ---------------
+ // Preparation
+ // ---------------
+ String token = MASTER_TOKEN_NAME;
+
+ // ---------------
+ // Execution
+ // ---------------
+ // Send message
+ response = SentMessageUtils.sent(token, srcCellName,
+ body.toJSONString(), HttpStatus.SC_CREATED);
+
+ // ---------------
+ // Verification
+ // ---------------
+ // Set expected response body
+ JSONObject expectedResult = new JSONObject();
+ expectedResult.put("To", UrlUtils.cellRoot(targetCellName));
+ expectedResult.put("Code", Integer.toString(HttpStatus.SC_CREATED));
+ expectedResult.put("Reason", "Created.");
+ JSONArray expectedResults = new JSONArray();
+ expectedResults.add(expectedResult);
+ JSONObject expected = new JSONObject();
+ expected.put("_Box.Name", null);
+ expected.put("InReplyTo", null);
+ expected.put("To", UrlUtils.cellRoot(targetCellName));
+ expected.put("ToRelation", null);
+ expected.put("Type", REQ_RELATION_BUILD);
+ expected.put("Title", "title");
+ expected.put("Body", "body");
+ expected.put("Priority", 3);
+ expected.put("RequestRelation", UrlUtils.relationClassUrl(appCellName, targetRelationName));
+ expected.put("RequestRelationTarget", UrlUtils.cellRoot(srcCellName));
+ expected.put("Result", expectedResults);
+ // Check response body
+ ODataCommon.checkResponseBody(response.bodyAsJson(), response.getLocationHeader(),
+ SENT_MESSAGE_TYPE, expected);
+
+ // Get message id
+ JSONObject results = (JSONObject) ((JSONObject) response.bodyAsJson().get("d")).get("results");
+ String id = (String) results.get("__id");
+ // Verify that the sent message is saved
+ SentMessageUtils.get(MASTER_TOKEN_NAME, srcCellName, HttpStatus.SC_OK, id);
+ // Verify that the received message is saved
+ ReceivedMessageUtils.get(MASTER_TOKEN_NAME, targetCellName, HttpStatus.SC_OK, id);
+ } finally {
+ // Delete sent message
+ if (response != null) {
+ deleteOdataResource(response.getLocationHeader());
+ }
+ // Delete received message
+ deleteReceivedMessage(targetCellName, UrlUtils.cellRoot(srcCellName), REQ_RELATION_BUILD, "title", "body");
+ }
+ }
+
+ /**
+ * Normal test.
+ * Send message of type RelationBuild.
+ * RequestRelation is unit local RelationClassURL.
+ */
+ @SuppressWarnings("unchecked")
+ @Test
+ public final void normal_send_message_of_type_relation_build_unit_local_relationClassURL() {
+ String targetCellName = Setup.TEST_CELL2;
+ String targetRelationName = "testRelation001";
+ String srcCellName = TEST_CELL1;
+ String appCellName = Setup.TEST_CELL_SCHEMA1;
+
+ // Set request body
+ JSONObject body = new JSONObject();
+ body.put("BoxBound", false);
+ body.put("InReplyTo", null);
+ body.put("To", UrlUtils.cellRoot(targetCellName));
+ body.put("ToRelation", null);
+ body.put("Type", REQ_RELATION_BUILD);
+ body.put("Title", "title");
+ body.put("Body", "body");
+ body.put("Priority", 3);
+ body.put("RequestRelation", UrlUtils.unitLocalRelationClassUrl(appCellName, targetRelationName));
+ body.put("RequestRelationTarget", UrlUtils.cellRoot(srcCellName));
+
+ TResponse response = null;
+ try {
+ // ---------------
+ // Preparation
+ // ---------------
+ String token = MASTER_TOKEN_NAME;
+
+ // ---------------
+ // Execution
+ // ---------------
+ // Send message
+ response = SentMessageUtils.sent(token, srcCellName,
+ body.toJSONString(), HttpStatus.SC_CREATED);
+
+ // ---------------
+ // Verification
+ // ---------------
+ // Set expected response body
+ JSONObject expectedResult = new JSONObject();
+ expectedResult.put("To", UrlUtils.cellRoot(targetCellName));
+ expectedResult.put("Code", Integer.toString(HttpStatus.SC_CREATED));
+ expectedResult.put("Reason", "Created.");
+ JSONArray expectedResults = new JSONArray();
+ expectedResults.add(expectedResult);
+ JSONObject expected = new JSONObject();
+ expected.put("_Box.Name", null);
+ expected.put("InReplyTo", null);
+ expected.put("To", UrlUtils.cellRoot(targetCellName));
+ expected.put("ToRelation", null);
+ expected.put("Type", REQ_RELATION_BUILD);
+ expected.put("Title", "title");
+ expected.put("Body", "body");
+ expected.put("Priority", 3);
+ expected.put("RequestRelation", UrlUtils.unitLocalRelationClassUrl(appCellName, targetRelationName));
+ expected.put("RequestRelationTarget", UrlUtils.cellRoot(srcCellName));
+ expected.put("Result", expectedResults);
+ // Check response body
+ ODataCommon.checkResponseBody(response.bodyAsJson(), response.getLocationHeader(),
+ SENT_MESSAGE_TYPE, expected);
+
+ // Get message id
+ JSONObject results = (JSONObject) ((JSONObject) response.bodyAsJson().get("d")).get("results");
+ String id = (String) results.get("__id");
+ // Verify that the sent message is saved
+ SentMessageUtils.get(MASTER_TOKEN_NAME, srcCellName, HttpStatus.SC_OK, id);
+ // Verify that the received message is saved
+ ReceivedMessageUtils.get(MASTER_TOKEN_NAME, targetCellName, HttpStatus.SC_OK, id);
+ } finally {
+ // Delete sent message
+ if (response != null) {
+ deleteOdataResource(response.getLocationHeader());
+ }
+ // Delete received message
+ deleteReceivedMessage(targetCellName, UrlUtils.cellRoot(srcCellName), REQ_RELATION_BUILD, "title", "body");
+ }
+ }
+
+ /**
+ * Normal test.
+ * Send message of type RelationBuild.
+ * RequestRelation is RelationName.
+ */
+ @SuppressWarnings("unchecked")
+ @Test
+ public final void normal_send_message_of_type_relation_build_relationName() {
+ String targetCellName = Setup.TEST_CELL2;
+ String targetRelationName = "testRelation001";
+ String srcCellName = TEST_CELL1;
+
+ // Set request body
+ JSONObject body = new JSONObject();
+ body.put("BoxBound", false);
+ body.put("InReplyTo", null);
+ body.put("To", UrlUtils.cellRoot(targetCellName));
+ body.put("ToRelation", null);
+ body.put("Type", REQ_RELATION_BUILD);
+ body.put("Title", "title");
+ body.put("Body", "body");
+ body.put("Priority", 3);
+ body.put("RequestRelation", targetRelationName);
+ body.put("RequestRelationTarget", UrlUtils.cellRoot(srcCellName));
+
+ TResponse response = null;
+ try {
+ // ---------------
+ // Preparation
+ // ---------------
+ String token = MASTER_TOKEN_NAME;
+
+ // ---------------
+ // Execution
+ // ---------------
+ // Send message
+ response = SentMessageUtils.sent(token, srcCellName,
+ body.toJSONString(), HttpStatus.SC_CREATED);
+
+ // ---------------
+ // Verification
+ // ---------------
+ // Set expected response body
+ JSONObject expectedResult = new JSONObject();
+ expectedResult.put("To", UrlUtils.cellRoot(targetCellName));
+ expectedResult.put("Code", Integer.toString(HttpStatus.SC_CREATED));
+ expectedResult.put("Reason", "Created.");
+ JSONArray expectedResults = new JSONArray();
+ expectedResults.add(expectedResult);
+ JSONObject expected = new JSONObject();
+ expected.put("_Box.Name", null);
+ expected.put("InReplyTo", null);
+ expected.put("To", UrlUtils.cellRoot(targetCellName));
+ expected.put("ToRelation", null);
+ expected.put("Type", REQ_RELATION_BUILD);
+ expected.put("Title", "title");
+ expected.put("Body", "body");
+ expected.put("Priority", 3);
+ expected.put("RequestRelation", targetRelationName);
+ expected.put("RequestRelationTarget", UrlUtils.cellRoot(srcCellName));
+ expected.put("Result", expectedResults);
+ // Check response body
+ ODataCommon.checkResponseBody(response.bodyAsJson(), response.getLocationHeader(),
+ SENT_MESSAGE_TYPE, expected);
+
+ // Get message id
+ JSONObject results = (JSONObject) ((JSONObject) response.bodyAsJson().get("d")).get("results");
+ String id = (String) results.get("__id");
+ // Verify that the sent message is saved
+ SentMessageUtils.get(MASTER_TOKEN_NAME, srcCellName, HttpStatus.SC_OK, id);
+ // Verify that the received message is saved
+ ReceivedMessageUtils.get(MASTER_TOKEN_NAME, targetCellName, HttpStatus.SC_OK, id);
+ } finally {
+ // Delete sent message
+ if (response != null) {
+ deleteOdataResource(response.getLocationHeader());
+ }
+ // Delete received message
+ deleteReceivedMessage(targetCellName, UrlUtils.cellRoot(srcCellName), REQ_RELATION_BUILD, "title", "body");
+ }
+ }
+
+ /**
+ * Error test.
+ * Send message of type RelationBuild.
+ * RequestRelation is invalid format.
+ */
+ @SuppressWarnings("unchecked")
+ @Test
+ public final void error_send_message_of_type_relation_build_requestRelation_invalid_format() {
+ String targetCellName = Setup.TEST_CELL2;
+ String targetRelationName = "testRelation001";
+ String srcCellName = TEST_CELL1;
+ String appCellName = Setup.TEST_CELL_SCHEMA1;
+
+ // Set request body
+ JSONObject body = new JSONObject();
+ body.put("BoxBound", false);
+ body.put("InReplyTo", null);
+ body.put("To", UrlUtils.cellRoot(targetCellName));
+ body.put("ToRelation", null);
+ body.put("Type", REQ_RELATION_BUILD);
+ body.put("Title", "title");
+ body.put("Body", "body");
+ body.put("Priority", 3);
+ body.put("RequestRelation", UrlUtils.relationUrl(appCellName, "box1", targetRelationName));
+ body.put("RequestRelationTarget", UrlUtils.cellRoot(srcCellName));
+
+ TResponse response = null;
+ try {
+ // ---------------
+ // Preparation
+ // ---------------
+ String token = MASTER_TOKEN_NAME;
+
+ // ---------------
+ // Execution
+ // ---------------
+ // Send message
+ response = SentMessageUtils.sent(token, srcCellName,
+ body.toJSONString(), HttpStatus.SC_BAD_REQUEST);
+
+ // ---------------
+ // Verification
+ // ---------------
+ // Check response body
+ PersoniumCoreException exception = PersoniumCoreException.OData.REQUEST_FIELD_FORMAT_ERROR
+ .params("RequestRelation");
+ String message = (String) ((JSONObject) response.bodyAsJson().get("message")).get("value");
+ assertThat(message, is(exception.getMessage()));
+ } finally {
+ // Delete sent message
+ if (response != null) {
+ deleteOdataResource(response.getLocationHeader());
+ }
+ // Delete received message
+ deleteReceivedMessage(targetCellName, UrlUtils.cellRoot(srcCellName), REQ_RELATION_BUILD, "title", "body");
+ }
+ }
+
+ /**
+ * Normal test.
+ * Send message of type RelationBreak.
+ * RequestRelation is RelationClassURL.
+ */
+ @SuppressWarnings("unchecked")
+ @Test
+ public final void normal_send_message_of_type_relation_break_relationClassURL() {
+ String targetCellName = Setup.TEST_CELL2;
+ String targetRelationName = "testRelation001";
+ String srcCellName = TEST_CELL1;
+ String appCellName = Setup.TEST_CELL_SCHEMA1;
+
+ // Set request body
+ JSONObject body = new JSONObject();
+ body.put("BoxBound", false);
+ body.put("InReplyTo", null);
+ body.put("To", UrlUtils.cellRoot(targetCellName));
+ body.put("ToRelation", null);
+ body.put("Type", REQ_RELATION_BREAK);
+ body.put("Title", "title");
+ body.put("Body", "body");
+ body.put("Priority", 3);
+ body.put("RequestRelation", UrlUtils.relationClassUrl(appCellName, targetRelationName));
+ body.put("RequestRelationTarget", UrlUtils.cellRoot(srcCellName));
+
+ TResponse response = null;
+ try {
+ // ---------------
+ // Preparation
+ // ---------------
+ String token = MASTER_TOKEN_NAME;
+
+ // ---------------
+ // Execution
+ // ---------------
+ // Send message
+ response = SentMessageUtils.sent(token, srcCellName,
+ body.toJSONString(), HttpStatus.SC_CREATED);
+
+ // ---------------
+ // Verification
+ // ---------------
+ // Set expected response body
+ JSONObject expectedResult = new JSONObject();
+ expectedResult.put("To", UrlUtils.cellRoot(targetCellName));
+ expectedResult.put("Code", Integer.toString(HttpStatus.SC_CREATED));
+ expectedResult.put("Reason", "Created.");
+ JSONArray expectedResults = new JSONArray();
+ expectedResults.add(expectedResult);
+ JSONObject expected = new JSONObject();
+ expected.put("_Box.Name", null);
+ expected.put("InReplyTo", null);
+ expected.put("To", UrlUtils.cellRoot(targetCellName));
+ expected.put("ToRelation", null);
+ expected.put("Type", REQ_RELATION_BREAK);
+ expected.put("Title", "title");
+ expected.put("Body", "body");
+ expected.put("Priority", 3);
+ expected.put("RequestRelation", UrlUtils.relationClassUrl(appCellName, targetRelationName));
+ expected.put("RequestRelationTarget", UrlUtils.cellRoot(srcCellName));
+ expected.put("Result", expectedResults);
+ // Check response body
+ ODataCommon.checkResponseBody(response.bodyAsJson(), response.getLocationHeader(),
+ SENT_MESSAGE_TYPE, expected);
+
+ // Get message id
+ JSONObject results = (JSONObject) ((JSONObject) response.bodyAsJson().get("d")).get("results");
+ String id = (String) results.get("__id");
+ // Verify that the sent message is saved
+ SentMessageUtils.get(MASTER_TOKEN_NAME, srcCellName, HttpStatus.SC_OK, id);
+ // Verify that the received message is saved
+ ReceivedMessageUtils.get(MASTER_TOKEN_NAME, targetCellName, HttpStatus.SC_OK, id);
+ } finally {
+ // Delete sent message
+ if (response != null) {
+ deleteOdataResource(response.getLocationHeader());
+ }
+ // Delete received message
+ deleteReceivedMessage(targetCellName, UrlUtils.cellRoot(srcCellName), REQ_RELATION_BREAK, "title", "body");
+ }
+ }
+
+ /**
+ * Normal test.
+ * Send message of type RelationBreak.
+ * RequestRelation is unit local RelationClassURL.
+ */
+ @SuppressWarnings("unchecked")
+ @Test
+ public final void normal_send_message_of_type_relation_break_unit_local_relationClassURL() {
+ String targetCellName = Setup.TEST_CELL2;
+ String targetRelationName = "testRelation001";
+ String srcCellName = TEST_CELL1;
+ String appCellName = Setup.TEST_CELL_SCHEMA1;
+
+ // Set request body
+ JSONObject body = new JSONObject();
+ body.put("BoxBound", false);
+ body.put("InReplyTo", null);
+ body.put("To", UrlUtils.cellRoot(targetCellName));
+ body.put("ToRelation", null);
+ body.put("Type", REQ_RELATION_BREAK);
+ body.put("Title", "title");
+ body.put("Body", "body");
+ body.put("Priority", 3);
+ body.put("RequestRelation", UrlUtils.unitLocalRelationClassUrl(appCellName, targetRelationName));
+ body.put("RequestRelationTarget", UrlUtils.cellRoot(srcCellName));
+
+ TResponse response = null;
+ try {
+ // ---------------
+ // Preparation
+ // ---------------
+ String token = MASTER_TOKEN_NAME;
+
+ // ---------------
+ // Execution
+ // ---------------
+ // Send message
+ response = SentMessageUtils.sent(token, srcCellName,
+ body.toJSONString(), HttpStatus.SC_CREATED);
+
+ // ---------------
+ // Verification
+ // ---------------
+ // Set expected response body
+ JSONObject expectedResult = new JSONObject();
+ expectedResult.put("To", UrlUtils.cellRoot(targetCellName));
+ expectedResult.put("Code", Integer.toString(HttpStatus.SC_CREATED));
+ expectedResult.put("Reason", "Created.");
+ JSONArray expectedResults = new JSONArray();
+ expectedResults.add(expectedResult);
+ JSONObject expected = new JSONObject();
+ expected.put("_Box.Name", null);
+ expected.put("InReplyTo", null);
+ expected.put("To", UrlUtils.cellRoot(targetCellName));
+ expected.put("ToRelation", null);
+ expected.put("Type", REQ_RELATION_BREAK);
+ expected.put("Title", "title");
+ expected.put("Body", "body");
+ expected.put("Priority", 3);
+ expected.put("RequestRelation", UrlUtils.unitLocalRelationClassUrl(appCellName, targetRelationName));
+ expected.put("RequestRelationTarget", UrlUtils.cellRoot(srcCellName));
+ expected.put("Result", expectedResults);
+ // Check response body
+ ODataCommon.checkResponseBody(response.bodyAsJson(), response.getLocationHeader(),
+ SENT_MESSAGE_TYPE, expected);
+
+ // Get message id
+ JSONObject results = (JSONObject) ((JSONObject) response.bodyAsJson().get("d")).get("results");
+ String id = (String) results.get("__id");
+ // Verify that the sent message is saved
+ SentMessageUtils.get(MASTER_TOKEN_NAME, srcCellName, HttpStatus.SC_OK, id);
+ // Verify that the received message is saved
+ ReceivedMessageUtils.get(MASTER_TOKEN_NAME, targetCellName, HttpStatus.SC_OK, id);
+ } finally {
+ // Delete sent message
+ if (response != null) {
+ deleteOdataResource(response.getLocationHeader());
+ }
+ // Delete received message
+ deleteReceivedMessage(targetCellName, UrlUtils.cellRoot(srcCellName), REQ_RELATION_BREAK, "title", "body");
+ }
+ }
+
+ /**
+ * Normal test.
+ * Send message of type RelationBreak.
+ * RequestRelation is RelationName.
+ */
+ @SuppressWarnings("unchecked")
+ @Test
+ public final void normal_send_message_of_type_relation_break_relationName() {
+ String targetCellName = Setup.TEST_CELL2;
+ String targetRelationName = "testRelation001";
+ String srcCellName = TEST_CELL1;
+
+ // Set request body
+ JSONObject body = new JSONObject();
+ body.put("BoxBound", false);
+ body.put("InReplyTo", null);
+ body.put("To", UrlUtils.cellRoot(targetCellName));
+ body.put("ToRelation", null);
+ body.put("Type", REQ_RELATION_BREAK);
+ body.put("Title", "title");
+ body.put("Body", "body");
+ body.put("Priority", 3);
+ body.put("RequestRelation", targetRelationName);
+ body.put("RequestRelationTarget", UrlUtils.cellRoot(srcCellName));
+
+ TResponse response = null;
+ try {
+ // ---------------
+ // Preparation
+ // ---------------
+ String token = MASTER_TOKEN_NAME;
+
+ // ---------------
+ // Execution
+ // ---------------
+ // Send message
+ response = SentMessageUtils.sent(token, srcCellName,
+ body.toJSONString(), HttpStatus.SC_CREATED);
+
+ // ---------------
+ // Verification
+ // ---------------
+ // Set expected response body
+ JSONObject expectedResult = new JSONObject();
+ expectedResult.put("To", UrlUtils.cellRoot(targetCellName));
+ expectedResult.put("Code", Integer.toString(HttpStatus.SC_CREATED));
+ expectedResult.put("Reason", "Created.");
+ JSONArray expectedResults = new JSONArray();
+ expectedResults.add(expectedResult);
+ JSONObject expected = new JSONObject();
+ expected.put("_Box.Name", null);
+ expected.put("InReplyTo", null);
+ expected.put("To", UrlUtils.cellRoot(targetCellName));
+ expected.put("ToRelation", null);
+ expected.put("Type", REQ_RELATION_BREAK);
+ expected.put("Title", "title");
+ expected.put("Body", "body");
+ expected.put("Priority", 3);
+ expected.put("RequestRelation", targetRelationName);
+ expected.put("RequestRelationTarget", UrlUtils.cellRoot(srcCellName));
+ expected.put("Result", expectedResults);
+ // Check response body
+ ODataCommon.checkResponseBody(response.bodyAsJson(), response.getLocationHeader(),
+ SENT_MESSAGE_TYPE, expected);
+
+ // Get message id
+ JSONObject results = (JSONObject) ((JSONObject) response.bodyAsJson().get("d")).get("results");
+ String id = (String) results.get("__id");
+ // Verify that the sent message is saved
+ SentMessageUtils.get(MASTER_TOKEN_NAME, srcCellName, HttpStatus.SC_OK, id);
+ // Verify that the received message is saved
+ ReceivedMessageUtils.get(MASTER_TOKEN_NAME, targetCellName, HttpStatus.SC_OK, id);
+ } finally {
+ // Delete sent message
+ if (response != null) {
+ deleteOdataResource(response.getLocationHeader());
+ }
+ // Delete received message
+ deleteReceivedMessage(targetCellName, UrlUtils.cellRoot(srcCellName), REQ_RELATION_BREAK, "title", "body");
+ }
+ }
+
+ /**
+ * Error test.
+ * Send message of type RelationBreak.
+ * RequestRelation is invalid format.
+ */
+ @SuppressWarnings("unchecked")
+ @Test
+ public final void error_send_message_of_type_relation_break_requestRelation_invalid_format() {
+ String targetCellName = Setup.TEST_CELL2;
+ String targetRelationName = "testRelation001";
+ String srcCellName = TEST_CELL1;
+
+ // Set request body
+ JSONObject body = new JSONObject();
+ body.put("BoxBound", false);
+ body.put("InReplyTo", null);
+ body.put("To", UrlUtils.cellRoot(targetCellName));
+ body.put("ToRelation", null);
+ body.put("Type", REQ_RELATION_BREAK);
+ body.put("Title", "title");
+ body.put("Body", "body");
+ body.put("Priority", 3);
+ body.put("RequestRelation", UrlUtils.relationUrl(targetCellName, "box1", targetRelationName));
+ body.put("RequestRelationTarget", UrlUtils.cellRoot(srcCellName));
+
+ TResponse response = null;
+ try {
+ // ---------------
+ // Preparation
+ // ---------------
+ String token = MASTER_TOKEN_NAME;
+
+ // ---------------
+ // Execution
+ // ---------------
+ // Send message
+ response = SentMessageUtils.sent(token, srcCellName,
+ body.toJSONString(), HttpStatus.SC_BAD_REQUEST);
+
+ // ---------------
+ // Verification
+ // ---------------
+ // Check response body
+ PersoniumCoreException exception = PersoniumCoreException.OData.REQUEST_FIELD_FORMAT_ERROR
+ .params("RequestRelation");
+ String message = (String) ((JSONObject) response.bodyAsJson().get("message")).get("value");
+ assertThat(message, is(exception.getMessage()));
+ } finally {
+ // Delete sent message
+ if (response != null) {
+ deleteOdataResource(response.getLocationHeader());
+ }
+ // Delete received message
+ deleteReceivedMessage(targetCellName, UrlUtils.cellRoot(srcCellName), REQ_RELATION_BREAK, "title", "body");
+ }
+ }
+
+ /**
+ * Normal test.
+ * Send BoxBound message of type Message.
+ */
+ @SuppressWarnings("unchecked")
+ @Test
+ public final void normal_send_boxbound_message_of_type_message() {
+ String targetCellName = Setup.TEST_CELL2;
+ String srcCellName = TEST_CELL1;
+ String appCellName = Setup.TEST_CELL_SCHEMA1;
+
+ // Set request body
+ JSONObject body = new JSONObject();
+ body.put("BoxBound", true);
+ body.put("InReplyTo", null);
+ body.put("To", UrlUtils.cellRoot(targetCellName));
+ body.put("ToRelation", null);
+ body.put("Type", MESSAGE);
+ body.put("Title", "title");
+ body.put("Body", "body");
+ body.put("Priority", 3);
+ body.put("RequestRelation", null);
+ body.put("RequestRelationTarget", null);
+
+ TResponse response = null;
+ try {
+ // ---------------
+ // Preparation
+ // ---------------
+ // Create role
+ RoleUtils.create(srcCellName, MASTER_TOKEN_NAME, "testRole001", HttpStatus.SC_CREATED);
+ // Set acl to role
+ Http.request("cell/acl-setting-cell-none-root.txt")
+ .with("url", srcCellName)
+ .with("token", MASTER_TOKEN_NAME)
+ .with("role1", "testRole001")
+ .with("roleBaseUrl", UrlUtils.roleResource(srcCellName, null, "")).returns()
+ .statusCode(HttpStatus.SC_OK);
+ // Set links account and role
+ ResourceUtils.linkAccountRole(srcCellName, MASTER_TOKEN_NAME, "account4", null,
+ "testRole001", HttpStatus.SC_NO_CONTENT);
+
+ // App auth
+ TResponse authnRes = CellUtils.tokenAuthenticationWithTarget(appCellName, "account0",
+ "password0", srcCellName);
+ String appToken = (String) authnRes.bodyAsJson().get(OAuth2Helper.Key.ACCESS_TOKEN);
+ // authz
+ TResponse authzRes = Http.request("authn/password-cl-cp.txt")
+ .with("remoteCell", srcCellName)
+ .with("username", "account4")
+ .with("password", "password4")
+ .with("client_id", UrlUtils.cellRoot(appCellName))
+ .with("client_secret", appToken)
+ .returns()
+ .statusCode(HttpStatus.SC_OK);
+ String token = (String) authzRes.bodyAsJson().get(OAuth2Helper.Key.ACCESS_TOKEN);
+
+ // ---------------
+ // Execution
+ // ---------------
+ // Send message
+ response = SentMessageUtils.sent(token, srcCellName,
+ body.toJSONString(), HttpStatus.SC_CREATED);
+
+ // ---------------
+ // Verification
+ // ---------------
+ // Set expected response body
+ JSONObject expectedResult = new JSONObject();
+ expectedResult.put("To", UrlUtils.cellRoot(targetCellName));
+ expectedResult.put("Code", Integer.toString(HttpStatus.SC_CREATED));
+ expectedResult.put("Reason", "Created.");
+ JSONArray expectedResults = new JSONArray();
+ expectedResults.add(expectedResult);
+ JSONObject expected = new JSONObject();
+ expected.put("_Box.Name", Setup.TEST_BOX1);
+ expected.put("InReplyTo", null);
+ expected.put("To", UrlUtils.cellRoot(targetCellName));
+ expected.put("ToRelation", null);
+ expected.put("Type", MESSAGE);
+ expected.put("Title", "title");
+ expected.put("Body", "body");
+ expected.put("Priority", 3);
+ expected.put("RequestRelation", null);
+ expected.put("RequestRelationTarget", null);
+ expected.put("Result", expectedResults);
+ // Check response body
+ ODataCommon.checkResponseBody(response.bodyAsJson(), response.getLocationHeader(),
+ SENT_MESSAGE_TYPE, expected);
+
+ // Get message id
+ JSONObject results = (JSONObject) ((JSONObject) response.bodyAsJson().get("d")).get("results");
+ String id = (String) results.get("__id");
+ // Verify that the sent message is saved
+ SentMessageUtils.get(MASTER_TOKEN_NAME, srcCellName, HttpStatus.SC_OK, id);
+ // Verify that the received message is saved
+ TResponse receivedResponse = ReceivedMessageUtils.get(
+ MASTER_TOKEN_NAME, targetCellName, HttpStatus.SC_OK, id);
+ // Verify that boxname is stored in the received message
+ results = (JSONObject) ((JSONObject) receivedResponse.bodyAsJson().get("d")).get("results");
+ assertThat((String) results.get("_Box.Name"), is(Setup.TEST_BOX1));
+ } finally {
+ // Delete sent message
+ if (response != null) {
+ deleteOdataResource(response.getLocationHeader());
+ }
+ // Delete received message
+ deleteReceivedMessage(targetCellName, UrlUtils.cellRoot(srcCellName), MESSAGE, "title", "body");
+ // Delete Role and Account $links
+ ResourceUtils.linkAccountRollDelete(srcCellName, MASTER_TOKEN_NAME, "account4", null, "testRole001");
+ // Delete role
+ RoleUtils.delete(srcCellName, MASTER_TOKEN_NAME, null, "testRole001", -1);
+ }
+ }
+
/**
* Normal test.
* Send BoxBound message of type RelationBuild.
@@ -733,7 +1457,7 @@ public final void normal_send_boxbound_message_of_type_relation_build() {
body.put("Title", "title");
body.put("Body", "body");
body.put("Priority", 3);
- body.put("RequestRelation", UrlUtils.cellRoot(targetCellName) + "__relation/__/" + targetRelationName);
+ body.put("RequestRelation", UrlUtils.relationClassUrl(appCellName, targetRelationName));
body.put("RequestRelationTarget", UrlUtils.cellRoot(srcCellName));
TResponse response = null;
@@ -795,7 +1519,7 @@ public final void normal_send_boxbound_message_of_type_relation_build() {
expected.put("Title", "title");
expected.put("Body", "body");
expected.put("Priority", 3);
- expected.put("RequestRelation", UrlUtils.cellRoot(targetCellName) + "__relation/__/" + targetRelationName);
+ expected.put("RequestRelation", UrlUtils.relationClassUrl(appCellName, targetRelationName));
expected.put("RequestRelationTarget", UrlUtils.cellRoot(srcCellName));
expected.put("Result", expectedResults);
// Check response body
@@ -820,15 +1544,6 @@ public final void normal_send_boxbound_message_of_type_relation_build() {
}
// Delete received message
deleteReceivedMessage(targetCellName, UrlUtils.cellRoot(srcCellName), REQ_RELATION_BUILD, "title", "body");
- // Delete ExtCell and Relation $links
- ResourceUtils.linksDelete(targetCellName, Relation.EDM_TYPE_NAME, targetRelationName, Setup.TEST_BOX1,
- ExtCell.EDM_TYPE_NAME, "'" + PersoniumCoreUtils.encodeUrlComp(UrlUtils.cellRoot(srcCellName)) + "'",
- MASTER_TOKEN_NAME);
- // Delete Box and Relation $links
- ResourceUtils.linksDelete(targetCellName, Relation.EDM_TYPE_NAME, targetRelationName, Setup.TEST_BOX1,
- Box.EDM_TYPE_NAME, "Name='" + Setup.TEST_BOX1 + "'", MASTER_TOKEN_NAME);
- // Delete relation
- RelationUtils.delete(targetCellName, MASTER_TOKEN_NAME, targetRelationName, null, -1);
// Delete Role and Account $links
ResourceUtils.linkAccountRollDelete(srcCellName, MASTER_TOKEN_NAME, "account4", null, "testRole001");
// Delete role
@@ -858,7 +1573,7 @@ public final void normal_send_boxbound_message_of_type_relation_break() {
body.put("Title", "title");
body.put("Body", "body");
body.put("Priority", 3);
- body.put("RequestRelation", UrlUtils.cellRoot(targetCellName) + "__relation/__/" + targetRelationName);
+ body.put("RequestRelation", UrlUtils.relationClassUrl(appCellName, targetRelationName));
body.put("RequestRelationTarget", UrlUtils.cellRoot(srcCellName));
TResponse response = null;
@@ -920,7 +1635,7 @@ public final void normal_send_boxbound_message_of_type_relation_break() {
expected.put("Title", "title");
expected.put("Body", "body");
expected.put("Priority", 3);
- expected.put("RequestRelation", UrlUtils.cellRoot(targetCellName) + "__relation/__/" + targetRelationName);
+ expected.put("RequestRelation", UrlUtils.relationClassUrl(appCellName, targetRelationName));
expected.put("RequestRelationTarget", UrlUtils.cellRoot(srcCellName));
expected.put("Result", expectedResults);
// Check response body
@@ -945,15 +1660,232 @@ public final void normal_send_boxbound_message_of_type_relation_break() {
}
// Delete received message
deleteReceivedMessage(targetCellName, UrlUtils.cellRoot(srcCellName), REQ_RELATION_BREAK, "title", "body");
- // Delete ExtCell and Relation $links
- ResourceUtils.linksDelete(targetCellName, Relation.EDM_TYPE_NAME, targetRelationName, Setup.TEST_BOX1,
- ExtCell.EDM_TYPE_NAME, "'" + PersoniumCoreUtils.encodeUrlComp(UrlUtils.cellRoot(srcCellName)) + "'",
- MASTER_TOKEN_NAME);
- // Delete Box and Relation $links
- ResourceUtils.linksDelete(targetCellName, Relation.EDM_TYPE_NAME, targetRelationName, Setup.TEST_BOX1,
- Box.EDM_TYPE_NAME, "Name='" + Setup.TEST_BOX1 + "'", MASTER_TOKEN_NAME);
- // Delete relation
- RelationUtils.delete(targetCellName, MASTER_TOKEN_NAME, targetRelationName, null, -1);
+ // Delete Role and Account $links
+ ResourceUtils.linkAccountRollDelete(srcCellName, MASTER_TOKEN_NAME, "account4", null, "testRole001");
+ // Delete role
+ RoleUtils.delete(srcCellName, MASTER_TOKEN_NAME, null, "testRole001", -1);
+ }
+ }
+
+ /**
+ * Error test.
+ * Send BoxBound message of type Message.
+ * Box corresponding to the schema does not exist on sender.
+ */
+ @SuppressWarnings("unchecked")
+ @Test
+ public final void error_send_boxbound_message_box_not_exists_on_sender() {
+ String targetCellName = Setup.TEST_CELL2;
+ String targetRelationName = "testRelation001";
+ String srcCellName = TEST_CELL1;
+ String appCellName = "testSchema001";
+
+ // Set request body
+ JSONObject body = new JSONObject();
+ body.put("BoxBound", true);
+ body.put("InReplyTo", null);
+ body.put("To", UrlUtils.cellRoot(targetCellName));
+ body.put("ToRelation", null);
+ body.put("Type", MESSAGE);
+ body.put("Title", "title");
+ body.put("Body", "body");
+ body.put("Priority", 3);
+ body.put("RequestRelation", UrlUtils.relationClassUrl(appCellName, targetRelationName));
+ body.put("RequestRelationTarget", UrlUtils.cellRoot(srcCellName));
+
+ TResponse response = null;
+ try {
+ // ---------------
+ // Preparation
+ // ---------------
+ // Create cell
+ CellUtils.create(appCellName, MASTER_TOKEN_NAME, HttpStatus.SC_CREATED);
+ // Create account
+ AccountUtils.create(MASTER_TOKEN_NAME, appCellName, "account0", "password0", HttpStatus.SC_CREATED);
+
+ // Create role
+ RoleUtils.create(srcCellName, MASTER_TOKEN_NAME, "testRole001", HttpStatus.SC_CREATED);
+ // Set acl to role
+ Http.request("cell/acl-setting-cell-none-root.txt")
+ .with("url", srcCellName)
+ .with("token", MASTER_TOKEN_NAME)
+ .with("role1", "testRole001")
+ .with("roleBaseUrl", UrlUtils.roleResource(srcCellName, null, "")).returns()
+ .statusCode(HttpStatus.SC_OK);
+ // Set links account and role
+ ResourceUtils.linkAccountRole(srcCellName, MASTER_TOKEN_NAME, "account4", null,
+ "testRole001", HttpStatus.SC_NO_CONTENT);
+
+ // App auth
+ TResponse authnRes = CellUtils.tokenAuthenticationWithTarget(appCellName, "account0",
+ "password0", srcCellName);
+ String appToken = (String) authnRes.bodyAsJson().get(OAuth2Helper.Key.ACCESS_TOKEN);
+ // authz
+ TResponse authzRes = Http.request("authn/password-cl-cp.txt")
+ .with("remoteCell", srcCellName)
+ .with("username", "account4")
+ .with("password", "password4")
+ .with("client_id", UrlUtils.cellRoot(appCellName))
+ .with("client_secret", appToken)
+ .returns()
+ .statusCode(HttpStatus.SC_OK);
+ String token = (String) authzRes.bodyAsJson().get(OAuth2Helper.Key.ACCESS_TOKEN);
+
+ // ---------------
+ // Execution
+ // ---------------
+ // Send message
+ response = SentMessageUtils.sent(token, srcCellName,
+ body.toJSONString(), HttpStatus.SC_BAD_REQUEST);
+
+ // ---------------
+ // Verification
+ // ---------------
+ // Check response body
+ PersoniumCoreException exception = PersoniumCoreException.SentMessage.BOX_THAT_MATCHES_SCHEMA_NOT_EXISTS
+ .params(UrlUtils.cellRoot(appCellName));
+ String message = (String) ((JSONObject) response.bodyAsJson().get("message")).get("value");
+ assertThat(message, is(exception.getMessage()));
+ } finally {
+ // Delete sent message
+ if (response != null) {
+ deleteOdataResource(response.getLocationHeader());
+ }
+ // Delete received message
+ deleteReceivedMessage(targetCellName, UrlUtils.cellRoot(srcCellName), MESSAGE, "title", "body");
+ // Delete Account
+ AccountUtils.delete(appCellName, MASTER_TOKEN_NAME, "account0", -1);
+ // Delete Cell
+ CellUtils.delete(MASTER_TOKEN_NAME, appCellName, -1);
+ // Delete Role and Account $links
+ ResourceUtils.linkAccountRollDelete(srcCellName, MASTER_TOKEN_NAME, "account4", null, "testRole001");
+ // Delete role
+ RoleUtils.delete(srcCellName, MASTER_TOKEN_NAME, null, "testRole001", -1);
+ }
+ }
+
+ /**
+ * Error test.
+ * Send BoxBound message of type Message.
+ * Box corresponding to the schema does not exist on receiver.
+ */
+ @SuppressWarnings("unchecked")
+ @Test
+ public final void error_send_boxbound_message_box_not_exists_on_receiver() {
+ String targetCellName = Setup.TEST_CELL2;
+ String targetRelationName = "testRelation001";
+ String srcCellName = TEST_CELL1;
+ String appCellName = "testSchema001";
+
+ // Set request body
+ JSONObject body = new JSONObject();
+ body.put("BoxBound", true);
+ body.put("InReplyTo", null);
+ body.put("To", UrlUtils.cellRoot(targetCellName));
+ body.put("ToRelation", null);
+ body.put("Type", MESSAGE);
+ body.put("Title", "title");
+ body.put("Body", "body");
+ body.put("Priority", 3);
+ body.put("RequestRelation", UrlUtils.relationClassUrl(targetCellName, targetRelationName));
+ body.put("RequestRelationTarget", UrlUtils.cellRoot(srcCellName));
+
+ TResponse response = null;
+ try {
+ // ---------------
+ // Preparation
+ // ---------------
+ // Create cell
+ CellUtils.create(appCellName, MASTER_TOKEN_NAME, HttpStatus.SC_CREATED);
+ // Create account
+ AccountUtils.create(MASTER_TOKEN_NAME, appCellName, "account0", "password0", HttpStatus.SC_CREATED);
+
+ // Create box
+ BoxUtils.createWithSchema(srcCellName, "testBox001", MASTER_TOKEN_NAME, UrlUtils.cellRoot(appCellName));
+
+ // Create role
+ RoleUtils.create(srcCellName, MASTER_TOKEN_NAME, "testRole001", HttpStatus.SC_CREATED);
+ // Set acl to role
+ Http.request("cell/acl-setting-cell-none-root.txt")
+ .with("url", srcCellName)
+ .with("token", MASTER_TOKEN_NAME)
+ .with("role1", "testRole001")
+ .with("roleBaseUrl", UrlUtils.roleResource(srcCellName, null, "")).returns()
+ .statusCode(HttpStatus.SC_OK);
+ // Set links account and role
+ ResourceUtils.linkAccountRole(srcCellName, MASTER_TOKEN_NAME, "account4", null,
+ "testRole001", HttpStatus.SC_NO_CONTENT);
+
+ // App auth
+ TResponse authnRes = CellUtils.tokenAuthenticationWithTarget(appCellName, "account0",
+ "password0", srcCellName);
+ String appToken = (String) authnRes.bodyAsJson().get(OAuth2Helper.Key.ACCESS_TOKEN);
+ // authz
+ TResponse authzRes = Http.request("authn/password-cl-cp.txt")
+ .with("remoteCell", srcCellName)
+ .with("username", "account4")
+ .with("password", "password4")
+ .with("client_id", UrlUtils.cellRoot(appCellName))
+ .with("client_secret", appToken)
+ .returns()
+ .statusCode(HttpStatus.SC_OK);
+ String token = (String) authzRes.bodyAsJson().get(OAuth2Helper.Key.ACCESS_TOKEN);
+
+ // ---------------
+ // Execution
+ // ---------------
+ // Send message
+ response = SentMessageUtils.sent(token, srcCellName,
+ body.toJSONString(), HttpStatus.SC_CREATED);
+
+ // ---------------
+ // Verification
+ // ---------------
+ // Set expected response body
+ JSONObject expectedResult = new JSONObject();
+ expectedResult.put("To", UrlUtils.cellRoot(targetCellName));
+ expectedResult.put("Code", Integer.toString(HttpStatus.SC_BAD_REQUEST));
+ PersoniumCoreException exception = PersoniumCoreException.ReceivedMessage.BOX_THAT_MATCHES_SCHEMA_NOT_EXISTS
+ .params(UrlUtils.cellRoot(appCellName));
+ expectedResult.put("Reason", exception.getMessage());
+ JSONArray expectedResults = new JSONArray();
+ expectedResults.add(expectedResult);
+ JSONObject expected = new JSONObject();
+ expected.put("_Box.Name", "testBox001");
+ expected.put("InReplyTo", null);
+ expected.put("To", UrlUtils.cellRoot(targetCellName));
+ expected.put("ToRelation", null);
+ expected.put("Type", MESSAGE);
+ expected.put("Title", "title");
+ expected.put("Body", "body");
+ expected.put("Priority", 3);
+ expected.put("RequestRelation", UrlUtils.relationClassUrl(targetCellName, targetRelationName));
+ expected.put("RequestRelationTarget", UrlUtils.cellRoot(srcCellName));
+ expected.put("Result", expectedResults);
+ // Check response body
+ ODataCommon.checkResponseBody(response.bodyAsJson(), response.getLocationHeader(),
+ SENT_MESSAGE_TYPE, expected);
+
+ // Get message id
+ JSONObject results = (JSONObject) ((JSONObject) response.bodyAsJson().get("d")).get("results");
+ String id = (String) results.get("__id");
+ // Verify that the sent message is saved
+ SentMessageUtils.get(MASTER_TOKEN_NAME, srcCellName, HttpStatus.SC_OK, id);
+ // Verify that the received message is not saved
+ ReceivedMessageUtils.get(MASTER_TOKEN_NAME, targetCellName, HttpStatus.SC_NOT_FOUND, id);
+ } finally {
+ // Delete sent message
+ if (response != null) {
+ deleteOdataResource(response.getLocationHeader());
+ }
+ // Delete received message
+ deleteReceivedMessage(targetCellName, UrlUtils.cellRoot(srcCellName), MESSAGE, "title", "body");
+ // Delete Box
+ BoxUtils.delete(srcCellName, MASTER_TOKEN_NAME, "testBox001", -1);
+ // Delete Account
+ AccountUtils.delete(appCellName, MASTER_TOKEN_NAME, "account0", -1);
+ // Delete Cell
+ CellUtils.delete(MASTER_TOKEN_NAME, appCellName, -1);
// Delete Role and Account $links
ResourceUtils.linkAccountRollDelete(srcCellName, MASTER_TOKEN_NAME, "account4", null, "testRole001");
// Delete role
diff --git a/src/test/java/io/personium/test/jersey/cell/auth/BasicAuthCellLevelTest.java b/src/test/java/io/personium/test/jersey/cell/auth/BasicAuthCellLevelTest.java
index 95c6a9622..1965ebd6d 100644
--- a/src/test/java/io/personium/test/jersey/cell/auth/BasicAuthCellLevelTest.java
+++ b/src/test/java/io/personium/test/jersey/cell/auth/BasicAuthCellLevelTest.java
@@ -93,7 +93,7 @@ public void after() {
String authSchemaAccount = "account0";
String authSchemaPassword = "password0";
- // __auth(スキーマ認証)
+ // __token(スキーマ認証)
PersoniumResponse dcRes = CellUtils.schemaAuthenticateWithBasic(
authTargetCell, "account4", "password4",
authSchemaCell, authSchemaAccount, authSchemaPassword);
@@ -120,7 +120,7 @@ public void after() {
String authSchemaAccount = "account0";
String authSchemaPassword = "password0";
- // __auth(スキーマ認証)
+ // __token(スキーマ認証)
// 認証失敗時:400が返却され、WWW-Authenticateヘッダー(Auth Scheme: Basic)が付与される。
PersoniumResponse dcRes = CellUtils.schemaAuthenticateWithBasic(
authTargetCell, "account4", "invlid_password",
diff --git a/src/test/java/io/personium/test/unit/core/UrlUtils.java b/src/test/java/io/personium/test/unit/core/UrlUtils.java
index ee4ead886..f327ce7d6 100644
--- a/src/test/java/io/personium/test/unit/core/UrlUtils.java
+++ b/src/test/java/io/personium/test/unit/core/UrlUtils.java
@@ -25,6 +25,7 @@
import io.personium.core.model.Box;
import io.personium.core.model.ctl.ReceivedMessage;
import io.personium.core.model.ctl.SentMessage;
+import io.personium.core.utils.UriUtils;
/**
* URLの作成の組立を行う関数群.
@@ -300,7 +301,7 @@ public static String accountLink(final String cellName, final String account, fi
* @return 認証エンドポイントURL
*/
public static String auth(final String cellName) {
- return String.format("%s/%s/__auth", baseUrl, cellName);
+ return String.format("%s/%s/__token", baseUrl, cellName);
}
/**
@@ -474,6 +475,26 @@ public static String relationUrl(final String cellName, final String boxName, fi
return String.format("%s/%s/__ctl/Relation(_Box.Name=%s,Name='%s')", baseUrl, cellName, box, relationName);
}
+ /**
+ * Get RelationClassURL.
+ * @param cellName Cell name
+ * @param relationName Relation name
+ * @return RelationClassURL
+ */
+ public static String relationClassUrl(final String cellName, final String relationName) {
+ return String.format("%s/%s/__relation/__/%s", baseUrl, cellName, relationName);
+ }
+
+ /**
+ * Get unit local RelationClassURL.
+ * @param cellName Cell name
+ * @param relationName Relation name
+ * @return unit local RelationClassURL
+ */
+ public static String unitLocalRelationClassUrl(final String cellName, final String relationName) {
+ return String.format("%s%s/__relation/__/%s", UriUtils.SCHEME_UNIT_URI, cellName, relationName);
+ }
+
/**
* ExtRoleのURL取得.
* @param cellName セル名
diff --git a/src/test/java/io/personium/test/unit/core/rs/odata/validate/ReceivedMessageValidateTest.java b/src/test/java/io/personium/test/unit/core/rs/odata/validate/ReceivedMessageValidateTest.java
index e19f1a005..2a4dce171 100644
--- a/src/test/java/io/personium/test/unit/core/rs/odata/validate/ReceivedMessageValidateTest.java
+++ b/src/test/java/io/personium/test/unit/core/rs/odata/validate/ReceivedMessageValidateTest.java
@@ -339,7 +339,8 @@ public ReceivedMessageValidateTest() {
public final void RequestRelationがURL形式の場合にPersoniumCoreExceptionが発生しないこと() {
this.validateProperty(ReceivedMessage.P_REQUEST_RELATION.build(),
ReceivedMessage.P_REQUEST_RELATION.getName(),
- OProperties.string(ReceivedMessage.P_REQUEST_RELATION.getName(), "http://example.com/test"));
+ OProperties.string(ReceivedMessage.P_REQUEST_RELATION.getName(),
+ "http://example.com/test/__relation/__/testRelation"));
}
/**
@@ -349,7 +350,8 @@ public ReceivedMessageValidateTest() {
public final void RequestRelationがURL形式でない場合にPersoniumCoreExceptionが発生すること() {
this.validateProperty(ReceivedMessage.P_REQUEST_RELATION.build(),
ReceivedMessage.P_REQUEST_RELATION.getName(),
- OProperties.string(ReceivedMessage.P_REQUEST_RELATION.getName(), "ftp://example.com/test"));
+ OProperties.string(ReceivedMessage.P_REQUEST_RELATION.getName(),
+ "ftp://example.com/test/__relation/__/testRelation"));
}
/**
diff --git a/src/test/java/io/personium/test/unit/core/rs/odata/validate/SentMessageValidateTest.java b/src/test/java/io/personium/test/unit/core/rs/odata/validate/SentMessageValidateTest.java
index 503c511a3..0cb1abf22 100644
--- a/src/test/java/io/personium/test/unit/core/rs/odata/validate/SentMessageValidateTest.java
+++ b/src/test/java/io/personium/test/unit/core/rs/odata/validate/SentMessageValidateTest.java
@@ -471,7 +471,8 @@ public SentMessageValidateTest() {
public final void RequestRelationがURL形式の場合にPersoniumCoreExceptionが発生しないこと() {
this.validateProperty(SentMessage.P_REQUEST_RELATION.build(),
SentMessage.P_REQUEST_RELATION.getName(),
- OProperties.string(SentMessage.P_REQUEST_RELATION.getName(), "http://example.com/test"));
+ OProperties.string(SentMessage.P_REQUEST_RELATION.getName(),
+ "http://example.com/test/__relation/__/testRelation"));
}
/**
@@ -481,7 +482,8 @@ public SentMessageValidateTest() {
public final void RequestRelationがURL形式でない場合にPersoniumCoreExceptionが発生すること() {
this.validateProperty(SentMessage.P_REQUEST_RELATION.build(),
SentMessage.P_REQUEST_RELATION.getName(),
- OProperties.string(SentMessage.P_REQUEST_RELATION.getName(), "ftp://example.com/test"));
+ OProperties.string(SentMessage.P_REQUEST_RELATION.getName(),
+ "ftp://example.com/test/__relation/__/testRelation"));
}
/**
diff --git a/src/test/java/io/personium/test/utils/CellUtils.java b/src/test/java/io/personium/test/utils/CellUtils.java
index f1bb48e68..c0f088da1 100644
--- a/src/test/java/io/personium/test/utils/CellUtils.java
+++ b/src/test/java/io/personium/test/utils/CellUtils.java
@@ -660,7 +660,7 @@ public static PersoniumResponse schemaAuthenticateWithBasic(
requestheaders.put(HttpHeaders.AUTHORIZATION, authorization);
String body = String.format("grant_type=password&username=%s&password=%s", account, password);
- return rest.post(UrlUtils.cellRoot(cellName) + "__auth", body, requestheaders);
+ return rest.post(UrlUtils.cellRoot(cellName) + "__token", body, requestheaders);
}
/**
diff --git a/src/test/resources/request/authn/auth-with-header.txt b/src/test/resources/request/authn/auth-with-header.txt
index c4234a77d..933194003 100644
--- a/src/test/resources/request/authn/auth-with-header.txt
+++ b/src/test/resources/request/authn/auth-with-header.txt
@@ -1,4 +1,4 @@
-POST /${remoteCell}/__auth HTTP/1.1
+POST /${remoteCell}/__token HTTP/1.1
Host: ?
Accept: application/json
Content-Type: application/x-www-form-urlencoded
diff --git a/src/test/resources/request/authn/auth.txt b/src/test/resources/request/authn/auth.txt
index 410ccf002..b28abb13d 100644
--- a/src/test/resources/request/authn/auth.txt
+++ b/src/test/resources/request/authn/auth.txt
@@ -1,4 +1,4 @@
-POST /${remoteCell}/__auth HTTP/1.1
+POST /${remoteCell}/__token HTTP/1.1
Host: ?
Content-Type: application/x-www-form-urlencoded
Content-Length: ?
diff --git a/src/test/resources/request/authn/issue-cookie-for-refreshToken.txt b/src/test/resources/request/authn/issue-cookie-for-refreshToken.txt
index 8fa66c0d3..13be4a1f4 100644
--- a/src/test/resources/request/authn/issue-cookie-for-refreshToken.txt
+++ b/src/test/resources/request/authn/issue-cookie-for-refreshToken.txt
@@ -1,8 +1,8 @@
-POST /${remoteCell}/__auth HTTP/1.1
-Host: ?
-Content-Type: application/x-www-form-urlencoded
-Content-Length: ?
-Accept: application/json
-Connection: close
-
+POST /${remoteCell}/__token HTTP/1.1
+Host: ?
+Content-Type: application/x-www-form-urlencoded
+Content-Length: ?
+Accept: application/json
+Connection: close
+
grant_type=refresh_token&refresh_token=${refresh_token}&p_cookie=true
\ No newline at end of file
diff --git a/src/test/resources/request/authn/issue-cookie-with-saml.txt b/src/test/resources/request/authn/issue-cookie-with-saml.txt
index 18ecaf880..f944e349c 100644
--- a/src/test/resources/request/authn/issue-cookie-with-saml.txt
+++ b/src/test/resources/request/authn/issue-cookie-with-saml.txt
@@ -1,4 +1,4 @@
-POST /${remoteCell}/__auth HTTP/1.1
+POST /${remoteCell}/__token HTTP/1.1
Host: ?
Content-Type: application/x-www-form-urlencoded
Content-Length: ?
diff --git a/src/test/resources/request/authn/issue-cookie-with-target.txt b/src/test/resources/request/authn/issue-cookie-with-target.txt
index b04e3da08..e0bd57924 100644
--- a/src/test/resources/request/authn/issue-cookie-with-target.txt
+++ b/src/test/resources/request/authn/issue-cookie-with-target.txt
@@ -1,4 +1,4 @@
-POST /${remoteCell}/__auth HTTP/1.1
+POST /${remoteCell}/__token HTTP/1.1
Host: ?
Content-Type: application/x-www-form-urlencoded
Content-Length: ?
diff --git a/src/test/resources/request/authn/issue-cookie-without-target.txt b/src/test/resources/request/authn/issue-cookie-without-target.txt
index ca2c5923a..b9b45516c 100644
--- a/src/test/resources/request/authn/issue-cookie-without-target.txt
+++ b/src/test/resources/request/authn/issue-cookie-without-target.txt
@@ -1,7 +1,7 @@
-POST /${remoteCell}/__auth HTTP/1.1
-Host: ?
-Content-Type: application/x-www-form-urlencoded
-Content-Length: ?
-Connection: close
-
+POST /${remoteCell}/__token HTTP/1.1
+Host: ?
+Content-Type: application/x-www-form-urlencoded
+Content-Length: ?
+Connection: close
+
grant_type=password&username=${username}&password=${password}&p_cookie=${p_cookie}
\ No newline at end of file
diff --git a/src/test/resources/request/authn/oidc-auth.txt b/src/test/resources/request/authn/oidc-auth.txt
index 286fe4d62..970ae4418 100644
--- a/src/test/resources/request/authn/oidc-auth.txt
+++ b/src/test/resources/request/authn/oidc-auth.txt
@@ -1,4 +1,4 @@
-POST /${remoteCell}/__auth HTTP/1.1
+POST /${remoteCell}/__token HTTP/1.1
Host: ?
Content-Type: application/x-www-form-urlencoded
Content-Length: ?
diff --git a/src/test/resources/request/authn/password-cl-c0-no-password.txt b/src/test/resources/request/authn/password-cl-c0-no-password.txt
index b6ed29384..8d4653b11 100644
--- a/src/test/resources/request/authn/password-cl-c0-no-password.txt
+++ b/src/test/resources/request/authn/password-cl-c0-no-password.txt
@@ -1,4 +1,4 @@
-POST /${remoteCell}/__auth HTTP/1.1
+POST /${remoteCell}/__token HTTP/1.1
Host: ?
Content-Type: application/x-www-form-urlencoded
Content-Length: ?
diff --git a/src/test/resources/request/authn/password-cl-c0.txt b/src/test/resources/request/authn/password-cl-c0.txt
index 2a59735ff..02753deda 100644
--- a/src/test/resources/request/authn/password-cl-c0.txt
+++ b/src/test/resources/request/authn/password-cl-c0.txt
@@ -1,4 +1,4 @@
-POST /${remoteCell}/__auth HTTP/1.1
+POST /${remoteCell}/__token HTTP/1.1
Host: ?
Content-Type: application/x-www-form-urlencoded
Content-Length: ?
diff --git a/src/test/resources/request/authn/password-cl-ch.txt b/src/test/resources/request/authn/password-cl-ch.txt
index e80da84e9..9bca663bd 100644
--- a/src/test/resources/request/authn/password-cl-ch.txt
+++ b/src/test/resources/request/authn/password-cl-ch.txt
@@ -1,4 +1,4 @@
-POST /${remoteCell}/__auth HTTP/1.1
+POST /${remoteCell}/__token HTTP/1.1
Host: ?
Accept: application/json
Content-Type: application/x-www-form-urlencoded
diff --git a/src/test/resources/request/authn/password-cl-cp.txt b/src/test/resources/request/authn/password-cl-cp.txt
index 1624e5690..dbee043f9 100644
--- a/src/test/resources/request/authn/password-cl-cp.txt
+++ b/src/test/resources/request/authn/password-cl-cp.txt
@@ -1,4 +1,4 @@
-POST /${remoteCell}/__auth HTTP/1.1
+POST /${remoteCell}/__token HTTP/1.1
Host: ?
Accept: application/json
Content-Type: application/x-www-form-urlencoded
diff --git a/src/test/resources/request/authn/password-cl-with-bearerheader.txt b/src/test/resources/request/authn/password-cl-with-bearerheader.txt
index 4a55021a4..5ff1fd58b 100644
--- a/src/test/resources/request/authn/password-cl-with-bearerheader.txt
+++ b/src/test/resources/request/authn/password-cl-with-bearerheader.txt
@@ -1,9 +1,9 @@
-POST /${remoteCell}/__auth HTTP/1.1
-Host: ?
-Content-Type: application/x-www-form-urlencoded
-Content-Length: ?
-Accept: application/json
-Authorization: Bearer ${Authorization_token}
-Connection: close
-
+POST /${remoteCell}/__token HTTP/1.1
+Host: ?
+Content-Type: application/x-www-form-urlencoded
+Content-Length: ?
+Accept: application/json
+Authorization: Bearer ${Authorization_token}
+Connection: close
+
grant_type=password&username=${username}&password=${password}
\ No newline at end of file
diff --git a/src/test/resources/request/authn/password-tc-c0.txt b/src/test/resources/request/authn/password-tc-c0.txt
index 576514a44..ca4cc194c 100644
--- a/src/test/resources/request/authn/password-tc-c0.txt
+++ b/src/test/resources/request/authn/password-tc-c0.txt
@@ -1,4 +1,4 @@
-POST /${remoteCell}/__auth HTTP/1.1
+POST /${remoteCell}/__token HTTP/1.1
Host: ?
Accept: application/json
Content-Type: application/xml
diff --git a/src/test/resources/request/authn/password-tc-ch.txt b/src/test/resources/request/authn/password-tc-ch.txt
index 7bb4f371c..723bc218d 100644
--- a/src/test/resources/request/authn/password-tc-ch.txt
+++ b/src/test/resources/request/authn/password-tc-ch.txt
@@ -1,4 +1,4 @@
-POST /${remoteCell}/__auth HTTP/1.1
+POST /${remoteCell}/__token HTTP/1.1
Host: ?
Content-Type: application/x-www-form-urlencoded
Content-Length: ?
diff --git a/src/test/resources/request/authn/password-tc-cp.txt b/src/test/resources/request/authn/password-tc-cp.txt
index 64859c8f5..f4cb53817 100644
--- a/src/test/resources/request/authn/password-tc-cp.txt
+++ b/src/test/resources/request/authn/password-tc-cp.txt
@@ -1,4 +1,4 @@
-POST /${remoteCell}/__auth HTTP/1.1
+POST /${remoteCell}/__token HTTP/1.1
Host: ?
Content-Type: application/x-www-form-urlencoded
Content-Length: ?
diff --git a/src/test/resources/request/authn/plugin-oidc-auth.txt b/src/test/resources/request/authn/plugin-oidc-auth.txt
index 2a00bada3..970ae4418 100644
--- a/src/test/resources/request/authn/plugin-oidc-auth.txt
+++ b/src/test/resources/request/authn/plugin-oidc-auth.txt
@@ -1,7 +1,7 @@
-POST /${remoteCell}/__auth HTTP/1.1
-Host: ?
-Content-Type: application/x-www-form-urlencoded
-Content-Length: ?
-Connection: close
-
+POST /${remoteCell}/__token HTTP/1.1
+Host: ?
+Content-Type: application/x-www-form-urlencoded
+Content-Length: ?
+Connection: close
+
grant_type=urn:x-personium:oidc:${id_provider}&id_token=${id_token}
\ No newline at end of file
diff --git a/src/test/resources/request/authn/refresh-cl-with-bearerheader.txt b/src/test/resources/request/authn/refresh-cl-with-bearerheader.txt
index 388c68917..7a5ef7f3c 100644
--- a/src/test/resources/request/authn/refresh-cl-with-bearerheader.txt
+++ b/src/test/resources/request/authn/refresh-cl-with-bearerheader.txt
@@ -1,9 +1,9 @@
-POST /${remoteCell}/__auth HTTP/1.1
-Host: ?
-Content-Type: application/x-www-form-urlencoded
-Content-Length: ?
-Accept: application/json
-Authorization: Bearer ${Authorization_token}
-Connection: close
-
+POST /${remoteCell}/__token HTTP/1.1
+Host: ?
+Content-Type: application/x-www-form-urlencoded
+Content-Length: ?
+Accept: application/json
+Authorization: Bearer ${Authorization_token}
+Connection: close
+
grant_type=refresh_token&refresh_token=${refresh_token}
\ No newline at end of file
diff --git a/src/test/resources/request/authn/refresh-cl.txt b/src/test/resources/request/authn/refresh-cl.txt
index d4b3d65e8..ff0c457e0 100644
--- a/src/test/resources/request/authn/refresh-cl.txt
+++ b/src/test/resources/request/authn/refresh-cl.txt
@@ -1,4 +1,4 @@
-POST /${remoteCell}/__auth HTTP/1.1
+POST /${remoteCell}/__token HTTP/1.1
Host: ?
Content-Type: application/x-www-form-urlencoded
Content-Length: ?
diff --git a/src/test/resources/request/authn/refresh-tc.txt b/src/test/resources/request/authn/refresh-tc.txt
index ee8f09cdd..2fef0b9fd 100644
--- a/src/test/resources/request/authn/refresh-tc.txt
+++ b/src/test/resources/request/authn/refresh-tc.txt
@@ -1,4 +1,4 @@
-POST /${remoteCell}/__auth HTTP/1.1
+POST /${remoteCell}/__token HTTP/1.1
Host: ?
Content-Type: application/x-www-form-urlencoded
Content-Length: ?
diff --git a/src/test/resources/request/authn/saml-cl-c0.txt b/src/test/resources/request/authn/saml-cl-c0.txt
index a4bad0544..59b01f8e4 100644
--- a/src/test/resources/request/authn/saml-cl-c0.txt
+++ b/src/test/resources/request/authn/saml-cl-c0.txt
@@ -1,4 +1,4 @@
-POST /${remoteCell}/__auth HTTP/1.1
+POST /${remoteCell}/__token HTTP/1.1
Host: ?
Content-Type: application/x-www-form-urlencoded
Content-Length: ?
diff --git a/src/test/resources/request/authn/saml-cl-ch.txt b/src/test/resources/request/authn/saml-cl-ch.txt
index 57e727945..b78338e81 100644
--- a/src/test/resources/request/authn/saml-cl-ch.txt
+++ b/src/test/resources/request/authn/saml-cl-ch.txt
@@ -1,4 +1,4 @@
-POST /${remoteCell}/__auth HTTP/1.1
+POST /${remoteCell}/__token HTTP/1.1
Host: ?
Content-Type: application/x-www-form-urlencoded
Content-Length: ?
diff --git a/src/test/resources/request/authn/saml-cl-cp.txt b/src/test/resources/request/authn/saml-cl-cp.txt
index b28947a08..6fc084925 100644
--- a/src/test/resources/request/authn/saml-cl-cp.txt
+++ b/src/test/resources/request/authn/saml-cl-cp.txt
@@ -1,4 +1,4 @@
-POST /${remoteCell}/__auth HTTP/1.1
+POST /${remoteCell}/__token HTTP/1.1
Host: ?
Content-Type: application/x-www-form-urlencoded
Content-Length: ?
diff --git a/src/test/resources/request/authn/saml-cl-with-bearerheader.txt b/src/test/resources/request/authn/saml-cl-with-bearerheader.txt
index e2be18027..d31585efb 100644
--- a/src/test/resources/request/authn/saml-cl-with-bearerheader.txt
+++ b/src/test/resources/request/authn/saml-cl-with-bearerheader.txt
@@ -1,4 +1,4 @@
-POST /${remoteCell}/__auth HTTP/1.1
+POST /${remoteCell}/__token HTTP/1.1
Host: ?
Content-Type: application/x-www-form-urlencoded
Content-Length: ?
diff --git a/src/test/resources/request/authn/saml-tc-c0.txt b/src/test/resources/request/authn/saml-tc-c0.txt
index c4bb6bb79..16e3169e7 100644
--- a/src/test/resources/request/authn/saml-tc-c0.txt
+++ b/src/test/resources/request/authn/saml-tc-c0.txt
@@ -1,4 +1,4 @@
-POST /${remoteCell}/__auth HTTP/1.1
+POST /${remoteCell}/__token HTTP/1.1
Host: ?
Content-Type: application/x-www-form-urlencoded
Content-Length: ?
diff --git a/src/test/resources/request/authn/saml-tc-ch.txt b/src/test/resources/request/authn/saml-tc-ch.txt
index 672d4e8ad..92a0d363f 100644
--- a/src/test/resources/request/authn/saml-tc-ch.txt
+++ b/src/test/resources/request/authn/saml-tc-ch.txt
@@ -1,4 +1,4 @@
-POST /${remoteCell}/__auth HTTP/1.1
+POST /${remoteCell}/__token HTTP/1.1
Host: ?
Content-Type: application/x-www-form-urlencoded
Content-Length: ?
diff --git a/src/test/resources/request/authn/saml-tc-cp.txt b/src/test/resources/request/authn/saml-tc-cp.txt
index af6cbb2ba..5b091120b 100644
--- a/src/test/resources/request/authn/saml-tc-cp.txt
+++ b/src/test/resources/request/authn/saml-tc-cp.txt
@@ -1,4 +1,4 @@
-POST /${remoteCell}/__auth HTTP/1.1
+POST /${remoteCell}/__token HTTP/1.1
Host: ?
Content-Type: application/x-www-form-urlencoded
Content-Length: ?
diff --git a/src/test/resources/request/authnUnit/password-uluut.txt b/src/test/resources/request/authnUnit/password-uluut.txt
index d5b6239fc..5a4275284 100644
--- a/src/test/resources/request/authnUnit/password-uluut.txt
+++ b/src/test/resources/request/authnUnit/password-uluut.txt
@@ -1,4 +1,4 @@
-POST /${remoteCell}/__auth HTTP/1.1
+POST /${remoteCell}/__token HTTP/1.1
Host: ?
Content-Type: application/x-www-form-urlencoded
Content-Length: ?
diff --git a/src/test/resources/request/authnUnit/refresh-uluut.txt b/src/test/resources/request/authnUnit/refresh-uluut.txt
index b927d860d..b034812f7 100644
--- a/src/test/resources/request/authnUnit/refresh-uluut.txt
+++ b/src/test/resources/request/authnUnit/refresh-uluut.txt
@@ -1,4 +1,4 @@
-POST /${remoteCell}/__auth HTTP/1.1
+POST /${remoteCell}/__token HTTP/1.1
Host: ?
Content-Type: application/x-www-form-urlencoded
Content-Length: ?
diff --git a/src/test/resources/request/authnUnit/saml-uluut.txt b/src/test/resources/request/authnUnit/saml-uluut.txt
index f21ccf005..714639ecc 100644
--- a/src/test/resources/request/authnUnit/saml-uluut.txt
+++ b/src/test/resources/request/authnUnit/saml-uluut.txt
@@ -1,4 +1,4 @@
-POST /${remoteCell}/__auth HTTP/1.1
+POST /${remoteCell}/__token HTTP/1.1
Host: ?
Content-Type: application/x-www-form-urlencoded
Content-Length: ?