Java Code Examples for org.json.simple.JSONObject#put()

The following examples show how to use org.json.simple.JSONObject#put() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: io   File: UserDataListPerformanceTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * ユーザデータの一覧を作成.
 * @param index インデックス番号
 * @return TResponse レスポンス情報
 */
@SuppressWarnings("unchecked")
public TResponse createData(int index) {
    // リクエストボディを設定
    JSONObject body = new JSONObject();
    body.put("__id", USERDATA_ID_PREFIX + String.valueOf(index));
    body.put("dynamicProperty", "dynamicPropertyValue");
    body.put("secondDynamicProperty", "secondDynamicPropertyValue");
    body.put("nullProperty", null);
    body.put("intProperty", 123);
    body.put("floatProperty", 123.123);
    body.put("trueProperty", true);
    body.put("falseProperty", false);
    body.put("nullStringProperty", "null");
    body.put("intStringProperty", "123");
    body.put("floatStringProperty", "123.123");
    body.put("trueStringProperty", "true");
    body.put("falseStringProperty", "false");

    // ユーザデータ作成
    return createUserData(body, HttpStatus.SC_CREATED);
}
 
Example 2
@SuppressWarnings("unchecked")
public static JSONObject extractSchema(Schema schema) {
  JSONObject object = new JSONObject();
  // just a defensive check
  if (schema != null) {
    object.put(NAME, schema.getName());
    object.put(CREATION_DATE, schema.getCreationDate().getTime());
    if (schema.getNote() != null) {
      object.put(NOTE, schema.getNote());
    }
    JSONArray columnArray = new JSONArray();
    for (Column column : schema.getColumnsArray()) {
      columnArray.add(extractColumn(column));
    }
    object.put(COLUMNS, columnArray);
  }
  return object;
}
 
Example 3
protected JSONObject getJson() {
    JSONObject json = new JSONObject();
    json.put(ID, getId());
    json.put(TITLE, getTitle());
    json.put(DESCRIPTION, getDescription());
    json.put(BODY, getBody().getBodyAsText());
    json.put(AUTHOR, getAuthor().displayName());
    json.put(LAST_MODIFIED, SolrTimestamp.convertToUtcAndUseNowIfNull(getLastUpdate()));
    json.put(PUBLISH_DATE, SolrTimestamp.convertToUtcAndUseNowIfNull(getPublishDate()));
    json.put(SLING_RESOUCE_TYPE, getSlingResourceType());
    json.put(URL, getUrl());

    JSONArray tags = new JSONArray();
    for (Tag tag : getTags()) {
        tags.add(tag.getTitle());
    }
    json.put(TAGS, tags);

    return json;
}
 
Example 4
Source Project: Modern-LWC   File: Metrics.java    License: MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
protected JSONObject getChartData() throws Exception {
    JSONObject data = new JSONObject();
    JSONObject values = new JSONObject();
    Map<String, Integer> map = callable.call();
    if (map == null || map.isEmpty()) {
        // Null = skip the chart
        return null;
    }
    boolean allSkipped = true;
    for (Map.Entry<String, Integer> entry : map.entrySet()) {
        if (entry.getValue() == 0) {
            continue; // Skip this invalid
        }
        allSkipped = false;
        values.put(entry.getKey(), entry.getValue());
    }
    if (allSkipped) {
        // Null = skip the chart
        return null;
    }
    data.put("values", values);
    return data;
}
 
Example 5
Source Project: java-sdk   File: JsonSimpleSerializer.java    License: Apache License 2.0 5 votes vote down vote up
private JSONArray serializeTags(Map<String, ?> tags) {
    JSONArray jsonArray = new JSONArray();
    for (Map.Entry<String, ?> entry : tags.entrySet()) {
        if (entry.getValue() != null) {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put(entry.getKey(), entry.getValue());
        }
    }

    return jsonArray;
}
 
Example 6
@Test
public void getsReadCharsetFromConfig() throws ParseException {
    JSONObject config = (JSONObject) new JSONParser().parse(parserConfig1);
    config.put(MessageParser.READ_CHARSET, StandardCharsets.UTF_16.toString());
    regularExpressionsParser.configure(config);
    assertThat(regularExpressionsParser.getReadCharset(), equalTo(StandardCharsets.UTF_16));
}
 
