Spring Boot 2.0 (#721)

* Migration to Boot 2.0.

Signed-off-by: Kai Zimmermann <kai.zimmermann@microsoft.com>
This commit is contained in:
Kai Zimmermann
2019-01-31 07:29:27 +01:00
committed by GitHub
parent b42b009f9e
commit d52a720480
263 changed files with 2874 additions and 2692 deletions

View File

@@ -78,7 +78,7 @@ public class RootControllerDocumentationTest extends AbstractApiRestDocumentatio
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(APPLICATION_JSON_HAL_UTF))
.andExpect(content().contentType(MediaTypes.HAL_JSON_UTF8))
.andDo(this.document.document(
pathParameters(parameterWithName("tenant").description(ApiModelPropertiesGeneric.TENANT),
parameterWithName("controllerId").description(DdiApiModelProperties.CONTROLLER_ID)),
@@ -107,7 +107,7 @@ public class RootControllerDocumentationTest extends AbstractApiRestDocumentatio
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(APPLICATION_JSON_HAL_UTF))
.andExpect(content().contentType(MediaTypes.HAL_JSON_UTF8))
.andDo(this.document.document(
pathParameters(parameterWithName("tenant").description(ApiModelPropertiesGeneric.TENANT),
parameterWithName("controllerId").description(DdiApiModelProperties.CONTROLLER_ID)),
@@ -147,7 +147,7 @@ public class RootControllerDocumentationTest extends AbstractApiRestDocumentatio
+ "/{actionId}", tenantAware.getCurrentTenant(), target.getControllerId(), cancelAction.getId())
.accept(MediaTypes.HAL_JSON_VALUE))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(content().contentType(APPLICATION_JSON_HAL_UTF))
.andExpect(content().contentType(MediaTypes.HAL_JSON_UTF8))
.andDo(this.document.document(
pathParameters(parameterWithName("tenant").description(ApiModelPropertiesGeneric.TENANT),
parameterWithName("controllerId").description(DdiApiModelProperties.CONTROLLER_ID),
@@ -217,7 +217,7 @@ public class RootControllerDocumentationTest extends AbstractApiRestDocumentatio
mockMvc.perform(
put(DdiRestConstants.BASE_V1_REQUEST_MAPPING + "/{controllerId}/" + DdiRestConstants.CONFIG_DATA_ACTION,
tenantAware.getCurrentTenant(), target.getControllerId())
.content(JsonBuilder.configData("", attributes, "closed", "merge"))
.content(JsonBuilder.configData("", attributes, "closed", "merge").toString())
.contentType(MediaType.APPLICATION_JSON_UTF8))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(this.document.document(
@@ -283,7 +283,7 @@ public class RootControllerDocumentationTest extends AbstractApiRestDocumentatio
+ "/{actionId}?actionHistory=10",
tenantAware.getCurrentTenant(), target.getControllerId(), actionId).accept(MediaTypes.HAL_JSON_VALUE))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(content().contentType(APPLICATION_JSON_HAL_UTF))
.andExpect(content().contentType(MediaTypes.HAL_JSON_UTF8))
.andDo(this.document.document(
pathParameters(parameterWithName("tenant").description(ApiModelPropertiesGeneric.TENANT),
parameterWithName("controllerId").description(DdiApiModelProperties.CONTROLLER_ID),
@@ -302,11 +302,11 @@ public class RootControllerDocumentationTest extends AbstractApiRestDocumentatio
.attributes(key("value").value("['available', 'unavailable']")),
fieldWithPath("deployment.chunks").description(DdiApiModelProperties.CHUNK),
fieldWithPath("deployment.chunks[].metadata")
.description(DdiApiModelProperties.CHUNK_META_DATA),
.description(DdiApiModelProperties.CHUNK_META_DATA).optional(),
fieldWithPath("deployment.chunks[].metadata[].key")
.description(DdiApiModelProperties.CHUNK_META_DATA_KEY),
.description(DdiApiModelProperties.CHUNK_META_DATA_KEY).optional(),
fieldWithPath("deployment.chunks[].metadata[].value")
.description(DdiApiModelProperties.CHUNK_META_DATA_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")
@@ -354,7 +354,7 @@ public class RootControllerDocumentationTest extends AbstractApiRestDocumentatio
+ "/{actionId}?actionHistory=10",
tenantAware.getCurrentTenant(), target.getControllerId(), actionId).accept(MediaTypes.HAL_JSON_VALUE))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(content().contentType(APPLICATION_JSON_HAL_UTF))
.andExpect(content().contentType(MediaTypes.HAL_JSON_UTF8))
.andDo(this.document.document(
pathParameters(parameterWithName("tenant").description(ApiModelPropertiesGeneric.TENANT),
parameterWithName("controllerId").description(DdiApiModelProperties.CONTROLLER_ID),
@@ -442,7 +442,7 @@ public class RootControllerDocumentationTest extends AbstractApiRestDocumentatio
tenantAware.getCurrentTenant(), target.getControllerId(), module.getId())
.accept(MediaTypes.HAL_JSON_VALUE))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(content().contentType(APPLICATION_JSON_HAL_UTF))
.andExpect(content().contentType(MediaTypes.HAL_JSON_UTF8))
.andDo(this.document.document(
pathParameters(parameterWithName("tenant").description(ApiModelPropertiesGeneric.TENANT),
parameterWithName("controllerId").description(DdiApiModelProperties.CONTROLLER_ID),

View File

@@ -24,23 +24,28 @@ import java.util.List;
import org.apache.commons.lang3.RandomStringUtils;
import org.eclipse.hawkbit.ddi.rest.resource.DdiApiConfiguration;
import org.eclipse.hawkbit.mgmt.rest.resource.MgmtApiConfiguration;
import org.eclipse.hawkbit.repository.jpa.RepositoryApplicationConfiguration;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.Action.Status;
import org.eclipse.hawkbit.repository.model.ArtifactUpload;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
import org.eclipse.hawkbit.repository.test.TestConfiguration;
import org.eclipse.hawkbit.rest.AbstractRestIntegrationTest;
import org.eclipse.hawkbit.rest.RestConfiguration;
import org.eclipse.hawkbit.rest.util.FilterHttpResponse;
import org.junit.Before;
import org.junit.Rule;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.cloud.stream.test.binder.TestSupportBinderAutoConfiguration;
import org.springframework.restdocs.JUnitRestDocumentation;
import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation;
import org.springframework.restdocs.mockmvc.RestDocumentationResultHandler;
import org.springframework.restdocs.payload.FieldDescriptor;
import org.springframework.restdocs.payload.SubsectionDescriptor;
import org.springframework.restdocs.snippet.Snippet;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
@@ -55,7 +60,8 @@ import io.qameta.allure.Feature;
*
*/
@Feature("Documentation Verfication - API")
@SpringApplicationConfiguration(classes = { DdiApiConfiguration.class, MgmtApiConfiguration.class })
@ContextConfiguration(classes = { DdiApiConfiguration.class, MgmtApiConfiguration.class, RestConfiguration.class,
RepositoryApplicationConfiguration.class, TestConfiguration.class, TestSupportBinderAutoConfiguration.class })
@TestPropertySource(locations = { "classpath:/updateserver-restdocumentation-test.properties" })
public abstract class AbstractApiRestDocumentation extends AbstractRestIntegrationTest {
@@ -94,6 +100,11 @@ public abstract class AbstractApiRestDocumentation extends AbstractRestIntegrati
myFieldDesc.attributes(key("mandatory").value(mandatory ? "X" : ""));
// defaults
myFieldDesc.attributes(key("value").value(""));
if (!mandatory) {
myFieldDesc.optional();
}
return myFieldDesc;
}
@@ -105,7 +116,7 @@ public abstract class AbstractApiRestDocumentation extends AbstractRestIntegrati
return requestFieldWithPath(path, false);
}
public static class MyFieldFieldDesc extends FieldDescriptor {
public static class MyFieldFieldDesc extends SubsectionDescriptor {
/**
* @param path

View File

@@ -39,6 +39,7 @@ import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.Before;
import org.junit.Test;
import org.springframework.hateoas.MediaTypes;
import org.springframework.http.MediaType;
import org.springframework.restdocs.payload.JsonFieldType;
@@ -361,9 +362,9 @@ public class DistributionSetsDocumentationTest extends AbstractApiRestDocumentat
final JSONArray list = new JSONArray();
for (final String targetId : knownTargetIds) {
targetManagement.create(entityFactory.target().create().controllerId(targetId));
list.put(new JSONObject().put("id", targetId).put("type", "timeforced").put("forcetime", forceTime).put(
"maintenanceWindow",
getMaintenanceWindow(getTestSchedule(10), getTestDuration(10), getTestTimeZone())));
list.put(new JSONObject().put("id", targetId).put("type", "timeforced").put("forcetime", forceTime)
.put("maintenanceWindow", new JSONObject().put("schedule", getTestSchedule(100))
.put("duration", getTestDuration(10)).put("timezone", getTestTimeZone())));
}
// assign already one target to DS
@@ -509,7 +510,7 @@ public class DistributionSetsDocumentationTest extends AbstractApiRestDocumentat
mockMvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/{distributionSetId}/metadata",
testDS.getId())).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(content().contentType(APPLICATION_JSON_HAL_UTF))
.andExpect(content().contentType(MediaTypes.HAL_JSON_UTF8))
.andDo(this.document.document(
pathParameters(
parameterWithName("distributionSetId").description(ApiModelPropertiesGeneric.ITEM_ID)),
@@ -538,7 +539,7 @@ public class DistributionSetsDocumentationTest extends AbstractApiRestDocumentat
mockMvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/{dsId}/metadata", testDS.getId())
.param("offset", "1").param("limit", "2").param("sort", "key:DESC").param("q", "key==known*"))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(content().contentType(APPLICATION_JSON_HAL_UTF))
.andExpect(content().contentType(MediaTypes.HAL_JSON_UTF8))
.andDo(this.document.document(
requestParameters(
parameterWithName("limit").attributes(key("type").value("query"))
@@ -648,7 +649,7 @@ public class DistributionSetsDocumentationTest extends AbstractApiRestDocumentat
mockMvc.perform(post(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/{distributionSetId}/metadata",
testDS.getId()).contentType(MediaType.APPLICATION_JSON_UTF8).content(jsonArray.toString()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated())
.andExpect(content().contentType(APPLICATION_JSON_HAL_UTF))
.andExpect(content().contentType(MediaTypes.HAL_JSON_UTF8))
.andDo(this.document.document(
pathParameters(
parameterWithName("distributionSetId").description(ApiModelPropertiesGeneric.ITEM_ID)),

View File

@@ -85,7 +85,7 @@ public class RolloutResourceDocumentationTest extends AbstractApiRestDocumentati
mockMvc.perform(get(MgmtRestConstants.ROLLOUT_V1_REQUEST_MAPPING).accept(MediaTypes.HAL_JSON_VALUE))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(content().contentType(APPLICATION_JSON_HAL_UTF))
.andExpect(content().contentType(MediaTypes.HAL_JSON_UTF8))
.andDo(this.document.document(getRolloutResponseFields(true, false,
fieldWithPath("total").description(ApiModelPropertiesGeneric.TOTAL_ELEMENTS),
fieldWithPath("size").type(JsonFieldType.NUMBER).description(ApiModelPropertiesGeneric.SIZE),
@@ -101,7 +101,7 @@ public class RolloutResourceDocumentationTest extends AbstractApiRestDocumentati
mockMvc.perform(get(MgmtRestConstants.ROLLOUT_V1_REQUEST_MAPPING).param("offset", "0").param("limit", "2")
.param("sort", "id:DESC").param("q", "name==exampleRollout*").accept(MediaTypes.HAL_JSON_VALUE))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(content().contentType(APPLICATION_JSON_HAL_UTF))
.andExpect(content().contentType(MediaTypes.HAL_JSON_UTF8))
.andDo(this.document.document(getFilterRequestParamter()));
}
@@ -162,7 +162,7 @@ public class RolloutResourceDocumentationTest extends AbstractApiRestDocumentati
mockMvc.perform(get(MgmtRestConstants.ROLLOUT_V1_REQUEST_MAPPING + "/{rolloutId}", rollout.getId())
.accept(MediaTypes.HAL_JSON_VALUE)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(content().contentType(APPLICATION_JSON_HAL_UTF))
.andExpect(content().contentType(MediaTypes.HAL_JSON_UTF8))
.andDo(this.document.document(getRolloutResponseFields(false, true),
pathParameters(parameterWithName("rolloutId").description(ApiModelPropertiesGeneric.ITEM_ID))));
}
@@ -185,9 +185,9 @@ public class RolloutResourceDocumentationTest extends AbstractApiRestDocumentati
.errorAction(RolloutGroupErrorAction.PAUSE, "").build();
mockMvc.perform(post(MgmtRestConstants.ROLLOUT_V1_REQUEST_MAPPING)
.content(JsonBuilder.rollout(name, description, groupSize, dsId, targetFilter, rolloutGroupConditions))
.contentType(APPLICATION_JSON_HAL_UTF).accept(MediaTypes.HAL_JSON_VALUE))
.contentType(MediaTypes.HAL_JSON_UTF8).accept(MediaTypes.HAL_JSON_VALUE))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated())
.andExpect(content().contentType(APPLICATION_JSON_HAL_UTF))
.andExpect(content().contentType(MediaTypes.HAL_JSON_UTF8))
.andDo(this.document.document(requestFields(
requestFieldWithPath("name").description(ApiModelPropertiesGeneric.NAME),
requestFieldWithPath("distributionSetId").description(MgmtApiModelProperties.ROLLOUT_DS_ID),
@@ -269,7 +269,7 @@ public class RolloutResourceDocumentationTest extends AbstractApiRestDocumentati
rolloutGroupConditions, rolloutGroups))
.contentType(MediaType.APPLICATION_JSON).accept(MediaTypes.HAL_JSON_VALUE))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated())
.andExpect(content().contentType(APPLICATION_JSON_HAL_UTF))
.andExpect(content().contentType(MediaTypes.HAL_JSON_UTF8))
.andDo(this.document.document(requestFields(
requestFieldWithPath("name").description(ApiModelPropertiesGeneric.NAME),
requestFieldWithPath("distributionSetId").description(MgmtApiModelProperties.ROLLOUT_DS_ID),
@@ -426,7 +426,7 @@ public class RolloutResourceDocumentationTest extends AbstractApiRestDocumentati
mockMvc.perform(get(MgmtRestConstants.ROLLOUT_V1_REQUEST_MAPPING + "/{rolloutId}/deploygroups", rollout.getId())
.accept(MediaTypes.HAL_JSON_VALUE)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(content().contentType(APPLICATION_JSON_HAL_UTF))
.andExpect(content().contentType(MediaTypes.HAL_JSON_UTF8))
.andDo(this.document.document(
getRolloutDeployGroupResponseFields(true, false,
fieldWithPath("total").description(ApiModelPropertiesGeneric.TOTAL_ELEMENTS),
@@ -447,7 +447,7 @@ public class RolloutResourceDocumentationTest extends AbstractApiRestDocumentati
mockMvc.perform(get(MgmtRestConstants.ROLLOUT_V1_REQUEST_MAPPING + "/{rolloutId}/deploygroups/{deployGroupId}",
rollout.getId(), firstRolloutGroup.getId()).accept(MediaTypes.HAL_JSON_VALUE))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(content().contentType(APPLICATION_JSON_HAL_UTF))
.andExpect(content().contentType(MediaTypes.HAL_JSON_UTF8))
.andDo(this.document.document(getRolloutDeployGroupResponseFields(false, true),
pathParameters(parameterWithName("rolloutId").description(ApiModelPropertiesGeneric.ITEM_ID),
parameterWithName("deployGroupId").description(ApiModelPropertiesGeneric.ITEM_ID))));
@@ -528,14 +528,14 @@ public class RolloutResourceDocumentationTest extends AbstractApiRestDocumentati
public void getRolloutDeployGroupWithParameters() throws Exception {
final Rollout rollout = createRolloutEntity();
final RolloutGroup firstRolloutGroup = rolloutGroupManagement
.findByRollout(new PageRequest(0, 1), rollout.getId()).getContent().get(0);
.findByRollout(PageRequest.of(0, 1), rollout.getId()).getContent().get(0);
mockMvc.perform(get(MgmtRestConstants.ROLLOUT_V1_REQUEST_MAPPING + "/{rolloutId}/deploygroups/{deployGroupId}",
rollout.getId(), firstRolloutGroup.getId()).param("offset", "0").param("limit", "2")
.param("sort", "id:DESC").param("q", "id==" + firstRolloutGroup.getId())
.accept(MediaTypes.HAL_JSON_VALUE))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(content().contentType(APPLICATION_JSON_HAL_UTF))
.andExpect(content().contentType(MediaTypes.HAL_JSON_UTF8))
.andDo(this.document.document(
pathParameters(parameterWithName("rolloutId").description(ApiModelPropertiesGeneric.ITEM_ID),
parameterWithName("deployGroupId").description(ApiModelPropertiesGeneric.ITEM_ID)),
@@ -548,13 +548,13 @@ public class RolloutResourceDocumentationTest extends AbstractApiRestDocumentati
public void getRolloutDeployGroupTargets() throws Exception {
final Rollout rollout = createRolloutEntity();
final RolloutGroup firstRolloutGroup = rolloutGroupManagement
.findByRollout(new PageRequest(0, 1), rollout.getId()).getContent().get(0);
.findByRollout(PageRequest.of(0, 1), rollout.getId()).getContent().get(0);
mockMvc.perform(
get(MgmtRestConstants.ROLLOUT_V1_REQUEST_MAPPING + "/{rolloutId}/deploygroups/{deployGroupId}/targets",
rollout.getId(), firstRolloutGroup.getId()).accept(MediaTypes.HAL_JSON_VALUE))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(content().contentType(APPLICATION_JSON_HAL_UTF))
.andExpect(content().contentType(MediaTypes.HAL_JSON_UTF8))
.andDo(this.document.document(
pathParameters(parameterWithName("rolloutId").description(ApiModelPropertiesGeneric.ITEM_ID),
parameterWithName("deployGroupId").description(ApiModelPropertiesGeneric.ITEM_ID)),
@@ -596,7 +596,7 @@ public class RolloutResourceDocumentationTest extends AbstractApiRestDocumentati
public void getRolloutDeployGroupTargetsWithParameters() throws Exception {
final Rollout rollout = createRolloutEntity();
final RolloutGroup firstRolloutGroup = rolloutGroupManagement
.findByRollout(new PageRequest(0, 1), rollout.getId()).getContent().get(0);
.findByRollout(PageRequest.of(0, 1), rollout.getId()).getContent().get(0);
mockMvc.perform(
get(MgmtRestConstants.ROLLOUT_V1_REQUEST_MAPPING + "/{rolloutId}/deploygroups/{deployGroupId}/targets",
@@ -604,7 +604,7 @@ public class RolloutResourceDocumentationTest extends AbstractApiRestDocumentati
.param("sort", "name:ASC").param("q", "controllerId==exampleTarget0")
.accept(MediaTypes.HAL_JSON_VALUE))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(content().contentType(APPLICATION_JSON_HAL_UTF))
.andExpect(content().contentType(MediaTypes.HAL_JSON_UTF8))
.andDo(this.document.document(
pathParameters(parameterWithName("rolloutId").description(ApiModelPropertiesGeneric.ITEM_ID),
parameterWithName("deployGroupId").description(ApiModelPropertiesGeneric.ITEM_ID)),

View File

@@ -42,6 +42,7 @@ import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.Before;
import org.junit.Test;
import org.springframework.hateoas.MediaTypes;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.restdocs.payload.JsonFieldType;
@@ -77,7 +78,7 @@ public class SoftwaremodulesDocumentationTest extends AbstractApiRestDocumentati
.update(entityFactory.softwareModule().update(sm2.getId()).description("a description"));
mockMvc.perform(get(MgmtRestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING)).andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()).andExpect(content().contentType(APPLICATION_JSON_HAL_UTF))
.andExpect(status().isOk()).andExpect(content().contentType(MediaTypes.HAL_JSON_UTF8))
.andDo(this.document.document(responseFields(
fieldWithPath("total").description(ApiModelPropertiesGeneric.TOTAL_ELEMENTS),
fieldWithPath("size").type(JsonFieldType.NUMBER).description(ApiModelPropertiesGeneric.SIZE),
@@ -113,7 +114,7 @@ public class SoftwaremodulesDocumentationTest extends AbstractApiRestDocumentati
.param("limit", "2").param("sort", "version:DESC").param("q", "name==SM*"))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(content().contentType(APPLICATION_JSON_HAL_UTF))
.andExpect(content().contentType(MediaTypes.HAL_JSON_UTF8))
.andDo(this.document.document(getFilterRequestParamter()));
}
@@ -129,9 +130,9 @@ public class SoftwaremodulesDocumentationTest extends AbstractApiRestDocumentati
final List<SoftwareModule> modules = Arrays.asList(os, ah);
mockMvc.perform(post(MgmtRestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING)
.content(JsonBuilder.softwareModulesCreatableFieldsOnly(modules)).contentType(APPLICATION_JSON_HAL_UTF))
.content(JsonBuilder.softwareModulesCreatableFieldsOnly(modules)).contentType(MediaTypes.HAL_JSON_UTF8))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated())
.andExpect(content().contentType(APPLICATION_JSON_HAL_UTF))
.andExpect(content().contentType(MediaTypes.HAL_JSON_UTF8))
.andDo(this.document.document(
requestFields(requestFieldWithPath("[]name").description(ApiModelPropertiesGeneric.NAME),
optionalRequestFieldWithPath("[]description")
@@ -178,7 +179,7 @@ public class SoftwaremodulesDocumentationTest extends AbstractApiRestDocumentati
mockMvc.perform(get(MgmtRestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING + "/{softwareModuleId}", sm.getId()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(content().contentType(APPLICATION_JSON_HAL_UTF))
.andExpect(content().contentType(MediaTypes.HAL_JSON_UTF8))
.andDo(this.document.document(
pathParameters(
parameterWithName("softwareModuleId").description(ApiModelPropertiesGeneric.ITEM_ID)),
@@ -210,9 +211,9 @@ public class SoftwaremodulesDocumentationTest extends AbstractApiRestDocumentati
.vendor("another Vendor").description("a new description").type(Constants.SMT_DEFAULT_OS_KEY).build();
mockMvc.perform(put(MgmtRestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING + "/{softwareModuleId}", sm.getId())
.content(JsonBuilder.softwareModuleUpdatableFieldsOnly(update)).contentType(APPLICATION_JSON_HAL_UTF))
.content(JsonBuilder.softwareModuleUpdatableFieldsOnly(update)).contentType(MediaTypes.HAL_JSON_UTF8))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(content().contentType(APPLICATION_JSON_HAL_UTF))
.andExpect(content().contentType(MediaTypes.HAL_JSON_UTF8))
.andDo(this.document.document(
pathParameters(
parameterWithName("softwareModuleId").description(ApiModelPropertiesGeneric.ITEM_ID)),
@@ -250,7 +251,7 @@ public class SoftwaremodulesDocumentationTest extends AbstractApiRestDocumentati
mockMvc.perform(
get(MgmtRestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING + "/{softwareModuleId}/artifacts", sm.getId()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(content().contentType(APPLICATION_JSON_HAL_UTF))
.andExpect(content().contentType(MediaTypes.HAL_JSON_UTF8))
.andDo(this.document.document(
pathParameters(
parameterWithName("softwareModuleId").description(ApiModelPropertiesGeneric.ITEM_ID)),
@@ -283,7 +284,7 @@ public class SoftwaremodulesDocumentationTest extends AbstractApiRestDocumentati
fileUpload(MgmtRestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING + "/{softwareModuleId}/artifacts",
sm.getId()).file(file))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated())
.andExpect(content().contentType(APPLICATION_JSON_HAL_UTF))
.andExpect(content().contentType(MediaTypes.HAL_JSON_UTF8))
.andDo(this.document.document(
pathParameters(
parameterWithName("softwareModuleId").description(ApiModelPropertiesGeneric.ITEM_ID)),
@@ -301,7 +302,7 @@ public class SoftwaremodulesDocumentationTest extends AbstractApiRestDocumentati
fieldWithPath("providedFilename")
.description(MgmtApiModelProperties.ARTIFACT_PROVIDED_FILENAME)))
);
);
}
@Test
@@ -318,7 +319,7 @@ public class SoftwaremodulesDocumentationTest extends AbstractApiRestDocumentati
sm.getId()).file(file).param("filename", "filename").param("file", "s")
.param("md5sum", "md5sum").param("sha1sum", "sha1sum"))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest())
.andExpect(content().contentType(APPLICATION_JSON_HAL_UTF))
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andDo(this.document.document(requestParameters(
parameterWithName("filename").description(MgmtApiModelProperties.ARTIFACT_PROVIDED_FILENAME),
parameterWithName("file").description(MgmtApiModelProperties.ARTIFACT_PROVIDED_FILE),
@@ -360,7 +361,7 @@ public class SoftwaremodulesDocumentationTest extends AbstractApiRestDocumentati
get(MgmtRestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING + "/{softwareModuleId}/artifacts/{artifactId}",
sm.getId(), artifact.getId()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(content().contentType(APPLICATION_JSON_HAL_UTF))
.andExpect(content().contentType(MediaTypes.HAL_JSON_UTF8))
.andDo(this.document.document(
pathParameters(
parameterWithName("softwareModuleId").description(ApiModelPropertiesGeneric.ITEM_ID),
@@ -417,7 +418,7 @@ public class SoftwaremodulesDocumentationTest extends AbstractApiRestDocumentati
mockMvc.perform(get(MgmtRestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING + "/{softwareModuleId}/metadata",
module.getId())).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(content().contentType(APPLICATION_JSON_HAL_UTF))
.andExpect(content().contentType(MediaTypes.HAL_JSON_UTF8))
.andDo(this.document.document(
pathParameters(
parameterWithName("softwareModuleId").description(ApiModelPropertiesGeneric.ITEM_ID)),
@@ -449,7 +450,7 @@ public class SoftwaremodulesDocumentationTest extends AbstractApiRestDocumentati
module.getId()).param("offset", "1").param("limit", "2").param("sort", "key:DESC").param("q",
"key==known*"))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(content().contentType(APPLICATION_JSON_HAL_UTF))
.andExpect(content().contentType(MediaTypes.HAL_JSON_UTF8))
.andDo(this.document.document(
pathParameters(
parameterWithName("softwareModuleId").description(ApiModelPropertiesGeneric.ITEM_ID)),
@@ -478,16 +479,16 @@ public class SoftwaremodulesDocumentationTest extends AbstractApiRestDocumentati
jsonArray.put(new JSONObject().put("key", knownKey2).put("value", knownValue2).put("targetVisible", true));
mockMvc.perform(post(MgmtRestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING + "/{softwareModuleId}/metadata",
module.getId()).contentType(APPLICATION_JSON_HAL_UTF).content(jsonArray.toString()))
module.getId()).contentType(MediaTypes.HAL_JSON_UTF8).content(jsonArray.toString()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated())
.andExpect(content().contentType(APPLICATION_JSON_HAL_UTF))
.andExpect(content().contentType(MediaTypes.HAL_JSON_UTF8))
.andDo(this.document.document(
pathParameters(
parameterWithName("softwareModuleId").description(ApiModelPropertiesGeneric.ITEM_ID)),
requestFields(requestFieldWithPath("[]key").description(MgmtApiModelProperties.META_DATA_KEY),
requestFieldWithPath("[]value").description(MgmtApiModelProperties.META_DATA_VALUE),
requestFieldWithPath("[]targetVisible")
.description(MgmtApiModelProperties.SM_META_DATA_TARGET_VISIBLE)),
.description(MgmtApiModelProperties.SM_META_DATA_TARGET_VISIBLE).optional()),
responseFields(fieldWithPath("[]key").description(MgmtApiModelProperties.META_DATA_KEY),
fieldWithPath("[]value").description(MgmtApiModelProperties.META_DATA_VALUE),
@@ -496,7 +497,7 @@ public class SoftwaremodulesDocumentationTest extends AbstractApiRestDocumentati
)
));
));
}
@Test
@@ -562,7 +563,7 @@ public class SoftwaremodulesDocumentationTest extends AbstractApiRestDocumentati
mockMvc.perform(
put(MgmtRestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING + "/{softwareModuleId}/metadata/{metadataKey}",
module.getId(), knownKey).contentType(APPLICATION_JSON_HAL_UTF).content(jsonObject.toString()))
module.getId(), knownKey).contentType(MediaTypes.HAL_JSON_UTF8).content(jsonObject.toString()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(this.document.document(
pathParameters(parameterWithName("softwareModuleId")

View File

@@ -46,6 +46,7 @@ import org.junit.Before;
import org.junit.Test;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.hateoas.MediaTypes;
import org.springframework.http.MediaType;
import org.springframework.restdocs.payload.JsonFieldType;
@@ -157,8 +158,7 @@ public class TargetResourceDocumentationTest extends AbstractApiRestDocumentatio
public void deleteTarget() throws Exception {
final Target target = testdataFactory.createTarget(targetId);
mockMvc.perform(
delete(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}", target.getControllerId()))
mockMvc.perform(delete(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}", target.getControllerId()))
.andExpect(status().isOk()).andDo(MockMvcResultPrinter.print()).andDo(this.document.document(
pathParameters(parameterWithName("targetId").description(ApiModelPropertiesGeneric.ITEM_ID))));
}
@@ -171,8 +171,7 @@ public class TargetResourceDocumentationTest extends AbstractApiRestDocumentatio
mockMvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}", target.getControllerId()))
.andExpect(status().isOk()).andDo(MockMvcResultPrinter.print())
.andDo(this.document.document(
pathParameters(
parameterWithName("targetId").description(ApiModelPropertiesGeneric.ITEM_ID)),
pathParameters(parameterWithName("targetId").description(ApiModelPropertiesGeneric.ITEM_ID)),
getResponseFieldTarget(false)));
}
@@ -186,8 +185,7 @@ public class TargetResourceDocumentationTest extends AbstractApiRestDocumentatio
.contentType(MediaType.APPLICATION_JSON_UTF8).content(targetAsJson)).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andDo(this.document.document(
pathParameters(
parameterWithName("targetId").description(ApiModelPropertiesGeneric.ITEM_ID)),
pathParameters(parameterWithName("targetId").description(ApiModelPropertiesGeneric.ITEM_ID)),
requestFields(optionalRequestFieldWithPath("name").description(ApiModelPropertiesGeneric.NAME),
optionalRequestFieldWithPath("description")
.description(ApiModelPropertiesGeneric.DESCRPTION),
@@ -206,12 +204,12 @@ public class TargetResourceDocumentationTest extends AbstractApiRestDocumentatio
public void getActionsFromTarget() throws Exception {
generateActionForTarget(targetId);
mockMvc.perform(get(
MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/" + MgmtRestConstants.TARGET_V1_ACTIONS,
targetId)).andExpect(status().isOk()).andDo(MockMvcResultPrinter.print())
mockMvc.perform(
get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/" + MgmtRestConstants.TARGET_V1_ACTIONS,
targetId))
.andExpect(status().isOk()).andDo(MockMvcResultPrinter.print())
.andDo(this.document.document(
pathParameters(
parameterWithName("targetId").description(ApiModelPropertiesGeneric.ITEM_ID)),
pathParameters(parameterWithName("targetId").description(ApiModelPropertiesGeneric.ITEM_ID)),
responseFields(
fieldWithPath("size").type(JsonFieldType.NUMBER)
.description(ApiModelPropertiesGeneric.SIZE),
@@ -238,12 +236,12 @@ public class TargetResourceDocumentationTest extends AbstractApiRestDocumentatio
public void getActionsFromTargetWithMaintenanceWindow() throws Exception {
generateActionForTarget(targetId, true, false, getTestSchedule(2), getTestDuration(1), getTestTimeZone());
mockMvc.perform(get(
MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/" + MgmtRestConstants.TARGET_V1_ACTIONS,
targetId)).andExpect(status().isOk()).andDo(MockMvcResultPrinter.print())
mockMvc.perform(
get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/" + MgmtRestConstants.TARGET_V1_ACTIONS,
targetId))
.andExpect(status().isOk()).andDo(MockMvcResultPrinter.print())
.andDo(this.document.document(
pathParameters(
parameterWithName("targetId").description(ApiModelPropertiesGeneric.ITEM_ID)),
pathParameters(parameterWithName("targetId").description(ApiModelPropertiesGeneric.ITEM_ID)),
responseFields(
fieldWithPath("size").type(JsonFieldType.NUMBER)
.description(ApiModelPropertiesGeneric.SIZE),
@@ -405,10 +403,10 @@ public class TargetResourceDocumentationTest extends AbstractApiRestDocumentatio
final Map<String, Object> body = new HashMap<>();
body.put("forceType", "forced");
mockMvc.perform(put(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/"
+ MgmtRestConstants.TARGET_V1_ACTIONS + "/{actionId}", targetId, actionId)
.content(this.objectMapper.writeValueAsString(body))
.contentType(MediaType.APPLICATION_JSON_UTF8))
mockMvc.perform(
put(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/" + MgmtRestConstants.TARGET_V1_ACTIONS
+ "/{actionId}", targetId, actionId).content(this.objectMapper.writeValueAsString(body))
.contentType(MediaType.APPLICATION_JSON_UTF8))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(this.document.document(
pathParameters(parameterWithName("targetId").description(ApiModelPropertiesGeneric.ITEM_ID),
@@ -439,9 +437,10 @@ public class TargetResourceDocumentationTest extends AbstractApiRestDocumentatio
public void getStatusFromAction() throws Exception {
final Action action = generateActionForTarget(targetId);
mockMvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/"
+ MgmtRestConstants.TARGET_V1_ACTIONS + "/{actionId}/" + MgmtRestConstants.TARGET_V1_ACTION_STATUS,
targetId, action.getId())).andExpect(status().isOk()).andDo(MockMvcResultPrinter.print())
mockMvc.perform(
get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/" + MgmtRestConstants.TARGET_V1_ACTIONS
+ "/{actionId}/" + MgmtRestConstants.TARGET_V1_ACTION_STATUS, targetId, action.getId()))
.andExpect(status().isOk()).andDo(MockMvcResultPrinter.print())
.andDo(this.document.document(
pathParameters(parameterWithName("targetId").description(ApiModelPropertiesGeneric.ITEM_ID),
parameterWithName("actionId").description(ApiModelPropertiesGeneric.ITEM_ID)),
@@ -484,8 +483,7 @@ public class TargetResourceDocumentationTest extends AbstractApiRestDocumentatio
+ MgmtRestConstants.TARGET_V1_ASSIGNED_DISTRIBUTION_SET, targetId)).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andDo(this.document.document(
pathParameters(
parameterWithName("targetId").description(ApiModelPropertiesGeneric.ITEM_ID)),
pathParameters(parameterWithName("targetId").description(ApiModelPropertiesGeneric.ITEM_ID)),
getResponseFieldsDistributionSet(false)));
}
@@ -497,8 +495,9 @@ public class TargetResourceDocumentationTest extends AbstractApiRestDocumentatio
final long forceTime = System.currentTimeMillis();
final String body = new JSONObject().put("id", set.getId()).put("type", "timeforced")
.put("forcetime", forceTime).put("maintenanceWindow",
getMaintenanceWindow(getTestSchedule(10), getTestDuration(10), getTestTimeZone()))
.put("forcetime", forceTime)
.put("maintenanceWindow", new JSONObject().put("schedule", getTestSchedule(100))
.put("duration", getTestDuration(10)).put("timezone", getTestTimeZone()))
.toString();
mockMvc.perform(post(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/"
@@ -506,8 +505,7 @@ public class TargetResourceDocumentationTest extends AbstractApiRestDocumentatio
.contentType(MediaType.APPLICATION_JSON_UTF8))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(this.document.document(
pathParameters(
parameterWithName("targetId").description(ApiModelPropertiesGeneric.ITEM_ID)),
pathParameters(parameterWithName("targetId").description(ApiModelPropertiesGeneric.ITEM_ID)),
requestParameters(parameterWithName("offline")
.description(MgmtApiModelProperties.OFFLINE_UPDATE).optional()),
requestFields(requestFieldWithPath("forcetime").description(MgmtApiModelProperties.FORCETIME),
@@ -541,12 +539,11 @@ public class TargetResourceDocumentationTest extends AbstractApiRestDocumentatio
controllerManagement.updateControllerAttributes(targetId, knownControllerAttrs, null);
// test query target over rest resource
mockMvc.perform(
get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/attributes", target.getName()))
mockMvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/attributes", target.getName()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().is2xxSuccessful())
.andExpect(jsonPath("$.a", equalTo("1"))).andExpect(jsonPath("$.b", equalTo("2")))
.andDo(this.document.document(pathParameters(
parameterWithName("targetId").description(ApiModelPropertiesGeneric.ITEM_ID))));
.andDo(this.document.document(
pathParameters(parameterWithName("targetId").description(ApiModelPropertiesGeneric.ITEM_ID))));
}
@Test
@@ -558,8 +555,7 @@ public class TargetResourceDocumentationTest extends AbstractApiRestDocumentatio
+ MgmtRestConstants.TARGET_V1_INSTALLED_DISTRIBUTION_SET, target.getName())).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andDo(this.document.document(
pathParameters(
parameterWithName("targetId").description(ApiModelPropertiesGeneric.ITEM_ID)),
pathParameters(parameterWithName("targetId").description(ApiModelPropertiesGeneric.ITEM_ID)),
getResponseFieldsDistributionSet(false)));
}
@@ -576,12 +572,12 @@ public class TargetResourceDocumentationTest extends AbstractApiRestDocumentatio
entityFactory.generateTargetMetadata(knownKeyPrefix + index, knownValuePrefix + index)));
}
mockMvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/metadata",
testTarget.getControllerId())).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(content().contentType(APPLICATION_JSON_HAL_UTF))
mockMvc.perform(
get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/metadata", testTarget.getControllerId()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(content().contentType(MediaTypes.HAL_JSON_UTF8))
.andDo(this.document.document(
pathParameters(
parameterWithName("targetId").description(ApiModelPropertiesGeneric.ITEM_ID)),
pathParameters(parameterWithName("targetId").description(ApiModelPropertiesGeneric.ITEM_ID)),
responseFields(fieldWithPath("total").description(ApiModelPropertiesGeneric.TOTAL_ELEMENTS),
fieldWithPath("size").type(JsonFieldType.NUMBER)
.description(ApiModelPropertiesGeneric.SIZE),
@@ -604,11 +600,11 @@ public class TargetResourceDocumentationTest extends AbstractApiRestDocumentatio
entityFactory.generateTargetMetadata(knownKeyPrefix + index, knownValuePrefix + index)));
}
mockMvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/metadata",
testTarget.getControllerId()).param("offset", "1").param("limit", "2").param("sort", "key:DESC")
.param("q", "key==known*"))
mockMvc.perform(
get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/metadata", testTarget.getControllerId())
.param("offset", "1").param("limit", "2").param("sort", "key:DESC").param("q", "key==known*"))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(content().contentType(APPLICATION_JSON_HAL_UTF))
.andExpect(content().contentType(MediaTypes.HAL_JSON_UTF8))
.andDo(this.document.document(
requestParameters(
parameterWithName("limit").attributes(key("type").value("query"))
@@ -711,14 +707,12 @@ public class TargetResourceDocumentationTest extends AbstractApiRestDocumentatio
jsonArray.put(new JSONObject().put("key", knownKey2).put("value", knownValue2));
mockMvc.perform(
post(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/metadata",
testTarget.getControllerId()).contentType(MediaType.APPLICATION_JSON_UTF8)
.content(jsonArray.toString()))
post(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/metadata", testTarget.getControllerId())
.contentType(MediaType.APPLICATION_JSON_UTF8).content(jsonArray.toString()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated())
.andExpect(content().contentType(APPLICATION_JSON_HAL_UTF))
.andExpect(content().contentType(MediaTypes.HAL_JSON_UTF8))
.andDo(this.document.document(
pathParameters(
parameterWithName("targetId").description(ApiModelPropertiesGeneric.ITEM_ID)),
pathParameters(parameterWithName("targetId").description(ApiModelPropertiesGeneric.ITEM_ID)),
requestFields(requestFieldWithPath("[]key").description(MgmtApiModelProperties.META_DATA_KEY),
optionalRequestFieldWithPath("[]value")
.description(MgmtApiModelProperties.META_DATA_VALUE))));
@@ -763,7 +757,7 @@ public class TargetResourceDocumentationTest extends AbstractApiRestDocumentatio
private Action generateActionForTarget(final String knownControllerId, final boolean inSync,
final boolean timeforced, final String maintenanceWindowSchedule, final String maintenanceWindowDuration,
final String maintenanceWindowTimeZone) throws Exception {
final PageRequest pageRequest = new PageRequest(0, 1, Direction.ASC, ActionStatusFields.ID.getFieldName());
final PageRequest pageRequest = PageRequest.of(0, 1, Direction.ASC, ActionStatusFields.ID.getFieldName());
createTargetByGivenNameWithAttributes(knownControllerId, inSync, timeforced, createDistributionSet(),
maintenanceWindowSchedule, maintenanceWindowDuration, maintenanceWindowTimeZone);