use of org.graylog2.contentpacks.ContentPackInstallationPersistenceService in project graylog2-server by Graylog2.
the class ContentPackServiceTest method setUp.
@Before
public void setUp() throws Exception {
final ContentPackInstallationPersistenceService contentPackInstallationPersistenceService = contentPackInstallService;
final Set<ConstraintChecker> constraintCheckers = Collections.emptySet();
pluginMetaData = new HashSet<>();
outputFactories = new HashMap<>();
outputFactories2 = new HashMap<>();
final Map<ModelType, EntityWithExcerptFacade<?, ?>> entityFacades = ImmutableMap.of(ModelTypes.GROK_PATTERN_V1, new GrokPatternFacade(objectMapper, patternService), ModelTypes.STREAM_V1, new StreamFacade(objectMapper, streamService, streamRuleService, alertService, alarmCallbackConfigurationService, legacyAlertConditionMigration, indexSetService, userService), ModelTypes.OUTPUT_V1, new OutputFacade(objectMapper, outputService, pluginMetaData, outputFactories, outputFactories2));
contentPackService = new ContentPackService(contentPackInstallationPersistenceService, constraintCheckers, entityFacades);
Map<String, String> entityData = new HashMap<>(2);
entityData.put("name", "NAME");
entityData.put("pattern", "\\w");
grokPattern = GrokPattern.builder().pattern("\\w").name("NAME").build();
JsonNode jsonData = objectMapper.convertValue(entityData, JsonNode.class);
EntityV1 entityV1 = EntityV1.builder().id(ModelId.of("12345")).type(ModelTypes.GROK_PATTERN_V1).data(jsonData).build();
ImmutableSet<Entity> entities = ImmutableSet.of(entityV1);
NativeEntityDescriptor nativeEntityDescriptor = NativeEntityDescriptor.create(ModelId.of("12345"), "dead-beef1", ModelTypes.GROK_PATTERN_V1, "NAME");
nativeEntityDescriptors = ImmutableSet.of(nativeEntityDescriptor);
contentPack = ContentPackV1.builder().description("test").entities(entities).name("test").revision(1).summary("").vendor("").url(URI.create("http://graylog.com")).id(ModelId.of("dead-beef")).build();
contentPackInstallation = ContentPackInstallation.builder().contentPackId(ModelId.of("dead-beef")).contentPackRevision(1).entities(nativeEntityDescriptors).comment("Installed").parameters(ImmutableMap.copyOf(Collections.emptyMap())).createdAt(Instant.now()).createdBy("me").build();
}
use of org.graylog2.contentpacks.ContentPackInstallationPersistenceService in project graylog2-server by Graylog2.
the class ContentPackResourceTest method notDeleteContentPack.
@Test
public void notDeleteContentPack() throws Exception {
final ModelId id = ModelId.of("1");
when(contentPackInstallations.size()).thenReturn(1);
when(contentPackInstallationPersistenceService.findByContentPackId(id)).thenReturn(contentPackInstallations);
boolean exceptionCalled = false;
try {
contentPackResource.deleteContentPack(id);
} catch (BadRequestException e) {
exceptionCalled = true;
}
assertThat(exceptionCalled).isEqualTo(true);
verify(contentPackInstallationPersistenceService, times(1)).findByContentPackId(id);
verify(contentPackPersistenceService, times(0)).deleteById(id);
when(contentPackInstallations.size()).thenReturn(1);
when(contentPackInstallationPersistenceService.findByContentPackIdAndRevision(id, 1)).thenReturn(contentPackInstallations);
exceptionCalled = false;
try {
contentPackResource.deleteContentPack(id, 1);
} catch (BadRequestException e) {
exceptionCalled = true;
}
assertThat(exceptionCalled).isEqualTo(true);
verify(contentPackInstallationPersistenceService, times(1)).findByContentPackIdAndRevision(id, 1);
verify(contentPackPersistenceService, times(0)).deleteByIdAndRevision(id, 1);
}
use of org.graylog2.contentpacks.ContentPackInstallationPersistenceService in project graylog2-server by Graylog2.
the class CatalogResourceTest method setUp.
@Before
public void setUp() {
final ContentPackInstallationPersistenceService contentPackInstallationPersistenceService = mock(ContentPackInstallationPersistenceService.class);
final Set<ConstraintChecker> constraintCheckers = Collections.emptySet();
final Map<ModelType, EntityWithExcerptFacade<?, ?>> entityFacades = Collections.singletonMap(ModelType.of("test", "1"), mockEntityFacade);
contentPackService = new ContentPackService(contentPackInstallationPersistenceService, constraintCheckers, entityFacades);
catalogResource = new CatalogResource(contentPackService);
}
use of org.graylog2.contentpacks.ContentPackInstallationPersistenceService in project graylog2-server by Graylog2.
the class ContentPackResourceTest method setUp.
@Before
public void setUp() {
objectMapper = new ObjectMapperProvider().get();
objectMapper.setSubtypeResolver(new AutoValueSubtypeResolver());
contentPackResource = new PermittedTestResource(contentPackService, contentPackPersistenceService, contentPackInstallationPersistenceService);
}
use of org.graylog2.contentpacks.ContentPackInstallationPersistenceService in project graylog2-server by Graylog2.
the class ContentPackInstallationPersistenceServiceTest method setUp.
@Before
public void setUp() throws Exception {
final ObjectMapper objectMapper = new ObjectMapperProvider().get();
final MongoJackObjectMapperProvider mongoJackObjectMapperProvider = new MongoJackObjectMapperProvider(objectMapper);
persistenceService = new ContentPackInstallationPersistenceService(mongoJackObjectMapperProvider, mongodb.mongoConnection());
}
Aggregations