Example usage for org.json.simple JSONObject remove

List of usage examples for org.json.simple JSONObject remove

Introduction

In this page you can find the example usage for org.json.simple JSONObject remove.

Prototype

V remove(Object key);

Source Link

Document

Removes the mapping for a key from this map if it is present (optional operation).

Usage

From source file:org.jasig.ssp.reference.AbstractReferenceTest.java

/**
 * Tests permission protected method(s) unauthenticated for a negative test.
 * Note: This method cannot take any validation measures as it is designed to be unauthenticated.
 *        Other validation measures (e.g. response body validation etc.) should be taken after this method.
 *           Do not expect passed objects to be the same after this test.
 * @param urlToTest//from w w  w  .  j ava 2 s  . com
 * @param contentToPostPut
 */
public final void referenceAuthenticationControlledMethodNegativeTest(final String urlToTest,
        final JSONObject contentToPostPut) {

    final String idToSave = contentToPostPut.get("id").toString();
    contentToPostPut.remove("id");

    //tests permission on get all method
    expect().statusCode(403).when().get(urlToTest);

    //tests permission on get id method
    expect().statusCode(403).when().get(urlToTest + "/" + idToSave);

    //tests permission on post method
    expect().statusCode(403).given().contentType("application/json").body(contentToPostPut).when()
            .post(urlToTest);

    contentToPostPut.put("name", ("testReferencePutUnAuth" + testPassDeConflictNumber));

    //tests permission on put method
    expect().statusCode(403).given().contentType("application/json").body(contentToPostPut).when()
            .put(urlToTest + "/" + idToSave);

    //tests permission on delete method
    expect().statusCode(403).when().delete(urlToTest + "/" + idToSave);

}

From source file:org.jasig.ssp.reference.ChallengeIT.java

