use of org.graylog2.contentpacks.model.ContentPackV1 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.ContentPackV1 in project graylog2-server by Graylog2.
the class V20191219090834_AddSourcesPageTest method upgradeSuccessfully.
@Test
public void upgradeSuccessfully() throws IOException {
final URL contentPackURL = V20191219090834_AddSourcesPage.class.getResource("V20191219090834_AddSourcesPage_Content_Pack.json");
final ContentPack contentPack = ContentPackV1.builder().id(ModelId.of("04fcf179-49e0-4e8f-9c02-0ff13062efbe")).summary("summary").revision(1).name("Sources Page").description("description").vendor("").url(URI.create("http://graylog.com")).entities(ImmutableSet.of()).build();
final ContentPackInstallation contentPackInstallation = ContentPackInstallation.builder().contentPackId(contentPack.id()).contentPackRevision(1).parameters(ImmutableMap.of()).entities(ImmutableSet.of()).comment("Comment").createdAt(Instant.now()).createdBy("admin").build();
when(configService.get(V20191219090834_AddSourcesPage.MigrationCompleted.class)).thenReturn(null);
when(contentPackPersistenceService.insert(contentPack)).thenReturn(Optional.ofNullable(contentPack));
when(contentPackService.installContentPack(contentPack, Collections.emptyMap(), "Add Sources Page", "admin")).thenReturn(contentPackInstallation);
when(objectMapper.readValue(contentPackURL, ContentPack.class)).thenReturn(contentPack);
migration.upgrade();
verify(contentPackService).installContentPack(contentPack, Collections.emptyMap(), "Add Sources Page", "admin");
verify(configService).write(V20191219090834_AddSourcesPage.MigrationCompleted.create("04fcf179-49e0-4e8f-9c02-0ff13062efbe"));
}
Aggregations