use of org.graylog2.contentpacks.model.entities.EntityDescriptor in project graylog2-server by Graylog2.
the class ViewFacadeTest method itShouldCreateADTOFromAnEntity.
@Test
@MongoDBFixtures("ViewFacadeTest.json")
public void itShouldCreateADTOFromAnEntity() throws Exception {
final StreamImpl stream = new StreamImpl(Collections.emptyMap());
final Entity viewEntity = createViewEntity();
final Map<EntityDescriptor, Object> nativeEntities = new HashMap<>(1);
nativeEntities.put(EntityDescriptor.create(newStreamId, ModelTypes.STREAM_V1), stream);
final UserImpl fakeUser = new UserImpl(mock(PasswordAlgorithmFactory.class), new Permissions(ImmutableSet.of()), ImmutableMap.of("username", "testuser"));
when(userService.load("testuser")).thenReturn(fakeUser);
final NativeEntity<ViewDTO> nativeEntity = facade.createNativeEntity(viewEntity, Collections.emptyMap(), nativeEntities, "testuser");
assertThat(nativeEntity.descriptor().title()).isEqualTo("title");
assertThat(nativeEntity.descriptor().type()).isEqualTo(ModelTypes.SEARCH_V1);
Optional<ViewDTO> resultedView = viewService.get(nativeEntity.descriptor().id().id());
assertThat(resultedView).isPresent();
Optional<Search> search = searchDbService.get(resultedView.get().searchId());
assertThat(search).isPresent();
final Query query = search.get().queries().iterator().next();
assertThat(query.filter()).isNotNull();
assertThat(query.filter().filters()).isNotEmpty();
final StreamFilter streamFilter = (StreamFilter) query.filter().filters().iterator().next();
assertThat(streamFilter.streamId()).doesNotMatch(newStreamId);
}
use of org.graylog2.contentpacks.model.entities.EntityDescriptor in project graylog2-server by Graylog2.
the class ViewFacadeTest method itShouldCreateAViewEntity.
@Test
@MongoDBFixtures("ViewFacadeTest.json")
public void itShouldCreateAViewEntity() {
final ViewDTO viewDTO = viewService.get(viewId).orElseThrow(() -> new NotFoundException("Missing view with id: " + viewId));
final EntityDescriptor searchDescriptor = EntityDescriptor.create(viewDTO.id(), ModelTypes.SEARCH_V1);
final EntityDescriptor streamDescriptor = EntityDescriptor.create(streamId, ModelTypes.STREAM_V1);
final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(searchDescriptor, streamDescriptor);
final Optional<Entity> optionalEntity = facade.exportEntity(searchDescriptor, entityDescriptorIds);
assertThat(optionalEntity).isPresent();
final Entity entity = optionalEntity.get();
assertThat(entity).isInstanceOf(EntityV1.class);
final EntityV1 entityV1 = (EntityV1) entity;
assertThat(entityV1.id()).isEqualTo(ModelId.of(entityDescriptorIds.get(searchDescriptor).orElse(null)));
assertThat(entityV1.type()).isEqualTo(ModelTypes.SEARCH_V1);
final ViewEntity viewEntity = objectMapper.convertValue(entityV1.data(), ViewEntity.class);
assertThat(viewEntity.title().asString()).isEqualTo(viewDTO.title());
assertThat(viewEntity.type().toString()).isEqualTo(ViewDTO.Type.SEARCH.toString());
assertThat(viewEntity.search().queries().size()).isEqualTo(1);
final QueryEntity queryEntity = viewEntity.search().queries().iterator().next();
assertThat(queryEntity.filter().filters().size()).isEqualTo(1);
final StreamFilter filter = (StreamFilter) queryEntity.filter().filters().iterator().next();
assertThat(filter.streamId()).doesNotMatch(streamId);
}
use of org.graylog2.contentpacks.model.entities.EntityDescriptor in project graylog2-server by Graylog2.
the class ViewFacadeTest method itShouldResolveDependencyForCreation.
@Test
@MongoDBFixtures("ViewFacadeTest.json")
public void itShouldResolveDependencyForCreation() {
final EntityDescriptor streamEntityDescriptor = EntityDescriptor.create(streamId, ModelTypes.STREAM_V1);
final EntityDescriptor viewEntityDescriptor = EntityDescriptor.create(viewId, ModelTypes.SEARCH_V1);
Graph graph = facade.resolveNativeEntity(viewEntityDescriptor);
assertThat(graph.nodes().toArray()).contains(streamEntityDescriptor);
}
use of org.graylog2.contentpacks.model.entities.EntityDescriptor in project graylog2-server by Graylog2.
the class PipelineFacadeTest method collectEntity.
@Test
@MongoDBFixtures("PipelineFacadeTest/pipelines.json")
public void collectEntity() {
final EntityDescriptor descriptor = EntityDescriptor.create("5a85c4854b900afd5d662be3", ModelTypes.PIPELINE_V1);
final EntityDescriptor streamDescriptor = EntityDescriptor.create("5adf23894b900a0fdb4e517d", ModelTypes.STREAM_V1);
final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor, streamDescriptor);
final Optional<Entity> collectedEntity = facade.exportEntity(descriptor, entityDescriptorIds);
assertThat(collectedEntity).isPresent().containsInstanceOf(EntityV1.class);
final EntityV1 entity = (EntityV1) collectedEntity.orElseThrow(AssertionError::new);
assertThat(entity.id()).isEqualTo(ModelId.of(entityDescriptorIds.get(descriptor).orElse(null)));
assertThat(entity.type()).isEqualTo(ModelTypes.PIPELINE_V1);
final PipelineEntity pipelineEntity = objectMapper.convertValue(entity.data(), PipelineEntity.class);
assertThat(pipelineEntity.title()).isEqualTo(ValueReference.of("Test"));
assertThat(pipelineEntity.description()).isEqualTo(ValueReference.of("Description"));
assertThat(pipelineEntity.source().asString(Collections.emptyMap())).startsWith("pipeline \"Test\"");
assertThat(pipelineEntity.connectedStreams()).containsOnly(ValueReference.of(entityDescriptorIds.get(streamDescriptor).orElse(null)));
}
use of org.graylog2.contentpacks.model.entities.EntityDescriptor in project graylog2-server by Graylog2.
the class PipelineFacadeTest method exportNativeEntity.
@Test
@MongoDBFixtures("PipelineFacadeTest/pipelines.json")
public void exportNativeEntity() {
final EntityDescriptor descriptor = EntityDescriptor.create("5a85c4854b900afd5d662be3", ModelTypes.PIPELINE_V1);
final EntityDescriptor streamDescriptor = EntityDescriptor.create("5adf23894b900a0fdb4e517d", ModelTypes.STREAM_V1);
final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor, streamDescriptor);
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.PIPELINE_V1);
final EntityV1 entityV1 = (EntityV1) entity;
final PipelineEntity pipelineEntity = objectMapper.convertValue(entityV1.data(), PipelineEntity.class);
assertThat(pipelineEntity.title()).isEqualTo(ValueReference.of("Test"));
assertThat(pipelineEntity.description()).isEqualTo(ValueReference.of("Description"));
assertThat(pipelineEntity.source().asString(Collections.emptyMap())).startsWith("pipeline \"Test\"");
assertThat(pipelineEntity.connectedStreams()).containsOnly(ValueReference.of(entityDescriptorIds.get(streamDescriptor).orElse(null)));
}
Aggregations