@Test
@ApiAuthentication(mode = "auth")
public void testChallengeReferenceSupportedMethodsPositive() {

    final JSONObject testPostPutPositive = (JSONObject) ((JSONObject) CHALLENGE_ROWS.get(3)).clone();
    testPostPutPositive.put("name", "testPostPositive");

    int checkResultCount = -2;

    //get all (store results to check at the end)
    Response checkItemCount = expect().statusCode(200).log().ifError().contentType("application/json").when()
            .get(CHALLENGE_PATH);//  w  w w.j a  v  a  2s  . c  o m

    String result = checkItemCount.getBody().jsonPath().getJsonObject("results").toString();

    if (StringUtils.isNotBlank(result)) {
        checkResultCount = Integer.parseInt(result);
    } else {
        LOGGER.error("Get all method failed at beginning of Positive Test! No results returned.");
        fail("GET all failed.");
    }

    //get /id
    expect().statusCode(200).log().ifError().contentType("application/json").when()
            .get(CHALLENGE_PATH + "/" + CHALLENGE_UUIDS[7]);

    testPostPutPositive.remove("id");

    //post
    Response postResponse = expect().statusCode(200).log().ifError().given().contentType("application/json")
            .body(testPostPutPositive).when().post(CHALLENGE_PATH);

    final String postContentUUID = postResponse.getBody().jsonPath().getJsonObject("id").toString();

    //get more complete data from post using get (MSSQL version is not reliable without this extra get)
    Map parsedPostResponse = expect().statusCode(200).log().ifError().contentType("application/json").when()
            .get(CHALLENGE_PATH + "/" + postContentUUID).getBody().jsonPath().getMap("");

    testPostPutPositive.put("id", postContentUUID);
    testPostPutPositive.put("createdBy", getCurrentLoginCreatedModifiedBy());
    testPostPutPositive.put("modifiedBy", getCurrentLoginCreatedModifiedBy());
    testPostPutPositive.put("createdDate", parsedPostResponse.get("createdDate"));
    testPostPutPositive.put("modifiedDate", parsedPostResponse.get("modifiedDate"));
    testPostPutPositive.put("challengeChallengeReferrals", new JSONArray());
    testPostPutPositive.put("selfHelpGuideQuestions", new JSONArray());
    testPostPutPositive.put("referralCount", 0);

    //verify post worked
    Map postVerificationActual = expect().statusCode(200).log().ifError().contentType("application/json").when()
            .get(CHALLENGE_PATH + "/" + postContentUUID).getBody().jsonPath().getMap("");

    assertTrue(checkChallengeResponseEqualToExpected(testPostPutPositive, postVerificationActual));

    testPostPutPositive.remove("id");
    testPostPutPositive.put("name", ("testReferencePut" + testPassDeConflictNumber));

    //put
    expect().statusCode(200).log().ifError().given().contentType("application/json").body(testPostPutPositive)
            .when().put(CHALLENGE_PATH + "/" + postContentUUID);

    //get more complete data from put using get
    final Response putResponse = expect().statusCode(200).log().ifError().contentType("application/json").when()
            .get(CHALLENGE_PATH + "/" + postContentUUID);

    testPostPutPositive.put("id", postContentUUID);
    testPostPutPositive.put("modifiedDate", putResponse.getBody().jsonPath().getJsonObject("modifiedDate"));

    //verify put worked
    Map putVerificationActual = expect().statusCode(200).log().ifError().contentType("application/json").when()
            .get(CHALLENGE_PATH + "/" + postContentUUID).getBody().jsonPath().getMap("");

    assertTrue(checkChallengeResponseEqualToExpected(testPostPutPositive, putVerificationActual));

    //delete
    expect().statusCode(200).log().ifError().when().delete(CHALLENGE_PATH + "/" + postContentUUID);

    testPostPutPositive.put("objectStatus", "INACTIVE");

    //get verify delete worked
    final Response deleteCheckResponse = expect().statusCode(200).log().ifError()
            .contentType("application/json").when().get(CHALLENGE_PATH + "/" + postContentUUID);

    testPostPutPositive.put("modifiedDate",
            deleteCheckResponse.getBody().jsonPath().getJsonObject("modifiedDate"));

    //verify delete is still intact but inactive
    Map deleteVerificationResponse = expect().statusCode(200).log().ifError().contentType("application/json")
            .when().get(CHALLENGE_PATH + "/" + postContentUUID).getBody().jsonPath().getMap("");

    assertTrue(checkChallengeResponseEqualToExpected(testPostPutPositive, deleteVerificationResponse));

    //get (verify result # matches expected active)
    expect().statusCode(200).log().ifError().contentType("application/json")
            .body("results", equalTo(checkResultCount)).given().queryParam("status", "ACTIVE").when()
            .get(CHALLENGE_PATH);

    //get (verify result # matches expected inactive)
    expect().statusCode(200).log().ifError().contentType("application/json").body("results", equalTo(1)).given()
            .queryParam("status", "INACTIVE").when().get(CHALLENGE_PATH);
}

From source file:org.jasig.ssp.reference.ChallengeIT.java

@Test
@ApiAuthentication(mode = "auth")
public void testChallengeReferenceSupportedMethodsNegative() {
    final JSONObject testNegativePostObject = (JSONObject) ((JSONObject) CHALLENGE_ROWS.get(5)).clone();
    testNegativePostObject.put("name", ("testPostNegative" + testPassDeConflictNumber));
    final JSONObject testNegativeValidateObject = (JSONObject) CHALLENGE_ROWS.get(6);

    int checkResultCount = 0;

    //get all (store results to check at the end)
    Response checkItemCount = expect().statusCode(200).log().ifError().contentType("application/json").when()
            .get(CHALLENGE_PATH);//  w w  w  .j a va2s  .c  o m

    String result = checkItemCount.getBody().jsonPath().getJsonObject("results").toString();

    if (StringUtils.isNotBlank(result)) {
        checkResultCount = Integer.parseInt(result);
    } else {
        LOGGER.error("Get all method failed in Negative Test! No results returned.");
        fail("GET all failed Negative Tests.");
    }

    //get invalid id
    expect().statusCode(404).contentType("application/json").when()
            .get(CHALLENGE_PATH + "/70b982b0-68d7-11e3-949a-0800200c9a66");

    testNegativePostObject.remove("id");
    final String name = testNegativePostObject.get("name").toString();
    testNegativePostObject.remove("name");

    //post empty name
    expect().statusCode(400).given().contentType("application/json").body(testNegativePostObject).when()
            .post(CHALLENGE_PATH);

    testNegativePostObject.put("name", name);
    testNegativePostObject.put("objectStatus", "");

    //put
    expect().statusCode(500).given().contentType("application/json").body(testNegativePostObject).when()
            .put(CHALLENGE_PATH + "/" + testNegativeValidateObject.get("id"));

    //verify put didn't work
    Map testPutNegative = expect().statusCode(200).contentType("application/json").when()
            .get(CHALLENGE_PATH + "/" + testNegativeValidateObject.get("id")).getBody().jsonPath().getMap("");

    if (checkChallengeResponseEqualToExpected(testNegativeValidateObject, testPutNegative) == false) {
        fail("Negative test for challenge in put method. Put worked despite invalid put content!");
    }

    //delete
    expect().statusCode(404).when().delete(CHALLENGE_PATH + "/70b982b0-68d7-11e3-949a-0800200c9a66");

    //get all (verify result # is unchanged)
    expect().statusCode(200).log().ifError().contentType("application/json")
            .body("results", equalTo(checkResultCount)).when().get(CHALLENGE_PATH);
}

