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.eclipse.hawkbit.mgmt.rest.resource.MgmtDistributionSetTypeResourceTest.java

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

    mvc.perform(get("/rest/v1/distributionsettypes/{dstID}/optionalmoduletypes", 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(appType.getName())))
            .andExpect(jsonPath("[0].description", equalTo(appType.getDescription())))
            .andExpect(jsonPath("[0].maxAssignments", equalTo(Integer.MAX_VALUE)))
            .andExpect(jsonPath("[0].key", equalTo("application")));
}

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} GET requests.")
public void getDistributionSetType() 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"));

    mvc.perform(/*from ww  w  . j  ava2s  . c o  m*/
            get("/rest/v1/distributionsettypes/{dstId}", testType.getId()).accept(MediaType.APPLICATION_JSON))
            .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
            .andExpect(jsonPath("$.name", equalTo("TestName123")))
            .andExpect(jsonPath("$.description", equalTo("Desc1234")))
            .andExpect(jsonPath("$.createdBy", equalTo("uploadTester")))
            .andExpect(jsonPath("$.createdAt", equalTo(testType.getCreatedAt())))
            .andExpect(jsonPath("$.lastModifiedBy", equalTo("uploadTester")))
            .andExpect(jsonPath("$.deleted", equalTo(testType.isDeleted())));
}

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

@Test
@Description("Tests the upload of an artifact binary. The upload is executed and the content checked in the repository for completeness.")
public void uploadArtifact() throws Exception {
    final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();

    // create test file
    final byte random[] = randomBytes(5 * 1024);
    final String md5sum = HashGeneratorUtils.generateMD5(random);
    final String sha1sum = HashGeneratorUtils.generateSHA1(random);
    final MockMultipartFile file = new MockMultipartFile("file", "origFilename", null, random);

    // upload/*www . j a v a  2s. c o m*/
    final MvcResult mvcResult = mvc
            .perform(fileUpload("/rest/v1/softwaremodules/{smId}/artifacts", sm.getId()).file(file)
                    .accept(MediaType.APPLICATION_JSON))
            .andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
            .andExpect(jsonPath("$.hashes.md5", equalTo(md5sum)))
            .andExpect(jsonPath("$.hashes.sha1", equalTo(sha1sum)))
            .andExpect(jsonPath("$.size", equalTo(random.length)))
            .andExpect(jsonPath("$.providedFilename", equalTo("origFilename"))).andReturn();

    // check rest of response compared to DB
    final MgmtArtifact artResult = ResourceUtility
            .convertArtifactResponse(mvcResult.getResponse().getContentAsString());
    final Long artId = softwareModuleManagement.get(sm.getId()).get().getArtifacts().get(0).getId();
    assertThat(artResult.getArtifactId()).as("Wrong artifact id").isEqualTo(artId);
    assertThat(JsonPath.compile("$._links.self.href").read(mvcResult.getResponse().getContentAsString())
            .toString()).as("Link contains no self url").isEqualTo(
                    "http://localhost/rest/v1/softwaremodules/" + sm.getId() + "/artifacts/" + artId);
    assertThat(JsonPath.compile("$._links.download.href").read(mvcResult.getResponse().getContentAsString())
            .toString()).as("response contains no download url ")
                    .isEqualTo("http://localhost/rest/v1/softwaremodules/" + sm.getId() + "/artifacts/" + artId
                            + "/download");

    assertArtifact(sm, random);
}

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

