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)));
}
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)));
}
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);
}
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()));
}
}
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();
}
Aggregations