use of org.graylog2.contentpacks.model.entities.QueryEntity 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.QueryEntity in project graylog2-server by Graylog2.
the class ViewFacadeTest method createViewEntity.
private EntityV1 createViewEntity() throws Exception {
final QueryEntity query = QueryEntity.builder().id("dead-beef").timerange(KeywordRange.create("last 5 minutes", "Etc/UTC")).filter(OrFilter.or(StreamFilter.ofId(newStreamId))).query(ElasticsearchQueryString.of("author: Mara Jade")).build();
final SearchEntity searchEntity = SearchEntity.builder().queries(ImmutableSet.of(query)).parameters(ImmutableSet.of()).requires(ImmutableMap.of()).createdAt(DateTime.now(DateTimeZone.UTC)).build();
final ViewStateEntity viewStateEntity = ViewStateEntity.builder().fields(ImmutableSet.of()).titles(Titles.empty()).widgets(ImmutableSet.of()).widgetMapping(ImmutableMap.of()).widgetPositions(ImmutableMap.of()).formatting(FormattingSettings.builder().highlighting(ImmutableSet.of()).build()).displayModeSettings(DisplayModeSettings.empty()).build();
final ViewEntity entity = ViewEntity.builder().type(ViewEntity.Type.SEARCH).summary(ValueReference.of("summary")).title(ValueReference.of("title")).description(ValueReference.of("description")).search(searchEntity).properties(ImmutableSet.of()).requires(ImmutableMap.of()).state(ImmutableMap.of(newViewId, viewStateEntity)).createdAt(DateTime.now(DateTimeZone.UTC)).build();
return EntityV1.builder().id(ModelId.of("1")).type(ModelTypes.SEARCH_V1).data(objectMapper.convertValue(entity, JsonNode.class)).build();
}
Aggregations