@Test
@Description("Verfies that the system does not accept identical artifacts uploads for the same software module. Expected response: CONFLICT")
public void duplicateUploadArtifact() throws Exception {
    final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();

    final byte random[] = randomBytes(5 * 1024);
    final String md5sum = HashGeneratorUtils.generateMD5(random);
    final String sha1sum = HashGeneratorUtils.generateSHA1(random);
    final MockMultipartFile file = new MockMultipartFile("file", "orig", null, random);

    mvc.perform(fileUpload("/rest/v1/softwaremodules/{smId}/artifacts", sm.getId()).file(file)
            .accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
            .andExpect(status().isCreated())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
            .andExpect(jsonPath("$.hashes.md5", equalTo(md5sum)))
            .andExpect(jsonPath("$.hashes.sha1", equalTo(sha1sum)))
            .andExpect(jsonPath("$.providedFilename", equalTo("orig"))).andExpect(status().isCreated());

    mvc.perform(fileUpload("/rest/v1/softwaremodules/{smId}/artifacts", sm.getId()).file(file))
            .andDo(MockMvcResultPrinter.print()).andExpect(status().isConflict());
}

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

@Test
@Description("Verifies that only a limited number of artifacts can be uploaded for one software module.")
public void uploadArtifactsUntilQuotaExceeded() throws Exception {
    final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
    final long maxArtifacts = quotaManagement.getMaxArtifactsPerSoftwareModule();

    for (int i = 0; i < maxArtifacts; ++i) {
        // create test file
        final byte random[] = randomBytes(5 * 1024);
        final String md5sum = HashGeneratorUtils.generateMD5(random);
        final String sha1sum = HashGeneratorUtils.generateSHA1(random);
        final MockMultipartFile file = new MockMultipartFile("file", "origFilename" + i, null, random);

        // upload
        mvc.perform(fileUpload("/rest/v1/softwaremodules/{smId}/artifacts", sm.getId()).file(file)
                .accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
                .andExpect(status().isCreated())
                .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
                .andExpect(jsonPath("$.hashes.md5", equalTo(md5sum)))
                .andExpect(jsonPath("$.hashes.sha1", equalTo(sha1sum)))
                .andExpect(jsonPath("$.size", equalTo(random.length)))
                .andExpect(jsonPath("$.providedFilename", equalTo("origFilename" + i))).andReturn();
    }/* w w w .  ja v  a  2s  .c  om*/

    // upload one more file to cause the quota to be exceeded
    final byte random[] = randomBytes(5 * 1024);
    HashGeneratorUtils.generateMD5(random);
    HashGeneratorUtils.generateSHA1(random);
    final MockMultipartFile file = new MockMultipartFile("file", "origFilename_final", null, random);

    // upload
    mvc.perform(fileUpload("/rest/v1/softwaremodules/{smId}/artifacts", sm.getId()).file(file)
            .accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
            .andExpect(status().isForbidden())
            .andExpect(jsonPath("$.exceptionClass", equalTo(QuotaExceededException.class.getName())))
            .andExpect(jsonPath("$.errorCode", equalTo(SpServerError.SP_QUOTA_EXCEEDED.getKey())));

}

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

@Test
@Description("Verifies that artifacts can only be added as long as the artifact storage quota is not exceeded.")
public void uploadArtifactsUntilStorageQuotaExceeded() throws Exception {

    final long storageLimit = quotaManagement.getMaxArtifactStorage();

    // choose an artifact size which does not violate the max file size
    final int artifactSize = Math.toIntExact(quotaManagement.getMaxArtifactSize() / 10);
    final int numArtifacts = Math.toIntExact(storageLimit / artifactSize);

    for (int i = 0; i < numArtifacts; ++i) {
        // create test file
        final byte random[] = randomBytes(artifactSize);
        final String md5sum = HashGeneratorUtils.generateMD5(random);
        final String sha1sum = HashGeneratorUtils.generateSHA1(random);
        final MockMultipartFile file = new MockMultipartFile("file", "origFilename" + i, null, random);

        // upload
        final SoftwareModule sm = testdataFactory.createSoftwareModuleOs("sm" + i);
        mvc.perform(fileUpload("/rest/v1/softwaremodules/{smId}/artifacts", sm.getId()).file(file)
                .accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
                .andExpect(status().isCreated())
                .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
                .andExpect(jsonPath("$.hashes.md5", equalTo(md5sum)))
                .andExpect(jsonPath("$.hashes.sha1", equalTo(sha1sum)))
                .andExpect(jsonPath("$.size", equalTo(random.length)))
                .andExpect(jsonPath("$.providedFilename", equalTo("origFilename" + i))).andReturn();
    }//ww w.jav  a2 s  . c  o  m

    // upload one more file to cause the quota to be exceeded
    final byte random[] = randomBytes(artifactSize);
    HashGeneratorUtils.generateMD5(random);
    HashGeneratorUtils.generateSHA1(random);
    final MockMultipartFile file = new MockMultipartFile("file", "origFilename_final", null, random);

    // upload
    final SoftwareModule sm = testdataFactory.createSoftwareModuleOs("sm" + numArtifacts);
    mvc.perform(fileUpload("/rest/v1/softwaremodules/{smId}/artifacts", sm.getId()).file(file)
            .accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
            .andExpect(status().isForbidden())
            .andExpect(jsonPath("$.exceptionClass", equalTo(QuotaExceededException.class.getName())))
            .andExpect(jsonPath("$.errorCode", equalTo(SpServerError.SP_QUOTA_EXCEEDED.getKey())));

}

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

@Test
@Description("Verifies the listing of one defined artifact assigned to a given software module. That includes the artifact metadata and download links.")
public void getArtifact() throws Exception {
    // prepare data for test
    final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();

    final int artifactSize = 5 * 1024;
    final byte random[] = randomBytes(artifactSize);

    final Artifact artifact = artifactManagement.create(
            new ArtifactUpload(new ByteArrayInputStream(random), sm.getId(), "file1", false, artifactSize));

    // perform test
    mvc.perform(get("/rest/v1/softwaremodules/{smId}/artifacts/{artId}", sm.getId(), artifact.getId())
            .accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
            .andExpect(jsonPath("$.id", equalTo(artifact.getId().intValue())))
            .andExpect(jsonPath("$.size", equalTo(random.length)))
            .andExpect(jsonPath("$.hashes.md5", equalTo(artifact.getMd5Hash())))
            .andExpect(jsonPath("$.hashes.sha1", equalTo(artifact.getSha1Hash())))
            .andExpect(jsonPath("$.providedFilename", equalTo("file1")))
            .andExpect(jsonPath("$._links.download.href",
                    equalTo("http://localhost/rest/v1/softwaremodules/" + sm.getId() + "/artifacts/"
                            + artifact.getId() + "/download")))
            .andExpect(jsonPath("$._links.self.href", equalTo("http://localhost/rest/v1/softwaremodules/"
                    + sm.getId() + "/artifacts/" + artifact.getId())));
}

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

@Test
@Description("Verifies the listing of all artifacts assigned to a software module. That includes the artifact metadata and download links.")
public void getArtifacts() throws Exception {
    final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();

    final int artifactSize = 5 * 1024;
    final byte random[] = randomBytes(artifactSize);

    final Artifact artifact = artifactManagement.create(
            new ArtifactUpload(new ByteArrayInputStream(random), sm.getId(), "file1", false, artifactSize));
    final Artifact artifact2 = artifactManagement.create(
            new ArtifactUpload(new ByteArrayInputStream(random), sm.getId(), "file2", false, artifactSize));

    mvc.perform(get("/rest/v1/softwaremodules/{smId}/artifacts", sm.getId()).accept(MediaType.APPLICATION_JSON))
            .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
            .andExpect(jsonPath("$.[0].id", equalTo(artifact.getId().intValue())))
            .andExpect(jsonPath("$.[0].size", equalTo(random.length)))
            .andExpect(jsonPath("$.[0].hashes.md5", equalTo(artifact.getMd5Hash())))
            .andExpect(jsonPath("$.[0].hashes.sha1", equalTo(artifact.getSha1Hash())))
            .andExpect(jsonPath("$.[0].providedFilename", equalTo("file1")))
            .andExpect(jsonPath("$.[0]._links.self.href",
                    equalTo("http://localhost/rest/v1/softwaremodules/" + sm.getId() + "/artifacts/"
                            + artifact.getId())))
            .andExpect(jsonPath("$.[1].id", equalTo(artifact2.getId().intValue())))
            .andExpect(jsonPath("$.[1].hashes.md5", equalTo(artifact2.getMd5Hash())))
            .andExpect(jsonPath("$.[1].hashes.sha1", equalTo(artifact2.getSha1Hash())))
            .andExpect(jsonPath("$.[1].providedFilename", equalTo("file2")))
            .andExpect(jsonPath("$.[1]._links.self.href", equalTo("http://localhost/rest/v1/softwaremodules/"
                    + sm.getId() + "/artifacts/" + artifact2.getId())));
}

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

@Test
@WithUser(principal = "uploadTester", allSpPermissions = true)
@Description("Test retrieval of all software modules the user has access to.")
public void getSoftwareModules() throws Exception {
    final SoftwareModule os = testdataFactory.createSoftwareModuleOs();
    final SoftwareModule app = testdataFactory.createSoftwareModuleApp();

    mvc.perform(get("/rest/v1/softwaremodules").accept(MediaType.APPLICATION_JSON))
            .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
            .andExpect(jsonPath("$.content.[?(@.id==" + os.getId() + ")].name", contains(os.getName())))
            .andExpect(jsonPath("$.content.[?(@.id==" + os.getId() + ")].version", contains(os.getVersion())))
            .andExpect(jsonPath("$.content.[?(@.id==" + os.getId() + ")].description",
                    contains(os.getDescription())))
            .andExpect(jsonPath("$.content.[?(@.id==" + os.getId() + ")].vendor", contains(os.getVendor())))
            .andExpect(jsonPath("$.content.[?(@.id==" + os.getId() + ")].type", contains("os")))
            .andExpect(jsonPath("$.content.[?(@.id==" + os.getId() + ")].createdBy", contains("uploadTester")))
            .andExpect(//from ww  w  .j av  a 2  s .c o  m
                    jsonPath("$.content.[?(@.id==" + os.getId() + ")].createdAt", contains(os.getCreatedAt())))
            .andExpect(jsonPath("$.content.[?(@.id==" + os.getId() + ")]._links.self.href",
                    contains("http://localhost/rest/v1/softwaremodules/" + os.getId())))
            .andExpect(jsonPath("$.content.[?(@.id==" + app.getId() + ")].name", contains(app.getName())))
            .andExpect(jsonPath("$.content.[?(@.id==" + app.getId() + ")].version", contains(app.getVersion())))
            .andExpect(jsonPath("$.content.[?(@.id==" + app.getId() + ")].description",
                    contains(app.getDescription())))
            .andExpect(jsonPath("$.content.[?(@.id==" + app.getId() + ")].vendor", contains(app.getVendor())))
            .andExpect(jsonPath("$.content.[?(@.id==" + app.getId() + ")].type", contains("application")))
            .andExpect(jsonPath("$.content.[?(@.id==" + app.getId() + ")].createdBy", contains("uploadTester")))
            .andExpect(jsonPath("$.content.[?(@.id==" + app.getId() + ")].createdAt",
                    contains(app.getCreatedAt())))
            .andExpect(jsonPath("$.content.[?(@.id==" + app.getId() + ")]._links.self.href",
                    contains("http://localhost/rest/v1/softwaremodules/" + app.getId())));

    assertThat(softwareModuleManagement.findAll(PAGE)).as("Softwaremodule size is wrong").hasSize(2);
}

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

@Test
@Description("Test the various filter parameters, e.g. filter by name or type of the module.")
public void getSoftwareModulesWithFilterParameters() throws Exception {
    final SoftwareModule os1 = testdataFactory.createSoftwareModuleOs("1");
    final SoftwareModule app1 = testdataFactory.createSoftwareModuleApp("1");
    testdataFactory.createSoftwareModuleOs("2");
    final SoftwareModule app2 = testdataFactory.createSoftwareModuleApp("2");

    assertThat(softwareModuleManagement.findAll(PAGE)).hasSize(4);

    // only by name, only one exists per name
    mvc.perform(get("/rest/v1/softwaremodules?q=name==" + os1.getName()).accept(MediaType.APPLICATION_JSON))
            .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
            .andExpect(jsonPath("$.content.[?(@.id==" + os1.getId() + ")].name", contains(os1.getName())))
            .andExpect(jsonPath("$.content.[?(@.id==" + os1.getId() + ")].version", contains(os1.getVersion())))
            .andExpect(jsonPath("$.content.[?(@.id==" + os1.getId() + ")].description",
                    contains(os1.getDescription())))
            .andExpect(jsonPath("$.content.[?(@.id==" + os1.getId() + ")].vendor", contains(os1.getVendor())))
            .andExpect(jsonPath("$.content.[?(@.id==" + os1.getId() + ")].type", contains("os")))
            .andExpect(jsonPath("$.content", hasSize(1))).andExpect(jsonPath("$.total", equalTo(1)));

    // by type, 2 software modules per type exists
    mvc.perform(get("/rest/v1/softwaremodules?q=type==" + Constants.SMT_DEFAULT_APP_KEY)
            .accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
            .andExpect(jsonPath("$.content.[?(@.id==" + app1.getId() + ")].name", contains(app1.getName())))
            .andExpect(//  w  w  w. j  a va2s .c  o  m
                    jsonPath("$.content.[?(@.id==" + app1.getId() + ")].version", contains(app1.getVersion())))
            .andExpect(jsonPath("$.content.[?(@.id==" + app1.getId() + ")].description",
                    contains(app1.getDescription())))
            .andExpect(jsonPath("$.content.[?(@.id==" + app1.getId() + ")].vendor", contains(app1.getVendor())))
            .andExpect(jsonPath("$.content.[?(@.id==" + app1.getId() + ")].type",
                    contains(Constants.SMT_DEFAULT_APP_KEY)))
            .andExpect(jsonPath("$.content.[?(@.id==" + app2.getId() + ")].name", contains(app2.getName())))
            .andExpect(
                    jsonPath("$.content.[?(@.id==" + app2.getId() + ")].version", contains(app2.getVersion())))
            .andExpect(jsonPath("$.content.[?(@.id==" + app2.getId() + ")].description",
                    contains(app2.getDescription())))
            .andExpect(jsonPath("$.content.[?(@.id==" + app2.getId() + ")].vendor", contains(app2.getVendor())))
            .andExpect(jsonPath("$.content.[?(@.id==" + app2.getId() + ")].type",
                    contains(Constants.SMT_DEFAULT_APP_KEY)))
            .andExpect(jsonPath("$.content", hasSize(2))).andExpect(jsonPath("$.total", equalTo(2)));

    // by type and version=2.0.0 -> only one result
    mvc.perform(get("/rest/v1/softwaremodules?q=type==" + Constants.SMT_DEFAULT_APP_KEY + ";version=="
            + app1.getVersion()).accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
            .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
            .andExpect(jsonPath("$.content.[?(@.id==" + app1.getId() + ")].name", contains(app1.getName())))
            .andExpect(
                    jsonPath("$.content.[?(@.id==" + app1.getId() + ")].version", contains(app1.getVersion())))
            .andExpect(jsonPath("$.content.[?(@.id==" + app1.getId() + ")].description",
                    contains(app1.getDescription())))
            .andExpect(jsonPath("$.content.[?(@.id==" + app1.getId() + ")].vendor", contains(app1.getVendor())))
            .andExpect(jsonPath("$.content.[?(@.id==" + app1.getId() + ")].type",
                    contains(Constants.SMT_DEFAULT_APP_KEY)))
            .andExpect(jsonPath("$.content", hasSize(1))).andExpect(jsonPath("$.total", equalTo(1)));
}