Example usage for org.springframework.hateoas MediaTypes HAL_JSON_VALUE

List of usage examples for org.springframework.hateoas MediaTypes HAL_JSON_VALUE

Introduction

In this page you can find the example usage for org.springframework.hateoas MediaTypes HAL_JSON_VALUE.

Prototype

String HAL_JSON_VALUE

To view the source code for org.springframework.hateoas MediaTypes HAL_JSON_VALUE.

Click Source Link

Document

A String equivalent of MediaTypes#HAL_JSON .

Usage

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

@Test
@Description("Assigns distribution set to target with only maintenance window duration.")
public void assignDistributionSetToTargetWithMaintenanceWindowEndTimeOnly() throws Exception {

    final Target target = testdataFactory.createTarget("fsdfsd");
    final DistributionSet set = testdataFactory.createDistributionSet("one");

    final String body = new JSONObject().put("id", set.getId()).put("type", "forced")
            .put("maintenanceWindow", new JSONObject().put("duration", getTestDuration(10))).toString();

    mvc.perform(//from ww  w  .  j ava  2s.  c o m
            post(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + target.getControllerId() + "/assignedDS")
                    .content(body).contentType(MediaTypes.HAL_JSON_VALUE))
            .andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest());
}

From source file:org.eclipse.hawkbit.rest.ddi.documentation.RootControllerDocumentationTest.java

@Test
@Description("This base resource can be regularly polled by the controller on the provisiong target or device "
        + "in order to retrieve actions that need to be executed. In this case including a config pull request and a deployment. The resource supports Etag based modification "
        + "checks in order to save traffic.")
@WithUser(tenantId = "TENANT_ID", authorities = "ROLE_CONTROLLER", allSpPermissions = true)
public void getControllerBaseWithOpenDeplyoment() throws Exception {
    final DistributionSet set = testdataFactory.createDistributionSet("one");

    final Target target = targetManagement.create(entityFactory.target().create().controllerId(CONTROLLER_ID));
    deploymentManagement.assignDistributionSet(set.getId(), Arrays.asList(target.getTargetWithActionType()));

    mockMvc.perform(get(DdiRestConstants.BASE_V1_REQUEST_MAPPING + "/{controllerId}",
            tenantAware.getCurrentTenant(), target.getControllerId()).accept(MediaTypes.HAL_JSON_VALUE))
            .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
            .andExpect(content().contentType(MediaTypes.HAL_JSON_UTF8))
            .andDo(this.document.document(
                    pathParameters(parameterWithName("tenant").description(ApiModelPropertiesGeneric.TENANT),
                            parameterWithName("controllerId").description(DdiApiModelProperties.CONTROLLER_ID)),
                    responseFields(/*  ww w  .  ja v  a2 s.  co  m*/
                            fieldWithPath("config.polling").description(DdiApiModelProperties.TARGET_POLL_TIME),
                            fieldWithPath("config.polling.sleep")
                                    .description(DdiApiModelProperties.TARGET_SLEEP),
                            fieldWithPath("_links").description(DdiApiModelProperties.TARGET_OPEN_ACTIONS),
                            fieldWithPath("_links.deploymentBase")
                                    .description(DdiApiModelProperties.DEPLOYMENT),
                            fieldWithPath("_links.configData")
                                    .description(DdiApiModelProperties.TARGET_CONFIG_DATA))));
}

From source file:org.eclipse.hawkbit.rest.ddi.documentation.RootControllerDocumentationTest.java

@Test
@Description("This base resource can be regularly polled by the controller on the provisiong target or device "
        + "in order to retrieve actions that need to be executed. In this case including a config pull request and a cancellation. "
        + "Note: as with deployments the cancel action has to be confirmed or rejected in order to move on to the next action.")
