Fix exception handling on repository (#546)

* Fix constraint violation handling (400 instead of 500).

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Dont map constraintvioalation

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Added test in target repo.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Extended dialect handler.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Fix broken constraint handling. Added target tests and docs.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Further restricted aspect.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Add macro test.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Reduce duplicate code.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* No need to open a new transaction here.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Remove comment.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Remove flush from assign DS.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Remove commented line

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Fix exception handling for non-SQL cause.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Remove deprecated comment.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Documentation

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* More tests and documentation.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Private final.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Fix loop skip.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Fix test description.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Completed test coverage.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
Kai Zimmermann
2017-06-20 17:20:13 +02:00
committed by GitHub
parent 3b5f12b7a4
commit 2383aff5bf
25 changed files with 613 additions and 227 deletions

View File

@@ -117,13 +117,17 @@ public final class MgmtDistributionSetMapper {
response.add(linkTo(methodOn(MgmtDistributionSetRestApi.class).getDistributionSet(response.getDsId()))
.withSelfRel());
response.add(linkTo(methodOn(MgmtDistributionSetRestApi.class).getAssignedSoftwareModules(response.getDsId(),
MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET_VALUE,
MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT_VALUE, null))
.withRel(MgmtRestConstants.DISTRIBUTIONSET_V1_MODULE));
response.add(linkTo(methodOn(MgmtDistributionSetTypeRestApi.class)
.getDistributionSetType(distributionSet.getType().getId())).withRel("type"));
response.add(linkTo(methodOn(MgmtDistributionSetRestApi.class).getMetadata(response.getDsId(),
MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET_VALUE,
MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT_VALUE, null, null))
.withRel("metadata"));
MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT_VALUE, null, null)).withRel("metadata"));
return response;
}

View File

@@ -352,6 +352,26 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest
assertThat(findTargetByControllerID.getName()).isEqualTo(knownNameNotModiy);
}
@Test
@Description("Ensures that target update request fails is updated value fails against a constraint.")
public void updateTargetDescriptionFailsIfInvalidLength() throws Exception {
final String knownControllerId = "123";
final String knownNewDescription = RandomStringUtils.randomAlphabetic(513);
final String knownNameNotModiy = "nameNotModiy";
final String body = new JSONObject().put("description", knownNewDescription).toString();
// prepare
targetManagement.createTarget(entityFactory.target().create().controllerId(knownControllerId)
.name(knownNameNotModiy).description("old description"));
mvc.perform(put(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownControllerId).content(body)
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
final Target findTargetByControllerID = targetManagement.findTargetByControllerID(knownControllerId).get();
assertThat(findTargetByControllerID.getDescription()).isEqualTo("old description");
}
@Test
@Description("Ensures that target update request is reflected by repository.")
public void updateTargetSecurityToken() throws Exception {