use of com.linkedin.data.codec.symbol.InMemorySymbolTable in project rest.li by linkedin.
the class TestRestLiSymbolTableRequestHandler method testReturnOtherSymbolTable.
@Test
public void testReturnOtherSymbolTable() throws Exception {
SymbolTable symbolTable = new InMemorySymbolTable("TestName", ImmutableList.of("Haha", "Hehe", "Hoho"));
URI uri = URI.create("/symbolTable/OtherTable");
RestRequest request = new RestRequestBuilder(uri).build();
when(_symbolTableProvider.getSymbolTable(eq("OtherTable"))).thenReturn(symbolTable);
CompletableFuture<RestResponse> future = new CompletableFuture<>();
_requestHandler.handleRequest(request, mock(RequestContext.class), new Callback<RestResponse>() {
@Override
public void onError(Throwable e) {
future.completeExceptionally(e);
}
@Override
public void onSuccess(RestResponse result) {
future.complete(result);
}
});
Assert.assertFalse(future.isCompletedExceptionally());
Assert.assertTrue(future.isDone());
RestResponse response = future.get();
Assert.assertEquals(response.getStatus(), HttpStatus.S_200_OK.getCode());
Assert.assertEquals(response.getHeader(RestConstants.HEADER_CONTENT_TYPE), ContentType.PROTOBUF2.getHeaderKey());
Assert.assertEquals(symbolTable, SymbolTableSerializer.fromByteString(response.getEntity(), ContentType.PROTOBUF2.getCodec()));
}
use of com.linkedin.data.codec.symbol.InMemorySymbolTable in project rest.li by linkedin.
the class TestRestLiSymbolTableRequestHandler method testReturnSelfSymbolTableWhenCalledWithServiceScope.
@Test
public void testReturnSelfSymbolTableWhenCalledWithServiceScope() throws Exception {
SymbolTable symbolTable = new InMemorySymbolTable("TestName", ImmutableList.of("Haha", "Hehe", "Hoho"));
URI uri = URI.create("/service/symbolTable");
RestRequest request = new RestRequestBuilder(uri).build();
when(_symbolTableProvider.getResponseSymbolTable(eq(uri), eq(Collections.emptyMap()))).thenReturn(symbolTable);
CompletableFuture<RestResponse> future = new CompletableFuture<>();
_requestHandler.handleRequest(request, mock(RequestContext.class), new Callback<RestResponse>() {
@Override
public void onError(Throwable e) {
future.completeExceptionally(e);
}
@Override
public void onSuccess(RestResponse result) {
future.complete(result);
}
});
Assert.assertFalse(future.isCompletedExceptionally());
Assert.assertTrue(future.isDone());
RestResponse response = future.get();
Assert.assertEquals(response.getStatus(), HttpStatus.S_200_OK.getCode());
Assert.assertEquals(response.getHeader(RestConstants.HEADER_CONTENT_TYPE), ContentType.PROTOBUF2.getHeaderKey());
Assert.assertEquals(symbolTable, SymbolTableSerializer.fromByteString(response.getEntity(), ContentType.PROTOBUF2.getCodec()));
}
use of com.linkedin.data.codec.symbol.InMemorySymbolTable in project rest.li by linkedin.
the class TestRestLiSymbolTableRequestHandler method testReturnOtherSymbolTableNonDefaultAcceptType.
@Test
public void testReturnOtherSymbolTableNonDefaultAcceptType() throws Exception {
SymbolTable symbolTable = new InMemorySymbolTable("TestName", ImmutableList.of("Haha", "Hehe", "Hoho"));
URI uri = URI.create("/symbolTable/OtherTable");
RestRequest request = new RestRequestBuilder(uri).setHeader(RestConstants.HEADER_ACCEPT, ContentType.JSON.getHeaderKey()).build();
when(_symbolTableProvider.getSymbolTable(eq("OtherTable"))).thenReturn(symbolTable);
CompletableFuture<RestResponse> future = new CompletableFuture<>();
_requestHandler.handleRequest(request, mock(RequestContext.class), new Callback<RestResponse>() {
@Override
public void onError(Throwable e) {
future.completeExceptionally(e);
}
@Override
public void onSuccess(RestResponse result) {
future.complete(result);
}
});
Assert.assertFalse(future.isCompletedExceptionally());
Assert.assertTrue(future.isDone());
RestResponse response = future.get();
Assert.assertEquals(response.getStatus(), HttpStatus.S_200_OK.getCode());
Assert.assertEquals(response.getHeader(RestConstants.HEADER_CONTENT_TYPE), ContentType.JSON.getHeaderKey());
Assert.assertEquals(symbolTable, SymbolTableSerializer.fromByteString(response.getEntity(), ContentType.JSON.getCodec()));
}
use of com.linkedin.data.codec.symbol.InMemorySymbolTable in project rest.li by linkedin.
the class TestStreamCodec method getCodecs.
private List<StreamDataCodec> getCodecs(int bufferSize, DataComplex data) {
List<StreamDataCodec> codecs = new ArrayList<>();
codecs.add(new JacksonSmileStreamDataCodec(bufferSize));
codecs.add(new JacksonStreamDataCodec(bufferSize));
codecs.add(new ProtobufStreamDataCodec(bufferSize));
Set<String> symbols = new HashSet<>();
if (data instanceof DataMap) {
collectSymbols(symbols, (DataMap) data);
} else {
collectSymbols(symbols, (DataList) data);
}
final String sharedSymbolTableName = "SHARED";
SymbolTable symbolTable = new InMemorySymbolTable(sharedSymbolTableName, new ArrayList<>(symbols));
codecs.add(new JacksonLICORStreamDataCodec(bufferSize, true, symbolTable));
codecs.add(new ProtobufStreamDataCodec(bufferSize, new ProtobufCodecOptions.Builder().setSymbolTable(symbolTable).setEnableASCIIOnlyStrings(true).build()));
return codecs;
}
use of com.linkedin.data.codec.symbol.InMemorySymbolTable in project rest.li by linkedin.
the class TestRestLiSymbolTableRequestHandler method testReturnSelfSymbolTable.
@Test
public void testReturnSelfSymbolTable() throws Exception {
SymbolTable symbolTable = new InMemorySymbolTable("TestName", ImmutableList.of("Haha", "Hehe", "Hoho"));
URI uri = URI.create("/symbolTable");
RestRequest request = new RestRequestBuilder(uri).build();
when(_symbolTableProvider.getResponseSymbolTable(eq(uri), eq(Collections.emptyMap()))).thenReturn(symbolTable);
CompletableFuture<RestResponse> future = new CompletableFuture<>();
_requestHandler.handleRequest(request, mock(RequestContext.class), new Callback<RestResponse>() {
@Override
public void onError(Throwable e) {
future.completeExceptionally(e);
}
@Override
public void onSuccess(RestResponse result) {
future.complete(result);
}
});
Assert.assertFalse(future.isCompletedExceptionally());
Assert.assertTrue(future.isDone());
RestResponse response = future.get();
Assert.assertEquals(response.getStatus(), HttpStatus.S_200_OK.getCode());
Assert.assertEquals(response.getHeader(RestConstants.HEADER_CONTENT_TYPE), ContentType.PROTOBUF2.getHeaderKey());
Assert.assertEquals(symbolTable, SymbolTableSerializer.fromByteString(response.getEntity(), ContentType.PROTOBUF2.getCodec()));
}
Aggregations