@WithUser(tenantId = "TENANT_ID", authorities = "ROLE_CONTROLLER", allSpPermissions = true)
public void getControllerBaseWithOpenDeploymentCancellation() throws Exception {
    final DistributionSet set = testdataFactory.createDistributionSet("one");
    final DistributionSet setTwo = testdataFactory.createDistributionSet("two");

    final Target target = targetManagement.create(entityFactory.target().create().controllerId(CONTROLLER_ID));
    deploymentManagement.assignDistributionSet(set.getId(), Arrays.asList(target.getTargetWithActionType()));
    deploymentManagement.assignDistributionSet(setTwo.getId(), Arrays.asList(target.getTargetWithActionType()));

    mockMvc.perform(get(DdiRestConstants.BASE_V1_REQUEST_MAPPING + "/{controllerId}",
            tenantAware.getCurrentTenant(), target.getControllerId()).accept(MediaTypes.HAL_JSON_VALUE))
            .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
            .andExpect(content().contentType(MediaTypes.HAL_JSON_UTF8))
            .andDo(this.document.document(
                    pathParameters(parameterWithName("tenant").description(ApiModelPropertiesGeneric.TENANT),
                            parameterWithName("controllerId").description(DdiApiModelProperties.CONTROLLER_ID)),
                    responseFields(//from   w  ww  . jav a2 s. c o m
                            fieldWithPath("config.polling").description(DdiApiModelProperties.TARGET_POLL_TIME),
                            fieldWithPath("config.polling.sleep")
                                    .description(DdiApiModelProperties.TARGET_SLEEP),
                            fieldWithPath("_links").description(DdiApiModelProperties.TARGET_OPEN_ACTIONS),
                            fieldWithPath("_links.cancelAction").description(DdiApiModelProperties.DEPLOYMENT),
                            fieldWithPath("_links.configData")
                                    .description(DdiApiModelProperties.TARGET_CONFIG_DATA))));
}

From source file:org.eclipse.hawkbit.rest.ddi.documentation.RootControllerDocumentationTest.java

@Test
@Description("The SP server might cancel an operation, e.g. an unfinished update has a sucessor. "
        + "It is up to the provisiong target to decide either to accept the cancelation or reject it.")
@WithUser(tenantId = "TENANT_ID", authorities = "ROLE_CONTROLLER", allSpPermissions = true)
public void getControllerCancelAction() throws Exception {
    final DistributionSet set = testdataFactory.createDistributionSet("one");

    set.getModules().forEach(module -> {
        final byte random[] = RandomStringUtils.random(5).getBytes();

        artifactManagement.create(/* w ww. j  a v a  2  s  . com*/
                new ArtifactUpload(new ByteArrayInputStream(random), module.getId(), "binary.tgz", false, 0));
        artifactManagement.create(new ArtifactUpload(new ByteArrayInputStream(random), module.getId(),
                "file.signature", false, 0));
    });

    final Target target = targetManagement.create(entityFactory.target().create().controllerId(CONTROLLER_ID));
    final Long actionId = deploymentManagement
            .assignDistributionSet(set.getId(), Arrays.asList(target.getTargetWithActionType())).getActions()
            .get(0);
    final Action cancelAction = deploymentManagement.cancelAction(actionId);

    mockMvc.perform(get(
            DdiRestConstants.BASE_V1_REQUEST_MAPPING + "/{controllerId}/" + DdiRestConstants.CANCEL_ACTION
                    + "/{actionId}",
            tenantAware.getCurrentTenant(), target.getControllerId(), cancelAction.getId())
                    .accept(MediaTypes.HAL_JSON_VALUE))
            .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
            .andExpect(content().contentType(MediaTypes.HAL_JSON_UTF8))
            .andDo(this.document.document(
                    pathParameters(parameterWithName("tenant").description(ApiModelPropertiesGeneric.TENANT),
                            parameterWithName("controllerId").description(DdiApiModelProperties.CONTROLLER_ID),
                            parameterWithName("actionId")
                                    .description(DdiApiModelProperties.ACTION_ID_CANCELED)),

                    responseFields(fieldWithPath("id").description(DdiApiModelProperties.ACTION_ID),
                            fieldWithPath("cancelAction").description(DdiApiModelProperties.CANCEL_ACTION),
                            fieldWithPath("cancelAction.stopId")
                                    .description(DdiApiModelProperties.ACTION_ID_CANCELED)

                    )));
}