From source file:org.jasig.ssp.reference.ConfigIT.java

@Test
@ApiAuthentication(mode = "auth")
public void testConfigReferenceSupportedMethodsPositive() {
    final JSONObject testPutPositive = copyOfExpectedObjectAtIndex(2, CONFIG_ROWS);
    testPutPositive.put("name", "testPutPositive");

    int checkResultCount = -2;

    //get all (store results to check at the end)
    Response checkItemCount = expect().statusCode(200).log().ifError().contentType("application/json").when()
            .get(CONFIG_PATH);//from   w w w  .  ja  v a2  s .  c  o m

    String result = checkItemCount.getBody().jsonPath().getJsonObject("results").toString();

    if (StringUtils.isNotBlank(result)) {
        checkResultCount = Integer.parseInt(result);
    } else {
        LOGGER.error("Get all method failed at beginning of Positive Test! No results returned.");
        fail("GET all failed.");
    }

    //get /id
    expect().statusCode(200).log().ifError().contentType("application/json").when()
            .get(CONFIG_PATH + "/" + expectedStringFieldValueAtIndex("id", 1, CONFIG_ROWS));

    //get /name
    expect().statusCode(200).log().ifError().contentType("application/json").given()
            .queryParam("name", expectedStringFieldValueAtIndex("name", 1, CONFIG_ROWS)).when()
            .get(CONFIG_PATH);

    final String putUUID = testPutPositive.get("id").toString();
    testPutPositive.remove("id");

    //post
    Response postResponse = expect().statusCode(500).given().contentType("application/json")
            .body(testPutPositive).when().post(CONFIG_PATH);

    //verify post did not set data (see ConfigController)
    expect().statusCode(200).log().ifError().contentType("").given()
            .queryParam("name", testPutPositive.get("name")).when().get(CONFIG_PATH);

    //put
    expect().statusCode(200).log().ifError().given().contentType("application/json").body(testPutPositive)
            .when().put(CONFIG_PATH + "/" + putUUID);

    //get more complete data from put using get
    final Response putResponse = expect().statusCode(200).log().ifError().contentType("application/json").when()
            .get(CONFIG_PATH + "/" + putUUID);

    final Map parsedPutResponse = putResponse.getBody().jsonPath().getJsonObject("");
    testPutPositive.put("id", putUUID);
    testPutPositive.put("modifiedBy", getCurrentLoginCreatedModifiedBy());
    testPutPositive.put("modifiedDate", parsedPutResponse.get("modifiedDate"));

    //verify put worked
    expect().statusCode(200).log().ifError().contentType("application/json").body("", equalTo(testPutPositive))
            .when().get(CONFIG_PATH + "/" + putUUID);

    //delete
    expect().statusCode(200).log().ifError().when().delete(CONFIG_PATH + "/" + putUUID);

    testPutPositive.put("objectStatus", "INACTIVE");

    //get verify delete worked
    final Response deleteCheckResponse = expect().statusCode(200).log().ifError()
            .contentType("application/json").when().get(CONFIG_PATH + "/" + putUUID);

    testPutPositive.put("modifiedDate", deleteCheckResponse.getBody().jsonPath().getJsonObject("modifiedDate"));

    //verify delete is still intact but inactive
    expect().statusCode(200).log().ifError().contentType("application/json").body("", equalTo(testPutPositive))
            .when().get(CONFIG_PATH + "/" + putUUID);

    //get (verify result # matches expected active)
    expect().statusCode(200).log().ifError().contentType("application/json")
            .body("results", equalTo(checkResultCount - 1)).given().queryParam("status", "ACTIVE").when()
            .get(CONFIG_PATH);

    //get (verify result # matches expected inactive)
    expect().statusCode(200).log().ifError().contentType("application/json").body("results", equalTo(2)) // normally 1, but 2 b/c we now have one, special, deactive-by-default config (task_directory_person_refresh_start_up_trigger)
            .given().queryParam("status", "INACTIVE").when().get(CONFIG_PATH);
}

