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);
}
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();
}
Aggregations