Example usage for org.springframework.http MediaType APPLICATION_JSON_UTF8_VALUE

List of usage examples for org.springframework.http MediaType APPLICATION_JSON_UTF8_VALUE

Introduction

In this page you can find the example usage for org.springframework.http MediaType APPLICATION_JSON_UTF8_VALUE.

Prototype

String APPLICATION_JSON_UTF8_VALUE

To view the source code for org.springframework.http MediaType APPLICATION_JSON_UTF8_VALUE.

Click Source Link

Document

A String equivalent of MediaType#APPLICATION_JSON_UTF8 .

Usage

From source file:org.apache.zeppelin.livy.BaseLivyInterpreter.java

private String callRestAPI(String targetURL, String method, String jsonData) throws LivyException {
    targetURL = livyURL + targetURL;// w w w.  j a  v a2 s .c o m
    LOGGER.debug("Call rest api in {}, method: {}, jsonData: {}", targetURL, method, jsonData);
    HttpHeaders headers = new HttpHeaders();
    headers.add("Content-Type", MediaType.APPLICATION_JSON_UTF8_VALUE);
    headers.add("X-Requested-By", "zeppelin");
    for (Map.Entry<String, String> entry : customHeaders.entrySet()) {
        headers.add(entry.getKey(), entry.getValue());
    }
    ResponseEntity<String> response = null;
    try {
        if (method.equals("POST")) {
            HttpEntity<String> entity = new HttpEntity<>(jsonData, headers);
            response = restTemplate.exchange(targetURL, HttpMethod.POST, entity, String.class);
        } else if (method.equals("GET")) {
            HttpEntity<String> entity = new HttpEntity<>(headers);
            response = restTemplate.exchange(targetURL, HttpMethod.GET, entity, String.class);
        } else if (method.equals("DELETE")) {
            HttpEntity<String> entity = new HttpEntity<>(headers);
            response = restTemplate.exchange(targetURL, HttpMethod.DELETE, entity, String.class);
        }
    } catch (HttpClientErrorException e) {
        response = new ResponseEntity(e.getResponseBodyAsString(), e.getStatusCode());
        LOGGER.error(String.format("Error with %s StatusCode: %s", response.getStatusCode().value(),
                e.getResponseBodyAsString()));
    } catch (RestClientException e) {
        // Exception happens when kerberos is enabled.
        if (e.getCause() instanceof HttpClientErrorException) {
            HttpClientErrorException cause = (HttpClientErrorException) e.getCause();
            if (cause.getResponseBodyAsString().matches(SESSION_NOT_FOUND_PATTERN)) {
                throw new SessionNotFoundException(cause.getResponseBodyAsString());
            }
            throw new LivyException(cause.getResponseBodyAsString() + "\n"
                    + ExceptionUtils.getFullStackTrace(ExceptionUtils.getRootCause(e)));
        }
        if (e instanceof HttpServerErrorException) {
            HttpServerErrorException errorException = (HttpServerErrorException) e;
            String errorResponse = errorException.getResponseBodyAsString();
            if (errorResponse.contains("Session is in state dead")) {
                throw new SessionDeadException();
            }
            throw new LivyException(errorResponse, e);
        }
        throw new LivyException(e);
    }
    if (response == null) {
        throw new LivyException("No http response returned");
    }
    LOGGER.debug("Get response, StatusCode: {}, responseBody: {}", response.getStatusCode(),
            response.getBody());
    if (response.getStatusCode().value() == 200 || response.getStatusCode().value() == 201) {
        return response.getBody();
    } else if (response.getStatusCode().value() == 404) {
        if (response.getBody().matches(SESSION_NOT_FOUND_PATTERN)) {
            throw new SessionNotFoundException(response.getBody());
        } else {
            throw new APINotFoundException(
                    "No rest api found for " + targetURL + ", " + response.getStatusCode());
        }
    } else {
        String responseString = response.getBody();
        if (responseString.contains("CreateInteractiveRequest[\\\"master\\\"]")) {
            return responseString;
        }
        throw new LivyException(String.format("Error with %s StatusCode: %s", response.getStatusCode().value(),
                responseString));
    }
}

From source file:org.eclipse.hawkbit.mgmt.rest.resource.MgmtDistributionSetResourceTest.java

