use of io.crnk.core.queryspec.internal.QuerySpecAdapter in project crnk-framework by crnk-project.
the class BraveResponseFilterTest method setup.
@Before
public void setup() {
boot = new CrnkBoot();
boot.setServiceDiscovery(new ReflectionsServiceDiscovery("io.crnk.test.mock.repository", new SampleJsonServiceLocator()));
boot.boot();
span = Mockito.mock(Span.class);
tracing = Mockito.mock(Tracing.class);
tracer = Mockito.mock(Tracer.class);
Mockito.when(tracing.tracer()).thenReturn(tracer);
Mockito.when(tracer.nextSpan()).thenReturn(span);
moduleContext = Mockito.mock(Module.ModuleContext.class);
Mockito.when(moduleContext.getResourceRegistry()).thenReturn(boot.getResourceRegistry());
QuerySpec querySpec = new QuerySpec(Task.class);
queryAdapter = new QuerySpecAdapter(querySpec, boot.getResourceRegistry());
ResourceInformation taskResourceInformation = boot.getResourceRegistry().getEntry(Task.class).getResourceInformation();
requestSpec = Mockito.mock(RepositoryRequestSpec.class);
Mockito.when(requestSpec.getMethod()).thenReturn(HttpMethod.GET);
Mockito.when(requestSpec.getQueryAdapter()).thenReturn(queryAdapter);
Mockito.when(requestSpec.getQuerySpec(taskResourceInformation)).thenReturn(querySpec);
filter = new BraveRepositoryFilter(tracing, moduleContext);
filterContext = Mockito.mock(RepositoryFilterContext.class);
Mockito.when(filterContext.getRequest()).thenReturn(requestSpec);
filterChain = Mockito.mock(RepositoryRequestFilterChain.class);
}
use of io.crnk.core.queryspec.internal.QuerySpecAdapter in project crnk-framework by crnk-project.
the class OperationsCall method toResource.
protected Resource toResource(Object object) {
JsonApiResponse response = new JsonApiResponse();
response.setEntity(object);
QuerySpec querySpec = new QuerySpec(object.getClass());
QueryAdapter queryAdapter = new QuerySpecAdapter(querySpec, client.getCrnk().getRegistry());
CrnkClient crnk = client.getCrnk();
DocumentMapper documentMapper = crnk.getDocumentMapper();
Document document = documentMapper.toDocument(response, queryAdapter);
return document.getSingleData().get();
}
use of io.crnk.core.queryspec.internal.QuerySpecAdapter in project crnk-framework by crnk-project.
the class BraveUtil method getQuery.
public static String getQuery(RepositoryRequestSpec request, ResourceRegistry resourceRegistry) {
QueryAdapter queryAdapter = request.getQueryAdapter();
StringBuilder builder = new StringBuilder();
builder.append("?");
if (queryAdapter instanceof QuerySpecAdapter) {
QuerySpec querySpec = request.getQuerySpec(queryAdapter.getResourceInformation());
DefaultQuerySpecSerializer serializer = new DefaultQuerySpecSerializer(resourceRegistry);
Map<String, Set<String>> parameters = serializer.serialize(querySpec);
for (Map.Entry<String, Set<String>> entry : parameters.entrySet()) {
if (builder.length() > 1) {
builder.append("&");
}
builder.append(entry.getKey());
builder.append("=");
builder.append(StringUtils.join(",", entry.getValue()));
}
return builder.toString();
}
return null;
}
Aggregations