Example 7
Source Project: netbeans   File: JSONWriter.java    License: Apache License 2.0 5 votes vote down vote up
private static JSONArray storeFlags(Map<String, Boolean> flags) {
    JSONArray array = new JSONArray();
    for (Map.Entry<String, Boolean> flag : flags.entrySet()) {
        JSONObject obj = newJSONObject();
        obj.put(NAME, flag.getKey());
        obj.put(VALUE, flag.getValue());
        array.add(obj);
    }
    return array;
}
 
Example 8
Source Project: io   File: Event.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * This method creates a new JSON object for Event.
 * @return JSON object
 */
@SuppressWarnings("unchecked")
public JSONObject toJSON() {
    JSONObject json = new JSONObject();
    json.put("action", this.action);
    json.put("level", this.level);
    json.put("object", this.object);
    json.put("result", this.result);
    return json;
}
 
Example 9
@SuppressWarnings("unchecked")
public JSONObject toJSON()
{
	JSONObject networkMemberJson = new JSONObject();
	networkMemberJson.put("id", getId());
	networkMemberJson.put("homeNetwork", isHomeNetwork());
	networkMemberJson.put("network", getNetwork());
	return networkMemberJson;
}
 
Example 10
Source Project: sqoop-on-spark   File: JobBean.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private JSONObject extractJob(boolean skipSensitive, MJob job) {
  JSONObject object = new JSONObject();
  object.put(ID, job.getPersistenceId());
  object.put(NAME, job.getName());
  object.put(ENABLED, job.getEnabled());
  object.put(CREATION_USER, job.getCreationUser());
  object.put(CREATION_DATE, job.getCreationDate().getTime());
  object.put(UPDATE_USER, job.getLastUpdateUser());
  object.put(UPDATE_DATE, job.getLastUpdateDate().getTime());
  // job link associated connectors
  // TODO(SQOOP-1634): fix not to require the connectorIds in the post data
  object.put(FROM_CONNECTOR_ID, job.getConnectorId(Direction.FROM));
  object.put(TO_CONNECTOR_ID, job.getConnectorId(Direction.TO));
  // job associated links
  object.put(FROM_LINK_ID, job.getLinkId(Direction.FROM));
  object.put(TO_LINK_ID, job.getLinkId(Direction.TO));
  // job configs
  MFromConfig fromConfigList = job.getFromJobConfig();
  object.put(FROM_CONFIG_VALUES,
      extractConfigList(fromConfigList.getConfigs(), fromConfigList.getType(), skipSensitive));
  MToConfig toConfigList = job.getToJobConfig();
  object.put(TO_CONFIG_VALUES,
      extractConfigList(toConfigList.getConfigs(), toConfigList.getType(), skipSensitive));
  MDriverConfig driverConfigList = job.getDriverConfig();
  object.put(
      DRIVER_CONFIG_VALUES,
      extractConfigList(driverConfigList.getConfigs(), driverConfigList.getType(),
          skipSensitive));

  return object;
}
 
Example 11
Source Project: io   File: RoleCreateTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 指定されたボックス名にリンクされたロール情報を作成する(エラー).
 * @param boxname
 * @param errKey エラーキー
 * @param errValue エラー値
 * @param 期待するエラーステータスコード
 */
@SuppressWarnings("unchecked")
private void errCreateRole(String boxname, String errKey, String errValue, int errSC) {
    JSONObject body = new JSONObject();
    body.put("Name", testRoleName);
    body.put("_Box.Name", boxname);
    body.put(errKey, errValue);

    Http.request("role-create.txt")
            .with("token", AbstractCase.MASTER_TOKEN_NAME)
            .with("cellPath", cellName)
            .with("body", body.toString())
            .returns()
            .statusCode(errSC);
}
 
Example 12
Source Project: netbeans   File: DOM.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Requests children information for the specified node. The children
 * are delivered in the form of {@code setChildNodes} events. This method
 * should be called for nodes whose {@code getChildren()} method
 * returns {@code null} only. Otherwise, the children information
 * of the node should be up to date.
 * 
 * @param nodeId ID of the node whose children are requested.
 */
public void requestChildNodes(int nodeId) {
    JSONObject params = new JSONObject();
    params.put("nodeId", nodeId); // NOI18N
    if (transport.isVersionUnknownBeforeRequestChildNodes()) {
        transport.sendCommand(new Command("DOM.getChildNodes", params)); // NOI18N
    } else {
        transport.sendCommand(new Command("DOM.requestChildNodes", params)); // NOI18N
    }
}
 