@Test
@WithUser(principal = "uploadTester", allSpPermissions = true)
@Description("Ensures that multiple DS requested are listed with expected payload.")
public void getDistributionSets() throws Exception {
    // prepare test data
    assertThat(distributionSetManagement.findByCompleted(PAGE, true)).hasSize(0);

    DistributionSet set = testdataFactory.createDistributionSet("one");
    set = distributionSetManagement.update(entityFactory.distributionSet().update(set.getId())
            .version("anotherVersion").requiredMigrationStep(true));

    // load also lazy stuff
    set = distributionSetManagement.getWithDetails(set.getId()).get();

    assertThat(distributionSetManagement.findByCompleted(PAGE, true)).hasSize(1);

    // perform request
    mvc.perform(get("/rest/v1/distributionsets").accept(MediaType.APPLICATION_JSON))
            .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
            .andExpect(jsonPath("$.content.[0]._links.self.href",
                    equalTo("http://localhost/rest/v1/distributionsets/" + set.getId())))
            .andExpect(jsonPath("$.content.[0].id", equalTo(set.getId().intValue())))
            .andExpect(jsonPath("$.content.[0].name", equalTo(set.getName())))
            .andExpect(jsonPath("$.content.[0].requiredMigrationStep", equalTo(Boolean.TRUE)))
            .andExpect(jsonPath("$.content.[0].description", equalTo(set.getDescription())))
            .andExpect(jsonPath("$.content.[0].type", equalTo(set.getType().getKey())))
            .andExpect(jsonPath("$.content.[0].createdBy", equalTo(set.getCreatedBy())))
            .andExpect(jsonPath("$.content.[0].createdAt", equalTo(set.getCreatedAt())))
            .andExpect(jsonPath("$.content.[0].complete", equalTo(Boolean.TRUE)))
            .andExpect(jsonPath("$.content.[0].lastModifiedBy", equalTo(set.getLastModifiedBy())))
            .andExpect(jsonPath("$.content.[0].lastModifiedAt", equalTo(set.getLastModifiedAt())))
            .andExpect(jsonPath("$.content.[0].version", equalTo(set.getVersion())))
            .andExpect(jsonPath("$.content.[0].modules.[?(@.type=='" + runtimeType.getKey() + "')].id",
                    contains(set.findFirstModuleByType(runtimeType).get().getId().intValue())))
            .andExpect(jsonPath("$.content.[0].modules.[?(@.type=='" + appType.getKey() + "')].id",
                    contains(set.findFirstModuleByType(appType).get().getId().intValue())))
            .andExpect(jsonPath("$.content.[0].modules.[?(@.type=='" + osType.getKey() + "')].id",
                    contains(getOsModule(set).intValue())));
}

From source file:org.eclipse.hawkbit.mgmt.rest.resource.MgmtDistributionSetResourceTest.java

@Test
@WithUser(principal = "uploadTester", allSpPermissions = true)
@Description("Ensures that single DS requested by ID is listed with expected payload.")
public void getDistributionSet() throws Exception {
    final DistributionSet set = testdataFactory.createUpdatedDistributionSet();

    // perform request
    mvc.perform(get("/rest/v1/distributionsets/{dsId}", set.getId()).accept(MediaType.APPLICATION_JSON))
            .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
            .andExpect(jsonPath("$._links.self.href",
                    equalTo("http://localhost/rest/v1/distributionsets/" + set.getId())))
            .andExpect(jsonPath("$.id", equalTo(set.getId().intValue())))
            .andExpect(jsonPath("$.name", equalTo(set.getName())))
            .andExpect(jsonPath("$.type", equalTo(set.getType().getKey())))
            .andExpect(jsonPath("$.description", equalTo(set.getDescription())))
            .andExpect(jsonPath("$.requiredMigrationStep", equalTo(set.isRequiredMigrationStep())))
            .andExpect(jsonPath("$.createdBy", equalTo(set.getCreatedBy())))
            .andExpect(jsonPath("$.complete", equalTo(Boolean.TRUE)))
            .andExpect(jsonPath("$.deleted", equalTo(set.isDeleted())))
            .andExpect(jsonPath("$.createdAt", equalTo(set.getCreatedAt())))
            .andExpect(jsonPath("$.lastModifiedBy", equalTo(set.getLastModifiedBy())))
            .andExpect(jsonPath("$.lastModifiedAt", equalTo(set.getLastModifiedAt())))
            .andExpect(jsonPath("$.version", equalTo(set.getVersion())))
            .andExpect(jsonPath("$.modules.[?(@.type=='" + runtimeType.getKey() + "')].id",
                    contains(set.findFirstModuleByType(runtimeType).get().getId().intValue())))
            .andExpect(jsonPath("$.modules.[?(@.type=='" + appType.getKey() + "')].id",
                    contains(set.findFirstModuleByType(appType).get().getId().intValue())))
            .andExpect(jsonPath("$.modules.[?(@.type=='" + osType.getKey() + "')].id",
                    contains(getOsModule(set).intValue())));

}

