Search in sources :

Example 61 with JsonPath

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

the class FileRecordJobIT method testPublishedDataset.

@Test
@Ignore
public /**
 * Published datasets should not allow import jobs for now since it isn't in DRAFT mode
 */
void testPublishedDataset() {
    try {
        RestAssured.urlEncodingEnabled = false;
        // publish the dataverse
        System.out.println("DATAVERSE: http://localhost:8080/api/dataverses/" + testName + "/actions/:publish?key=" + token);
        given().body("{}").contentType("application/json").post("/api/dataverses/" + testName + "/actions/:publish?key=" + token).then().assertThat().statusCode(200);
        // publish the dataset
        System.out.println("DATASET: http://localhost:8080/api/datasets/" + dsId + "/actions/:publish?type=major&key=" + token);
        given().get("/api/datasets/" + dsId + "/actions/:publish?type=major&key=" + token).then().assertThat().statusCode(200);
        isDraft = false;
        JsonPath jsonPath = getFaileJobJson();
        assertTrue(jsonPath.getString("status").equalsIgnoreCase("ERROR"));
        assertTrue(jsonPath.getString("message").contains("Dataset isn't in DRAFT mode."));
    } catch (Exception e) {
        System.out.println("Error testChecksumImport: " + e.getMessage());
        e.printStackTrace();
        fail();
    }
}
Also used : JsonPath(com.jayway.restassured.path.json.JsonPath) IOException(java.io.IOException) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 62 with JsonPath

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

the class BatchImportIT method setUpClass.

@BeforeClass
public static void setUpClass() {
    Response createUserResponse = createUser(getRandomUsername(), "firstName", "lastName");
    // createUserResponse.prettyPrint();
    assertEquals(200, createUserResponse.getStatusCode());
    JsonPath createdUser1 = JsonPath.from(createUserResponse.body().asString());
    apiToken1 = createdUser1.getString("data." + apiTokenKey);
    username1 = createdUser1.getString("data.user." + usernameKey);
    Response makeSuperuserResponse = makeSuperuser(username1);
    assertEquals(200, makeSuperuserResponse.getStatusCode());
    Response createUserResponse1 = createUser(getRandomUsername(), "firstName", "lastName");
    // createUserResponse.prettyPrint();
    assertEquals(200, createUserResponse1.getStatusCode());
    JsonPath createdUser2 = JsonPath.from(createUserResponse1.body().asString());
    apiToken2 = createdUser2.getString("data." + apiTokenKey);
    username2 = createdUser2.getString("data.user." + usernameKey);
    dataverseAlias = "dv" + getRandomIdentifier();
    Response createDataverseResponse = createDataverse(dataverseAlias, apiToken1);
// createDataverseResponse.prettyPrint();
// assertEquals(201, createDataverseResponse.getStatusCode());
}
Also used : Response(com.jayway.restassured.response.Response) JsonPath(com.jayway.restassured.path.json.JsonPath) BeforeClass(org.junit.BeforeClass)

Example 63 with JsonPath

use of com.jayway.restassured.path.json.JsonPath in project components by Talend.

the class VersionControllerImplTest method testGetVersion.

@Test
public void testGetVersion() throws Exception {
    Response r = // 
    given().accept(APPLICATION_JSON_UTF8_VALUE).expect().statusCode(200).log().ifError().with().port(// 
    localServerPort).get(getVersionPrefix() + "/version");
    // 
    r.then().statusCode(HttpStatus.OK.value()).log().ifError().contentType(APPLICATION_JSON_UTF8_VALUE);
    // We don't care what values are returned as long as they are filled.
    JsonPath jsonPathEvaluator = r.jsonPath();
    assertThat(jsonPathEvaluator.get("version"), allOf(notNullValue(), not(equalTo(VersionDto.N_A))));
    assertThat(jsonPathEvaluator.get("commit"), allOf(notNullValue(), not(equalTo(VersionDto.N_A))));
    assertThat(jsonPathEvaluator.get("time"), allOf(notNullValue(), not(equalTo(VersionDto.N_A))));
}
Also used : Response(com.jayway.restassured.response.Response) JsonPath(com.jayway.restassured.path.json.JsonPath) Test(org.junit.Test)

Example 64 with JsonPath

use of com.jayway.restassured.path.json.JsonPath in project data-prep by Talend.

the class PreparationAPITest method should_save_created_columns_ids_on_append.

@Test
public void should_save_created_columns_ids_on_append() throws Exception {
    // when
    final String preparationId = testClient.createPreparationFromFile("dataset/dataset.csv", "testPreparation", home.getId());
    // when
    testClient.applyActionFromFile(preparationId, "transformation/copy_firstname.json");
    // then
    final JsonPath jsonPath = given().get("/api/preparations/{preparation}/details", preparationId).jsonPath();
    final List<String> createdColumns = jsonPath.getList("diff[0].createdColumns");
    assertThat(createdColumns, hasSize(1));
    assertThat(createdColumns, hasItem("0006"));
}
Also used : JsonPath(com.jayway.restassured.path.json.JsonPath) Test(org.junit.Test)

Example 65 with JsonPath

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

the class BundleInfoRestEndpointTest method testBundleInfoJsonSerialization.

@Test
public void testBundleInfoJsonSerialization() {
    final JsonPath p = JsonPath.from(bundleInfoJson(bundleInfo("host", "bundle", 1L, "version", some("sha"))).toJson());
    run(BundleInfo.class, new BundleInfo() {

        @Override
        public String getHost() {
            assertEquals("host", p.getString("host"));
            return null;
        }

        @Override
        public String getBundleSymbolicName() {
            assertEquals("bundle", p.getString("bundleSymbolicName"));
            return null;
        }

        @Override
        public long getBundleId() {
            assertEquals(1L, p.getLong("bundleId"));
            return 0;
        }

        @Override
        public String getBundleVersion() {
            assertEquals("bundle", p.getString("bundleSymbolicName"));
            return null;
        }

        @Override
        public Option<String> getBuildNumber() {
            assertEquals("sha", p.getString("buildNumber"));
            return null;
        }

        @Override
        public BundleVersion getVersion() {
            assertEquals("sha", p.getString("buildNumber"));
            return null;
        }
    });
}
Also used : Option(org.opencastproject.util.data.Option) JsonPath(com.jayway.restassured.path.json.JsonPath) Test(org.junit.Test)

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