From source file:org.eclipse.hawkbit.rest.ddi.documentation.RootControllerDocumentationTest.java

@Test
@Description("Core resource for deployment operations. Contains all information necessary in order to execute the operation.")
@WithUser(tenantId = "TENANT_ID", authorities = "ROLE_CONTROLLER", allSpPermissions = true)
public void getControllerBasedeploymentAction() throws Exception {
    final DistributionSet set = testdataFactory.createDistributionSet("one");

    set.getModules().forEach(module -> {
        final byte random[] = RandomStringUtils.random(5).getBytes();

        artifactManagement.create(/*from  www .  j ava2 s.  c o  m*/
                new ArtifactUpload(new ByteArrayInputStream(random), module.getId(), "binary.tgz", false, 0));
        artifactManagement.create(new ArtifactUpload(new ByteArrayInputStream(random), module.getId(),
                "file.signature", false, 0));
    });

    softwareModuleManagement.createMetaData(entityFactory.softwareModuleMetadata()
            .create(set.getModules().iterator().next().getId()).key("aMetadataKey")
            .value("Metadata value as defined in software module").targetVisible(true));

    final Target target = targetManagement.create(entityFactory.target().create().controllerId(CONTROLLER_ID));
    final Long actionId = assignDistributionSetWithMaintenanceWindow(set.getId(), target.getControllerId(),
            getTestSchedule(-5), getTestDuration(10), getTestTimeZone()).getActions().get(0);

    controllerManagement.addInformationalActionStatus(
            entityFactory.actionStatus().create(actionId).message("Started download").status(Status.DOWNLOAD));
    controllerManagement.addInformationalActionStatus(entityFactory.actionStatus().create(actionId)
            .message("Download failed. ErrorCode #5876745. Retry").status(Status.WARNING));
    controllerManagement.addInformationalActionStatus(
            entityFactory.actionStatus().create(actionId).message("Download done").status(Status.DOWNLOADED));
    controllerManagement.addInformationalActionStatus(
            entityFactory.actionStatus().create(actionId).message("Write firmware").status(Status.RUNNING));
    controllerManagement.addInformationalActionStatus(
            entityFactory.actionStatus().create(actionId).message("Reboot").status(Status.RUNNING));

    mockMvc.perform(get(
            DdiRestConstants.BASE_V1_REQUEST_MAPPING + "/{controllerId}/"
                    + DdiRestConstants.DEPLOYMENT_BASE_ACTION + "/{actionId}?actionHistory=10",
            tenantAware.getCurrentTenant(), target.getControllerId(), actionId)
                    .accept(MediaTypes.HAL_JSON_VALUE))
            .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
            .andExpect(content().contentType(MediaTypes.HAL_JSON_UTF8))
            .andDo(this.document.document(
                    pathParameters(parameterWithName("tenant").description(ApiModelPropertiesGeneric.TENANT),
                            parameterWithName("controllerId").description(DdiApiModelProperties.CONTROLLER_ID),
                            parameterWithName("actionId").description(DdiApiModelProperties.ACTION_ID)),
                    requestParameters(parameterWithName("actionHistory")
                            .description(DdiApiModelProperties.ACTION_HISTORY)),
                    responseFields(fieldWithPath("id").description(DdiApiModelProperties.ACTION_ID),
                            fieldWithPath("deployment").description(DdiApiModelProperties.DEPLOYMENT),
                            fieldWithPath("deployment.download")
                                    .description(DdiApiModelProperties.HANDLING_DOWNLOAD).type("enum")
                                    .attributes(key("value").value("['skip', 'attempt', 'forced']")),
                            fieldWithPath("deployment.update")
                                    .description(DdiApiModelProperties.HANDLING_UPDATE).type("enum")
                                    .attributes(key("value").value("['skip', 'attempt', 'forced']")),
                            fieldWithPath("deployment.maintenanceWindow")
                                    .description(DdiApiModelProperties.MAINTENANCE_WINDOW).type("enum")
                                    .attributes(key("value").value("['available', 'unavailable']")),
                            fieldWithPath("deployment.chunks").description(DdiApiModelProperties.CHUNK),
                            fieldWithPath("deployment.chunks[].metadata")
                                    .description(DdiApiModelProperties.CHUNK_META_DATA).optional(),
                            fieldWithPath("deployment.chunks[].metadata[].key")
                                    .description(DdiApiModelProperties.CHUNK_META_DATA_KEY).optional(),
                            fieldWithPath("deployment.chunks[].metadata[].value")
                                    .description(DdiApiModelProperties.CHUNK_META_DATA_VALUE).optional(),
                            fieldWithPath("deployment.chunks[].part")
                                    .description(DdiApiModelProperties.CHUNK_TYPE),
                            fieldWithPath("deployment.chunks[].name")
                                    .description(DdiApiModelProperties.CHUNK_NAME),
                            fieldWithPath("deployment.chunks[].version")
                                    .description(DdiApiModelProperties.CHUNK_VERSION),
                            fieldWithPath("deployment.chunks[].artifacts")
                                    .description(DdiApiModelProperties.ARTIFACTS),
                            fieldWithPath("deployment.chunks[].artifacts[].filename")
                                    .description(DdiApiModelProperties.ARTIFACTS),
                            fieldWithPath("deployment.chunks[].artifacts[].hashes")
                                    .description(DdiApiModelProperties.ARTIFACTS),
                            fieldWithPath("deployment.chunks[].artifacts[].hashes.sha1")
                                    .description(DdiApiModelProperties.ARTIFACT_HASHES_SHA1),
                            fieldWithPath("deployment.chunks[].artifacts[].hashes.md5")
                                    .description(DdiApiModelProperties.ARTIFACT_HASHES_MD5),
                            fieldWithPath("deployment.chunks[].artifacts[].size")
                                    .description(DdiApiModelProperties.ARTIFACT_SIZE),
                            fieldWithPath("deployment.chunks[].artifacts[]._links.download").description(
                                    DdiApiModelProperties.ARTIFACT_HTTPS_DOWNLOAD_LINK_BY_CONTROLLER),
                            fieldWithPath("deployment.chunks[].artifacts[]._links.md5sum")
                                    .description(DdiApiModelProperties.ARTIFACT_HTTPS_HASHES_MD5SUM_LINK),
                            fieldWithPath("deployment.chunks[].artifacts[]._links.download-http").description(
                                    DdiApiModelProperties.ARTIFACT_HTTP_DOWNLOAD_LINK_BY_CONTROLLER),
                            fieldWithPath("deployment.chunks[].artifacts[]._links.md5sum-http")
                                    .description(DdiApiModelProperties.ARTIFACT_HTTP_HASHES_MD5SUM_LINK),
                            fieldWithPath("actionHistory")
                                    .description(DdiApiModelProperties.ACTION_HISTORY_RESP),
                            fieldWithPath("actionHistory.status")
                                    .description(DdiApiModelProperties.ACTION_HISTORY_RESP_STATUS),
                            fieldWithPath("actionHistory.messages")
                                    .description(DdiApiModelProperties.ACTION_HISTORY_RESP_MESSAGES))));

}