Example 13
@SuppressWarnings("unchecked")
public static String createKernelJSON(String classpath, String logLevel, String javaBinaryPath) {
    JSONObject root = new JSONObject();
    root.put("language", ScijavaEvaluator.DEFAULT_LANGUAGE);
    root.put("display_name", "SciJava");

    JSONArray argv = new JSONArray();

    if (javaBinaryPath == null) {
        argv.add(SystemUtil.getJavaBinary());
    } else {
        argv.add(javaBinaryPath);
    }

    argv.add("-classpath");

    String finalClasspath = "";
    finalClasspath += SystemUtil.getImageJClassPaths();
    
    String classPathSeparator = SystemUtil.getClassPathSeparator();
    
    if (classpath != null) {
        if (finalClasspath.length() > 0) {
            finalClasspath += classPathSeparator + classpath;
        } else {
            finalClasspath += classpath;
        }

    }
    argv.add(finalClasspath);

    argv.add("org.scijava.jupyter.kernel.ScijavaKernel");
    argv.add("-verbose");
    argv.add(logLevel);
    argv.add("-connectionFile");
    argv.add("{connection_file}");
    root.put("argv", argv);

    return root.toJSONString();
}
 
Example 14
@SuppressWarnings("unchecked")
public String toJSONString() {
	JSONObject jo = new JSONObject();
	jo.put(ConstantsKeys.PRODUCTNAME, this.getProductName());
	jo.put(ConstantsKeys.VERSION, this.getVersion());
	jo.put(ConstantsKeys.MESSAGES, this.getMessages().toJSONString());
	jo.put(ConstantsKeys.COMPONENT, this.getComponent());
	return jo.toJSONString();
}
 
Example 15
/**
 * ComplexTypeの配列の必須ではない項目にデフォルト値が設定されて登録されること.
 */
@SuppressWarnings("unchecked")
@Test
public final void ComplexTypeの配列の必須ではない項目にデフォルト値が設定されて登録されること() {
    String userdatalocationUrl = UrlUtils.userdata(Setup.TEST_CELL1, Setup.TEST_BOX1, Setup.TEST_ODATA,
            UserDataComplexTypeUtils.ENTITY_TYPE_NAME, "test000");
    try {
        UserDataComplexTypeUtils.createComplexArraySchema();

        // complexTypeProperty作成
        UserDataUtils.createComplexTypeProperty(Setup.TEST_CELL1, Setup.TEST_BOX1,
                Setup.TEST_ODATA, "requiredStringEntry", "ListComplexType",
                EdmSimpleType.STRING.getFullyQualifiedTypeName(), false, "test", null);

        // リクエストパラメータ設定
        JSONObject ct1stProp = new JSONObject();
        ct1stProp.put(UserDataComplexTypeUtils.CT1ST_STRING_PROP,
                "CT1ST_STRING_PROP_VALUE");

        JSONObject listComplexType1 = new JSONObject();
        JSONObject listComplexType2 = new JSONObject();
        listComplexType1.put("lctStr", "xxx_lctStr");
        listComplexType1.put("requiredStringEntry", "xxx_requiredStringEntry");
        listComplexType2.put("lctStr", "yyy_lctStr");
        listComplexType2.put("requiredStringEntry", null);
        JSONArray etListPropStr = new JSONArray();
        etListPropStr.add(listComplexType1);
        etListPropStr.add(listComplexType2);

        String requestUrl = UrlUtils.userdata(Setup.TEST_CELL1, Setup.TEST_BOX1, Setup.TEST_ODATA,
                UserDataComplexTypeUtils.ENTITY_TYPE_NAME, null);
        DcRequest req = DcRequest.post(requestUrl);
        req.header(HttpHeaders.AUTHORIZATION, BEARER_MASTER_TOKEN);
        req.addJsonBody("__id", "test000");
        req.addJsonBody(UserDataComplexTypeUtils.ET_STRING_PROP, "UserDataComplexTypeUtils.ET_STRING_PROP_VALUE");
        req.addJsonBody(UserDataComplexTypeUtils.ET_CT1ST_PROP, ct1stProp);
        req.addJsonBody("listComplexType", etListPropStr);

        // リクエスト実行
        DcResponse response = request(req);

        // レスポンスチェック
        listComplexType2.put("requiredStringEntry", "test");
        Map<String, Object> expected = new HashMap<String, Object>();
        expected.put("__id", "test000");
        expected.put(UserDataComplexTypeUtils.ET_STRING_PROP, "UserDataComplexTypeUtils.ET_STRING_PROP_VALUE");
        expected.put("listComplexType", etListPropStr);
        expected.put(UserDataComplexTypeUtils.ET_CT1ST_PROP, ct1stProp);
        assertEquals(HttpStatus.SC_CREATED, response.getStatusCode());
        String nameSpace = getNameSpace(UserDataComplexTypeUtils.ENTITY_TYPE_NAME);
        ODataCommon.checkResponseBody(response.bodyAsJson(), userdatalocationUrl, nameSpace, expected);

        // 取得リクエスト実行
        req = DcRequest.get(userdatalocationUrl);
        req.header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON);
        req.header(HttpHeaders.AUTHORIZATION, BEARER_MASTER_TOKEN);
        response = request(req);
        assertEquals(HttpStatus.SC_OK, response.getStatusCode());
        ODataCommon.checkResponseBody(response.bodyAsJson(), userdatalocationUrl, nameSpace, expected);

    } finally {
        ODataCommon.deleteOdataResource(userdatalocationUrl);
        ODataCommon.deleteOdataResource(UrlUtils.complexTypeProperty(
                Setup.TEST_CELL1, Setup.TEST_BOX1, Setup.TEST_ODATA, "requiredStringEntry", "ListComplexType"));
        UserDataComplexTypeUtils.deleteComplexArraySchema();
    }
}
 
