com.fujitsu.dc.test.utils.UserDataUtils.java Source code

Java tutorial

Introduction

Here is the source code for com.fujitsu.dc.test.utils.UserDataUtils.java

Source

/**
 * 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 com.fujitsu.dc.test.utils;

import static org.junit.Assert.assertEquals;

import javax.ws.rs.core.MediaType;

import org.apache.commons.codec.binary.Base64;
import org.apache.http.HttpHeaders;
import org.apache.http.HttpStatus;
import org.json.simple.JSONObject;

import com.fujitsu.dc.core.DcCoreConfig;
import com.fujitsu.dc.test.jersey.AbstractCase;
import com.fujitsu.dc.test.jersey.DcRequest;
import com.fujitsu.dc.test.jersey.DcResponse;
import com.fujitsu.dc.test.jersey.box.odatacol.schema.complextypeproperty.ComplexTypePropertyUtils;
import com.fujitsu.dc.test.jersey.box.odatacol.schema.property.PropertyUtils;
import com.fujitsu.dc.test.setup.Setup;
import com.fujitsu.dc.test.unit.core.UrlUtils;

/**
 * Odata?Http?.
 */
public class UserDataUtils {
    private static final int NUMBER_FOR_CREATESTRING = 10;

    private UserDataUtils() {
    }

    /**
     * ComplexType??.
     * @param cellName ??
     * @param boxName ??
     * @param odataSvcPath Odata??
     * @param complexTypeName ??
     * @return ?
     */
    public static DcResponse createComplexType(final String cellName, final String boxName,
            final String odataSvcPath, final String complexTypeName) {
        // 
        DcRequest req = DcRequest.post(UrlUtils.complexType(cellName, boxName, odataSvcPath, null));
        req.header(HttpHeaders.AUTHORIZATION, AbstractCase.BEARER_MASTER_TOKEN);
        req.addJsonBody("Name", complexTypeName);

        // 
        return AbstractCase.request(req);
    }

    /**
     * Property??.
     * @param cellName ??
     * @param boxName ??
     * @param odataSvcPath Odata??
     * @param propName ??
     * @param entityTypeName ??
     * @param type 
     * @param nullable Null?
     * @param defaultValue 
     * @param collectionKind ?
     * @param isKey 
     * @param uniqueKey 
     * @return ?
     */
    public static DcResponse createProperty(final String cellName, final String boxName, final String odataSvcPath,
            final String propName, final String entityTypeName, final String type, final boolean nullable,
            final String defaultValue, final String collectionKind, final boolean isKey, final String uniqueKey) {
        // 
        DcRequest req = DcRequest.post(UrlUtils.property(cellName, boxName, odataSvcPath, null, null));
        req.header(HttpHeaders.AUTHORIZATION, AbstractCase.BEARER_MASTER_TOKEN);
        req.addJsonBody(PropertyUtils.PROPERTY_NAME_KEY, propName);
        req.addJsonBody(PropertyUtils.PROPERTY_ENTITYTYPE_NAME_KEY, entityTypeName);
        req.addJsonBody(PropertyUtils.PROPERTY_TYPE_KEY, type);
        req.addJsonBody(PropertyUtils.PROPERTY_NULLABLE_KEY, nullable);
        req.addJsonBody(PropertyUtils.PROPERTY_DEFAULT_VALUE_KEY, defaultValue);
        req.addJsonBody(PropertyUtils.PROPERTY_COLLECTION_KIND_KEY, collectionKind);
        req.addJsonBody(PropertyUtils.PROPERTY_IS_KEY_KEY, isKey);
        req.addJsonBody(PropertyUtils.PROPERTY_UNIQUE_KEY_KEY, uniqueKey);

        // 
        return AbstractCase.request(req);
    }

