Search in sources :

Example 56 with JsonPath

use of com.jayway.restassured.path.json.JsonPath in project graylog2-server by Graylog2.

the class StreamsTest method updatingMatchingTypeOfStream.

@Test
@MongoDbSeed(locations = { "single-stream", "second-single-stream" })
public void updatingMatchingTypeOfStream() {
    // id of stream to be updated
    final String streamId = "552b92b2e4b0c055e41ffb8d";
    // id of stream that is supposed to be left untampered
    final String otherStreamId = "552b92b2e4b0c055e41ffb8e";
    assertThat(streamCount()).isEqualTo(2);
    final JsonPath response = given().when().body("{\"matching_type\":\"OR\"}").put("/streams/" + streamId).then().statusCode(200).contentType(ContentType.JSON).extract().jsonPath();
    assertThat(response.getString("matching_type")).isEqualTo("OR");
    getStream(streamId).statusCode(200).assertThat().body("matching_type", equalTo("OR"));
    getStream(otherStreamId).statusCode(200).assertThat().body("matching_type", equalTo("AND"));
}
Also used : JsonPath(com.jayway.restassured.path.json.JsonPath) Test(org.junit.Test) BaseRestTest(integration.BaseRestTest) MongoDbSeed(integration.MongoDbSeed)

Example 57 with JsonPath

use of com.jayway.restassured.path.json.JsonPath in project graylog2-server by Graylog2.

the class StreamsTest method listStreamsWhenNoStreamsArePresent.

@Test
public void listStreamsWhenNoStreamsArePresent() throws Exception {
    final JsonPath response = given().when().get("/streams").then().statusCode(200).assertThat().body(".", containsAllKeys("total", "streams")).extract().jsonPath();
    assertThat(response.getInt("total")).isEqualTo(0);
    assertThat(response.getList("streams")).isEmpty();
}
Also used : JsonPath(com.jayway.restassured.path.json.JsonPath) Test(org.junit.Test) BaseRestTest(integration.BaseRestTest)

Example 58 with JsonPath

use of com.jayway.restassured.path.json.JsonPath in project ddf by codice.

the class TestFederation method testAsyncDownloadActionPresentUsingCometDClient.

/**
     * Tests that the async download action's URL is returned in the CometD search results.
     *
     * @throws Exception
     */
@Test
// TODO: DDF-2581
@ConditionalIgnore(condition = SkipUnstableTest.class)
public void testAsyncDownloadActionPresentUsingCometDClient() throws Exception {
    getCatalogBundle().setupCaching(true);
    String src = "ddf.distribution";
    String metacardId = ingestXmlWithProduct(String.format("%s.txt", testName.getMethodName()));
    String responseChannelId = "0193d9e7f9ed4f8f8bd02103143c41d6";
    String responseChannelPath = String.format("/%s", responseChannelId);
    String expectedUrl = String.format("%s?source=%s&metacard=%s", RESOURCE_DOWNLOAD_ENDPOINT_ROOT.getUrl(), src, metacardId);
    String actionTitle = "Copy resource to local site";
    cometDClient = setupCometDClient(Collections.singletonList(responseChannelPath));
    cometDClient.searchByMetacardId(responseChannelId, src, metacardId);
    expect("CometD query response").within(20, SECONDS).until(() -> cometDClient.getMessages(responseChannelPath).size() >= 1);
    Optional<String> searchResult = cometDClient.searchMessages(metacardId);
    assertThat("Async download action not found", searchResult.isPresent(), is(true));
    JsonPath path = JsonPath.from(searchResult.get());
    assertThat(path.getString(String.format(FIND_ACTION_URL_BY_TITLE_PATTERN, actionTitle)), is(expectedUrl));
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) JsonPath(com.jayway.restassured.path.json.JsonPath) ConditionalIgnore(org.codice.ddf.itests.common.annotations.ConditionalIgnoreRule.ConditionalIgnore) SkipUnstableTest(org.codice.ddf.itests.common.annotations.SkipUnstableTest) Test(org.junit.Test) AbstractIntegrationTest(org.codice.ddf.itests.common.AbstractIntegrationTest)