Example 16
Source Project: io   File: MessageSentTest.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * ToとtoRelationに異なるCellの値を使用して複数件Message送信されること.
 */
@SuppressWarnings("unchecked")
@Test
public final void ToとtoRelationに異なるCellの値を使用して複数件Message送信されること() {
    // 送信先CellUrl
    String targetCell = Setup.TEST_CELL2;

    // リクエストボディ作成
    JSONObject body = new JSONObject();
    body.put("BoxBound", false);
    body.put("InReplyTo", null);
    body.put("To", UrlUtils.cellRoot(targetCell) + "," + UrlUtils.cellRoot("testcell999"));
    body.put("ToRelation", "cellrelation");
    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 {
        // メッセージ送信
        response = SentMessageUtils.sent(MASTER_TOKEN_NAME, TEST_CELL1,
                body.toJSONString(), HttpStatus.SC_CREATED);

        // レスポンスボディのチェック
        JSONObject expectedResult = new JSONObject();
        expectedResult.put("To", UrlUtils.cellRoot(targetCell));
        expectedResult.put("Code", Integer.toString(HttpStatus.SC_CREATED));
        expectedResult.put("Reason", "Created.");
        JSONObject expectedResultNotFound = new JSONObject();
        expectedResultNotFound.put("To", UrlUtils.cellRoot("testcell999"));
        expectedResultNotFound.put("Code", Integer.toString(HttpStatus.SC_FORBIDDEN));
        expectedResultNotFound.put("Reason", "Unit user access required.");
        JSONArray expectedResults = new JSONArray();
        expectedResults.add(expectedResult);
        expectedResults.add(expectedResultNotFound);
        JSONObject expected = new JSONObject();
        expected.put("_Box.Name", null);
        expected.put("InReplyTo", null);
        expected.put("To", UrlUtils.cellRoot(targetCell) + "," + UrlUtils.cellRoot("testcell999"));
        expected.put("ToRelation", "cellrelation");
        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);

        ODataCommon.checkResponseBody(response.bodyAsJson(), response.getLocationHeader(),
                SENT_MESSAGE_TYPE, expected);

        // __idの取得
        JSONObject result = (JSONObject) ((JSONObject) response.bodyAsJson().get("d")).get("results");
        String id = (String) result.get("__id");

        // 送信メッセージを一件取得してボディをチェック
        TResponse getSMResponse = SentMessageUtils.get(MASTER_TOKEN_NAME, TEST_CELL1, HttpStatus.SC_OK,
                id);
        ODataCommon.checkResponseBody(getSMResponse.bodyAsJson(), response.getLocationHeader(),
                SENT_MESSAGE_TYPE, expected);
    } finally {
        // 送信メッセージの削除
        if (response != null) {
            deleteOdataResource(response.getLocationHeader());
        }
        // 自動生成された受信メッセージの削除
        deleteReceivedMessage(targetCell, UrlUtils.cellRoot(Setup.TEST_CELL1), MESSAGE, "title", "body");
    }
}
 