From source file:org.eclipse.hawkbit.rest.ddi.documentation.RootControllerDocumentationTest.java

@Test
@Description("Core resource for deployment operations. Contains all information necessary in order to execute the operation. Example with maintenance window where the device is requested to download only as it is not in the maintenance window yet.")
@WithUser(tenantId = "TENANT_ID", authorities = "ROLE_CONTROLLER", allSpPermissions = true)
public void getControllerBasedeploymentActionWithMaintenanceWindow() throws Exception {
    final DistributionSet set = testdataFactory.createDistributionSet("one");

    final Target target = targetManagement.create(entityFactory.target().create().controllerId(CONTROLLER_ID));
    final Long actionId = assignDistributionSetWithMaintenanceWindow(set.getId(), target.getControllerId(),
            getTestSchedule(2), getTestDuration(1), getTestTimeZone()).getActions().get(0);

    mockMvc.perform(get(//from   w w w.  j  a v a2s. c o m
            DdiRestConstants.BASE_V1_REQUEST_MAPPING + "/{controllerId}/"
                    + DdiRestConstants.DEPLOYMENT_BASE_ACTION + "/{actionId}?actionHistory=10",
            tenantAware.getCurrentTenant(), target.getControllerId(), actionId)
                    .accept(MediaTypes.HAL_JSON_VALUE))
            .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
            .andExpect(content().contentType(MediaTypes.HAL_JSON_UTF8))
            .andDo(this.document.document(
                    pathParameters(parameterWithName("tenant").description(ApiModelPropertiesGeneric.TENANT),
                            parameterWithName("controllerId").description(DdiApiModelProperties.CONTROLLER_ID),
                            parameterWithName("actionId").description(DdiApiModelProperties.ACTION_ID)),
                    requestParameters(parameterWithName("actionHistory")
                            .description(DdiApiModelProperties.ACTION_HISTORY)),
                    responseFields(fieldWithPath("id").description(DdiApiModelProperties.ACTION_ID),
                            fieldWithPath("deployment").description(DdiApiModelProperties.DEPLOYMENT),
                            fieldWithPath("deployment.download")
                                    .description(DdiApiModelProperties.HANDLING_DOWNLOAD),
                            fieldWithPath("deployment.update")
                                    .description(DdiApiModelProperties.HANDLING_UPDATE).type("enum")
                                    .attributes(key("value").value("['attempt', 'forced']")),
                            fieldWithPath("deployment.maintenanceWindow")
                                    .description(DdiApiModelProperties.MAINTENANCE_WINDOW).type("enum")
                                    .attributes(key("value").value("['available', 'unavailable']")),
                            fieldWithPath("deployment.chunks").description(DdiApiModelProperties.CHUNK),
                            fieldWithPath("deployment.chunks[].part")
                                    .description(DdiApiModelProperties.CHUNK_TYPE),
                            fieldWithPath("deployment.chunks[].name")
                                    .description(DdiApiModelProperties.CHUNK_NAME),
                            fieldWithPath("deployment.chunks[].version")
                                    .description(DdiApiModelProperties.CHUNK_VERSION))));

}