From source file:org.jasig.ssp.reference.SelfHelpGuideIT.java

@Test
@ApiAuthentication(mode = "auth")
public void testSelfHelpGuideReferenceSupportedMethodsPositive() {

    final JSONObject testPostPutPositive = (JSONObject) SELF_HELP_GUIDE_SSC.clone();
    testPostPutPositive.put("name", "testPostPositive");

    int checkResultCount = -2;

    //get all (store results to check at the end)
    Response checkItemCount = expect().statusCode(200).log().ifError().contentType("application/json").when()
            .get(SELF_HELP_GUIDE_PATH);//w  w w . j av  a 2s .  c  o  m

    String result = checkItemCount.getBody().jsonPath().getJsonObject("results").toString();

    if (StringUtils.isNotBlank(result)) {
        checkResultCount = Integer.parseInt(result);
    } else {
        LOGGER.error("Get all method failed at beginning of Positive Test! No results returned.");
        fail("GET all failed.");
    }

    //get /id
    expect().statusCode(200).log().ifError().contentType("application/json").when()
            .get(SELF_HELP_GUIDE_PATH + "/" + SELF_HELP_GUIDE_QSGC.get("id").toString());

    testPostPutPositive.remove("id");

    final JSONObject testPostPutPositiveFull = (JSONObject) testPostPutPositive.clone();
    testPostPutPositiveFull.put("threshold", 0);
    testPostPutPositiveFull.put("introductoryText", "testIntroText");
    testPostPutPositiveFull.put("summaryText", "testSumText");
    testPostPutPositiveFull.put("summaryTextEarlyAlert", "testEarlyAlertText");
    testPostPutPositiveFull.put("summaryTextThreshold", "testThresholdText");
    testPostPutPositiveFull.put("authenticationRequired", false);
    testPostPutPositiveFull.put("active", true);

    //TODO Note: Uses SelfHelpGuideAdminController for post as SelfHelpGuide reference post was not working,(DB Error returned)
    //post
    Response postResponse = expect().statusCode(200).log().ifError().given().contentType("application/json")
            .body(testPostPutPositiveFull).when().post("selfHelpGuides/search");

    final String postContentUUID = postResponse.getBody().jsonPath().getJsonObject("id").toString();

    //get more complete data from post using get (MSSQL version is not reliable without this extra get)
    postResponse = expect().statusCode(200).log().ifError().contentType("application/json").when()
            .get(SELF_HELP_GUIDE_PATH + "/" + postContentUUID);

    final Map parsedPostResponse = postResponse.getBody().jsonPath().getJsonObject("");

    testPostPutPositive.put("id", postContentUUID);
    testPostPutPositive.put("createdBy", getCurrentLoginCreatedModifiedBy());
    testPostPutPositive.put("modifiedBy", getCurrentLoginCreatedModifiedBy());
    testPostPutPositive.put("createdDate", parsedPostResponse.get("createdDate"));
    testPostPutPositive.put("modifiedDate", parsedPostResponse.get("modifiedDate"));

    //verify post worked
    expect().statusCode(200).log().ifError().contentType("application/json")
            .body("", equalTo(testPostPutPositive)).when().get(SELF_HELP_GUIDE_PATH + "/" + postContentUUID);

    testPostPutPositive.remove("id");
    testPostPutPositive.put("name", ("testReferencePut" + testPassDeConflictNumber));

    //put
    expect().statusCode(200).log().ifError().given().contentType("application/json").body(testPostPutPositive)
            .when().put(SELF_HELP_GUIDE_PATH + "/" + postContentUUID);

    //get more complete data from put using get
    final Response putResponse = expect().statusCode(200).log().ifError().contentType("application/json").when()
            .get(SELF_HELP_GUIDE_PATH + "/" + postContentUUID);

    testPostPutPositive.put("id", postContentUUID);
    testPostPutPositive.put("modifiedDate", putResponse.getBody().jsonPath().getJsonObject("modifiedDate"));

    //verify put worked
    expect().statusCode(200).log().ifError().contentType("application/json")
            .body("", equalTo(testPostPutPositive)).when().get(SELF_HELP_GUIDE_PATH + "/" + postContentUUID);

    //delete
    expect().statusCode(200).log().ifError().when().delete(SELF_HELP_GUIDE_PATH + "/" + postContentUUID);

    testPostPutPositive.put("objectStatus", "INACTIVE");

    //get verify delete worked
    final Response deleteCheckResponse = expect().statusCode(200).log().ifError()
            .contentType("application/json").when().get(SELF_HELP_GUIDE_PATH + "/" + postContentUUID);

    testPostPutPositive.put("modifiedDate",
            deleteCheckResponse.getBody().jsonPath().getJsonObject("modifiedDate"));

    //verify delete is still intact but inactive
    expect().statusCode(200).log().ifError().contentType("application/json")
            .body("", equalTo(testPostPutPositive)).when().get(SELF_HELP_GUIDE_PATH + "/" + postContentUUID);

    //get (verify result # matches expected active)
    expect().statusCode(200).log().ifError().contentType("application/json")
            .body("results", equalTo(checkResultCount)).given().queryParam("status", "ACTIVE").when()
            .get(SELF_HELP_GUIDE_PATH);

    //get (verify result # matches expected inactive)
    expect().statusCode(200).log().ifError().contentType("application/json").body("results", equalTo(1)).given()
            .queryParam("status", "INACTIVE").when().get(SELF_HELP_GUIDE_PATH);

}