Example 17
Source Project: sqoop-on-spark   File: SubmissionBean.java    License: Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private JSONObject extractSubmission(MSubmission submission) {
  JSONObject object = new JSONObject();

  object.put(JOB, submission.getJobId());
  object.put(STATUS, submission.getStatus().name());
  object.put(PROGRESS, submission.getProgress());

  if (submission.getCreationUser() != null) {
    object.put(CREATION_USER, submission.getCreationUser());
  }
  if (submission.getCreationDate() != null) {
    object.put(CREATION_DATE, submission.getCreationDate().getTime());
  }
  if (submission.getLastUpdateUser() != null) {
    object.put(LAST_UPDATE_USER, submission.getLastUpdateUser());
  }
  if (submission.getLastUpdateDate() != null) {
    object.put(LAST_UPDATE_DATE, submission.getLastUpdateDate().getTime());
  }
  if (submission.getExternalJobId() != null) {
    object.put(EXTERNAL_ID, submission.getExternalJobId());
  }
  if (submission.getExternalLink() != null) {
    object.put(EXTERNAL_LINK, submission.getExternalLink());
  }
  if (submission.getError().getErrorSummary() != null) {
    object.put(ERROR_SUMMARY, submission.getError().getErrorSummary());
  }
  if (submission.getError().getErrorDetails() != null) {
    object.put(ERROR_DETAILS, submission.getError().getErrorDetails());
  }
  if (submission.getCounters() != null) {
    object.put(COUNTERS, extractCounters(submission.getCounters()));
  }
  if (submission.getFromSchema() != null) {
    object.put(FROM_SCHEMA, extractSchema(submission.getFromSchema()));
  }
  if (submission.getToSchema() != null) {
    object.put(TO_SCHEMA, extractSchema(submission.getToSchema()));
  }
  return object;
}
 
Example 18
Source Project: io   File: UserDataLinkTest.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * ユーザデータのlinkを削除できること_AssociationEndが0対0.
 */
@SuppressWarnings("unchecked")
@Test
public final void ユーザデータのlinkを削除できること_AssociationEndが0対0() {
    String srcEntityType = "Sales";
    String targetEntityType = "Price";
    String srcUserDataId = "srcId";
    String targetUserDataId = "targetId";

    JSONObject body = new JSONObject();
    try {
        body.put("__id", srcUserDataId);
        createUserData(body, HttpStatus.SC_CREATED, Setup.TEST_CELL1, Setup.TEST_BOX1, Setup.TEST_ODATA,
                srcEntityType);
        body.put("__id", targetUserDataId);
        createUserData(body, HttpStatus.SC_CREATED, Setup.TEST_CELL1, Setup.TEST_BOX1, Setup.TEST_ODATA,
                targetEntityType);

        // $links登録
        ResourceUtils.linksUserData(srcEntityType, srcUserDataId, targetEntityType, targetUserDataId,
                HttpStatus.SC_NO_CONTENT);

        // $links削除
        ResourceUtils.deleteUserDataLinks(srcUserDataId, targetUserDataId, targetEntityType, Setup.TEST_CELL1,
                Setup.TEST_BOX1, Setup.TEST_ODATA, srcEntityType, HttpStatus.SC_NO_CONTENT);

        // $links一覧取得
        TResponse resList = Http.request("box/odatacol/list-link.txt")
                .with("cellPath", Setup.TEST_CELL1)
                .with("boxPath", Setup.TEST_BOX1)
                .with("colPath", Setup.TEST_ODATA)
                .with("srcPath", srcEntityType + "('" + srcUserDataId + "')")
                .with("trgPath", targetEntityType)
                .with("token", DcCoreConfig.getMasterToken())
                .with("accept", MediaType.APPLICATION_JSON)
                .returns()
                .statusCode(HttpStatus.SC_OK)
                .debug();

        ArrayList<String> expectedUriList = new ArrayList<String>();
        // レスポンスボディのチェック
        ODataCommon.checkLinResponseBody(resList.bodyAsJson(), expectedUriList);

    } finally {
        deleteUserData(Setup.TEST_CELL1, Setup.TEST_BOX1, Setup.TEST_ODATA,
                targetEntityType, targetUserDataId, DcCoreConfig.getMasterToken(), HttpStatus.SC_NO_CONTENT);
        deleteUserData(Setup.TEST_CELL1, Setup.TEST_BOX1, Setup.TEST_ODATA,
                srcEntityType, srcUserDataId, DcCoreConfig.getMasterToken(), HttpStatus.SC_NO_CONTENT);
    }
}
 
