Search in sources :

Example 1 with Response

use of jakarta.ws.rs.core.Response 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 2 with Response

use of jakarta.ws.rs.core.Response 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)

Example 3 with Response

use of jakarta.ws.rs.core.Response 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 4 with Response

use of jakarta.ws.rs.core.Response in project OpenGrok by OpenGrok.

the class ConfigurationControllerTest method testApplySetOptionInvalidInteger.

@Test
void testApplySetOptionInvalidInteger() {
    Response r = setValue("hitsPerPage", "abcd");
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), r.getStatus());
}
Also used : Response(jakarta.ws.rs.core.Response) Test(org.junit.jupiter.api.Test)

Example 5 with Response

use of jakarta.ws.rs.core.Response in project OpenGrok by OpenGrok.

the class ConfigurationControllerTest method testApplySetInvalidMethod.

@Test
void testApplySetInvalidMethod() {
    Response r = setValue("noMethodExists", "1000");
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), r.getStatus());
}
Also used : Response(jakarta.ws.rs.core.Response) Test(org.junit.jupiter.api.Test)

Aggregations

Response (jakarta.ws.rs.core.Response)51 Test (org.junit.jupiter.api.Test)43 ContainerRequestContext (jakarta.ws.rs.container.ContainerRequestContext)6 Path (java.nio.file.Path)3 TreeMap (java.util.TreeMap)3 Configuration (org.opengrok.indexer.configuration.Configuration)3 RuntimeEnvironment (org.opengrok.indexer.configuration.RuntimeEnvironment)3 Message (org.opengrok.indexer.web.messages.Message)3 AcceptedMessage (org.opengrok.indexer.web.messages.MessagesContainer.AcceptedMessage)3 ApiTask (org.opengrok.web.api.ApiTask)3 ApiTaskManager (org.opengrok.web.api.ApiTaskManager)3 File (java.io.File)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)1 HttpServletResponse (jakarta.servlet.http.HttpServletResponse)1 NotFoundException (jakarta.ws.rs.NotFoundException)1 WebApplicationException (jakarta.ws.rs.WebApplicationException)1 Client (jakarta.ws.rs.client.Client)1 Invocation (jakarta.ws.rs.client.Invocation)1 IOException (java.io.IOException)1