From source file:org.jasig.ssp.reference.SelfHelpGuideQuestionIT.java

@Test
@ApiAuthentication(mode = "auth")
public void testSelfHelpGuideQuestionDetailReferenceSupportedMethodsPositive() {
    final JSONObject testPostPutPositive = (JSONObject) ((JSONObject) SELF_HELP_GUIDE_QUESTION_ROWS.get(2))
            .clone();//  w ww . j ava 2  s .  co m
    testPostPutPositive.put("description", "testPostPositive");

    int checkResultCount = -2;

    //get all (store results to check at the end)
    Response checkItemCount = expect().statusCode(200).log().ifError().contentType("application/json").when()
            .get(SELF_HELP_GUIDE_QUESTION_PATH);

    String result = checkItemCount.getBody().jsonPath().getJsonObject("results").toString();

    if (StringUtils.isNotBlank(result)) {
        checkResultCount = Integer.parseInt(result);
    } else {
        LOGGER.error("Get all method failed at beginning of Positive Test! No results returned.");
        fail("GET all failed.");
    }

    //get /id
    expect().statusCode(200).log().ifError().contentType("application/json").when()
            .get(SELF_HELP_GUIDE_QUESTION_PATH + "/" + testPostPutPositive.get("id"));

    testPostPutPositive.remove("id");

    //post
    Response postResponse = expect().statusCode(200).log().ifError().given().contentType("application/json")
            .body(testPostPutPositive).when().post(SELF_HELP_GUIDE_QUESTION_PATH);

    final String postContentUUID = postResponse.getBody().jsonPath().getJsonObject("id").toString();

    //get more complete data from post using get (MSSQL version is not reliable without this extra get)
    postResponse = expect().statusCode(200).log().ifError().contentType("application/json").when()
            .get(SELF_HELP_GUIDE_QUESTION_PATH + "/" + postContentUUID);

    final Map parsedPostResponse = postResponse.getBody().jsonPath().getJsonObject("");

    testPostPutPositive.put("id", postContentUUID);
    testPostPutPositive.put("createdBy", getCurrentLoginCreatedModifiedBy());
    testPostPutPositive.put("modifiedBy", getCurrentLoginCreatedModifiedBy());
    testPostPutPositive.put("createdDate", parsedPostResponse.get("createdDate"));
    testPostPutPositive.put("modifiedDate", parsedPostResponse.get("modifiedDate"));

    //verify post worked
    expect().statusCode(200).log().ifError().contentType("application/json")
            .body("", equalTo(testPostPutPositive)).when()
            .get(SELF_HELP_GUIDE_QUESTION_PATH + "/" + postContentUUID);

    testPostPutPositive.remove("id");
    testPostPutPositive.put("description", ("testReferencePut" + testPassDeConflictNumber));

    //put
    expect().statusCode(200).log().ifError().given().contentType("application/json").body(testPostPutPositive)
            .when().put(SELF_HELP_GUIDE_QUESTION_PATH + "/" + postContentUUID);

    //get more complete data from put using get
    final Response putResponse = expect().statusCode(200).log().ifError().contentType("application/json").when()
            .get(SELF_HELP_GUIDE_QUESTION_PATH + "/" + postContentUUID);

    testPostPutPositive.put("id", postContentUUID);
    testPostPutPositive.put("modifiedDate", putResponse.getBody().jsonPath().getJsonObject("modifiedDate"));

    //verify put worked
    expect().statusCode(200).log().ifError().contentType("application/json")
            .body("", equalTo(testPostPutPositive)).when()
            .get(SELF_HELP_GUIDE_QUESTION_PATH + "/" + postContentUUID);

    //delete
    expect().statusCode(200).log().ifError().when()
            .delete(SELF_HELP_GUIDE_QUESTION_PATH + "/" + postContentUUID);

    testPostPutPositive.put("objectStatus", "INACTIVE");

    //get verify delete worked
    final Response deleteCheckResponse = expect().statusCode(200).log().ifError()
            .contentType("application/json").when().get(SELF_HELP_GUIDE_QUESTION_PATH + "/" + postContentUUID);

    testPostPutPositive.put("modifiedDate",
            deleteCheckResponse.getBody().jsonPath().getJsonObject("modifiedDate"));

    //verify delete is still intact but inactive
    expect().statusCode(200).log().ifError().contentType("application/json")
            .body("", equalTo(testPostPutPositive)).when()
            .get(SELF_HELP_GUIDE_QUESTION_PATH + "/" + postContentUUID);

    //get (verify result # matches expected active)
    expect().statusCode(200).log().ifError().contentType("application/json")
            .body("results", equalTo(checkResultCount)).given().queryParam("status", "ACTIVE").when()
            .get(SELF_HELP_GUIDE_QUESTION_PATH);
}

