@Test /** for {@link SingleThumbnailAdapter#get()} */ public void should_return_proper_operation_result() { // Given mockStatic(JerseyRequest.class); when(buildRequest( eq(sessionStorageMock), eq(InputStream.class), eq(new String[] {"/thumbnails", "/public/Samples/Reports/07g.RevenueDetailReport"}), any(DefaultErrorHandler.class))) .thenReturn(jerseyRequestMock); when(jerseyRequestMock.setAccept("image/jpeg")).thenReturn(jerseyRequestMock); when(jerseyRequestMock.get()).thenReturn(operationResultMock); SingleThumbnailAdapter thumbnailAdapter = new SingleThumbnailAdapter(sessionStorageMock); thumbnailAdapter.report("/public/Samples/Reports/07g.RevenueDetailReport"); // When OperationResult<InputStream> retrieved = thumbnailAdapter.get(); // Then assertNotNull(retrieved); assertSame(retrieved, operationResultMock); verify(jerseyRequestMock).setAccept(eq("image/jpeg")); verify(jerseyRequestMock).get(); verifyStatic(times(1)); buildRequest( eq(sessionStorageMock), eq(InputStream.class), eq(new String[] {"/thumbnails", "/public/Samples/Reports/07g.RevenueDetailReport"}), any(DefaultErrorHandler.class)); }
private <T> JerseyRequest<T> getBuilder(Class<T> responseClass) { JerseyRequest<T> request = buildRequest( sessionStorage, responseClass, new String[] {"/resources"}, new DefaultErrorHandler()); request.addParams(params); return request; }
private JerseyRequest<ClientFile> prepareUploadFileRequest() { JerseyRequest<ClientFile> request = buildRequest(sessionStorage, ClientFile.class, new String[] {"/resources", resourceUri}); request.addParams(params); request.setContentType(MediaType.MULTIPART_FORM_DATA); return request; }
/** * Allows to upload resource with MultiPart request. * * @param multipartResource form * @param clazz entity class * @param <T> type of entity class * @return result instance */ public <T> OperationResult<T> uploadMultipartResource( FormDataMultiPart multipartResource, Class<T> clazz) { JerseyRequest<T> request = buildRequest(sessionStorage, clazz, new String[] {"/resources", resourceUri}); request.setContentType(MediaType.MULTIPART_FORM_DATA); return request.post(multipartResource); }
private OperationResult<ClientResource> copyOrMove(boolean moving, String fromUri) { JerseyRequest<ClientResource> request = prepareCopyOrMoveRequest(fromUri); if (moving) { return request.put(""); } else { return request.post(null); } }
/** * Jersey request setup. Generified with a proper entity. * * @return JerseyRequest instance */ private JerseyRequest<ClientSemanticLayerDataSource> prepareUploadResourcesRequest() { JerseyRequest<ClientSemanticLayerDataSource> request = buildRequest( sessionStorage, ClientSemanticLayerDataSource.class, new String[] {"/resources", resourceUri}); request.setContentType(MediaType.MULTIPART_FORM_DATA); return request; }
private JerseyRequest<ClientResource> prepareCopyOrMoveRequest(String fromUri) { JerseyRequest<ClientResource> request = buildRequest( sessionStorage, ClientResource.class, new String[] {"/resources", resourceUri}, new DefaultErrorHandler()); request.addParams(params); request.addHeader("Content-Location", fromUri); return request; }
private <ResourceType extends ClientResource> JerseyRequest<ResourceType> preparePatchResourceRequest( Class<ResourceType> resourceTypeClass) { JerseyRequest<ResourceType> request = buildRequest(sessionStorage, resourceTypeClass, new String[] {"/resources", resourceUri}); request.setAccept( MimeTypeUtil.toCorrectContentMime( sessionStorage.getConfiguration(), ResourcesTypeResolverUtil.getMimeType(resourceTypeClass))); request.addHeader("X-HTTP-Method-Override", "PATCH"); return request; }
private JerseyRequest<ClientResource> prepareDetailsRequest() { JerseyRequest<ClientResource> request = buildRequest( sessionStorage, ClientResource.class, new String[] {"/resources", resourceUri}); request.addParams(params); if (isRootFolder(resourceUri)) { request.setAccept(ResourceMediaType.FOLDER_JSON); } else { request.setAccept(ResourceMediaType.FILE_JSON); } return request; }
private JerseyRequest<Organization> buildRequest() { return JerseyRequest.buildRequest( sessionStorage, Organization.class, new String[] {"/organizations", organizationId}, new DefaultErrorHandler()); }
private JerseyRequest<ClientResource> prepareCreateOrUpdateRequest(ClientResource resource) { Class<? extends ClientResource> resourceType = ResourcesTypeResolverUtil.getResourceType(resource); JerseyRequest<? extends ClientResource> request = buildRequest( sessionStorage, resourceType, new String[] {"/resources", resourceUri}, new DefaultErrorHandler()); request.setContentType( MimeTypeUtil.toCorrectContentMime( sessionStorage.getConfiguration(), ResourcesTypeResolverUtil.getMimeType(resourceType))); request.addParams(params); return (JerseyRequest<ClientResource>) request; }
private JerseyRequest<Map> request() { return JerseyRequest.buildRequest( sessionStorage, Map.class, new String[] {"/settings/" + groupKey}, new DefaultErrorHandler()); }
@Test(testName = "state") public void should_return_proper_OperationResult_object() { // Given PowerMockito.mockStatic(JerseyRequest.class); PowerMockito.when( JerseyRequest.buildRequest( eq(storageMock), eq(StateDto.class), eq(fakeArrayPath), any(DefaultErrorHandler.class))) .thenReturn(requestMock); PowerMockito.when(requestMock.get()).thenReturn(resultMock); // When ImportRequestAdapter adapter = new ImportRequestAdapter(storageMock, taskId); OperationResult<StateDto> opResult = adapter.state(); // Then assertSame(opResult, resultMock); }
@Test public void should_retrieve_state_asynchronously() throws InterruptedException { /* Given */ PowerMockito.mockStatic(JerseyRequest.class); PowerMockito.when( JerseyRequest.buildRequest( eq(storageMock), eq(StateDto.class), eq(new String[] {"/import", taskId, "/state"}))) .thenReturn(requestMock); PowerMockito.doReturn(resultMock).when(requestMock).get(); ImportRequestAdapter adapterSpy = PowerMockito.spy(new ImportRequestAdapter(storageMock, taskId)); final AtomicInteger newThreadId = new AtomicInteger(); final int currentThreadId = (int) Thread.currentThread().getId(); final Callback<OperationResult<StateDto>, Void> callback = PowerMockito.spy( new Callback<OperationResult<StateDto>, Void>() { @Override public Void execute(OperationResult<StateDto> data) { newThreadId.set((int) Thread.currentThread().getId()); synchronized (this) { this.notify(); } return null; } }); PowerMockito.doReturn(null).when(callback).execute(resultMock); /* When */ RequestExecution retrieved = adapterSpy.asyncState(callback); /* Wait */ synchronized (callback) { callback.wait(1000); } /* Then */ Mockito.verify(requestMock).get(); Mockito.verify(callback).execute(resultMock); Assert.assertNotNull(retrieved); Assert.assertNotSame(currentThreadId, newThreadId.get()); }
public OperationResult<ClientResource> details() { JerseyRequest<ClientResource> request = prepareDetailsRequest(); return request.get(); }
public <ResourceType extends ClientResource> OperationResult<ResourceType> patchResource( Class<ResourceType> resourceTypeClass, PatchDescriptor descriptor) { JerseyRequest<ResourceType> request = preparePatchResourceRequest(resourceTypeClass); return request.post(descriptor); }
public OperationResult delete() { JerseyRequest request = buildRequest(sessionStorage, Object.class, new String[] {"/resources", resourceUri}); return request.delete(); }
public <T> OperationResult<T> get(Class<T> clazz) { JerseyRequest<T> request = buildRequest(sessionStorage, clazz, new String[] {"/resources", resourceUri}); return request.get(); }
public OperationResult<ClientFile> uploadFile( File fileContent, ClientFile.FileType fileType, String label, String description) { FormDataMultiPart form = prepareUploadForm(fileContent, fileType, label, description); JerseyRequest<ClientFile> request = prepareUploadFileRequest(); return request.post(form); }