Example 19
Source Project: io   File: UserDataUpdateTest.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * null値のスキーマにboolean値をsetでエラーとならないこと.
 */
@SuppressWarnings("unchecked")
@Test
public final void null値のスキーマにboolean値をsetでエラーとならないこと() {
    // リクエストボディを設定
    String userDataId = "userdata001";
    String entityTypeName = "scmTest";

    try {
        // EntityTypeの登録
        createEntityType(entityTypeName, colName);
        // Schemaに数値をset

        JSONObject body = new JSONObject();
        body.put("__id", userDataId);
        body.put("dynamicProperty", "dynamicPropertyValue");
        body.put("secondDynamicProperty", "secondDynamicPropertyValue");
        body.put("nullPropertyB", null);
        body.put("intProperty", 123);
        body.put("floatProperty", 123.123);
        body.put("trueProperty", true);
        body.put("falseProperty", false);
        body.put("nullStringProperty", "null");
        body.put("intStringProperty", "123");
        body.put("floatStringProperty", "123.123");
        body.put("trueStringProperty", "true");
        body.put("falseStringProperty", "false");
        createUserData(body, entityTypeName, HttpStatus.SC_CREATED);

        // Schemaに文字列をセット
        // リクエストボディを設定
        body.put("nullPropertyB", false);
        Http.request("box/odatacol/update.txt")
                .with("cell", cellName)
                .with("box", boxName)
                .with("collection", colName)
                .with("entityType", entityTypeName)
                .with("id", userDataId)
                .with("accept", MediaType.APPLICATION_JSON)
                .with("contentType", MediaType.APPLICATION_JSON)
                .with("ifMatch", "*")
                .with("token", DcCoreConfig.getMasterToken())
                .with("body", body.toJSONString())
                .returns()
                .statusCode(HttpStatus.SC_NO_CONTENT)
                .debug();

    } finally {
        deleteUserData(entityTypeName, userDataId);
        EntityTypeUtils.delete(colName, MASTER_TOKEN_NAME,
                "application/xml", entityTypeName, Setup.TEST_CELL1, -1);
    }
}
 
Example 20
Source Project: io   File: UserDataBatchListQueryTest.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * ユーザOData$batch登録でexpandに最大プロパティ数を超える値を指定した場合400エラーとなること.
 */
@SuppressWarnings("unchecked")
@Test
public final void ユーザOData$batch登録でexpandに最大プロパティ数を超える値を指定した場合400エラーとなること() {
    String fromEntity = "Sales";
    String targetEntity1 = "Price";
    String targetEntity2 = "Product";
    String targetEntity3 = "Supplier";

    String userDataId = "npdata";

    try {
        // 事前にデータを登録する
        JSONObject body = new JSONObject();
        body.put("__id", userDataId);
        UserDataUtils.create(AbstractCase.MASTER_TOKEN_NAME, -1, body, Setup.TEST_CELL1, Setup.TEST_BOX1,
                Setup.TEST_ODATA, fromEntity);

        // $batchリクエスト
        String query = String.format("?\\$expand=_%s,_%s,_%s", targetEntity1, targetEntity2, targetEntity3);
        String bodyBatch = START_BOUNDARY + retrieveListBodyWithQuery(fromEntity, query)
                + END_BOUNDARY;
        TResponse res = Http.request("box/odatacol/batch.txt")
                .with("cell", cellName)
                .with("box", boxName)
                .with("collection", colName)
                .with("boundary", BOUNDARY)
                .with("token", DcCoreConfig.getMasterToken())
                .with("body", bodyBatch)
                .returns()
                .statusCode(HttpStatus.SC_ACCEPTED)
                .debug();

        // レスポンスヘッダのチェック
        checkBatchResponseHeaders(res);

        // レスポンスボディのチェック
        String expectedBody = START_BOUNDARY
                + retrieveQueryOperationResErrorBody(HttpStatus.SC_BAD_REQUEST)
                + END_BOUNDARY;
        checkBatchResponseBody(res, expectedBody);
    } finally {
        UserDataUtils.delete(AbstractCase.MASTER_TOKEN_NAME, -1, Setup.TEST_CELL1, Setup.TEST_BOX1,
                Setup.TEST_ODATA, fromEntity, userDataId);
    }
}