From source file:org.jolokia.handler.list.MBeanInfoData.java

/**
 * Add information about an MBean as obtained from an {@link MBeanInfo} descriptor. The information added
 * can be restricted by a given path (which has already be prepared as a stack). Also, a max depth as given in the
 * constructor restricts the size of the map from the top.
 *
 * @param mBeanInfo the MBean info//w  w w .ja v  a 2 s . co m
 * @param pName the object name of the MBean
 */
public void addMBeanInfo(MBeanInfo mBeanInfo, ObjectName pName)
        throws InstanceNotFoundException, IntrospectionException, ReflectionException, IOException {

    JSONObject mBeansMap = getOrCreateJSONObject(infoMap, pName.getDomain());
    JSONObject mBeanMap = getOrCreateJSONObject(mBeansMap, getKeyPropertyString(pName));
    // Trim down stack to get rid of domain/property list
    Stack<String> stack = truncatePathStack(2);
    if (stack.empty()) {
        addFullMBeanInfo(mBeanMap, mBeanInfo);
    } else {
        addPartialMBeanInfo(mBeanMap, mBeanInfo, stack);
    }
    // Trim if required
    if (mBeanMap.size() == 0) {
        mBeansMap.remove(getKeyPropertyString(pName));
        if (mBeansMap.size() == 0) {
            infoMap.remove(pName.getDomain());
        }
    }
}

From source file:org.neo4j.gis.spatial.indexfilter.DynamicIndexReader.java

private boolean queryNodeProperties(Node node, JSONObject properties) {
    if (properties != null) {
        if (properties.containsKey("geometry")) {
            System.out.println("Unexpected 'geometry' in query string");
            properties.remove("geometry");
        }//from  w  ww  . ja  v  a 2 s .co m

        for (Object key : properties.keySet()) {
            Object value = node.getProperty(key.toString(), null);
            Object match = properties.get(key);
            // TODO: Find a better way to solve minor type mismatches (Long!=Integer) than the string conversion below
            if (value == null
                    || (match != null && !value.equals(match) && !value.toString().equals(match.toString()))) {
                return false;
            }
        }
    }

    return true;
}

