use of org.graylog2.contentpacks.model.ModelId in project graylog2-server by Graylog2.
the class InputFacadeTest method exportEntity.
@Test
@MongoDBFixtures("InputFacadeTest.json")
public void exportEntity() {
final ModelId id = ModelId.of("5acc84f84b900a4ff290d9a7");
final EntityDescriptor descriptor = EntityDescriptor.create(id, ModelTypes.INPUT_V1);
final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor);
final Entity entity = facade.exportEntity(descriptor, entityDescriptorIds).orElseThrow(AssertionError::new);
assertThat(entity).isInstanceOf(EntityV1.class);
assertThat(entity.id()).isEqualTo(ModelId.of(entityDescriptorIds.get(descriptor).orElse(null)));
assertThat(entity.type()).isEqualTo(ModelTypes.INPUT_V1);
final EntityV1 entityV1 = (EntityV1) entity;
final InputEntity inputEntity = objectMapper.convertValue(entityV1.data(), InputEntity.class);
assertThat(inputEntity.title()).isEqualTo(ValueReference.of("Local Raw UDP"));
assertThat(inputEntity.type()).isEqualTo(ValueReference.of("org.graylog2.inputs.raw.udp.RawUDPInput"));
assertThat(inputEntity.global()).isEqualTo(ValueReference.of(false));
assertThat(inputEntity.configuration()).containsEntry("bind_address", ValueReference.of("127.0.0.1")).containsEntry("port", ValueReference.of(5555));
}
use of org.graylog2.contentpacks.model.ModelId in project graylog2-server by Graylog2.
the class ContentPackInstallationPersistenceServiceTest method findByContentPackId.
@Test
@MongoDBFixtures("ContentPackInstallationPersistenceServiceTest.json")
public void findByContentPackId() {
final ModelId id = ModelId.of("4e3d7025-881e-6870-da03-cafebabe0001");
final Set<ContentPackInstallation> contentPacks = persistenceService.findByContentPackId(id);
assertThat(contentPacks).hasSize(2).allSatisfy(contentPackInstallation -> assertThat(contentPackInstallation.contentPackId()).isEqualTo(id)).anySatisfy(contentPackInstallation -> assertThat(contentPackInstallation.id()).isEqualTo(new ObjectId("5b4c935b4b900a0000000001"))).anySatisfy(contentPackInstallation -> assertThat(contentPackInstallation.id()).isEqualTo(new ObjectId("5b4c935b4b900a0000000002")));
}
use of org.graylog2.contentpacks.model.ModelId in project graylog2-server by Graylog2.
the class ContentPackInstallationPersistenceServiceTest method findByContentPackIdAndRevision.
@Test
@MongoDBFixtures("ContentPackInstallationPersistenceServiceTest.json")
public void findByContentPackIdAndRevision() {
final ModelId id = ModelId.of("4e3d7025-881e-6870-da03-cafebabe0001");
final Set<ContentPackInstallation> contentPack = persistenceService.findByContentPackIdAndRevision(id, 1);
assertThat(contentPack).hasSize(1).anySatisfy(c -> assertThat(c.contentPackId()).isEqualTo(id));
}
use of org.graylog2.contentpacks.model.ModelId in project graylog2-server by Graylog2.
the class ContentPackResourceTest method notDeleteContentPack.
@Test
public void notDeleteContentPack() throws Exception {
final ModelId id = ModelId.of("1");
when(contentPackInstallations.size()).thenReturn(1);
when(contentPackInstallationPersistenceService.findByContentPackId(id)).thenReturn(contentPackInstallations);
boolean exceptionCalled = false;
try {
contentPackResource.deleteContentPack(id);
} catch (BadRequestException e) {
exceptionCalled = true;
}
assertThat(exceptionCalled).isEqualTo(true);
verify(contentPackInstallationPersistenceService, times(1)).findByContentPackId(id);
verify(contentPackPersistenceService, times(0)).deleteById(id);
when(contentPackInstallations.size()).thenReturn(1);
when(contentPackInstallationPersistenceService.findByContentPackIdAndRevision(id, 1)).thenReturn(contentPackInstallations);
exceptionCalled = false;
try {
contentPackResource.deleteContentPack(id, 1);
} catch (BadRequestException e) {
exceptionCalled = true;
}
assertThat(exceptionCalled).isEqualTo(true);
verify(contentPackInstallationPersistenceService, times(1)).findByContentPackIdAndRevision(id, 1);
verify(contentPackPersistenceService, times(0)).deleteByIdAndRevision(id, 1);
}
use of org.graylog2.contentpacks.model.ModelId 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);
}
Aggregations