    /**
     * ComplexTypeProperty??.
     * @param cellName ??
     * @param boxName ??
     * @param odataSvcPath Odata??
     * @param propName ??
     * @param complexTypeName ??
     * @param type 
     * @param nullable Null?
     * @param defaultValue 
     * @param collectionKind ?
     * @return ?
     */
    public static DcResponse createComplexTypeProperty(final String cellName, final String boxName,
            final String odataSvcPath, final String propName, final String complexTypeName, final String type,
            final boolean nullable, final String defaultValue, final String collectionKind) {
        // 
        DcRequest req = DcRequest.post(UrlUtils.complexTypeProperty(cellName, boxName, odataSvcPath, null, null));
        req.header(HttpHeaders.AUTHORIZATION, AbstractCase.BEARER_MASTER_TOKEN);
        req.addJsonBody(ComplexTypePropertyUtils.CT_PROPERTY_NAME_KEY, propName);
        req.addJsonBody(ComplexTypePropertyUtils.CT_PROPERTY_COMPLEXTYPE_NAME_KEY, complexTypeName);
        req.addJsonBody(ComplexTypePropertyUtils.CT_PROPERTY_TYPE_KEY, type);
        req.addJsonBody(ComplexTypePropertyUtils.CT_PROPERTY_NULLABLE_KEY, nullable);
        req.addJsonBody(ComplexTypePropertyUtils.CT_PROPERTY_DEFAULT_VALUE_KEY, defaultValue);
        req.addJsonBody(ComplexTypePropertyUtils.CT_PROPERTY_COLLECTION_KIND_KEY, collectionKind);

        // 
        return AbstractCase.request(req);
    }

    /**
     * ???????.
     * @param token 
     * @param code ??
     * @return ?
     */
    public static TResponse get(String token, int code) {
        TResponse res = Http.request("box/odatacol/get.txt").with("cell", "testcell1").with("box", "box1")
                .with("collection", "setodata").with("entityType", "Price").with("id", "auth_test")
                .with("accept", MediaType.APPLICATION_JSON).with("token", token).with("query", "").returns()
                .statusCode(code).debug();
        return res;
    }

    /**
     * ???????.
     * @param cellName Cell??
     * @param token 
     * @param boxName Box??
     * @param colName OData??
     * @param entTypeName EntityType??
     * @param id ID
     * @param code ??
     * @return ?
     */
    public static TResponse get(final String cellName, final String token, final String boxName,
            final String colName, final String entTypeName, String id, int code) {
        return getWithQuery(cellName, token, boxName, colName, entTypeName, "", id, code);
    }

    /**
     * ???????.
     * @param cellName Cell??
     * @param token 
     * @param boxName Box??
     * @param colName OData??
     * @param entTypeName EntityType??
     * @param query 
     * @param id ID
     * @param code ??
     * @return ?
     */
    public static TResponse getWithQuery(final String cellName, final String token, final String boxName,
            final String colName, final String entTypeName, final String query, String id, int code) {
        TResponse res = Http.request("box/odatacol/get.txt").with("cell", cellName).with("box", boxName)
                .with("collection", colName).with("entityType", entTypeName).with("id", id)
                .with("accept", MediaType.APPLICATION_JSON).with("token", token).with("query", query).returns()
                .statusCode(code).debug();
        return res;
    }

    /**
     * ???????.
     * @param cellName Cell??
     * @param token (??)
     * @param boxName Box??
     * @param colName OData??
     * @param entTypeName EntityType??
     * @param query 
     * @param id ID
     * @param code ??
     * @return ?
     */
    public static TResponse getWithQueryAnyAuthSchema(final String cellName, final String token,
            final String boxName, final String colName, final String entTypeName, final String query, String id,
            int code) {
        TResponse res = Http.request("box/odatacol/get-anyAuthSchema.txt").with("cell", cellName)
                .with("box", boxName).with("collection", colName).with("entityType", entTypeName).with("id", id)
                .with("accept", MediaType.APPLICATION_JSON).with("token", token).with("query", query).returns()
                .statusCode(code).debug();
        return res;
    }