From source file:org.opencastproject.adminui.endpoint.ThemesEndpointTest.java

@Test
public void testCreateTheme() throws ParseException, IOException {
    String themesString = IOUtils.toString(getClass().getResource("/theme-create.json"), "UTF-8");
    Boolean isDefault = true;/*from w ww  . j av  a2s .c  om*/
    String name = "New Theme Name";
    String description = "New Theme Description";

    Boolean bumperActive = true;
    String bumperFile = "bumper-file";

    Boolean trailerActive = true;
    String trailerFile = "trailer-file";

    Boolean titleSlideActive = true;
    String titleSlideBackground = "title-background";
    String titleSlideMetadata = "title-metadata";

    Boolean licenseSlideActive = true;
    String licenseSlideBackground = "license-background";
    String licenseSlideDescription = "license-description";

    Boolean watermarkActive = true;
    String watermarkPosition = "watermark-position";
    String watermarkFile = "watermark-file";

    String result = given().formParam("default", isDefault.toString()).formParam("name", name)
            .formParam("description", description).formParam("bumperActive", bumperActive.toString())
            .formParam("bumperFile", bumperFile).formParam("trailerActive", trailerActive.toString())
            .formParam("trailerFile", trailerFile).formParam("titleSlideActive", titleSlideActive.toString())
            .formParam("titleSlideBackground", titleSlideBackground)
            .formParam("titleSlideMetadata", titleSlideMetadata)
            .formParam("licenseSlideActive", licenseSlideActive)
            .formParam("licenseSlideBackground", licenseSlideBackground)
            .formParam("licenseSlideDescription", licenseSlideDescription)
            .formParam("watermarkActive", watermarkActive).formParam("watermarkPosition", watermarkPosition)
            .formParam("watermarkFile", watermarkFile).expect().statusCode(HttpStatus.SC_OK).when()
            .post(rt.host("/")).asString();

    JSONObject theme = ((JSONObject) parser.parse(result));
    // Make sure the creationDate property exists
    assertTrue(StringUtils.trimToNull(theme.get("creationDate").toString()) != null);
    // Remove it from the results
    theme.remove("creationDate");
    System.out.println("Expected" + themesString);
    System.out.println("Result: " + theme.toJSONString());
    assertThat(themesString, SameJSONAs.sameJSONAs(theme.toJSONString()).allowingAnyArrayOrdering());
}

From source file:org.opencastproject.adminui.endpoint.ThemesEndpointTest.java

@Test
public void testUpdateTheme() throws ParseException, IOException {
    String themesString = IOUtils.toString(getClass().getResource("/theme-update.json"), "UTF-8");
    String result = given().pathParam("themeId", 1).formParam("default", true).formParam("name", "new-name")
            .formParam("description", "new-description").formParam("bumperActive", true)
            .formParam("bumperFile", "new-bumper-file").formParam("trailerActive", true)
            .formParam("trailerFile", "new-trailer-file").formParam("titleSlideActive", true)
            .formParam("titleSlideBackground", "new-title-background")
            .formParam("titleSlideMetadata", "new-title-metadata").formParam("licenseSlideActive", true)
            .formParam("licenseSlideBackground", "new-license-background")
            .formParam("licenseSlideDescription", "new-license-description").formParam("watermarkActive", true)
            .formParam("watermarkPosition", "new-watermark-position")
            .formParam("watermarkFile", "new-watermark-file").expect().statusCode(HttpStatus.SC_OK).when()
            .put(rt.host("/{themeId}")).asString();

    JSONObject theme = ((JSONObject) parser.parse(result));
    // Make sure the creationDate property exists
    assertTrue(StringUtils.trimToNull(theme.get("creationDate").toString()) != null);
    // Remove it from the results
    theme.remove("creationDate");
    System.out.println("Expected" + themesString);
    System.out.println("Result: " + theme.toJSONString());
    assertThat(themesString, SameJSONAs.sameJSONAs(theme.toJSONString()).allowingAnyArrayOrdering());
}