Search in sources :

Example 36 with HttpHeaders

use of javax.ws.rs.core.HttpHeaders in project com-liferay-apio-architect by liferay.

the class JSONLDDocumentationMessageMapperTest method testJSONLDDocumentationMessageMapper.

@Test
public void testJSONLDDocumentationMessageMapper() {
    HttpHeaders httpHeaders = Mockito.mock(HttpHeaders.class);
    JsonObject jsonObject = MockDocumentationWriter.write(httpHeaders, _documentationMessageMapper);
    Conditions.Builder builder = new Conditions.Builder();
    Conditions conditions = builder.where("@context", IS_A_LINK_TO_HYDRA_PROFILE).where("@id", is(aJsonString(equalTo("http://api.example.com/doc/")))).where("@type", is(aJsonString(equalTo("ApiDocumentation")))).where("description", is(aJsonString(equalTo("Description")))).where("title", is(aJsonString(equalTo("Title")))).build();
    assertThat(jsonObject, is(aJsonObjectWith(conditions)));
}
Also used : HttpHeaders(javax.ws.rs.core.HttpHeaders) JsonObject(com.google.gson.JsonObject) Conditions(com.liferay.apio.architect.test.util.json.Conditions) Test(org.junit.Test)

Example 37 with HttpHeaders

use of javax.ws.rs.core.HttpHeaders in project com-liferay-apio-architect by liferay.

the class JSONLDSingleModelMessageMapperTest method testJSONLDSingleModelMessageMapper.

@Test
public void testJSONLDSingleModelMessageMapper() {
    HttpHeaders httpHeaders = Mockito.mock(HttpHeaders.class);
    JsonObject jsonObject = MockSingleModelWriter.write(httpHeaders, _singleModelMessageMapper);
    assertThat(jsonObject, is(aRootElementJsonObjectWithId("first", true, false)));
}
Also used : HttpHeaders(javax.ws.rs.core.HttpHeaders) JsonObject(com.google.gson.JsonObject) Test(org.junit.Test)

Example 38 with HttpHeaders

use of javax.ws.rs.core.HttpHeaders in project com-liferay-apio-architect by liferay.

the class MockSingleModelWriter method write.

/**
 * Writes a {@link RootModel}, with the hierarchy of embedded models and
 * multiple fields.
 *
 * @param httpHeaders the request's {@code HttpHeaders}
 * @param singleModelMessageMapper the {@link SingleModelMessageMapper} to
 *        use for writing the JSON object
 */
public static JsonObject write(HttpHeaders httpHeaders, SingleModelMessageMapper<RootModel> singleModelMessageMapper) {
    RequestInfo requestInfo = getRequestInfo(httpHeaders);
    Operation deleteOperation = new Operation(DELETE, "delete-operation");
    Operation putOperation = new Operation(createForm("u", "r"), PUT, "update-operation");
    SingleModel<RootModel> singleModel = new SingleModel<>(() -> "first", "root", asList(deleteOperation, putOperation));
    SingleModelWriter<RootModel> singleModelWriter = SingleModelWriter.create(builder -> builder.singleModel(singleModel).modelMessageMapper(singleModelMessageMapper).pathFunction(MockWriterUtil::identifierToPath).resourceNameFunction(__ -> Optional.of("models")).representorFunction(MockWriterUtil::getRepresentorOptional).requestInfo(requestInfo).singleModelFunction(MockWriterUtil::getSingleModel).build());
    Optional<String> optional = singleModelWriter.write();
    if (!optional.isPresent()) {
        throw new AssertionError("Writer failed to write");
    }
    return new Gson().fromJson(optional.get(), JsonObject.class);
}
Also used : SingleModel(com.liferay.apio.architect.single.model.SingleModel) JsonObject(com.google.gson.JsonObject) MockFormCreator.createForm(com.liferay.apio.architect.test.util.form.MockFormCreator.createForm) RequestInfo(com.liferay.apio.architect.request.RequestInfo) SingleModelMessageMapper(com.liferay.apio.architect.message.json.SingleModelMessageMapper) Operation(com.liferay.apio.architect.operation.Operation) HttpHeaders(javax.ws.rs.core.HttpHeaders) SingleModelWriter(com.liferay.apio.architect.writer.SingleModelWriter) Arrays.asList(java.util.Arrays.asList) Gson(com.google.gson.Gson) RootModel(com.liferay.apio.architect.test.util.model.RootModel) DELETE(com.liferay.apio.architect.operation.Method.DELETE) Optional(java.util.Optional) MockWriterUtil.getRequestInfo(com.liferay.apio.architect.test.util.writer.MockWriterUtil.getRequestInfo) SingleModel(com.liferay.apio.architect.single.model.SingleModel) PUT(com.liferay.apio.architect.operation.Method.PUT) RootModel(com.liferay.apio.architect.test.util.model.RootModel) Gson(com.google.gson.Gson) Operation(com.liferay.apio.architect.operation.Operation) RequestInfo(com.liferay.apio.architect.request.RequestInfo) MockWriterUtil.getRequestInfo(com.liferay.apio.architect.test.util.writer.MockWriterUtil.getRequestInfo)

Example 39 with HttpHeaders

use of javax.ws.rs.core.HttpHeaders in project neo4j by neo4j.

the class AbstractCypherResource method commitNewTransaction.