    /**
     * ???????.
     * @param token 
     * @param code ??
     * @return ?
     */
    public static TResponse list(String token, int code) {
        return list(token, "", code);
    }

    /**
     * ???????.
     * @param token 
     * @param query 
     * @param code ??
     * @return ?
     */
    public static TResponse list(String token, String query, int code) {
        return list("testcell1", "box1", "setodata", "Category", query, token, code);
    }

    /**
     * ??.
     * @param cell ??
     * @param box ??
     * @param col ??
     * @param entityType ??
     * @param query 
     * @param token 
     * @param code ??
     * @return ?
     */
    public static TResponse list(String cell, String box, String col, String entityType, String query, String token,
            int code) {
        TResponse response = Http.request("box/odatacol/list.txt").with("cell", cell).with("box", box)
                .with("collection", col).with("entityType", entityType).with("query", query)
                .with("accept", MediaType.APPLICATION_JSON).with("token", token).returns().statusCode(code).debug();
        return response;
    }

    /**
     * ??.
     * @param cell ??
     * @param box ??
     * @param col ??
     * @param entityType ??
     * @param query 
     * @param token (??)
     * @param code ??
     * @return ?
     */
    public static TResponse listAnyAuthSchema(String cell, String box, String col, String entityType, String query,
            String token, int code) {
        TResponse response = Http.request("box/odatacol/list-anyAuthSchema.txt").with("cell", cell).with("box", box)
                .with("collection", col).with("entityType", entityType).with("query", query)
                .with("accept", MediaType.APPLICATION_JSON).with("token", token).returns().statusCode(code).debug();
        return response;
    }