From source file:org.eclipse.hawkbit.mgmt.rest.resource.MgmtDistributionSetResourceTest.java

@Step
private MvcResult executeMgmtTargetPost(final DistributionSet one, final DistributionSet two,
        final DistributionSet three) throws Exception {
    return mvc//from  ww w  . j  a va2s. co  m
            .perform(post("/rest/v1/distributionsets/")
                    .content(JsonBuilder.distributionSets(Arrays.asList(one, two, three)))
                    .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
            .andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
            .andExpect(jsonPath("[0]name", equalTo(one.getName())))
            .andExpect(jsonPath("[0]description", equalTo(one.getDescription())))
            .andExpect(jsonPath("[0]type", equalTo(standardDsType.getKey())))
            .andExpect(jsonPath("[0]createdBy", equalTo("uploadTester")))
            .andExpect(jsonPath("[0]version", equalTo(one.getVersion())))
            .andExpect(jsonPath("[0]complete", equalTo(Boolean.TRUE)))
            .andExpect(jsonPath("[0]requiredMigrationStep", equalTo(one.isRequiredMigrationStep())))
            .andExpect(jsonPath("[0].modules.[?(@.type=='" + runtimeType.getKey() + "')].id",
                    contains(one.findFirstModuleByType(runtimeType).get().getId().intValue())))
            .andExpect(jsonPath("[0].modules.[?(@.type=='" + appType.getKey() + "')].id",
                    contains(one.findFirstModuleByType(appType).get().getId().intValue())))
            .andExpect(jsonPath("[0].modules.[?(@.type=='" + osType.getKey() + "')].id",
                    contains(one.findFirstModuleByType(osType).get().getId().intValue())))
            .andExpect(jsonPath("[1]name", equalTo(two.getName())))
            .andExpect(jsonPath("[1]description", equalTo(two.getDescription())))
            .andExpect(jsonPath("[1]complete", equalTo(Boolean.TRUE)))
            .andExpect(jsonPath("[1]type", equalTo(standardDsType.getKey())))
            .andExpect(jsonPath("[1]createdBy", equalTo("uploadTester")))
            .andExpect(jsonPath("[1]version", equalTo(two.getVersion())))
            .andExpect(jsonPath("[1].modules.[?(@.type=='" + runtimeType.getKey() + "')].id",
                    contains(two.findFirstModuleByType(runtimeType).get().getId().intValue())))
            .andExpect(jsonPath("[1].modules.[?(@.type=='" + appType.getKey() + "')].id",
                    contains(two.findFirstModuleByType(appType).get().getId().intValue())))
            .andExpect(jsonPath("[1].modules.[?(@.type=='" + osType.getKey() + "')].id",
                    contains(two.findFirstModuleByType(osType).get().getId().intValue())))
            .andExpect(jsonPath("[1]requiredMigrationStep", equalTo(two.isRequiredMigrationStep())))
            .andExpect(jsonPath("[2]name", equalTo(three.getName())))
            .andExpect(jsonPath("[2]description", equalTo(three.getDescription())))
            .andExpect(jsonPath("[2]complete", equalTo(Boolean.TRUE)))
            .andExpect(jsonPath("[2]type", equalTo(standardDsType.getKey())))
            .andExpect(jsonPath("[2]createdBy", equalTo("uploadTester")))
            .andExpect(jsonPath("[2]version", equalTo(three.getVersion())))
            .andExpect(jsonPath("[2].modules.[?(@.type=='" + runtimeType.getKey() + "')].id",
                    contains(three.findFirstModuleByType(runtimeType).get().getId().intValue())))
            .andExpect(jsonPath("[2].modules.[?(@.type=='" + appType.getKey() + "')].id",
                    contains(three.findFirstModuleByType(appType).get().getId().intValue())))
            .andExpect(jsonPath("[2].modules.[?(@.type=='" + osType.getKey() + "')].id",
                    contains(three.findFirstModuleByType(osType).get().getId().intValue())))
            .andExpect(jsonPath("[2]requiredMigrationStep", equalTo(three.isRequiredMigrationStep())))
            .andReturn();
}

From source file:org.eclipse.hawkbit.mgmt.rest.resource.MgmtDistributionSetResourceTest.java

@Test
@Description("Ensures that the metadata creation through API is reflected by the repository.")
public void createMetadata() throws Exception {
    final DistributionSet testDS = testdataFactory.createDistributionSet("one");

    final String knownKey1 = "knownKey1";
    final String knownKey2 = "knownKey2";

    final String knownValue1 = "knownValue1";
    final String knownValue2 = "knownValue2";

    final JSONArray metaData1 = new JSONArray();
    metaData1.put(new JSONObject().put("key", knownKey1).put("value", knownValue1));
    metaData1.put(new JSONObject().put("key", knownKey2).put("value", knownValue2));

    mvc.perform(//from ww  w .  j  a v a  2 s  .  c  om
            post("/rest/v1/distributionsets/{dsId}/metadata", testDS.getId()).accept(MediaType.APPLICATION_JSON)
                    .contentType(MediaType.APPLICATION_JSON).content(metaData1.toString()))
            .andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
            .andExpect(jsonPath("[0]key", equalTo(knownKey1)))
            .andExpect(jsonPath("[0]value", equalTo(knownValue1)))
            .andExpect(jsonPath("[1]key", equalTo(knownKey2)))
            .andExpect(jsonPath("[1]value", equalTo(knownValue2)));

    final DistributionSetMetadata metaKey1 = distributionSetManagement
            .getMetaDataByDistributionSetId(testDS.getId(), knownKey1).get();
    final DistributionSetMetadata metaKey2 = distributionSetManagement
            .getMetaDataByDistributionSetId(testDS.getId(), knownKey2).get();

    assertThat(metaKey1.getValue()).isEqualTo(knownValue1);
    assertThat(metaKey2.getValue()).isEqualTo(knownValue2);

    // verify quota enforcement
    final int maxMetaData = quotaManagement.getMaxMetaDataEntriesPerDistributionSet();

    final JSONArray metaData2 = new JSONArray();
    for (int i = 0; i < maxMetaData - metaData1.length() + 1; ++i) {
        metaData2.put(new JSONObject().put("key", knownKey1 + i).put("value", knownValue1 + i));
    }

    mvc.perform(
            post("/rest/v1/distributionsets/{dsId}/metadata", testDS.getId()).accept(MediaType.APPLICATION_JSON)
                    .contentType(MediaType.APPLICATION_JSON).content(metaData2.toString()))
            .andDo(MockMvcResultPrinter.print()).andExpect(status().isForbidden());

    // verify that the number of meta data entries has not changed
    // (we cannot use the PAGE constant here as it tries to sort by ID)
    assertThat(distributionSetManagement
            .findMetaDataByDistributionSetId(PageRequest.of(0, Integer.MAX_VALUE), testDS.getId())
            .getTotalElements()).isEqualTo(metaData1.length());

}

From source file:org.eclipse.hawkbit.mgmt.rest.resource.MgmtDistributionSetResourceTest.java

@Test
@Description("Ensures that a metadata update through API is reflected by the repository.")
public void updateMetadata() throws Exception {
    // prepare and create metadata for update
    final String knownKey = "knownKey";
    final String knownValue = "knownValue";
    final String updateValue = "valueForUpdate";

    final DistributionSet testDS = testdataFactory.createDistributionSet("one");
    createDistributionSetMetadata(testDS.getId(), entityFactory.generateDsMetadata(knownKey, knownValue));

    final JSONObject jsonObject = new JSONObject().put("key", knownKey).put("value", updateValue);

    mvc.perform(put("/rest/v1/distributionsets/{dsId}/metadata/{key}", testDS.getId(), knownKey)
            .accept(MediaType.APPLICATION_JSON).contentType(MediaType.APPLICATION_JSON)
            .content(jsonObject.toString())).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
            .andExpect(jsonPath("key", equalTo(knownKey))).andExpect(jsonPath("value", equalTo(updateValue)));

    final DistributionSetMetadata assertDS = distributionSetManagement
            .getMetaDataByDistributionSetId(testDS.getId(), knownKey).get();
    assertThat(assertDS.getValue()).isEqualTo(updateValue);

}

From source file:org.eclipse.hawkbit.mgmt.rest.resource.MgmtDistributionSetTypeResourceTest.java

@Test
@WithUser(principal = "uploadTester", allSpPermissions = true)
@Description("Checks the correct behaviour of /rest/v1/distributionsettypes GET requests.")
public void getDistributionSetTypes() throws Exception {

    DistributionSetType testType = distributionSetTypeManagement.create(entityFactory.distributionSetType()
            .create().key("test123").name("TestName123").description("Desc123").colour("col12"));
    testType = distributionSetTypeManagement
            .update(entityFactory.distributionSetType().update(testType.getId()).description("Desc1234"));

    // 4 types overall (2 hawkbit tenant default, 1 test default and 1
    // generated in this test)
    mvc.perform(get("/rest/v1/distributionsettypes").accept(MediaType.APPLICATION_JSON))
            .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
            .andExpect(jsonPath("$.content.[?(@.key=='" + standardDsType.getKey() + "')].name",
                    contains(standardDsType.getName())))
            .andExpect(jsonPath("$.content.[?(@.key=='" + standardDsType.getKey() + "')].description",
                    contains(standardDsType.getDescription())))
            .andExpect(jsonPath("$.content.[?(@.key=='" + standardDsType.getKey() + "')].key",
                    contains(standardDsType.getKey())))
            .andExpect(jsonPath("$.content.[?(@.key=='test123')].id", contains(testType.getId().intValue())))
            .andExpect(jsonPath("$.content.[?(@.key=='test123')].name", contains("TestName123")))
            .andExpect(jsonPath("$.content.[?(@.key=='test123')].description", contains("Desc1234")))
            .andExpect(jsonPath("$.content.[?(@.key=='test123')].createdBy", contains("uploadTester")))
            .andExpect(jsonPath("$.content.[?(@.key=='test123')].createdAt", contains(testType.getCreatedAt())))
            .andExpect(jsonPath("$.content.[?(@.key=='test123')].lastModifiedBy", contains("uploadTester")))
            .andExpect(jsonPath("$.content.[?(@.key=='test123')].lastModifiedAt",
                    contains(testType.getLastModifiedAt())))
            .andExpect(jsonPath("$.content.[?(@.key=='test123')].key", contains("test123")))
            .andExpect(jsonPath("$.content.[?(@.key=='test123')]._links.self.href",
                    contains("http://localhost/rest/v1/distributionsettypes/" + testType.getId())))
            .andExpect(jsonPath("$.total", equalTo(5)));
}

From source file:org.eclipse.hawkbit.mgmt.rest.resource.MgmtDistributionSetTypeResourceTest.java

@Test
@WithUser(principal = "uploadTester", allSpPermissions = true)
@Description("Checks the correct behaviour of /rest/v1/distributionsettypes GET requests with sorting by KEY.")
public void getDistributionSetTypesSortedByKey() throws Exception {

    DistributionSetType testType = distributionSetTypeManagement.create(entityFactory.distributionSetType()
            .create().key("zzzzz").name("TestName123").description("Desc123").colour("col12"));
    testType = distributionSetTypeManagement
            .update(entityFactory.distributionSetType().update(testType.getId()).description("Desc1234"));

    // descending
    mvc.perform(get("/rest/v1/distributionsettypes").accept(MediaType.APPLICATION_JSON)
            .param(MgmtRestConstants.REQUEST_PARAMETER_SORTING, "KEY:DESC")).andDo(MockMvcResultPrinter.print())
            .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
            .andExpect(jsonPath("$.content.[0].id", equalTo(testType.getId().intValue())))
            .andExpect(jsonPath("$.content.[0].name", equalTo("TestName123")))
            .andExpect(jsonPath("$.content.[0].description", equalTo("Desc1234")))
            .andExpect(jsonPath("$.content.[0].createdBy", equalTo("uploadTester")))
            .andExpect(jsonPath("$.content.[0].createdAt", equalTo(testType.getCreatedAt())))
            .andExpect(jsonPath("$.content.[0].lastModifiedBy", equalTo("uploadTester")))
            .andExpect(jsonPath("$.content.[0].lastModifiedAt", equalTo(testType.getLastModifiedAt())))
            .andExpect(jsonPath("$.content.[0].key", equalTo("zzzzz")))
            .andExpect(jsonPath("$.total", equalTo(DEFAULT_DS_TYPES + 1)));

    // ascending//from  ww  w.  j  a v  a  2  s .c  om
    mvc.perform(get("/rest/v1/distributionsettypes").accept(MediaType.APPLICATION_JSON)
            .param(MgmtRestConstants.REQUEST_PARAMETER_SORTING, "KEY:ASC")).andDo(MockMvcResultPrinter.print())
            .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
            .andExpect(jsonPath("$.content.[4].id", equalTo(testType.getId().intValue())))
            .andExpect(jsonPath("$.content.[4].name", equalTo("TestName123")))
            .andExpect(jsonPath("$.content.[4].description", equalTo("Desc1234")))
            .andExpect(jsonPath("$.content.[4].createdBy", equalTo("uploadTester")))
            .andExpect(jsonPath("$.content.[4].createdAt", equalTo(testType.getCreatedAt())))
            .andExpect(jsonPath("$.content.[4].lastModifiedBy", equalTo("uploadTester")))
            .andExpect(jsonPath("$.content.[4].lastModifiedAt", equalTo(testType.getLastModifiedAt())))
            .andExpect(jsonPath("$.content.[4].key", equalTo("zzzzz")))
            .andExpect(jsonPath("$.total", equalTo(DEFAULT_DS_TYPES + 1)));
}

From source file:org.eclipse.hawkbit.mgmt.rest.resource.MgmtDistributionSetTypeResourceTest.java

@Step
private MvcResult runPostDistributionSetType(final List<DistributionSetType> types) throws Exception {
    return mvc//from   ww  w . j av a 2  s .c  o m
            .perform(post("/rest/v1/distributionsettypes/").content(JsonBuilder.distributionSetTypes(types))
                    .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
            .andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
            .andExpect(jsonPath("[0].name", equalTo("TestName1")))
            .andExpect(jsonPath("[0].key", equalTo("testKey1")))
            .andExpect(jsonPath("[0].description", equalTo("Desc1")))
            .andExpect(jsonPath("[0].createdBy", equalTo("uploadTester")))
            .andExpect(jsonPath("[1].name", equalTo("TestName2")))
            .andExpect(jsonPath("[1].key", equalTo("testKey2")))
            .andExpect(jsonPath("[1].description", equalTo("Desc2")))
            .andExpect(jsonPath("[1].createdBy", equalTo("uploadTester")))
            .andExpect(jsonPath("[2].name", equalTo("TestName3")))
            .andExpect(jsonPath("[2].key", equalTo("testKey3")))
            .andExpect(jsonPath("[2].description", equalTo("Desc3")))
            .andExpect(jsonPath("[2].createdBy", equalTo("uploadTester")))
            .andExpect(jsonPath("[2].createdAt", not(equalTo(0)))).andReturn();
}

From source file:org.eclipse.hawkbit.mgmt.rest.resource.MgmtDistributionSetTypeResourceTest.java

@Test
@WithUser(principal = "uploadTester", allSpPermissions = true)
@Description("Checks the correct behaviour of /rest/v1/distributionsettypes/{ID}/mandatorymoduletypes GET requests.")
public void getMandatoryModulesOfDistributionSetType() throws Exception {
    final DistributionSetType testType = generateTestType();

    mvc.perform(get("/rest/v1/distributionsettypes/{dstID}/mandatorymoduletypes", testType.getId())
            .accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
            .andExpect(jsonPath("[0].name", equalTo(osType.getName())))
            .andExpect(jsonPath("[0].description", equalTo(osType.getDescription())))
            .andExpect(jsonPath("[0].maxAssignments", equalTo(1)))
            .andExpect(jsonPath("[0].key", equalTo("os")));
}