Merge pull request #107 from bsinno/complete-rep-tests
Complete repository tests
This commit is contained in:
@@ -17,7 +17,7 @@ import org.eclipse.hawkbit.repository.TagManagement;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetTagAssigmentResult;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult;
|
||||
import org.eclipse.hawkbit.repository.rsql.RSQLUtility;
|
||||
import org.eclipse.hawkbit.rest.resource.api.DistributionSetTagRestApi;
|
||||
import org.eclipse.hawkbit.rest.resource.model.PagedList;
|
||||
@@ -26,7 +26,6 @@ import org.eclipse.hawkbit.rest.resource.model.tag.AssignedDistributionSetReques
|
||||
import org.eclipse.hawkbit.rest.resource.model.tag.DistributionSetTagAssigmentResultRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.tag.TagRequestBodyPut;
|
||||
import org.eclipse.hawkbit.rest.resource.model.tag.TagRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.tag.TagsRest;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -86,7 +85,7 @@ public class DistributionSetTagResource implements DistributionSetTagRestApi {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<TagsRest> createDistributionSetTags(final List<TagRequestBodyPut> tags) {
|
||||
public ResponseEntity<List<TagRest>> createDistributionSetTags(final List<TagRequestBodyPut> tags) {
|
||||
LOG.debug("creating {} ds tags", tags.size());
|
||||
|
||||
final List<DistributionSetTag> createdTags = this.tagManagement
|
||||
@@ -135,7 +134,7 @@ public class DistributionSetTagResource implements DistributionSetTagRestApi {
|
||||
|
||||
final DistributionSetTag tag = findDistributionTagById(distributionsetTagId);
|
||||
|
||||
final DistributionSetTagAssigmentResult assigmentResult = this.distributionSetManagement
|
||||
final DistributionSetTagAssignmentResult assigmentResult = this.distributionSetManagement
|
||||
.toggleTagAssignment(findDistributionSetIds(assignedDSRequestBodies), tag.getName());
|
||||
|
||||
final DistributionSetTagAssigmentResultRest tagAssigmentResultRest = new DistributionSetTagAssigmentResultRest();
|
||||
|
||||
@@ -225,7 +225,7 @@ public class SoftwareModuleResource implements SoftwareModuleRestAPI {
|
||||
// check if distribution set exists otherwise throw exception
|
||||
// immediately
|
||||
final SoftwareModule sw = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null);
|
||||
final SoftwareModuleMetadata findOne = softwareManagement.findOne(new SwMetadataCompositeKey(sw, metadataKey));
|
||||
final SoftwareModuleMetadata findOne = softwareManagement.findSoftwareModuleMetadata(new SwMetadataCompositeKey(sw, metadataKey));
|
||||
return ResponseEntity.<MetadataRest> ok(SoftwareModuleMapper.toResponseSwMetadata(findOne));
|
||||
}
|
||||
|
||||
|
||||
@@ -102,7 +102,7 @@ public class SoftwareModuleTypeResource implements SoftwareModuleTypeRestApi {
|
||||
final List<SoftwareModuleTypeRequestBodyPost> softwareModuleTypes) {
|
||||
|
||||
final List<SoftwareModuleType> createdSoftwareModules = this.softwareManagement
|
||||
.createSoftwareModuleTypes(SoftwareModuleTypeMapper.smFromRequest(softwareModuleTypes));
|
||||
.createSoftwareModuleType(SoftwareModuleTypeMapper.smFromRequest(softwareModuleTypes));
|
||||
|
||||
return new ResponseEntity<>(SoftwareModuleTypeMapper.toTypesResponse(createdSoftwareModules),
|
||||
HttpStatus.CREATED);
|
||||
|
||||
@@ -88,7 +88,7 @@ public class SystemManagementResource {
|
||||
.setOverallTargets(report.getOverallTargets()).setOverallTenants(report.getTenants().size());
|
||||
|
||||
result.setTenantStats(
|
||||
report.getTenants().stream().map(tenant -> convertTenant(tenant)).collect(Collectors.toList()));
|
||||
report.getTenants().stream().map(SystemManagementResource::convertTenant).collect(Collectors.toList()));
|
||||
|
||||
return ResponseEntity.ok(result);
|
||||
}
|
||||
@@ -104,7 +104,7 @@ public class SystemManagementResource {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all caches containing currently.
|
||||
* Returns a list of all caches.
|
||||
*
|
||||
* @return a list of caches for all tenants
|
||||
*/
|
||||
@@ -112,8 +112,8 @@ public class SystemManagementResource {
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_SYSTEM_ADMIN)
|
||||
public ResponseEntity<Collection<CacheRest>> getCaches() {
|
||||
final Collection<String> cacheNames = cacheManager.getCacheNames();
|
||||
return ResponseEntity.ok(cacheNames.stream().map(cacheName -> cacheManager.getCache(cacheName))
|
||||
.map(cache -> cacheRest(cache)).collect(Collectors.toList()));
|
||||
return ResponseEntity
|
||||
.ok(cacheNames.stream().map(cacheManager::getCache).map(this::cacheRest).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -21,7 +21,6 @@ import org.eclipse.hawkbit.rest.resource.api.DistributionSetTagRestApi;
|
||||
import org.eclipse.hawkbit.rest.resource.api.TargetTagRestApi;
|
||||
import org.eclipse.hawkbit.rest.resource.model.tag.TagRequestBodyPut;
|
||||
import org.eclipse.hawkbit.rest.resource.model.tag.TagRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.tag.TagsRest;
|
||||
|
||||
/**
|
||||
* A mapper which maps repository model to RESTful model representation and
|
||||
@@ -33,8 +32,8 @@ final class TagMapper {
|
||||
// Utility class
|
||||
}
|
||||
|
||||
static TagsRest toResponse(final List<TargetTag> targetTags) {
|
||||
final TagsRest tagsRest = new TagsRest();
|
||||
static List<TagRest> toResponse(final List<TargetTag> targetTags) {
|
||||
final List<TagRest> tagsRest = new ArrayList<>();
|
||||
if (targetTags == null) {
|
||||
return tagsRest;
|
||||
}
|
||||
@@ -63,8 +62,8 @@ final class TagMapper {
|
||||
return response;
|
||||
}
|
||||
|
||||
static TagsRest toResponseDistributionSetTag(final List<DistributionSetTag> distributionSetTags) {
|
||||
final TagsRest tagsRest = new TagsRest();
|
||||
static List<TagRest> toResponseDistributionSetTag(final List<DistributionSetTag> distributionSetTags) {
|
||||
final List<TagRest> tagsRest = new ArrayList<>();
|
||||
if (distributionSetTags == null) {
|
||||
return tagsRest;
|
||||
}
|
||||
@@ -131,7 +130,5 @@ final class TagMapper {
|
||||
if (response.getName() != null) {
|
||||
tag.setName(response.getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@ import org.eclipse.hawkbit.rest.resource.api.TargetRestApi;
|
||||
import org.eclipse.hawkbit.rest.resource.model.PollStatusRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.action.ActionRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.action.ActionStatusRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.action.ActionsRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.target.TargetRequestBody;
|
||||
import org.eclipse.hawkbit.rest.resource.model.target.TargetRest;
|
||||
|
||||
@@ -214,8 +213,8 @@ public final class TargetMapper {
|
||||
return result;
|
||||
}
|
||||
|
||||
static ActionsRest toResponse(final String targetId, final List<Action> actions) {
|
||||
final ActionsRest mappedList = new ActionsRest();
|
||||
static List<ActionRest> toResponse(final String targetId, final List<Action> actions) {
|
||||
final List<ActionRest> mappedList = new ArrayList<>();
|
||||
|
||||
for (final Action action : actions) {
|
||||
final ActionRest response = toResponse(targetId, action, action.isActive());
|
||||
|
||||
@@ -17,14 +17,13 @@ import org.eclipse.hawkbit.repository.TargetManagement;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetTag;
|
||||
import org.eclipse.hawkbit.repository.model.TargetTagAssigmentResult;
|
||||
import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult;
|
||||
import org.eclipse.hawkbit.repository.rsql.RSQLUtility;
|
||||
import org.eclipse.hawkbit.rest.resource.api.TargetTagRestApi;
|
||||
import org.eclipse.hawkbit.rest.resource.model.PagedList;
|
||||
import org.eclipse.hawkbit.rest.resource.model.tag.AssignedTargetRequestBody;
|
||||
import org.eclipse.hawkbit.rest.resource.model.tag.TagRequestBodyPut;
|
||||
import org.eclipse.hawkbit.rest.resource.model.tag.TagRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.tag.TagsRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.tag.TargetTagAssigmentResultRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.target.TargetRest;
|
||||
import org.slf4j.Logger;
|
||||
@@ -87,7 +86,7 @@ public class TargetTagResource implements TargetTagRestApi {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<TagsRest> createTargetTags(@RequestBody final List<TagRequestBodyPut> tags) {
|
||||
public ResponseEntity<List<TagRest>> createTargetTags(@RequestBody final List<TagRequestBodyPut> tags) {
|
||||
LOG.debug("creating {} target tags", tags.size());
|
||||
final List<TargetTag> createdTargetTags = this.tagManagement
|
||||
.createTargetTags(TagMapper.mapTargeTagFromRequest(tags));
|
||||
@@ -130,7 +129,7 @@ public class TargetTagResource implements TargetTagRestApi {
|
||||
LOG.debug("Toggle Target assignment {} for target tag {}", assignedTargetRequestBodies.size(), targetTagId);
|
||||
|
||||
final TargetTag targetTag = findTargetTagById(targetTagId);
|
||||
final TargetTagAssigmentResult assigmentResult = this.targetManagement
|
||||
final TargetTagAssignmentResult assigmentResult = this.targetManagement
|
||||
.toggleTagAssignment(findTargetControllerIds(assignedTargetRequestBodies), targetTag.getName());
|
||||
|
||||
final TargetTagAssigmentResultRest tagAssigmentResultRest = new TargetTagAssigmentResultRest();
|
||||
|
||||
@@ -169,7 +169,7 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
artifactManagement
|
||||
.loadLocalArtifactBinary((LocalArtifact) softwareManagement
|
||||
.findSoftwareModuleWithDetails(sm.getId()).getArtifacts().get(0))
|
||||
.getFileInputStream()));
|
||||
.getFileInputStream()));
|
||||
|
||||
// hashes
|
||||
assertThat(artifactManagement.findLocalArtifactByFilename("origFilename").get(0).getSha1Hash())
|
||||
@@ -773,12 +773,12 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
.andExpect(jsonPath("[2].createdBy", equalTo("uploadTester")))
|
||||
.andExpect(jsonPath("[2].createdAt", not(equalTo(0)))).andReturn();
|
||||
|
||||
final SoftwareModule osCreated = softwareManagement.findSoftwareModuleByNameAndVersion("name1", "version1")
|
||||
.get(0);
|
||||
final SoftwareModule jvmCreated = softwareManagement.findSoftwareModuleByNameAndVersion("name2", "version1")
|
||||
.get(0);
|
||||
final SoftwareModule ahCreated = softwareManagement.findSoftwareModuleByNameAndVersion("name3", "version1")
|
||||
.get(0);
|
||||
final SoftwareModule osCreated = softwareManagement.findSoftwareModuleByNameAndVersion("name1", "version1",
|
||||
osType);
|
||||
final SoftwareModule jvmCreated = softwareManagement.findSoftwareModuleByNameAndVersion("name2", "version1",
|
||||
runtimeType);
|
||||
final SoftwareModule ahCreated = softwareManagement.findSoftwareModuleByNameAndVersion("name3", "version1",
|
||||
appType);
|
||||
|
||||
assertThat(
|
||||
JsonPath.compile("[0]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString())
|
||||
@@ -930,8 +930,10 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
.andExpect(jsonPath("[1]key", equalTo(knownKey2)))
|
||||
.andExpect(jsonPath("[1]value", equalTo(knownValue2)));
|
||||
|
||||
final SoftwareModuleMetadata metaKey1 = softwareManagement.findOne(new SwMetadataCompositeKey(sm, knownKey1));
|
||||
final SoftwareModuleMetadata metaKey2 = softwareManagement.findOne(new SwMetadataCompositeKey(sm, knownKey2));
|
||||
final SoftwareModuleMetadata metaKey1 = softwareManagement
|
||||
.findSoftwareModuleMetadata(new SwMetadataCompositeKey(sm, knownKey1));
|
||||
final SoftwareModuleMetadata metaKey2 = softwareManagement
|
||||
.findSoftwareModuleMetadata(new SwMetadataCompositeKey(sm, knownKey2));
|
||||
|
||||
assertThat(metaKey1.getValue()).as("Metadata key is wrong").isEqualTo(knownValue1);
|
||||
assertThat(metaKey2.getValue()).as("Metadata key is wrong").isEqualTo(knownValue2);
|
||||
@@ -957,7 +959,8 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("key", equalTo(knownKey))).andExpect(jsonPath("value", equalTo(updateValue)));
|
||||
|
||||
final SoftwareModuleMetadata assertDS = softwareManagement.findOne(new SwMetadataCompositeKey(sm, knownKey));
|
||||
final SoftwareModuleMetadata assertDS = softwareManagement
|
||||
.findSoftwareModuleMetadata(new SwMetadataCompositeKey(sm, knownKey));
|
||||
assertThat(assertDS.getValue()).as("Metadata is wrong").isEqualTo(updateValue);
|
||||
}
|
||||
|
||||
@@ -976,7 +979,7 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
|
||||
try {
|
||||
softwareManagement.findOne(new SwMetadataCompositeKey(sm, knownKey));
|
||||
softwareManagement.findSoftwareModuleMetadata(new SwMetadataCompositeKey(sm, knownKey));
|
||||
fail("expected EntityNotFoundException but didn't throw");
|
||||
} catch (final EntityNotFoundException e) {
|
||||
// ok as expected
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
package org.eclipse.hawkbit.rest.resource.model;
|
||||
|
||||
import static org.fest.assertions.Assertions.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -23,10 +24,14 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
||||
@Stories("Paged List Handling")
|
||||
public class PagedListTest {
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
@Test
|
||||
@Description("Ensures that a null payload entitiy throws an exception.")
|
||||
public void createListWithNullContentThrowsException() {
|
||||
new PagedList<>(null, 0);
|
||||
try {
|
||||
new PagedList<>(null, 0);
|
||||
fail("as content is null");
|
||||
} catch (final NullPointerException e) {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user