use of org.graylog2.contentpacks.model.entities.NativeEntity in project graylog2-server by Graylog2.
the class LookupTableFacadeTest method findExistingWithNoExistingEntity.
@Test
@MongoDBFixtures("LookupTableFacadeTest.json")
public void findExistingWithNoExistingEntity() {
final Entity entity = EntityV1.builder().id(ModelId.of("1")).type(ModelTypes.LOOKUP_TABLE_V1).data(objectMapper.convertValue(LookupTableEntity.create(ValueReference.of("some-name"), ValueReference.of("Title"), ValueReference.of("Description"), ValueReference.of("cache-id"), ValueReference.of("data-adapter-id"), ValueReference.of("Default single value"), ValueReference.of(LookupDefaultValue.Type.STRING), ValueReference.of("Default multi value"), ValueReference.of(LookupDefaultValue.Type.OBJECT)), JsonNode.class)).build();
final Optional<NativeEntity<LookupTableDto>> existingEntity = facade.findExisting(entity, Collections.emptyMap());
assertThat(existingEntity).isEmpty();
}
use of org.graylog2.contentpacks.model.entities.NativeEntity in project graylog2-server by Graylog2.
the class LookupTableFacadeTest method findExisting.
@Test
@MongoDBFixtures("LookupTableFacadeTest.json")
public void findExisting() {
final Entity entity = EntityV1.builder().id(ModelId.of("1")).type(ModelTypes.LOOKUP_TABLE_V1).data(objectMapper.convertValue(LookupTableEntity.create(ValueReference.of("http-dsv-no-cache"), ValueReference.of("HTTP DSV without Cache"), ValueReference.of("HTTP DSV without Cache"), ValueReference.of("cache-id"), ValueReference.of("data-adapter-id"), ValueReference.of("Default single value"), ValueReference.of(LookupDefaultValue.Type.STRING), ValueReference.of("Default multi value"), ValueReference.of(LookupDefaultValue.Type.OBJECT)), JsonNode.class)).build();
final NativeEntity<LookupTableDto> existingEntity = facade.findExisting(entity, Collections.emptyMap()).orElseThrow(AssertionError::new);
assertThat(existingEntity.descriptor().id()).isEqualTo(ModelId.of("5adf24dd4b900a0fdb4e530d"));
assertThat(existingEntity.descriptor().type()).isEqualTo(ModelTypes.LOOKUP_TABLE_V1);
assertThat(existingEntity.entity().name()).isEqualTo("http-dsv-no-cache");
assertThat(existingEntity.entity().title()).isEqualTo("HTTP DSV without Cache");
assertThat(existingEntity.entity().description()).isEqualTo("HTTP DSV without Cache");
assertThat(existingEntity.entity().dataAdapterId()).isEqualTo("5adf24a04b900a0fdb4e52c8");
assertThat(existingEntity.entity().cacheId()).isEqualTo("5adf24b24b900a0fdb4e52dd");
assertThat(existingEntity.entity().defaultSingleValue()).isEqualTo("Default single value");
assertThat(existingEntity.entity().defaultSingleValueType()).isEqualTo(LookupDefaultValue.Type.STRING);
assertThat(existingEntity.entity().defaultMultiValue()).isEqualTo("Default multi value");
assertThat(existingEntity.entity().defaultMultiValueType()).isEqualTo(LookupDefaultValue.Type.OBJECT);
}
use of org.graylog2.contentpacks.model.entities.NativeEntity in project graylog2-server by Graylog2.
the class SidecarCollectorFacadeTest method createNativeEntity.
@Test
public void createNativeEntity() {
final Entity entity = EntityV1.builder().id(ModelId.of("0")).type(ModelTypes.SIDECAR_COLLECTOR_V1).data(objectMapper.convertValue(SidecarCollectorEntity.create(ValueReference.of("filebeat"), ValueReference.of("exec"), ValueReference.of("linux"), ValueReference.of("/usr/lib/graylog-sidecar/filebeat"), ValueReference.of("-c %s"), ValueReference.of("test config -c %s"), ValueReference.of("")), JsonNode.class)).build();
assertThat(collectorService.count()).isEqualTo(0L);
final NativeEntity<Collector> nativeEntity = facade.createNativeEntity(entity, Collections.emptyMap(), Collections.emptyMap(), "username");
assertThat(collectorService.count()).isEqualTo(1L);
final Collector collector = collectorService.findByName("filebeat");
assertThat(collector).isNotNull();
final NativeEntityDescriptor expectedDescriptor = NativeEntityDescriptor.create(entity.id(), collector.id(), ModelTypes.SIDECAR_COLLECTOR_V1, collector.name(), false);
assertThat(nativeEntity.descriptor()).isEqualTo(expectedDescriptor);
assertThat(nativeEntity.entity()).isEqualTo(collector);
}
use of org.graylog2.contentpacks.model.entities.NativeEntity in project graylog2-server by Graylog2.
the class SidecarCollectorFacadeTest method findExisting.
@Test
@MongoDBFixtures("SidecarCollectorFacadeTest.json")
public void findExisting() {
final Entity entity = EntityV1.builder().id(ModelId.of("0")).type(ModelTypes.SIDECAR_COLLECTOR_V1).data(objectMapper.convertValue(SidecarCollectorEntity.create(ValueReference.of("filebeat"), ValueReference.of("exec"), ValueReference.of("linux"), ValueReference.of("/usr/lib/graylog-sidecar/filebeat"), ValueReference.of("-c %s"), ValueReference.of("test config -c %s"), ValueReference.of("")), JsonNode.class)).build();
final NativeEntity<Collector> existingCollector = facade.findExisting(entity, Collections.emptyMap()).orElseThrow(AssertionError::new);
final Collector collector = collectorService.findByName("filebeat");
assertThat(collector).isNotNull();
final NativeEntityDescriptor expectedDescriptor = NativeEntityDescriptor.create(entity.id(), collector.id(), ModelTypes.SIDECAR_COLLECTOR_V1, collector.name(), false);
assertThat(existingCollector.descriptor()).isEqualTo(expectedDescriptor);
assertThat(existingCollector.entity()).isEqualTo(collector);
}
use of org.graylog2.contentpacks.model.entities.NativeEntity 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);
}
Aggregations