@POST
@Path("/commit")
public Response commitNewTransaction(InputEventStream inputEventStream, @Context HttpServletRequest request, @Context HttpHeaders headers) {
    try (var memoryTracker = createMemoryTracker()) {
        InputEventStream inputStream = ensureNotNull(inputEventStream);
        Optional<GraphDatabaseAPI> graphDatabaseAPI = httpTransactionManager.getGraphDatabaseAPI(databaseName);
        return graphDatabaseAPI.map(databaseAPI -> {
            if (isDatabaseNotAvailable(databaseAPI)) {
                return createNonAvailableDatabaseResponse(inputStream.getParameters());
            }
            memoryTracker.allocateHeap(Invocation.SHALLOW_SIZE);
            final TransactionFacade transactionFacade = httpTransactionManager.createTransactionFacade(databaseAPI, memoryTracker);
            TransactionHandle transactionHandle = createNewTransactionHandle(transactionFacade, request, headers, memoryTracker, true);
            Invocation invocation = new Invocation(log, transactionHandle, null, memoryPool, inputStream, true);
            OutputEventStreamImpl outputStream = new OutputEventStreamImpl(inputStream.getParameters(), transactionHandle, uriScheme, invocation::execute);
            return Response.ok(outputStream).build();
        }).orElse(createNonExistentDatabaseResponse(inputStream.getParameters()));
    }
}
Also used : PathParam(javax.ws.rs.PathParam) Neo4jError(org.neo4j.server.rest.Neo4jError) Log(org.neo4j.logging.Log) TransactionUriScheme(org.neo4j.server.http.cypher.format.api.TransactionUriScheme) Status(org.neo4j.kernel.api.exceptions.Status) Path(javax.ws.rs.Path) LoginContext(org.neo4j.internal.kernel.api.security.LoginContext) LocalMemoryTracker(org.neo4j.memory.LocalMemoryTracker) Objects.requireNonNullElse(java.util.Objects.requireNonNullElse) HttpServletRequest(javax.servlet.http.HttpServletRequest) Map(java.util.Map) UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) MemoryTracker(org.neo4j.memory.MemoryTracker) DELETE(javax.ws.rs.DELETE) HttpHeaderUtils.getTransactionTimeout(org.neo4j.server.web.HttpHeaderUtils.getTransactionTimeout) Collections.emptyMap(java.util.Collections.emptyMap) POST(javax.ws.rs.POST) Context(javax.ws.rs.core.Context) InputEventStream(org.neo4j.server.http.cypher.format.api.InputEventStream) MemoryPool(org.neo4j.memory.MemoryPool) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) AuthorizedRequestWrapper(org.neo4j.server.rest.dbms.AuthorizedRequestWrapper) HttpHeaders(javax.ws.rs.core.HttpHeaders) Response(javax.ws.rs.core.Response) Optional(java.util.Optional) UriInfo(javax.ws.rs.core.UriInfo) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) InputEventStream(org.neo4j.server.http.cypher.format.api.InputEventStream) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 40 with HttpHeaders

use of javax.ws.rs.core.HttpHeaders in project kafka by apache.

the class ConnectorsResourceTest method testResetConnectorActiveTopicsWithTopicTrackingEnabled.

@Test
public void testResetConnectorActiveTopicsWithTopicTrackingEnabled() {
    PowerMock.reset(workerConfig);
    EasyMock.expect(workerConfig.getBoolean(TOPIC_TRACKING_ENABLE_CONFIG)).andReturn(true);
    EasyMock.expect(workerConfig.getBoolean(TOPIC_TRACKING_ALLOW_RESET_CONFIG)).andReturn(false);
    HttpHeaders headers = EasyMock.mock(HttpHeaders.class);
    PowerMock.replay(workerConfig);
    connectorsResource = new ConnectorsResource(herder, workerConfig);
    PowerMock.replayAll();
    Exception e = assertThrows(ConnectRestException.class, () -> connectorsResource.resetConnectorActiveTopics(CONNECTOR_NAME, headers));
    assertEquals("Topic tracking reset is disabled.", e.getMessage());
    PowerMock.verifyAll();
}
Also used : HttpHeaders(javax.ws.rs.core.HttpHeaders) RebalanceNeededException(org.apache.kafka.connect.runtime.distributed.RebalanceNeededException) AlreadyExistsException(org.apache.kafka.connect.errors.AlreadyExistsException) NotLeaderException(org.apache.kafka.connect.runtime.distributed.NotLeaderException) BadRequestException(javax.ws.rs.BadRequestException) NotFoundException(org.apache.kafka.connect.errors.NotFoundException) NotAssignedException(org.apache.kafka.connect.runtime.distributed.NotAssignedException) ConnectRestException(org.apache.kafka.connect.runtime.rest.errors.ConnectRestException) IOException(java.io.IOException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

HttpHeaders (javax.ws.rs.core.HttpHeaders)95 Test (org.junit.Test)57 Message (org.apache.cxf.message.Message)31 Optional (java.util.Optional)13 HttpServletRequest (javax.servlet.http.HttpServletRequest)13 UriInfo (javax.ws.rs.core.UriInfo)12 CatalogFramework (ddf.catalog.CatalogFramework)10 Locale (java.util.Locale)10 Response (javax.ws.rs.core.Response)10 MultipartBody (org.apache.cxf.jaxrs.ext.multipart.MultipartBody)10 JsonObject (com.google.gson.JsonObject)9 MediaType (javax.ws.rs.core.MediaType)9 ByteArrayInputStream (java.io.ByteArrayInputStream)8 Map (java.util.Map)8 Cookie (javax.ws.rs.core.Cookie)8 IOException (java.io.IOException)7 Collections (java.util.Collections)7 WebApplicationException (javax.ws.rs.WebApplicationException)7 URI (java.net.URI)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6