Search in sources :

Example 1 with Message

use of org.opengrok.indexer.web.messages.Message in project OpenGrok by OpenGrok.

the class MessagesControllerTest method addMessageWithInvalidLevel.

@Test
public void addMessageWithInvalidLevel() throws JsonProcessingException {
    // Construct correct Message object first.
    Message msg = new Message("message with broken message level", Collections.singleton(MessagesContainer.MESSAGES_MAIN_PAGE_TAG), Message.MessageLevel.INFO, Duration.ofMinutes(10));
    // Convert it to JSON string and replace the messageLevel value.
    ObjectMapper objectMapper = new ObjectMapper();
    final String invalidMessageLevel = "invalid";
    String msgAsString = objectMapper.writeValueAsString(msg);
    msgAsString = msgAsString.replaceAll(Message.MessageLevel.INFO.toString(), invalidMessageLevel);
    assertTrue(msgAsString.contains(invalidMessageLevel));
    // Finally, send the request as JSON string.
    Response r = target("messages").request(MediaType.APPLICATION_JSON_TYPE).post(Entity.json(msgAsString));
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), r.getStatus());
}
Also used : Response(jakarta.ws.rs.core.Response) AcceptedMessage(org.opengrok.indexer.web.messages.MessagesContainer.AcceptedMessage) Message(org.opengrok.indexer.web.messages.Message) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test)

Example 2 with Message

use of org.opengrok.indexer.web.messages.Message in project OpenGrok by OpenGrok.

the class MessagesControllerTest method addMessage.

private void addMessage(String text, String... tags) {
    if (tags == null || tags.length == 0) {
        tags = new String[] { MessagesContainer.MESSAGES_MAIN_PAGE_TAG };
    }
    Message m = new Message(text, new HashSet<>(Arrays.asList(tags)), Message.MessageLevel.INFO, Duration.ofMinutes(10));
    target("messages").request().post(Entity.json(m));
}
Also used : AcceptedMessage(org.opengrok.indexer.web.messages.MessagesContainer.AcceptedMessage) Message(org.opengrok.indexer.web.messages.Message)

Example 3 with Message

use of org.opengrok.indexer.web.messages.Message in project OpenGrok by OpenGrok.

the class MessagesControllerTest method removeMessageTest.

@Test
public void removeMessageTest() {
    env.addMessage(new Message("test", Collections.singleton(MessagesContainer.MESSAGES_MAIN_PAGE_TAG), Message.MessageLevel.INFO, Duration.ofMinutes(10)));
    assertFalse(env.getMessages().isEmpty());
    removeMessages(MessagesContainer.MESSAGES_MAIN_PAGE_TAG);
    assertTrue(env.getMessages().isEmpty());
}
Also used : AcceptedMessage(org.opengrok.indexer.web.messages.MessagesContainer.AcceptedMessage) Message(org.opengrok.indexer.web.messages.Message) Test(org.junit.jupiter.api.Test)

Example 4 with Message

use of org.opengrok.indexer.web.messages.Message in project OpenGrok by OpenGrok.

the class MessagesControllerTest method addMessageNegativeDurationTest.

@Test
public void addMessageNegativeDurationTest() throws Exception {
    Message m = new Message("text", Collections.singleton("test"), Message.MessageLevel.INFO, Duration.ofMinutes(1));
    setDuration(m, Duration.ofMinutes(-10));
    Response r = target("messages").request().post(Entity.json(m));
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), r.getStatus());
}
Also used : Response(jakarta.ws.rs.core.Response) AcceptedMessage(org.opengrok.indexer.web.messages.MessagesContainer.AcceptedMessage) Message(org.opengrok.indexer.web.messages.Message) Test(org.junit.jupiter.api.Test)

Example 5 with Message

use of org.opengrok.indexer.web.messages.Message in project OpenGrok by OpenGrok.

the class MessagesControllerTest method addEmptyMessageTest.

@Test
public void addEmptyMessageTest() throws Exception {
    Message m = new Message("text", Collections.singleton("test"), Message.MessageLevel.INFO, Duration.ofMinutes(1));
    setText(m, "");
    Response r = target("messages").request().post(Entity.json(m));
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), r.getStatus());
}
Also used : Response(jakarta.ws.rs.core.Response) AcceptedMessage(org.opengrok.indexer.web.messages.MessagesContainer.AcceptedMessage) Message(org.opengrok.indexer.web.messages.Message) Test(org.junit.jupiter.api.Test)

Aggregations

Message (org.opengrok.indexer.web.messages.Message)5 AcceptedMessage (org.opengrok.indexer.web.messages.MessagesContainer.AcceptedMessage)5 Test (org.junit.jupiter.api.Test)4 Response (jakarta.ws.rs.core.Response)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1