Search in sources :

Example 21 with ContentPack

use of org.graylog2.contentpacks.model.ContentPack 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();
}
Also used : NumberVisualizationConfigDTO(org.graylog.plugins.views.search.views.widgets.aggregation.NumberVisualizationConfigDTO) EntityConverter(org.graylog2.contentpacks.facades.dashboardV1.EntityConverter) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) PivotEntity(org.graylog2.contentpacks.model.entities.PivotEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) HashMap(java.util.HashMap) NamedType(com.fasterxml.jackson.databind.jsontype.NamedType) TimeHistogramConfigDTO(org.graylog.plugins.views.search.views.widgets.aggregation.TimeHistogramConfigDTO) AutoIntervalDTO(org.graylog.plugins.views.search.views.widgets.aggregation.AutoIntervalDTO) PivotSortConfig(org.graylog.plugins.views.search.views.widgets.aggregation.sort.PivotSortConfig) StreamFilter(org.graylog.plugins.views.search.filter.StreamFilter) QueryStringFilter(org.graylog.plugins.views.search.filter.QueryStringFilter) DashboardV1Facade(org.graylog2.contentpacks.facades.dashboardV1.DashboardV1Facade) URL(java.net.URL) AggregationConfigDTO(org.graylog.plugins.views.search.views.widgets.aggregation.AggregationConfigDTO) ViewDTO(org.graylog.plugins.views.search.views.ViewDTO) PasswordAlgorithmFactory(org.graylog2.security.PasswordAlgorithmFactory) MessageListConfigDTO(org.graylog.plugins.views.search.views.widgets.messagelist.MessageListConfigDTO) ContentPackV1(org.graylog2.contentpacks.model.ContentPackV1) UserImpl(org.graylog2.users.UserImpl) Permissions(org.graylog2.shared.security.Permissions) DashboardWidgetConverter(org.graylog2.contentpacks.facades.dashboardV1.DashboardWidgetConverter) BarVisualizationConfigDTO(org.graylog.plugins.views.search.views.widgets.aggregation.BarVisualizationConfigDTO) UserService(org.graylog2.shared.users.UserService) MongoJackObjectMapperProvider(org.graylog2.bindings.providers.MongoJackObjectMapperProvider) ContentPack(org.graylog2.contentpacks.model.ContentPack) OrFilter(org.graylog.plugins.views.search.filter.OrFilter) LineVisualizationConfigDTO(org.graylog.plugins.views.search.views.widgets.aggregation.LineVisualizationConfigDTO) PivotSort(org.graylog.plugins.views.search.searchtypes.pivot.PivotSort) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) StreamImpl(org.graylog2.streams.StreamImpl) ValueConfigDTO(org.graylog.plugins.views.search.views.widgets.aggregation.ValueConfigDTO) MongoConnection(org.graylog2.database.MongoConnection) PivotEntity(org.graylog2.contentpacks.model.entities.PivotEntity) Before(org.junit.Before)

Example 22 with ContentPack

use of org.graylog2.contentpacks.model.ContentPack in project graylog2-server by Graylog2.

the class ContentPackResourceTest method uploadContentPack.

@Test
public void uploadContentPack() throws Exception {
    final ContentPack contentPack = objectMapper.readValue(CONTENT_PACK, ContentPack.class);
    when(contentPackPersistenceService.filterMissingResourcesAndInsert(contentPack)).thenReturn(Optional.ofNullable(contentPack));
    final Response response = contentPackResource.createContentPack(contentPack);
    verify(contentPackPersistenceService, times(1)).filterMissingResourcesAndInsert(contentPack);
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.CREATED);
}
Also used : ContentPackResponse(org.graylog2.rest.models.system.contentpacks.responses.ContentPackResponse) Response(javax.ws.rs.core.Response) ContentPack(org.graylog2.contentpacks.model.ContentPack) Test(org.junit.Test)

Example 23 with ContentPack

use of org.graylog2.contentpacks.model.ContentPack in project graylog2-server by Graylog2.

the class ContentPackResourceTest method listAndLatest.

