Search in sources :

Example 21 with Version

use of org.graylog2.plugin.Version in project graylog2-server by Graylog2.

the class PluginVersionConstraintCheckerTest method checkConstraints.

@Test
public void checkConstraints() {
    final TestPluginMetaData pluginMetaData = new TestPluginMetaData();
    final PluginVersionConstraintChecker constraintChecker = new PluginVersionConstraintChecker(Collections.singleton(pluginMetaData));
    final GraylogVersionConstraint graylogVersionConstraint = GraylogVersionConstraint.builder().version("^2.0.0").build();
    final PluginVersionConstraint pluginVersionConstraint = PluginVersionConstraint.builder().pluginId("unique-id").version("^1.0.0").build();
    final ImmutableSet<Constraint> requiredConstraints = ImmutableSet.of(graylogVersionConstraint, pluginVersionConstraint);
    assertThat(constraintChecker.checkConstraints(requiredConstraints).stream().allMatch(c -> c.fulfilled())).isTrue();
}
Also used : PluginVersionConstraint(org.graylog2.contentpacks.model.constraints.PluginVersionConstraint) GraylogVersionConstraint(org.graylog2.contentpacks.model.constraints.GraylogVersionConstraint) PluginVersionConstraint(org.graylog2.contentpacks.model.constraints.PluginVersionConstraint) Constraint(org.graylog2.contentpacks.model.constraints.Constraint) GraylogVersionConstraint(org.graylog2.contentpacks.model.constraints.GraylogVersionConstraint) Test(org.junit.Test)

Example 22 with Version

use of org.graylog2.plugin.Version in project graylog2-server by Graylog2.

the class PluginVersionConstraintCheckerTest method checkConstraintsFails.

@Test
public void checkConstraintsFails() {
    final TestPluginMetaData pluginMetaData = new TestPluginMetaData();
    final PluginVersionConstraintChecker constraintChecker = new PluginVersionConstraintChecker(Collections.singleton(pluginMetaData));
    final GraylogVersionConstraint graylogVersionConstraint = GraylogVersionConstraint.builder().version("^2.0.0").build();
    final PluginVersionConstraint pluginVersionConstraint = PluginVersionConstraint.builder().pluginId("unique-id").version("^2.0.0").build();
    final ImmutableSet<Constraint> requiredConstraints = ImmutableSet.of(graylogVersionConstraint, pluginVersionConstraint);
    assertThat(constraintChecker.checkConstraints(requiredConstraints).stream().allMatch(c -> !c.fulfilled())).isTrue();
}
Also used : PluginVersionConstraint(org.graylog2.contentpacks.model.constraints.PluginVersionConstraint) GraylogVersionConstraint(org.graylog2.contentpacks.model.constraints.GraylogVersionConstraint) PluginVersionConstraint(org.graylog2.contentpacks.model.constraints.PluginVersionConstraint) Constraint(org.graylog2.contentpacks.model.constraints.Constraint) GraylogVersionConstraint(org.graylog2.contentpacks.model.constraints.GraylogVersionConstraint) Test(org.junit.Test)

Example 23 with Version

use of org.graylog2.plugin.Version in project graylog2-server by Graylog2.

the class SyslogCodecTest method testDecodeUnstructuredWithFullMessage.

@Test
public void testDecodeUnstructuredWithFullMessage() throws Exception {
    when(configuration.getBoolean(SyslogCodec.CK_STORE_FULL_MESSAGE)).thenReturn(true);
    final Message message = codec.decode(buildRawMessage(UNSTRUCTURED));
    assertNotNull(message);
    assertEquals("c4dc57ba1ebb syslog-ng[7208]: syslog-ng starting up; version='3.5.3'", message.getMessage());
    assertEquals(new DateTime(YEAR + "-10-21T12:09:37"), message.getField("timestamp"));
    assertEquals("c4dc57ba1ebb", message.getField("source"));
    assertEquals(5, message.getField("level"));
    assertEquals("syslogd", message.getField("facility"));
    assertEquals(UNSTRUCTURED, message.getField("full_message"));
    assertEquals(5, message.getField("facility_num"));
}
Also used : RawMessage(org.graylog2.plugin.journal.RawMessage) Message(org.graylog2.plugin.Message) ZonedDateTime(java.time.ZonedDateTime) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 24 with Version

use of org.graylog2.plugin.Version in project graylog2-server by Graylog2.

the class GelfCodecTest method decodeFailsWithEmptyHost.

@Test
public void decodeFailsWithEmptyHost() throws Exception {
    final String json = "{" + "\"version\": \"1.1\"," + "\"host\": \"\"," + "\"short_message\": \"A short message that helps you identify what is going on\"" + "}";
    final RawMessage rawMessage = new RawMessage(json.getBytes(StandardCharsets.UTF_8));
    assertThatIllegalArgumentException().isThrownBy(() -> codec.decode(rawMessage)).withNoCause().withMessageMatching("GELF message <[0-9a-f-]+> has empty mandatory \"host\" field.");
}
Also used : RawMessage(org.graylog2.plugin.journal.RawMessage) Test(org.junit.Test)

Example 25 with Version

use of org.graylog2.plugin.Version in project graylog2-server by Graylog2.

the class GelfCodecTest method decodeFailsWithWrongTypeForHost.

@Test
public void decodeFailsWithWrongTypeForHost() throws Exception {
    final String json = "{" + "\"version\": \"1.1\"," + "\"host\": 42," + "\"short_message\": \"A short message that helps you identify what is going on\"" + "}";
    final RawMessage rawMessage = new RawMessage(json.getBytes(StandardCharsets.UTF_8));
    assertThatIllegalArgumentException().isThrownBy(() -> codec.decode(rawMessage)).withNoCause().withMessageMatching("GELF message <[0-9a-f-]+> has invalid \"host\": 42");
}
Also used : RawMessage(org.graylog2.plugin.journal.RawMessage) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)29 RawMessage (org.graylog2.plugin.journal.RawMessage)28 Message (org.graylog2.plugin.Message)15 SearchVersion (org.graylog2.storage.SearchVersion)13 JsonNode (com.fasterxml.jackson.databind.JsonNode)7 IOException (java.io.IOException)5 Inject (javax.inject.Inject)5 DateTime (org.joda.time.DateTime)5 ZonedDateTime (java.time.ZonedDateTime)4 Map (java.util.Map)4 Optional (java.util.Optional)4 Constraint (org.graylog2.contentpacks.model.constraints.Constraint)4 GraylogVersionConstraint (org.graylog2.contentpacks.model.constraints.GraylogVersionConstraint)4 PluginVersionConstraint (org.graylog2.contentpacks.model.constraints.PluginVersionConstraint)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)3 ApiOperation (io.swagger.annotations.ApiOperation)3 URI (java.net.URI)3 HashSet (java.util.HashSet)3