Search in sources :

Example 6 with ConstraintCheckResult

use of org.graylog2.contentpacks.model.constraints.ConstraintCheckResult in project graylog2-server by Graylog2.

the class ContentPackResourceTest method getContentPack.

@Test
public void getContentPack() throws Exception {
    final ContentPack contentPack = objectMapper.readValue(CONTENT_PACK, ContentPack.class);
    final Set<ContentPack> contentPackSet = Collections.singleton(contentPack);
    final Set<ConstraintCheckResult> constraints = Collections.emptySet();
    final Map<Integer, ContentPack> contentPacks = Collections.singletonMap(1, contentPack);
    final Map<Integer, Set<ConstraintCheckResult>> constraintMap = Collections.singletonMap(1, constraints);
    final ContentPackRevisions expectedRevisions = ContentPackRevisions.create(contentPacks, constraintMap);
    final ModelId id = ModelId.of("1");
    when(contentPackPersistenceService.findAllById(id)).thenReturn(contentPackSet);
    final ContentPackRevisions contentPackRevisions = contentPackResource.listContentPackRevisions(id);
    verify(contentPackPersistenceService, times(1)).findAllById(id);
    assertThat(contentPackRevisions).isEqualTo(expectedRevisions);
    when(contentPackPersistenceService.findByIdAndRevision(id, 1)).thenReturn(Optional.ofNullable(contentPack));
    final ContentPackResponse contentPackResponse = contentPackResource.getContentPackRevisions(id, 1);
    verify(contentPackPersistenceService, times(1)).findByIdAndRevision(id, 1);
    assertThat(contentPackResponse.contentPack()).isEqualTo(contentPack);
}
Also used : ConstraintCheckResult(org.graylog2.contentpacks.model.constraints.ConstraintCheckResult) Set(java.util.Set) ContentPackRevisions(org.graylog2.rest.models.system.contentpacks.responses.ContentPackRevisions) ContentPack(org.graylog2.contentpacks.model.ContentPack) ContentPackResponse(org.graylog2.rest.models.system.contentpacks.responses.ContentPackResponse) ModelId(org.graylog2.contentpacks.model.ModelId) Test(org.junit.Test)

Example 7 with ConstraintCheckResult

use of org.graylog2.contentpacks.model.constraints.ConstraintCheckResult in project graylog2-server by Graylog2.

the class GraylogVersionConstraintChecker method checkConstraints.

@Override
public Set<ConstraintCheckResult> checkConstraints(Collection<Constraint> requestedConstraints) {
    final ImmutableSet.Builder<ConstraintCheckResult> fulfilledConstraints = ImmutableSet.builder();
    for (Constraint constraint : requestedConstraints) {
        if (constraint instanceof GraylogVersionConstraint) {
            final GraylogVersionConstraint versionConstraint = (GraylogVersionConstraint) constraint;
            final Requirement requiredVersion = versionConstraint.version();
            final ConstraintCheckResult constraintCheckResult = ConstraintCheckResult.create(versionConstraint, requiredVersion.isSatisfiedBy(graylogVersion.withClearedSuffixAndBuild()));
            fulfilledConstraints.add(constraintCheckResult);
        }
    }
    return fulfilledConstraints.build();
}
Also used : ConstraintCheckResult(org.graylog2.contentpacks.model.constraints.ConstraintCheckResult) Requirement(com.vdurmont.semver4j.Requirement) ImmutableSet(com.google.common.collect.ImmutableSet) GraylogVersionConstraint(org.graylog2.contentpacks.model.constraints.GraylogVersionConstraint) Constraint(org.graylog2.contentpacks.model.constraints.Constraint) GraylogVersionConstraint(org.graylog2.contentpacks.model.constraints.GraylogVersionConstraint)

Aggregations

ConstraintCheckResult (org.graylog2.contentpacks.model.constraints.ConstraintCheckResult)7 Constraint (org.graylog2.contentpacks.model.constraints.Constraint)5 GraylogVersionConstraint (org.graylog2.contentpacks.model.constraints.GraylogVersionConstraint)3 PluginVersionConstraint (org.graylog2.contentpacks.model.constraints.PluginVersionConstraint)3 Test (org.junit.Test)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 Requirement (com.vdurmont.semver4j.Requirement)2 ContentPack (org.graylog2.contentpacks.model.ContentPack)2 Timed (com.codahale.metrics.annotation.Timed)1 JsonView (com.fasterxml.jackson.annotation.JsonView)1 Semver (com.vdurmont.semver4j.Semver)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 GET (javax.ws.rs.GET)1 NotFoundException (javax.ws.rs.NotFoundException)1 Path (javax.ws.rs.Path)1 ConstraintChecker (org.graylog2.contentpacks.constraints.ConstraintChecker)1 ModelId (org.graylog2.contentpacks.model.ModelId)1