From source file:org.eclipse.hawkbit.rest.ddi.documentation.RootControllerDocumentationTest.java

@Test
@Description("Feedback channel. It is up to the device to decided how much intermediate feedback is "
        + "provided. However, the action will be kept open until the controller on the device reports a "
        + "finished (either successfull or error).")
@WithUser(tenantId = "TENANT_ID", authorities = "ROLE_CONTROLLER", allSpPermissions = true)
public void postBasedeploymentActionFeedback() throws Exception {
    final DistributionSet set = testdataFactory.createDistributionSet("one");

    final Target target = targetManagement.create(entityFactory.target().create().controllerId(CONTROLLER_ID));
    final Long actionId = deploymentManagement
            .assignDistributionSet(set.getId(), Arrays.asList(target.getTargetWithActionType())).getActions()
            .get(0);/*  w ww.j  a  v a  2  s . co  m*/

    mockMvc.perform(post(
            DdiRestConstants.BASE_V1_REQUEST_MAPPING + "/{controllerId}/"
                    + DdiRestConstants.DEPLOYMENT_BASE_ACTION + "/{actionId}/feedback",
            tenantAware.getCurrentTenant(), target.getControllerId(), actionId).content(
                    JsonBuilder.deploymentActionFeedback(actionId.toString(), "closed", "Feddback message"))
                    .contentType(MediaType.APPLICATION_JSON_UTF8).accept(MediaTypes.HAL_JSON_VALUE))
            .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
            .andDo(this.document.document(
                    pathParameters(parameterWithName("tenant").description(ApiModelPropertiesGeneric.TENANT),
                            parameterWithName("controllerId").description(DdiApiModelProperties.CONTROLLER_ID),
                            parameterWithName("actionId").description(DdiApiModelProperties.ACTION_ID)),

                    requestFields(
                            optionalRequestFieldWithPath("id").description(DdiApiModelProperties.ACTION_ID),
                            optionalRequestFieldWithPath("time").description(DdiApiModelProperties.TARGET_TIME),
                            requestFieldWithPath("status").description(DdiApiModelProperties.TARGET_STATUS),
                            requestFieldWithPath("status.execution")
                                    .description(DdiApiModelProperties.TARGET_EXEC_STATUS).type("enum")
                                    .attributes(key("value").value(
                                            "['closed', 'proceeding', 'canceled','scheduled', 'rejected', 'resumed']")),
                            requestFieldWithPath("status.result")
                                    .description(DdiApiModelProperties.TARGET_RESULT_VALUE),
                            requestFieldWithPath("status.result.finished")
                                    .description(DdiApiModelProperties.TARGET_RESULT_FINISHED).type("enum")
                                    .attributes(key("value").value("['success', 'failure', 'none']")),
                            optionalRequestFieldWithPath("status.result.progress")
                                    .description(DdiApiModelProperties.TARGET_RESULT_PROGRESS),
                            optionalRequestFieldWithPath("status.details")
                                    .description(DdiApiModelProperties.TARGET_RESULT_DETAILS))));
}