Example 59 with JsonPath

use of com.jayway.restassured.path.json.JsonPath in project ddf by codice.

the class TestSecurity method testCertificateGeneratorService.

//Purpose is to make sure operations of the security certificate generator are accessible
//at runtime. The actual functionality of these operations is proved in unit tests.
@Test
public void testCertificateGeneratorService() throws Exception {
    String commonName = "myCn";
    String expectedValue = "CN=" + commonName;
    String featureName = "security-certificate";
    String certGenPath = SECURE_ROOT_AND_PORT + "/admin/jolokia/exec/org.codice.ddf.security.certificate.generator.CertificateGenerator:service=certgenerator";
    getBackupKeystoreFile();
    try {
        getServiceManager().startFeature(true, featureName);
        //Test first operation
        Response response = given().auth().basic("admin", "admin").when().get(certGenPath + "/configureDemoCert/" + commonName);
        String actualValue = JsonPath.from(response.getBody().asString()).getString("value");
        assertThat(actualValue, equalTo(expectedValue));
        //Test second operation
        response = given().auth().basic("admin", "admin").when().get(certGenPath + "/configureDemoCertWithDefaultHostname");
        String jsonString = response.getBody().asString();
        JsonPath jsonPath = JsonPath.from(jsonString);
        //If the key value exists, the return value is well-formatted (i.e. not a stacktrace)
        assertThat(jsonPath.getString("value"), notNullValue());
        //Make sure an invalid key would return null
        assertThat(jsonPath.getString("someinvalidkey"), nullValue());
        getServiceManager().stopFeature(false, featureName);
    } finally {
        restoreKeystoreFile();
    }
}
Also used : Response(com.jayway.restassured.response.Response) Matchers.containsString(org.hamcrest.Matchers.containsString) JsonPath(com.jayway.restassured.path.json.JsonPath) AbstractIntegrationTest(org.codice.ddf.itests.common.AbstractIntegrationTest) Test(org.junit.Test)

Example 60 with JsonPath

use of com.jayway.restassured.path.json.JsonPath in project dataverse by IQSS.

the class UtilIT method getUsernameFromResponse.

static String getUsernameFromResponse(Response createUserResponse) {
    JsonPath createdUser = JsonPath.from(createUserResponse.body().asString());
    String username = createdUser.getString("data.user." + USERNAME_KEY);
    logger.info("Username found in create user response: " + username);
    return username;
}
Also used : JsonPath(com.jayway.restassured.path.json.JsonPath)

Aggregations

JsonPath (com.jayway.restassured.path.json.JsonPath)87 Test (org.junit.Test)56 Response (com.jayway.restassured.response.Response)29 BaseRestTest (integration.BaseRestTest)11 BaseRestIntegrationTest (se.inera.intyg.webcert.web.web.controller.integrationtest.BaseRestIntegrationTest)10 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)9 Matchers.anyString (org.mockito.Matchers.anyString)8 ValidatableResponse (com.jayway.restassured.response.ValidatableResponse)6 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)6 Matchers.containsString (org.hamcrest.Matchers.containsString)6 UsingDataSet (com.lordofthejars.nosqlunit.annotation.UsingDataSet)5 HttpServletResponse (javax.servlet.http.HttpServletResponse)5 Ignore (org.junit.Ignore)5 MongoDbSeed (integration.MongoDbSeed)4 HashMap (java.util.HashMap)3 Then (cucumber.api.java.en.Then)2 AbstractIntegrationTest (org.codice.ddf.itests.common.AbstractIntegrationTest)2 BaseMatcher (org.hamcrest.BaseMatcher)2 Description (org.hamcrest.Description)2 PreparationDTO (org.talend.dataprep.api.preparation.PreparationDTO)2