    /**
     * ??.
     * @param cell ??
     * @param box ??
     * @param col ??
     * @param entityType ??
     * @param query 
     * @param token 
     * @param code ??
     * @return ?
     */
    public static DcResponse listEntities(String cell, String box, String col, String entityType, String query,
            String token, int code) {
        String reqUrl = UrlUtils.userData(cell, box, col, entityType) + query;
        DcRequest req = DcRequest.get(reqUrl);
        req.header(HttpHeaders.AUTHORIZATION, AbstractCase.BEARER_MASTER_TOKEN);
        req.header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON);
        DcResponse res = AbstractCase.request(req);
        if (-1 != code) {
            assertEquals(code, res.getStatusCode());
        }
        return res;
    }

    /**
     * ??????.
     * @param token 
     * @param code ??
     * @return ?
     */
    public static TResponse create(String token, int code) {
        return create(token, code, "testcell1", "box1");
    }

    /**
     * ??????.
     * @param token 
     * @param code ??
     * @param cell 
     * @param box 
     * @return ?
     */
    @SuppressWarnings("unchecked")
    public static TResponse create(String token, int code, String cell, String box) {
        JSONObject body = new JSONObject();
        body.put("__id", "auth_test");
        TResponse res = Http.request("box/odatacol/create.txt").with("cell", cell).with("box", box)
                .with("collection", "setodata").with("entityType", "Price")
                .with("accept", MediaType.APPLICATION_JSON).with("contentType", MediaType.APPLICATION_JSON)
                .with("token", "Bearer " + token).with("body", body.toJSONString()).returns().statusCode(code)
                .debug();
        return res;
    }

    /**
     * ??????.
     * @param token 
     * @param code ??
     * @param body 
     * @param cell ??
     * @param box ??
     * @param collection ??
     * @param entityType 
     * @return ?
     */
    public static TResponse create(String token, int code, JSONObject body, String cell, String box,
            String collection, String entityType) {
        return create(token, code, body.toJSONString(), cell, box, collection, entityType);
    }

    /**
     * ??????.
     * @param token 
     * @param code ??
     * @param body 
     * @param cell ??
     * @param box ??
     * @param collection ??
     * @param entityType 
     * @return ?
     */
    public static TResponse create(String token, int code, String body, String cell, String box, String collection,
            String entityType) {
        TResponse res = Http.request("box/odatacol/create.txt").with("cell", cell).with("box", box)
                .with("collection", collection).with("entityType", entityType)
                .with("accept", MediaType.APPLICATION_JSON).with("contentType", MediaType.APPLICATION_JSON)
                .with("token", "Bearer " + token).with("body", body).returns().statusCode(code).debug();
        return res;
    }

    /**
     * ??????(Basic?).
     * @param accountName Basic???Account??
     * @param password Basic???
     * @param code ??
     * @param body 
     * @param cell ??
     * @param box ??
     * @param collection ??
     * @param entityType 
     * @return ?
     */
    public static TResponse createWithBasic(String accountName, String password, int code, String body, String cell,
            String box, String collection, String entityType) {
        String credentials = Base64.encodeBase64String((accountName + ":" + password).getBytes());

        TResponse res = Http.request("box/odatacol/create.txt").with("cell", cell).with("box", box)
                .with("collection", collection).with("entityType", entityType)
                .with("accept", MediaType.APPLICATION_JSON).with("contentType", MediaType.APPLICATION_JSON)
                .with("token", "Basic " + credentials).with("body", body).returns().statusCode(code).debug();
        return res;
    }

    /**
     * ?????????.
     * @param token 
     * @param code ??
     */
    public static void createWithDelete(String token, int code) {
        TResponse res = create(token, code);
        if (res.getStatusCode() == HttpStatus.SC_CREATED) {
            UserDataUtils.delete(AbstractCase.MASTER_TOKEN_NAME, HttpStatus.SC_NO_CONTENT, "Price", "auth_test",
                    "setodata");
        }
    }

    /**
     * ??????.
     * @param token 
     * @param code ??
     * @return ?
     */
    @SuppressWarnings("unchecked")
    public static TResponse update(String token, int code) {
        JSONObject body = new JSONObject();
        body.put("__id", "auth_test");
        body.put("prop", "prop");
        TResponse res = Http.request("box/odatacol/update.txt").with("cell", "testcell1").with("box", "box1")
                .with("collection", "setodata").with("entityType", "Price").with("id", "auth_test")
                .with("accept", MediaType.APPLICATION_JSON).with("contentType", MediaType.APPLICATION_JSON)
                .with("token", token).with("ifMatch", "*").with("body", body.toJSONString()).returns()
                .statusCode(code).debug();
        return res;
    }

    /**
     * OData??????.
     * @param token 
     * @param code ??
     * @param body 
     * @param cell ??
     * @param box ??
     * @param collection ??
     * @param entityType 
     * @param id OData?UUID
     * @param ifMatch If-Match
     * @return ?
     */
    public static TResponse update(String token, int code, JSONObject body, String cell, String box,
            String collection, String entityType, String id, String ifMatch) {
        TResponse res = Http.request("box/odatacol/update.txt").with("cell", cell).with("box", box)
                .with("collection", collection).with("entityType", entityType).with("id", id)
                .with("accept", MediaType.APPLICATION_JSON).with("contentType", MediaType.APPLICATION_JSON)
                .with("token", token).with("ifMatch", ifMatch).with("body", body.toJSONString()).returns()
                .statusCode(code).debug();
        return res;
    }

    /**
     * OData??????.
     * @param token (???)
     * @param code ??
     * @param body 
     * @param cell ??
     * @param box ??
     * @param collection ??
     * @param entityType 
     * @param id OData?UUID
     * @param ifMatch If-Match
     * @return ?
     */
    public static TResponse updateAnyAuthSchema(String token, int code, JSONObject body, String cell, String box,
            String collection, String entityType, String id, String ifMatch) {
        TResponse res = Http.request("box/odatacol/update-anyAuthSchema.txt").with("cell", cell).with("box", box)
                .with("collection", collection).with("entityType", entityType).with("id", id)
                .with("accept", MediaType.APPLICATION_JSON).with("contentType", MediaType.APPLICATION_JSON)
                .with("token", token).with("ifMatch", ifMatch).with("body", body.toJSONString()).returns()
                .statusCode(code).debug();
        return res;
    }

    /**
     * ??????.
     * @param token 
     * @param code ??
     * @param entityType 
     * @param id ID
     * @param odataName odata??
     * @return ?
     */
    public static TResponse delete(String token, int code, String entityType, String id, String odataName) {
        return delete(token, code, Setup.TEST_CELL1, Setup.TEST_BOX1, odataName, entityType, id);
    }

    /**
     * ??????.
     * @param token 
     * @param code ??
     * @param cellName Cell??
     * @param boxName Box??
     * @param colName odata??
     * @param entityType 
     * @param id ID
     * @return ?
     */
    public static TResponse delete(String token, int code, String cellName, String boxName, String colName,
            String entityType, String id) {
        TResponse res = Http.request("box/odatacol/delete.txt").with("cell", cellName).with("box", boxName)
                .with("collection", colName).with("entityType", entityType).with("id", id).with("token", token)
                .with("ifMatch", "*").returns().statusCode(code).debug();
        return res;
    }

    /**
     * ??????.
     * @param token (??)
     * @param code ??
     * @param cellName Cell??
     * @param boxName Box??
     * @param colName odata??
     * @param entityType 
     * @param id ID
     * @return ?
     */
    public static TResponse deleteAnyAuthSchema(String token, int code, String cellName, String boxName,
            String colName, String entityType, String id) {
        TResponse res = Http.request("box/odatacol/delete-anyAuthSchema.txt").with("cell", cellName)
                .with("box", boxName).with("collection", colName).with("entityType", entityType).with("id", id)
                .with("token", token).with("ifMatch", "*").returns().statusCode(code).debug();
        return res;
    }

    /**
     * ?MERGE?????.
     * @param token 
     * @param code ??
     * @return ?
     */
    @SuppressWarnings("unchecked")
    public static TResponse merge(String token, int code) {
        JSONObject body = new JSONObject();
        body.put("__id", "auth_test");
        body.put("prop", "prop");
        TResponse res = Http.request("box/odatacol/merge.txt").with("cell", "testcell1").with("box", "box1")
                .with("collection", "setodata").with("entityType", "Price").with("id", "auth_test")
                .with("accept", MediaType.APPLICATION_JSON).with("contentType", MediaType.APPLICATION_JSON)
                .with("token", token).with("ifMatch", "*").with("body", body.toJSONString()).returns()
                .statusCode(code).debug();
        return res;
    }

    /**
     * OData??????.
     * @param token 
     * @param code ??
     * @param body 
     * @param cell ??
     * @param box ??
     * @param collection ??
     * @param entityType 
     * @param id OData?UUID
     * @param ifMatch If-Match
     * @return ?
     */
    public static TResponse merge(String token, int code, JSONObject body, String cell, String box,
            String collection, String entityType, String id, String ifMatch) {
        TResponse res = Http.request("box/odatacol/merge.txt").with("cell", cell).with("box", box)
                .with("collection", collection).with("entityType", entityType).with("id", id)
                .with("accept", MediaType.APPLICATION_JSON).with("contentType", MediaType.APPLICATION_JSON)
                .with("token", token).with("ifMatch", ifMatch).with("body", body.toJSONString()).returns()
                .statusCode(code).debug();
        return res;
    }

    /**
     * OData??????.
     * @param token (???)
     * @param code ??
     * @param body 
     * @param cell ??
     * @param box ??
     * @param collection ??
     * @param entityType 
     * @param id OData?UUID
     * @param ifMatch If-Match
     * @return ?
     */
    public static TResponse mergeAnyAuthSchema(String token, int code, JSONObject body, String cell, String box,
            String collection, String entityType, String id, String ifMatch) {
        TResponse res = Http.request("box/odatacol/merge-anyAuthSchema.txt").with("cell", cell).with("box", box)
                .with("collection", collection).with("entityType", entityType).with("id", id)
                .with("accept", MediaType.APPLICATION_JSON).with("contentType", MediaType.APPLICATION_JSON)
                .with("token", token).with("ifMatch", ifMatch).with("body", body.toJSONString()).returns()
                .statusCode(code).debug();
        return res;
    }

    /**
     * $batch??.
     * @param cellName ??
     * @param boxName ??
     * @param colName ??
     * @param boundary ?
     * @param body $batch?
     * @param token 
     * @param code ??
     * @return ?
     */
    public static TResponse batch(String cellName, String boxName, String colName, String boundary, String body,
            String token, int code) {
        // UserData$batch?
        TResponse res = Http.request("box/odatacol/batch.txt").with("cell", cellName).with("box", boxName)
                .with("collection", colName).with("boundary", boundary).with("token", token).with("body", body)
                .returns().statusCode(code).debug();
        return res;
    }

    /**
     * ?OPTIONS?????.
     * @param token 
     * @param code ??
     * @param path 
     * @return ?
     */
    public static TResponse options(String token, int code, String path) {
        TResponse res = Http.request("crossdomain/xhr2-preflight.txt").with("path", path).with("token", token)
                .returns().statusCode(code).debug();
        return res;
    }

    /**
     * NP???????.
     * @param token 
     * @param code ??
     * @return ?
     */
    @SuppressWarnings("unchecked")
    public static TResponse createViaNP(String token, int code) {
        JSONObject body = new JSONObject();
        body.put("__id", "npdata");
        TResponse res = Http.request("box/odatacol/createNP.txt").with("cell", "testcell1").with("box", "box1")
                .with("collection", "setodata").with("entityType", "Price").with("id", "auth_test")
                .with("navPropName", "_Sales").with("accept", MediaType.APPLICATION_JSON)
                .with("contentType", MediaType.APPLICATION_JSON).with("token", token)
                .with("body", body.toJSONString()).returns().statusCode(code).debug();

        return res;
    }

    /**
     * NP???????.
     * @param token 
     * @param code ??
     * @param body 
     * @param cell ??
     * @param box ??
     * @param collection ??
     * @param entityType 
     * @param id ?__id
     * @param navPropName NavigationProperty??("_"??)
     * @return ?
     */
    public static TResponse createViaNP(String token, JSONObject body, String cell, String box, String collection,
            String entityType, String id, String navPropName, int code) {
        TResponse res = Http.request("box/odatacol/createNP.txt").with("cell", cell).with("box", box)
                .with("collection", collection).with("entityType", entityType).with("id", id)
                .with("navPropName", "_" + navPropName).with("accept", MediaType.APPLICATION_JSON)
                .with("contentType", MediaType.APPLICATION_JSON).with("token", token)
                .with("body", body.toJSONString()).returns().statusCode(code).debug();
        return res;
    }

    /**
     * NP???????.
     * @param token (???)
     * @param code ??
     * @param body 
     * @param cell ??
     * @param box ??
     * @param collection ??
     * @param entityType 
     * @param id ?__id
     * @param navPropName NavigationProperty??("_"??)
     * @return ?
     */
    public static TResponse createViaNPAnyAuthSchema(String token, JSONObject body, String cell, String box,
            String collection, String entityType, String id, String navPropName, int code) {
        TResponse res = Http.request("box/odatacol/createNP-anyAuthSchema.txt").with("cell", cell).with("box", box)
                .with("collection", collection).with("entityType", entityType).with("id", id)
                .with("navPropName", "_" + navPropName).with("accept", MediaType.APPLICATION_JSON)
                .with("contentType", MediaType.APPLICATION_JSON).with("token", token)
                .with("body", body.toJSONString()).returns().statusCode(code).debug();
        return res;
    }

    /**
     * OData?$links?.
     * @param token 
     * @param cellName Cell??
     * @param boxName Box??
     * @param colName Collection??
     * @param srcEntityTypeName ?EntityType??
     * @param srcId ??OData ID
     * @param navPropName ?EntityType??
     * @param targetId ??OData ID
     * @param code ?
     * @return ?
     */
    public static TResponse createLink(String token, String cellName, String boxName, String colName,
            String srcEntityTypeName, String srcId, String navPropName, String targetId, int code) {
        String targetUri = UrlUtils.cellRoot(cellName) + boxName + "/" + colName + "/" + navPropName + "('"
                + targetId + "')";
        return Http.request("link-userdata-userdata.txt").with("cellPath", cellName).with("boxPath", boxName)
                .with("colPath", colName).with("srcPath", srcEntityTypeName + "('" + srcId + "')")
                .with("trgPath", navPropName).with("token", token).with("trgUserdataUrl", targetUri).returns()
                .debug().statusCode(code);
    }

    /**
     * OData?$links?.
     * @param token (??)
     * @param cellName Cell??
     * @param boxName Box??
     * @param colName Collection??
     * @param srcEntityTypeName ?EntityType??
     * @param srcId ??OData ID
     * @param navPropName ?EntityType??
     * @param targetId ??OData ID
     * @param code ?
     * @return ?
     */
    public static TResponse createLinkAnyAuthSchema(String token, String cellName, String boxName, String colName,
            String srcEntityTypeName, String srcId, String navPropName, String targetId, int code) {
        String targetUri = UrlUtils.cellRoot(cellName) + boxName + "/" + colName + "/" + navPropName + "('"
                + targetId + "')";
        return Http.request("link-userdata-userdata-anyAuthSchema.txt").with("cellPath", cellName)
                .with("boxPath", boxName).with("colPath", colName)
                .with("srcPath", srcEntityTypeName + "('" + srcId + "')").with("trgPath", navPropName)
                .with("token", token).with("trgUserdataUrl", targetUri).returns().debug().statusCode(code);
    }

    /**
     * ??????.
     * @param token 
     * @param code ??
     */
    public static void createViaNPWithDelete(String token, int code) {
        TResponse res = createViaNP(token, code);
        if (res.getStatusCode() == HttpStatus.SC_CREATED) {
            UserDataUtils.delete(AbstractCase.MASTER_TOKEN_NAME, HttpStatus.SC_NO_CONTENT, "Sales", "npdata",
                    "setodata");
        }
    }

    /**
     * ????.
     * @param token ?(??)
     * @param cellName ??
     * @param boxName ??
     * @param colName ??
     * @param sourceEntity ???
     * @param sourceId ??__id
     * @param targetEntity NavigationProperty??("_"??)
     * @param code ??
     * @return ?
     */
    public static TResponse listLinkAnyAuthSchema(String token, String cellName, String boxName, String colName,
            String sourceEntity, String sourceId, String targetEntity, int code) {
        return Http.request("box/odatacol/list-link-anyAuthSchema.txt").with("cellPath", cellName)
                .with("boxPath", boxName).with("colPath", colName)
                .with("srcPath", sourceEntity + "('" + sourceId + "')").with("trgPath", targetEntity)
                .with("token", token).with("accept", MediaType.APPLICATION_JSON).returns().statusCode(code).debug();
    }

    /**
     * ????.
     * @param cellName ??
     * @param boxName ??
     * @param colName ??
     * @param sourceEntity ???
     * @param sourceId ??__id
     * @param targetEntity NavigationProperty??("_"??)
     * @return ?
     */
    public static TResponse listLink(String cellName, String boxName, String colName, String sourceEntity,
            String sourceId, String targetEntity) {
        return Http.request("box/odatacol/list-link.txt").with("cellPath", cellName).with("boxPath", boxName)
                .with("colPath", colName).with("srcPath", sourceEntity + "('" + sourceId + "')")
                .with("trgPath", targetEntity).with("token", DcCoreConfig.getMasterToken())
                .with("accept", MediaType.APPLICATION_JSON).returns().statusCode(HttpStatus.SC_OK).debug();
    }

    /**
     * ?link?????.
     * @param cell ??
     * @param box ??
     * @param collection ??
     * @param srcEntity ?
     * @param userDataId ??__id
     * @param navPropEntity NavigationProperty??("_"??)
     * @param navPropId ??__id
     * @param code ??
     */
    public static void deleteLinks(String cell, String box, String collection, String srcEntity, String userDataId,
            String navPropEntity, String navPropId, int code) {
        // 
        Http.request("box/odatacol/delete-link.txt").with("cell", cell).with("box", box)
                .with("collection", collection).with("entityType", srcEntity).with("id", userDataId)
                .with("navProp", "_" + navPropEntity).with("navKey", navPropId)
                .with("contentType", MediaType.APPLICATION_JSON).with("token", DcCoreConfig.getMasterToken())
                .with("ifMatch", "*").returns().statusCode(code);
    }

    /**
     * ?link?????.
     * @param token ?(??)
     * @param cell ??
     * @param box ??
     * @param collection ??
     * @param srcEntity ?
     * @param userDataId ??__id
     * @param navPropEntity NavigationProperty??("_"??)
     * @param navPropId ??__id
     * @param code ??
     * @return ?
     */
    public static TResponse deleteLinksAnyAuthSchema(String token, String cell, String box, String collection,
            String srcEntity, String userDataId, String navPropEntity, String navPropId, int code) {
        // 
        return Http.request("box/odatacol/delete-link-anyAuthSchema.txt").with("cell", cell).with("box", box)
                .with("collection", collection).with("entityType", srcEntity).with("id", userDataId)
                .with("navProp", "_" + navPropEntity).with("navKey", navPropId)
                .with("contentType", MediaType.APPLICATION_JSON).with("token", token).with("ifMatch", "*").returns()
                .statusCode(code);
    }

    /**
     * ODataNP?.
     * @param cell Cell??
     * @param box Box??
     * @param collection ??
     * @param srcEntity srcEntity
     * @param srcId srcId
     * @param navPropEntity navPropEntity
     * @param query (?????)
     * @param code ?
     * @return ?
     */
    public static TResponse listViaNP(String cell, String box, String collection, String srcEntity, String srcId,
            String navPropEntity, String query, int code) {
        // ??
        return Http.request("box/odatacol/list.txt").with("cell", cell).with("box", box)
                .with("collection", collection + "/" + srcEntity + "('" + srcId + "')")
                .with("entityType", "_" + navPropEntity).with("query", query)
                .with("accept", MediaType.APPLICATION_JSON).with("token", DcCoreConfig.getMasterToken()).returns()
                .statusCode(code).debug();
    }

    /**
     * ODataNP?.
     * @param token ????
     * @param cell Cell??
     * @param box Box??
     * @param collection ??
     * @param srcEntity srcEntity
     * @param srcId srcId
     * @param navPropEntity navPropEntity
     * @param query (?????)
     * @param code ?
     * @return ?
     */
    public static TResponse listViaNPAnyAuthSchema(String token, String cell, String box, String collection,
            String srcEntity, String srcId, String navPropEntity, String query, int code) {
        // ??
        return Http.request("box/odatacol/list-anyAuthSchema.txt").with("cell", cell).with("box", box)
                .with("collection", collection + "/" + srcEntity + "('" + srcId + "')")
                .with("entityType", "_" + navPropEntity).with("query", query)
                .with("accept", MediaType.APPLICATION_JSON).with("token", token).returns().statusCode(code).debug();
    }

    /**
     * ???????
     * @param length ????
     * @return ???
     */
    public static String createString(int length) {
        String str = "";

        for (int i = 0; i < length; i++) {
            str += (i % NUMBER_FOR_CREATESTRING);
        }
        return str;
    }

}