From source file:org.eclipse.hawkbit.rest.ddi.documentation.RootControllerDocumentationTest.java

@Test
@Description("Returns all artifacts whichs is assigned to the software module."
        + "Can be usesfull for the target to double check that its current state matches with the targeted state.")
@WithUser(tenantId = "TENANT_ID", authorities = "ROLE_CONTROLLER", allSpPermissions = true)
public void getSoftwareModulesArtifacts() throws Exception {
    final DistributionSet set = testdataFactory.createDistributionSet("");

    final SoftwareModule module = (SoftwareModule) set.getModules().toArray()[0];

    final byte random[] = RandomStringUtils.random(5).getBytes();
    artifactManagement.create(/*from  w w  w  .  j ava2  s .  c o m*/
            new ArtifactUpload(new ByteArrayInputStream(random), module.getId(), "binaryFile", false, 0));

    final Target target = targetManagement.create(entityFactory.target().create().controllerId(CONTROLLER_ID));
    deploymentManagement.assignDistributionSet(set.getId(), Arrays.asList(target.getTargetWithActionType()));

    mockMvc.perform(get(
            DdiRestConstants.BASE_V1_REQUEST_MAPPING + "/{controllerId}/softwaremodules/{moduleId}/artifacts",
            tenantAware.getCurrentTenant(), target.getControllerId(), module.getId())
                    .accept(MediaTypes.HAL_JSON_VALUE))
            .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
            .andExpect(content().contentType(MediaTypes.HAL_JSON_UTF8))
            .andDo(this.document.document(
                    pathParameters(parameterWithName("tenant").description(ApiModelPropertiesGeneric.TENANT),
                            parameterWithName("controllerId").description(DdiApiModelProperties.CONTROLLER_ID),
                            parameterWithName("moduleId").description(DdiApiModelProperties.SOFTWARE_MODUL_ID)),
                    responseFields(fieldWithPath("[]filename").description(DdiApiModelProperties.ARTIFACTS),
                            fieldWithPath("[]hashes").description(DdiApiModelProperties.ARTIFACTS),
                            fieldWithPath("[]hashes.sha1")
                                    .description(DdiApiModelProperties.ARTIFACT_HASHES_SHA1),
                            fieldWithPath("[]hashes.md5")
                                    .description(DdiApiModelProperties.ARTIFACT_HASHES_MD5),
                            fieldWithPath("[]size").description(DdiApiModelProperties.ARTIFACT_SIZE),
                            fieldWithPath("[]_links.download").description(
                                    DdiApiModelProperties.ARTIFACT_HTTPS_DOWNLOAD_LINK_BY_CONTROLLER),
                            fieldWithPath("[]_links.md5sum")
                                    .description(DdiApiModelProperties.ARTIFACT_HTTPS_HASHES_MD5SUM_LINK),
                            fieldWithPath("[]_links.download-http").description(
                                    DdiApiModelProperties.ARTIFACT_HTTP_DOWNLOAD_LINK_BY_CONTROLLER),
                            fieldWithPath("[]_links.md5sum-http")
                                    .description(DdiApiModelProperties.ARTIFACT_HTTP_HASHES_MD5SUM_LINK))));
}