@Test
public void listAndLatest() throws Exception {
    final ContentPack contentPack = objectMapper.readValue(CONTENT_PACK, ContentPack.class);
    final Set<ContentPack> contentPacks = Collections.singleton(contentPack);
    final Map<ModelId, Map<Integer, ContentPackMetadata>> metaDataMap = Collections.emptyMap();
    final ContentPackList expectedList = ContentPackList.create(contentPacks.size(), contentPacks, metaDataMap);
    when(contentPackPersistenceService.loadAll()).thenReturn(Collections.singleton(contentPack));
    final ContentPackList contentPackList = contentPackResource.listContentPacks();
    verify(contentPackPersistenceService, times(1)).loadAll();
    assertThat(contentPackList).isEqualTo(expectedList);
    when(contentPackPersistenceService.loadAllLatest()).thenReturn(Collections.singleton(contentPack));
    final ContentPackList contentPackLatest = contentPackResource.listLatestContentPacks();
    verify(contentPackPersistenceService, times(1)).loadAll();
    assertThat(contentPackLatest).isEqualTo(expectedList);
}
Also used : ContentPackList(org.graylog2.rest.models.system.contentpacks.responses.ContentPackList) ContentPack(org.graylog2.contentpacks.model.ContentPack) Map(java.util.Map) ModelId(org.graylog2.contentpacks.model.ModelId) Test(org.junit.Test)

Example 24 with ContentPack

use of org.graylog2.contentpacks.model.ContentPack in project graylog2-server by Graylog2.

the class ContentPackInstallationPersistenceServiceTest method deleteById.

@Test
@MongoDBFixtures("ContentPackInstallationPersistenceServiceTest.json")
public void deleteById() {
    final ObjectId objectId = new ObjectId("5b4c935b4b900a0000000001");
    final int deletedContentPacks = persistenceService.deleteById(objectId);
    final Set<ContentPackInstallation> contentPacks = persistenceService.loadAll();
    assertThat(deletedContentPacks).isEqualTo(1);
    assertThat(contentPacks).hasSize(3).noneSatisfy(contentPack -> assertThat(contentPack.id()).isEqualTo(objectId));
}
Also used : ContentPackInstallation(org.graylog2.contentpacks.model.ContentPackInstallation) ObjectId(org.bson.types.ObjectId) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 25 with ContentPack

use of org.graylog2.contentpacks.model.ContentPack in project graylog2-server by Graylog2.

the class ContentPackServiceTest method getUninstallDetails.

@Test
public void getUninstallDetails() throws NotFoundException {
    /* Test will be uninstalled */
    when(contentPackInstallService.countInstallationOfEntityById(ModelId.of("dead-beef1"))).thenReturn((long) 1);
    ContentPackUninstallDetails expect = ContentPackUninstallDetails.create(nativeEntityDescriptors);
    ContentPackUninstallDetails result = contentPackService.getUninstallDetails(contentPack, contentPackInstallation);
    assertThat(result).isEqualTo(expect);
    /* Test nothing will be uninstalled */
    when(contentPackInstallService.countInstallationOfEntityById(ModelId.of("dead-beef1"))).thenReturn((long) 2);
    ContentPackUninstallDetails expectNon = ContentPackUninstallDetails.create(ImmutableSet.of());
    ContentPackUninstallDetails resultNon = contentPackService.getUninstallDetails(contentPack, contentPackInstallation);
    assertThat(resultNon).isEqualTo(expectNon);
}
Also used : ContentPackUninstallDetails(org.graylog2.contentpacks.model.ContentPackUninstallDetails) Test(org.junit.Test)

Aggregations

ContentPack (org.graylog2.contentpacks.model.ContentPack)21 Test (org.junit.Test)11 ContentPackInstallation (org.graylog2.contentpacks.model.ContentPackInstallation)10 HashMap (java.util.HashMap)7 ContentPackV1 (org.graylog2.contentpacks.model.ContentPackV1)7 ModelId (org.graylog2.contentpacks.model.ModelId)7 Timed (com.codahale.metrics.annotation.Timed)6 JsonView (com.fasterxml.jackson.annotation.JsonView)6 ApiOperation (io.swagger.annotations.ApiOperation)6 ApiResponses (io.swagger.annotations.ApiResponses)6 ImmutableSet (com.google.common.collect.ImmutableSet)5 URL (java.net.URL)5 Map (java.util.Map)5 NotFoundException (javax.ws.rs.NotFoundException)5 Path (javax.ws.rs.Path)5 ContentPackException (org.graylog2.contentpacks.exceptions.ContentPackException)5 Entity (org.graylog2.contentpacks.model.entities.Entity)5 ObjectId (org.bson.types.ObjectId)4 EntityWithExcerptFacade (org.graylog2.contentpacks.facades.EntityWithExcerptFacade)4 ContentPackUninstallation (org.graylog2.contentpacks.model.ContentPackUninstallation)4