use of org.graylog2.contentpacks.model.entities.NativeEntity in project graylog2-server by Graylog2.
the class InputFacadeTest method createNativeEntity.
@Test
@Ignore("Doesn't work without massive amount of mocks")
public void createNativeEntity() {
final Map<String, Object> configuration = new HashMap<>();
configuration.put("override_source", null);
configuration.put("recv_buffer_size", 262144);
configuration.put("bind_address", "127.0.0.1");
configuration.put("port", 5555);
configuration.put("number_worker_threads", 8);
final Entity entity = EntityV1.builder().id(ModelId.of("5acc84f84b900a4ff290d9a7")).type(ModelTypes.INPUT_V1).data(objectMapper.convertValue(InputEntity.create(ValueReference.of("Local Raw UDP"), ReferenceMapUtils.toReferenceMap(configuration), Collections.emptyMap(), ValueReference.of("org.graylog2.inputs.raw.udp.RawUDPInput"), ValueReference.of(false), Collections.emptyList()), JsonNode.class)).build();
final NativeEntity<InputWithExtractors> nativeEntity = facade.createNativeEntity(entity, Collections.emptyMap(), Collections.emptyMap(), "username");
final InputWithExtractors inputWithExtractors = nativeEntity.entity();
final Input savedInput = inputWithExtractors.input();
final String savedId = savedInput.getId();
assertThat(nativeEntity.descriptor()).isEqualTo(EntityDescriptor.create(savedId, ModelTypes.INPUT_V1));
assertThat(savedInput.getTitle()).isEqualTo("Local Raw UDP");
assertThat(savedInput.getType()).isEqualTo("org.graylog2.inputs.raw.udp.RawUDPInput");
assertThat(savedInput.isGlobal()).isFalse();
assertThat(savedInput.getContentPack()).isNull();
}
use of org.graylog2.contentpacks.model.entities.NativeEntity in project graylog2-server by Graylog2.
the class DashboardV1FacadeTest method setUp.
@Before
public void setUp() throws IOException {
objectMapper.registerSubtypes(new NamedType(AggregationConfigDTO.class, AggregationConfigDTO.NAME));
objectMapper.registerSubtypes(new NamedType(MessageListConfigDTO.class, MessageListConfigDTO.NAME));
objectMapper.registerSubtypes(new NamedType(LineVisualizationConfigDTO.class, LineVisualizationConfigDTO.NAME));
objectMapper.registerSubtypes(new NamedType(BarVisualizationConfigDTO.class, BarVisualizationConfigDTO.NAME));
objectMapper.registerSubtypes(new NamedType(NumberVisualizationConfigDTO.class, NumberVisualizationConfigDTO.NAME));
objectMapper.registerSubtypes(new NamedType(TimeHistogramConfigDTO.class, TimeHistogramConfigDTO.NAME));
objectMapper.registerSubtypes(new NamedType(ValueConfigDTO.class, ValueConfigDTO.NAME));
objectMapper.registerSubtypes(new NamedType(PivotSortConfig.class, PivotSortConfig.Type));
objectMapper.registerSubtypes(new NamedType(PivotEntity.class, PivotEntity.NAME));
objectMapper.registerSubtypes(new NamedType(PivotSort.class, PivotSort.Type));
objectMapper.registerSubtypes(new NamedType(OrFilter.class, OrFilter.NAME));
objectMapper.registerSubtypes(new NamedType(StreamFilter.class, StreamFilter.NAME));
objectMapper.registerSubtypes(new NamedType(QueryStringFilter.class, QueryStringFilter.NAME));
objectMapper.registerSubtypes(new NamedType(AutoIntervalDTO.class, AutoIntervalDTO.type));
final MongoConnection mongoConnection = mongodb.mongoConnection();
final MongoJackObjectMapperProvider mapper = new MongoJackObjectMapperProvider(objectMapper);
searchDbService = new ViewFacadeTest.TestSearchDBService(mongoConnection, mapper);
viewService = new ViewFacadeTest.TestViewService(mongoConnection, mapper, null);
viewSummaryService = new ViewFacadeTest.TestViewSummaryService(mongoConnection, mapper);
userService = mock(UserService.class);
final UserImpl fakeUser = new UserImpl(mock(PasswordAlgorithmFactory.class), new Permissions(ImmutableSet.of()), ImmutableMap.of("username", "testuser"));
when(userService.load("testuser")).thenReturn(fakeUser);
final DashboardWidgetConverter dashboardWidgetConverter = new DashboardWidgetConverter();
final EntityConverter entityConverter = new EntityConverter(dashboardWidgetConverter);
facade = new DashboardV1Facade(objectMapper, searchDbService, entityConverter, viewService, viewSummaryService, userService);
final URL resourceUrl = Resources.getResource(DashboardV1Facade.class, "content-pack-dashboard-v1.json");
final ContentPack contentPack = objectMapper.readValue(resourceUrl, ContentPack.class);
assertThat(contentPack).isInstanceOf(ContentPackV1.class);
final ContentPackV1 contentPackV1 = (ContentPackV1) contentPack;
final Entity entity = contentPackV1.entities().iterator().next();
final StreamImpl stream = new StreamImpl(Collections.emptyMap());
final Map<EntityDescriptor, Object> nativeEntities = new HashMap<>(1);
nativeEntities.put(EntityDescriptor.create("58b3d55a-51ad-4b3e-865c-85776016a151", ModelTypes.STREAM_V1), stream);
final NativeEntity<ViewDTO> nativeEntity = facade.createNativeEntity(entity, ImmutableMap.of(), nativeEntities, "testuser");
assertThat(nativeEntity).isNotNull();
viewDTO = nativeEntity.entity();
}
use of org.graylog2.contentpacks.model.entities.NativeEntity in project graylog2-server by Graylog2.
the class LookupDataAdapterFacadeTest method findExistingWithNoExistingEntity.
@Test
@MongoDBFixtures("LookupDataAdapterFacadeTest.json")
public void findExistingWithNoExistingEntity() {
final Entity entity = EntityV1.builder().id(ModelId.of("1")).type(ModelTypes.LOOKUP_ADAPTER_V1).data(objectMapper.convertValue(LookupDataAdapterEntity.create(ValueReference.of("some-name"), ValueReference.of("Some title"), ValueReference.of("Some description"), ReferenceMapUtils.toReferenceMap(Collections.emptyMap())), JsonNode.class)).build();
final Optional<NativeEntity<DataAdapterDto>> 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 LookupDataAdapterFacadeTest method findExisting.
@Test
@MongoDBFixtures("LookupDataAdapterFacadeTest.json")
public void findExisting() {
final Entity entity = EntityV1.builder().id(ModelId.of("1")).type(ModelTypes.LOOKUP_ADAPTER_V1).data(objectMapper.convertValue(LookupDataAdapterEntity.create(ValueReference.of("http-dsv"), ValueReference.of("HTTP DSV"), ValueReference.of("HTTP DSV"), ReferenceMapUtils.toReferenceMap(Collections.emptyMap())), JsonNode.class)).build();
final NativeEntity<DataAdapterDto> nativeEntity = facade.findExisting(entity, Collections.emptyMap()).orElseThrow(AssertionError::new);
assertThat(nativeEntity.descriptor().id()).isEqualTo(ModelId.of("5adf24a04b900a0fdb4e52c8"));
assertThat(nativeEntity.descriptor().type()).isEqualTo(ModelTypes.LOOKUP_ADAPTER_V1);
assertThat(nativeEntity.entity().name()).isEqualTo("http-dsv");
assertThat(nativeEntity.entity().title()).isEqualTo("HTTP DSV");
assertThat(nativeEntity.entity().description()).isEqualTo("HTTP DSV");
}
use of org.graylog2.contentpacks.model.entities.NativeEntity in project graylog2-server by Graylog2.
the class PipelineRuleFacadeTest method findExisting.
@Test
@MongoDBFixtures("PipelineRuleFacadeTest.json")
public void findExisting() {
final Entity entity = EntityV1.builder().id(ModelId.of("debug")).type(ModelTypes.PIPELINE_RULE_V1).data(objectMapper.convertValue(PipelineRuleEntity.create(ValueReference.of("debug"), ValueReference.of("Debug"), ValueReference.of("rule \"debug\"\nwhen\n true\nthen\n debug($message.message);\nend")), JsonNode.class)).build();
final NativeEntity<RuleDao> existingRule = facade.findExisting(entity, Collections.emptyMap()).orElseThrow(AssertionError::new);
assertThat(existingRule.descriptor().id()).isEqualTo(ModelId.of("5adf25034b900a0fdb4e5338"));
assertThat(existingRule.descriptor().type()).isEqualTo(ModelTypes.PIPELINE_RULE_V1);
assertThat(existingRule.entity().title()).isEqualTo("debug");
assertThat(existingRule.entity().description()).isEqualTo("Debug");
assertThat(existingRule.entity().source()).startsWith("rule \"debug\"\n");
}
Aggregations